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