Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: content/browser/web_contents/web_contents_impl.cc

Issue 10868012: Browser Plugin: New Implementation (Browser Side) (Closed) Base URL: http://git.chromium.org/chromium/src.git@master-trial-obrowser
Patch Set: Remove TestTimeoutTracker and wait indefinitely in tests instead, fix one include. Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin) 718 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
688 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed) 719 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
689 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser) 720 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
690 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser) 721 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
691 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser, 722 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
692 OnSetSelectedColorInColorChooser) 723 OnSetSelectedColorInColorChooser)
693 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung) 724 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung)
694 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend) 725 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
695 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission, 726 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
696 OnRequestPpapiBrokerPermission) 727 OnRequestPpapiBrokerPermission)
728 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_NavigateGuest,
729 OnBrowserPluginNavigateGuest)
697 IPC_MESSAGE_UNHANDLED(handled = false) 730 IPC_MESSAGE_UNHANDLED(handled = false)
698 IPC_END_MESSAGE_MAP_EX() 731 IPC_END_MESSAGE_MAP_EX()
699 message_source_ = NULL; 732 message_source_ = NULL;
700 733
701 if (!message_is_ok) { 734 if (!message_is_ok) {
702 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD")); 735 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
703 GetRenderProcessHost()->ReceivedBadMessage(); 736 GetRenderProcessHost()->ReceivedBadMessage();
704 } 737 }
705 738
706 return handled; 739 return handled;
(...skipping 1591 matching lines...) Expand 10 before | Expand all | Expand 10 after
2298 } 2331 }
2299 2332
2300 void WebContentsImpl::OnPpapiBrokerPermissionResult(int request_id, 2333 void WebContentsImpl::OnPpapiBrokerPermissionResult(int request_id,
2301 bool result) { 2334 bool result) {
2302 RenderViewHostImpl* rvh = GetRenderViewHostImpl(); 2335 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
2303 rvh->Send(new ViewMsg_PpapiBrokerPermissionResult(rvh->GetRoutingID(), 2336 rvh->Send(new ViewMsg_PpapiBrokerPermissionResult(rvh->GetRoutingID(),
2304 request_id, 2337 request_id,
2305 result)); 2338 result));
2306 } 2339 }
2307 2340
2341 void WebContentsImpl::OnBrowserPluginNavigateGuest(int instance_id,
2342 int64 frame_id,
2343 const std::string& src,
2344 const gfx::Size& size) {
2345 // This is the first 'navigate' to a browser plugin, before WebContents has/is
2346 // an 'Embedder'; subsequent navigate messages for this WebContents will
2347 // be handled by the BrowserPluginEmbedderHelper of the embedder itself (this
2348 // also means any message from browser plugin renderer prior to NavigateGuest
2349 // which is not NavigateGuest will be ignored). Therefore
2350 // |browser_plugin_embedder_| should not be set.
2351 // For more info, see comment above classes BrowserPluginEmbedder and
2352 // BrowserPluginGuest.
2353 CHECK(!browser_plugin_embedder_.get());
2354
2355 browser_plugin_embedder_.reset(
2356 content::BrowserPluginEmbedder::Create(this, GetRenderViewHost()));
2357 browser_plugin_embedder_->NavigateGuest(GetRenderViewHost(),
2358 instance_id,
2359 frame_id,
2360 src,
2361 size);
2362 }
2363
2308 // Notifies the RenderWidgetHost instance about the fact that the page is 2364 // Notifies the RenderWidgetHost instance about the fact that the page is
2309 // loading, or done loading and calls the base implementation. 2365 // loading, or done loading and calls the base implementation.
2310 void WebContentsImpl::SetIsLoading(bool is_loading, 2366 void WebContentsImpl::SetIsLoading(bool is_loading,
2311 LoadNotificationDetails* details) { 2367 LoadNotificationDetails* details) {
2312 if (is_loading == is_loading_) 2368 if (is_loading == is_loading_)
2313 return; 2369 return;
2314 2370
2315 if (!is_loading) { 2371 if (!is_loading) {
2316 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16()); 2372 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
2317 load_state_host_.clear(); 2373 load_state_host_.clear();
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
2454 2510
2455 void WebContentsImpl::NotifySwapped() { 2511 void WebContentsImpl::NotifySwapped() {
2456 // After sending out a swap notification, we need to send a disconnect 2512 // After sending out a swap notification, we need to send a disconnect
2457 // notification so that clients that pick up a pointer to |this| can NULL the 2513 // notification so that clients that pick up a pointer to |this| can NULL the
2458 // pointer. See Bug 1230284. 2514 // pointer. See Bug 1230284.
2459 notify_disconnection_ = true; 2515 notify_disconnection_ = true;
2460 content::NotificationService::current()->Notify( 2516 content::NotificationService::current()->Notify(
2461 content::NOTIFICATION_WEB_CONTENTS_SWAPPED, 2517 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
2462 content::Source<WebContents>(this), 2518 content::Source<WebContents>(this),
2463 content::NotificationService::NoDetails()); 2519 content::NotificationService::NoDetails());
2520
2521 // Ensure that the associated embedder gets cleared after a RenderViewHost
2522 // gets swapped, so we don't reuse the same embedder next time a
2523 // RenderViewHost is attached to this WebContents.
2524 RemoveBrowserPluginEmbedder();
2464 } 2525 }
2465 2526
2466 void WebContentsImpl::NotifyConnected() { 2527 void WebContentsImpl::NotifyConnected() {
2467 notify_disconnection_ = true; 2528 notify_disconnection_ = true;
2468 content::NotificationService::current()->Notify( 2529 content::NotificationService::current()->Notify(
2469 content::NOTIFICATION_WEB_CONTENTS_CONNECTED, 2530 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
2470 content::Source<WebContents>(this), 2531 content::Source<WebContents>(this),
2471 content::NotificationService::NoDetails()); 2532 content::NotificationService::NoDetails());
2472 } 2533 }
2473 2534
(...skipping 25 matching lines...) Expand all
2499 WebContents* WebContentsImpl::GetAsWebContents() { 2560 WebContents* WebContentsImpl::GetAsWebContents() {
2500 return this; 2561 return this;
2501 } 2562 }
2502 2563
2503 gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const { 2564 gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
2504 if (delegate_) 2565 if (delegate_)
2505 return delegate_->GetRootWindowResizerRect(); 2566 return delegate_->GetRootWindowResizerRect();
2506 return gfx::Rect(); 2567 return gfx::Rect();
2507 } 2568 }
2508 2569
2570 void WebContentsImpl::RemoveBrowserPluginEmbedder() {
2571 if (browser_plugin_embedder_.get())
2572 browser_plugin_embedder_.reset();
2573 }
2574
2509 void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) { 2575 void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
2510 // Don't send notifications if we are just creating a swapped-out RVH for 2576 // Don't send notifications if we are just creating a swapped-out RVH for
2511 // the opener chain. These won't be used for view-source or WebUI, so it's 2577 // the opener chain. These won't be used for view-source or WebUI, so it's
2512 // ok to return early. 2578 // ok to return early.
2513 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out()) 2579 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2514 return; 2580 return;
2515 2581
2516 content::NotificationService::current()->Notify( 2582 content::NotificationService::current()->Notify(
2517 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, 2583 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
2518 content::Source<WebContents>(this), 2584 content::Source<WebContents>(this),
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after
3287 old_browser_plugin_host()->embedder_render_process_host(); 3353 old_browser_plugin_host()->embedder_render_process_host();
3288 *embedder_container_id = old_browser_plugin_host()->instance_id(); 3354 *embedder_container_id = old_browser_plugin_host()->instance_id();
3289 int embedder_process_id = 3355 int embedder_process_id =
3290 embedder_render_process_host ? embedder_render_process_host->GetID() : -1; 3356 embedder_render_process_host ? embedder_render_process_host->GetID() : -1;
3291 if (embedder_process_id != -1) { 3357 if (embedder_process_id != -1) {
3292 *embedder_channel_name = 3358 *embedder_channel_name =
3293 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(), 3359 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(),
3294 embedder_process_id); 3360 embedder_process_id);
3295 } 3361 }
3296 } 3362 }
3363
3364 content::BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() {
3365 return browser_plugin_guest_.get();
3366 }
3367
3368 content::BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() {
3369 return browser_plugin_embedder_.get();
3370 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698