| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/frame_host/render_frame_message_filter.h" | 5 #include "content/browser/frame_host/render_frame_message_filter.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "content/browser/bad_message.h" | 12 #include "content/browser/bad_message.h" |
| 13 #include "content/browser/blob_storage/chrome_blob_storage_context.h" |
| 13 #include "content/browser/child_process_security_policy_impl.h" | 14 #include "content/browser/child_process_security_policy_impl.h" |
| 15 #include "content/browser/download/download_stats.h" |
| 14 #include "content/browser/frame_host/render_frame_host_impl.h" | 16 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 15 #include "content/browser/gpu/gpu_data_manager_impl.h" | 17 #include "content/browser/gpu/gpu_data_manager_impl.h" |
| 16 #include "content/browser/renderer_host/render_widget_helper.h" | 18 #include "content/browser/renderer_host/render_widget_helper.h" |
| 19 #include "content/browser/resource_context_impl.h" |
| 20 #include "content/common/content_constants_internal.h" |
| 17 #include "content/common/frame_messages.h" | 21 #include "content/common/frame_messages.h" |
| 18 #include "content/common/view_messages.h" | 22 #include "content/common/view_messages.h" |
| 19 #include "content/public/browser/browser_context.h" | 23 #include "content/public/browser/browser_context.h" |
| 20 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 25 #include "content/public/browser/download_manager.h" |
| 26 #include "content/public/browser/download_url_parameters.h" |
| 21 #include "content/public/common/content_constants.h" | 27 #include "content/public/common/content_constants.h" |
| 22 #include "content/public/common/content_switches.h" | 28 #include "content/public/common/content_switches.h" |
| 23 #include "gpu/GLES2/gl2extchromium.h" | 29 #include "gpu/GLES2/gl2extchromium.h" |
| 24 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 30 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 25 #include "net/cookies/cookie_options.h" | 31 #include "net/cookies/cookie_options.h" |
| 26 #include "net/cookies/cookie_store.h" | 32 #include "net/cookies/cookie_store.h" |
| 27 #include "net/url_request/url_request_context.h" | 33 #include "net/url_request/url_request_context.h" |
| 28 #include "net/url_request/url_request_context_getter.h" | 34 #include "net/url_request/url_request_context_getter.h" |
| 35 #include "storage/browser/blob/blob_storage_context.h" |
| 29 #include "url/gurl.h" | 36 #include "url/gurl.h" |
| 30 | 37 |
| 31 #if !defined(OS_MACOSX) | 38 #if !defined(OS_MACOSX) |
| 32 #include "third_party/khronos/GLES2/gl2.h" | 39 #include "third_party/khronos/GLES2/gl2.h" |
| 33 #include "third_party/khronos/GLES2/gl2ext.h" | 40 #include "third_party/khronos/GLES2/gl2ext.h" |
| 34 #endif | 41 #endif |
| 35 | 42 |
| 36 #if defined(ENABLE_PLUGINS) | 43 #if defined(ENABLE_PLUGINS) |
| 37 #include "content/browser/plugin_service_impl.h" | 44 #include "content/browser/plugin_service_impl.h" |
| 38 #include "content/browser/ppapi_plugin_process_host.h" | 45 #include "content/browser/ppapi_plugin_process_host.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 63 RenderFrameHostImpl::FromID(process_id, parent_routing_id); | 70 RenderFrameHostImpl::FromID(process_id, parent_routing_id); |
| 64 // Handles the RenderFrameHost being deleted on the UI thread while | 71 // Handles the RenderFrameHost being deleted on the UI thread while |
| 65 // processing a subframe creation message. | 72 // processing a subframe creation message. |
| 66 if (render_frame_host) { | 73 if (render_frame_host) { |
| 67 render_frame_host->OnCreateChildFrame(new_routing_id, scope, frame_name, | 74 render_frame_host->OnCreateChildFrame(new_routing_id, scope, frame_name, |
| 68 frame_unique_name, sandbox_flags, | 75 frame_unique_name, sandbox_flags, |
| 69 frame_owner_properties); | 76 frame_owner_properties); |
| 70 } | 77 } |
| 71 } | 78 } |
| 72 | 79 |
| 80 void DownloadUrlOnUIThread(std::unique_ptr<DownloadUrlParameters> parameters) { |
| 81 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 82 |
| 83 RenderProcessHost* render_process_host = |
| 84 RenderProcessHost::FromID(parameters->render_process_host_id()); |
| 85 if (!render_process_host) |
| 86 return; |
| 87 |
| 88 BrowserContext* browser_context = render_process_host->GetBrowserContext(); |
| 89 DownloadManager* download_manager = |
| 90 BrowserContext::GetDownloadManager(browser_context); |
| 91 RecordDownloadSource(INITIATED_BY_RENDERER); |
| 92 download_manager->DownloadUrl(std::move(parameters)); |
| 93 } |
| 94 |
| 73 // Common functionality for converting a sync renderer message to a callback | 95 // Common functionality for converting a sync renderer message to a callback |
| 74 // function in the browser. Derive from this, create it on the heap when | 96 // function in the browser. Derive from this, create it on the heap when |
| 75 // issuing your callback. When done, write your reply parameters into | 97 // issuing your callback. When done, write your reply parameters into |
| 76 // reply_msg(), and then call SendReplyAndDeleteThis(). | 98 // reply_msg(), and then call SendReplyAndDeleteThis(). |
| 77 class RenderMessageCompletionCallback { | 99 class RenderMessageCompletionCallback { |
| 78 public: | 100 public: |
| 79 RenderMessageCompletionCallback(RenderFrameMessageFilter* filter, | 101 RenderMessageCompletionCallback(RenderFrameMessageFilter* filter, |
| 80 IPC::Message* reply_msg) | 102 IPC::Message* reply_msg) |
| 81 : filter_(filter), | 103 : filter_(filter), |
| 82 reply_msg_(reply_msg) { | 104 reply_msg_(reply_msg) { |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 222 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 201 } | 223 } |
| 202 | 224 |
| 203 bool RenderFrameMessageFilter::OnMessageReceived(const IPC::Message& message) { | 225 bool RenderFrameMessageFilter::OnMessageReceived(const IPC::Message& message) { |
| 204 bool handled = true; | 226 bool handled = true; |
| 205 IPC_BEGIN_MESSAGE_MAP(RenderFrameMessageFilter, message) | 227 IPC_BEGIN_MESSAGE_MAP(RenderFrameMessageFilter, message) |
| 206 IPC_MESSAGE_HANDLER(FrameHostMsg_CreateChildFrame, OnCreateChildFrame) | 228 IPC_MESSAGE_HANDLER(FrameHostMsg_CreateChildFrame, OnCreateChildFrame) |
| 207 IPC_MESSAGE_HANDLER(FrameHostMsg_SetCookie, OnSetCookie) | 229 IPC_MESSAGE_HANDLER(FrameHostMsg_SetCookie, OnSetCookie) |
| 208 IPC_MESSAGE_HANDLER_DELAY_REPLY(FrameHostMsg_GetCookies, OnGetCookies) | 230 IPC_MESSAGE_HANDLER_DELAY_REPLY(FrameHostMsg_GetCookies, OnGetCookies) |
| 209 IPC_MESSAGE_HANDLER(FrameHostMsg_CookiesEnabled, OnCookiesEnabled) | 231 IPC_MESSAGE_HANDLER(FrameHostMsg_CookiesEnabled, OnCookiesEnabled) |
| 232 IPC_MESSAGE_HANDLER(FrameHostMsg_DownloadUrl, OnDownloadUrl) |
| 233 IPC_MESSAGE_HANDLER(FrameHostMsg_SaveImageFromDataURL, |
| 234 OnSaveImageFromDataURL) |
| 210 IPC_MESSAGE_HANDLER(FrameHostMsg_Are3DAPIsBlocked, OnAre3DAPIsBlocked) | 235 IPC_MESSAGE_HANDLER(FrameHostMsg_Are3DAPIsBlocked, OnAre3DAPIsBlocked) |
| 211 IPC_MESSAGE_HANDLER_GENERIC(FrameHostMsg_RenderProcessGone, | 236 IPC_MESSAGE_HANDLER_GENERIC(FrameHostMsg_RenderProcessGone, |
| 212 OnRenderProcessGone()) | 237 OnRenderProcessGone()) |
| 213 #if defined(ENABLE_PLUGINS) | 238 #if defined(ENABLE_PLUGINS) |
| 214 IPC_MESSAGE_HANDLER_DELAY_REPLY(FrameHostMsg_GetPlugins, OnGetPlugins) | 239 IPC_MESSAGE_HANDLER_DELAY_REPLY(FrameHostMsg_GetPlugins, OnGetPlugins) |
| 215 IPC_MESSAGE_HANDLER(FrameHostMsg_GetPluginInfo, OnGetPluginInfo) | 240 IPC_MESSAGE_HANDLER(FrameHostMsg_GetPluginInfo, OnGetPluginInfo) |
| 216 IPC_MESSAGE_HANDLER_DELAY_REPLY(FrameHostMsg_OpenChannelToPepperPlugin, | 241 IPC_MESSAGE_HANDLER_DELAY_REPLY(FrameHostMsg_OpenChannelToPepperPlugin, |
| 217 OnOpenChannelToPepperPlugin) | 242 OnOpenChannelToPepperPlugin) |
| 218 IPC_MESSAGE_HANDLER(FrameHostMsg_DidCreateOutOfProcessPepperInstance, | 243 IPC_MESSAGE_HANDLER(FrameHostMsg_DidCreateOutOfProcessPepperInstance, |
| 219 OnDidCreateOutOfProcessPepperInstance) | 244 OnDidCreateOutOfProcessPepperInstance) |
| 220 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDeleteOutOfProcessPepperInstance, | 245 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDeleteOutOfProcessPepperInstance, |
| 221 OnDidDeleteOutOfProcessPepperInstance) | 246 OnDidDeleteOutOfProcessPepperInstance) |
| 222 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenChannelToPpapiBroker, | 247 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenChannelToPpapiBroker, |
| 223 OnOpenChannelToPpapiBroker) | 248 OnOpenChannelToPpapiBroker) |
| 224 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginInstanceThrottleStateChange, | 249 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginInstanceThrottleStateChange, |
| 225 OnPluginInstanceThrottleStateChange) | 250 OnPluginInstanceThrottleStateChange) |
| 226 #endif // ENABLE_PLUGINS | 251 #endif // ENABLE_PLUGINS |
| 227 IPC_MESSAGE_UNHANDLED(handled = false) | 252 IPC_MESSAGE_UNHANDLED(handled = false) |
| 228 IPC_END_MESSAGE_MAP() | 253 IPC_END_MESSAGE_MAP() |
| 229 | 254 |
| 230 return handled; | 255 return handled; |
| 231 } | 256 } |
| 232 | 257 |
| 258 void RenderFrameMessageFilter::DownloadUrl(int render_view_id, |
| 259 int render_frame_id, |
| 260 const GURL& url, |
| 261 const Referrer& referrer, |
| 262 const base::string16& suggested_name, |
| 263 const bool use_prompt) const { |
| 264 if (!resource_context_) |
| 265 return; |
| 266 |
| 267 std::unique_ptr<DownloadUrlParameters> parameters( |
| 268 new DownloadUrlParameters(url, render_process_id_, render_view_id, |
| 269 render_frame_id, request_context_.get())); |
| 270 parameters->set_content_initiated(true); |
| 271 parameters->set_suggested_name(suggested_name); |
| 272 parameters->set_prompt(use_prompt); |
| 273 parameters->set_referrer(referrer); |
| 274 |
| 275 if (url.SchemeIsBlob()) { |
| 276 ChromeBlobStorageContext* blob_context = |
| 277 GetChromeBlobStorageContextForResourceContext(resource_context_); |
| 278 parameters->set_blob_data_handle( |
| 279 blob_context->context()->GetBlobDataFromPublicURL(url)); |
| 280 // Don't care if the above fails. We are going to let the download go |
| 281 // through and allow it to be interrupted so that the embedder can deal. |
| 282 } |
| 283 |
| 284 BrowserThread::PostTask( |
| 285 BrowserThread::UI, FROM_HERE, |
| 286 base::Bind(&DownloadUrlOnUIThread, base::Passed(¶meters))); |
| 287 } |
| 288 |
| 233 void RenderFrameMessageFilter::OnCreateChildFrame( | 289 void RenderFrameMessageFilter::OnCreateChildFrame( |
| 234 const FrameHostMsg_CreateChildFrame_Params& params, | 290 const FrameHostMsg_CreateChildFrame_Params& params, |
| 235 int* new_routing_id) { | 291 int* new_routing_id) { |
| 236 *new_routing_id = render_widget_helper_->GetNextRoutingID(); | 292 *new_routing_id = render_widget_helper_->GetNextRoutingID(); |
| 237 BrowserThread::PostTask( | 293 BrowserThread::PostTask( |
| 238 BrowserThread::UI, FROM_HERE, | 294 BrowserThread::UI, FROM_HERE, |
| 239 base::Bind(&CreateChildFrameOnUI, render_process_id_, | 295 base::Bind(&CreateChildFrameOnUI, render_process_id_, |
| 240 params.parent_routing_id, params.scope, params.frame_name, | 296 params.parent_routing_id, params.scope, params.frame_name, |
| 241 params.frame_unique_name, params.sandbox_flags, | 297 params.frame_unique_name, params.sandbox_flags, |
| 242 params.frame_owner_properties, *new_routing_id)); | 298 params.frame_owner_properties, *new_routing_id)); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 } | 404 } |
| 349 } | 405 } |
| 350 | 406 |
| 351 void RenderFrameMessageFilter::SendGetCookiesResponse( | 407 void RenderFrameMessageFilter::SendGetCookiesResponse( |
| 352 IPC::Message* reply_msg, | 408 IPC::Message* reply_msg, |
| 353 const std::string& cookies) { | 409 const std::string& cookies) { |
| 354 FrameHostMsg_GetCookies::WriteReplyParams(reply_msg, cookies); | 410 FrameHostMsg_GetCookies::WriteReplyParams(reply_msg, cookies); |
| 355 Send(reply_msg); | 411 Send(reply_msg); |
| 356 } | 412 } |
| 357 | 413 |
| 414 void RenderFrameMessageFilter::OnDownloadUrl( |
| 415 int render_view_id, |
| 416 int render_frame_id, |
| 417 const GURL& url, |
| 418 const Referrer& referrer, |
| 419 const base::string16& suggested_name) { |
| 420 DownloadUrl(render_view_id, render_frame_id, url, referrer, suggested_name, |
| 421 false); |
| 422 } |
| 423 |
| 424 void RenderFrameMessageFilter::OnSaveImageFromDataURL( |
| 425 int render_view_id, |
| 426 int render_frame_id, |
| 427 const std::string& url_str) { |
| 428 // Please refer to RenderFrameImpl::saveImageFromDataURL(). |
| 429 if (url_str.length() >= kMaxLengthOfDataURLString) |
| 430 return; |
| 431 |
| 432 GURL data_url(url_str); |
| 433 if (!data_url.is_valid() || !data_url.SchemeIs(url::kDataScheme)) |
| 434 return; |
| 435 |
| 436 DownloadUrl(render_view_id, render_frame_id, data_url, Referrer(), |
| 437 base::string16(), true); |
| 438 } |
| 439 |
| 358 void RenderFrameMessageFilter::OnAre3DAPIsBlocked(int render_frame_id, | 440 void RenderFrameMessageFilter::OnAre3DAPIsBlocked(int render_frame_id, |
| 359 const GURL& top_origin_url, | 441 const GURL& top_origin_url, |
| 360 ThreeDAPIType requester, | 442 ThreeDAPIType requester, |
| 361 bool* blocked) { | 443 bool* blocked) { |
| 362 *blocked = GpuDataManagerImpl::GetInstance()->Are3DAPIsBlocked( | 444 *blocked = GpuDataManagerImpl::GetInstance()->Are3DAPIsBlocked( |
| 363 top_origin_url, render_process_id_, render_frame_id, requester); | 445 top_origin_url, render_process_id_, render_frame_id, requester); |
| 364 } | 446 } |
| 365 | 447 |
| 366 void RenderFrameMessageFilter::OnRenderProcessGone() { | 448 void RenderFrameMessageFilter::OnRenderProcessGone() { |
| 367 // FrameHostMessage_RenderProcessGone is a synthetic IPC message used by | 449 // FrameHostMessage_RenderProcessGone is a synthetic IPC message used by |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 net::URLRequestContext* context = | 601 net::URLRequestContext* context = |
| 520 GetContentClient()->browser()->OverrideRequestContextForURL( | 602 GetContentClient()->browser()->OverrideRequestContextForURL( |
| 521 url, resource_context_); | 603 url, resource_context_); |
| 522 if (!context) | 604 if (!context) |
| 523 context = request_context_->GetURLRequestContext(); | 605 context = request_context_->GetURLRequestContext(); |
| 524 | 606 |
| 525 return context; | 607 return context; |
| 526 } | 608 } |
| 527 | 609 |
| 528 } // namespace content | 610 } // namespace content |
| OLD | NEW |