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 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 render_widget_host_ = new RenderWidgetHostImpl(rwh_delegate, GetProcess(), | 439 render_widget_host_ = new RenderWidgetHostImpl(rwh_delegate, GetProcess(), |
440 widget_routing_id, hidden); | 440 widget_routing_id, hidden); |
441 render_widget_host_->set_owned_by_render_frame_host(true); | 441 render_widget_host_->set_owned_by_render_frame_host(true); |
442 } else { | 442 } else { |
443 DCHECK(!render_widget_host_->owned_by_render_frame_host()); | 443 DCHECK(!render_widget_host_->owned_by_render_frame_host()); |
444 } | 444 } |
445 InputRouterImpl* ir = | 445 InputRouterImpl* ir = |
446 static_cast<InputRouterImpl*>(render_widget_host_->input_router()); | 446 static_cast<InputRouterImpl*>(render_widget_host_->input_router()); |
447 ir->SetFrameTreeNodeId(frame_tree_node_->frame_tree_node_id()); | 447 ir->SetFrameTreeNodeId(frame_tree_node_->frame_tree_node_id()); |
448 } | 448 } |
| 449 ResetFeaturePolicy(); |
449 } | 450 } |
450 | 451 |
451 RenderFrameHostImpl::~RenderFrameHostImpl() { | 452 RenderFrameHostImpl::~RenderFrameHostImpl() { |
452 // Destroying navigation handle may call into delegates/observers, | 453 // Destroying navigation handle may call into delegates/observers, |
453 // so we do it early while |this| object is still in a sane state. | 454 // so we do it early while |this| object is still in a sane state. |
454 navigation_handle_.reset(); | 455 navigation_handle_.reset(); |
455 | 456 |
456 // Release the WebUI instances before all else as the WebUI may accesses the | 457 // Release the WebUI instances before all else as the WebUI may accesses the |
457 // RenderFrameHost during cleanup. | 458 // RenderFrameHost during cleanup. |
458 ClearAllWebUI(); | 459 ClearAllWebUI(); |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeOpener, OnDidChangeOpener) | 772 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeOpener, OnDidChangeOpener) |
772 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeName, OnDidChangeName) | 773 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeName, OnDidChangeName) |
773 IPC_MESSAGE_HANDLER(FrameHostMsg_DidSetFeaturePolicyHeader, | 774 IPC_MESSAGE_HANDLER(FrameHostMsg_DidSetFeaturePolicyHeader, |
774 OnDidSetFeaturePolicyHeader) | 775 OnDidSetFeaturePolicyHeader) |
775 IPC_MESSAGE_HANDLER(FrameHostMsg_DidAddContentSecurityPolicies, | 776 IPC_MESSAGE_HANDLER(FrameHostMsg_DidAddContentSecurityPolicies, |
776 OnDidAddContentSecurityPolicies) | 777 OnDidAddContentSecurityPolicies) |
777 IPC_MESSAGE_HANDLER(FrameHostMsg_EnforceInsecureRequestPolicy, | 778 IPC_MESSAGE_HANDLER(FrameHostMsg_EnforceInsecureRequestPolicy, |
778 OnEnforceInsecureRequestPolicy) | 779 OnEnforceInsecureRequestPolicy) |
779 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateToUniqueOrigin, | 780 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateToUniqueOrigin, |
780 OnUpdateToUniqueOrigin) | 781 OnUpdateToUniqueOrigin) |
781 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeSandboxFlags, | 782 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeFramePolicy, |
782 OnDidChangeSandboxFlags) | 783 OnDidChangeFramePolicy) |
783 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeFrameOwnerProperties, | 784 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeFrameOwnerProperties, |
784 OnDidChangeFrameOwnerProperties) | 785 OnDidChangeFrameOwnerProperties) |
785 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateTitle, OnUpdateTitle) | 786 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateTitle, OnUpdateTitle) |
786 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateEncoding, OnUpdateEncoding) | 787 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateEncoding, OnUpdateEncoding) |
787 IPC_MESSAGE_HANDLER(FrameHostMsg_BeginNavigation, | 788 IPC_MESSAGE_HANDLER(FrameHostMsg_BeginNavigation, |
788 OnBeginNavigation) | 789 OnBeginNavigation) |
789 IPC_MESSAGE_HANDLER(FrameHostMsg_AbortNavigation, OnAbortNavigation) | 790 IPC_MESSAGE_HANDLER(FrameHostMsg_AbortNavigation, OnAbortNavigation) |
790 IPC_MESSAGE_HANDLER(FrameHostMsg_DispatchLoad, OnDispatchLoad) | 791 IPC_MESSAGE_HANDLER(FrameHostMsg_DispatchLoad, OnDispatchLoad) |
791 IPC_MESSAGE_HANDLER(FrameHostMsg_TextSurroundingSelectionResponse, | 792 IPC_MESSAGE_HANDLER(FrameHostMsg_TextSurroundingSelectionResponse, |
792 OnTextSurroundingSelectionResponse) | 793 OnTextSurroundingSelectionResponse) |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1090 << ")"; | 1091 << ")"; |
1091 } | 1092 } |
1092 } | 1093 } |
1093 | 1094 |
1094 void RenderFrameHostImpl::OnCreateChildFrame( | 1095 void RenderFrameHostImpl::OnCreateChildFrame( |
1095 int new_routing_id, | 1096 int new_routing_id, |
1096 blink::WebTreeScopeType scope, | 1097 blink::WebTreeScopeType scope, |
1097 const std::string& frame_name, | 1098 const std::string& frame_name, |
1098 const std::string& frame_unique_name, | 1099 const std::string& frame_unique_name, |
1099 blink::WebSandboxFlags sandbox_flags, | 1100 blink::WebSandboxFlags sandbox_flags, |
| 1101 const ParsedFeaturePolicyHeader& container_policy, |
1100 const FrameOwnerProperties& frame_owner_properties) { | 1102 const FrameOwnerProperties& frame_owner_properties) { |
1101 // TODO(lukasza): Call ReceivedBadMessage when |frame_unique_name| is empty. | 1103 // TODO(lukasza): Call ReceivedBadMessage when |frame_unique_name| is empty. |
1102 DCHECK(!frame_unique_name.empty()); | 1104 DCHECK(!frame_unique_name.empty()); |
1103 | 1105 |
1104 // The RenderFrame corresponding to this host sent an IPC message to create a | 1106 // The RenderFrame corresponding to this host sent an IPC message to create a |
1105 // child, but by the time we get here, it's possible for the host to have been | 1107 // child, but by the time we get here, it's possible for the host to have been |
1106 // swapped out, or for its process to have disconnected (maybe due to browser | 1108 // swapped out, or for its process to have disconnected (maybe due to browser |
1107 // shutdown). Ignore such messages. | 1109 // shutdown). Ignore such messages. |
1108 if (!is_active() || frame_tree_node_->current_frame_host() != this || | 1110 if (!is_active() || frame_tree_node_->current_frame_host() != this || |
1109 !render_frame_created_) | 1111 !render_frame_created_) |
1110 return; | 1112 return; |
1111 | 1113 |
1112 frame_tree_->AddFrame( | 1114 frame_tree_->AddFrame(frame_tree_node_, GetProcess()->GetID(), new_routing_id, |
1113 frame_tree_node_, GetProcess()->GetID(), new_routing_id, scope, | 1115 scope, frame_name, frame_unique_name, sandbox_flags, |
1114 frame_name, frame_unique_name, sandbox_flags, frame_owner_properties); | 1116 container_policy, frame_owner_properties); |
1115 } | 1117 } |
1116 | 1118 |
1117 void RenderFrameHostImpl::OnCreateNewWindow( | 1119 void RenderFrameHostImpl::OnCreateNewWindow( |
1118 int32_t render_view_route_id, | 1120 int32_t render_view_route_id, |
1119 int32_t main_frame_route_id, | 1121 int32_t main_frame_route_id, |
1120 int32_t main_frame_widget_route_id, | 1122 int32_t main_frame_widget_route_id, |
1121 const mojom::CreateNewWindowParams& params, | 1123 const mojom::CreateNewWindowParams& params, |
1122 SessionStorageNamespace* session_storage_namespace) { | 1124 SessionStorageNamespace* session_storage_namespace) { |
1123 mojom::CreateNewWindowParamsPtr validated_params(params.Clone()); | 1125 mojom::CreateNewWindowParamsPtr validated_params(params.Clone()); |
1124 GetProcess()->FilterURL(false, &validated_params->target_url); | 1126 GetProcess()->FilterURL(false, &validated_params->target_url); |
(...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1980 GetProcess()->GetID(), child_frame_routing_id); | 1982 GetProcess()->GetID(), child_frame_routing_id); |
1981 // A race can result in |child| to be nullptr. Avoid killing the renderer in | 1983 // A race can result in |child| to be nullptr. Avoid killing the renderer in |
1982 // that case. | 1984 // that case. |
1983 if (child && child->parent() != frame_tree_node()) { | 1985 if (child && child->parent() != frame_tree_node()) { |
1984 bad_message::ReceivedBadMessage(GetProcess(), reason); | 1986 bad_message::ReceivedBadMessage(GetProcess(), reason); |
1985 return nullptr; | 1987 return nullptr; |
1986 } | 1988 } |
1987 return child; | 1989 return child; |
1988 } | 1990 } |
1989 | 1991 |
1990 void RenderFrameHostImpl::OnDidChangeSandboxFlags( | 1992 void RenderFrameHostImpl::OnDidChangeFramePolicy( |
1991 int32_t frame_routing_id, | 1993 int32_t frame_routing_id, |
1992 blink::WebSandboxFlags flags) { | 1994 blink::WebSandboxFlags flags, |
1993 // Ensure that a frame can only update sandbox flags for its immediate | 1995 const ParsedFeaturePolicyHeader& container_policy) { |
1994 // children. If this is not the case, the renderer is considered malicious | 1996 // Ensure that a frame can only update sandbox flags or feature policy for its |
1995 // and is killed. | 1997 // immediate children. If this is not the case, the renderer is considered |
| 1998 // malicious and is killed. |
1996 FrameTreeNode* child = FindAndVerifyChild( | 1999 FrameTreeNode* child = FindAndVerifyChild( |
| 2000 // TODO(iclelland): Rename this message |
1997 frame_routing_id, bad_message::RFH_SANDBOX_FLAGS); | 2001 frame_routing_id, bad_message::RFH_SANDBOX_FLAGS); |
1998 if (!child) | 2002 if (!child) |
1999 return; | 2003 return; |
2000 | 2004 |
2001 child->SetPendingSandboxFlags(flags); | 2005 child->SetPendingSandboxFlags(flags); |
| 2006 child->SetPendingContainerPolicy(container_policy); |
2002 | 2007 |
2003 // Notify the RenderFrame if it lives in a different process from its | 2008 // Notify the RenderFrame if it lives in a different process from its parent. |
2004 // parent. The frame's proxies in other processes also need to learn about | 2009 // The frame's proxies in other processes also need to learn about the updated |
2005 // the updated sandbox flags, but these notifications are sent later in | 2010 // flags and policy, but these notifications are sent later in |
2006 // RenderFrameHostManager::CommitPendingSandboxFlags(), when the frame | 2011 // RenderFrameHostManager::CommitPendingFramePolicy(), when the frame |
2007 // navigates and the new sandbox flags take effect. | 2012 // navigates and the new policies take effect. |
2008 RenderFrameHost* child_rfh = child->current_frame_host(); | 2013 RenderFrameHost* child_rfh = child->current_frame_host(); |
2009 if (child_rfh->GetSiteInstance() != GetSiteInstance()) { | 2014 if (child_rfh->GetSiteInstance() != GetSiteInstance()) { |
2010 child_rfh->Send( | 2015 child_rfh->Send(new FrameMsg_DidUpdateFramePolicy(child_rfh->GetRoutingID(), |
2011 new FrameMsg_DidUpdateSandboxFlags(child_rfh->GetRoutingID(), flags)); | 2016 flags, container_policy)); |
2012 } | 2017 } |
2013 } | 2018 } |
2014 | 2019 |
2015 void RenderFrameHostImpl::OnDidChangeFrameOwnerProperties( | 2020 void RenderFrameHostImpl::OnDidChangeFrameOwnerProperties( |
2016 int32_t frame_routing_id, | 2021 int32_t frame_routing_id, |
2017 const FrameOwnerProperties& properties) { | 2022 const FrameOwnerProperties& properties) { |
2018 FrameTreeNode* child = FindAndVerifyChild( | 2023 FrameTreeNode* child = FindAndVerifyChild( |
2019 frame_routing_id, bad_message::RFH_OWNER_PROPERTY); | 2024 frame_routing_id, bad_message::RFH_OWNER_PROPERTY); |
2020 if (!child) | 2025 if (!child) |
2021 return; | 2026 return; |
(...skipping 1469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3491 return web_bluetooth_service == service.get(); | 3496 return web_bluetooth_service == service.get(); |
3492 }); | 3497 }); |
3493 DCHECK(it != web_bluetooth_services_.end()); | 3498 DCHECK(it != web_bluetooth_services_.end()); |
3494 web_bluetooth_services_.erase(it); | 3499 web_bluetooth_services_.erase(it); |
3495 } | 3500 } |
3496 | 3501 |
3497 void RenderFrameHostImpl::ResetFeaturePolicy() { | 3502 void RenderFrameHostImpl::ResetFeaturePolicy() { |
3498 RenderFrameHostImpl* parent_frame_host = GetParent(); | 3503 RenderFrameHostImpl* parent_frame_host = GetParent(); |
3499 const FeaturePolicy* parent_policy = | 3504 const FeaturePolicy* parent_policy = |
3500 parent_frame_host ? parent_frame_host->get_feature_policy() : nullptr; | 3505 parent_frame_host ? parent_frame_host->get_feature_policy() : nullptr; |
3501 // TODO(iclelland): Get the frame owner properties here to reset properly. | 3506 ParsedFeaturePolicyHeader container_policy = |
3502 ParsedFeaturePolicyHeader container_policy; | 3507 frame_tree_node()->effective_container_policy(); |
3503 feature_policy_ = FeaturePolicy::CreateFromParentPolicy( | 3508 feature_policy_ = FeaturePolicy::CreateFromParentPolicy( |
3504 parent_policy, container_policy, last_committed_origin_); | 3509 parent_policy, container_policy, last_committed_origin_); |
3505 } | 3510 } |
3506 | 3511 |
3507 void RenderFrameHostImpl::Create( | 3512 void RenderFrameHostImpl::Create( |
3508 const service_manager::Identity& remote_identity, | 3513 const service_manager::Identity& remote_identity, |
3509 media::mojom::InterfaceFactoryRequest request) { | 3514 media::mojom::InterfaceFactoryRequest request) { |
3510 DCHECK(!media_interface_proxy_); | 3515 DCHECK(!media_interface_proxy_); |
3511 media_interface_proxy_.reset(new MediaInterfaceProxy( | 3516 media_interface_proxy_.reset(new MediaInterfaceProxy( |
3512 this, std::move(request), | 3517 this, std::move(request), |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3664 } | 3669 } |
3665 | 3670 |
3666 void RenderFrameHostImpl::ForwardGetInterfaceToRenderFrame( | 3671 void RenderFrameHostImpl::ForwardGetInterfaceToRenderFrame( |
3667 const std::string& interface_name, | 3672 const std::string& interface_name, |
3668 mojo::ScopedMessagePipeHandle pipe) { | 3673 mojo::ScopedMessagePipeHandle pipe) { |
3669 GetRemoteInterfaces()->GetInterface(interface_name, std::move(pipe)); | 3674 GetRemoteInterfaces()->GetInterface(interface_name, std::move(pipe)); |
3670 } | 3675 } |
3671 #endif | 3676 #endif |
3672 | 3677 |
3673 } // namespace content | 3678 } // namespace content |
OLD | NEW |