Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 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. |
| 4 | |
| 5 | #ifndef CONTENT_BROWSER_RENDERER_HOST_RENDER_MESSAGE_FILTER_H_ |
| 6 | #define CONTENT_BROWSER_RENDERER_HOST_RENDER_MESSAGE_FILTER_H_ |
| 7 | |
| 8 | #if defined(OS_WIN) |
| 9 | #include <windows.h> |
| 10 | #endif |
| 11 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 12 | #include <set> |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 13 | #include <string> |
| 14 | #include <vector> |
| 15 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 16 | #include "base/files/file_path.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 17 | #include "base/memory/linked_ptr.h" |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 18 | #include "base/memory/shared_memory.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 19 | #include "base/sequenced_task_runner_helpers.h" |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 20 | #include "base/strings/string16.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 21 | #include "build/build_config.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 22 | #include "content/common/pepper_renderer_instance_data.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 23 | #include "content/public/browser/browser_message_filter.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 24 | #include "content/public/common/three_d_api_types.h" |
| 25 | #include "media/audio/audio_parameters.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 26 | #include "media/base/channel_layout.h" |
| 27 | #include "net/cookies/canonical_cookie.h" |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 28 | #include "third_party/WebKit/public/web/WebPopupType.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 29 | #include "ui/gfx/native_widget_types.h" |
| 30 | #include "ui/surface/transport_dib.h" |
| 31 | |
| 32 | #if defined(OS_MACOSX) |
| 33 | #include "content/common/mac/font_loader.h" |
| 34 | #endif |
| 35 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 36 | #if defined(OS_ANDROID) |
| 37 | #include "base/threading/worker_pool.h" |
| 38 | #endif |
| 39 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 40 | struct FontDescriptor; |
| 41 | struct ViewHostMsg_CreateWindow_Params; |
| 42 | |
| 43 | namespace WebKit { |
| 44 | struct WebScreenInfo; |
| 45 | } |
| 46 | |
| 47 | namespace base { |
| 48 | class ProcessMetrics; |
| 49 | class SharedMemory; |
| 50 | class TaskRunner; |
| 51 | } |
| 52 | |
| 53 | namespace gfx { |
| 54 | class Rect; |
| 55 | } |
| 56 | |
| 57 | namespace media { |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 58 | class AudioManager; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 59 | struct MediaLogEvent; |
| 60 | } |
| 61 | |
| 62 | namespace net { |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 63 | class URLRequestContext; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 64 | class URLRequestContextGetter; |
| 65 | } |
| 66 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 67 | namespace content { |
| 68 | class BrowserContext; |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 69 | class DOMStorageContextWrapper; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 70 | class MediaInternals; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 71 | class PluginServiceImpl; |
| 72 | class RenderWidgetHelper; |
| 73 | class ResourceContext; |
| 74 | class ResourceDispatcherHostImpl; |
| 75 | struct Referrer; |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 76 | struct WebPluginInfo; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 77 | |
| 78 | // This class filters out incoming IPC messages for the renderer process on the |
| 79 | // IPC thread. |
| 80 | class RenderMessageFilter : public BrowserMessageFilter { |
| 81 | public: |
| 82 | // Create the filter. |
| 83 | RenderMessageFilter(int render_process_id, |
Ben Murdoch | 558790d | 2013-07-30 15:19:42 +0100 | [diff] [blame] | 84 | bool is_guest, |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 85 | PluginServiceImpl * plugin_service, |
| 86 | BrowserContext* browser_context, |
| 87 | net::URLRequestContextGetter* request_context, |
| 88 | RenderWidgetHelper* render_widget_helper, |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 89 | media::AudioManager* audio_manager, |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 90 | MediaInternals* media_internals, |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 91 | DOMStorageContextWrapper* dom_storage_context); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 92 | |
| 93 | // IPC::ChannelProxy::MessageFilter methods: |
| 94 | virtual void OnChannelClosing() OVERRIDE; |
| 95 | virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; |
| 96 | |
| 97 | // BrowserMessageFilter methods: |
| 98 | virtual bool OnMessageReceived(const IPC::Message& message, |
| 99 | bool* message_was_ok) OVERRIDE; |
| 100 | virtual void OnDestruct() const OVERRIDE; |
| 101 | virtual base::TaskRunner* OverrideTaskRunnerForMessage( |
| 102 | const IPC::Message& message) OVERRIDE; |
| 103 | |
| 104 | bool OffTheRecord() const; |
| 105 | |
| 106 | int render_process_id() const { return render_process_id_; } |
| 107 | |
| 108 | // Returns the correct net::URLRequestContext depending on what type of url is |
| 109 | // given. |
| 110 | // Only call on the IO thread. |
| 111 | net::URLRequestContext* GetRequestContextForURL(const GURL& url); |
| 112 | |
| 113 | private: |
| 114 | friend class BrowserThread; |
| 115 | friend class base::DeleteHelper<RenderMessageFilter>; |
| 116 | |
| 117 | class OpenChannelToNpapiPluginCallback; |
| 118 | |
| 119 | virtual ~RenderMessageFilter(); |
| 120 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 121 | void OnGetProcessMemorySizes(size_t* private_bytes, size_t* shared_bytes); |
| 122 | void OnCreateWindow(const ViewHostMsg_CreateWindow_Params& params, |
| 123 | int* route_id, |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 124 | int* main_frame_route_id, |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 125 | int* surface_id, |
| 126 | int64* cloned_session_storage_namespace_id); |
| 127 | void OnCreateWidget(int opener_id, |
| 128 | WebKit::WebPopupType popup_type, |
| 129 | int* route_id, |
| 130 | int* surface_id); |
| 131 | void OnCreateFullscreenWidget(int opener_id, |
| 132 | int* route_id, |
| 133 | int* surface_id); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 134 | void OnSetCookie(const IPC::Message& message, |
| 135 | const GURL& url, |
| 136 | const GURL& first_party_for_cookies, |
| 137 | const std::string& cookie); |
| 138 | void OnGetCookies(const GURL& url, |
| 139 | const GURL& first_party_for_cookies, |
| 140 | IPC::Message* reply_msg); |
| 141 | void OnGetRawCookies(const GURL& url, |
| 142 | const GURL& first_party_for_cookies, |
| 143 | IPC::Message* reply_msg); |
| 144 | void OnDeleteCookie(const GURL& url, |
| 145 | const std::string& cookieName); |
| 146 | void OnCookiesEnabled(const GURL& url, |
| 147 | const GURL& first_party_for_cookies, |
| 148 | bool* cookies_enabled); |
| 149 | |
| 150 | #if defined(OS_MACOSX) |
| 151 | // Messages for OOP font loading. |
| 152 | void OnLoadFont(const FontDescriptor& font, IPC::Message* reply_msg); |
| 153 | void SendLoadFontReply(IPC::Message* reply, FontLoader::Result* result); |
| 154 | #endif |
| 155 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 156 | #if defined(OS_WIN) |
| 157 | void OnPreCacheFontCharacters(const LOGFONT& log_font, |
| 158 | const string16& characters); |
| 159 | #endif |
| 160 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 161 | void OnGetPlugins(bool refresh, IPC::Message* reply_msg); |
| 162 | void GetPluginsCallback(IPC::Message* reply_msg, |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 163 | const std::vector<WebPluginInfo>& plugins); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 164 | void OnGetPluginInfo(int routing_id, |
| 165 | const GURL& url, |
| 166 | const GURL& policy_url, |
| 167 | const std::string& mime_type, |
| 168 | bool* found, |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 169 | WebPluginInfo* info, |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 170 | std::string* actual_mime_type); |
| 171 | void OnOpenChannelToPlugin(int routing_id, |
| 172 | const GURL& url, |
| 173 | const GURL& policy_url, |
| 174 | const std::string& mime_type, |
| 175 | IPC::Message* reply_msg); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 176 | void OnOpenChannelToPepperPlugin(const base::FilePath& path, |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 177 | IPC::Message* reply_msg); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 178 | void OnDidCreateOutOfProcessPepperInstance( |
| 179 | int plugin_child_id, |
| 180 | int32 pp_instance, |
| 181 | PepperRendererInstanceData instance_data, |
| 182 | bool is_external); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 183 | void OnDidDeleteOutOfProcessPepperInstance(int plugin_child_id, |
| 184 | int32 pp_instance, |
| 185 | bool is_external); |
| 186 | void OnOpenChannelToPpapiBroker(int routing_id, |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 187 | const base::FilePath& path); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 188 | void OnGenerateRoutingID(int* route_id); |
| 189 | void OnDownloadUrl(const IPC::Message& message, |
| 190 | const GURL& url, |
| 191 | const Referrer& referrer, |
| 192 | const string16& suggested_name); |
| 193 | void OnCheckNotificationPermission(const GURL& source_origin, |
| 194 | int* permission_level); |
| 195 | |
| 196 | void OnGetCPUUsage(int* cpu_usage); |
| 197 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 198 | void OnGetAudioHardwareConfig(media::AudioParameters* input_params, |
| 199 | media::AudioParameters* output_params); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 200 | |
| 201 | // Used to look up the monitor color profile. |
| 202 | void OnGetMonitorColorProfile(std::vector<char>* profile); |
| 203 | |
| 204 | // Used to ask the browser to allocate a block of shared memory for the |
| 205 | // renderer to send back data in, since shared memory can't be created |
| 206 | // in the renderer on POSIX due to the sandbox. |
| 207 | void OnAllocateSharedMemory(uint32 buffer_size, |
| 208 | base::SharedMemoryHandle* handle); |
| 209 | void OnResolveProxy(const GURL& url, IPC::Message* reply_msg); |
| 210 | |
| 211 | // Browser side transport DIB allocation |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 212 | void OnAllocTransportDIB(uint32 size, |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 213 | bool cache_in_browser, |
| 214 | TransportDIB::Handle* result); |
| 215 | void OnFreeTransportDIB(TransportDIB::Id dib_id); |
| 216 | void OnCacheableMetadataAvailable(const GURL& url, |
| 217 | double expected_response_time, |
| 218 | const std::vector<char>& data); |
| 219 | void OnKeygen(uint32 key_size_index, const std::string& challenge_string, |
| 220 | const GURL& url, IPC::Message* reply_msg); |
| 221 | void OnKeygenOnWorkerThread( |
| 222 | int key_size_in_bits, |
| 223 | const std::string& challenge_string, |
| 224 | const GURL& url, |
| 225 | IPC::Message* reply_msg); |
Ben Murdoch | 2385ea3 | 2013-08-06 11:01:04 +0100 | [diff] [blame] | 226 | void OnAsyncOpenPepperFile(int routing_id, |
Torne (Richard Coles) | a36e592 | 2013-08-05 13:57:33 +0100 | [diff] [blame] | 227 | const base::FilePath& path, |
| 228 | int pp_open_flags, |
| 229 | int message_id); |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 230 | void OnMediaLogEvents(const std::vector<media::MediaLogEvent>&); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 231 | |
| 232 | // Check the policy for getting cookies. Gets the cookies if allowed. |
| 233 | void CheckPolicyForCookies(const GURL& url, |
| 234 | const GURL& first_party_for_cookies, |
| 235 | IPC::Message* reply_msg, |
| 236 | const net::CookieList& cookie_list); |
| 237 | |
| 238 | // Writes the cookies to reply messages, and sends the message. |
| 239 | // Callback functions for getting cookies from cookie store. |
| 240 | void SendGetCookiesResponse(IPC::Message* reply_msg, |
| 241 | const std::string& cookies); |
| 242 | void SendGetRawCookiesResponse(IPC::Message* reply_msg, |
| 243 | const net::CookieList& cookie_list); |
| 244 | |
| 245 | bool CheckBenchmarkingEnabled() const; |
| 246 | bool CheckPreparsedJsCachingEnabled() const; |
| 247 | void OnCompletedOpenChannelToNpapiPlugin( |
| 248 | OpenChannelToNpapiPluginCallback* client); |
| 249 | |
| 250 | void OnUpdateIsDelayed(const IPC::Message& msg); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 251 | void OnAre3DAPIsBlocked(int render_view_id, |
| 252 | const GURL& top_origin_url, |
| 253 | ThreeDAPIType requester, |
| 254 | bool* blocked); |
| 255 | void OnDidLose3DContext(const GURL& top_origin_url, |
| 256 | ThreeDAPIType context_type, |
| 257 | int arb_robustness_status_code); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 258 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 259 | #if defined(OS_ANDROID) |
| 260 | void OnWebAudioMediaCodec(base::SharedMemoryHandle encoded_data_handle, |
| 261 | base::FileDescriptor pcm_output, |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 262 | uint32_t data_size); |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 263 | #endif |
| 264 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 265 | // Cached resource request dispatcher host and plugin service, guaranteed to |
| 266 | // be non-null if Init succeeds. We do not own the objects, they are managed |
| 267 | // by the BrowserProcess, which has a wider scope than we do. |
| 268 | ResourceDispatcherHostImpl* resource_dispatcher_host_; |
| 269 | PluginServiceImpl* plugin_service_; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 270 | base::FilePath profile_data_directory_; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 271 | |
| 272 | // Contextual information to be used for requests created here. |
| 273 | scoped_refptr<net::URLRequestContextGetter> request_context_; |
| 274 | |
| 275 | // The ResourceContext which is to be used on the IO thread. |
| 276 | ResourceContext* resource_context_; |
| 277 | |
| 278 | scoped_refptr<RenderWidgetHelper> render_widget_helper_; |
| 279 | |
| 280 | // Whether this process is used for incognito contents. |
| 281 | // This doesn't belong here; http://crbug.com/89628 |
| 282 | bool incognito_; |
| 283 | |
| 284 | // Initialized to 0, accessed on FILE thread only. |
| 285 | base::TimeTicks last_plugin_refresh_time_; |
| 286 | |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 287 | scoped_refptr<DOMStorageContextWrapper> dom_storage_context_; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 288 | |
| 289 | int render_process_id_; |
| 290 | |
Ben Murdoch | 558790d | 2013-07-30 15:19:42 +0100 | [diff] [blame] | 291 | bool is_guest_; |
| 292 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 293 | std::set<OpenChannelToNpapiPluginCallback*> plugin_host_clients_; |
| 294 | |
| 295 | // Records the last time we sampled CPU usage of the renderer process. |
| 296 | base::TimeTicks cpu_usage_sample_time_; |
| 297 | // Records the last sampled CPU usage in percents. |
| 298 | int cpu_usage_; |
| 299 | // Used for sampling CPU usage of the renderer process. |
| 300 | scoped_ptr<base::ProcessMetrics> process_metrics_; |
| 301 | |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 302 | media::AudioManager* audio_manager_; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 303 | MediaInternals* media_internals_; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 304 | |
| 305 | DISALLOW_COPY_AND_ASSIGN(RenderMessageFilter); |
| 306 | }; |
| 307 | |
| 308 | } // namespace content |
| 309 | |
| 310 | #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_MESSAGE_FILTER_H_ |