| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 // RemoterFactory that delegates Create() calls to the ContentBrowserClient. | 228 // RemoterFactory that delegates Create() calls to the ContentBrowserClient. |
| 229 // | 229 // |
| 230 // Since Create() could be called at any time, perhaps by a stray task being run | 230 // Since Create() could be called at any time, perhaps by a stray task being run |
| 231 // after a RenderFrameHost has been destroyed, the RemoterFactoryImpl uses the | 231 // after a RenderFrameHost has been destroyed, the RemoterFactoryImpl uses the |
| 232 // process/routing IDs as a weak reference to the RenderFrameHostImpl. | 232 // process/routing IDs as a weak reference to the RenderFrameHostImpl. |
| 233 class RemoterFactoryImpl final : public media::mojom::RemoterFactory { | 233 class RemoterFactoryImpl final : public media::mojom::RemoterFactory { |
| 234 public: | 234 public: |
| 235 RemoterFactoryImpl(int process_id, int routing_id) | 235 RemoterFactoryImpl(int process_id, int routing_id) |
| 236 : process_id_(process_id), routing_id_(routing_id) {} | 236 : process_id_(process_id), routing_id_(routing_id) {} |
| 237 | 237 |
| 238 static void Bind(int process_id, int routing_id, | 238 static void Bind(int process_id, |
| 239 int routing_id, |
| 240 const service_manager::BindSourceInfo& source_info, |
| 239 media::mojom::RemoterFactoryRequest request) { | 241 media::mojom::RemoterFactoryRequest request) { |
| 240 mojo::MakeStrongBinding( | 242 mojo::MakeStrongBinding( |
| 241 base::MakeUnique<RemoterFactoryImpl>(process_id, routing_id), | 243 base::MakeUnique<RemoterFactoryImpl>(process_id, routing_id), |
| 242 std::move(request)); | 244 std::move(request)); |
| 243 } | 245 } |
| 244 | 246 |
| 245 private: | 247 private: |
| 246 void Create(media::mojom::RemotingSourcePtr source, | 248 void Create(media::mojom::RemotingSourcePtr source, |
| 247 media::mojom::RemoterRequest request) final { | 249 media::mojom::RemoterRequest request) final { |
| 248 if (auto* host = RenderFrameHostImpl::FromID(process_id_, routing_id_)) { | 250 if (auto* host = RenderFrameHostImpl::FromID(process_id_, routing_id_)) { |
| 249 GetContentClient()->browser()->CreateMediaRemoter( | 251 GetContentClient()->browser()->CreateMediaRemoter( |
| 250 host, std::move(source), std::move(request)); | 252 host, std::move(source), std::move(request)); |
| 251 } | 253 } |
| 252 } | 254 } |
| 253 | 255 |
| 254 const int process_id_; | 256 const int process_id_; |
| 255 const int routing_id_; | 257 const int routing_id_; |
| 256 | 258 |
| 257 DISALLOW_COPY_AND_ASSIGN(RemoterFactoryImpl); | 259 DISALLOW_COPY_AND_ASSIGN(RemoterFactoryImpl); |
| 258 }; | 260 }; |
| 259 #endif // BUILDFLAG(ENABLE_MEDIA_REMOTING) | 261 #endif // BUILDFLAG(ENABLE_MEDIA_REMOTING) |
| 260 | 262 |
| 261 template <typename Interface> | 263 template <typename Interface> |
| 262 void IgnoreInterfaceRequest(mojo::InterfaceRequest<Interface> request) { | 264 void IgnoreInterfaceRequest(const service_manager::BindSourceInfo& source_info, |
| 265 mojo::InterfaceRequest<Interface> request) { |
| 263 // Intentionally ignore the interface request. | 266 // Intentionally ignore the interface request. |
| 264 } | 267 } |
| 265 | 268 |
| 266 // The following functions simplify code paths where the UI thread notifies the | 269 // The following functions simplify code paths where the UI thread notifies the |
| 267 // ResourceDispatcherHostImpl of information pertaining to loading behavior of | 270 // ResourceDispatcherHostImpl of information pertaining to loading behavior of |
| 268 // frame hosts. | 271 // frame hosts. |
| 269 void NotifyRouteChangesOnIO( | 272 void NotifyRouteChangesOnIO( |
| 270 base::Callback<void(ResourceDispatcherHostImpl*, | 273 base::Callback<void(ResourceDispatcherHostImpl*, |
| 271 const GlobalFrameRoutingId&)> frame_callback, | 274 const GlobalFrameRoutingId&)> frame_callback, |
| 272 std::unique_ptr<std::set<GlobalFrameRoutingId>> routing_ids) { | 275 std::unique_ptr<std::set<GlobalFrameRoutingId>> routing_ids) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 } | 319 } |
| 317 | 320 |
| 318 #if defined(OS_ANDROID) | 321 #if defined(OS_ANDROID) |
| 319 // static | 322 // static |
| 320 void RenderFrameHost::AllowInjectingJavaScriptForAndroidWebView() { | 323 void RenderFrameHost::AllowInjectingJavaScriptForAndroidWebView() { |
| 321 g_allow_injecting_javascript = true; | 324 g_allow_injecting_javascript = true; |
| 322 } | 325 } |
| 323 | 326 |
| 324 void CreateMediaPlayerRenderer( | 327 void CreateMediaPlayerRenderer( |
| 325 content::RenderFrameHost* render_frame_host, | 328 content::RenderFrameHost* render_frame_host, |
| 326 mojo::InterfaceRequest<media::mojom::Renderer> request) { | 329 const service_manager::BindSourceInfo& source_info, |
| 330 media::mojom::RendererRequest request) { |
| 327 std::unique_ptr<MediaPlayerRenderer> renderer = | 331 std::unique_ptr<MediaPlayerRenderer> renderer = |
| 328 base::MakeUnique<MediaPlayerRenderer>(render_frame_host); | 332 base::MakeUnique<MediaPlayerRenderer>(render_frame_host); |
| 329 | 333 |
| 330 // base::Unretained is safe here because the lifetime of the MediaPlayerRender | 334 // base::Unretained is safe here because the lifetime of the MediaPlayerRender |
| 331 // is tied to the lifetime of the MojoRendererService. | 335 // is tied to the lifetime of the MojoRendererService. |
| 332 media::MojoRendererService::InitiateSurfaceRequestCB surface_request_cb = | 336 media::MojoRendererService::InitiateSurfaceRequestCB surface_request_cb = |
| 333 base::Bind(&MediaPlayerRenderer::InitiateScopedSurfaceRequest, | 337 base::Bind(&MediaPlayerRenderer::InitiateScopedSurfaceRequest, |
| 334 base::Unretained(renderer.get())); | 338 base::Unretained(renderer.get())); |
| 335 | 339 |
| 336 media::MojoRendererService::Create( | 340 media::MojoRendererService::Create( |
| (...skipping 2328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2665 // this object and destruction of any GeolocationServicesImpls created via | 2669 // this object and destruction of any GeolocationServicesImpls created via |
| 2666 // the below service registry, the reason being that the destruction of the | 2670 // the below service registry, the reason being that the destruction of the |
| 2667 // latter is triggered by receiving a message that the pipe was closed from | 2671 // latter is triggered by receiving a message that the pipe was closed from |
| 2668 // the renderer side. Hence, supply the reference to this object as a weak | 2672 // the renderer side. Hence, supply the reference to this object as a weak |
| 2669 // pointer. | 2673 // pointer. |
| 2670 GetInterfaceRegistry()->AddInterface( | 2674 GetInterfaceRegistry()->AddInterface( |
| 2671 base::Bind(&device::GeolocationServiceContext::CreateService, | 2675 base::Bind(&device::GeolocationServiceContext::CreateService, |
| 2672 base::Unretained(geolocation_service_context))); | 2676 base::Unretained(geolocation_service_context))); |
| 2673 } | 2677 } |
| 2674 | 2678 |
| 2675 device::mojom::WakeLockContext* wake_lock_service_context = | 2679 GetInterfaceRegistry()->AddInterface<device::mojom::WakeLockService>( |
| 2676 delegate_ ? delegate_->GetWakeLockServiceContext() : nullptr; | 2680 base::Bind(&RenderFrameHostImpl::BindWakeLockServiceRequest, |
| 2677 if (wake_lock_service_context) { | 2681 base::Unretained(this))); |
| 2678 // WakeLockServiceContext is owned by WebContentsImpl so it will outlive | |
| 2679 // this RenderFrameHostImpl, hence a raw pointer can be bound to service | |
| 2680 // factory callback. | |
| 2681 GetInterfaceRegistry()->AddInterface<device::mojom::WakeLockService>( | |
| 2682 base::Bind(&device::mojom::WakeLockContext::GetWakeLock, | |
| 2683 base::Unretained(wake_lock_service_context))); | |
| 2684 } | |
| 2685 | 2682 |
| 2686 if (!permission_service_context_) | 2683 if (!permission_service_context_) |
| 2687 permission_service_context_.reset(new PermissionServiceContext(this)); | 2684 permission_service_context_.reset(new PermissionServiceContext(this)); |
| 2688 | 2685 |
| 2689 GetInterfaceRegistry()->AddInterface( | 2686 GetInterfaceRegistry()->AddInterface( |
| 2690 base::Bind(&PermissionServiceContext::CreateService, | 2687 base::Bind(&PermissionServiceContext::CreateService, |
| 2691 base::Unretained(permission_service_context_.get()))); | 2688 base::Unretained(permission_service_context_.get()))); |
| 2692 | 2689 |
| 2693 GetInterfaceRegistry()->AddInterface(base::Bind( | 2690 GetInterfaceRegistry()->AddInterface(base::Bind( |
| 2694 &PresentationServiceImpl::CreateMojoService, base::Unretained(this))); | 2691 &PresentationServiceImpl::CreateMojoService, base::Unretained(this))); |
| (...skipping 968 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3663 FrameTreeNode* focused_frame_tree_node = frame_tree_->GetFocusedFrame(); | 3660 FrameTreeNode* focused_frame_tree_node = frame_tree_->GetFocusedFrame(); |
| 3664 if (!focused_frame_tree_node) | 3661 if (!focused_frame_tree_node) |
| 3665 return; | 3662 return; |
| 3666 RenderFrameHostImpl* focused_frame = | 3663 RenderFrameHostImpl* focused_frame = |
| 3667 focused_frame_tree_node->current_frame_host(); | 3664 focused_frame_tree_node->current_frame_host(); |
| 3668 DCHECK(focused_frame); | 3665 DCHECK(focused_frame); |
| 3669 dst->focused_tree_id = focused_frame->GetAXTreeID(); | 3666 dst->focused_tree_id = focused_frame->GetAXTreeID(); |
| 3670 } | 3667 } |
| 3671 | 3668 |
| 3672 WebBluetoothServiceImpl* RenderFrameHostImpl::CreateWebBluetoothService( | 3669 WebBluetoothServiceImpl* RenderFrameHostImpl::CreateWebBluetoothService( |
| 3670 const service_manager::BindSourceInfo& source_info, |
| 3673 blink::mojom::WebBluetoothServiceRequest request) { | 3671 blink::mojom::WebBluetoothServiceRequest request) { |
| 3674 // RFHI owns |web_bluetooth_services_| and |web_bluetooth_service| owns the | 3672 // RFHI owns |web_bluetooth_services_| and |web_bluetooth_service| owns the |
| 3675 // |binding_| which may run the error handler. |binding_| can't run the error | 3673 // |binding_| which may run the error handler. |binding_| can't run the error |
| 3676 // handler after it's destroyed so it can't run after the RFHI is destroyed. | 3674 // handler after it's destroyed so it can't run after the RFHI is destroyed. |
| 3677 auto web_bluetooth_service = | 3675 auto web_bluetooth_service = |
| 3678 base::MakeUnique<WebBluetoothServiceImpl>(this, std::move(request)); | 3676 base::MakeUnique<WebBluetoothServiceImpl>(this, std::move(request)); |
| 3679 web_bluetooth_service->SetClientConnectionErrorHandler( | 3677 web_bluetooth_service->SetClientConnectionErrorHandler( |
| 3680 base::Bind(&RenderFrameHostImpl::DeleteWebBluetoothService, | 3678 base::Bind(&RenderFrameHostImpl::DeleteWebBluetoothService, |
| 3681 base::Unretained(this), web_bluetooth_service.get())); | 3679 base::Unretained(this), web_bluetooth_service.get())); |
| 3682 web_bluetooth_services_.push_back(std::move(web_bluetooth_service)); | 3680 web_bluetooth_services_.push_back(std::move(web_bluetooth_service)); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 3713 this, std::move(request), | 3711 this, std::move(request), |
| 3714 base::Bind(&RenderFrameHostImpl::OnMediaInterfaceFactoryConnectionError, | 3712 base::Bind(&RenderFrameHostImpl::OnMediaInterfaceFactoryConnectionError, |
| 3715 base::Unretained(this)))); | 3713 base::Unretained(this)))); |
| 3716 } | 3714 } |
| 3717 | 3715 |
| 3718 void RenderFrameHostImpl::OnMediaInterfaceFactoryConnectionError() { | 3716 void RenderFrameHostImpl::OnMediaInterfaceFactoryConnectionError() { |
| 3719 DCHECK(media_interface_proxy_); | 3717 DCHECK(media_interface_proxy_); |
| 3720 media_interface_proxy_.reset(); | 3718 media_interface_proxy_.reset(); |
| 3721 } | 3719 } |
| 3722 | 3720 |
| 3721 void RenderFrameHostImpl::BindWakeLockServiceRequest( |
| 3722 const service_manager::BindSourceInfo& source_info, |
| 3723 device::mojom::WakeLockServiceRequest request) { |
| 3724 device::mojom::WakeLockContext* wake_lock_service_context = |
| 3725 delegate_ ? delegate_->GetWakeLockServiceContext() : nullptr; |
| 3726 if (wake_lock_service_context) |
| 3727 wake_lock_service_context->GetWakeLock(std::move(request)); |
| 3728 } |
| 3729 |
| 3723 void RenderFrameHostImpl::GetInterface( | 3730 void RenderFrameHostImpl::GetInterface( |
| 3724 const std::string& interface_name, | 3731 const std::string& interface_name, |
| 3725 mojo::ScopedMessagePipeHandle interface_pipe) { | 3732 mojo::ScopedMessagePipeHandle interface_pipe) { |
| 3726 if (interface_registry_.get()) { | 3733 if (interface_registry_.get()) { |
| 3727 service_manager::BindSourceInfo source_info( | 3734 service_manager::BindSourceInfo source_info( |
| 3728 GetProcess()->GetChildIdentity(), service_manager::CapabilitySet()); | 3735 GetProcess()->GetChildIdentity(), service_manager::CapabilitySet()); |
| 3729 interface_registry_->BindInterface(source_info, interface_name, | 3736 interface_registry_->BindInterface(source_info, interface_name, |
| 3730 std::move(interface_pipe)); | 3737 std::move(interface_pipe)); |
| 3731 } | 3738 } |
| 3732 } | 3739 } |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3894 } | 3901 } |
| 3895 | 3902 |
| 3896 void RenderFrameHostImpl::ForwardGetInterfaceToRenderFrame( | 3903 void RenderFrameHostImpl::ForwardGetInterfaceToRenderFrame( |
| 3897 const std::string& interface_name, | 3904 const std::string& interface_name, |
| 3898 mojo::ScopedMessagePipeHandle pipe) { | 3905 mojo::ScopedMessagePipeHandle pipe) { |
| 3899 GetRemoteInterfaces()->GetInterface(interface_name, std::move(pipe)); | 3906 GetRemoteInterfaces()->GetInterface(interface_name, std::move(pipe)); |
| 3900 } | 3907 } |
| 3901 #endif | 3908 #endif |
| 3902 | 3909 |
| 3903 } // namespace content | 3910 } // namespace content |
| OLD | NEW |