OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/web_contents/web_contents_impl.h" | 5 #include "content/browser/web_contents/web_contents_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/metrics/stats_counters.h" | 11 #include "base/metrics/stats_counters.h" |
12 #include "base/string16.h" | 12 #include "base/string16.h" |
13 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
15 #include "base/sys_info.h" | 15 #include "base/sys_info.h" |
16 #include "base/time.h" | 16 #include "base/time.h" |
17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
| 18 #include "content/browser/browser_plugin/browser_plugin_embedder.h" |
| 19 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
18 #include "content/browser/browser_plugin/old/old_browser_plugin_host.h" | 20 #include "content/browser/browser_plugin/old/old_browser_plugin_host.h" |
19 #include "content/browser/child_process_security_policy_impl.h" | 21 #include "content/browser/child_process_security_policy_impl.h" |
20 #include "content/browser/debugger/devtools_manager_impl.h" | 22 #include "content/browser/debugger/devtools_manager_impl.h" |
21 #include "content/browser/dom_storage/dom_storage_context_impl.h" | 23 #include "content/browser/dom_storage/dom_storage_context_impl.h" |
22 #include "content/browser/dom_storage/session_storage_namespace_impl.h" | 24 #include "content/browser/dom_storage/session_storage_namespace_impl.h" |
23 #include "content/browser/download/download_stats.h" | 25 #include "content/browser/download/download_stats.h" |
24 #include "content/browser/download/mhtml_generation_manager.h" | 26 #include "content/browser/download/mhtml_generation_manager.h" |
25 #include "content/browser/download/save_package.h" | 27 #include "content/browser/download/save_package.h" |
26 #include "content/browser/gpu/gpu_data_manager_impl.h" | 28 #include "content/browser/gpu/gpu_data_manager_impl.h" |
27 #include "content/browser/gpu/gpu_process_host.h" | 29 #include "content/browser/gpu/gpu_process_host.h" |
28 #include "content/browser/host_zoom_map_impl.h" | 30 #include "content/browser/host_zoom_map_impl.h" |
29 #include "content/browser/intents/web_intents_dispatcher_impl.h" | 31 #include "content/browser/intents/web_intents_dispatcher_impl.h" |
30 #include "content/browser/renderer_host/render_process_host_impl.h" | 32 #include "content/browser/renderer_host/render_process_host_impl.h" |
31 #include "content/browser/renderer_host/render_view_host_impl.h" | 33 #include "content/browser/renderer_host/render_view_host_impl.h" |
32 #include "content/browser/renderer_host/render_widget_host_impl.h" | 34 #include "content/browser/renderer_host/render_widget_host_impl.h" |
33 #include "content/browser/renderer_host/resource_dispatcher_host_impl.h" | 35 #include "content/browser/renderer_host/resource_dispatcher_host_impl.h" |
34 #include "content/browser/site_instance_impl.h" | 36 #include "content/browser/site_instance_impl.h" |
35 #include "content/browser/web_contents/interstitial_page_impl.h" | 37 #include "content/browser/web_contents/interstitial_page_impl.h" |
36 #include "content/browser/web_contents/navigation_entry_impl.h" | 38 #include "content/browser/web_contents/navigation_entry_impl.h" |
37 #include "content/browser/webui/web_ui_impl.h" | 39 #include "content/browser/webui/web_ui_impl.h" |
| 40 #include "content/common/browser_plugin_messages.h" |
38 #include "content/common/intents_messages.h" | 41 #include "content/common/intents_messages.h" |
39 #include "content/common/ssl_status_serialization.h" | 42 #include "content/common/ssl_status_serialization.h" |
40 #include "content/common/view_messages.h" | 43 #include "content/common/view_messages.h" |
41 #include "content/port/browser/render_view_host_delegate_view.h" | 44 #include "content/port/browser/render_view_host_delegate_view.h" |
42 #include "content/port/browser/render_widget_host_view_port.h" | 45 #include "content/port/browser/render_widget_host_view_port.h" |
43 #include "content/public/browser/browser_context.h" | 46 #include "content/public/browser/browser_context.h" |
44 #include "content/public/browser/color_chooser.h" | 47 #include "content/public/browser/color_chooser.h" |
45 #include "content/public/browser/content_browser_client.h" | 48 #include "content/public/browser/content_browser_client.h" |
46 #include "content/public/browser/devtools_agent_host_registry.h" | 49 #include "content/public/browser/devtools_agent_host_registry.h" |
47 #include "content/public/browser/download_manager.h" | 50 #include "content/public/browser/download_manager.h" |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 int routing_id, | 419 int routing_id, |
417 const WebContentsImpl* base_web_contents, | 420 const WebContentsImpl* base_web_contents, |
418 WebContentsImpl* opener) { | 421 WebContentsImpl* opener) { |
419 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, opener); | 422 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, opener); |
420 | 423 |
421 new_contents->Init(browser_context, site_instance, routing_id, | 424 new_contents->Init(browser_context, site_instance, routing_id, |
422 static_cast<const WebContentsImpl*>(base_web_contents)); | 425 static_cast<const WebContentsImpl*>(base_web_contents)); |
423 return new_contents; | 426 return new_contents; |
424 } | 427 } |
425 | 428 |
| 429 WebContentsImpl* WebContentsImpl::CreateGuest(BrowserContext* browser_context, |
| 430 const std::string& host_url, |
| 431 int guest_instance_id) { |
| 432 // The SiteInstance of a given guest is based on the fact that it's a guest |
| 433 // in addition to which platform application the guest belongs to, rather |
| 434 // than the URL that the guest is being navigated to. |
| 435 GURL guest_site( |
| 436 base::StringPrintf("%s://%s", chrome::kGuestScheme, host_url.c_str())); |
| 437 SiteInstance* guest_site_instance = |
| 438 SiteInstance::CreateForURL(browser_context, guest_site); |
| 439 WebContentsImpl* new_contents = WebContentsImpl::Create( |
| 440 browser_context, |
| 441 guest_site_instance, |
| 442 MSG_ROUTING_NONE, |
| 443 NULL); // base WebContents |
| 444 WebContentsImpl* new_contents_impl = |
| 445 static_cast<WebContentsImpl*>(new_contents); |
| 446 |
| 447 // This makes |new_contents| act as a guest. |
| 448 // For more info, see comment above class BrowserPluginGuest. |
| 449 new_contents_impl->browser_plugin_guest_.reset( |
| 450 content::BrowserPluginGuest::Create( |
| 451 guest_instance_id, |
| 452 new_contents_impl, |
| 453 new_contents_impl->GetRenderViewHost())); |
| 454 return new_contents; |
| 455 } |
| 456 |
426 WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh, | 457 WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh, |
427 const GURL& url) { | 458 const GURL& url) { |
428 WebPreferences prefs; | 459 WebPreferences prefs; |
429 | 460 |
430 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 461 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
431 | 462 |
432 prefs.developer_extras_enabled = true; | 463 prefs.developer_extras_enabled = true; |
433 prefs.javascript_enabled = | 464 prefs.javascript_enabled = |
434 !command_line.HasSwitch(switches::kDisableJavaScript); | 465 !command_line.HasSwitch(switches::kDisableJavaScript); |
435 prefs.web_security_enabled = | 466 prefs.web_security_enabled = |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin) | 723 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin) |
693 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed) | 724 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed) |
694 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser) | 725 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser) |
695 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser) | 726 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser) |
696 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser, | 727 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser, |
697 OnSetSelectedColorInColorChooser) | 728 OnSetSelectedColorInColorChooser) |
698 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung) | 729 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung) |
699 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend) | 730 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend) |
700 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission, | 731 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission, |
701 OnRequestPpapiBrokerPermission) | 732 OnRequestPpapiBrokerPermission) |
| 733 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_NavigateGuest, |
| 734 OnBrowserPluginNavigateGuest) |
702 IPC_MESSAGE_UNHANDLED(handled = false) | 735 IPC_MESSAGE_UNHANDLED(handled = false) |
703 IPC_END_MESSAGE_MAP_EX() | 736 IPC_END_MESSAGE_MAP_EX() |
704 message_source_ = NULL; | 737 message_source_ = NULL; |
705 | 738 |
706 if (!message_is_ok) { | 739 if (!message_is_ok) { |
707 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD")); | 740 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD")); |
708 GetRenderProcessHost()->ReceivedBadMessage(); | 741 GetRenderProcessHost()->ReceivedBadMessage(); |
709 } | 742 } |
710 | 743 |
711 return handled; | 744 return handled; |
(...skipping 1591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2303 } | 2336 } |
2304 | 2337 |
2305 void WebContentsImpl::OnPpapiBrokerPermissionResult(int request_id, | 2338 void WebContentsImpl::OnPpapiBrokerPermissionResult(int request_id, |
2306 bool result) { | 2339 bool result) { |
2307 RenderViewHostImpl* rvh = GetRenderViewHostImpl(); | 2340 RenderViewHostImpl* rvh = GetRenderViewHostImpl(); |
2308 rvh->Send(new ViewMsg_PpapiBrokerPermissionResult(rvh->GetRoutingID(), | 2341 rvh->Send(new ViewMsg_PpapiBrokerPermissionResult(rvh->GetRoutingID(), |
2309 request_id, | 2342 request_id, |
2310 result)); | 2343 result)); |
2311 } | 2344 } |
2312 | 2345 |
| 2346 void WebContentsImpl::OnBrowserPluginNavigateGuest(int instance_id, |
| 2347 int64 frame_id, |
| 2348 const std::string& src, |
| 2349 const gfx::Size& size) { |
| 2350 // This is the first 'navigate' to a browser plugin, before WebContents has/is |
| 2351 // an 'Embedder'; subsequent navigate messages for this WebContents will |
| 2352 // be handled by the BrowserPluginEmbedderHelper of the embedder itself (this |
| 2353 // also means any message from browser plugin renderer prior to NavigateGuest |
| 2354 // which is not NavigateGuest will be ignored). Therefore |
| 2355 // |browser_plugin_embedder_| should not be set. |
| 2356 // For more info, see comment above classes BrowserPluginEmbedder and |
| 2357 // BrowserPluginGuest. |
| 2358 CHECK(!browser_plugin_embedder_.get()); |
| 2359 |
| 2360 browser_plugin_embedder_.reset( |
| 2361 content::BrowserPluginEmbedder::Create(this, GetRenderViewHost())); |
| 2362 browser_plugin_embedder_->NavigateGuest(GetRenderViewHost(), |
| 2363 instance_id, |
| 2364 frame_id, |
| 2365 src, |
| 2366 size); |
| 2367 } |
| 2368 |
2313 // Notifies the RenderWidgetHost instance about the fact that the page is | 2369 // Notifies the RenderWidgetHost instance about the fact that the page is |
2314 // loading, or done loading and calls the base implementation. | 2370 // loading, or done loading and calls the base implementation. |
2315 void WebContentsImpl::SetIsLoading(bool is_loading, | 2371 void WebContentsImpl::SetIsLoading(bool is_loading, |
2316 LoadNotificationDetails* details) { | 2372 LoadNotificationDetails* details) { |
2317 if (is_loading == is_loading_) | 2373 if (is_loading == is_loading_) |
2318 return; | 2374 return; |
2319 | 2375 |
2320 if (!is_loading) { | 2376 if (!is_loading) { |
2321 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16()); | 2377 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16()); |
2322 load_state_host_.clear(); | 2378 load_state_host_.clear(); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2459 | 2515 |
2460 void WebContentsImpl::NotifySwapped() { | 2516 void WebContentsImpl::NotifySwapped() { |
2461 // After sending out a swap notification, we need to send a disconnect | 2517 // After sending out a swap notification, we need to send a disconnect |
2462 // notification so that clients that pick up a pointer to |this| can NULL the | 2518 // notification so that clients that pick up a pointer to |this| can NULL the |
2463 // pointer. See Bug 1230284. | 2519 // pointer. See Bug 1230284. |
2464 notify_disconnection_ = true; | 2520 notify_disconnection_ = true; |
2465 content::NotificationService::current()->Notify( | 2521 content::NotificationService::current()->Notify( |
2466 content::NOTIFICATION_WEB_CONTENTS_SWAPPED, | 2522 content::NOTIFICATION_WEB_CONTENTS_SWAPPED, |
2467 content::Source<WebContents>(this), | 2523 content::Source<WebContents>(this), |
2468 content::NotificationService::NoDetails()); | 2524 content::NotificationService::NoDetails()); |
| 2525 |
| 2526 // Ensure that the associated embedder gets cleared after a RenderViewHost |
| 2527 // gets swapped, so we don't reuse the same embedder next time a |
| 2528 // RenderViewHost is attached to this WebContents. |
| 2529 RemoveBrowserPluginEmbedder(); |
2469 } | 2530 } |
2470 | 2531 |
2471 void WebContentsImpl::NotifyConnected() { | 2532 void WebContentsImpl::NotifyConnected() { |
2472 notify_disconnection_ = true; | 2533 notify_disconnection_ = true; |
2473 content::NotificationService::current()->Notify( | 2534 content::NotificationService::current()->Notify( |
2474 content::NOTIFICATION_WEB_CONTENTS_CONNECTED, | 2535 content::NOTIFICATION_WEB_CONTENTS_CONNECTED, |
2475 content::Source<WebContents>(this), | 2536 content::Source<WebContents>(this), |
2476 content::NotificationService::NoDetails()); | 2537 content::NotificationService::NoDetails()); |
2477 } | 2538 } |
2478 | 2539 |
(...skipping 25 matching lines...) Expand all Loading... |
2504 WebContents* WebContentsImpl::GetAsWebContents() { | 2565 WebContents* WebContentsImpl::GetAsWebContents() { |
2505 return this; | 2566 return this; |
2506 } | 2567 } |
2507 | 2568 |
2508 gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const { | 2569 gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const { |
2509 if (delegate_) | 2570 if (delegate_) |
2510 return delegate_->GetRootWindowResizerRect(); | 2571 return delegate_->GetRootWindowResizerRect(); |
2511 return gfx::Rect(); | 2572 return gfx::Rect(); |
2512 } | 2573 } |
2513 | 2574 |
| 2575 void WebContentsImpl::RemoveBrowserPluginEmbedder() { |
| 2576 if (browser_plugin_embedder_.get()) |
| 2577 browser_plugin_embedder_.reset(); |
| 2578 } |
| 2579 |
2514 void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) { | 2580 void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) { |
2515 // Don't send notifications if we are just creating a swapped-out RVH for | 2581 // Don't send notifications if we are just creating a swapped-out RVH for |
2516 // the opener chain. These won't be used for view-source or WebUI, so it's | 2582 // the opener chain. These won't be used for view-source or WebUI, so it's |
2517 // ok to return early. | 2583 // ok to return early. |
2518 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out()) | 2584 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out()) |
2519 return; | 2585 return; |
2520 | 2586 |
2521 content::NotificationService::current()->Notify( | 2587 content::NotificationService::current()->Notify( |
2522 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, | 2588 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, |
2523 content::Source<WebContents>(this), | 2589 content::Source<WebContents>(this), |
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3292 old_browser_plugin_host()->embedder_render_process_host(); | 3358 old_browser_plugin_host()->embedder_render_process_host(); |
3293 *embedder_container_id = old_browser_plugin_host()->instance_id(); | 3359 *embedder_container_id = old_browser_plugin_host()->instance_id(); |
3294 int embedder_process_id = | 3360 int embedder_process_id = |
3295 embedder_render_process_host ? embedder_render_process_host->GetID() : -1; | 3361 embedder_render_process_host ? embedder_render_process_host->GetID() : -1; |
3296 if (embedder_process_id != -1) { | 3362 if (embedder_process_id != -1) { |
3297 *embedder_channel_name = | 3363 *embedder_channel_name = |
3298 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(), | 3364 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(), |
3299 embedder_process_id); | 3365 embedder_process_id); |
3300 } | 3366 } |
3301 } | 3367 } |
| 3368 |
| 3369 content::BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() { |
| 3370 return browser_plugin_guest_.get(); |
| 3371 } |
| 3372 |
| 3373 content::BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() { |
| 3374 return browser_plugin_embedder_.get(); |
| 3375 } |
OLD | NEW |