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_host_impl.h" | 5 #include "content/browser/frame_host/render_frame_host_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 #include "content/public/browser/user_metrics.h" | 74 #include "content/public/browser/user_metrics.h" |
75 #include "content/public/common/browser_side_navigation_policy.h" | 75 #include "content/public/common/browser_side_navigation_policy.h" |
76 #include "content/public/common/content_constants.h" | 76 #include "content/public/common/content_constants.h" |
77 #include "content/public/common/content_switches.h" | 77 #include "content/public/common/content_switches.h" |
78 #include "content/public/common/file_chooser_file_info.h" | 78 #include "content/public/common/file_chooser_file_info.h" |
79 #include "content/public/common/file_chooser_params.h" | 79 #include "content/public/common/file_chooser_params.h" |
80 #include "content/public/common/isolated_world_ids.h" | 80 #include "content/public/common/isolated_world_ids.h" |
81 #include "content/public/common/url_constants.h" | 81 #include "content/public/common/url_constants.h" |
82 #include "content/public/common/url_utils.h" | 82 #include "content/public/common/url_utils.h" |
83 #include "device/vibration/vibration_manager_impl.h" | 83 #include "device/vibration/vibration_manager_impl.h" |
| 84 #include "services/shell/public/cpp/interface_provider.h" |
84 #include "ui/accessibility/ax_tree.h" | 85 #include "ui/accessibility/ax_tree.h" |
85 #include "ui/accessibility/ax_tree_update.h" | 86 #include "ui/accessibility/ax_tree_update.h" |
86 #include "ui/gfx/geometry/quad_f.h" | 87 #include "ui/gfx/geometry/quad_f.h" |
87 #include "url/gurl.h" | 88 #include "url/gurl.h" |
88 | 89 |
89 #if defined(OS_ANDROID) | 90 #if defined(OS_ANDROID) |
90 #include "content/browser/mojo/service_registrar_android.h" | 91 #include "content/browser/mojo/service_registrar_android.h" |
91 #endif | 92 #endif |
92 | 93 |
93 #if defined(OS_MACOSX) | 94 #if defined(OS_MACOSX) |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 } | 465 } |
465 | 466 |
466 void RenderFrameHostImpl::SaveImageAt(int x, int y) { | 467 void RenderFrameHostImpl::SaveImageAt(int x, int y) { |
467 Send(new FrameMsg_SaveImageAt(routing_id_, x, y)); | 468 Send(new FrameMsg_SaveImageAt(routing_id_, x, y)); |
468 } | 469 } |
469 | 470 |
470 RenderViewHost* RenderFrameHostImpl::GetRenderViewHost() { | 471 RenderViewHost* RenderFrameHostImpl::GetRenderViewHost() { |
471 return render_view_host_; | 472 return render_view_host_; |
472 } | 473 } |
473 | 474 |
474 ServiceRegistry* RenderFrameHostImpl::GetServiceRegistry() { | 475 shell::InterfaceRegistry* RenderFrameHostImpl::GetInterfaceRegistry() { |
475 return service_registry_.get(); | 476 return interface_registry_.get(); |
| 477 } |
| 478 |
| 479 shell::InterfaceProvider* RenderFrameHostImpl::GetRemoteInterfaces() { |
| 480 return remote_interfaces_.get(); |
476 } | 481 } |
477 | 482 |
478 blink::WebPageVisibilityState RenderFrameHostImpl::GetVisibilityState() { | 483 blink::WebPageVisibilityState RenderFrameHostImpl::GetVisibilityState() { |
479 // Works around the crashes seen in https://crbug.com/501863, where the | 484 // Works around the crashes seen in https://crbug.com/501863, where the |
480 // active WebContents from a browser iterator may contain a render frame | 485 // active WebContents from a browser iterator may contain a render frame |
481 // detached from the frame tree. This tries to find a RenderWidgetHost | 486 // detached from the frame tree. This tries to find a RenderWidgetHost |
482 // attached to an ancestor frame, and defaults to visibility hidden if | 487 // attached to an ancestor frame, and defaults to visibility hidden if |
483 // it fails. | 488 // it fails. |
484 // TODO(yfriedman, peter): Ideally this would never be called on an | 489 // TODO(yfriedman, peter): Ideally this would never be called on an |
485 // unattached frame and we could omit this check. See | 490 // unattached frame and we could omit this check. See |
(...skipping 1499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1985 } | 1990 } |
1986 | 1991 |
1987 void RenderFrameHostImpl::OnHidePopup() { | 1992 void RenderFrameHostImpl::OnHidePopup() { |
1988 RenderViewHostDelegateView* view = | 1993 RenderViewHostDelegateView* view = |
1989 render_view_host_->delegate_->GetDelegateView(); | 1994 render_view_host_->delegate_->GetDelegateView(); |
1990 if (view) | 1995 if (view) |
1991 view->HidePopupMenu(); | 1996 view->HidePopupMenu(); |
1992 } | 1997 } |
1993 #endif | 1998 #endif |
1994 | 1999 |
1995 void RenderFrameHostImpl::RegisterMojoServices() { | 2000 void RenderFrameHostImpl::RegisterMojoInterfaces() { |
1996 GeolocationServiceContext* geolocation_service_context = | 2001 GeolocationServiceContext* geolocation_service_context = |
1997 delegate_ ? delegate_->GetGeolocationServiceContext() : NULL; | 2002 delegate_ ? delegate_->GetGeolocationServiceContext() : NULL; |
1998 if (geolocation_service_context) { | 2003 if (geolocation_service_context) { |
1999 // TODO(creis): Bind process ID here so that GeolocationServiceImpl | 2004 // TODO(creis): Bind process ID here so that GeolocationServiceImpl |
2000 // can perform permissions checks once site isolation is complete. | 2005 // can perform permissions checks once site isolation is complete. |
2001 // crbug.com/426384 | 2006 // crbug.com/426384 |
2002 // NOTE: At shutdown, there is no guaranteed ordering between destruction of | 2007 // NOTE: At shutdown, there is no guaranteed ordering between destruction of |
2003 // this object and destruction of any GeolocationServicesImpls created via | 2008 // this object and destruction of any GeolocationServicesImpls created via |
2004 // the below service registry, the reason being that the destruction of the | 2009 // the below service registry, the reason being that the destruction of the |
2005 // latter is triggered by receiving a message that the pipe was closed from | 2010 // latter is triggered by receiving a message that the pipe was closed from |
2006 // the renderer side. Hence, supply the reference to this object as a weak | 2011 // the renderer side. Hence, supply the reference to this object as a weak |
2007 // pointer. | 2012 // pointer. |
2008 GetServiceRegistry()->AddService( | 2013 GetInterfaceRegistry()->AddInterface( |
2009 base::Bind(&GeolocationServiceContext::CreateService, | 2014 base::Bind(&GeolocationServiceContext::CreateService, |
2010 base::Unretained(geolocation_service_context), | 2015 base::Unretained(geolocation_service_context), |
2011 base::Bind(&RenderFrameHostImpl::DidUseGeolocationPermission, | 2016 base::Bind(&RenderFrameHostImpl::DidUseGeolocationPermission, |
2012 weak_ptr_factory_.GetWeakPtr()))); | 2017 weak_ptr_factory_.GetWeakPtr()))); |
2013 } | 2018 } |
2014 | 2019 |
2015 WakeLockServiceContext* wake_lock_service_context = | 2020 WakeLockServiceContext* wake_lock_service_context = |
2016 delegate_ ? delegate_->GetWakeLockServiceContext() : nullptr; | 2021 delegate_ ? delegate_->GetWakeLockServiceContext() : nullptr; |
2017 if (wake_lock_service_context) { | 2022 if (wake_lock_service_context) { |
2018 // WakeLockServiceContext is owned by WebContentsImpl so it will outlive | 2023 // WakeLockServiceContext is owned by WebContentsImpl so it will outlive |
2019 // this RenderFrameHostImpl, hence a raw pointer can be bound to service | 2024 // this RenderFrameHostImpl, hence a raw pointer can be bound to service |
2020 // factory callback. | 2025 // factory callback. |
2021 GetServiceRegistry()->AddService<blink::mojom::WakeLockService>( | 2026 GetInterfaceRegistry()->AddInterface<blink::mojom::WakeLockService>( |
2022 base::Bind(&WakeLockServiceContext::CreateService, | 2027 base::Bind(&WakeLockServiceContext::CreateService, |
2023 base::Unretained(wake_lock_service_context), | 2028 base::Unretained(wake_lock_service_context), |
2024 GetProcess()->GetID(), GetRoutingID())); | 2029 GetProcess()->GetID(), GetRoutingID())); |
2025 } | 2030 } |
2026 | 2031 |
2027 if (!permission_service_context_) | 2032 if (!permission_service_context_) |
2028 permission_service_context_.reset(new PermissionServiceContext(this)); | 2033 permission_service_context_.reset(new PermissionServiceContext(this)); |
2029 | 2034 |
2030 GetServiceRegistry()->AddService( | 2035 GetInterfaceRegistry()->AddInterface( |
2031 base::Bind(&PermissionServiceContext::CreateService, | 2036 base::Bind(&PermissionServiceContext::CreateService, |
2032 base::Unretained(permission_service_context_.get()))); | 2037 base::Unretained(permission_service_context_.get()))); |
2033 | 2038 |
2034 GetServiceRegistry()->AddService(base::Bind( | 2039 GetInterfaceRegistry()->AddInterface(base::Bind( |
2035 &PresentationServiceImpl::CreateMojoService, base::Unretained(this))); | 2040 &PresentationServiceImpl::CreateMojoService, base::Unretained(this))); |
2036 | 2041 |
2037 #if !defined(OS_ANDROID) | 2042 #if !defined(OS_ANDROID) |
2038 GetServiceRegistry()->AddService( | 2043 GetInterfaceRegistry()->AddInterface( |
2039 base::Bind(&device::VibrationManagerImpl::Create)); | 2044 base::Bind(&device::VibrationManagerImpl::Create)); |
2040 #endif | 2045 #endif |
2041 | 2046 |
2042 bool enable_web_bluetooth = base::CommandLine::ForCurrentProcess()->HasSwitch( | 2047 bool enable_web_bluetooth = base::CommandLine::ForCurrentProcess()->HasSwitch( |
2043 switches::kEnableWebBluetooth); | 2048 switches::kEnableWebBluetooth); |
2044 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) | 2049 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) |
2045 enable_web_bluetooth = true; | 2050 enable_web_bluetooth = true; |
2046 #endif | 2051 #endif |
2047 | 2052 |
2048 if (enable_web_bluetooth) { | 2053 if (enable_web_bluetooth) { |
2049 GetServiceRegistry()->AddService( | 2054 GetInterfaceRegistry()->AddInterface( |
2050 base::Bind(&RenderFrameHostImpl::CreateWebBluetoothService, | 2055 base::Bind(&RenderFrameHostImpl::CreateWebBluetoothService, |
2051 base::Unretained(this))); | 2056 base::Unretained(this))); |
2052 } | 2057 } |
2053 | 2058 |
2054 if (!frame_mojo_shell_) | 2059 if (!frame_mojo_shell_) |
2055 frame_mojo_shell_.reset(new FrameMojoShell(this)); | 2060 frame_mojo_shell_.reset(new FrameMojoShell(this)); |
2056 | 2061 |
2057 GetServiceRegistry()->AddService<shell::mojom::Connector>(base::Bind( | 2062 GetInterfaceRegistry()->AddInterface<shell::mojom::Connector>(base::Bind( |
2058 &FrameMojoShell::BindRequest, base::Unretained(frame_mojo_shell_.get()))); | 2063 &FrameMojoShell::BindRequest, base::Unretained(frame_mojo_shell_.get()))); |
2059 | 2064 |
2060 #if defined(ENABLE_WEBVR) | 2065 #if defined(ENABLE_WEBVR) |
2061 const base::CommandLine& browser_command_line = | 2066 const base::CommandLine& browser_command_line = |
2062 *base::CommandLine::ForCurrentProcess(); | 2067 *base::CommandLine::ForCurrentProcess(); |
2063 | 2068 |
2064 if (browser_command_line.HasSwitch(switches::kEnableWebVR)) { | 2069 if (browser_command_line.HasSwitch(switches::kEnableWebVR)) { |
2065 GetServiceRegistry()->AddService<device::VRService>( | 2070 GetInterfaceRegistry()->AddInterface<device::VRService>( |
2066 base::Bind(&device::VRDeviceManager::BindRequest)); | 2071 base::Bind(&device::VRDeviceManager::BindRequest)); |
2067 } | 2072 } |
2068 #endif | 2073 #endif |
2069 | 2074 |
2070 GetContentClient()->browser()->RegisterRenderFrameMojoServices( | 2075 GetContentClient()->browser()->RegisterRenderFrameMojoInterfaces( |
2071 GetServiceRegistry(), this); | 2076 GetInterfaceRegistry(), this); |
2072 } | 2077 } |
2073 | 2078 |
2074 void RenderFrameHostImpl::ResetWaitingState() { | 2079 void RenderFrameHostImpl::ResetWaitingState() { |
2075 DCHECK(is_active()); | 2080 DCHECK(is_active()); |
2076 | 2081 |
2077 // The active state of the RVH is determined by its main frame, since | 2082 // The active state of the RVH is determined by its main frame, since |
2078 // subframes should have their own widgets. | 2083 // subframes should have their own widgets. |
2079 if (frame_tree_node_->IsMainFrame()) { | 2084 if (frame_tree_node_->IsMainFrame()) { |
2080 render_view_host_->set_is_active(true); | 2085 render_view_host_->set_is_active(true); |
2081 render_view_host_->set_is_swapped_out(false); | 2086 render_view_host_->set_is_swapped_out(false); |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2377 | 2382 |
2378 Send(new FrameMsg_FailedNavigation(routing_id_, common_params, request_params, | 2383 Send(new FrameMsg_FailedNavigation(routing_id_, common_params, request_params, |
2379 has_stale_copy_in_cache, error_code)); | 2384 has_stale_copy_in_cache, error_code)); |
2380 | 2385 |
2381 // An error page is expected to commit, hence why is_loading_ is set to true. | 2386 // An error page is expected to commit, hence why is_loading_ is set to true. |
2382 is_loading_ = true; | 2387 is_loading_ = true; |
2383 frame_tree_node_->ResetNavigationRequest(true); | 2388 frame_tree_node_->ResetNavigationRequest(true); |
2384 } | 2389 } |
2385 | 2390 |
2386 void RenderFrameHostImpl::SetUpMojoIfNeeded() { | 2391 void RenderFrameHostImpl::SetUpMojoIfNeeded() { |
2387 if (service_registry_.get()) | 2392 if (interface_registry_.get()) |
2388 return; | 2393 return; |
2389 | 2394 |
2390 service_registry_.reset(new ServiceRegistryImpl()); | 2395 interface_registry_.reset(new shell::InterfaceRegistry(nullptr)); |
2391 if (!GetProcess()->GetServiceRegistry()) | 2396 if (!GetProcess()->GetServiceRegistry()) |
2392 return; | 2397 return; |
2393 | 2398 |
2394 RegisterMojoServices(); | 2399 RegisterMojoInterfaces(); |
2395 mojom::FrameFactoryPtr frame_factory; | 2400 mojom::FrameFactoryPtr frame_factory; |
2396 GetProcess()->GetServiceRegistry()->ConnectToRemoteService( | 2401 GetProcess()->GetServiceRegistry()->ConnectToRemoteService( |
2397 mojo::GetProxy(&frame_factory)); | 2402 mojo::GetProxy(&frame_factory)); |
2398 | 2403 |
2399 frame_factory->CreateFrame(routing_id_, GetProxy(&frame_), | 2404 frame_factory->CreateFrame(routing_id_, GetProxy(&frame_), |
2400 frame_host_binding_.CreateInterfacePtrAndBind()); | 2405 frame_host_binding_.CreateInterfacePtrAndBind()); |
2401 frame_->GetInterfaceProvider(service_registry_->TakeRemoteRequest()); | 2406 |
| 2407 |
| 2408 shell::mojom::InterfaceProviderPtr remote_interfaces; |
| 2409 shell::mojom::InterfaceProviderRequest remote_interfaces_request = |
| 2410 GetProxy(&remote_interfaces); |
| 2411 remote_interfaces_.reset( |
| 2412 new shell::InterfaceProvider(std::move(remote_interfaces))); |
| 2413 frame_->GetInterfaceProvider(std::move(remote_interfaces_request)); |
2402 | 2414 |
2403 #if defined(OS_ANDROID) | 2415 #if defined(OS_ANDROID) |
2404 service_registry_android_ = | 2416 service_registry_android_ = |
2405 ServiceRegistryAndroid::Create(service_registry_.get()); | 2417 ServiceRegistryAndroid::Create(interface_registry_.get(), |
| 2418 remote_interfaces_.get()); |
2406 ServiceRegistrarAndroid::RegisterFrameHostServices( | 2419 ServiceRegistrarAndroid::RegisterFrameHostServices( |
2407 service_registry_android_.get()); | 2420 service_registry_android_.get()); |
2408 #endif | 2421 #endif |
2409 } | 2422 } |
2410 | 2423 |
2411 void RenderFrameHostImpl::InvalidateMojoConnection() { | 2424 void RenderFrameHostImpl::InvalidateMojoConnection() { |
2412 #if defined(OS_ANDROID) | 2425 #if defined(OS_ANDROID) |
2413 // The Android-specific service registry has a reference to | 2426 // The Android-specific service registry has a reference to |
2414 // |service_registry_| and thus must be torn down first. | 2427 // |service_registry_| and thus must be torn down first. |
2415 service_registry_android_.reset(); | 2428 service_registry_android_.reset(); |
2416 #endif | 2429 #endif |
2417 | 2430 |
2418 service_registry_.reset(); | 2431 interface_registry_.reset(); |
2419 frame_.reset(); | 2432 frame_.reset(); |
2420 frame_host_binding_.Close(); | 2433 frame_host_binding_.Close(); |
2421 | 2434 |
2422 // Disconnect with ImageDownloader Mojo service in RenderFrame. | 2435 // Disconnect with ImageDownloader Mojo service in RenderFrame. |
2423 mojo_image_downloader_.reset(); | 2436 mojo_image_downloader_.reset(); |
2424 } | 2437 } |
2425 | 2438 |
2426 bool RenderFrameHostImpl::IsFocused() { | 2439 bool RenderFrameHostImpl::IsFocused() { |
2427 return GetRenderWidgetHost()->is_focused() && | 2440 return GetRenderWidgetHost()->is_focused() && |
2428 frame_tree_->GetFocusedFrame() && | 2441 frame_tree_->GetFocusedFrame() && |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2516 } | 2529 } |
2517 | 2530 |
2518 void RenderFrameHostImpl::ClearAllWebUI() { | 2531 void RenderFrameHostImpl::ClearAllWebUI() { |
2519 ClearPendingWebUI(); | 2532 ClearPendingWebUI(); |
2520 web_ui_type_ = WebUI::kNoWebUI; | 2533 web_ui_type_ = WebUI::kNoWebUI; |
2521 web_ui_.reset(); | 2534 web_ui_.reset(); |
2522 } | 2535 } |
2523 | 2536 |
2524 const content::mojom::ImageDownloaderPtr& | 2537 const content::mojom::ImageDownloaderPtr& |
2525 RenderFrameHostImpl::GetMojoImageDownloader() { | 2538 RenderFrameHostImpl::GetMojoImageDownloader() { |
2526 if (!mojo_image_downloader_.get() && GetServiceRegistry()) { | 2539 if (!mojo_image_downloader_.get() && GetRemoteInterfaces()) |
2527 GetServiceRegistry()->ConnectToRemoteService( | 2540 GetRemoteInterfaces()->GetInterface(&mojo_image_downloader_); |
2528 mojo::GetProxy(&mojo_image_downloader_)); | |
2529 } | |
2530 return mojo_image_downloader_; | 2541 return mojo_image_downloader_; |
2531 } | 2542 } |
2532 | 2543 |
2533 void RenderFrameHostImpl::ResetLoadingState() { | 2544 void RenderFrameHostImpl::ResetLoadingState() { |
2534 if (is_loading()) { | 2545 if (is_loading()) { |
2535 // When pending deletion, just set the loading state to not loading. | 2546 // When pending deletion, just set the loading state to not loading. |
2536 // Otherwise, OnDidStopLoading will take care of that, as well as sending | 2547 // Otherwise, OnDidStopLoading will take care of that, as well as sending |
2537 // notification to the FrameTreeNode about the change in loading state. | 2548 // notification to the FrameTreeNode about the change in loading state. |
2538 if (!is_active()) | 2549 if (!is_active()) |
2539 is_loading_ = false; | 2550 is_loading_ = false; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2675 file_system_context->CrackURL(file.file_system_url) | 2686 file_system_context->CrackURL(file.file_system_url) |
2676 .mount_filesystem_id()); | 2687 .mount_filesystem_id()); |
2677 } | 2688 } |
2678 } | 2689 } |
2679 | 2690 |
2680 Send(new FrameMsg_RunFileChooserResponse(routing_id_, files)); | 2691 Send(new FrameMsg_RunFileChooserResponse(routing_id_, files)); |
2681 } | 2692 } |
2682 | 2693 |
2683 void RenderFrameHostImpl::GetInterfaceProvider( | 2694 void RenderFrameHostImpl::GetInterfaceProvider( |
2684 shell::mojom::InterfaceProviderRequest interfaces) { | 2695 shell::mojom::InterfaceProviderRequest interfaces) { |
2685 service_registry_->Bind(std::move(interfaces)); | 2696 interface_registry_->Bind(std::move(interfaces)); |
2686 } | 2697 } |
2687 | 2698 |
2688 #if defined(USE_EXTERNAL_POPUP_MENU) | 2699 #if defined(USE_EXTERNAL_POPUP_MENU) |
2689 #if defined(OS_MACOSX) | 2700 #if defined(OS_MACOSX) |
2690 | 2701 |
2691 void RenderFrameHostImpl::DidSelectPopupMenuItem(int selected_index) { | 2702 void RenderFrameHostImpl::DidSelectPopupMenuItem(int selected_index) { |
2692 Send(new FrameMsg_SelectPopupMenuItem(routing_id_, selected_index)); | 2703 Send(new FrameMsg_SelectPopupMenuItem(routing_id_, selected_index)); |
2693 } | 2704 } |
2694 | 2705 |
2695 void RenderFrameHostImpl::DidCancelPopupMenu() { | 2706 void RenderFrameHostImpl::DidCancelPopupMenu() { |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2948 // handler after it's destroyed so it can't run after the RFHI is destroyed. | 2959 // handler after it's destroyed so it can't run after the RFHI is destroyed. |
2949 web_bluetooth_service_->SetClientConnectionErrorHandler(base::Bind( | 2960 web_bluetooth_service_->SetClientConnectionErrorHandler(base::Bind( |
2950 &RenderFrameHostImpl::DeleteWebBluetoothService, base::Unretained(this))); | 2961 &RenderFrameHostImpl::DeleteWebBluetoothService, base::Unretained(this))); |
2951 } | 2962 } |
2952 | 2963 |
2953 void RenderFrameHostImpl::DeleteWebBluetoothService() { | 2964 void RenderFrameHostImpl::DeleteWebBluetoothService() { |
2954 web_bluetooth_service_.reset(); | 2965 web_bluetooth_service_.reset(); |
2955 } | 2966 } |
2956 | 2967 |
2957 } // namespace content | 2968 } // namespace content |
OLD | NEW |