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 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
775 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeOpener, OnDidChangeOpener) | 776 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeOpener, OnDidChangeOpener) |
776 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeName, OnDidChangeName) | 777 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeName, OnDidChangeName) |
777 IPC_MESSAGE_HANDLER(FrameHostMsg_DidSetFeaturePolicyHeader, | 778 IPC_MESSAGE_HANDLER(FrameHostMsg_DidSetFeaturePolicyHeader, |
778 OnDidSetFeaturePolicyHeader) | 779 OnDidSetFeaturePolicyHeader) |
779 IPC_MESSAGE_HANDLER(FrameHostMsg_DidAddContentSecurityPolicies, | 780 IPC_MESSAGE_HANDLER(FrameHostMsg_DidAddContentSecurityPolicies, |
780 OnDidAddContentSecurityPolicies) | 781 OnDidAddContentSecurityPolicies) |
781 IPC_MESSAGE_HANDLER(FrameHostMsg_EnforceInsecureRequestPolicy, | 782 IPC_MESSAGE_HANDLER(FrameHostMsg_EnforceInsecureRequestPolicy, |
782 OnEnforceInsecureRequestPolicy) | 783 OnEnforceInsecureRequestPolicy) |
783 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateToUniqueOrigin, | 784 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateToUniqueOrigin, |
784 OnUpdateToUniqueOrigin) | 785 OnUpdateToUniqueOrigin) |
785 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeSandboxFlags, | 786 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeFramePolicy, |
786 OnDidChangeSandboxFlags) | 787 OnDidChangeFramePolicy) |
787 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeFrameOwnerProperties, | 788 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeFrameOwnerProperties, |
788 OnDidChangeFrameOwnerProperties) | 789 OnDidChangeFrameOwnerProperties) |
789 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateTitle, OnUpdateTitle) | 790 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateTitle, OnUpdateTitle) |
790 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateEncoding, OnUpdateEncoding) | 791 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateEncoding, OnUpdateEncoding) |
791 IPC_MESSAGE_HANDLER(FrameHostMsg_BeginNavigation, | 792 IPC_MESSAGE_HANDLER(FrameHostMsg_BeginNavigation, |
792 OnBeginNavigation) | 793 OnBeginNavigation) |
793 IPC_MESSAGE_HANDLER(FrameHostMsg_AbortNavigation, OnAbortNavigation) | 794 IPC_MESSAGE_HANDLER(FrameHostMsg_AbortNavigation, OnAbortNavigation) |
794 IPC_MESSAGE_HANDLER(FrameHostMsg_DispatchLoad, OnDispatchLoad) | 795 IPC_MESSAGE_HANDLER(FrameHostMsg_DispatchLoad, OnDispatchLoad) |
795 IPC_MESSAGE_HANDLER(FrameHostMsg_TextSurroundingSelectionResponse, | 796 IPC_MESSAGE_HANDLER(FrameHostMsg_TextSurroundingSelectionResponse, |
796 OnTextSurroundingSelectionResponse) | 797 OnTextSurroundingSelectionResponse) |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1094 << ")"; | 1095 << ")"; |
1095 } | 1096 } |
1096 } | 1097 } |
1097 | 1098 |
1098 void RenderFrameHostImpl::OnCreateChildFrame( | 1099 void RenderFrameHostImpl::OnCreateChildFrame( |
1099 int new_routing_id, | 1100 int new_routing_id, |
1100 blink::WebTreeScopeType scope, | 1101 blink::WebTreeScopeType scope, |
1101 const std::string& frame_name, | 1102 const std::string& frame_name, |
1102 const std::string& frame_unique_name, | 1103 const std::string& frame_unique_name, |
1103 blink::WebSandboxFlags sandbox_flags, | 1104 blink::WebSandboxFlags sandbox_flags, |
1105 const ParsedFeaturePolicyHeader& container_policy, | |
1104 const FrameOwnerProperties& frame_owner_properties) { | 1106 const FrameOwnerProperties& frame_owner_properties) { |
1105 // TODO(lukasza): Call ReceivedBadMessage when |frame_unique_name| is empty. | 1107 // TODO(lukasza): Call ReceivedBadMessage when |frame_unique_name| is empty. |
1106 DCHECK(!frame_unique_name.empty()); | 1108 DCHECK(!frame_unique_name.empty()); |
1107 | 1109 |
1108 // The RenderFrame corresponding to this host sent an IPC message to create a | 1110 // The RenderFrame corresponding to this host sent an IPC message to create a |
1109 // child, but by the time we get here, it's possible for the host to have been | 1111 // child, but by the time we get here, it's possible for the host to have been |
1110 // swapped out, or for its process to have disconnected (maybe due to browser | 1112 // swapped out, or for its process to have disconnected (maybe due to browser |
1111 // shutdown). Ignore such messages. | 1113 // shutdown). Ignore such messages. |
1112 if (!is_active() || frame_tree_node_->current_frame_host() != this || | 1114 if (!is_active() || frame_tree_node_->current_frame_host() != this || |
1113 !render_frame_created_) | 1115 !render_frame_created_) |
1114 return; | 1116 return; |
1115 | 1117 |
1116 frame_tree_->AddFrame( | 1118 frame_tree_->AddFrame(frame_tree_node_, GetProcess()->GetID(), new_routing_id, |
1117 frame_tree_node_, GetProcess()->GetID(), new_routing_id, scope, | 1119 scope, frame_name, frame_unique_name, sandbox_flags, |
1118 frame_name, frame_unique_name, sandbox_flags, frame_owner_properties); | 1120 container_policy, frame_owner_properties); |
1119 } | 1121 } |
1120 | 1122 |
1121 void RenderFrameHostImpl::OnCreateNewWindow( | 1123 void RenderFrameHostImpl::OnCreateNewWindow( |
1122 int32_t render_view_route_id, | 1124 int32_t render_view_route_id, |
1123 int32_t main_frame_route_id, | 1125 int32_t main_frame_route_id, |
1124 int32_t main_frame_widget_route_id, | 1126 int32_t main_frame_widget_route_id, |
1125 const mojom::CreateNewWindowParams& params, | 1127 const mojom::CreateNewWindowParams& params, |
1126 SessionStorageNamespace* session_storage_namespace) { | 1128 SessionStorageNamespace* session_storage_namespace) { |
1127 mojom::CreateNewWindowParamsPtr validated_params(params.Clone()); | 1129 mojom::CreateNewWindowParamsPtr validated_params(params.Clone()); |
1128 GetProcess()->FilterURL(false, &validated_params->target_url); | 1130 GetProcess()->FilterURL(false, &validated_params->target_url); |
(...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1974 GetProcess()->GetID(), child_frame_routing_id); | 1976 GetProcess()->GetID(), child_frame_routing_id); |
1975 // A race can result in |child| to be nullptr. Avoid killing the renderer in | 1977 // A race can result in |child| to be nullptr. Avoid killing the renderer in |
1976 // that case. | 1978 // that case. |
1977 if (child && child->parent() != frame_tree_node()) { | 1979 if (child && child->parent() != frame_tree_node()) { |
1978 bad_message::ReceivedBadMessage(GetProcess(), reason); | 1980 bad_message::ReceivedBadMessage(GetProcess(), reason); |
1979 return nullptr; | 1981 return nullptr; |
1980 } | 1982 } |
1981 return child; | 1983 return child; |
1982 } | 1984 } |
1983 | 1985 |
1984 void RenderFrameHostImpl::OnDidChangeSandboxFlags( | 1986 void RenderFrameHostImpl::OnDidChangeFramePolicy( |
1985 int32_t frame_routing_id, | 1987 int32_t frame_routing_id, |
1986 blink::WebSandboxFlags flags) { | 1988 blink::WebSandboxFlags flags, |
1987 // Ensure that a frame can only update sandbox flags for its immediate | 1989 const ParsedFeaturePolicyHeader& container_policy) { |
1988 // children. If this is not the case, the renderer is considered malicious | 1990 // Ensure that a frame can only update sandbox flags or feature policy for its |
1989 // and is killed. | 1991 // immediate children. If this is not the case, the renderer is considered |
1992 // malicious and is killed. | |
1990 FrameTreeNode* child = FindAndVerifyChild( | 1993 FrameTreeNode* child = FindAndVerifyChild( |
1994 // TODO(iclelland): Rename this message | |
1991 frame_routing_id, bad_message::RFH_SANDBOX_FLAGS); | 1995 frame_routing_id, bad_message::RFH_SANDBOX_FLAGS); |
1992 if (!child) | 1996 if (!child) |
1993 return; | 1997 return; |
1994 | 1998 |
1995 child->SetPendingSandboxFlags(flags); | 1999 child->SetPendingSandboxFlags(flags); |
2000 child->SetPendingContainerPolicy(container_policy); | |
1996 | 2001 |
1997 // Notify the RenderFrame if it lives in a different process from its | 2002 // Notify the RenderFrame if it lives in a different process from its parent. |
1998 // parent. The frame's proxies in other processes also need to learn about | 2003 // The frame's proxies in other processes also need to learn about the updated |
1999 // the updated sandbox flags, but these notifications are sent later in | 2004 // flags and policy, but these notifications are sent later in |
2000 // RenderFrameHostManager::CommitPendingSandboxFlags(), when the frame | 2005 // RenderFrameHostManager::CommitPendingFramePolicy(), when the frame |
2001 // navigates and the new sandbox flags take effect. | 2006 // navigates and the new policies take effect. |
2002 RenderFrameHost* child_rfh = child->current_frame_host(); | 2007 RenderFrameHost* child_rfh = child->current_frame_host(); |
2003 if (child_rfh->GetSiteInstance() != GetSiteInstance()) { | 2008 if (child_rfh->GetSiteInstance() != GetSiteInstance()) { |
2004 child_rfh->Send( | 2009 child_rfh->Send(new FrameMsg_DidUpdateFramePolicy(child_rfh->GetRoutingID(), |
2005 new FrameMsg_DidUpdateSandboxFlags(child_rfh->GetRoutingID(), flags)); | 2010 flags, container_policy)); |
2006 } | 2011 } |
2007 } | 2012 } |
2008 | 2013 |
2009 void RenderFrameHostImpl::OnDidChangeFrameOwnerProperties( | 2014 void RenderFrameHostImpl::OnDidChangeFrameOwnerProperties( |
2010 int32_t frame_routing_id, | 2015 int32_t frame_routing_id, |
2011 const FrameOwnerProperties& properties) { | 2016 const FrameOwnerProperties& properties) { |
2012 FrameTreeNode* child = FindAndVerifyChild( | 2017 FrameTreeNode* child = FindAndVerifyChild( |
2013 frame_routing_id, bad_message::RFH_OWNER_PROPERTY); | 2018 frame_routing_id, bad_message::RFH_OWNER_PROPERTY); |
2014 if (!child) | 2019 if (!child) |
2015 return; | 2020 return; |
(...skipping 1507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3523 return web_bluetooth_service == service.get(); | 3528 return web_bluetooth_service == service.get(); |
3524 }); | 3529 }); |
3525 DCHECK(it != web_bluetooth_services_.end()); | 3530 DCHECK(it != web_bluetooth_services_.end()); |
3526 web_bluetooth_services_.erase(it); | 3531 web_bluetooth_services_.erase(it); |
3527 } | 3532 } |
3528 | 3533 |
3529 void RenderFrameHostImpl::ResetFeaturePolicy() { | 3534 void RenderFrameHostImpl::ResetFeaturePolicy() { |
3530 RenderFrameHostImpl* parent_frame_host = GetParent(); | 3535 RenderFrameHostImpl* parent_frame_host = GetParent(); |
3531 const FeaturePolicy* parent_policy = | 3536 const FeaturePolicy* parent_policy = |
3532 parent_frame_host ? parent_frame_host->get_feature_policy() : nullptr; | 3537 parent_frame_host ? parent_frame_host->get_feature_policy() : nullptr; |
3533 // TODO(iclelland): Get the frame owner properties here to reset properly. | 3538 // TODO(iclelland): Get the frame owner properties here to reset properly. |
raymes
2017/04/05 05:24:38
nit: Can this be removed now?
iclelland
2017/04/05 14:51:13
Yes, thanks. Forgot to remove the comment when I T
| |
3534 ParsedFeaturePolicyHeader container_policy; | 3539 ParsedFeaturePolicyHeader container_policy = |
3540 frame_tree_node()->effective_container_policy(); | |
3535 feature_policy_ = FeaturePolicy::CreateFromParentPolicy( | 3541 feature_policy_ = FeaturePolicy::CreateFromParentPolicy( |
3536 parent_policy, container_policy, last_committed_origin_); | 3542 parent_policy, container_policy, last_committed_origin_); |
3537 } | 3543 } |
3538 | 3544 |
3539 void RenderFrameHostImpl::Create( | 3545 void RenderFrameHostImpl::Create( |
3540 const service_manager::Identity& remote_identity, | 3546 const service_manager::Identity& remote_identity, |
3541 media::mojom::InterfaceFactoryRequest request) { | 3547 media::mojom::InterfaceFactoryRequest request) { |
3542 DCHECK(!media_interface_proxy_); | 3548 DCHECK(!media_interface_proxy_); |
3543 media_interface_proxy_.reset(new MediaInterfaceProxy( | 3549 media_interface_proxy_.reset(new MediaInterfaceProxy( |
3544 this, std::move(request), | 3550 this, std::move(request), |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3678 service_manager::mojom::InterfaceProviderPtr provider; | 3684 service_manager::mojom::InterfaceProviderPtr provider; |
3679 BindInterfaceRegistryForRenderFrameHost(mojo::MakeRequest(&provider), this); | 3685 BindInterfaceRegistryForRenderFrameHost(mojo::MakeRequest(&provider), this); |
3680 java_interfaces_.reset(new service_manager::InterfaceProvider); | 3686 java_interfaces_.reset(new service_manager::InterfaceProvider); |
3681 java_interfaces_->Bind(std::move(provider)); | 3687 java_interfaces_->Bind(std::move(provider)); |
3682 } | 3688 } |
3683 return java_interfaces_.get(); | 3689 return java_interfaces_.get(); |
3684 } | 3690 } |
3685 #endif | 3691 #endif |
3686 | 3692 |
3687 } // namespace content | 3693 } // namespace content |
OLD | NEW |