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

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

Issue 1472703004: Reland #2 of: Move WebUI ownership from the RenderFrameHostManager to the RenderFrameHost. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test shared code now uses lambda functions. More comments. Created 5 years 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 <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/containers/hash_tables.h" 11 #include "base/containers/hash_tables.h"
12 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/process/kill.h" 14 #include "base/process/kill.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "content/browser/accessibility/accessibility_mode_helper.h" 16 #include "content/browser/accessibility/accessibility_mode_helper.h"
17 #include "content/browser/accessibility/ax_tree_id_registry.h" 17 #include "content/browser/accessibility/ax_tree_id_registry.h"
18 #include "content/browser/accessibility/browser_accessibility_manager.h" 18 #include "content/browser/accessibility/browser_accessibility_manager.h"
19 #include "content/browser/accessibility/browser_accessibility_state_impl.h" 19 #include "content/browser/accessibility/browser_accessibility_state_impl.h"
20 #include "content/browser/child_process_security_policy_impl.h" 20 #include "content/browser/child_process_security_policy_impl.h"
21 #include "content/browser/child_process_security_policy_impl.h"
21 #include "content/browser/devtools/render_frame_devtools_agent_host.h" 22 #include "content/browser/devtools/render_frame_devtools_agent_host.h"
22 #include "content/browser/frame_host/cross_process_frame_connector.h" 23 #include "content/browser/frame_host/cross_process_frame_connector.h"
23 #include "content/browser/frame_host/cross_site_transferring_request.h" 24 #include "content/browser/frame_host/cross_site_transferring_request.h"
24 #include "content/browser/frame_host/frame_mojo_shell.h" 25 #include "content/browser/frame_host/frame_mojo_shell.h"
25 #include "content/browser/frame_host/frame_tree.h" 26 #include "content/browser/frame_host/frame_tree.h"
26 #include "content/browser/frame_host/frame_tree_node.h" 27 #include "content/browser/frame_host/frame_tree_node.h"
27 #include "content/browser/frame_host/navigation_handle_impl.h" 28 #include "content/browser/frame_host/navigation_handle_impl.h"
28 #include "content/browser/frame_host/navigation_request.h" 29 #include "content/browser/frame_host/navigation_request.h"
29 #include "content/browser/frame_host/navigator.h" 30 #include "content/browser/frame_host/navigator.h"
30 #include "content/browser/frame_host/navigator_impl.h" 31 #include "content/browser/frame_host/navigator_impl.h"
31 #include "content/browser/frame_host/render_frame_host_delegate.h" 32 #include "content/browser/frame_host/render_frame_host_delegate.h"
32 #include "content/browser/frame_host/render_frame_proxy_host.h" 33 #include "content/browser/frame_host/render_frame_proxy_host.h"
33 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" 34 #include "content/browser/frame_host/render_widget_host_view_child_frame.h"
34 #include "content/browser/geolocation/geolocation_service_context.h" 35 #include "content/browser/geolocation/geolocation_service_context.h"
35 #include "content/browser/permissions/permission_service_context.h" 36 #include "content/browser/permissions/permission_service_context.h"
36 #include "content/browser/permissions/permission_service_impl.h" 37 #include "content/browser/permissions/permission_service_impl.h"
37 #include "content/browser/presentation/presentation_service_impl.h" 38 #include "content/browser/presentation/presentation_service_impl.h"
38 #include "content/browser/renderer_host/input/input_router.h" 39 #include "content/browser/renderer_host/input/input_router.h"
39 #include "content/browser/renderer_host/input/timeout_monitor.h" 40 #include "content/browser/renderer_host/input/timeout_monitor.h"
40 #include "content/browser/renderer_host/render_process_host_impl.h" 41 #include "content/browser/renderer_host/render_process_host_impl.h"
41 #include "content/browser/renderer_host/render_view_host_delegate.h" 42 #include "content/browser/renderer_host/render_view_host_delegate.h"
42 #include "content/browser/renderer_host/render_view_host_delegate_view.h" 43 #include "content/browser/renderer_host/render_view_host_delegate_view.h"
43 #include "content/browser/renderer_host/render_view_host_impl.h" 44 #include "content/browser/renderer_host/render_view_host_impl.h"
44 #include "content/browser/renderer_host/render_widget_host_delegate.h" 45 #include "content/browser/renderer_host/render_widget_host_delegate.h"
45 #include "content/browser/renderer_host/render_widget_host_impl.h" 46 #include "content/browser/renderer_host/render_widget_host_impl.h"
46 #include "content/browser/renderer_host/render_widget_host_view_base.h" 47 #include "content/browser/renderer_host/render_widget_host_view_base.h"
47 #include "content/browser/wake_lock/wake_lock_service_context.h" 48 #include "content/browser/wake_lock/wake_lock_service_context.h"
49 #include "content/browser/webui/web_ui_controller_factory_registry.h"
48 #include "content/common/accessibility_messages.h" 50 #include "content/common/accessibility_messages.h"
49 #include "content/common/frame_messages.h" 51 #include "content/common/frame_messages.h"
50 #include "content/common/input_messages.h" 52 #include "content/common/input_messages.h"
51 #include "content/common/inter_process_time_ticks_converter.h" 53 #include "content/common/inter_process_time_ticks_converter.h"
52 #include "content/common/mojo/service_registry_for_route.h" 54 #include "content/common/mojo/service_registry_for_route.h"
53 #include "content/common/navigation_params.h" 55 #include "content/common/navigation_params.h"
54 #include "content/common/site_isolation_policy.h" 56 #include "content/common/site_isolation_policy.h"
55 #include "content/common/swapped_out_messages.h" 57 #include "content/common/swapped_out_messages.h"
56 #include "content/public/browser/ax_event_notification_details.h" 58 #include "content/public/browser/ax_event_notification_details.h"
57 #include "content/public/browser/browser_accessibility_state.h" 59 #include "content/public/browser/browser_accessibility_state.h"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 render_frame_created_(false), 192 render_frame_created_(false),
191 navigations_suspended_(false), 193 navigations_suspended_(false),
192 is_waiting_for_beforeunload_ack_(false), 194 is_waiting_for_beforeunload_ack_(false),
193 unload_ack_is_for_navigation_(false), 195 unload_ack_is_for_navigation_(false),
194 is_loading_(false), 196 is_loading_(false),
195 pending_commit_(false), 197 pending_commit_(false),
196 nav_entry_id_(0), 198 nav_entry_id_(0),
197 accessibility_reset_token_(0), 199 accessibility_reset_token_(0),
198 accessibility_reset_count_(0), 200 accessibility_reset_count_(0),
199 no_create_browser_accessibility_manager_for_testing_(false), 201 no_create_browser_accessibility_manager_for_testing_(false),
202 web_ui_type_(WebUI::kNoWebUI),
203 pending_web_ui_type_(WebUI::kNoWebUI),
204 should_reuse_web_ui_(false),
200 weak_ptr_factory_(this) { 205 weak_ptr_factory_(this) {
201 bool is_swapped_out = !!(flags & CREATE_RF_SWAPPED_OUT); 206 bool is_swapped_out = !!(flags & CREATE_RF_SWAPPED_OUT);
202 bool hidden = !!(flags & CREATE_RF_HIDDEN); 207 bool hidden = !!(flags & CREATE_RF_HIDDEN);
203 frame_tree_->AddRenderViewHostRef(render_view_host_); 208 frame_tree_->AddRenderViewHostRef(render_view_host_);
204 GetProcess()->AddRoute(routing_id_, this); 209 GetProcess()->AddRoute(routing_id_, this);
205 g_routing_id_frame_map.Get().insert(std::make_pair( 210 g_routing_id_frame_map.Get().insert(std::make_pair(
206 RenderFrameHostID(GetProcess()->GetID(), routing_id_), 211 RenderFrameHostID(GetProcess()->GetID(), routing_id_),
207 this)); 212 this));
208 213
209 if (is_swapped_out) { 214 if (is_swapped_out) {
(...skipping 25 matching lines...) Expand all
235 render_widget_host_ = new RenderWidgetHostImpl(rwh_delegate, GetProcess(), 240 render_widget_host_ = new RenderWidgetHostImpl(rwh_delegate, GetProcess(),
236 widget_routing_id, hidden); 241 widget_routing_id, hidden);
237 render_widget_host_->set_owned_by_render_frame_host(true); 242 render_widget_host_->set_owned_by_render_frame_host(true);
238 } else { 243 } else {
239 DCHECK(!render_widget_host_->owned_by_render_frame_host()); 244 DCHECK(!render_widget_host_->owned_by_render_frame_host());
240 } 245 }
241 } 246 }
242 } 247 }
243 248
244 RenderFrameHostImpl::~RenderFrameHostImpl() { 249 RenderFrameHostImpl::~RenderFrameHostImpl() {
250 // Release the WebUI instances before all else as the WebUI may accesses the
251 // RenderFrameHost during cleanup.
252 ClearAllWebUI();
253
245 GetProcess()->RemoveRoute(routing_id_); 254 GetProcess()->RemoveRoute(routing_id_);
246 g_routing_id_frame_map.Get().erase( 255 g_routing_id_frame_map.Get().erase(
247 RenderFrameHostID(GetProcess()->GetID(), routing_id_)); 256 RenderFrameHostID(GetProcess()->GetID(), routing_id_));
248 257
249 if (delegate_ && render_frame_created_) 258 if (delegate_ && render_frame_created_)
250 delegate_->RenderFrameDeleted(this); 259 delegate_->RenderFrameDeleted(this);
251 260
252 // If this was swapped out, it already decremented the active frame count of 261 // If this was swapped out, it already decremented the active frame count of
253 // the SiteInstance it belongs to. 262 // the SiteInstance it belongs to.
254 if (IsRFHStateActive(rfh_state_)) 263 if (IsRFHStateActive(rfh_state_))
(...skipping 977 matching lines...) Expand 10 before | Expand all | Expand 10 after
1232 } 1241 }
1233 1242
1234 void RenderFrameHostImpl::OnSwappedOut() { 1243 void RenderFrameHostImpl::OnSwappedOut() {
1235 // Ignore spurious swap out ack. 1244 // Ignore spurious swap out ack.
1236 if (rfh_state_ != STATE_PENDING_SWAP_OUT) 1245 if (rfh_state_ != STATE_PENDING_SWAP_OUT)
1237 return; 1246 return;
1238 1247
1239 TRACE_EVENT_ASYNC_END0("navigation", "RenderFrameHostImpl::SwapOut", this); 1248 TRACE_EVENT_ASYNC_END0("navigation", "RenderFrameHostImpl::SwapOut", this);
1240 swapout_event_monitor_timeout_->Stop(); 1249 swapout_event_monitor_timeout_->Stop();
1241 1250
1251 ClearAllWebUI();
1242 1252
1243 // If this is a main frame RFH that's about to be deleted, update its RVH's 1253 // If this is a main frame RFH that's about to be deleted, update its RVH's
1244 // swapped-out state here, since SetState won't be called once this RFH is 1254 // swapped-out state here, since SetState won't be called once this RFH is
1245 // deleted below. https://crbug.com/505887 1255 // deleted below. https://crbug.com/505887
1246 if (frame_tree_node_->IsMainFrame() && 1256 if (frame_tree_node_->IsMainFrame() &&
1247 frame_tree_node_->render_manager()->IsPendingDeletion(this)) { 1257 frame_tree_node_->render_manager()->IsPendingDeletion(this)) {
1248 render_view_host_->set_is_active(false); 1258 render_view_host_->set_is_active(false);
1249 render_view_host_->set_is_swapped_out(true); 1259 render_view_host_->set_is_swapped_out(true);
1250 } 1260 }
1251 1261
(...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after
2062 bool RenderFrameHostImpl::IsFocused() { 2072 bool RenderFrameHostImpl::IsFocused() {
2063 // TODO(mlamouri,kenrb): call GetRenderWidgetHost() directly when it stops 2073 // TODO(mlamouri,kenrb): call GetRenderWidgetHost() directly when it stops
2064 // returning nullptr in some cases. See https://crbug.com/455245. 2074 // returning nullptr in some cases. See https://crbug.com/455245.
2065 return RenderWidgetHostImpl::From( 2075 return RenderWidgetHostImpl::From(
2066 GetView()->GetRenderWidgetHost())->is_focused() && 2076 GetView()->GetRenderWidgetHost())->is_focused() &&
2067 frame_tree_->GetFocusedFrame() && 2077 frame_tree_->GetFocusedFrame() &&
2068 (frame_tree_->GetFocusedFrame() == frame_tree_node() || 2078 (frame_tree_->GetFocusedFrame() == frame_tree_node() ||
2069 frame_tree_->GetFocusedFrame()->IsDescendantOf(frame_tree_node())); 2079 frame_tree_->GetFocusedFrame()->IsDescendantOf(frame_tree_node()));
2070 } 2080 }
2071 2081
2082 bool RenderFrameHostImpl::UpdatePendingWebUI(const GURL& dest_url,
2083 int entry_bindings) {
2084 WebUI::TypeID new_web_ui_type =
2085 WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType(
2086 GetSiteInstance()->GetBrowserContext(), dest_url);
2087
2088 // If the required WebUI matches the pending WebUI or if it matches the
2089 // to-be-reused active WebUI, then leave everything as is.
2090 if (new_web_ui_type == pending_web_ui_type_ ||
2091 (should_reuse_web_ui_ && new_web_ui_type == web_ui_type_)) {
2092 return false;
2093 }
2094
2095 // Reset the pending WebUI as from this point it will certainly not be reused.
2096 ClearPendingWebUI();
2097
2098 // If this navigation is not to a WebUI, skip directly to bindings work.
2099 if (new_web_ui_type != WebUI::kNoWebUI) {
2100 if (new_web_ui_type == web_ui_type_) {
2101 // The active WebUI should be reused when dest_url requires a WebUI and
2102 // its type matches the current.
2103 DCHECK(web_ui_);
2104 should_reuse_web_ui_ = true;
2105 } else {
2106 // Otherwise create a new pending WebUI.
2107 pending_web_ui_ = delegate_->CreateWebUIForRenderFrameHost(dest_url);
2108 DCHECK(pending_web_ui_);
2109 pending_web_ui_type_ = new_web_ui_type;
2110
2111 // If we have assigned (zero or more) bindings to the NavigationEntry in
2112 // the past, make sure we're not granting it different bindings than it
2113 // had before. If so, note it and don't give it any bindings, to avoid a
2114 // potential privilege escalation.
2115 if (entry_bindings != NavigationEntryImpl::kInvalidBindings &&
2116 pending_web_ui_->GetBindings() != entry_bindings) {
2117 RecordAction(
2118 base::UserMetricsAction("ProcessSwapBindingsMismatch_RVHM"));
2119 ClearPendingWebUI();
2120 }
2121 }
2122 }
2123 DCHECK_EQ(!pending_web_ui_, pending_web_ui_type_ == WebUI::kNoWebUI);
2124
2125 // Either grant or check the RenderViewHost with/for proper bindings.
2126 if (pending_web_ui_ && !render_view_host_->GetProcess()->IsForGuestsOnly()) {
2127 // If a WebUI was created for the URL and the RenderView is not in a guest
2128 // process, then enable missing bindings with the RenderViewHost.
2129 int new_bindings = pending_web_ui_->GetBindings();
2130 if ((render_view_host_->GetEnabledBindings() & new_bindings) !=
2131 new_bindings) {
2132 render_view_host_->AllowBindings(new_bindings);
2133 }
2134 } else if (render_view_host_->is_active()) {
2135 // If the ongoing navigation is not to a WebUI or the RenderView is in a
2136 // guest process, ensure that we don't create an unprivileged RenderView in
2137 // a WebUI-enabled process unless it's swapped out.
2138 bool url_acceptable_for_webui =
2139 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI(
2140 GetSiteInstance()->GetBrowserContext(), dest_url);
2141 if (!url_acceptable_for_webui) {
2142 CHECK(!ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
2143 GetProcess()->GetID()));
2144 }
2145 }
2146 return true;
2147 }
2148
2149 void RenderFrameHostImpl::CommitPendingWebUI() {
2150 if (should_reuse_web_ui_) {
2151 should_reuse_web_ui_ = false;
2152 } else {
2153 web_ui_ = pending_web_ui_.Pass();
2154 web_ui_type_ = pending_web_ui_type_;
2155 pending_web_ui_type_ = WebUI::kNoWebUI;
2156 }
2157 DCHECK(!pending_web_ui_ && pending_web_ui_type_ == WebUI::kNoWebUI &&
2158 !should_reuse_web_ui_);
2159 }
2160
2161 void RenderFrameHostImpl::ClearPendingWebUI() {
2162 pending_web_ui_.reset();
2163 pending_web_ui_type_ = WebUI::kNoWebUI;
2164 should_reuse_web_ui_ = false;
2165 }
2166
2167 void RenderFrameHostImpl::ClearAllWebUI() {
2168 ClearPendingWebUI();
2169 web_ui_type_ = WebUI::kNoWebUI;
2170 web_ui_.reset();
2171 }
2172
2072 const image_downloader::ImageDownloaderPtr& 2173 const image_downloader::ImageDownloaderPtr&
2073 RenderFrameHostImpl::GetMojoImageDownloader() { 2174 RenderFrameHostImpl::GetMojoImageDownloader() {
2074 if (!mojo_image_downloader_.get() && GetServiceRegistry()) { 2175 if (!mojo_image_downloader_.get() && GetServiceRegistry()) {
2075 GetServiceRegistry()->ConnectToRemoteService( 2176 GetServiceRegistry()->ConnectToRemoteService(
2076 mojo::GetProxy(&mojo_image_downloader_)); 2177 mojo::GetProxy(&mojo_image_downloader_));
2077 } 2178 }
2078 return mojo_image_downloader_; 2179 return mojo_image_downloader_;
2079 } 2180 }
2080 2181
2081 bool RenderFrameHostImpl::IsSameSiteInstance( 2182 bool RenderFrameHostImpl::IsSameSiteInstance(
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
2374 *dst = src; 2475 *dst = src;
2375 2476
2376 if (src.routing_id != -1) 2477 if (src.routing_id != -1)
2377 dst->tree_id = RoutingIDToAXTreeID(src.routing_id); 2478 dst->tree_id = RoutingIDToAXTreeID(src.routing_id);
2378 2479
2379 if (src.parent_routing_id != -1) 2480 if (src.parent_routing_id != -1)
2380 dst->parent_tree_id = RoutingIDToAXTreeID(src.parent_routing_id); 2481 dst->parent_tree_id = RoutingIDToAXTreeID(src.parent_routing_id);
2381 } 2482 }
2382 2483
2383 } // namespace content 2484 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698