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

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: Removed InitializeWebUI Created 5 years, 2 months 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"
(...skipping 23 matching lines...) Expand all
34 #include "content/browser/permissions/permission_service_impl.h" 34 #include "content/browser/permissions/permission_service_impl.h"
35 #include "content/browser/presentation/presentation_service_impl.h" 35 #include "content/browser/presentation/presentation_service_impl.h"
36 #include "content/browser/renderer_host/input/input_router.h" 36 #include "content/browser/renderer_host/input/input_router.h"
37 #include "content/browser/renderer_host/input/timeout_monitor.h" 37 #include "content/browser/renderer_host/input/timeout_monitor.h"
38 #include "content/browser/renderer_host/render_process_host_impl.h" 38 #include "content/browser/renderer_host/render_process_host_impl.h"
39 #include "content/browser/renderer_host/render_view_host_delegate.h" 39 #include "content/browser/renderer_host/render_view_host_delegate.h"
40 #include "content/browser/renderer_host/render_view_host_delegate_view.h" 40 #include "content/browser/renderer_host/render_view_host_delegate_view.h"
41 #include "content/browser/renderer_host/render_view_host_impl.h" 41 #include "content/browser/renderer_host/render_view_host_impl.h"
42 #include "content/browser/renderer_host/render_widget_host_impl.h" 42 #include "content/browser/renderer_host/render_widget_host_impl.h"
43 #include "content/browser/renderer_host/render_widget_host_view_base.h" 43 #include "content/browser/renderer_host/render_widget_host_view_base.h"
44 #include "content/browser/webui/web_ui_controller_factory_registry.h"
44 #include "content/common/accessibility_messages.h" 45 #include "content/common/accessibility_messages.h"
45 #include "content/common/frame_messages.h" 46 #include "content/common/frame_messages.h"
46 #include "content/common/input_messages.h" 47 #include "content/common/input_messages.h"
47 #include "content/common/inter_process_time_ticks_converter.h" 48 #include "content/common/inter_process_time_ticks_converter.h"
48 #include "content/common/navigation_params.h" 49 #include "content/common/navigation_params.h"
49 #include "content/common/render_frame_setup.mojom.h" 50 #include "content/common/render_frame_setup.mojom.h"
50 #include "content/common/site_isolation_policy.h" 51 #include "content/common/site_isolation_policy.h"
51 #include "content/common/swapped_out_messages.h" 52 #include "content/common/swapped_out_messages.h"
52 #include "content/public/browser/ax_event_notification_details.h" 53 #include "content/public/browser/ax_event_notification_details.h"
53 #include "content/public/browser/browser_accessibility_state.h" 54 #include "content/public/browser/browser_accessibility_state.h"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 } 164 }
164 165
165 RenderFrameHostImpl::RenderFrameHostImpl(SiteInstance* site_instance, 166 RenderFrameHostImpl::RenderFrameHostImpl(SiteInstance* site_instance,
166 RenderViewHostImpl* render_view_host, 167 RenderViewHostImpl* render_view_host,
167 RenderFrameHostDelegate* delegate, 168 RenderFrameHostDelegate* delegate,
168 RenderWidgetHostDelegate* rwh_delegate, 169 RenderWidgetHostDelegate* rwh_delegate,
169 FrameTree* frame_tree, 170 FrameTree* frame_tree,
170 FrameTreeNode* frame_tree_node, 171 FrameTreeNode* frame_tree_node,
171 int32 routing_id, 172 int32 routing_id,
172 int32 widget_routing_id, 173 int32 widget_routing_id,
173 int flags) 174 int flags,
175 const GURL& dest_url,
176 int past_bindings)
174 : render_view_host_(render_view_host), 177 : render_view_host_(render_view_host),
175 delegate_(delegate), 178 delegate_(delegate),
176 site_instance_(static_cast<SiteInstanceImpl*>(site_instance)), 179 site_instance_(static_cast<SiteInstanceImpl*>(site_instance)),
177 process_(site_instance->GetProcess()), 180 process_(site_instance->GetProcess()),
178 cross_process_frame_connector_(NULL), 181 cross_process_frame_connector_(NULL),
179 render_frame_proxy_host_(NULL), 182 render_frame_proxy_host_(NULL),
180 frame_tree_(frame_tree), 183 frame_tree_(frame_tree),
181 frame_tree_node_(frame_tree_node), 184 frame_tree_node_(frame_tree_node),
182 render_widget_host_(nullptr), 185 render_widget_host_(nullptr),
183 routing_id_(routing_id), 186 routing_id_(routing_id),
184 render_frame_created_(false), 187 render_frame_created_(false),
185 navigations_suspended_(false), 188 navigations_suspended_(false),
186 is_waiting_for_beforeunload_ack_(false), 189 is_waiting_for_beforeunload_ack_(false),
187 unload_ack_is_for_navigation_(false), 190 unload_ack_is_for_navigation_(false),
188 is_loading_(false), 191 is_loading_(false),
189 pending_commit_(false), 192 pending_commit_(false),
190 accessibility_reset_token_(0), 193 accessibility_reset_token_(0),
191 accessibility_reset_count_(0), 194 accessibility_reset_count_(0),
192 no_create_browser_accessibility_manager_for_testing_(false), 195 no_create_browser_accessibility_manager_for_testing_(false),
196 web_ui_type_(WebUI::kNoWebUI),
197 should_reuse_web_ui_(false),
193 weak_ptr_factory_(this) { 198 weak_ptr_factory_(this) {
194 bool is_swapped_out = !!(flags & CREATE_RF_SWAPPED_OUT); 199 bool is_swapped_out = !!(flags & CREATE_RF_SWAPPED_OUT);
195 bool hidden = !!(flags & CREATE_RF_HIDDEN); 200 bool hidden = !!(flags & CREATE_RF_HIDDEN);
196 frame_tree_->AddRenderViewHostRef(render_view_host_); 201 frame_tree_->AddRenderViewHostRef(render_view_host_);
197 GetProcess()->AddRoute(routing_id_, this); 202 GetProcess()->AddRoute(routing_id_, this);
198 g_routing_id_frame_map.Get().insert(std::make_pair( 203 g_routing_id_frame_map.Get().insert(std::make_pair(
199 RenderFrameHostID(GetProcess()->GetID(), routing_id_), 204 RenderFrameHostID(GetProcess()->GetID(), routing_id_),
200 this)); 205 this));
201 206
202 if (is_swapped_out) { 207 if (is_swapped_out) {
203 rfh_state_ = STATE_SWAPPED_OUT; 208 rfh_state_ = STATE_SWAPPED_OUT;
204 } else { 209 } else {
205 rfh_state_ = STATE_DEFAULT; 210 rfh_state_ = STATE_DEFAULT;
206 GetSiteInstance()->increment_active_frame_count(); 211 GetSiteInstance()->increment_active_frame_count();
207 } 212 }
208 213
209 SetUpMojoIfNeeded(); 214 SetUpMojoIfNeeded();
210 swapout_event_monitor_timeout_.reset(new TimeoutMonitor(base::Bind( 215 swapout_event_monitor_timeout_.reset(new TimeoutMonitor(base::Bind(
211 &RenderFrameHostImpl::OnSwappedOut, weak_ptr_factory_.GetWeakPtr()))); 216 &RenderFrameHostImpl::OnSwappedOut, weak_ptr_factory_.GetWeakPtr())));
212 217
213 if (widget_routing_id != MSG_ROUTING_NONE) { 218 if (widget_routing_id != MSG_ROUTING_NONE) {
214 render_widget_host_ = new RenderWidgetHostImpl(rwh_delegate, GetProcess(), 219 render_widget_host_ = new RenderWidgetHostImpl(rwh_delegate, GetProcess(),
215 widget_routing_id, hidden); 220 widget_routing_id, hidden);
216 render_widget_host_->set_owned_by_render_frame_host(true); 221 render_widget_host_->set_owned_by_render_frame_host(true);
217 } 222 }
223
224 web_ui_ = CreateWebUI(dest_url, past_bindings, &web_ui_type_);
225 if (web_ui_ && frame_tree_node_->IsMainFrame())
226 web_ui_->RenderViewCreated(render_view_host_);
nasko 2015/10/01 20:05:16 Urgh! This is ugly and we need to figure out why i
carlosk 2015/10/05 16:59:57 Acknowledged.
Dan Beam 2015/10/06 17:50:33 this CL may make it irrelevant
nasko 2015/10/07 23:49:32 Care to add some context why it will be irrelevant
Dan Beam 2015/10/07 23:55:11 I originally thought this was solely to support su
Dan Beam 2015/10/08 00:01:35 if handlers are created before renderframes**
carlosk 2015/10/09 17:29:10 OK, so I'm keeping them. But it's still not clear
Dan Beam 2015/10/13 16:24:21 RenderViewCreated() is useful as the WebUI exists
218 } 227 }
219 228
220 RenderFrameHostImpl::~RenderFrameHostImpl() { 229 RenderFrameHostImpl::~RenderFrameHostImpl() {
230 // Release the WebUI before all else as the WebUI accesses the RenderFrameHost
231 // during cleanup.
232 web_ui_.reset();
233 pending_web_ui_.reset();
234
221 GetProcess()->RemoveRoute(routing_id_); 235 GetProcess()->RemoveRoute(routing_id_);
222 g_routing_id_frame_map.Get().erase( 236 g_routing_id_frame_map.Get().erase(
223 RenderFrameHostID(GetProcess()->GetID(), routing_id_)); 237 RenderFrameHostID(GetProcess()->GetID(), routing_id_));
224 238
225 if (delegate_ && render_frame_created_) 239 if (delegate_ && render_frame_created_)
226 delegate_->RenderFrameDeleted(this); 240 delegate_->RenderFrameDeleted(this);
227 241
228 // If this was swapped out, it already decremented the active frame count of 242 // If this was swapped out, it already decremented the active frame count of
229 // the SiteInstance it belongs to. 243 // the SiteInstance it belongs to.
230 if (IsRFHStateActive(rfh_state_)) 244 if (IsRFHStateActive(rfh_state_))
(...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 // gone through this, therefore just return. 1027 // gone through this, therefore just return.
1014 if (rfh_state_ != RenderFrameHostImpl::STATE_DEFAULT) { 1028 if (rfh_state_ != RenderFrameHostImpl::STATE_DEFAULT) {
1015 NOTREACHED() << "RFH should be in default state when calling SwapOut."; 1029 NOTREACHED() << "RFH should be in default state when calling SwapOut.";
1016 return; 1030 return;
1017 } 1031 }
1018 1032
1019 SetState(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT); 1033 SetState(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT);
1020 swapout_event_monitor_timeout_->Start( 1034 swapout_event_monitor_timeout_->Start(
1021 base::TimeDelta::FromMilliseconds(RenderViewHostImpl::kUnloadTimeoutMS)); 1035 base::TimeDelta::FromMilliseconds(RenderViewHostImpl::kUnloadTimeoutMS));
1022 1036
1037 web_ui_.reset();
1038 web_ui_type_ = WebUI::kNoWebUI;
1039
1023 // There may be no proxy if there are no active views in the process. 1040 // There may be no proxy if there are no active views in the process.
1024 int proxy_routing_id = MSG_ROUTING_NONE; 1041 int proxy_routing_id = MSG_ROUTING_NONE;
1025 FrameReplicationState replication_state; 1042 FrameReplicationState replication_state;
1026 if (proxy) { 1043 if (proxy) {
1027 set_render_frame_proxy_host(proxy); 1044 set_render_frame_proxy_host(proxy);
1028 proxy_routing_id = proxy->GetRoutingID(); 1045 proxy_routing_id = proxy->GetRoutingID();
1029 replication_state = proxy->frame_tree_node()->current_replication_state(); 1046 replication_state = proxy->frame_tree_node()->current_replication_state();
1030 } 1047 }
1031 1048
1032 if (IsRenderFrameLive()) { 1049 if (IsRenderFrameLive()) {
(...skipping 917 matching lines...) Expand 10 before | Expand all | Expand 10 after
1950 bool RenderFrameHostImpl::IsFocused() { 1967 bool RenderFrameHostImpl::IsFocused() {
1951 // TODO(mlamouri,kenrb): call GetRenderWidgetHost() directly when it stops 1968 // TODO(mlamouri,kenrb): call GetRenderWidgetHost() directly when it stops
1952 // returning nullptr in some cases. See https://crbug.com/455245. 1969 // returning nullptr in some cases. See https://crbug.com/455245.
1953 return RenderWidgetHostImpl::From( 1970 return RenderWidgetHostImpl::From(
1954 GetView()->GetRenderWidgetHost())->is_focused() && 1971 GetView()->GetRenderWidgetHost())->is_focused() &&
1955 frame_tree_->GetFocusedFrame() && 1972 frame_tree_->GetFocusedFrame() &&
1956 (frame_tree_->GetFocusedFrame() == frame_tree_node() || 1973 (frame_tree_->GetFocusedFrame() == frame_tree_node() ||
1957 frame_tree_->GetFocusedFrame()->IsDescendantOf(frame_tree_node())); 1974 frame_tree_->GetFocusedFrame()->IsDescendantOf(frame_tree_node()));
1958 } 1975 }
1959 1976
1977 void RenderFrameHostImpl::UpdatePendingWebUI(const GURL& dest_url,
1978 int past_bindings) {
1979 WebUI::TypeID new_web_ui_type =
1980 WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType(
1981 GetSiteInstance()->GetBrowserContext(), dest_url);
1982 // The current WebUI should be reused when dest_url requires a WebUI and its
1983 // type matches the current.
1984 should_reuse_web_ui_ =
1985 new_web_ui_type != WebUI::kNoWebUI && web_ui_type_ == new_web_ui_type;
nasko 2015/10/01 20:05:16 This will be more readable if the boolean is initi
carlosk 2015/10/05 16:59:57 Done.
1986
1987 if (should_reuse_web_ui_) {
1988 DCHECK(web_ui_);
1989 // Reset the pending WebUI if the current one will be reused.
1990 pending_web_ui_.reset();
1991 pending_web_ui_type_ = WebUI::kNoWebUI;
1992 } else if (pending_web_ui_type_ != new_web_ui_type) {
1993 // Otherwise create, update or reset the pending one if its type doesn't
1994 // match the new type (if new type is kNoWebUI then it will be reset).
1995 pending_web_ui_ =
1996 CreateWebUI(dest_url, past_bindings, &pending_web_ui_type_);
1997
1998 if (pending_web_ui_ && IsRenderFrameLive()) {
1999 pending_web_ui_->RenderViewReused(render_view_host_,
2000 frame_tree_node_->IsMainFrame());
2001 }
2002 }
2003 CHECK_IMPLIES(pending_web_ui_, pending_web_ui_type_ != WebUI::kNoWebUI);
2004 CHECK_IMPLIES(!pending_web_ui_, pending_web_ui_type_ == WebUI::kNoWebUI);
2005 }
2006
2007 void RenderFrameHostImpl::CommitPendingWebUI() {
2008 if (should_reuse_web_ui_) {
2009 CHECK(!pending_web_ui_ && pending_web_ui_type_ == WebUI::kNoWebUI);
2010 should_reuse_web_ui_ = false;
2011 } else {
2012 web_ui_ = pending_web_ui_.Pass();
2013 web_ui_type_ = pending_web_ui_type_;
2014 pending_web_ui_type_ = WebUI::kNoWebUI;
2015 }
2016 }
2017
2018 void RenderFrameHostImpl::DiscardPendingWebUI() {
2019 pending_web_ui_.reset();
2020 pending_web_ui_type_ = WebUI::kNoWebUI;
2021 should_reuse_web_ui_ = false;
2022 }
2023
1960 const image_downloader::ImageDownloaderPtr& 2024 const image_downloader::ImageDownloaderPtr&
1961 RenderFrameHostImpl::GetMojoImageDownloader() { 2025 RenderFrameHostImpl::GetMojoImageDownloader() {
1962 if (!mojo_image_downloader_.get() && GetServiceRegistry()) { 2026 if (!mojo_image_downloader_.get() && GetServiceRegistry()) {
1963 GetServiceRegistry()->ConnectToRemoteService( 2027 GetServiceRegistry()->ConnectToRemoteService(
1964 mojo::GetProxy(&mojo_image_downloader_)); 2028 mojo::GetProxy(&mojo_image_downloader_));
1965 } 2029 }
1966 return mojo_image_downloader_; 2030 return mojo_image_downloader_;
1967 } 2031 }
1968 2032
1969 bool RenderFrameHostImpl::IsSameSiteInstance( 2033 bool RenderFrameHostImpl::IsSameSiteInstance(
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
2245 ui::AX_ATTR_CHILD_TREE_ID, 2309 ui::AX_ATTR_CHILD_TREE_ID,
2246 BrowserPluginInstanceIDToAXTreeID(value))); 2310 BrowserPluginInstanceIDToAXTreeID(value)));
2247 break; 2311 break;
2248 case AX_CONTENT_INT_ATTRIBUTE_LAST: 2312 case AX_CONTENT_INT_ATTRIBUTE_LAST:
2249 NOTREACHED(); 2313 NOTREACHED();
2250 break; 2314 break;
2251 } 2315 }
2252 } 2316 }
2253 } 2317 }
2254 2318
2319 scoped_ptr<WebUIImpl> RenderFrameHostImpl::CreateWebUI(
2320 const GURL& dest_url,
2321 int past_bindings,
2322 WebUI::TypeID* web_ui_type) {
2323 scoped_ptr<WebUIImpl> web_ui;
2324 *web_ui_type = WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType(
2325 GetSiteInstance()->GetBrowserContext(), dest_url);
2326 if (*web_ui_type != WebUI::kNoWebUI) {
2327 web_ui = delegate_->CreateWebUIForRenderFrameHost(dest_url);
nasko 2015/10/01 20:05:16 Why do we need the delegate to create it. Can't we
carlosk 2015/10/05 16:59:57 There is some code sharing for the creation logic
nasko 2015/10/07 23:49:32 Ah, I missed that. Yeah, passing WebContents as a
2328 CHECK(web_ui);
2329 // If we have assigned (zero or more) bindings to the NavigationEntry in the
2330 // past, make sure we're not granting it different bindings than it had
2331 // before. If so, note it and don't give it any bindings, to avoid a
2332 // potential privilege escalation.
2333 if (web_ui && past_bindings != NavigationEntryImpl::kInvalidBindings &&
2334 web_ui->GetBindings() != past_bindings) {
2335 RecordAction(base::UserMetricsAction("ProcessSwapBindingsMismatch_RVHM"));
2336 web_ui.reset();
2337 *web_ui_type = WebUI::kNoWebUI;
2338 }
2339 }
2340
2341 // Check RenderViewHost for proper bindings.
2342 if (web_ui && !render_view_host_->GetProcess()->IsForGuestsOnly()) {
2343 // If a WebUI was created for the URL and the RenderView is not in a guest
2344 // process, then enable missing bindings with the RenderViewHost.
2345 int new_bindings = web_ui->GetBindings();
2346 if ((render_view_host_->GetEnabledBindings() & new_bindings) !=
2347 new_bindings) {
2348 render_view_host_->AllowBindings(new_bindings);
2349 }
2350 }
2351
2352 CHECK_IMPLIES(web_ui, *web_ui_type != WebUI::kNoWebUI);
2353 CHECK_IMPLIES(!web_ui, *web_ui_type == WebUI::kNoWebUI);
2354 return web_ui.Pass();
2355 }
2356
2255 } // namespace content 2357 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698