1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_RENDERER_HOST_CHROME_RENDER_MESSAGE_FILTER_H_
6 #define CHROME_BROWSER_RENDERER_HOST_CHROME_RENDER_MESSAGE_FILTER_H_
11 #include "base/files/file_path.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/sequenced_task_runner_helpers.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/common/content_settings.h"
16 #include "content/public/browser/browser_message_filter.h"
17 #include "third_party/WebKit/public/web/WebCache.h"
20 struct ExtensionHostMsg_APIActionOrEvent_Params;
21 struct ExtensionHostMsg_DOMAction_Params;
22 struct ExtensionHostMsg_Request_Params;
23 struct ExtensionMsg_ExternalConnectionInfo;
26 namespace extensions {
32 class URLRequestContextGetter;
35 // This class filters out incoming Chrome-specific IPC messages for the renderer
36 // process on the IPC thread.
37 class ChromeRenderMessageFilter : public content::BrowserMessageFilter {
39 ChromeRenderMessageFilter(int render_process_id,
41 net::URLRequestContextGetter* request_context);
43 // Notification detail classes.
46 FPSDetails(int routing_id, float fps)
47 : routing_id_(routing_id),
49 int routing_id() const { return routing_id_; }
50 float fps() const { return fps_; }
56 class V8HeapStatsDetails {
58 V8HeapStatsDetails(size_t v8_memory_allocated,
59 size_t v8_memory_used)
60 : v8_memory_allocated_(v8_memory_allocated),
61 v8_memory_used_(v8_memory_used) {}
62 size_t v8_memory_allocated() const { return v8_memory_allocated_; }
63 size_t v8_memory_used() const { return v8_memory_used_; }
65 size_t v8_memory_allocated_;
66 size_t v8_memory_used_;
69 // content::BrowserMessageFilter methods:
70 virtual bool OnMessageReceived(const IPC::Message& message,
71 bool* message_was_ok) OVERRIDE;
72 virtual void OverrideThreadForMessage(
73 const IPC::Message& message,
74 content::BrowserThread::ID* thread) OVERRIDE;
76 int render_process_id() { return render_process_id_; }
77 bool off_the_record() { return off_the_record_; }
78 net::HostResolver* GetHostResolver();
81 friend class content::BrowserThread;
82 friend class base::DeleteHelper<ChromeRenderMessageFilter>;
84 virtual ~ChromeRenderMessageFilter();
86 void OnDnsPrefetch(const std::vector<std::string>& hostnames);
87 void OnPreconnect(const GURL& url);
88 void OnResourceTypeStats(const blink::WebCache::ResourceTypeStats& stats);
89 void OnUpdatedCacheStats(const blink::WebCache::UsageStats& stats);
90 void OnFPS(int routing_id, float fps);
91 void OnV8HeapStats(int v8_memory_allocated, int v8_memory_used);
93 // TODO(jamescook): Move these functions into the extensions module. Ideally
94 // this would be in extensions::ExtensionMessageFilter but that will require
95 // resolving the MessageService and ActivityLog dependencies on src/chrome.
96 // http://crbug.com/339637
97 void OnOpenChannelToExtension(int routing_id,
98 const ExtensionMsg_ExternalConnectionInfo& info,
99 const std::string& channel_name,
100 bool include_tls_channel_id,
102 void OpenChannelToExtensionOnUIThread(
103 int source_process_id,
104 int source_routing_id,
105 int receiver_port_id,
106 const ExtensionMsg_ExternalConnectionInfo& info,
107 const std::string& channel_name,
108 bool include_tls_channel_id);
109 void OnOpenChannelToNativeApp(int routing_id,
110 const std::string& source_extension_id,
111 const std::string& native_app_name,
113 void OpenChannelToNativeAppOnUIThread(int source_routing_id,
114 int receiver_port_id,
115 const std::string& source_extension_id,
116 const std::string& native_app_name);
117 void OnOpenChannelToTab(int routing_id, int tab_id,
118 const std::string& extension_id,
119 const std::string& channel_name, int* port_id);
120 void OpenChannelToTabOnUIThread(int source_process_id, int source_routing_id,
121 int receiver_port_id,
122 int tab_id, const std::string& extension_id,
123 const std::string& channel_name);
124 void OnGetExtensionMessageBundle(const std::string& extension_id,
125 IPC::Message* reply_msg);
126 void OnGetExtensionMessageBundleOnFileThread(
127 const base::FilePath& extension_path,
128 const std::string& extension_id,
129 const std::string& default_locale,
130 IPC::Message* reply_msg);
131 void OnExtensionCloseChannel(int port_id, const std::string& error_message);
132 void OnExtensionRequestForIOThread(
134 const ExtensionHostMsg_Request_Params& params);
135 void OnAddAPIActionToExtensionActivityLog(
136 const std::string& extension_id,
137 const ExtensionHostMsg_APIActionOrEvent_Params& params);
138 void OnAddBlockedCallToExtensionActivityLog(
139 const std::string& extension_id,
140 const std::string& function_name);
141 void OnAddDOMActionToExtensionActivityLog(
142 const std::string& extension_id,
143 const ExtensionHostMsg_DOMAction_Params& params);
144 void OnAddEventToExtensionActivityLog(
145 const std::string& extension_id,
146 const ExtensionHostMsg_APIActionOrEvent_Params& params);
147 void OnAllowDatabase(int render_frame_id,
148 const GURL& origin_url,
149 const GURL& top_origin_url,
150 const base::string16& name,
151 const base::string16& display_name,
153 void OnAllowDOMStorage(int render_frame_id,
154 const GURL& origin_url,
155 const GURL& top_origin_url,
158 void OnAllowFileSystem(int render_frame_id,
159 const GURL& origin_url,
160 const GURL& top_origin_url,
162 void OnAllowIndexedDB(int render_frame_id,
163 const GURL& origin_url,
164 const GURL& top_origin_url,
165 const base::string16& name,
167 void OnCanTriggerClipboardRead(const GURL& origin, bool* allowed);
168 void OnCanTriggerClipboardWrite(const GURL& origin, bool* allowed);
170 int render_process_id_;
172 // The Profile associated with our renderer process. This should only be
173 // accessed on the UI thread!
175 // Copied from the profile so that it can be read on the IO thread.
176 bool off_the_record_;
177 // The Predictor for the associated Profile. It is stored so that it can be
178 // used on the IO thread.
179 chrome_browser_net::Predictor* predictor_;
180 scoped_refptr<net::URLRequestContextGetter> request_context_;
181 scoped_refptr<extensions::InfoMap> extension_info_map_;
182 // Used to look up permissions at database creation time.
183 scoped_refptr<CookieSettings> cookie_settings_;
185 base::WeakPtrFactory<ChromeRenderMessageFilter> weak_ptr_factory_;
187 DISALLOW_COPY_AND_ASSIGN(ChromeRenderMessageFilter);
190 #endif // CHROME_BROWSER_RENDERER_HOST_CHROME_RENDER_MESSAGE_FILTER_H_