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

Side by Side Diff: content/browser/frame_host/render_frame_host_impl.cc

Issue 2821473002: Service CreateNewWindow on the UI thread with a new mojo interface (Closed)
Patch Set: devlin review Created 3 years, 8 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 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_host_impl.h" 5 #include "content/browser/frame_host/render_frame_host_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/containers/hash_tables.h" 12 #include "base/containers/hash_tables.h"
13 #include "base/lazy_instance.h" 13 #include "base/lazy_instance.h"
14 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "base/metrics/histogram_macros.h" 15 #include "base/metrics/histogram_macros.h"
16 #include "base/metrics/user_metrics.h" 16 #include "base/metrics/user_metrics.h"
17 #include "base/process/kill.h" 17 #include "base/process/kill.h"
18 #include "base/time/time.h" 18 #include "base/time/time.h"
19 #include "build/build_config.h" 19 #include "build/build_config.h"
20 #include "content/browser/accessibility/browser_accessibility_manager.h" 20 #include "content/browser/accessibility/browser_accessibility_manager.h"
21 #include "content/browser/accessibility/browser_accessibility_state_impl.h" 21 #include "content/browser/accessibility/browser_accessibility_state_impl.h"
22 #include "content/browser/bluetooth/web_bluetooth_service_impl.h" 22 #include "content/browser/bluetooth/web_bluetooth_service_impl.h"
23 #include "content/browser/browser_main_loop.h" 23 #include "content/browser/browser_main_loop.h"
24 #include "content/browser/child_process_security_policy_impl.h" 24 #include "content/browser/child_process_security_policy_impl.h"
25 #include "content/browser/devtools/render_frame_devtools_agent_host.h" 25 #include "content/browser/devtools/render_frame_devtools_agent_host.h"
26 #include "content/browser/dom_storage/dom_storage_context_wrapper.h"
26 #include "content/browser/download/mhtml_generation_manager.h" 27 #include "content/browser/download/mhtml_generation_manager.h"
27 #include "content/browser/frame_host/cross_process_frame_connector.h" 28 #include "content/browser/frame_host/cross_process_frame_connector.h"
28 #include "content/browser/frame_host/debug_urls.h" 29 #include "content/browser/frame_host/debug_urls.h"
29 #include "content/browser/frame_host/frame_tree.h" 30 #include "content/browser/frame_host/frame_tree.h"
30 #include "content/browser/frame_host/frame_tree_node.h" 31 #include "content/browser/frame_host/frame_tree_node.h"
31 #include "content/browser/frame_host/navigation_entry_impl.h" 32 #include "content/browser/frame_host/navigation_entry_impl.h"
32 #include "content/browser/frame_host/navigation_handle_impl.h" 33 #include "content/browser/frame_host/navigation_handle_impl.h"
33 #include "content/browser/frame_host/navigation_request.h" 34 #include "content/browser/frame_host/navigation_request.h"
34 #include "content/browser/frame_host/navigator.h" 35 #include "content/browser/frame_host/navigator.h"
35 #include "content/browser/frame_host/navigator_impl.h" 36 #include "content/browser/frame_host/navigator_impl.h"
(...skipping 16 matching lines...) Expand all
52 #include "content/browser/renderer_host/render_view_host_delegate_view.h" 53 #include "content/browser/renderer_host/render_view_host_delegate_view.h"
53 #include "content/browser/renderer_host/render_view_host_impl.h" 54 #include "content/browser/renderer_host/render_view_host_impl.h"
54 #include "content/browser/renderer_host/render_widget_host_delegate.h" 55 #include "content/browser/renderer_host/render_widget_host_delegate.h"
55 #include "content/browser/renderer_host/render_widget_host_impl.h" 56 #include "content/browser/renderer_host/render_widget_host_impl.h"
56 #include "content/browser/renderer_host/render_widget_host_view_base.h" 57 #include "content/browser/renderer_host/render_widget_host_view_base.h"
57 #include "content/browser/shared_worker/shared_worker_service_impl.h" 58 #include "content/browser/shared_worker/shared_worker_service_impl.h"
58 #include "content/browser/websockets/websocket_manager.h" 59 #include "content/browser/websockets/websocket_manager.h"
59 #include "content/browser/webui/web_ui_controller_factory_registry.h" 60 #include "content/browser/webui/web_ui_controller_factory_registry.h"
60 #include "content/common/accessibility_messages.h" 61 #include "content/common/accessibility_messages.h"
61 #include "content/common/associated_interface_provider_impl.h" 62 #include "content/common/associated_interface_provider_impl.h"
63 #include "content/common/associated_interface_registry_impl.h"
62 #include "content/common/associated_interfaces.mojom.h" 64 #include "content/common/associated_interfaces.mojom.h"
63 #include "content/common/content_security_policy/content_security_policy.h" 65 #include "content/common/content_security_policy/content_security_policy.h"
64 #include "content/common/frame_messages.h" 66 #include "content/common/frame_messages.h"
65 #include "content/common/frame_owner_properties.h" 67 #include "content/common/frame_owner_properties.h"
66 #include "content/common/input_messages.h" 68 #include "content/common/input_messages.h"
67 #include "content/common/inter_process_time_ticks_converter.h" 69 #include "content/common/inter_process_time_ticks_converter.h"
68 #include "content/common/navigation_params.h" 70 #include "content/common/navigation_params.h"
69 #include "content/common/render_message_filter.mojom.h" 71 #include "content/common/render_message_filter.mojom.h"
70 #include "content/common/renderer.mojom.h" 72 #include "content/common/renderer.mojom.h"
71 #include "content/common/site_isolation_policy.h" 73 #include "content/common/site_isolation_policy.h"
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 accessibility_reset_token_(0), 389 accessibility_reset_token_(0),
388 accessibility_reset_count_(0), 390 accessibility_reset_count_(0),
389 browser_plugin_embedder_ax_tree_id_(ui::AXTreeIDRegistry::kNoAXTreeID), 391 browser_plugin_embedder_ax_tree_id_(ui::AXTreeIDRegistry::kNoAXTreeID),
390 no_create_browser_accessibility_manager_for_testing_(false), 392 no_create_browser_accessibility_manager_for_testing_(false),
391 web_ui_type_(WebUI::kNoWebUI), 393 web_ui_type_(WebUI::kNoWebUI),
392 pending_web_ui_type_(WebUI::kNoWebUI), 394 pending_web_ui_type_(WebUI::kNoWebUI),
393 should_reuse_web_ui_(false), 395 should_reuse_web_ui_(false),
394 has_selection_(false), 396 has_selection_(false),
395 last_navigation_previews_state_(PREVIEWS_UNSPECIFIED), 397 last_navigation_previews_state_(PREVIEWS_UNSPECIFIED),
396 frame_host_binding_(this), 398 frame_host_binding_(this),
399 frame_host_associated_binding_(this),
397 waiting_for_init_(renderer_initiated_creation), 400 waiting_for_init_(renderer_initiated_creation),
398 has_focused_editable_element_(false), 401 has_focused_editable_element_(false),
399 weak_ptr_factory_(this) { 402 weak_ptr_factory_(this) {
400 frame_tree_->AddRenderViewHostRef(render_view_host_); 403 frame_tree_->AddRenderViewHostRef(render_view_host_);
401 GetProcess()->AddRoute(routing_id_, this); 404 GetProcess()->AddRoute(routing_id_, this);
402 g_routing_id_frame_map.Get().insert(std::make_pair( 405 g_routing_id_frame_map.Get().insert(std::make_pair(
403 RenderFrameHostID(GetProcess()->GetID(), routing_id_), 406 RenderFrameHostID(GetProcess()->GetID(), routing_id_),
404 this)); 407 this));
405 site_instance_->AddObserver(this); 408 site_instance_->AddObserver(this);
406 GetSiteInstance()->IncrementActiveFrameCount(); 409 GetSiteInstance()->IncrementActiveFrameCount();
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 IPC_MESSAGE_HANDLER(FrameHostMsg_ShowCreatedWindow, OnShowCreatedWindow) 824 IPC_MESSAGE_HANDLER(FrameHostMsg_ShowCreatedWindow, OnShowCreatedWindow)
822 IPC_END_MESSAGE_MAP() 825 IPC_END_MESSAGE_MAP()
823 826
824 // No further actions here, since we may have been deleted. 827 // No further actions here, since we may have been deleted.
825 return handled; 828 return handled;
826 } 829 }
827 830
828 void RenderFrameHostImpl::OnAssociatedInterfaceRequest( 831 void RenderFrameHostImpl::OnAssociatedInterfaceRequest(
829 const std::string& interface_name, 832 const std::string& interface_name,
830 mojo::ScopedInterfaceEndpointHandle handle) { 833 mojo::ScopedInterfaceEndpointHandle handle) {
831 delegate_->OnAssociatedInterfaceRequest( 834 if (associated_registry_->CanBindRequest(interface_name)) {
832 this, interface_name, std::move(handle)); 835 associated_registry_->BindRequest(interface_name, std::move(handle));
836 } else {
837 delegate_->OnAssociatedInterfaceRequest(this, interface_name,
838 std::move(handle));
839 }
833 } 840 }
834 841
835 void RenderFrameHostImpl::AccessibilityPerformAction( 842 void RenderFrameHostImpl::AccessibilityPerformAction(
836 const ui::AXActionData& action_data) { 843 const ui::AXActionData& action_data) {
837 Send(new AccessibilityMsg_PerformAction(routing_id_, action_data)); 844 Send(new AccessibilityMsg_PerformAction(routing_id_, action_data));
838 } 845 }
839 846
840 bool RenderFrameHostImpl::AccessibilityViewHasFocus() const { 847 bool RenderFrameHostImpl::AccessibilityViewHasFocus() const {
841 RenderWidgetHostView* view = render_view_host_->GetWidget()->GetView(); 848 RenderWidgetHostView* view = render_view_host_->GetWidget()->GetView();
842 if (view) 849 if (view)
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
1131 GetProcess()->FilterURL(true, &validated_params->opener_security_origin); 1138 GetProcess()->FilterURL(true, &validated_params->opener_security_origin);
1132 1139
1133 // Ignore creation when sent from a frame that's not current. 1140 // Ignore creation when sent from a frame that's not current.
1134 if (frame_tree_node_->current_frame_host() == this) { 1141 if (frame_tree_node_->current_frame_host() == this) {
1135 delegate_->CreateNewWindow(GetSiteInstance(), render_view_route_id, 1142 delegate_->CreateNewWindow(GetSiteInstance(), render_view_route_id,
1136 main_frame_route_id, main_frame_widget_route_id, 1143 main_frame_route_id, main_frame_widget_route_id,
1137 *validated_params, session_storage_namespace); 1144 *validated_params, session_storage_namespace);
1138 } 1145 }
1139 1146
1140 // Our caller (RenderWidgetHelper::OnCreateNewWindowOnUI) will send 1147 // Our caller (RenderWidgetHelper::OnCreateNewWindowOnUI) will send
1141 // ViewMsg_Close if the above step did not adopt |main_frame_route_id|. 1148 // ViewMsg_Close if the above step did not adopt |main_frame_route_id|.
alexmos 2017/04/19 22:28:02 nit: update this comment.
Charlie Harrison 2017/04/20 14:02:23 Done.
1142 } 1149 }
1143 1150
1144 void RenderFrameHostImpl::SetLastCommittedOrigin(const url::Origin& origin) { 1151 void RenderFrameHostImpl::SetLastCommittedOrigin(const url::Origin& origin) {
1145 last_committed_origin_ = origin; 1152 last_committed_origin_ = origin;
1146 CSPContext::SetSelf(origin); 1153 CSPContext::SetSelf(origin);
1147 } 1154 }
1148 1155
1149 void RenderFrameHostImpl::OnDetach() { 1156 void RenderFrameHostImpl::OnDetach() {
1150 frame_tree_->RemoveFrame(frame_tree_node_); 1157 frame_tree_->RemoveFrame(frame_tree_node_);
1151 } 1158 }
(...skipping 1283 matching lines...) Expand 10 before | Expand all | Expand 10 after
2435 #endif 2442 #endif
2436 2443
2437 void RenderFrameHostImpl::OnShowCreatedWindow(int pending_widget_routing_id, 2444 void RenderFrameHostImpl::OnShowCreatedWindow(int pending_widget_routing_id,
2438 WindowOpenDisposition disposition, 2445 WindowOpenDisposition disposition,
2439 const gfx::Rect& initial_rect, 2446 const gfx::Rect& initial_rect,
2440 bool user_gesture) { 2447 bool user_gesture) {
2441 delegate_->ShowCreatedWindow(GetProcess()->GetID(), pending_widget_routing_id, 2448 delegate_->ShowCreatedWindow(GetProcess()->GetID(), pending_widget_routing_id,
2442 disposition, initial_rect, user_gesture); 2449 disposition, initial_rect, user_gesture);
2443 } 2450 }
2444 2451
2452 void RenderFrameHostImpl::CreateNewWindow(
2453 mojom::CreateNewWindowParamsPtr params,
2454 const CreateNewWindowCallback& callback) {
2455 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2456 bool no_javascript_access = false;
2457
2458 bool can_create_window = GetContentClient()->browser()->CanCreateWindow(
2459 this, params->opener_url, params->opener_top_level_frame_url,
2460 params->opener_security_origin, params->window_container_type,
2461 params->target_url, params->referrer, params->frame_name,
2462 params->disposition, *params->features, params->user_gesture,
2463 params->opener_suppressed, &no_javascript_access);
2464
2465 mojom::CreateNewWindowReplyPtr reply = mojom::CreateNewWindowReply::New();
2466 if (!can_create_window) {
2467 RunCreateWindowCompleteCallback(callback, std::move(reply),
2468 MSG_ROUTING_NONE, MSG_ROUTING_NONE,
2469 MSG_ROUTING_NONE, 0);
2470 return;
2471 }
2472
2473 // This will clone the sessionStorage for namespace_id_to_clone.
2474 DOMStorageContextWrapper* dom_storage_context =
2475 static_cast<DOMStorageContextWrapper*>(
2476 BrowserContext::GetStoragePartition(
alexmos 2017/04/19 22:28:02 nit: might be a bit more readable if you declare a
Charlie Harrison 2017/04/20 14:02:23 Done.
2477 GetSiteInstance()->GetBrowserContext(), GetSiteInstance())
2478 ->GetDOMStorageContext());
2479 scoped_refptr<SessionStorageNamespaceImpl> cloned_namespace =
2480 new SessionStorageNamespaceImpl(dom_storage_context,
2481 params->session_storage_namespace_id);
2482 reply->cloned_session_storage_namespace_id = cloned_namespace->id();
2483
2484 // If the opener is supppressed or script access is disallowed, we should
alexmos 2017/04/19 22:28:02 nit: s/supppressed/suppressed/ while you're here
Charlie Harrison 2017/04/20 14:02:23 Done.
2485 // open the window in a new BrowsingInstance, and thus a new process. That
2486 // means the current renderer process will not be able to route messages to
2487 // it. Because of this, we will immediately show and navigate the window
2488 // in OnCreateNewWindowOnUI, using the params provided here.
2489 int render_view_route_id = MSG_ROUTING_NONE;
2490 int main_frame_route_id = MSG_ROUTING_NONE;
2491 int main_frame_widget_route_id = MSG_ROUTING_NONE;
2492 if (!params->opener_suppressed && !no_javascript_access) {
2493 render_view_route_id = GetProcess()->GetNextRoutingID();
2494 main_frame_route_id = GetProcess()->GetNextRoutingID();
2495 // TODO(avi): When RenderViewHostImpl has-a RenderWidgetHostImpl, this
2496 // should be updated to give the widget a distinct routing ID.
2497 // https://crbug.com/545684
2498 main_frame_widget_route_id = render_view_route_id;
2499 // Block resource requests until the frame is created, since the HWND might
2500 // be needed if a response ends up creating a plugin. We'll only have a
2501 // single frame at this point. These requests will be resumed either in
2502 // WebContentsImpl::CreateNewWindow or RenderFrameHost::Init.
2503 // TODO(crbug.com/581037): Now that NPAPI is deprecated we should be able to
2504 // remove this, but more investigation is needed.
2505 auto block_requests_for_route = base::Bind(
2506 [](const GlobalFrameRoutingId& id) {
2507 auto* rdh = ResourceDispatcherHostImpl::Get();
2508 if (rdh)
2509 rdh->BlockRequestsForRoute(id);
2510 },
2511 GlobalFrameRoutingId(GetProcess()->GetID(), main_frame_route_id));
2512 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
2513 block_requests_for_route);
2514 }
2515
2516 DCHECK(IsRenderFrameLive());
2517 OnCreateNewWindow(render_view_route_id, main_frame_route_id,
2518 main_frame_widget_route_id, *params,
2519 cloned_namespace.get());
2520
2521 // If we did not create a WebContents to host the renderer-created
2522 // RenderFrame/RenderView/RenderWidget objects, make sure to send invalid
2523 // routing ids back to the renderer.
2524 if (main_frame_route_id != MSG_ROUTING_NONE &&
2525 RenderWidgetHost::FromID(GetProcess()->GetID(),
alexmos 2017/04/19 22:28:02 (probably also a question for nick@) There's a com
Charlie Harrison 2017/04/20 14:02:23 I re-added the DCHECKs, sorry about that!
2526 main_frame_widget_route_id) == nullptr) {
2527 RunCreateWindowCompleteCallback(callback, std::move(reply),
2528 MSG_ROUTING_NONE, MSG_ROUTING_NONE,
2529 MSG_ROUTING_NONE, 0);
2530 return;
2531 }
2532
2533 RunCreateWindowCompleteCallback(
2534 callback, std::move(reply), render_view_route_id, main_frame_route_id,
2535 main_frame_widget_route_id, cloned_namespace->id());
2536 }
2537
2538 void RenderFrameHostImpl::RunCreateWindowCompleteCallback(
2539 const CreateNewWindowCallback& callback,
2540 mojom::CreateNewWindowReplyPtr reply,
2541 int render_view_route_id,
2542 int main_frame_route_id,
2543 int main_frame_widget_route_id,
2544 int cloned_session_storage_namespace_id) {
2545 reply->route_id = render_view_route_id;
2546 reply->main_frame_route_id = main_frame_route_id;
2547 reply->main_frame_widget_route_id = main_frame_widget_route_id;
2548 reply->cloned_session_storage_namespace_id =
2549 cloned_session_storage_namespace_id;
2550 callback.Run(std::move(reply));
2551 }
2552
2445 void RenderFrameHostImpl::RegisterMojoInterfaces() { 2553 void RenderFrameHostImpl::RegisterMojoInterfaces() {
2446 device::GeolocationServiceContext* geolocation_service_context = 2554 device::GeolocationServiceContext* geolocation_service_context =
2447 delegate_ ? delegate_->GetGeolocationServiceContext() : NULL; 2555 delegate_ ? delegate_->GetGeolocationServiceContext() : NULL;
2448 2556
2449 #if !defined(OS_ANDROID) 2557 #if !defined(OS_ANDROID)
2450 // The default (no-op) implementation of InstalledAppProvider. On Android, the 2558 // The default (no-op) implementation of InstalledAppProvider. On Android, the
2451 // real implementation is provided in Java. 2559 // real implementation is provided in Java.
2452 GetInterfaceRegistry()->AddInterface( 2560 GetInterfaceRegistry()->AddInterface(
2453 base::Bind(&InstalledAppProviderImplDefault::Create)); 2561 base::Bind(&InstalledAppProviderImplDefault::Create));
2454 #endif // !defined(OS_ANDROID) 2562 #endif // !defined(OS_ANDROID)
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
2883 2991
2884 // An error page is expected to commit, hence why is_loading_ is set to true. 2992 // An error page is expected to commit, hence why is_loading_ is set to true.
2885 is_loading_ = true; 2993 is_loading_ = true;
2886 frame_tree_node_->ResetNavigationRequest(true, true); 2994 frame_tree_node_->ResetNavigationRequest(true, true);
2887 } 2995 }
2888 2996
2889 void RenderFrameHostImpl::SetUpMojoIfNeeded() { 2997 void RenderFrameHostImpl::SetUpMojoIfNeeded() {
2890 if (interface_registry_.get()) 2998 if (interface_registry_.get())
2891 return; 2999 return;
2892 3000
3001 associated_registry_ = base::MakeUnique<AssociatedInterfaceRegistryImpl>();
2893 interface_registry_ = base::MakeUnique<service_manager::InterfaceRegistry>( 3002 interface_registry_ = base::MakeUnique<service_manager::InterfaceRegistry>(
2894 mojom::kNavigation_FrameSpec); 3003 mojom::kNavigation_FrameSpec);
2895 3004
3005 auto make_binding = [](RenderFrameHostImpl* impl,
3006 mojom::FrameHostIPCAssociatedRequest request) {
3007 impl->frame_host_associated_binding_.Bind(std::move(request));
3008 };
3009 static_cast<AssociatedInterfaceRegistry*>(associated_registry_.get())
3010 ->AddInterface(base::Bind(make_binding, base::Unretained(this)));
3011
2896 ServiceManagerConnection* service_manager_connection = 3012 ServiceManagerConnection* service_manager_connection =
2897 BrowserContext::GetServiceManagerConnectionFor( 3013 BrowserContext::GetServiceManagerConnectionFor(
2898 GetProcess()->GetBrowserContext()); 3014 GetProcess()->GetBrowserContext());
2899 // |service_manager_connection| may not be set in unit tests using 3015 // |service_manager_connection| may not be set in unit tests using
2900 // TestBrowserContext. 3016 // TestBrowserContext.
2901 if (service_manager_connection) { 3017 if (service_manager_connection) {
2902 on_connect_handler_id_ = service_manager_connection->AddOnConnectHandler( 3018 on_connect_handler_id_ = service_manager_connection->AddOnConnectHandler(
2903 base::Bind(&RenderFrameHostImpl::OnRendererConnect, 3019 base::Bind(&RenderFrameHostImpl::OnRendererConnect,
2904 weak_ptr_factory_.GetWeakPtr())); 3020 weak_ptr_factory_.GetWeakPtr()));
2905 } 3021 }
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after
3664 } 3780 }
3665 3781
3666 void RenderFrameHostImpl::ForwardGetInterfaceToRenderFrame( 3782 void RenderFrameHostImpl::ForwardGetInterfaceToRenderFrame(
3667 const std::string& interface_name, 3783 const std::string& interface_name,
3668 mojo::ScopedMessagePipeHandle pipe) { 3784 mojo::ScopedMessagePipeHandle pipe) {
3669 GetRemoteInterfaces()->GetInterface(interface_name, std::move(pipe)); 3785 GetRemoteInterfaces()->GetInterface(interface_name, std::move(pipe));
3670 } 3786 }
3671 #endif 3787 #endif
3672 3788
3673 } // namespace content 3789 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698