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

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 uninitialized variable and missing call to WebUIImpl::RenderViewReused. 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 entry_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 pending_web_ui_type_(WebUI::kNoWebUI),
198 should_reuse_web_ui_(false),
193 weak_ptr_factory_(this) { 199 weak_ptr_factory_(this) {
194 bool is_swapped_out = !!(flags & CREATE_RF_SWAPPED_OUT); 200 bool is_swapped_out = !!(flags & CREATE_RF_SWAPPED_OUT);
195 bool hidden = !!(flags & CREATE_RF_HIDDEN); 201 bool hidden = !!(flags & CREATE_RF_HIDDEN);
196 frame_tree_->AddRenderViewHostRef(render_view_host_); 202 frame_tree_->AddRenderViewHostRef(render_view_host_);
197 GetProcess()->AddRoute(routing_id_, this); 203 GetProcess()->AddRoute(routing_id_, this);
198 g_routing_id_frame_map.Get().insert(std::make_pair( 204 g_routing_id_frame_map.Get().insert(std::make_pair(
199 RenderFrameHostID(GetProcess()->GetID(), routing_id_), 205 RenderFrameHostID(GetProcess()->GetID(), routing_id_),
200 this)); 206 this));
201 207
202 if (is_swapped_out) { 208 if (is_swapped_out) {
203 rfh_state_ = STATE_SWAPPED_OUT; 209 rfh_state_ = STATE_SWAPPED_OUT;
204 } else { 210 } else {
205 rfh_state_ = STATE_DEFAULT; 211 rfh_state_ = STATE_DEFAULT;
206 GetSiteInstance()->increment_active_frame_count(); 212 GetSiteInstance()->increment_active_frame_count();
207 } 213 }
208 214
209 SetUpMojoIfNeeded(); 215 SetUpMojoIfNeeded();
210 swapout_event_monitor_timeout_.reset(new TimeoutMonitor(base::Bind( 216 swapout_event_monitor_timeout_.reset(new TimeoutMonitor(base::Bind(
211 &RenderFrameHostImpl::OnSwappedOut, weak_ptr_factory_.GetWeakPtr()))); 217 &RenderFrameHostImpl::OnSwappedOut, weak_ptr_factory_.GetWeakPtr())));
212 218
213 if (widget_routing_id != MSG_ROUTING_NONE) { 219 if (widget_routing_id != MSG_ROUTING_NONE) {
214 render_widget_host_ = new RenderWidgetHostImpl(rwh_delegate, GetProcess(), 220 render_widget_host_ = new RenderWidgetHostImpl(rwh_delegate, GetProcess(),
215 widget_routing_id, hidden); 221 widget_routing_id, hidden);
216 render_widget_host_->set_owned_by_render_frame_host(true); 222 render_widget_host_->set_owned_by_render_frame_host(true);
217 } 223 }
224
225 web_ui_ = CreateWebUI(dest_url, entry_bindings, &web_ui_type_);
226 // If a WebUI is created and this RenderFrameHost is for the main frame, it is
nasko 2015/10/07 23:49:33 nit: Empty line between code and comment lines.
carlosk 2015/10/09 17:29:10 Done here and a few more places.
227 // assumed that the associated RenderViewHost has also just been created and
228 // notify the WebUI the RenderView was created.
229 if (web_ui_ && frame_tree_node_->IsMainFrame())
230 web_ui_->RenderViewCreated(render_view_host_);
218 } 231 }
219 232
220 RenderFrameHostImpl::~RenderFrameHostImpl() { 233 RenderFrameHostImpl::~RenderFrameHostImpl() {
234 // Release the WebUI before all else as the WebUI accesses the RenderFrameHost
235 // during cleanup.
236 web_ui_type_ = WebUI::kNoWebUI;
237 web_ui_.reset();
238 pending_web_ui_type_ = WebUI::kNoWebUI;
239 pending_web_ui_.reset();
240
221 GetProcess()->RemoveRoute(routing_id_); 241 GetProcess()->RemoveRoute(routing_id_);
222 g_routing_id_frame_map.Get().erase( 242 g_routing_id_frame_map.Get().erase(
223 RenderFrameHostID(GetProcess()->GetID(), routing_id_)); 243 RenderFrameHostID(GetProcess()->GetID(), routing_id_));
224 244
225 if (delegate_ && render_frame_created_) 245 if (delegate_ && render_frame_created_)
226 delegate_->RenderFrameDeleted(this); 246 delegate_->RenderFrameDeleted(this);
227 247
228 // If this was swapped out, it already decremented the active frame count of 248 // If this was swapped out, it already decremented the active frame count of
229 // the SiteInstance it belongs to. 249 // the SiteInstance it belongs to.
230 if (IsRFHStateActive(rfh_state_)) 250 if (IsRFHStateActive(rfh_state_))
(...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 // gone through this, therefore just return. 1033 // gone through this, therefore just return.
1014 if (rfh_state_ != RenderFrameHostImpl::STATE_DEFAULT) { 1034 if (rfh_state_ != RenderFrameHostImpl::STATE_DEFAULT) {
1015 NOTREACHED() << "RFH should be in default state when calling SwapOut."; 1035 NOTREACHED() << "RFH should be in default state when calling SwapOut.";
1016 return; 1036 return;
1017 } 1037 }
1018 1038
1019 SetState(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT); 1039 SetState(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT);
1020 swapout_event_monitor_timeout_->Start( 1040 swapout_event_monitor_timeout_->Start(
1021 base::TimeDelta::FromMilliseconds(RenderViewHostImpl::kUnloadTimeoutMS)); 1041 base::TimeDelta::FromMilliseconds(RenderViewHostImpl::kUnloadTimeoutMS));
1022 1042
1043 web_ui_.reset();
1044 web_ui_type_ = WebUI::kNoWebUI;
1045
1023 // 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.
1024 int proxy_routing_id = MSG_ROUTING_NONE; 1047 int proxy_routing_id = MSG_ROUTING_NONE;
1025 FrameReplicationState replication_state; 1048 FrameReplicationState replication_state;
1026 if (proxy) { 1049 if (proxy) {
1027 set_render_frame_proxy_host(proxy); 1050 set_render_frame_proxy_host(proxy);
1028 proxy_routing_id = proxy->GetRoutingID(); 1051 proxy_routing_id = proxy->GetRoutingID();
1029 replication_state = proxy->frame_tree_node()->current_replication_state(); 1052 replication_state = proxy->frame_tree_node()->current_replication_state();
1030 } 1053 }
1031 1054
1032 if (IsRenderFrameLive()) { 1055 if (IsRenderFrameLive()) {
(...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after
1952 bool RenderFrameHostImpl::IsFocused() { 1975 bool RenderFrameHostImpl::IsFocused() {
1953 // TODO(mlamouri,kenrb): call GetRenderWidgetHost() directly when it stops 1976 // TODO(mlamouri,kenrb): call GetRenderWidgetHost() directly when it stops
1954 // returning nullptr in some cases. See https://crbug.com/455245. 1977 // returning nullptr in some cases. See https://crbug.com/455245.
1955 return RenderWidgetHostImpl::From( 1978 return RenderWidgetHostImpl::From(
1956 GetView()->GetRenderWidgetHost())->is_focused() && 1979 GetView()->GetRenderWidgetHost())->is_focused() &&
1957 frame_tree_->GetFocusedFrame() && 1980 frame_tree_->GetFocusedFrame() &&
1958 (frame_tree_->GetFocusedFrame() == frame_tree_node() || 1981 (frame_tree_->GetFocusedFrame() == frame_tree_node() ||
1959 frame_tree_->GetFocusedFrame()->IsDescendantOf(frame_tree_node())); 1982 frame_tree_->GetFocusedFrame()->IsDescendantOf(frame_tree_node()));
1960 } 1983 }
1961 1984
1985 void RenderFrameHostImpl::UpdatePendingWebUI(const GURL& dest_url,
1986 int entry_bindings) {
1987 WebUI::TypeID new_web_ui_type =
1988 WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType(
1989 GetSiteInstance()->GetBrowserContext(), dest_url);
1990 // The current WebUI should be reused when dest_url requires a WebUI and its
1991 // type matches the current.
1992 should_reuse_web_ui_ = false;
1993 if (new_web_ui_type != WebUI::kNoWebUI && web_ui_type_ == new_web_ui_type) {
1994 DCHECK(web_ui_);
1995 should_reuse_web_ui_ = true;
1996 // Reset the pending WebUI as the current one will be reused.
1997 pending_web_ui_.reset();
1998 pending_web_ui_type_ = WebUI::kNoWebUI;
1999 } else if (pending_web_ui_type_ != new_web_ui_type) {
2000 // Otherwise create, update or reset the pending one if its type doesn't
2001 // match the new type (if new type is kNoWebUI then it will be reset).
2002 pending_web_ui_ =
2003 CreateWebUI(dest_url, entry_bindings, &pending_web_ui_type_);
2004 }
2005 // If a pending WebUI is set (be it an actual pending one or the reused
2006 // current one) and the associated RenderFrame is live, notify the WebUI about
2007 // the reusing of the RenderView.
2008 if (pending_web_ui() && IsRenderFrameLive()) {
2009 pending_web_ui()->RenderViewReused(render_view_host_,
2010 frame_tree_node_->IsMainFrame());
2011 }
2012 CHECK_IMPLIES(pending_web_ui_, pending_web_ui_type_ != WebUI::kNoWebUI);
2013 CHECK_IMPLIES(!pending_web_ui_, pending_web_ui_type_ == WebUI::kNoWebUI);
2014 }
2015
2016 void RenderFrameHostImpl::CommitPendingWebUI() {
2017 if (should_reuse_web_ui_) {
2018 CHECK(!pending_web_ui_ && pending_web_ui_type_ == WebUI::kNoWebUI);
2019 should_reuse_web_ui_ = false;
2020 } else {
2021 web_ui_ = pending_web_ui_.Pass();
2022 web_ui_type_ = pending_web_ui_type_;
2023 pending_web_ui_type_ = WebUI::kNoWebUI;
2024 }
2025 }
2026
2027 void RenderFrameHostImpl::DiscardPendingWebUI() {
2028 pending_web_ui_.reset();
2029 pending_web_ui_type_ = WebUI::kNoWebUI;
2030 should_reuse_web_ui_ = false;
2031 }
2032
1962 const image_downloader::ImageDownloaderPtr& 2033 const image_downloader::ImageDownloaderPtr&
1963 RenderFrameHostImpl::GetMojoImageDownloader() { 2034 RenderFrameHostImpl::GetMojoImageDownloader() {
1964 if (!mojo_image_downloader_.get() && GetServiceRegistry()) { 2035 if (!mojo_image_downloader_.get() && GetServiceRegistry()) {
1965 GetServiceRegistry()->ConnectToRemoteService( 2036 GetServiceRegistry()->ConnectToRemoteService(
1966 mojo::GetProxy(&mojo_image_downloader_)); 2037 mojo::GetProxy(&mojo_image_downloader_));
1967 } 2038 }
1968 return mojo_image_downloader_; 2039 return mojo_image_downloader_;
1969 } 2040 }
1970 2041
1971 bool RenderFrameHostImpl::IsSameSiteInstance( 2042 bool RenderFrameHostImpl::IsSameSiteInstance(
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
2247 ui::AX_ATTR_CHILD_TREE_ID, 2318 ui::AX_ATTR_CHILD_TREE_ID,
2248 BrowserPluginInstanceIDToAXTreeID(value))); 2319 BrowserPluginInstanceIDToAXTreeID(value)));
2249 break; 2320 break;
2250 case AX_CONTENT_INT_ATTRIBUTE_LAST: 2321 case AX_CONTENT_INT_ATTRIBUTE_LAST:
2251 NOTREACHED(); 2322 NOTREACHED();
2252 break; 2323 break;
2253 } 2324 }
2254 } 2325 }
2255 } 2326 }
2256 2327
2328 scoped_ptr<WebUIImpl> RenderFrameHostImpl::CreateWebUI(
2329 const GURL& dest_url,
2330 int entry_bindings,
2331 WebUI::TypeID* web_ui_type) {
2332 scoped_ptr<WebUIImpl> web_ui;
2333 *web_ui_type = WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType(
2334 GetSiteInstance()->GetBrowserContext(), dest_url);
2335 if (*web_ui_type != WebUI::kNoWebUI) {
2336 web_ui = delegate_->CreateWebUIForRenderFrameHost(dest_url);
2337 CHECK(web_ui);
2338 // If we have assigned (zero or more) bindings to the NavigationEntry in the
2339 // past, make sure we're not granting it different bindings than it had
2340 // before. If so, note it and don't give it any bindings, to avoid a
2341 // potential privilege escalation.
2342 if (web_ui && entry_bindings != NavigationEntryImpl::kInvalidBindings &&
2343 web_ui->GetBindings() != entry_bindings) {
2344 RecordAction(base::UserMetricsAction("ProcessSwapBindingsMismatch_RVHM"));
2345 web_ui.reset();
2346 *web_ui_type = WebUI::kNoWebUI;
2347 }
2348 }
2349
2350 // Check RenderViewHost for proper bindings.
2351 if (web_ui && !render_view_host_->GetProcess()->IsForGuestsOnly()) {
2352 // If a WebUI was created for the URL and the RenderView is not in a guest
2353 // process, then enable missing bindings with the RenderViewHost.
2354 int new_bindings = web_ui->GetBindings();
2355 if ((render_view_host_->GetEnabledBindings() & new_bindings) !=
2356 new_bindings) {
2357 render_view_host_->AllowBindings(new_bindings);
2358 }
2359 }
2360
2361 CHECK_IMPLIES(web_ui, *web_ui_type != WebUI::kNoWebUI);
2362 CHECK_IMPLIES(!web_ui, *web_ui_type == WebUI::kNoWebUI);
2363 return web_ui.Pass();
2364 }
2365
2257 } // namespace content 2366 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/render_frame_host_impl.h ('k') | content/browser/frame_host/render_frame_host_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698