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 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
307 ++it) { | 310 ++it) { |
308 new_contents->GetController().SetSessionStorageNamespace(it->first, | 311 new_contents->GetController().SetSessionStorageNamespace(it->first, |
309 it->second); | 312 it->second); |
310 } | 313 } |
311 | 314 |
312 new_contents->Init(browser_context, site_instance, routing_id, | 315 new_contents->Init(browser_context, site_instance, routing_id, |
313 static_cast<const WebContentsImpl*>(base_web_contents)); | 316 static_cast<const WebContentsImpl*>(base_web_contents)); |
314 return new_contents; | 317 return new_contents; |
315 } | 318 } |
316 | 319 |
320 WebContents* WebContents::CreateGuest(BrowserContext* browser_context, | |
321 const std::string& host_url, | |
322 int guest_instance_id) { | |
323 // The SiteInstance of a given guest is based on the fact that it's a guest | |
324 // in addition to which platform application the guest belongs to, rather | |
325 // than the URL that the guest is being navigated to. | |
326 GURL guest_site( | |
327 base::StringPrintf("%s://%s", chrome::kGuestScheme, host_url.c_str())); | |
328 SiteInstance* guest_site_instance = | |
329 SiteInstance::CreateForURL(browser_context, guest_site); | |
330 WebContents* new_contents = WebContents::Create( | |
331 browser_context, | |
332 guest_site_instance, | |
333 MSG_ROUTING_NONE, | |
334 NULL); // base WebContents | |
335 | |
336 static_cast<WebContentsImpl*>(new_contents)->AssignBrowserPluginGuest( | |
337 guest_instance_id); | |
awong
2012/09/09 18:08:09
You can also just do new_contents->browser_plugin_
lazyboy
2012/09/10 16:30:17
Ah
Interesting, done and removed AssignBrowserPlug
| |
338 return new_contents; | |
339 } | |
340 | |
317 WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) { | 341 WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) { |
318 return rvh->GetDelegate()->GetAsWebContents(); | 342 return rvh->GetDelegate()->GetAsWebContents(); |
319 } | 343 } |
320 | 344 |
321 } | 345 } |
322 | 346 |
323 // WebContentsImpl ------------------------------------------------------------- | 347 // WebContentsImpl ------------------------------------------------------------- |
324 | 348 |
325 WebContentsImpl::WebContentsImpl( | 349 WebContentsImpl::WebContentsImpl( |
326 content::BrowserContext* browser_context, | 350 content::BrowserContext* browser_context, |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
680 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin) | 704 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin) |
681 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed) | 705 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed) |
682 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser) | 706 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser) |
683 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser) | 707 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser) |
684 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser, | 708 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser, |
685 OnSetSelectedColorInColorChooser) | 709 OnSetSelectedColorInColorChooser) |
686 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung) | 710 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung) |
687 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend) | 711 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend) |
688 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission, | 712 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission, |
689 OnRequestPpapiBrokerPermission) | 713 OnRequestPpapiBrokerPermission) |
714 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_NavigateGuest, | |
715 OnBrowserPluginNavigateGuest) | |
690 IPC_MESSAGE_UNHANDLED(handled = false) | 716 IPC_MESSAGE_UNHANDLED(handled = false) |
691 IPC_END_MESSAGE_MAP_EX() | 717 IPC_END_MESSAGE_MAP_EX() |
692 message_source_ = NULL; | 718 message_source_ = NULL; |
693 | 719 |
694 if (!message_is_ok) { | 720 if (!message_is_ok) { |
695 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD")); | 721 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD")); |
696 GetRenderProcessHost()->ReceivedBadMessage(); | 722 GetRenderProcessHost()->ReceivedBadMessage(); |
697 } | 723 } |
698 | 724 |
699 return handled; | 725 return handled; |
(...skipping 1567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2267 } | 2293 } |
2268 | 2294 |
2269 void WebContentsImpl::OnPpapiBrokerPermissionResult(int request_id, | 2295 void WebContentsImpl::OnPpapiBrokerPermissionResult(int request_id, |
2270 bool result) { | 2296 bool result) { |
2271 RenderViewHostImpl* rvh = GetRenderViewHostImpl(); | 2297 RenderViewHostImpl* rvh = GetRenderViewHostImpl(); |
2272 rvh->Send(new ViewMsg_PpapiBrokerPermissionResult(rvh->GetRoutingID(), | 2298 rvh->Send(new ViewMsg_PpapiBrokerPermissionResult(rvh->GetRoutingID(), |
2273 request_id, | 2299 request_id, |
2274 result)); | 2300 result)); |
2275 } | 2301 } |
2276 | 2302 |
2303 void WebContentsImpl::OnBrowserPluginNavigateGuest(int instance_id, | |
2304 int64 frame_id, | |
2305 const std::string& src, | |
2306 const gfx::Size& size) { | |
2307 // This is the first 'navigate' to a browser plugin, before WebContents has/is | |
2308 // an 'Embedder'; subsequent navigate messages for this WebContents will | |
2309 // be handled by the BrowserPluginEmbedderHelper of the embedder itself (this | |
2310 // also means any message from browser plugin renderer prior to NavigateGuest | |
2311 // which is not NavigateGuest will be ignored). Therefore | |
2312 // |browser_plugin_embedder_| should not be set. | |
2313 // For more info, see comment above classes BrowserPluginEmbedder and | |
2314 // BrowserPluginGuest. | |
2315 CHECK(!browser_plugin_embedder_.get()); | |
2316 | |
2317 browser_plugin_embedder_.reset( | |
2318 content::BrowserPluginEmbedder::Create(this, GetRenderViewHost())); | |
2319 browser_plugin_embedder_->NavigateGuest(GetRenderViewHost(), | |
2320 instance_id, | |
2321 frame_id, | |
2322 src, | |
2323 size); | |
2324 } | |
2325 | |
2277 // Notifies the RenderWidgetHost instance about the fact that the page is | 2326 // Notifies the RenderWidgetHost instance about the fact that the page is |
2278 // loading, or done loading and calls the base implementation. | 2327 // loading, or done loading and calls the base implementation. |
2279 void WebContentsImpl::SetIsLoading(bool is_loading, | 2328 void WebContentsImpl::SetIsLoading(bool is_loading, |
2280 LoadNotificationDetails* details) { | 2329 LoadNotificationDetails* details) { |
2281 if (is_loading == is_loading_) | 2330 if (is_loading == is_loading_) |
2282 return; | 2331 return; |
2283 | 2332 |
2284 if (!is_loading) { | 2333 if (!is_loading) { |
2285 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16()); | 2334 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16()); |
2286 load_state_host_.clear(); | 2335 load_state_host_.clear(); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2423 | 2472 |
2424 void WebContentsImpl::NotifySwapped() { | 2473 void WebContentsImpl::NotifySwapped() { |
2425 // After sending out a swap notification, we need to send a disconnect | 2474 // After sending out a swap notification, we need to send a disconnect |
2426 // notification so that clients that pick up a pointer to |this| can NULL the | 2475 // notification so that clients that pick up a pointer to |this| can NULL the |
2427 // pointer. See Bug 1230284. | 2476 // pointer. See Bug 1230284. |
2428 notify_disconnection_ = true; | 2477 notify_disconnection_ = true; |
2429 content::NotificationService::current()->Notify( | 2478 content::NotificationService::current()->Notify( |
2430 content::NOTIFICATION_WEB_CONTENTS_SWAPPED, | 2479 content::NOTIFICATION_WEB_CONTENTS_SWAPPED, |
2431 content::Source<WebContents>(this), | 2480 content::Source<WebContents>(this), |
2432 content::NotificationService::NoDetails()); | 2481 content::NotificationService::NoDetails()); |
2482 | |
2483 // Ensure that the associated embedder gets cleared after a RenderViewHost | |
2484 // gets swapped, so we don't reuse the same embedder next time a | |
2485 // RenderViewHost is attached to this WebContents (for security concerns). | |
2486 RemoveSwappedOutBrowserPluginEmbedder(); | |
2433 } | 2487 } |
2434 | 2488 |
2435 void WebContentsImpl::NotifyConnected() { | 2489 void WebContentsImpl::NotifyConnected() { |
2436 notify_disconnection_ = true; | 2490 notify_disconnection_ = true; |
2437 content::NotificationService::current()->Notify( | 2491 content::NotificationService::current()->Notify( |
2438 content::NOTIFICATION_WEB_CONTENTS_CONNECTED, | 2492 content::NOTIFICATION_WEB_CONTENTS_CONNECTED, |
2439 content::Source<WebContents>(this), | 2493 content::Source<WebContents>(this), |
2440 content::NotificationService::NoDetails()); | 2494 content::NotificationService::NoDetails()); |
2441 } | 2495 } |
2442 | 2496 |
(...skipping 25 matching lines...) Expand all Loading... | |
2468 WebContents* WebContentsImpl::GetAsWebContents() { | 2522 WebContents* WebContentsImpl::GetAsWebContents() { |
2469 return this; | 2523 return this; |
2470 } | 2524 } |
2471 | 2525 |
2472 gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const { | 2526 gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const { |
2473 if (delegate_) | 2527 if (delegate_) |
2474 return delegate_->GetRootWindowResizerRect(); | 2528 return delegate_->GetRootWindowResizerRect(); |
2475 return gfx::Rect(); | 2529 return gfx::Rect(); |
2476 } | 2530 } |
2477 | 2531 |
2532 void WebContentsImpl::RemoveSwappedOutBrowserPluginEmbedder() { | |
2533 if (browser_plugin_embedder_.get()) | |
2534 browser_plugin_embedder_.reset(); | |
2535 } | |
2536 | |
2478 void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) { | 2537 void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) { |
2479 // Don't send notifications if we are just creating a swapped-out RVH for | 2538 // Don't send notifications if we are just creating a swapped-out RVH for |
2480 // the opener chain. These won't be used for view-source or WebUI, so it's | 2539 // the opener chain. These won't be used for view-source or WebUI, so it's |
2481 // ok to return early. | 2540 // ok to return early. |
2482 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out()) | 2541 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out()) |
2483 return; | 2542 return; |
2484 | 2543 |
2485 content::NotificationService::current()->Notify( | 2544 content::NotificationService::current()->Notify( |
2486 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, | 2545 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, |
2487 content::Source<WebContents>(this), | 2546 content::Source<WebContents>(this), |
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3256 old_browser_plugin_host()->embedder_render_process_host(); | 3315 old_browser_plugin_host()->embedder_render_process_host(); |
3257 *embedder_container_id = old_browser_plugin_host()->instance_id(); | 3316 *embedder_container_id = old_browser_plugin_host()->instance_id(); |
3258 int embedder_process_id = | 3317 int embedder_process_id = |
3259 embedder_render_process_host ? embedder_render_process_host->GetID() : -1; | 3318 embedder_render_process_host ? embedder_render_process_host->GetID() : -1; |
3260 if (embedder_process_id != -1) { | 3319 if (embedder_process_id != -1) { |
3261 *embedder_channel_name = | 3320 *embedder_channel_name = |
3262 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(), | 3321 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(), |
3263 embedder_process_id); | 3322 embedder_process_id); |
3264 } | 3323 } |
3265 } | 3324 } |
3325 | |
3326 content::BrowserPluginGuest* WebContentsImpl::AssignBrowserPluginGuest( | |
3327 int instance_id) { | |
3328 // This makes this WebContents to have a guest role. | |
3329 // For more info, see comment above class BrowserPluginGuest. | |
3330 browser_plugin_guest_.reset(content::BrowserPluginGuest::Create( | |
3331 instance_id, this, GetRenderViewHost())); | |
3332 return browser_plugin_guest_.get(); | |
3333 } | |
3334 | |
3335 content::BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() { | |
3336 return browser_plugin_guest_.get(); | |
3337 } | |
3338 | |
3339 content::BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() { | |
3340 return browser_plugin_embedder_.get(); | |
3341 } | |
OLD | NEW |