| 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 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 render_widget_host_ = new RenderWidgetHostImpl(rwh_delegate, GetProcess(), | 440 render_widget_host_ = new RenderWidgetHostImpl(rwh_delegate, GetProcess(), |
| 441 widget_routing_id, hidden); | 441 widget_routing_id, hidden); |
| 442 render_widget_host_->set_owned_by_render_frame_host(true); | 442 render_widget_host_->set_owned_by_render_frame_host(true); |
| 443 } else { | 443 } else { |
| 444 DCHECK(!render_widget_host_->owned_by_render_frame_host()); | 444 DCHECK(!render_widget_host_->owned_by_render_frame_host()); |
| 445 } | 445 } |
| 446 InputRouterImpl* ir = | 446 InputRouterImpl* ir = |
| 447 static_cast<InputRouterImpl*>(render_widget_host_->input_router()); | 447 static_cast<InputRouterImpl*>(render_widget_host_->input_router()); |
| 448 ir->SetFrameTreeNodeId(frame_tree_node_->frame_tree_node_id()); | 448 ir->SetFrameTreeNodeId(frame_tree_node_->frame_tree_node_id()); |
| 449 } | 449 } |
| 450 ResetFeaturePolicy(); |
| 450 } | 451 } |
| 451 | 452 |
| 452 RenderFrameHostImpl::~RenderFrameHostImpl() { | 453 RenderFrameHostImpl::~RenderFrameHostImpl() { |
| 453 // Destroying navigation handle may call into delegates/observers, | 454 // Destroying navigation handle may call into delegates/observers, |
| 454 // so we do it early while |this| object is still in a sane state. | 455 // so we do it early while |this| object is still in a sane state. |
| 455 navigation_handle_.reset(); | 456 navigation_handle_.reset(); |
| 456 | 457 |
| 457 // Release the WebUI instances before all else as the WebUI may accesses the | 458 // Release the WebUI instances before all else as the WebUI may accesses the |
| 458 // RenderFrameHost during cleanup. | 459 // RenderFrameHost during cleanup. |
| 459 ClearAllWebUI(); | 460 ClearAllWebUI(); |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeOpener, OnDidChangeOpener) | 777 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeOpener, OnDidChangeOpener) |
| 777 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeName, OnDidChangeName) | 778 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeName, OnDidChangeName) |
| 778 IPC_MESSAGE_HANDLER(FrameHostMsg_DidSetFeaturePolicyHeader, | 779 IPC_MESSAGE_HANDLER(FrameHostMsg_DidSetFeaturePolicyHeader, |
| 779 OnDidSetFeaturePolicyHeader) | 780 OnDidSetFeaturePolicyHeader) |
| 780 IPC_MESSAGE_HANDLER(FrameHostMsg_DidAddContentSecurityPolicies, | 781 IPC_MESSAGE_HANDLER(FrameHostMsg_DidAddContentSecurityPolicies, |
| 781 OnDidAddContentSecurityPolicies) | 782 OnDidAddContentSecurityPolicies) |
| 782 IPC_MESSAGE_HANDLER(FrameHostMsg_EnforceInsecureRequestPolicy, | 783 IPC_MESSAGE_HANDLER(FrameHostMsg_EnforceInsecureRequestPolicy, |
| 783 OnEnforceInsecureRequestPolicy) | 784 OnEnforceInsecureRequestPolicy) |
| 784 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateToUniqueOrigin, | 785 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateToUniqueOrigin, |
| 785 OnUpdateToUniqueOrigin) | 786 OnUpdateToUniqueOrigin) |
| 786 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeSandboxFlags, | 787 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeFramePolicy, |
| 787 OnDidChangeSandboxFlags) | 788 OnDidChangeFramePolicy) |
| 788 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeFrameOwnerProperties, | 789 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeFrameOwnerProperties, |
| 789 OnDidChangeFrameOwnerProperties) | 790 OnDidChangeFrameOwnerProperties) |
| 790 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateTitle, OnUpdateTitle) | 791 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateTitle, OnUpdateTitle) |
| 791 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateEncoding, OnUpdateEncoding) | 792 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateEncoding, OnUpdateEncoding) |
| 792 IPC_MESSAGE_HANDLER(FrameHostMsg_BeginNavigation, | 793 IPC_MESSAGE_HANDLER(FrameHostMsg_BeginNavigation, |
| 793 OnBeginNavigation) | 794 OnBeginNavigation) |
| 794 IPC_MESSAGE_HANDLER(FrameHostMsg_AbortNavigation, OnAbortNavigation) | 795 IPC_MESSAGE_HANDLER(FrameHostMsg_AbortNavigation, OnAbortNavigation) |
| 795 IPC_MESSAGE_HANDLER(FrameHostMsg_DispatchLoad, OnDispatchLoad) | 796 IPC_MESSAGE_HANDLER(FrameHostMsg_DispatchLoad, OnDispatchLoad) |
| 796 IPC_MESSAGE_HANDLER(FrameHostMsg_TextSurroundingSelectionResponse, | 797 IPC_MESSAGE_HANDLER(FrameHostMsg_TextSurroundingSelectionResponse, |
| 797 OnTextSurroundingSelectionResponse) | 798 OnTextSurroundingSelectionResponse) |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1095 << ")"; | 1096 << ")"; |
| 1096 } | 1097 } |
| 1097 } | 1098 } |
| 1098 | 1099 |
| 1099 void RenderFrameHostImpl::OnCreateChildFrame( | 1100 void RenderFrameHostImpl::OnCreateChildFrame( |
| 1100 int new_routing_id, | 1101 int new_routing_id, |
| 1101 blink::WebTreeScopeType scope, | 1102 blink::WebTreeScopeType scope, |
| 1102 const std::string& frame_name, | 1103 const std::string& frame_name, |
| 1103 const std::string& frame_unique_name, | 1104 const std::string& frame_unique_name, |
| 1104 blink::WebSandboxFlags sandbox_flags, | 1105 blink::WebSandboxFlags sandbox_flags, |
| 1106 const ParsedFeaturePolicyHeader& container_policy, |
| 1105 const FrameOwnerProperties& frame_owner_properties) { | 1107 const FrameOwnerProperties& frame_owner_properties) { |
| 1106 // TODO(lukasza): Call ReceivedBadMessage when |frame_unique_name| is empty. | 1108 // TODO(lukasza): Call ReceivedBadMessage when |frame_unique_name| is empty. |
| 1107 DCHECK(!frame_unique_name.empty()); | 1109 DCHECK(!frame_unique_name.empty()); |
| 1108 | 1110 |
| 1109 // The RenderFrame corresponding to this host sent an IPC message to create a | 1111 // The RenderFrame corresponding to this host sent an IPC message to create a |
| 1110 // child, but by the time we get here, it's possible for the host to have been | 1112 // child, but by the time we get here, it's possible for the host to have been |
| 1111 // swapped out, or for its process to have disconnected (maybe due to browser | 1113 // swapped out, or for its process to have disconnected (maybe due to browser |
| 1112 // shutdown). Ignore such messages. | 1114 // shutdown). Ignore such messages. |
| 1113 if (!is_active() || frame_tree_node_->current_frame_host() != this || | 1115 if (!is_active() || frame_tree_node_->current_frame_host() != this || |
| 1114 !render_frame_created_) | 1116 !render_frame_created_) |
| 1115 return; | 1117 return; |
| 1116 | 1118 |
| 1117 frame_tree_->AddFrame( | 1119 frame_tree_->AddFrame(frame_tree_node_, GetProcess()->GetID(), new_routing_id, |
| 1118 frame_tree_node_, GetProcess()->GetID(), new_routing_id, scope, | 1120 scope, frame_name, frame_unique_name, sandbox_flags, |
| 1119 frame_name, frame_unique_name, sandbox_flags, frame_owner_properties); | 1121 container_policy, frame_owner_properties); |
| 1120 } | 1122 } |
| 1121 | 1123 |
| 1122 void RenderFrameHostImpl::OnCreateNewWindow( | 1124 void RenderFrameHostImpl::OnCreateNewWindow( |
| 1123 int32_t render_view_route_id, | 1125 int32_t render_view_route_id, |
| 1124 int32_t main_frame_route_id, | 1126 int32_t main_frame_route_id, |
| 1125 int32_t main_frame_widget_route_id, | 1127 int32_t main_frame_widget_route_id, |
| 1126 const mojom::CreateNewWindowParams& params, | 1128 const mojom::CreateNewWindowParams& params, |
| 1127 SessionStorageNamespace* session_storage_namespace) { | 1129 SessionStorageNamespace* session_storage_namespace) { |
| 1128 mojom::CreateNewWindowParamsPtr validated_params(params.Clone()); | 1130 mojom::CreateNewWindowParamsPtr validated_params(params.Clone()); |
| 1129 GetProcess()->FilterURL(false, &validated_params->target_url); | 1131 GetProcess()->FilterURL(false, &validated_params->target_url); |
| (...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1979 GetProcess()->GetID(), child_frame_routing_id); | 1981 GetProcess()->GetID(), child_frame_routing_id); |
| 1980 // A race can result in |child| to be nullptr. Avoid killing the renderer in | 1982 // A race can result in |child| to be nullptr. Avoid killing the renderer in |
| 1981 // that case. | 1983 // that case. |
| 1982 if (child && child->parent() != frame_tree_node()) { | 1984 if (child && child->parent() != frame_tree_node()) { |
| 1983 bad_message::ReceivedBadMessage(GetProcess(), reason); | 1985 bad_message::ReceivedBadMessage(GetProcess(), reason); |
| 1984 return nullptr; | 1986 return nullptr; |
| 1985 } | 1987 } |
| 1986 return child; | 1988 return child; |
| 1987 } | 1989 } |
| 1988 | 1990 |
| 1989 void RenderFrameHostImpl::OnDidChangeSandboxFlags( | 1991 void RenderFrameHostImpl::OnDidChangeFramePolicy( |
| 1990 int32_t frame_routing_id, | 1992 int32_t frame_routing_id, |
| 1991 blink::WebSandboxFlags flags) { | 1993 blink::WebSandboxFlags flags, |
| 1992 // Ensure that a frame can only update sandbox flags for its immediate | 1994 const ParsedFeaturePolicyHeader& container_policy) { |
| 1993 // children. If this is not the case, the renderer is considered malicious | 1995 // Ensure that a frame can only update sandbox flags or feature policy for its |
| 1994 // and is killed. | 1996 // immediate children. If this is not the case, the renderer is considered |
| 1997 // malicious and is killed. |
| 1995 FrameTreeNode* child = FindAndVerifyChild( | 1998 FrameTreeNode* child = FindAndVerifyChild( |
| 1999 // TODO(iclelland): Rename this message |
| 1996 frame_routing_id, bad_message::RFH_SANDBOX_FLAGS); | 2000 frame_routing_id, bad_message::RFH_SANDBOX_FLAGS); |
| 1997 if (!child) | 2001 if (!child) |
| 1998 return; | 2002 return; |
| 1999 | 2003 |
| 2000 child->SetPendingSandboxFlags(flags); | 2004 child->SetPendingSandboxFlags(flags); |
| 2005 child->SetPendingContainerPolicy(container_policy); |
| 2001 | 2006 |
| 2002 // Notify the RenderFrame if it lives in a different process from its | 2007 // Notify the RenderFrame if it lives in a different process from its parent. |
| 2003 // parent. The frame's proxies in other processes also need to learn about | 2008 // The frame's proxies in other processes also need to learn about the updated |
| 2004 // the updated sandbox flags, but these notifications are sent later in | 2009 // flags and policy, but these notifications are sent later in |
| 2005 // RenderFrameHostManager::CommitPendingSandboxFlags(), when the frame | 2010 // RenderFrameHostManager::CommitPendingFramePolicy(), when the frame |
| 2006 // navigates and the new sandbox flags take effect. | 2011 // navigates and the new policies take effect. |
| 2007 RenderFrameHost* child_rfh = child->current_frame_host(); | 2012 RenderFrameHost* child_rfh = child->current_frame_host(); |
| 2008 if (child_rfh->GetSiteInstance() != GetSiteInstance()) { | 2013 if (child_rfh->GetSiteInstance() != GetSiteInstance()) { |
| 2009 child_rfh->Send( | 2014 child_rfh->Send(new FrameMsg_DidUpdateFramePolicy(child_rfh->GetRoutingID(), |
| 2010 new FrameMsg_DidUpdateSandboxFlags(child_rfh->GetRoutingID(), flags)); | 2015 flags, container_policy)); |
| 2011 } | 2016 } |
| 2012 } | 2017 } |
| 2013 | 2018 |
| 2014 void RenderFrameHostImpl::OnDidChangeFrameOwnerProperties( | 2019 void RenderFrameHostImpl::OnDidChangeFrameOwnerProperties( |
| 2015 int32_t frame_routing_id, | 2020 int32_t frame_routing_id, |
| 2016 const FrameOwnerProperties& properties) { | 2021 const FrameOwnerProperties& properties) { |
| 2017 FrameTreeNode* child = FindAndVerifyChild( | 2022 FrameTreeNode* child = FindAndVerifyChild( |
| 2018 frame_routing_id, bad_message::RFH_OWNER_PROPERTY); | 2023 frame_routing_id, bad_message::RFH_OWNER_PROPERTY); |
| 2019 if (!child) | 2024 if (!child) |
| 2020 return; | 2025 return; |
| (...skipping 1504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3525 return web_bluetooth_service == service.get(); | 3530 return web_bluetooth_service == service.get(); |
| 3526 }); | 3531 }); |
| 3527 DCHECK(it != web_bluetooth_services_.end()); | 3532 DCHECK(it != web_bluetooth_services_.end()); |
| 3528 web_bluetooth_services_.erase(it); | 3533 web_bluetooth_services_.erase(it); |
| 3529 } | 3534 } |
| 3530 | 3535 |
| 3531 void RenderFrameHostImpl::ResetFeaturePolicy() { | 3536 void RenderFrameHostImpl::ResetFeaturePolicy() { |
| 3532 RenderFrameHostImpl* parent_frame_host = GetParent(); | 3537 RenderFrameHostImpl* parent_frame_host = GetParent(); |
| 3533 const FeaturePolicy* parent_policy = | 3538 const FeaturePolicy* parent_policy = |
| 3534 parent_frame_host ? parent_frame_host->get_feature_policy() : nullptr; | 3539 parent_frame_host ? parent_frame_host->get_feature_policy() : nullptr; |
| 3535 // TODO(iclelland): Get the frame owner properties here to reset properly. | 3540 ParsedFeaturePolicyHeader container_policy = |
| 3536 ParsedFeaturePolicyHeader container_policy; | 3541 frame_tree_node()->effective_container_policy(); |
| 3537 feature_policy_ = FeaturePolicy::CreateFromParentPolicy( | 3542 feature_policy_ = FeaturePolicy::CreateFromParentPolicy( |
| 3538 parent_policy, container_policy, last_committed_origin_); | 3543 parent_policy, container_policy, last_committed_origin_); |
| 3539 } | 3544 } |
| 3540 | 3545 |
| 3541 void RenderFrameHostImpl::Create( | 3546 void RenderFrameHostImpl::Create( |
| 3542 const service_manager::Identity& remote_identity, | 3547 const service_manager::Identity& remote_identity, |
| 3543 media::mojom::InterfaceFactoryRequest request) { | 3548 media::mojom::InterfaceFactoryRequest request) { |
| 3544 DCHECK(!media_interface_proxy_); | 3549 DCHECK(!media_interface_proxy_); |
| 3545 media_interface_proxy_.reset(new MediaInterfaceProxy( | 3550 media_interface_proxy_.reset(new MediaInterfaceProxy( |
| 3546 this, std::move(request), | 3551 this, std::move(request), |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3698 } | 3703 } |
| 3699 | 3704 |
| 3700 void RenderFrameHostImpl::ForwardGetInterfaceToRenderFrame( | 3705 void RenderFrameHostImpl::ForwardGetInterfaceToRenderFrame( |
| 3701 const std::string& interface_name, | 3706 const std::string& interface_name, |
| 3702 mojo::ScopedMessagePipeHandle pipe) { | 3707 mojo::ScopedMessagePipeHandle pipe) { |
| 3703 GetRemoteInterfaces()->GetInterface(interface_name, std::move(pipe)); | 3708 GetRemoteInterfaces()->GetInterface(interface_name, std::move(pipe)); |
| 3704 } | 3709 } |
| 3705 #endif | 3710 #endif |
| 3706 | 3711 |
| 3707 } // namespace content | 3712 } // namespace content |
| OLD | NEW |