Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: content/browser/frame_host/render_frame_host_impl.cc

Issue 1352813006: Move WebUI ownership from the RenderFrameHostManager to the RenderFrameHost. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase to fix patch errors. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/containers/hash_tables.h" 9 #include "base/containers/hash_tables.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/process/kill.h" 12 #include "base/process/kill.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "content/browser/accessibility/accessibility_mode_helper.h" 14 #include "content/browser/accessibility/accessibility_mode_helper.h"
15 #include "content/browser/accessibility/ax_tree_id_registry.h" 15 #include "content/browser/accessibility/ax_tree_id_registry.h"
16 #include "content/browser/accessibility/browser_accessibility_manager.h" 16 #include "content/browser/accessibility/browser_accessibility_manager.h"
17 #include "content/browser/accessibility/browser_accessibility_state_impl.h" 17 #include "content/browser/accessibility/browser_accessibility_state_impl.h"
18 #include "content/browser/bad_message.h" 18 #include "content/browser/bad_message.h"
19 #include "content/browser/child_process_security_policy_impl.h" 19 #include "content/browser/child_process_security_policy_impl.h"
20 #include "content/browser/child_process_security_policy_impl.h"
20 #include "content/browser/devtools/render_frame_devtools_agent_host.h" 21 #include "content/browser/devtools/render_frame_devtools_agent_host.h"
21 #include "content/browser/frame_host/cross_process_frame_connector.h" 22 #include "content/browser/frame_host/cross_process_frame_connector.h"
22 #include "content/browser/frame_host/cross_site_transferring_request.h" 23 #include "content/browser/frame_host/cross_site_transferring_request.h"
23 #include "content/browser/frame_host/frame_mojo_shell.h" 24 #include "content/browser/frame_host/frame_mojo_shell.h"
24 #include "content/browser/frame_host/frame_tree.h" 25 #include "content/browser/frame_host/frame_tree.h"
25 #include "content/browser/frame_host/frame_tree_node.h" 26 #include "content/browser/frame_host/frame_tree_node.h"
26 #include "content/browser/frame_host/navigation_handle_impl.h" 27 #include "content/browser/frame_host/navigation_handle_impl.h"
27 #include "content/browser/frame_host/navigation_request.h" 28 #include "content/browser/frame_host/navigation_request.h"
28 #include "content/browser/frame_host/navigator.h" 29 #include "content/browser/frame_host/navigator.h"
29 #include "content/browser/frame_host/navigator_impl.h" 30 #include "content/browser/frame_host/navigator_impl.h"
30 #include "content/browser/frame_host/render_frame_host_delegate.h" 31 #include "content/browser/frame_host/render_frame_host_delegate.h"
31 #include "content/browser/frame_host/render_frame_proxy_host.h" 32 #include "content/browser/frame_host/render_frame_proxy_host.h"
32 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" 33 #include "content/browser/frame_host/render_widget_host_view_child_frame.h"
33 #include "content/browser/geolocation/geolocation_service_context.h" 34 #include "content/browser/geolocation/geolocation_service_context.h"
34 #include "content/browser/permissions/permission_service_context.h" 35 #include "content/browser/permissions/permission_service_context.h"
35 #include "content/browser/permissions/permission_service_impl.h" 36 #include "content/browser/permissions/permission_service_impl.h"
36 #include "content/browser/presentation/presentation_service_impl.h" 37 #include "content/browser/presentation/presentation_service_impl.h"
37 #include "content/browser/renderer_host/input/input_router.h" 38 #include "content/browser/renderer_host/input/input_router.h"
38 #include "content/browser/renderer_host/input/timeout_monitor.h" 39 #include "content/browser/renderer_host/input/timeout_monitor.h"
39 #include "content/browser/renderer_host/render_process_host_impl.h" 40 #include "content/browser/renderer_host/render_process_host_impl.h"
40 #include "content/browser/renderer_host/render_view_host_delegate.h" 41 #include "content/browser/renderer_host/render_view_host_delegate.h"
41 #include "content/browser/renderer_host/render_view_host_delegate_view.h" 42 #include "content/browser/renderer_host/render_view_host_delegate_view.h"
42 #include "content/browser/renderer_host/render_view_host_impl.h" 43 #include "content/browser/renderer_host/render_view_host_impl.h"
43 #include "content/browser/renderer_host/render_widget_host_impl.h" 44 #include "content/browser/renderer_host/render_widget_host_impl.h"
44 #include "content/browser/renderer_host/render_widget_host_view_base.h" 45 #include "content/browser/renderer_host/render_widget_host_view_base.h"
46 #include "content/browser/webui/web_ui_controller_factory_registry.h"
45 #include "content/common/accessibility_messages.h" 47 #include "content/common/accessibility_messages.h"
46 #include "content/common/frame_messages.h" 48 #include "content/common/frame_messages.h"
47 #include "content/common/input_messages.h" 49 #include "content/common/input_messages.h"
48 #include "content/common/inter_process_time_ticks_converter.h" 50 #include "content/common/inter_process_time_ticks_converter.h"
49 #include "content/common/navigation_params.h" 51 #include "content/common/navigation_params.h"
50 #include "content/common/render_frame_setup.mojom.h" 52 #include "content/common/render_frame_setup.mojom.h"
51 #include "content/common/site_isolation_policy.h" 53 #include "content/common/site_isolation_policy.h"
52 #include "content/common/swapped_out_messages.h" 54 #include "content/common/swapped_out_messages.h"
53 #include "content/public/browser/ax_event_notification_details.h" 55 #include "content/public/browser/ax_event_notification_details.h"
54 #include "content/public/browser/browser_accessibility_state.h" 56 #include "content/public/browser/browser_accessibility_state.h"
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 routing_id_(routing_id), 188 routing_id_(routing_id),
187 render_frame_created_(false), 189 render_frame_created_(false),
188 navigations_suspended_(false), 190 navigations_suspended_(false),
189 is_waiting_for_beforeunload_ack_(false), 191 is_waiting_for_beforeunload_ack_(false),
190 unload_ack_is_for_navigation_(false), 192 unload_ack_is_for_navigation_(false),
191 is_loading_(false), 193 is_loading_(false),
192 pending_commit_(false), 194 pending_commit_(false),
193 accessibility_reset_token_(0), 195 accessibility_reset_token_(0),
194 accessibility_reset_count_(0), 196 accessibility_reset_count_(0),
195 no_create_browser_accessibility_manager_for_testing_(false), 197 no_create_browser_accessibility_manager_for_testing_(false),
198 web_ui_type_(WebUI::kNoWebUI),
196 weak_ptr_factory_(this) { 199 weak_ptr_factory_(this) {
197 bool is_swapped_out = !!(flags & CREATE_RF_SWAPPED_OUT); 200 bool is_swapped_out = !!(flags & CREATE_RF_SWAPPED_OUT);
198 bool hidden = !!(flags & CREATE_RF_HIDDEN); 201 bool hidden = !!(flags & CREATE_RF_HIDDEN);
199 frame_tree_->AddRenderViewHostRef(render_view_host_); 202 frame_tree_->AddRenderViewHostRef(render_view_host_);
200 GetProcess()->AddRoute(routing_id_, this); 203 GetProcess()->AddRoute(routing_id_, this);
201 g_routing_id_frame_map.Get().insert(std::make_pair( 204 g_routing_id_frame_map.Get().insert(std::make_pair(
202 RenderFrameHostID(GetProcess()->GetID(), routing_id_), 205 RenderFrameHostID(GetProcess()->GetID(), routing_id_),
203 this)); 206 this));
204 207
205 if (is_swapped_out) { 208 if (is_swapped_out) {
(...skipping 19 matching lines...) Expand all
225 render_widget_host_ = new RenderWidgetHostImpl(rwh_delegate, GetProcess(), 228 render_widget_host_ = new RenderWidgetHostImpl(rwh_delegate, GetProcess(),
226 widget_routing_id, hidden); 229 widget_routing_id, hidden);
227 render_widget_host_->set_owned_by_render_frame_host(true); 230 render_widget_host_->set_owned_by_render_frame_host(true);
228 } else { 231 } else {
229 DCHECK(!render_widget_host_->owned_by_render_frame_host()); 232 DCHECK(!render_widget_host_->owned_by_render_frame_host());
230 } 233 }
231 } 234 }
232 } 235 }
233 236
234 RenderFrameHostImpl::~RenderFrameHostImpl() { 237 RenderFrameHostImpl::~RenderFrameHostImpl() {
238 // Release the WebUI before all else as the WebUI accesses the RenderFrameHost
239 // during cleanup.
240 ResetWebUI();
241
235 GetProcess()->RemoveRoute(routing_id_); 242 GetProcess()->RemoveRoute(routing_id_);
236 g_routing_id_frame_map.Get().erase( 243 g_routing_id_frame_map.Get().erase(
237 RenderFrameHostID(GetProcess()->GetID(), routing_id_)); 244 RenderFrameHostID(GetProcess()->GetID(), routing_id_));
238 245
239 if (delegate_ && render_frame_created_) 246 if (delegate_ && render_frame_created_)
240 delegate_->RenderFrameDeleted(this); 247 delegate_->RenderFrameDeleted(this);
241 248
242 // If this was swapped out, it already decremented the active frame count of 249 // If this was swapped out, it already decremented the active frame count of
243 // the SiteInstance it belongs to. 250 // the SiteInstance it belongs to.
244 if (IsRFHStateActive(rfh_state_)) 251 if (IsRFHStateActive(rfh_state_))
(...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 // gone through this, therefore just return. 1034 // gone through this, therefore just return.
1028 if (rfh_state_ != RenderFrameHostImpl::STATE_DEFAULT) { 1035 if (rfh_state_ != RenderFrameHostImpl::STATE_DEFAULT) {
1029 NOTREACHED() << "RFH should be in default state when calling SwapOut."; 1036 NOTREACHED() << "RFH should be in default state when calling SwapOut.";
1030 return; 1037 return;
1031 } 1038 }
1032 1039
1033 SetState(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT); 1040 SetState(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT);
1034 swapout_event_monitor_timeout_->Start( 1041 swapout_event_monitor_timeout_->Start(
1035 base::TimeDelta::FromMilliseconds(RenderViewHostImpl::kUnloadTimeoutMS)); 1042 base::TimeDelta::FromMilliseconds(RenderViewHostImpl::kUnloadTimeoutMS));
1036 1043
1044 ResetWebUI();
nasko 2015/10/29 22:13:15 This should probably be done when we receive the S
carlosk 2015/10/30 10:35:23 See similar question and my answer here: https://c
carlosk 2015/11/03 09:50:30 Done (as discussed in the link above).
1045
1037 // There may be no proxy if there are no active views in the process. 1046 // There may be no proxy if there are no active views in the process.
1038 int proxy_routing_id = MSG_ROUTING_NONE; 1047 int proxy_routing_id = MSG_ROUTING_NONE;
1039 FrameReplicationState replication_state; 1048 FrameReplicationState replication_state;
1040 if (proxy) { 1049 if (proxy) {
1041 set_render_frame_proxy_host(proxy); 1050 set_render_frame_proxy_host(proxy);
1042 proxy_routing_id = proxy->GetRoutingID(); 1051 proxy_routing_id = proxy->GetRoutingID();
1043 replication_state = proxy->frame_tree_node()->current_replication_state(); 1052 replication_state = proxy->frame_tree_node()->current_replication_state();
1044 } 1053 }
1045 1054
1046 if (IsRenderFrameLive()) { 1055 if (IsRenderFrameLive()) {
(...skipping 936 matching lines...) Expand 10 before | Expand all | Expand 10 after
1983 bool RenderFrameHostImpl::IsFocused() { 1992 bool RenderFrameHostImpl::IsFocused() {
1984 // TODO(mlamouri,kenrb): call GetRenderWidgetHost() directly when it stops 1993 // TODO(mlamouri,kenrb): call GetRenderWidgetHost() directly when it stops
1985 // returning nullptr in some cases. See https://crbug.com/455245. 1994 // returning nullptr in some cases. See https://crbug.com/455245.
1986 return RenderWidgetHostImpl::From( 1995 return RenderWidgetHostImpl::From(
1987 GetView()->GetRenderWidgetHost())->is_focused() && 1996 GetView()->GetRenderWidgetHost())->is_focused() &&
1988 frame_tree_->GetFocusedFrame() && 1997 frame_tree_->GetFocusedFrame() &&
1989 (frame_tree_->GetFocusedFrame() == frame_tree_node() || 1998 (frame_tree_->GetFocusedFrame() == frame_tree_node() ||
1990 frame_tree_->GetFocusedFrame()->IsDescendantOf(frame_tree_node())); 1999 frame_tree_->GetFocusedFrame()->IsDescendantOf(frame_tree_node()));
1991 } 2000 }
1992 2001
2002 bool RenderFrameHostImpl::UpdateWebUI(const GURL& dest_url,
2003 int entry_bindings) {
2004 WebUI::TypeID new_web_ui_type = WebUI::kNoWebUI;
2005 if (dest_url.is_valid()) {
2006 new_web_ui_type =
2007 WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType(
2008 GetSiteInstance()->GetBrowserContext(), dest_url);
2009 }
2010
2011 WebUIImpl* prev_web_ui_ptr = web_ui_.get();
nasko 2015/10/29 22:13:15 nit: No need to add _ptr in the variable name.
carlosk 2015/10/30 10:35:23 Done.
2012 if (new_web_ui_type == WebUI::kNoWebUI) {
2013 ResetWebUI();
2014 } else {
2015 // The current WebUI should be reused when dest_url requires a WebUI and its
2016 // type matches the current. Otherwise replace it with a new one.
2017 if (web_ui_type_ != new_web_ui_type) {
2018 web_ui_ = delegate_->CreateWebUIForRenderFrameHost(dest_url);
2019 DCHECK(web_ui_);
2020 web_ui_type_ = new_web_ui_type;
2021
2022 // If we have assigned (zero or more) bindings to the NavigationEntry in
2023 // the past, make sure we're not granting it different bindings than it
2024 // had before. If so, note it and don't give it any bindings, to avoid a
2025 // potential privilege escalation.
2026 if (entry_bindings != NavigationEntryImpl::kInvalidBindings &&
2027 web_ui_->GetBindings() != entry_bindings) {
2028 RecordAction(
2029 base::UserMetricsAction("ProcessSwapBindingsMismatch_RVHM"));
2030 ResetWebUI();
2031 return prev_web_ui_ptr;
nasko 2015/10/29 22:13:15 The return type of this method is a boolean value,
carlosk 2015/10/30 10:35:23 Fixed. Trybots also brought that one to my attenti
2032 }
2033 }
2034 }
2035 DCHECK_EQ(!web_ui_, web_ui_type_ == WebUI::kNoWebUI);
2036
2037 // Check RenderViewHost for proper bindings.
2038 if (web_ui_ && !render_view_host_->GetProcess()->IsForGuestsOnly()) {
2039 // If a WebUI was created for the URL and the RenderView is not in a guest
2040 // process, then enable missing bindings with the RenderViewHost.
2041 int new_bindings = web_ui_->GetBindings();
2042 if ((render_view_host_->GetEnabledBindings() & new_bindings) !=
2043 new_bindings) {
2044 render_view_host_->AllowBindings(new_bindings);
2045 }
2046 } else if (render_view_host_->is_active()) {
2047 // If the ongoing navigation is not to a WebUI or the RenderView is in a
2048 // guest process, ensure that we don't create an unprivileged RenderView in
2049 // a WebUI-enabled process unless it's swapped out.
2050 bool url_acceptable_for_webui =
2051 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI(
2052 GetSiteInstance()->GetBrowserContext(), dest_url);
2053 if (!url_acceptable_for_webui) {
2054 CHECK(!ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
2055 GetProcess()->GetID()));
2056 }
2057 }
2058 return prev_web_ui_ptr != web_ui_.get();
2059 }
2060
1993 const image_downloader::ImageDownloaderPtr& 2061 const image_downloader::ImageDownloaderPtr&
1994 RenderFrameHostImpl::GetMojoImageDownloader() { 2062 RenderFrameHostImpl::GetMojoImageDownloader() {
1995 if (!mojo_image_downloader_.get() && GetServiceRegistry()) { 2063 if (!mojo_image_downloader_.get() && GetServiceRegistry()) {
1996 GetServiceRegistry()->ConnectToRemoteService( 2064 GetServiceRegistry()->ConnectToRemoteService(
1997 mojo::GetProxy(&mojo_image_downloader_)); 2065 mojo::GetProxy(&mojo_image_downloader_));
1998 } 2066 }
1999 return mojo_image_downloader_; 2067 return mojo_image_downloader_;
2000 } 2068 }
2001 2069
2002 bool RenderFrameHostImpl::IsSameSiteInstance( 2070 bool RenderFrameHostImpl::IsSameSiteInstance(
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
2292 // Copy the common fields. 2360 // Copy the common fields.
2293 *dst = src; 2361 *dst = src;
2294 2362
2295 if (src.routing_id != -1) 2363 if (src.routing_id != -1)
2296 dst->tree_id = RoutingIDToAXTreeID(src.routing_id); 2364 dst->tree_id = RoutingIDToAXTreeID(src.routing_id);
2297 2365
2298 if (src.parent_routing_id != -1) 2366 if (src.parent_routing_id != -1)
2299 dst->parent_tree_id = RoutingIDToAXTreeID(src.parent_routing_id); 2367 dst->parent_tree_id = RoutingIDToAXTreeID(src.parent_routing_id);
2300 } 2368 }
2301 2369
2370 void RenderFrameHostImpl::ResetWebUI() {
2371 web_ui_type_ = WebUI::kNoWebUI;
2372 web_ui_.reset();
2373 }
2374
2302 } // namespace content 2375 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698