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

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: Fixed header comments. 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"
45 #include "content/browser/wake_lock/wake_lock_service_context.h" 46 #include "content/browser/wake_lock/wake_lock_service_context.h"
47 #include "content/browser/webui/web_ui_controller_factory_registry.h"
46 #include "content/common/accessibility_messages.h" 48 #include "content/common/accessibility_messages.h"
47 #include "content/common/frame_messages.h" 49 #include "content/common/frame_messages.h"
48 #include "content/common/input_messages.h" 50 #include "content/common/input_messages.h"
49 #include "content/common/inter_process_time_ticks_converter.h" 51 #include "content/common/inter_process_time_ticks_converter.h"
50 #include "content/common/navigation_params.h" 52 #include "content/common/navigation_params.h"
51 #include "content/common/render_frame_setup.mojom.h" 53 #include "content/common/render_frame_setup.mojom.h"
52 #include "content/common/site_isolation_policy.h" 54 #include "content/common/site_isolation_policy.h"
53 #include "content/common/swapped_out_messages.h" 55 #include "content/common/swapped_out_messages.h"
54 #include "content/public/browser/ax_event_notification_details.h" 56 #include "content/public/browser/ax_event_notification_details.h"
55 #include "content/public/browser/browser_accessibility_state.h" 57 #include "content/public/browser/browser_accessibility_state.h"
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 routing_id_(routing_id), 189 routing_id_(routing_id),
188 render_frame_created_(false), 190 render_frame_created_(false),
189 navigations_suspended_(false), 191 navigations_suspended_(false),
190 is_waiting_for_beforeunload_ack_(false), 192 is_waiting_for_beforeunload_ack_(false),
191 unload_ack_is_for_navigation_(false), 193 unload_ack_is_for_navigation_(false),
192 is_loading_(false), 194 is_loading_(false),
193 pending_commit_(false), 195 pending_commit_(false),
194 accessibility_reset_token_(0), 196 accessibility_reset_token_(0),
195 accessibility_reset_count_(0), 197 accessibility_reset_count_(0),
196 no_create_browser_accessibility_manager_for_testing_(false), 198 no_create_browser_accessibility_manager_for_testing_(false),
199 web_ui_type_(WebUI::kNoWebUI),
197 weak_ptr_factory_(this) { 200 weak_ptr_factory_(this) {
198 bool is_swapped_out = !!(flags & CREATE_RF_SWAPPED_OUT); 201 bool is_swapped_out = !!(flags & CREATE_RF_SWAPPED_OUT);
199 bool hidden = !!(flags & CREATE_RF_HIDDEN); 202 bool hidden = !!(flags & CREATE_RF_HIDDEN);
200 frame_tree_->AddRenderViewHostRef(render_view_host_); 203 frame_tree_->AddRenderViewHostRef(render_view_host_);
201 GetProcess()->AddRoute(routing_id_, this); 204 GetProcess()->AddRoute(routing_id_, this);
202 g_routing_id_frame_map.Get().insert(std::make_pair( 205 g_routing_id_frame_map.Get().insert(std::make_pair(
203 RenderFrameHostID(GetProcess()->GetID(), routing_id_), 206 RenderFrameHostID(GetProcess()->GetID(), routing_id_),
204 this)); 207 this));
205 208
206 if (is_swapped_out) { 209 if (is_swapped_out) {
(...skipping 19 matching lines...) Expand all
226 render_widget_host_ = new RenderWidgetHostImpl(rwh_delegate, GetProcess(), 229 render_widget_host_ = new RenderWidgetHostImpl(rwh_delegate, GetProcess(),
227 widget_routing_id, hidden); 230 widget_routing_id, hidden);
228 render_widget_host_->set_owned_by_render_frame_host(true); 231 render_widget_host_->set_owned_by_render_frame_host(true);
229 } else { 232 } else {
230 DCHECK(!render_widget_host_->owned_by_render_frame_host()); 233 DCHECK(!render_widget_host_->owned_by_render_frame_host());
231 } 234 }
232 } 235 }
233 } 236 }
234 237
235 RenderFrameHostImpl::~RenderFrameHostImpl() { 238 RenderFrameHostImpl::~RenderFrameHostImpl() {
239 // Release the WebUI before all else as the WebUI accesses the RenderFrameHost
240 // during cleanup.
241 ResetWebUI();
242
236 GetProcess()->RemoveRoute(routing_id_); 243 GetProcess()->RemoveRoute(routing_id_);
237 g_routing_id_frame_map.Get().erase( 244 g_routing_id_frame_map.Get().erase(
238 RenderFrameHostID(GetProcess()->GetID(), routing_id_)); 245 RenderFrameHostID(GetProcess()->GetID(), routing_id_));
239 246
240 if (delegate_ && render_frame_created_) 247 if (delegate_ && render_frame_created_)
241 delegate_->RenderFrameDeleted(this); 248 delegate_->RenderFrameDeleted(this);
242 249
243 // If this was swapped out, it already decremented the active frame count of 250 // If this was swapped out, it already decremented the active frame count of
244 // the SiteInstance it belongs to. 251 // the SiteInstance it belongs to.
245 if (IsRFHStateActive(rfh_state_)) 252 if (IsRFHStateActive(rfh_state_))
(...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 // gone through this, therefore just return. 1035 // gone through this, therefore just return.
1029 if (rfh_state_ != RenderFrameHostImpl::STATE_DEFAULT) { 1036 if (rfh_state_ != RenderFrameHostImpl::STATE_DEFAULT) {
1030 NOTREACHED() << "RFH should be in default state when calling SwapOut."; 1037 NOTREACHED() << "RFH should be in default state when calling SwapOut.";
1031 return; 1038 return;
1032 } 1039 }
1033 1040
1034 SetState(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT); 1041 SetState(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT);
1035 swapout_event_monitor_timeout_->Start( 1042 swapout_event_monitor_timeout_->Start(
1036 base::TimeDelta::FromMilliseconds(RenderViewHostImpl::kUnloadTimeoutMS)); 1043 base::TimeDelta::FromMilliseconds(RenderViewHostImpl::kUnloadTimeoutMS));
1037 1044
1045 ResetWebUI();
1046
1038 // There may be no proxy if there are no active views in the process. 1047 // There may be no proxy if there are no active views in the process.
1039 int proxy_routing_id = MSG_ROUTING_NONE; 1048 int proxy_routing_id = MSG_ROUTING_NONE;
1040 FrameReplicationState replication_state; 1049 FrameReplicationState replication_state;
1041 if (proxy) { 1050 if (proxy) {
1042 set_render_frame_proxy_host(proxy); 1051 set_render_frame_proxy_host(proxy);
1043 proxy_routing_id = proxy->GetRoutingID(); 1052 proxy_routing_id = proxy->GetRoutingID();
1044 replication_state = proxy->frame_tree_node()->current_replication_state(); 1053 replication_state = proxy->frame_tree_node()->current_replication_state();
1045 } 1054 }
1046 1055
1047 if (IsRenderFrameLive()) { 1056 if (IsRenderFrameLive()) {
(...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after
1996 bool RenderFrameHostImpl::IsFocused() { 2005 bool RenderFrameHostImpl::IsFocused() {
1997 // TODO(mlamouri,kenrb): call GetRenderWidgetHost() directly when it stops 2006 // TODO(mlamouri,kenrb): call GetRenderWidgetHost() directly when it stops
1998 // returning nullptr in some cases. See https://crbug.com/455245. 2007 // returning nullptr in some cases. See https://crbug.com/455245.
1999 return RenderWidgetHostImpl::From( 2008 return RenderWidgetHostImpl::From(
2000 GetView()->GetRenderWidgetHost())->is_focused() && 2009 GetView()->GetRenderWidgetHost())->is_focused() &&
2001 frame_tree_->GetFocusedFrame() && 2010 frame_tree_->GetFocusedFrame() &&
2002 (frame_tree_->GetFocusedFrame() == frame_tree_node() || 2011 (frame_tree_->GetFocusedFrame() == frame_tree_node() ||
2003 frame_tree_->GetFocusedFrame()->IsDescendantOf(frame_tree_node())); 2012 frame_tree_->GetFocusedFrame()->IsDescendantOf(frame_tree_node()));
2004 } 2013 }
2005 2014
2015 bool RenderFrameHostImpl::UpdateWebUI(const GURL& dest_url,
2016 int entry_bindings) {
2017 WebUI::TypeID new_web_ui_type = WebUI::kNoWebUI;
2018 if (dest_url.is_valid()) {
2019 new_web_ui_type =
2020 WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType(
2021 GetSiteInstance()->GetBrowserContext(), dest_url);
2022 }
2023
2024 WebUIImpl* prev_web_ui = web_ui_.get();
2025 if (new_web_ui_type == WebUI::kNoWebUI) {
2026 ResetWebUI();
nasko 2015/11/02 17:00:36 Can't we early return from here? It will make also
carlosk 2015/11/03 09:50:30 No because of the bindings checks further below. U
nasko 2015/11/04 17:16:10 No, let's keep it all in one place, as bindings ch
carlosk 2015/11/04 21:43:59 Acknowledged.
2027 } else {
2028 // The current WebUI should be reused when dest_url requires a WebUI and its
2029 // type matches the current. Otherwise replace it with a new one.
2030 if (web_ui_type_ != new_web_ui_type) {
2031 web_ui_ = delegate_->CreateWebUIForRenderFrameHost(dest_url);
2032 DCHECK(web_ui_);
2033 web_ui_type_ = new_web_ui_type;
2034
2035 // If we have assigned (zero or more) bindings to the NavigationEntry in
2036 // the past, make sure we're not granting it different bindings than it
2037 // had before. If so, note it and don't give it any bindings, to avoid a
2038 // potential privilege escalation.
2039 if (entry_bindings != NavigationEntryImpl::kInvalidBindings &&
2040 web_ui_->GetBindings() != entry_bindings) {
2041 RecordAction(
2042 base::UserMetricsAction("ProcessSwapBindingsMismatch_RVHM"));
2043 ResetWebUI();
2044 return !!prev_web_ui;
2045 }
2046 }
2047 }
2048 DCHECK_EQ(!web_ui_, web_ui_type_ == WebUI::kNoWebUI);
2049
2050 // Check RenderViewHost for proper bindings.
2051 if (web_ui_ && !render_view_host_->GetProcess()->IsForGuestsOnly()) {
2052 // If a WebUI was created for the URL and the RenderView is not in a guest
2053 // process, then enable missing bindings with the RenderViewHost.
2054 int new_bindings = web_ui_->GetBindings();
2055 if ((render_view_host_->GetEnabledBindings() & new_bindings) !=
2056 new_bindings) {
2057 render_view_host_->AllowBindings(new_bindings);
2058 }
2059 } else if (render_view_host_->is_active()) {
2060 // If the ongoing navigation is not to a WebUI or the RenderView is in a
2061 // guest process, ensure that we don't create an unprivileged RenderView in
2062 // a WebUI-enabled process unless it's swapped out.
2063 bool url_acceptable_for_webui =
2064 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI(
2065 GetSiteInstance()->GetBrowserContext(), dest_url);
2066 if (!url_acceptable_for_webui) {
2067 CHECK(!ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
2068 GetProcess()->GetID()));
2069 }
2070 }
2071 return prev_web_ui != web_ui_.get();
2072 }
2073
2006 const image_downloader::ImageDownloaderPtr& 2074 const image_downloader::ImageDownloaderPtr&
2007 RenderFrameHostImpl::GetMojoImageDownloader() { 2075 RenderFrameHostImpl::GetMojoImageDownloader() {
2008 if (!mojo_image_downloader_.get() && GetServiceRegistry()) { 2076 if (!mojo_image_downloader_.get() && GetServiceRegistry()) {
2009 GetServiceRegistry()->ConnectToRemoteService( 2077 GetServiceRegistry()->ConnectToRemoteService(
2010 mojo::GetProxy(&mojo_image_downloader_)); 2078 mojo::GetProxy(&mojo_image_downloader_));
2011 } 2079 }
2012 return mojo_image_downloader_; 2080 return mojo_image_downloader_;
2013 } 2081 }
2014 2082
2015 bool RenderFrameHostImpl::IsSameSiteInstance( 2083 bool RenderFrameHostImpl::IsSameSiteInstance(
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
2305 // Copy the common fields. 2373 // Copy the common fields.
2306 *dst = src; 2374 *dst = src;
2307 2375
2308 if (src.routing_id != -1) 2376 if (src.routing_id != -1)
2309 dst->tree_id = RoutingIDToAXTreeID(src.routing_id); 2377 dst->tree_id = RoutingIDToAXTreeID(src.routing_id);
2310 2378
2311 if (src.parent_routing_id != -1) 2379 if (src.parent_routing_id != -1)
2312 dst->parent_tree_id = RoutingIDToAXTreeID(src.parent_routing_id); 2380 dst->parent_tree_id = RoutingIDToAXTreeID(src.parent_routing_id);
2313 } 2381 }
2314 2382
2383 void RenderFrameHostImpl::ResetWebUI() {
2384 web_ui_type_ = WebUI::kNoWebUI;
2385 web_ui_.reset();
2386 }
2387
2315 } // namespace content 2388 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698