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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 #include "content/public/browser/browser_thread.h" | 75 #include "content/public/browser/browser_thread.h" |
76 #include "content/public/browser/content_browser_client.h" | 76 #include "content/public/browser/content_browser_client.h" |
77 #include "content/public/browser/permission_manager.h" | 77 #include "content/public/browser/permission_manager.h" |
78 #include "content/public/browser/permission_type.h" | 78 #include "content/public/browser/permission_type.h" |
79 #include "content/public/browser/render_process_host.h" | 79 #include "content/public/browser/render_process_host.h" |
80 #include "content/public/browser/render_widget_host_view.h" | 80 #include "content/public/browser/render_widget_host_view.h" |
81 #include "content/public/browser/resource_context.h" | 81 #include "content/public/browser/resource_context.h" |
82 #include "content/public/browser/storage_partition.h" | 82 #include "content/public/browser/storage_partition.h" |
83 #include "content/public/browser/stream_handle.h" | 83 #include "content/public/browser/stream_handle.h" |
84 #include "content/public/browser/user_metrics.h" | 84 #include "content/public/browser/user_metrics.h" |
85 #include "content/public/common/bindings_policy.h" | |
85 #include "content/public/common/browser_side_navigation_policy.h" | 86 #include "content/public/common/browser_side_navigation_policy.h" |
86 #include "content/public/common/content_constants.h" | 87 #include "content/public/common/content_constants.h" |
87 #include "content/public/common/content_features.h" | 88 #include "content/public/common/content_features.h" |
88 #include "content/public/common/content_switches.h" | 89 #include "content/public/common/content_switches.h" |
89 #include "content/public/common/file_chooser_file_info.h" | 90 #include "content/public/common/file_chooser_file_info.h" |
90 #include "content/public/common/file_chooser_params.h" | 91 #include "content/public/common/file_chooser_params.h" |
91 #include "content/public/common/form_field_data.h" | 92 #include "content/public/common/form_field_data.h" |
92 #include "content/public/common/isolated_world_ids.h" | 93 #include "content/public/common/isolated_world_ids.h" |
93 #include "content/public/common/service_manager_connection.h" | 94 #include "content/public/common/service_manager_connection.h" |
94 #include "content/public/common/service_names.mojom.h" | 95 #include "content/public/common/service_names.mojom.h" |
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
946 if (created) { | 947 if (created) { |
947 SetUpMojoIfNeeded(); | 948 SetUpMojoIfNeeded(); |
948 delegate_->RenderFrameCreated(this); | 949 delegate_->RenderFrameCreated(this); |
949 } else { | 950 } else { |
950 delegate_->RenderFrameDeleted(this); | 951 delegate_->RenderFrameDeleted(this); |
951 } | 952 } |
952 } | 953 } |
953 | 954 |
954 if (created && render_widget_host_) | 955 if (created && render_widget_host_) |
955 render_widget_host_->InitForFrame(); | 956 render_widget_host_->InitForFrame(); |
957 | |
958 if (enabled_bindings_) { | |
Charlie Reis
2017/01/18 22:18:43
Should this also check |created|? I'm guessing we
Sam McNally
2017/01/19 05:30:37
Done.
| |
959 if (!frame_bindings_control_) | |
960 GetRemoteAssociatedInterfaces()->GetInterface(&frame_bindings_control_); | |
961 frame_bindings_control_->AllowBindings(enabled_bindings_); | |
962 } | |
956 } | 963 } |
957 | 964 |
958 void RenderFrameHostImpl::Init() { | 965 void RenderFrameHostImpl::Init() { |
959 ResourceDispatcherHost::ResumeBlockedRequestsForFrameFromUI(this); | 966 ResourceDispatcherHost::ResumeBlockedRequestsForFrameFromUI(this); |
960 if (!waiting_for_init_) | 967 if (!waiting_for_init_) |
961 return; | 968 return; |
962 | 969 |
963 waiting_for_init_ = false; | 970 waiting_for_init_ = false; |
964 if (pendinging_navigate_) { | 971 if (pendinging_navigate_) { |
965 frame_tree_node()->navigator()->OnBeginNavigation( | 972 frame_tree_node()->navigator()->OnBeginNavigation( |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1011 // TODO(lukasza): Call ReceivedBadMessage when |frame_unique_name| is empty. | 1018 // TODO(lukasza): Call ReceivedBadMessage when |frame_unique_name| is empty. |
1012 DCHECK(!frame_unique_name.empty()); | 1019 DCHECK(!frame_unique_name.empty()); |
1013 | 1020 |
1014 // It is possible that while a new RenderFrameHost was committed, the | 1021 // It is possible that while a new RenderFrameHost was committed, the |
1015 // RenderFrame corresponding to this host sent an IPC message to create a | 1022 // RenderFrame corresponding to this host sent an IPC message to create a |
1016 // frame and it is delivered after this host is swapped out. | 1023 // frame and it is delivered after this host is swapped out. |
1017 // Ignore such messages, as we know this RenderFrameHost is going away. | 1024 // Ignore such messages, as we know this RenderFrameHost is going away. |
1018 if (!is_active() || frame_tree_node_->current_frame_host() != this) | 1025 if (!is_active() || frame_tree_node_->current_frame_host() != this) |
1019 return; | 1026 return; |
1020 | 1027 |
1021 frame_tree_->AddFrame(frame_tree_node_, GetProcess()->GetID(), new_routing_id, | 1028 bool added = frame_tree_->AddFrame( |
Charlie Reis
2017/01/18 22:18:43
Note that AddFrame already calls SetRenderFrameCre
Sam McNally
2017/01/19 05:30:37
Done.
Charlie Reis
2017/01/19 17:58:55
Thanks! That looks better.
| |
1022 scope, frame_name, frame_unique_name, sandbox_flags, | 1029 frame_tree_node_, GetProcess()->GetID(), new_routing_id, scope, |
1023 frame_owner_properties); | 1030 frame_name, frame_unique_name, sandbox_flags, frame_owner_properties); |
1031 | |
1032 if (added && enabled_bindings_) { | |
1033 frame_tree_->FindByRoutingID(GetProcess()->GetID(), new_routing_id) | |
1034 ->current_frame_host() | |
1035 ->AllowBindings(enabled_bindings_); | |
1036 } | |
1024 } | 1037 } |
1025 | 1038 |
1026 void RenderFrameHostImpl::OnCreateNewWindow( | 1039 void RenderFrameHostImpl::OnCreateNewWindow( |
1027 int32_t render_view_route_id, | 1040 int32_t render_view_route_id, |
1028 int32_t main_frame_route_id, | 1041 int32_t main_frame_route_id, |
1029 int32_t main_frame_widget_route_id, | 1042 int32_t main_frame_widget_route_id, |
1030 const mojom::CreateNewWindowParams& params, | 1043 const mojom::CreateNewWindowParams& params, |
1031 SessionStorageNamespace* session_storage_namespace) { | 1044 SessionStorageNamespace* session_storage_namespace) { |
1032 mojom::CreateNewWindowParamsPtr validated_params(params.Clone()); | 1045 mojom::CreateNewWindowParamsPtr validated_params(params.Clone()); |
1033 GetProcess()->FilterURL(false, &validated_params->target_url); | 1046 GetProcess()->FilterURL(false, &validated_params->target_url); |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1337 } | 1350 } |
1338 | 1351 |
1339 RenderWidgetHostView* RenderFrameHostImpl::GetView() { | 1352 RenderWidgetHostView* RenderFrameHostImpl::GetView() { |
1340 return GetRenderWidgetHost()->GetView(); | 1353 return GetRenderWidgetHost()->GetView(); |
1341 } | 1354 } |
1342 | 1355 |
1343 GlobalFrameRoutingId RenderFrameHostImpl::GetGlobalFrameRoutingId() { | 1356 GlobalFrameRoutingId RenderFrameHostImpl::GetGlobalFrameRoutingId() { |
1344 return GlobalFrameRoutingId(GetProcess()->GetID(), GetRoutingID()); | 1357 return GlobalFrameRoutingId(GetProcess()->GetID(), GetRoutingID()); |
1345 } | 1358 } |
1346 | 1359 |
1347 int RenderFrameHostImpl::GetEnabledBindings() { | |
1348 return render_view_host_->GetEnabledBindings(); | |
1349 } | |
1350 | |
1351 void RenderFrameHostImpl::SetNavigationHandle( | 1360 void RenderFrameHostImpl::SetNavigationHandle( |
1352 std::unique_ptr<NavigationHandleImpl> navigation_handle) { | 1361 std::unique_ptr<NavigationHandleImpl> navigation_handle) { |
1353 navigation_handle_ = std::move(navigation_handle); | 1362 navigation_handle_ = std::move(navigation_handle); |
1354 | 1363 |
1355 // TODO(clamy): Remove this debug code once we understand better how we get to | 1364 // TODO(clamy): Remove this debug code once we understand better how we get to |
1356 // the point of attempting to transfer a navigation from a RFH that is no | 1365 // the point of attempting to transfer a navigation from a RFH that is no |
1357 // longer active. | 1366 // longer active. |
1358 if (navigation_handle_ && !is_active()) | 1367 if (navigation_handle_ && !is_active()) |
1359 base::debug::DumpWithoutCrashing(); | 1368 base::debug::DumpWithoutCrashing(); |
1360 } | 1369 } |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1723 } | 1732 } |
1724 | 1733 |
1725 void RenderFrameHostImpl::RequestFocusedFormFieldData( | 1734 void RenderFrameHostImpl::RequestFocusedFormFieldData( |
1726 FormFieldDataCallback& callback) { | 1735 FormFieldDataCallback& callback) { |
1727 static int next_id = 1; | 1736 static int next_id = 1; |
1728 int request_id = ++next_id; | 1737 int request_id = ++next_id; |
1729 form_field_data_callbacks_[request_id] = callback; | 1738 form_field_data_callbacks_[request_id] = callback; |
1730 Send(new FrameMsg_FocusedFormFieldDataRequest(GetRoutingID(), request_id)); | 1739 Send(new FrameMsg_FocusedFormFieldDataRequest(GetRoutingID(), request_id)); |
1731 } | 1740 } |
1732 | 1741 |
1742 void RenderFrameHostImpl::AllowBindings(int bindings_flags) { | |
1743 // Never grant any bindings to browser plugin guests. | |
1744 if (GetProcess()->IsForGuestsOnly()) { | |
1745 NOTREACHED() << "Never grant bindings to a guest process."; | |
1746 return; | |
1747 } | |
1748 | |
1749 // Ensure we aren't granting WebUI bindings to a process that has already | |
1750 // been used for non-privileged views. | |
1751 if (bindings_flags & BINDINGS_POLICY_WEB_UI && | |
1752 GetProcess()->HasConnection() && | |
1753 !ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( | |
1754 GetProcess()->GetID())) { | |
1755 // This process has no bindings yet. Make sure it does not have more | |
1756 // than this single active view. | |
1757 // --single-process only has one renderer. | |
1758 if (GetProcess()->GetActiveViewCount() > 1 && | |
1759 !base::CommandLine::ForCurrentProcess()->HasSwitch( | |
1760 switches::kSingleProcess)) | |
1761 return; | |
1762 } | |
1763 | |
1764 if (bindings_flags & BINDINGS_POLICY_WEB_UI) { | |
1765 ChildProcessSecurityPolicyImpl::GetInstance()->GrantWebUIBindings( | |
1766 GetProcess()->GetID()); | |
1767 } | |
1768 | |
1769 enabled_bindings_ |= bindings_flags; | |
1770 if (GetParent()) | |
1771 DCHECK_EQ(GetParent()->GetEnabledBindings(), GetEnabledBindings()); | |
1772 | |
1773 if (render_frame_created_) { | |
1774 if (!frame_bindings_control_) | |
1775 GetRemoteAssociatedInterfaces()->GetInterface(&frame_bindings_control_); | |
1776 frame_bindings_control_->AllowBindings(enabled_bindings_); | |
1777 } | |
1778 } | |
1779 | |
1780 int RenderFrameHostImpl::GetEnabledBindings() const { | |
1781 return enabled_bindings_; | |
1782 } | |
1783 | |
1733 void RenderFrameHostImpl::OnFocusedFormFieldDataResponse( | 1784 void RenderFrameHostImpl::OnFocusedFormFieldDataResponse( |
1734 int request_id, | 1785 int request_id, |
1735 const FormFieldData& field_data) { | 1786 const FormFieldData& field_data) { |
1736 auto it = form_field_data_callbacks_.find(request_id); | 1787 auto it = form_field_data_callbacks_.find(request_id); |
1737 if (it != form_field_data_callbacks_.end()) { | 1788 if (it != form_field_data_callbacks_.end()) { |
1738 it->second.Run(field_data); | 1789 it->second.Run(field_data); |
1739 form_field_data_callbacks_.erase(it); | 1790 form_field_data_callbacks_.erase(it); |
1740 } | 1791 } |
1741 } | 1792 } |
1742 | 1793 |
(...skipping 970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2713 BrowserContext::GetServiceManagerConnectionFor( | 2764 BrowserContext::GetServiceManagerConnectionFor( |
2714 GetProcess()->GetBrowserContext()); | 2765 GetProcess()->GetBrowserContext()); |
2715 // |service_manager_connection| may be null in tests using TestBrowserContext. | 2766 // |service_manager_connection| may be null in tests using TestBrowserContext. |
2716 if (service_manager_connection) { | 2767 if (service_manager_connection) { |
2717 service_manager_connection->RemoveOnConnectHandler(on_connect_handler_id_); | 2768 service_manager_connection->RemoveOnConnectHandler(on_connect_handler_id_); |
2718 on_connect_handler_id_ = 0; | 2769 on_connect_handler_id_ = 0; |
2719 } | 2770 } |
2720 | 2771 |
2721 frame_.reset(); | 2772 frame_.reset(); |
2722 frame_host_binding_.Close(); | 2773 frame_host_binding_.Close(); |
2774 frame_bindings_control_.reset(); | |
2723 | 2775 |
2724 // Disconnect with ImageDownloader Mojo service in RenderFrame. | 2776 // Disconnect with ImageDownloader Mojo service in RenderFrame. |
2725 mojo_image_downloader_.reset(); | 2777 mojo_image_downloader_.reset(); |
2726 } | 2778 } |
2727 | 2779 |
2728 bool RenderFrameHostImpl::IsFocused() { | 2780 bool RenderFrameHostImpl::IsFocused() { |
2729 return GetRenderWidgetHost()->is_focused() && | 2781 return GetRenderWidgetHost()->is_focused() && |
2730 frame_tree_->GetFocusedFrame() && | 2782 frame_tree_->GetFocusedFrame() && |
2731 (frame_tree_->GetFocusedFrame() == frame_tree_node() || | 2783 (frame_tree_->GetFocusedFrame() == frame_tree_node() || |
2732 frame_tree_->GetFocusedFrame()->IsDescendantOf(frame_tree_node())); | 2784 frame_tree_->GetFocusedFrame()->IsDescendantOf(frame_tree_node())); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2771 base::UserMetricsAction("ProcessSwapBindingsMismatch_RVHM")); | 2823 base::UserMetricsAction("ProcessSwapBindingsMismatch_RVHM")); |
2772 ClearPendingWebUI(); | 2824 ClearPendingWebUI(); |
2773 } | 2825 } |
2774 } | 2826 } |
2775 } | 2827 } |
2776 DCHECK_EQ(!pending_web_ui_, pending_web_ui_type_ == WebUI::kNoWebUI); | 2828 DCHECK_EQ(!pending_web_ui_, pending_web_ui_type_ == WebUI::kNoWebUI); |
2777 | 2829 |
2778 // Either grant or check the RenderViewHost with/for proper bindings. | 2830 // Either grant or check the RenderViewHost with/for proper bindings. |
2779 if (pending_web_ui_ && !render_view_host_->GetProcess()->IsForGuestsOnly()) { | 2831 if (pending_web_ui_ && !render_view_host_->GetProcess()->IsForGuestsOnly()) { |
2780 // If a WebUI was created for the URL and the RenderView is not in a guest | 2832 // If a WebUI was created for the URL and the RenderView is not in a guest |
2781 // process, then enable missing bindings with the RenderViewHost. | 2833 // process, then enable missing bindings with the RenderViewHost. |
Charlie Reis
2017/01/18 22:18:43
nit: Drop "with the RenderViewHost."
Sam McNally
2017/01/19 05:30:37
Done.
| |
2782 int new_bindings = pending_web_ui_->GetBindings(); | 2834 int new_bindings = pending_web_ui_->GetBindings(); |
2783 if ((render_view_host_->GetEnabledBindings() & new_bindings) != | 2835 if ((GetEnabledBindings() & new_bindings) != new_bindings) { |
2784 new_bindings) { | 2836 AllowBindings(new_bindings); |
2785 render_view_host_->AllowBindings(new_bindings); | |
2786 } | 2837 } |
2787 } else if (render_view_host_->is_active()) { | 2838 } else if (render_view_host_->is_active()) { |
2788 // If the ongoing navigation is not to a WebUI or the RenderView is in a | 2839 // If the ongoing navigation is not to a WebUI or the RenderView is in a |
2789 // guest process, ensure that we don't create an unprivileged RenderView in | 2840 // guest process, ensure that we don't create an unprivileged RenderView in |
2790 // a WebUI-enabled process unless it's swapped out. | 2841 // a WebUI-enabled process unless it's swapped out. |
2791 bool url_acceptable_for_webui = | 2842 bool url_acceptable_for_webui = |
2792 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI( | 2843 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI( |
2793 GetSiteInstance()->GetBrowserContext(), dest_url); | 2844 GetSiteInstance()->GetBrowserContext(), dest_url); |
2794 if (!url_acceptable_for_webui) { | 2845 if (!url_acceptable_for_webui) { |
2795 CHECK(!ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( | 2846 CHECK(!ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3384 // There is no pending NavigationEntry in these cases, so pass 0 as the | 3435 // There is no pending NavigationEntry in these cases, so pass 0 as the |
3385 // pending_nav_entry_id. If the previous handle was a prematurely aborted | 3436 // pending_nav_entry_id. If the previous handle was a prematurely aborted |
3386 // navigation loaded via LoadDataWithBaseURL, propagate the entry id. | 3437 // navigation loaded via LoadDataWithBaseURL, propagate the entry id. |
3387 return NavigationHandleImpl::Create( | 3438 return NavigationHandleImpl::Create( |
3388 params.url, frame_tree_node_, is_renderer_initiated, | 3439 params.url, frame_tree_node_, is_renderer_initiated, |
3389 params.was_within_same_page, base::TimeTicks::Now(), | 3440 params.was_within_same_page, base::TimeTicks::Now(), |
3390 entry_id_for_data_nav, false); // started_from_context_menu | 3441 entry_id_for_data_nav, false); // started_from_context_menu |
3391 } | 3442 } |
3392 | 3443 |
3393 } // namespace content | 3444 } // namespace content |
OLD | NEW |