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/sequenced_task_runner_helpers.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/common/content_settings.h"
15 #include "content/public/browser/browser_message_filter.h"
16 #include "third_party/WebKit/public/web/WebCache.h"
19 struct ExtensionHostMsg_APIActionOrEvent_Params;
20 struct ExtensionHostMsg_DOMAction_Params;
21 struct ExtensionMsg_ExternalConnectionInfo;
24 namespace extensions {
30 class URLRequestContextGetter;
33 // This class filters out incoming Chrome-specific IPC messages for the renderer
34 // process on the IPC thread.
35 class ChromeRenderMessageFilter : public content::BrowserMessageFilter {
37 ChromeRenderMessageFilter(int render_process_id,
39 net::URLRequestContextGetter* request_context);
41 class V8HeapStatsDetails {
43 V8HeapStatsDetails(size_t v8_memory_allocated,
44 size_t v8_memory_used)
45 : v8_memory_allocated_(v8_memory_allocated),
46 v8_memory_used_(v8_memory_used) {}
47 size_t v8_memory_allocated() const { return v8_memory_allocated_; }
48 size_t v8_memory_used() const { return v8_memory_used_; }
50 size_t v8_memory_allocated_;
51 size_t v8_memory_used_;
54 // content::BrowserMessageFilter methods:
55 virtual bool OnMessageReceived(const IPC::Message& message,
56 bool* message_was_ok) OVERRIDE;
57 virtual void OverrideThreadForMessage(
58 const IPC::Message& message,
59 content::BrowserThread::ID* thread) OVERRIDE;
61 int render_process_id() { return render_process_id_; }
62 bool off_the_record() { return off_the_record_; }
63 net::HostResolver* GetHostResolver();
66 friend class content::BrowserThread;
67 friend class base::DeleteHelper<ChromeRenderMessageFilter>;
69 virtual ~ChromeRenderMessageFilter();
71 void OnDnsPrefetch(const std::vector<std::string>& hostnames);
72 void OnPreconnect(const GURL& url);
73 void OnResourceTypeStats(const blink::WebCache::ResourceTypeStats& stats);
74 void OnUpdatedCacheStats(const blink::WebCache::UsageStats& stats);
75 void OnFPS(int routing_id, float fps);
76 void OnV8HeapStats(int v8_memory_allocated, int v8_memory_used);
78 // TODO(jamescook): Move these functions into the extensions module. Ideally
79 // this would be in extensions::ExtensionMessageFilter but that will require
80 // resolving the MessageService and ActivityLog dependencies on src/chrome.
81 // http://crbug.com/339637
82 void OnOpenChannelToExtension(int routing_id,
83 const ExtensionMsg_ExternalConnectionInfo& info,
84 const std::string& channel_name,
85 bool include_tls_channel_id,
87 void OpenChannelToExtensionOnUIThread(
88 int source_process_id,
89 int source_routing_id,
91 const ExtensionMsg_ExternalConnectionInfo& info,
92 const std::string& channel_name,
93 bool include_tls_channel_id);
94 void OnOpenChannelToNativeApp(int routing_id,
95 const std::string& source_extension_id,
96 const std::string& native_app_name,
98 void OpenChannelToNativeAppOnUIThread(int source_routing_id,
100 const std::string& source_extension_id,
101 const std::string& native_app_name);
102 void OnOpenChannelToTab(int routing_id, int tab_id,
103 const std::string& extension_id,
104 const std::string& channel_name, int* port_id);
105 void OpenChannelToTabOnUIThread(int source_process_id, int source_routing_id,
106 int receiver_port_id,
107 int tab_id, const std::string& extension_id,
108 const std::string& channel_name);
109 void OnGetExtensionMessageBundle(const std::string& extension_id,
110 IPC::Message* reply_msg);
111 void OnGetExtensionMessageBundleOnFileThread(
112 const base::FilePath& extension_path,
113 const std::string& extension_id,
114 const std::string& default_locale,
115 IPC::Message* reply_msg);
116 void OnExtensionCloseChannel(int port_id, const std::string& error_message);
117 void OnAddAPIActionToExtensionActivityLog(
118 const std::string& extension_id,
119 const ExtensionHostMsg_APIActionOrEvent_Params& params);
120 void OnAddBlockedCallToExtensionActivityLog(
121 const std::string& extension_id,
122 const std::string& function_name);
123 void OnAddDOMActionToExtensionActivityLog(
124 const std::string& extension_id,
125 const ExtensionHostMsg_DOMAction_Params& params);
126 void OnAddEventToExtensionActivityLog(
127 const std::string& extension_id,
128 const ExtensionHostMsg_APIActionOrEvent_Params& params);
129 void OnAllowDatabase(int render_frame_id,
130 const GURL& origin_url,
131 const GURL& top_origin_url,
132 const base::string16& name,
133 const base::string16& display_name,
135 void OnAllowDOMStorage(int render_frame_id,
136 const GURL& origin_url,
137 const GURL& top_origin_url,
140 void OnAllowFileSystem(int render_frame_id,
141 const GURL& origin_url,
142 const GURL& top_origin_url,
144 void OnAllowIndexedDB(int render_frame_id,
145 const GURL& origin_url,
146 const GURL& top_origin_url,
147 const base::string16& name,
149 void OnCanTriggerClipboardRead(const GURL& origin, bool* allowed);
150 void OnCanTriggerClipboardWrite(const GURL& origin, bool* allowed);
151 void OnIsCrashReportingEnabled(bool* enabled);
153 int render_process_id_;
155 // The Profile associated with our renderer process. This should only be
156 // accessed on the UI thread!
158 // Copied from the profile so that it can be read on the IO thread.
159 bool off_the_record_;
160 // The Predictor for the associated Profile. It is stored so that it can be
161 // used on the IO thread.
162 chrome_browser_net::Predictor* predictor_;
163 scoped_refptr<net::URLRequestContextGetter> request_context_;
164 scoped_refptr<extensions::InfoMap> extension_info_map_;
165 // Used to look up permissions at database creation time.
166 scoped_refptr<CookieSettings> cookie_settings_;
168 DISALLOW_COPY_AND_ASSIGN(ChromeRenderMessageFilter);
171 #endif // CHROME_BROWSER_RENDERER_HOST_CHROME_RENDER_MESSAGE_FILTER_H_