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

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 ChromeOS errors caused by improper timing of RenderView(Created|Reused) calls. 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 24 matching lines...) Expand all
35 #include "content/browser/permissions/permission_service_impl.h" 35 #include "content/browser/permissions/permission_service_impl.h"
36 #include "content/browser/presentation/presentation_service_impl.h" 36 #include "content/browser/presentation/presentation_service_impl.h"
37 #include "content/browser/renderer_host/input/input_router.h" 37 #include "content/browser/renderer_host/input/input_router.h"
38 #include "content/browser/renderer_host/input/timeout_monitor.h" 38 #include "content/browser/renderer_host/input/timeout_monitor.h"
39 #include "content/browser/renderer_host/render_process_host_impl.h" 39 #include "content/browser/renderer_host/render_process_host_impl.h"
40 #include "content/browser/renderer_host/render_view_host_delegate.h" 40 #include "content/browser/renderer_host/render_view_host_delegate.h"
41 #include "content/browser/renderer_host/render_view_host_delegate_view.h" 41 #include "content/browser/renderer_host/render_view_host_delegate_view.h"
42 #include "content/browser/renderer_host/render_view_host_impl.h" 42 #include "content/browser/renderer_host/render_view_host_impl.h"
43 #include "content/browser/renderer_host/render_widget_host_impl.h" 43 #include "content/browser/renderer_host/render_widget_host_impl.h"
44 #include "content/browser/renderer_host/render_widget_host_view_base.h" 44 #include "content/browser/renderer_host/render_widget_host_view_base.h"
45 #include "content/browser/webui/web_ui_controller_factory_registry.h"
45 #include "content/common/accessibility_messages.h" 46 #include "content/common/accessibility_messages.h"
46 #include "content/common/frame_messages.h" 47 #include "content/common/frame_messages.h"
47 #include "content/common/input_messages.h" 48 #include "content/common/input_messages.h"
48 #include "content/common/inter_process_time_ticks_converter.h" 49 #include "content/common/inter_process_time_ticks_converter.h"
49 #include "content/common/navigation_params.h" 50 #include "content/common/navigation_params.h"
50 #include "content/common/render_frame_setup.mojom.h" 51 #include "content/common/render_frame_setup.mojom.h"
51 #include "content/common/site_isolation_policy.h" 52 #include "content/common/site_isolation_policy.h"
52 #include "content/common/swapped_out_messages.h" 53 #include "content/common/swapped_out_messages.h"
53 #include "content/public/browser/ax_event_notification_details.h" 54 #include "content/public/browser/ax_event_notification_details.h"
54 #include "content/public/browser/browser_accessibility_state.h" 55 #include "content/public/browser/browser_accessibility_state.h"
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 routing_id_(routing_id), 185 routing_id_(routing_id),
185 render_frame_created_(false), 186 render_frame_created_(false),
186 navigations_suspended_(false), 187 navigations_suspended_(false),
187 is_waiting_for_beforeunload_ack_(false), 188 is_waiting_for_beforeunload_ack_(false),
188 unload_ack_is_for_navigation_(false), 189 unload_ack_is_for_navigation_(false),
189 is_loading_(false), 190 is_loading_(false),
190 pending_commit_(false), 191 pending_commit_(false),
191 accessibility_reset_token_(0), 192 accessibility_reset_token_(0),
192 accessibility_reset_count_(0), 193 accessibility_reset_count_(0),
193 no_create_browser_accessibility_manager_for_testing_(false), 194 no_create_browser_accessibility_manager_for_testing_(false),
195 web_ui_type_(WebUI::kNoWebUI),
196 pending_web_ui_type_(WebUI::kNoWebUI),
197 should_reuse_web_ui_(false),
194 weak_ptr_factory_(this) { 198 weak_ptr_factory_(this) {
195 bool is_swapped_out = !!(flags & CREATE_RF_SWAPPED_OUT); 199 bool is_swapped_out = !!(flags & CREATE_RF_SWAPPED_OUT);
196 bool hidden = !!(flags & CREATE_RF_HIDDEN); 200 bool hidden = !!(flags & CREATE_RF_HIDDEN);
197 frame_tree_->AddRenderViewHostRef(render_view_host_); 201 frame_tree_->AddRenderViewHostRef(render_view_host_);
198 GetProcess()->AddRoute(routing_id_, this); 202 GetProcess()->AddRoute(routing_id_, this);
199 g_routing_id_frame_map.Get().insert(std::make_pair( 203 g_routing_id_frame_map.Get().insert(std::make_pair(
200 RenderFrameHostID(GetProcess()->GetID(), routing_id_), 204 RenderFrameHostID(GetProcess()->GetID(), routing_id_),
201 this)); 205 this));
202 206
203 if (is_swapped_out) { 207 if (is_swapped_out) {
204 rfh_state_ = STATE_SWAPPED_OUT; 208 rfh_state_ = STATE_SWAPPED_OUT;
205 } else { 209 } else {
206 rfh_state_ = STATE_DEFAULT; 210 rfh_state_ = STATE_DEFAULT;
207 GetSiteInstance()->increment_active_frame_count(); 211 GetSiteInstance()->increment_active_frame_count();
208 } 212 }
209 213
210 SetUpMojoIfNeeded(); 214 SetUpMojoIfNeeded();
211 swapout_event_monitor_timeout_.reset(new TimeoutMonitor(base::Bind( 215 swapout_event_monitor_timeout_.reset(new TimeoutMonitor(base::Bind(
212 &RenderFrameHostImpl::OnSwappedOut, weak_ptr_factory_.GetWeakPtr()))); 216 &RenderFrameHostImpl::OnSwappedOut, weak_ptr_factory_.GetWeakPtr())));
213 217
214 if (widget_routing_id != MSG_ROUTING_NONE) { 218 if (widget_routing_id != MSG_ROUTING_NONE) {
215 render_widget_host_ = new RenderWidgetHostImpl(rwh_delegate, GetProcess(), 219 render_widget_host_ = new RenderWidgetHostImpl(rwh_delegate, GetProcess(),
216 widget_routing_id, hidden); 220 widget_routing_id, hidden);
217 render_widget_host_->set_owned_by_render_frame_host(true); 221 render_widget_host_->set_owned_by_render_frame_host(true);
218 } 222 }
219 } 223 }
220 224
221 RenderFrameHostImpl::~RenderFrameHostImpl() { 225 RenderFrameHostImpl::~RenderFrameHostImpl() {
226 // Release the WebUI before all else as the WebUI accesses the RenderFrameHost
227 // during cleanup.
228 web_ui_type_ = WebUI::kNoWebUI;
229 web_ui_.reset();
230 pending_web_ui_type_ = WebUI::kNoWebUI;
231 pending_web_ui_.reset();
232
222 GetProcess()->RemoveRoute(routing_id_); 233 GetProcess()->RemoveRoute(routing_id_);
223 g_routing_id_frame_map.Get().erase( 234 g_routing_id_frame_map.Get().erase(
224 RenderFrameHostID(GetProcess()->GetID(), routing_id_)); 235 RenderFrameHostID(GetProcess()->GetID(), routing_id_));
225 236
226 if (delegate_ && render_frame_created_) 237 if (delegate_ && render_frame_created_)
227 delegate_->RenderFrameDeleted(this); 238 delegate_->RenderFrameDeleted(this);
228 239
229 // If this was swapped out, it already decremented the active frame count of 240 // If this was swapped out, it already decremented the active frame count of
230 // the SiteInstance it belongs to. 241 // the SiteInstance it belongs to.
231 if (IsRFHStateActive(rfh_state_)) 242 if (IsRFHStateActive(rfh_state_))
(...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 // gone through this, therefore just return. 1029 // gone through this, therefore just return.
1019 if (rfh_state_ != RenderFrameHostImpl::STATE_DEFAULT) { 1030 if (rfh_state_ != RenderFrameHostImpl::STATE_DEFAULT) {
1020 NOTREACHED() << "RFH should be in default state when calling SwapOut."; 1031 NOTREACHED() << "RFH should be in default state when calling SwapOut.";
1021 return; 1032 return;
1022 } 1033 }
1023 1034
1024 SetState(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT); 1035 SetState(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT);
1025 swapout_event_monitor_timeout_->Start( 1036 swapout_event_monitor_timeout_->Start(
1026 base::TimeDelta::FromMilliseconds(RenderViewHostImpl::kUnloadTimeoutMS)); 1037 base::TimeDelta::FromMilliseconds(RenderViewHostImpl::kUnloadTimeoutMS));
1027 1038
1039 web_ui_.reset();
1040 web_ui_type_ = WebUI::kNoWebUI;
1041
1028 // There may be no proxy if there are no active views in the process. 1042 // There may be no proxy if there are no active views in the process.
1029 int proxy_routing_id = MSG_ROUTING_NONE; 1043 int proxy_routing_id = MSG_ROUTING_NONE;
1030 FrameReplicationState replication_state; 1044 FrameReplicationState replication_state;
1031 if (proxy) { 1045 if (proxy) {
1032 set_render_frame_proxy_host(proxy); 1046 set_render_frame_proxy_host(proxy);
1033 proxy_routing_id = proxy->GetRoutingID(); 1047 proxy_routing_id = proxy->GetRoutingID();
1034 replication_state = proxy->frame_tree_node()->current_replication_state(); 1048 replication_state = proxy->frame_tree_node()->current_replication_state();
1035 } 1049 }
1036 1050
1037 if (IsRenderFrameLive()) { 1051 if (IsRenderFrameLive()) {
(...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after
1962 bool RenderFrameHostImpl::IsFocused() { 1976 bool RenderFrameHostImpl::IsFocused() {
1963 // TODO(mlamouri,kenrb): call GetRenderWidgetHost() directly when it stops 1977 // TODO(mlamouri,kenrb): call GetRenderWidgetHost() directly when it stops
1964 // returning nullptr in some cases. See https://crbug.com/455245. 1978 // returning nullptr in some cases. See https://crbug.com/455245.
1965 return RenderWidgetHostImpl::From( 1979 return RenderWidgetHostImpl::From(
1966 GetView()->GetRenderWidgetHost())->is_focused() && 1980 GetView()->GetRenderWidgetHost())->is_focused() &&
1967 frame_tree_->GetFocusedFrame() && 1981 frame_tree_->GetFocusedFrame() &&
1968 (frame_tree_->GetFocusedFrame() == frame_tree_node() || 1982 (frame_tree_->GetFocusedFrame() == frame_tree_node() ||
1969 frame_tree_->GetFocusedFrame()->IsDescendantOf(frame_tree_node())); 1983 frame_tree_->GetFocusedFrame()->IsDescendantOf(frame_tree_node()));
1970 } 1984 }
1971 1985
1986 void RenderFrameHostImpl::InitializeWebUI(const GURL& dest_url,
1987 int entry_bindings) {
1988 CHECK(!web_ui_ && !pending_web_ui_);
1989 web_ui_ = CreateWebUI(dest_url, entry_bindings, &web_ui_type_);
1990 }
1991
1992 void RenderFrameHostImpl::UpdatePendingWebUI(const GURL& dest_url,
1993 int entry_bindings) {
1994 WebUI::TypeID new_web_ui_type =
1995 WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType(
1996 GetSiteInstance()->GetBrowserContext(), dest_url);
1997
1998 // The current WebUI should be reused when dest_url requires a WebUI and its
1999 // type matches the current.
2000 should_reuse_web_ui_ = false;
2001 if (new_web_ui_type != WebUI::kNoWebUI && web_ui_type_ == new_web_ui_type) {
2002 DCHECK(web_ui_);
2003 should_reuse_web_ui_ = true;
2004
2005 // Reset the pending WebUI as the current one will be reused.
2006 pending_web_ui_.reset();
2007 pending_web_ui_type_ = WebUI::kNoWebUI;
2008 } else if (pending_web_ui_type_ != new_web_ui_type) {
2009 // Otherwise create, update or reset the pending one if its type doesn't
2010 // match the new type (if new type is kNoWebUI then it will be reset).
2011 pending_web_ui_ =
2012 CreateWebUI(dest_url, entry_bindings, &pending_web_ui_type_);
2013 }
2014
2015 CHECK_EQ(!pending_web_ui_, pending_web_ui_type_ == WebUI::kNoWebUI);
2016 }
2017
2018 void RenderFrameHostImpl::CommitPendingWebUI() {
2019 if (should_reuse_web_ui_) {
2020 CHECK(!pending_web_ui_ && pending_web_ui_type_ == WebUI::kNoWebUI);
2021 should_reuse_web_ui_ = false;
2022 } else {
2023 web_ui_ = pending_web_ui_.Pass();
2024 web_ui_type_ = pending_web_ui_type_;
2025 pending_web_ui_type_ = WebUI::kNoWebUI;
2026 }
2027 }
2028
2029 void RenderFrameHostImpl::DiscardPendingWebUI() {
2030 pending_web_ui_.reset();
2031 pending_web_ui_type_ = WebUI::kNoWebUI;
2032 should_reuse_web_ui_ = false;
2033 }
2034
1972 const image_downloader::ImageDownloaderPtr& 2035 const image_downloader::ImageDownloaderPtr&
1973 RenderFrameHostImpl::GetMojoImageDownloader() { 2036 RenderFrameHostImpl::GetMojoImageDownloader() {
1974 if (!mojo_image_downloader_.get() && GetServiceRegistry()) { 2037 if (!mojo_image_downloader_.get() && GetServiceRegistry()) {
1975 GetServiceRegistry()->ConnectToRemoteService( 2038 GetServiceRegistry()->ConnectToRemoteService(
1976 mojo::GetProxy(&mojo_image_downloader_)); 2039 mojo::GetProxy(&mojo_image_downloader_));
1977 } 2040 }
1978 return mojo_image_downloader_; 2041 return mojo_image_downloader_;
1979 } 2042 }
1980 2043
1981 bool RenderFrameHostImpl::IsSameSiteInstance( 2044 bool RenderFrameHostImpl::IsSameSiteInstance(
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
2266 ui::AX_ATTR_CHILD_TREE_ID, 2329 ui::AX_ATTR_CHILD_TREE_ID,
2267 BrowserPluginInstanceIDToAXTreeID(value))); 2330 BrowserPluginInstanceIDToAXTreeID(value)));
2268 break; 2331 break;
2269 case AX_CONTENT_INT_ATTRIBUTE_LAST: 2332 case AX_CONTENT_INT_ATTRIBUTE_LAST:
2270 NOTREACHED(); 2333 NOTREACHED();
2271 break; 2334 break;
2272 } 2335 }
2273 } 2336 }
2274 } 2337 }
2275 2338
2339 scoped_ptr<WebUIImpl> RenderFrameHostImpl::CreateWebUI(
2340 const GURL& dest_url,
2341 int entry_bindings,
2342 WebUI::TypeID* web_ui_type) {
2343 if (!dest_url.is_valid()) {
2344 *web_ui_type = WebUI::kNoWebUI;
2345 return nullptr;
2346 }
2347
2348 scoped_ptr<WebUIImpl> web_ui;
2349 *web_ui_type = WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType(
2350 GetSiteInstance()->GetBrowserContext(), dest_url);
2351 if (*web_ui_type != WebUI::kNoWebUI) {
2352 web_ui = delegate_->CreateWebUIForRenderFrameHost(dest_url);
2353 CHECK(web_ui);
2354
2355 // If we have assigned (zero or more) bindings to the NavigationEntry in the
2356 // past, make sure we're not granting it different bindings than it had
2357 // before. If so, note it and don't give it any bindings, to avoid a
2358 // potential privilege escalation.
2359 if (entry_bindings != NavigationEntryImpl::kInvalidBindings &&
2360 web_ui->GetBindings() != entry_bindings) {
2361 RecordAction(base::UserMetricsAction("ProcessSwapBindingsMismatch_RVHM"));
2362 *web_ui_type = WebUI::kNoWebUI;
2363 return nullptr;
2364 }
2365 }
2366
2367 // Check RenderViewHost for proper bindings.
2368 if (web_ui && !render_view_host_->GetProcess()->IsForGuestsOnly()) {
2369 // If a WebUI was created for the URL and the RenderView is not in a guest
2370 // process, then enable missing bindings with the RenderViewHost.
2371 int new_bindings = web_ui->GetBindings();
2372 if ((render_view_host_->GetEnabledBindings() & new_bindings) !=
2373 new_bindings) {
2374 render_view_host_->AllowBindings(new_bindings);
2375 }
2376 }
2377
2378 CHECK_EQ(!web_ui, *web_ui_type == WebUI::kNoWebUI);
2379 return web_ui.Pass();
2380 }
2381
2276 } // namespace content 2382 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698