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

Side by Side Diff: content/browser/frame_host/render_frame_host_manager.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: Simplified the code mainly by consolidating WebUIImpl::RenderView* 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_manager.h" 5 #include "content/browser/frame_host/render_frame_host_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 12 matching lines...) Expand all
23 #include "content/browser/frame_host/navigation_request.h" 23 #include "content/browser/frame_host/navigation_request.h"
24 #include "content/browser/frame_host/navigator.h" 24 #include "content/browser/frame_host/navigator.h"
25 #include "content/browser/frame_host/render_frame_host_factory.h" 25 #include "content/browser/frame_host/render_frame_host_factory.h"
26 #include "content/browser/frame_host/render_frame_host_impl.h" 26 #include "content/browser/frame_host/render_frame_host_impl.h"
27 #include "content/browser/frame_host/render_frame_proxy_host.h" 27 #include "content/browser/frame_host/render_frame_proxy_host.h"
28 #include "content/browser/renderer_host/render_process_host_impl.h" 28 #include "content/browser/renderer_host/render_process_host_impl.h"
29 #include "content/browser/renderer_host/render_view_host_factory.h" 29 #include "content/browser/renderer_host/render_view_host_factory.h"
30 #include "content/browser/renderer_host/render_view_host_impl.h" 30 #include "content/browser/renderer_host/render_view_host_impl.h"
31 #include "content/browser/site_instance_impl.h" 31 #include "content/browser/site_instance_impl.h"
32 #include "content/browser/webui/web_ui_controller_factory_registry.h" 32 #include "content/browser/webui/web_ui_controller_factory_registry.h"
33 #include "content/browser/webui/web_ui_impl.h"
34 #include "content/common/frame_messages.h" 33 #include "content/common/frame_messages.h"
35 #include "content/common/site_isolation_policy.h" 34 #include "content/common/site_isolation_policy.h"
36 #include "content/common/view_messages.h" 35 #include "content/common/view_messages.h"
37 #include "content/public/browser/content_browser_client.h" 36 #include "content/public/browser/content_browser_client.h"
38 #include "content/public/browser/render_process_host_observer.h" 37 #include "content/public/browser/render_process_host_observer.h"
39 #include "content/public/browser/render_widget_host_iterator.h" 38 #include "content/public/browser/render_widget_host_iterator.h"
40 #include "content/public/browser/render_widget_host_view.h" 39 #include "content/public/browser/render_widget_host_view.h"
41 #include "content/public/browser/user_metrics.h" 40 #include "content/public/browser/user_metrics.h"
42 #include "content/public/browser/web_ui_controller.h"
43 #include "content/public/common/browser_plugin_guest_mode.h" 41 #include "content/public/common/browser_plugin_guest_mode.h"
44 #include "content/public/common/content_switches.h" 42 #include "content/public/common/content_switches.h"
45 #include "content/public/common/referrer.h" 43 #include "content/public/common/referrer.h"
46 #include "content/public/common/url_constants.h" 44 #include "content/public/common/url_constants.h"
47 45
48 namespace content { 46 namespace content {
49 47
50 namespace { 48 namespace {
51 49
52 // Helper function to add the FrameTree of the given node's opener to the list 50 // Helper function to add the FrameTree of the given node's opener to the list
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 RenderViewHostDelegate* render_view_delegate, 211 RenderViewHostDelegate* render_view_delegate,
214 RenderWidgetHostDelegate* render_widget_delegate, 212 RenderWidgetHostDelegate* render_widget_delegate,
215 Delegate* delegate) 213 Delegate* delegate)
216 : frame_tree_node_(frame_tree_node), 214 : frame_tree_node_(frame_tree_node),
217 delegate_(delegate), 215 delegate_(delegate),
218 render_frame_delegate_(render_frame_delegate), 216 render_frame_delegate_(render_frame_delegate),
219 render_view_delegate_(render_view_delegate), 217 render_view_delegate_(render_view_delegate),
220 render_widget_delegate_(render_widget_delegate), 218 render_widget_delegate_(render_widget_delegate),
221 proxy_hosts_(new RenderFrameProxyHostMap(this)), 219 proxy_hosts_(new RenderFrameProxyHostMap(this)),
222 interstitial_page_(nullptr), 220 interstitial_page_(nullptr),
223 should_reuse_web_ui_(false),
224 weak_factory_(this) { 221 weak_factory_(this) {
225 DCHECK(frame_tree_node_); 222 DCHECK(frame_tree_node_);
226 } 223 }
227 224
228 RenderFrameHostManager::~RenderFrameHostManager() { 225 RenderFrameHostManager::~RenderFrameHostManager() {
229 if (pending_render_frame_host_) { 226 if (pending_render_frame_host_) {
230 scoped_ptr<RenderFrameHostImpl> relic = UnsetPendingRenderFrameHost(); 227 scoped_ptr<RenderFrameHostImpl> relic = UnsetPendingRenderFrameHost();
231 ShutdownProxiesIfLastActiveFrameInSiteInstance(relic.get()); 228 ShutdownProxiesIfLastActiveFrameInSiteInstance(relic.get());
232 } 229 }
233 230
234 if (speculative_render_frame_host_) { 231 if (speculative_render_frame_host_) {
235 scoped_ptr<RenderFrameHostImpl> relic = UnsetSpeculativeRenderFrameHost(); 232 scoped_ptr<RenderFrameHostImpl> relic = UnsetSpeculativeRenderFrameHost();
236 ShutdownProxiesIfLastActiveFrameInSiteInstance(relic.get()); 233 ShutdownProxiesIfLastActiveFrameInSiteInstance(relic.get());
237 } 234 }
238 235
239 ShutdownProxiesIfLastActiveFrameInSiteInstance(render_frame_host_.get()); 236 ShutdownProxiesIfLastActiveFrameInSiteInstance(render_frame_host_.get());
240 237
241 // Delete any RenderFrameProxyHosts and swapped out RenderFrameHosts. 238 // Delete any RenderFrameProxyHosts and swapped out RenderFrameHosts.
242 // It is important to delete those prior to deleting the current 239 // It is important to delete those prior to deleting the current
243 // RenderFrameHost, since the CrossProcessFrameConnector (owned by 240 // RenderFrameHost, since the CrossProcessFrameConnector (owned by
244 // RenderFrameProxyHost) points to the RenderWidgetHostView associated with 241 // RenderFrameProxyHost) points to the RenderWidgetHostView associated with
245 // the current RenderFrameHost and uses it during its destructor. 242 // the current RenderFrameHost and uses it during its destructor.
246 ResetProxyHosts(); 243 ResetProxyHosts();
247 244
248 // Release the WebUI prior to resetting the current RenderFrameHost, as the
249 // WebUI accesses the RenderFrameHost during cleanup.
250 web_ui_.reset();
251
252 // We should always have a current RenderFrameHost except in some tests. 245 // We should always have a current RenderFrameHost except in some tests.
253 SetRenderFrameHost(scoped_ptr<RenderFrameHostImpl>()); 246 SetRenderFrameHost(scoped_ptr<RenderFrameHostImpl>());
254 } 247 }
255 248
256 void RenderFrameHostManager::Init(BrowserContext* browser_context, 249 void RenderFrameHostManager::Init(BrowserContext* browser_context,
257 SiteInstance* site_instance, 250 SiteInstance* site_instance,
258 int32 view_routing_id, 251 int32 view_routing_id,
259 int32 frame_routing_id, 252 int32 frame_routing_id,
260 int32 widget_routing_id) { 253 int32 widget_routing_id) {
261 // Create a RenderViewHost and RenderFrameHost, once we have an instance. It 254 // Create a RenderViewHost and RenderFrameHost, once we have an instance. It
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 337
345 void RenderFrameHostManager::RemoveOuterDelegateFrame() { 338 void RenderFrameHostManager::RemoveOuterDelegateFrame() {
346 FrameTreeNode* outer_delegate_frame_tree_node = 339 FrameTreeNode* outer_delegate_frame_tree_node =
347 FrameTreeNode::GloballyFindByID( 340 FrameTreeNode::GloballyFindByID(
348 delegate_->GetOuterDelegateFrameTreeNodeID()); 341 delegate_->GetOuterDelegateFrameTreeNodeID());
349 DCHECK(outer_delegate_frame_tree_node->parent()); 342 DCHECK(outer_delegate_frame_tree_node->parent());
350 outer_delegate_frame_tree_node->frame_tree()->RemoveFrame( 343 outer_delegate_frame_tree_node->frame_tree()->RemoveFrame(
351 outer_delegate_frame_tree_node); 344 outer_delegate_frame_tree_node);
352 } 345 }
353 346
354 void RenderFrameHostManager::SetPendingWebUI(const GURL& url, int bindings) {
355 pending_web_ui_ = CreateWebUI(url, bindings);
356 pending_and_current_web_ui_.reset();
357 }
358
359 scoped_ptr<WebUIImpl> RenderFrameHostManager::CreateWebUI(const GURL& url,
360 int bindings) {
361 scoped_ptr<WebUIImpl> new_web_ui(delegate_->CreateWebUIForRenderManager(url));
362
363 // If we have assigned (zero or more) bindings to this NavigationEntry in the
364 // past, make sure we're not granting it different bindings than it had
365 // before. If so, note it and don't give it any bindings, to avoid a
366 // potential privilege escalation.
367 if (new_web_ui && bindings != NavigationEntryImpl::kInvalidBindings &&
368 new_web_ui->GetBindings() != bindings) {
369 RecordAction(base::UserMetricsAction("ProcessSwapBindingsMismatch_RVHM"));
370 return nullptr;
371 }
372 return new_web_ui.Pass();
373 }
374
375 RenderFrameHostImpl* RenderFrameHostManager::Navigate( 347 RenderFrameHostImpl* RenderFrameHostManager::Navigate(
376 const GURL& dest_url, 348 const GURL& dest_url,
377 const FrameNavigationEntry& frame_entry, 349 const FrameNavigationEntry& frame_entry,
378 const NavigationEntryImpl& entry) { 350 const NavigationEntryImpl& entry) {
379 TRACE_EVENT1("navigation", "RenderFrameHostManager:Navigate", 351 TRACE_EVENT1("navigation", "RenderFrameHostManager:Navigate",
380 "FrameTreeNode id", frame_tree_node_->frame_tree_node_id()); 352 "FrameTreeNode id", frame_tree_node_->frame_tree_node_id());
381 // Create a pending RenderFrameHost to use for the navigation. 353 // Create a pending RenderFrameHost to use for the navigation.
382 RenderFrameHostImpl* dest_render_frame_host = UpdateStateForNavigate( 354 RenderFrameHostImpl* dest_render_frame_host = UpdateStateForNavigate(
383 dest_url, 355 dest_url,
384 // TODO(creis): Move source_site_instance to FNE. 356 // TODO(creis): Move source_site_instance to FNE.
(...skipping 29 matching lines...) Expand all
414 // add a service to this RFH's ServiceRegistry). 386 // add a service to this RFH's ServiceRegistry).
415 dest_render_frame_host->SetUpMojoIfNeeded(); 387 dest_render_frame_host->SetUpMojoIfNeeded();
416 388
417 // Recreate the opener chain. 389 // Recreate the opener chain.
418 CreateOpenerProxies(dest_render_frame_host->GetSiteInstance(), 390 CreateOpenerProxies(dest_render_frame_host->GetSiteInstance(),
419 frame_tree_node_); 391 frame_tree_node_);
420 if (!InitRenderView(dest_render_frame_host->render_view_host(), 392 if (!InitRenderView(dest_render_frame_host->render_view_host(),
421 MSG_ROUTING_NONE)) 393 MSG_ROUTING_NONE))
422 return nullptr; 394 return nullptr;
423 395
396 // TODO(carlosk): figure out if WebUIImpl::RenderViewCreated should
397 // be invoked here for the *correct* WebUI instance.
nasko 2015/10/15 17:40:09 Are this and the same TODO below supposed to be re
carlosk 2015/10/19 17:21:01 My intention was not that but I was wrong so thank
398
424 // Now that we've created a new renderer, be sure to hide it if it isn't 399 // Now that we've created a new renderer, be sure to hide it if it isn't
425 // our primary one. Otherwise, we might crash if we try to call Show() 400 // our primary one. Otherwise, we might crash if we try to call Show()
426 // on it later. 401 // on it later.
427 if (dest_render_frame_host != render_frame_host_) { 402 if (dest_render_frame_host != render_frame_host_) {
428 if (dest_render_frame_host->GetView()) 403 if (dest_render_frame_host->GetView())
429 dest_render_frame_host->GetView()->Hide(); 404 dest_render_frame_host->GetView()->Hide();
430 } else { 405 } else {
431 // After a renderer crash we'd have marked the host as invisible, so we 406 // After a renderer crash we'd have marked the host as invisible, so we
432 // need to set the visibility of the new View to the correct value here 407 // need to set the visibility of the new View to the correct value here
433 // after reload. 408 // after reload.
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 638
664 // Make sure any dynamic changes to this frame's sandbox flags that were made 639 // Make sure any dynamic changes to this frame's sandbox flags that were made
665 // prior to navigation take effect. 640 // prior to navigation take effect.
666 CommitPendingSandboxFlags(); 641 CommitPendingSandboxFlags();
667 } 642 }
668 643
669 void RenderFrameHostManager::CommitPendingIfNecessary( 644 void RenderFrameHostManager::CommitPendingIfNecessary(
670 RenderFrameHostImpl* render_frame_host, 645 RenderFrameHostImpl* render_frame_host,
671 bool was_caused_by_user_gesture) { 646 bool was_caused_by_user_gesture) {
672 if (!pending_render_frame_host_ && !speculative_render_frame_host_) { 647 if (!pending_render_frame_host_ && !speculative_render_frame_host_) {
673 DCHECK_IMPLIES(should_reuse_web_ui_, web_ui_);
674 648
675 // We should only hear this from our current renderer. 649 // We should only hear this from our current renderer.
676 DCHECK_EQ(render_frame_host_, render_frame_host); 650 DCHECK_EQ(render_frame_host_, render_frame_host);
677 651
678 // Even when there is no pending RVH, there may be a pending Web UI. 652 // If current RenderFrameHost has a pending WebUI, commit it.
679 if (pending_web_ui() || speculative_web_ui_) 653 if (render_frame_host_->pending_web_ui())
680 CommitPending(); 654 CommitPending();
681 return; 655 return;
682 } 656 }
683 657
684 if (render_frame_host == pending_render_frame_host_ || 658 if (render_frame_host == pending_render_frame_host_ ||
685 render_frame_host == speculative_render_frame_host_) { 659 render_frame_host == speculative_render_frame_host_) {
686 // The pending cross-process navigation completed, so show the renderer. 660 // The pending cross-process navigation completed, so show the renderer.
687 CommitPending(); 661 CommitPending();
688 } else if (render_frame_host == render_frame_host_) { 662 } else if (render_frame_host == render_frame_host_) {
689 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 663 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 if (current_site_instance == dest_site_instance.get() || 992 if (current_site_instance == dest_site_instance.get() ||
1019 (!request.browser_initiated() && is_main_frame) || 993 (!request.browser_initiated() && is_main_frame) ||
1020 (!is_main_frame && !dest_site_instance->RequiresDedicatedProcess() && 994 (!is_main_frame && !dest_site_instance->RequiresDedicatedProcess() &&
1021 !current_site_instance->RequiresDedicatedProcess())) { 995 !current_site_instance->RequiresDedicatedProcess())) {
1022 // Reuse the current RFH if its SiteInstance matches the the navigation's 996 // Reuse the current RFH if its SiteInstance matches the the navigation's
1023 // or if this is a subframe navigation. We only swap RFHs for subframes when 997 // or if this is a subframe navigation. We only swap RFHs for subframes when
1024 // --site-per-process is enabled. 998 // --site-per-process is enabled.
1025 CleanUpNavigation(); 999 CleanUpNavigation();
1026 navigation_rfh = render_frame_host_.get(); 1000 navigation_rfh = render_frame_host_.get();
1027 1001
1028 // As SiteInstances are the same, check if the WebUI should be reused. 1002 // As SiteInstances are the same, make the RFH update its possible pending
1029 const NavigationEntry* current_navigation_entry = 1003 // WebUI.
1030 delegate_->GetLastCommittedNavigationEntryForRenderManager(); 1004 render_frame_host_->UpdatePendingWebUI(request.common_params().url,
1031 should_reuse_web_ui_ = ShouldReuseWebUI(current_navigation_entry, 1005 request.bindings());
1032 request.common_params().url); 1006 DCHECK(speculative_web_ui() == render_frame_host_->pending_web_ui());
1033 if (!should_reuse_web_ui_) { 1007
1034 speculative_web_ui_ = CreateWebUI(request.common_params().url, 1008 // If a pending WebUI was set on the current RenderFrameHost (be it a new
1035 request.bindings()); 1009 // one or the reused current one) and the associated RenderFrame is alive,
1036 // Make sure the current RenderViewHost has the right bindings. 1010 // notify the WebUI the RenderView is being reused.
1037 if (speculative_web_ui() && 1011 if (pending_web_ui() && render_frame_host_->IsRenderFrameLive()) {
1038 !render_frame_host_->GetProcess()->IsForGuestsOnly()) { 1012 pending_web_ui()->RenderViewReused(render_frame_host_->render_view_host(),
1039 render_frame_host_->render_view_host()->AllowBindings( 1013 frame_tree_node_->IsMainFrame());
1040 speculative_web_ui()->GetBindings());
1041 }
1042 } 1014 }
1015
1016 DCHECK(!speculative_render_frame_host_);
1043 } else { 1017 } else {
1044 // If the SiteInstance for the final URL doesn't match the one from the 1018 // If the SiteInstance for the final URL doesn't match the one from the
1045 // speculatively created RenderFrameHost, create a new RenderFrameHost using 1019 // speculatively created RenderFrameHost, create a new RenderFrameHost using
1046 // this new SiteInstance. 1020 // this new SiteInstance.
1047 if (!speculative_render_frame_host_ || 1021 if (!speculative_render_frame_host_ ||
1048 speculative_render_frame_host_->GetSiteInstance() != 1022 speculative_render_frame_host_->GetSiteInstance() !=
1049 dest_site_instance.get()) { 1023 dest_site_instance.get()) {
1050 CleanUpNavigation(); 1024 CleanUpNavigation();
1051 bool success = CreateSpeculativeRenderFrameHost( 1025 bool success = CreateSpeculativeRenderFrameHost(
1052 request.common_params().url, current_site_instance, 1026 request.common_params().url, current_site_instance,
1053 dest_site_instance.get(), request.bindings()); 1027 dest_site_instance.get(), request.bindings());
1054 DCHECK(success); 1028 DCHECK(success);
1029 } else {
1030 // When reusing an existing speculative RenderFrameHost its active WebUI
1031 // must be updated to make sure it matches the current URL. As it is not a
1032 // new RenderFrameHost instance it must be done by updating the pending
1033 // WebUI and immediately making it active.
1034 speculative_render_frame_host_->UpdatePendingWebUI(
1035 request.common_params().url, request.bindings());
1036 speculative_render_frame_host_->CommitPendingWebUI();
1055 } 1037 }
1056 DCHECK(speculative_render_frame_host_); 1038 DCHECK(speculative_render_frame_host_);
1039 DCHECK_EQ(speculative_web_ui(), speculative_render_frame_host_->web_ui());
1040 DCHECK(!speculative_render_frame_host_->pending_web_ui());
1041 DCHECK(!render_frame_host_->pending_web_ui());
1042
1057 navigation_rfh = speculative_render_frame_host_.get(); 1043 navigation_rfh = speculative_render_frame_host_.get();
1058 1044
1059 // Check if our current RFH is live. 1045 // Check if our current RFH is live.
1060 if (!render_frame_host_->IsRenderFrameLive()) { 1046 if (!render_frame_host_->IsRenderFrameLive()) {
1061 // The current RFH is not live. There's no reason to sit around with a 1047 // The current RFH is not live. There's no reason to sit around with a
1062 // sad tab or a newly created RFH while we wait for the navigation to 1048 // sad tab or a newly created RFH while we wait for the navigation to
1063 // complete. Just switch to the speculative RFH now and go back to normal. 1049 // complete. Just switch to the speculative RFH now and go back to normal.
1064 // (Note that we don't care about on{before}unload handlers if the current 1050 // (Note that we don't care about on{before}unload handlers if the current
1065 // RFH isn't live.) 1051 // RFH isn't live.)
1066 CommitPending(); 1052 CommitPending();
1067 } 1053 }
1068 } 1054 }
1069 DCHECK(navigation_rfh && 1055 DCHECK(navigation_rfh &&
1070 (navigation_rfh == render_frame_host_.get() || 1056 (navigation_rfh == render_frame_host_.get() ||
1071 navigation_rfh == speculative_render_frame_host_.get())); 1057 navigation_rfh == speculative_render_frame_host_.get()));
1072 1058
1073 // If the RenderFrame that needs to navigate is not live (its process was just 1059 // If the RenderFrame that needs to navigate is not live (its process was just
1074 // created or has crashed), initialize it. 1060 // created or has crashed), initialize it.
1075 if (!navigation_rfh->IsRenderFrameLive()) { 1061 if (!navigation_rfh->IsRenderFrameLive()) {
1076 // Recreate the opener chain. 1062 // Recreate the opener chain.
1077 CreateOpenerProxies(navigation_rfh->GetSiteInstance(), frame_tree_node_); 1063 CreateOpenerProxies(navigation_rfh->GetSiteInstance(), frame_tree_node_);
1078 if (!InitRenderView(navigation_rfh->render_view_host(), MSG_ROUTING_NONE)) { 1064 if (!InitRenderView(navigation_rfh->render_view_host(), MSG_ROUTING_NONE))
1079 return nullptr; 1065 return nullptr;
1080 } 1066
1067 // TODO(carlosk): figure out if WebUIImpl::RenderViewCreated should
1068 // be invoked here for the *correct* WebUI instance.
1081 1069
1082 if (navigation_rfh == render_frame_host_) { 1070 if (navigation_rfh == render_frame_host_) {
1083 // TODO(nasko): This is a very ugly hack. The Chrome extensions process 1071 // TODO(nasko): This is a very ugly hack. The Chrome extensions process
1084 // manager still uses NotificationService and expects to see a 1072 // manager still uses NotificationService and expects to see a
1085 // RenderViewHost changed notification after WebContents and 1073 // RenderViewHost changed notification after WebContents and
1086 // RenderFrameHostManager are completely initialized. This should be 1074 // RenderFrameHostManager are completely initialized. This should be
1087 // removed once the process manager moves away from NotificationService. 1075 // removed once the process manager moves away from NotificationService.
1088 // See https://crbug.com/462682. 1076 // See https://crbug.com/462682.
1089 delegate_->NotifyMainFrameSwappedFromRenderManager( 1077 delegate_->NotifyMainFrameSwappedFromRenderManager(
1090 nullptr, render_frame_host_->render_view_host()); 1078 nullptr, render_frame_host_->render_view_host());
1091 } 1079 }
1092 } 1080 }
1093 1081
1094 return navigation_rfh; 1082 return navigation_rfh;
1095 } 1083 }
1096 1084
1097 // PlzNavigate 1085 // PlzNavigate
1098 void RenderFrameHostManager::CleanUpNavigation() { 1086 void RenderFrameHostManager::CleanUpNavigation() {
1099 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( 1087 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
1100 switches::kEnableBrowserSideNavigation)); 1088 switches::kEnableBrowserSideNavigation));
1101 speculative_web_ui_.reset(); 1089 render_frame_host_->DiscardPendingWebUI();
carlosk 2015/10/15 16:34:08 Calling this here is incorrect for PlzNavigate. Th
nasko 2015/10/15 17:40:09 Acknowledged.
1102 should_reuse_web_ui_ = false;
1103 if (speculative_render_frame_host_) 1090 if (speculative_render_frame_host_)
1104 DiscardUnusedFrame(UnsetSpeculativeRenderFrameHost()); 1091 DiscardUnusedFrame(UnsetSpeculativeRenderFrameHost());
1105 } 1092 }
1106 1093
1107 // PlzNavigate 1094 // PlzNavigate
1108 scoped_ptr<RenderFrameHostImpl> 1095 scoped_ptr<RenderFrameHostImpl>
1109 RenderFrameHostManager::UnsetSpeculativeRenderFrameHost() { 1096 RenderFrameHostManager::UnsetSpeculativeRenderFrameHost() {
1110 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( 1097 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
1111 switches::kEnableBrowserSideNavigation)); 1098 switches::kEnableBrowserSideNavigation));
1112 speculative_render_frame_host_->GetProcess()->RemovePendingView(); 1099 speculative_render_frame_host_->GetProcess()->RemovePendingView();
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
1276 // We can't switch a RenderView between view source and non-view source mode 1263 // We can't switch a RenderView between view source and non-view source mode
1277 // without screwing up the session history sometimes (when navigating between 1264 // without screwing up the session history sometimes (when navigating between
1278 // "view-source:http://foo.com/" and "http://foo.com/", Blink doesn't treat 1265 // "view-source:http://foo.com/" and "http://foo.com/", Blink doesn't treat
1279 // it as a new navigation). So require a BrowsingInstance switch. 1266 // it as a new navigation). So require a BrowsingInstance switch.
1280 if (current_is_view_source_mode != new_is_view_source_mode) 1267 if (current_is_view_source_mode != new_is_view_source_mode)
1281 return true; 1268 return true;
1282 1269
1283 return false; 1270 return false;
1284 } 1271 }
1285 1272
1286 bool RenderFrameHostManager::ShouldReuseWebUI(
1287 const NavigationEntry* current_entry,
1288 const GURL& new_url) const {
1289 NavigationControllerImpl& controller =
1290 delegate_->GetControllerForRenderManager();
1291 return current_entry && web_ui_ &&
1292 (WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType(
1293 controller.GetBrowserContext(), current_entry->GetURL()) ==
1294 WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType(
1295 controller.GetBrowserContext(), new_url));
1296 }
1297
1298 SiteInstance* RenderFrameHostManager::GetSiteInstanceForNavigation( 1273 SiteInstance* RenderFrameHostManager::GetSiteInstanceForNavigation(
1299 const GURL& dest_url, 1274 const GURL& dest_url,
1300 SiteInstance* source_instance, 1275 SiteInstance* source_instance,
1301 SiteInstance* dest_instance, 1276 SiteInstance* dest_instance,
1302 SiteInstance* candidate_instance, 1277 SiteInstance* candidate_instance,
1303 ui::PageTransition transition, 1278 ui::PageTransition transition,
1304 bool dest_is_restore, 1279 bool dest_is_restore,
1305 bool dest_is_view_source_mode) { 1280 bool dest_is_view_source_mode) {
1306 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); 1281 SiteInstance* current_instance = render_frame_host_->GetSiteInstance();
1307 1282
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
1601 // to open a new tab to an interstitial-inducing URL, and then navigates 1576 // to open a new tab to an interstitial-inducing URL, and then navigates
1602 // the page to a different same-site URL. (This seems very unlikely in 1577 // the page to a different same-site URL. (This seems very unlikely in
1603 // practice.) 1578 // practice.)
1604 if (current_entry) 1579 if (current_entry)
1605 return current_entry->GetURL(); 1580 return current_entry->GetURL();
1606 return current_instance->GetSiteURL(); 1581 return current_instance->GetSiteURL();
1607 } 1582 }
1608 1583
1609 void RenderFrameHostManager::CreatePendingRenderFrameHost( 1584 void RenderFrameHostManager::CreatePendingRenderFrameHost(
1610 SiteInstance* old_instance, 1585 SiteInstance* old_instance,
1611 SiteInstance* new_instance) { 1586 SiteInstance* new_instance,
1587 const GURL& url,
1588 int bindings) {
1612 int create_render_frame_flags = 0; 1589 int create_render_frame_flags = 0;
1613 if (delegate_->IsHidden()) 1590 if (delegate_->IsHidden())
1614 create_render_frame_flags |= CREATE_RF_HIDDEN; 1591 create_render_frame_flags |= CREATE_RF_HIDDEN;
1615 1592
1616 if (pending_render_frame_host_) 1593 if (pending_render_frame_host_)
1617 CancelPending(); 1594 CancelPending();
1618 1595
1619 // The process for the new SiteInstance may (if we're sharing a process with 1596 // The process for the new SiteInstance may (if we're sharing a process with
1620 // another host that already initialized it) or may not (we have our own 1597 // another host that already initialized it) or may not (we have our own
1621 // process or the existing process crashed) have been initialized. Calling 1598 // process or the existing process crashed) have been initialized. Calling
1622 // Init multiple times will be ignored, so this is safe. 1599 // Init multiple times will be ignored, so this is safe.
1623 if (!new_instance->GetProcess()->Init()) 1600 if (!new_instance->GetProcess()->Init())
1624 return; 1601 return;
1625 1602
1626 CreateProxiesForNewRenderFrameHost(old_instance, new_instance); 1603 CreateProxiesForNewRenderFrameHost(old_instance, new_instance);
1627 1604
1628 // Create a non-swapped-out RFH with the given opener. 1605 // Create a non-swapped-out RFH with the given opener.
1629 pending_render_frame_host_ = CreateRenderFrame( 1606 pending_render_frame_host_ =
1630 new_instance, pending_web_ui(), create_render_frame_flags, nullptr); 1607 CreateRenderFrame(new_instance, create_render_frame_flags, nullptr);
1608
1609 InitializeWebUI(url, bindings, pending_render_frame_host_.get());
nasko 2015/10/15 17:40:09 Now that I think a bit more about it, this call ca
carlosk 2015/10/19 17:21:01 Done. What I like most about this format is that,
1631 } 1610 }
1632 1611
1633 void RenderFrameHostManager::CreateProxiesForNewRenderFrameHost( 1612 void RenderFrameHostManager::CreateProxiesForNewRenderFrameHost(
1634 SiteInstance* old_instance, 1613 SiteInstance* old_instance,
1635 SiteInstance* new_instance) { 1614 SiteInstance* new_instance) {
1636 // Only create opener proxies if they are in the same BrowsingInstance. 1615 // Only create opener proxies if they are in the same BrowsingInstance.
1637 if (new_instance->IsRelatedSiteInstance(old_instance)) { 1616 if (new_instance->IsRelatedSiteInstance(old_instance)) {
1638 CreateOpenerProxies(new_instance, frame_tree_node_); 1617 CreateOpenerProxies(new_instance, frame_tree_node_);
1639 } else if (SiteIsolationPolicy::AreCrossProcessFramesPossible()) { 1618 } else if (SiteIsolationPolicy::AreCrossProcessFramesPossible()) {
1640 // Ensure that the frame tree has RenderFrameProxyHosts for the 1619 // Ensure that the frame tree has RenderFrameProxyHosts for the
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1708 } 1687 }
1709 1688
1710 // PlzNavigate 1689 // PlzNavigate
1711 bool RenderFrameHostManager::CreateSpeculativeRenderFrameHost( 1690 bool RenderFrameHostManager::CreateSpeculativeRenderFrameHost(
1712 const GURL& url, 1691 const GURL& url,
1713 SiteInstance* old_instance, 1692 SiteInstance* old_instance,
1714 SiteInstance* new_instance, 1693 SiteInstance* new_instance,
1715 int bindings) { 1694 int bindings) {
1716 CHECK(new_instance); 1695 CHECK(new_instance);
1717 CHECK_NE(old_instance, new_instance); 1696 CHECK_NE(old_instance, new_instance);
1718 CHECK(!should_reuse_web_ui_);
1719
1720 // Note: |speculative_web_ui_| must be initialized before starting the
1721 // |speculative_render_frame_host_| creation steps otherwise the WebUI
1722 // won't be properly initialized.
1723 speculative_web_ui_ = CreateWebUI(url, bindings);
1724 1697
1725 // The process for the new SiteInstance may (if we're sharing a process with 1698 // The process for the new SiteInstance may (if we're sharing a process with
1726 // another host that already initialized it) or may not (we have our own 1699 // another host that already initialized it) or may not (we have our own
1727 // process or the existing process crashed) have been initialized. Calling 1700 // process or the existing process crashed) have been initialized. Calling
1728 // Init multiple times will be ignored, so this is safe. 1701 // Init multiple times will be ignored, so this is safe.
1729 if (!new_instance->GetProcess()->Init()) 1702 if (!new_instance->GetProcess()->Init())
1730 return false; 1703 return false;
1731 1704
1732 CreateProxiesForNewRenderFrameHost(old_instance, new_instance); 1705 CreateProxiesForNewRenderFrameHost(old_instance, new_instance);
1733 1706
1734 int create_render_frame_flags = 0; 1707 int create_render_frame_flags = 0;
1735 if (delegate_->IsHidden()) 1708 if (delegate_->IsHidden())
1736 create_render_frame_flags |= CREATE_RF_HIDDEN; 1709 create_render_frame_flags |= CREATE_RF_HIDDEN;
1737 speculative_render_frame_host_ = 1710 speculative_render_frame_host_ =
1738 CreateRenderFrame(new_instance, speculative_web_ui_.get(), 1711 CreateRenderFrame(new_instance, create_render_frame_flags, nullptr);
1739 create_render_frame_flags, nullptr);
1740 1712
1741 if (!speculative_render_frame_host_) { 1713 InitializeWebUI(url, bindings, speculative_render_frame_host_.get());
1742 speculative_web_ui_.reset(); 1714
1743 return false; 1715 return true;
1716 }
1717
1718 void RenderFrameHostManager::InitializeWebUI(const GURL& url,
1719 int bindings,
1720 RenderFrameHostImpl* rfh) {
nasko 2015/10/15 17:40:09 Can't we just pick pending vs speculative inside t
carlosk 2015/10/19 17:21:01 Done.
1721 rfh->UpdatePendingWebUI(url, bindings);
1722 rfh->CommitPendingWebUI();
1723 RenderViewHostImpl* rvh = rfh->render_view_host();
1724
1725 if (rfh->web_ui())
1726 rfh->web_ui()->RenderViewCreated(rvh);
1727
1728 // If the ongoing navigation is not to a WebUI or the RenderView is in a
1729 // guest process, ensure that we don't create an unprivileged RenderView in a
1730 // WebUI-enabled process unless it's swapped out.
1731 if ((!rfh->web_ui() || rvh->GetProcess()->IsForGuestsOnly()) &&
1732 rvh->is_active()) {
1733 bool url_acceptable_for_webui =
1734 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI(
1735 delegate_->GetControllerForRenderManager().GetBrowserContext(),
1736 url);
1737 if (!url_acceptable_for_webui) {
1738 CHECK(!ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
1739 rvh->GetProcess()->GetID()));
1740 }
1744 } 1741 }
1745 return true;
1746 } 1742 }
1747 1743
1748 scoped_ptr<RenderFrameHostImpl> RenderFrameHostManager::CreateRenderFrame( 1744 scoped_ptr<RenderFrameHostImpl> RenderFrameHostManager::CreateRenderFrame(
1749 SiteInstance* instance, 1745 SiteInstance* instance,
1750 WebUIImpl* web_ui,
1751 int flags, 1746 int flags,
1752 int* view_routing_id_ptr) { 1747 int* view_routing_id_ptr) {
1753 bool swapped_out = !!(flags & CREATE_RF_SWAPPED_OUT); 1748 bool swapped_out = !!(flags & CREATE_RF_SWAPPED_OUT);
1754 bool swapped_out_forbidden = 1749 bool swapped_out_forbidden =
1755 SiteIsolationPolicy::IsSwappedOutStateForbidden(); 1750 SiteIsolationPolicy::IsSwappedOutStateForbidden();
1756 1751
1757 CHECK(instance); 1752 CHECK(instance);
1758 CHECK_IMPLIES(swapped_out_forbidden, !swapped_out); 1753 CHECK_IMPLIES(swapped_out_forbidden, !swapped_out);
1759 CHECK_IMPLIES(!SiteIsolationPolicy::AreCrossProcessFramesPossible(), 1754 CHECK_IMPLIES(!SiteIsolationPolicy::AreCrossProcessFramesPossible(),
1760 frame_tree_node_->IsMainFrame()); 1755 frame_tree_node_->IsMainFrame());
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1859 success = InitRenderFrame(new_render_frame_host.get()); 1854 success = InitRenderFrame(new_render_frame_host.get());
1860 } 1855 }
1861 } 1856 }
1862 1857
1863 if (success) { 1858 if (success) {
1864 if (view_routing_id_ptr) 1859 if (view_routing_id_ptr)
1865 *view_routing_id_ptr = render_view_host->GetRoutingID(); 1860 *view_routing_id_ptr = render_view_host->GetRoutingID();
1866 } 1861 }
1867 } 1862 }
1868 1863
1869 // When a new RenderView is created by the renderer process, the new
1870 // WebContents gets a RenderViewHost in the SiteInstance of its opener
1871 // WebContents. If not used in the first navigation, this RVH is swapped out
1872 // and is not granted bindings, so we may need to grant them when swapping it
1873 // in.
1874 if (web_ui && !new_render_frame_host->GetProcess()->IsForGuestsOnly()) {
1875 int required_bindings = web_ui->GetBindings();
1876 RenderViewHost* render_view_host =
1877 new_render_frame_host->render_view_host();
1878 if ((render_view_host->GetEnabledBindings() & required_bindings) !=
1879 required_bindings) {
1880 render_view_host->AllowBindings(required_bindings);
1881 }
1882 }
1883
1884 // Returns the new RFH if it isn't swapped out. 1864 // Returns the new RFH if it isn't swapped out.
1885 if (success && !swapped_out) { 1865 if (success && !swapped_out) {
1886 DCHECK(new_render_frame_host->GetSiteInstance() == instance); 1866 DCHECK(new_render_frame_host->GetSiteInstance() == instance);
1867 DCHECK(new_render_frame_host->render_view_host()->IsRenderViewLive());
carlosk 2015/10/15 16:34:08 I added this check here as it seemed to be true by
nasko 2015/10/15 17:40:09 Acknowledged.
1887 return new_render_frame_host.Pass(); 1868 return new_render_frame_host.Pass();
1888 } 1869 }
1889 return nullptr; 1870 return nullptr;
1890 } 1871 }
1891 1872
1892 int RenderFrameHostManager::CreateRenderFrameProxy(SiteInstance* instance) { 1873 int RenderFrameHostManager::CreateRenderFrameProxy(SiteInstance* instance) {
1893 // A RenderFrameProxyHost should never be created in the same SiteInstance as 1874 // A RenderFrameProxyHost should never be created in the same SiteInstance as
1894 // the current RFH. 1875 // the current RFH.
1895 CHECK(instance); 1876 CHECK(instance);
1896 CHECK_NE(instance, render_frame_host_->GetSiteInstance()); 1877 CHECK_NE(instance, render_frame_host_->GetSiteInstance());
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1994 int proxy_routing_id) { 1975 int proxy_routing_id) {
1995 // Ensure the renderer process is initialized before creating the 1976 // Ensure the renderer process is initialized before creating the
1996 // RenderView. 1977 // RenderView.
1997 if (!render_view_host->GetProcess()->Init()) 1978 if (!render_view_host->GetProcess()->Init())
1998 return false; 1979 return false;
1999 1980
2000 // We may have initialized this RenderViewHost for another RenderFrameHost. 1981 // We may have initialized this RenderViewHost for another RenderFrameHost.
2001 if (render_view_host->IsRenderViewLive()) 1982 if (render_view_host->IsRenderViewLive())
2002 return true; 1983 return true;
2003 1984
2004 // If the ongoing navigation is to a WebUI and the RenderView is not in a
2005 // guest process, tell the RenderViewHost about any bindings it will need
2006 // enabled.
2007 WebUIImpl* dest_web_ui = nullptr;
2008 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
2009 switches::kEnableBrowserSideNavigation)) {
2010 dest_web_ui =
2011 should_reuse_web_ui_ ? web_ui_.get() : speculative_web_ui_.get();
2012 } else {
2013 dest_web_ui = pending_web_ui();
2014 }
2015 if (dest_web_ui && !render_view_host->GetProcess()->IsForGuestsOnly()) {
2016 render_view_host->AllowBindings(dest_web_ui->GetBindings());
2017 } else {
2018 // Ensure that we don't create an unprivileged RenderView in a WebUI-enabled
2019 // process unless it's swapped out.
2020 if (render_view_host->is_active()) {
2021 CHECK(!ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
2022 render_view_host->GetProcess()->GetID()));
2023 }
2024 }
2025
2026 int opener_frame_routing_id = 1985 int opener_frame_routing_id =
2027 GetOpenerRoutingID(render_view_host->GetSiteInstance()); 1986 GetOpenerRoutingID(render_view_host->GetSiteInstance());
2028 1987
2029 return delegate_->CreateRenderViewForRenderManager( 1988 return delegate_->CreateRenderViewForRenderManager(
2030 render_view_host, opener_frame_routing_id, proxy_routing_id, 1989 render_view_host, opener_frame_routing_id, proxy_routing_id,
2031 frame_tree_node_->current_replication_state()); 1990 frame_tree_node_->current_replication_state());
2032 } 1991 }
2033 1992
2034 bool RenderFrameHostManager::InitRenderFrame( 1993 bool RenderFrameHostManager::InitRenderFrame(
2035 RenderFrameHostImpl* render_frame_host) { 1994 RenderFrameHostImpl* render_frame_host) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
2101 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(site_instance); 2060 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(site_instance);
2102 if (proxy) 2061 if (proxy)
2103 return proxy->GetRoutingID(); 2062 return proxy->GetRoutingID();
2104 2063
2105 return MSG_ROUTING_NONE; 2064 return MSG_ROUTING_NONE;
2106 } 2065 }
2107 2066
2108 void RenderFrameHostManager::CommitPending() { 2067 void RenderFrameHostManager::CommitPending() {
2109 TRACE_EVENT1("navigation", "RenderFrameHostManager::CommitPending", 2068 TRACE_EVENT1("navigation", "RenderFrameHostManager::CommitPending",
2110 "FrameTreeNode id", frame_tree_node_->frame_tree_node_id()); 2069 "FrameTreeNode id", frame_tree_node_->frame_tree_node_id());
2111 bool browser_side_navigation =
2112 base::CommandLine::ForCurrentProcess()->HasSwitch(
2113 switches::kEnableBrowserSideNavigation);
2114
2115 // First check whether we're going to want to focus the location bar after 2070 // First check whether we're going to want to focus the location bar after
2116 // this commit. We do this now because the navigation hasn't formally 2071 // this commit. We do this now because the navigation hasn't formally
2117 // committed yet, so if we've already cleared |pending_web_ui_| the call chain 2072 // committed yet, so if we've already cleared the pending WebUI the call chain
2118 // this triggers won't be able to figure out what's going on. 2073 // this triggers won't be able to figure out what's going on.
2119 bool will_focus_location_bar = delegate_->FocusLocationBarByDefault(); 2074 bool will_focus_location_bar = delegate_->FocusLocationBarByDefault();
2120 2075
2121 // Next commit the Web UI, if any. Either replace |web_ui_| with 2076 // If the current RenderFrameHost has a pending WebUI then just commit it and
2122 // |pending_web_ui_|, or clear |web_ui_| if there is no pending WebUI, or 2077 // return (there should be nothing else to commit).
2123 // leave |web_ui_| as is if reusing it. 2078 if (render_frame_host_->pending_web_ui()) {
2124 DCHECK(!(pending_web_ui_ && pending_and_current_web_ui_)); 2079 DCHECK(!pending_render_frame_host_ && !speculative_render_frame_host_);
2125 if (pending_web_ui_ || speculative_web_ui_) { 2080 render_frame_host_->CommitPendingWebUI();
2126 DCHECK(!should_reuse_web_ui_);
2127 web_ui_.reset(browser_side_navigation ? speculative_web_ui_.release()
2128 : pending_web_ui_.release());
2129 } else if (pending_and_current_web_ui_ || should_reuse_web_ui_) {
2130 if (browser_side_navigation) {
2131 DCHECK(web_ui_);
2132 should_reuse_web_ui_ = false;
2133 } else {
2134 DCHECK_EQ(pending_and_current_web_ui_.get(), web_ui_.get());
2135 pending_and_current_web_ui_.reset();
2136 }
2137 } else {
2138 web_ui_.reset();
2139 }
2140 DCHECK(!speculative_web_ui_);
2141 DCHECK(!should_reuse_web_ui_);
2142
2143 // It's possible for the pending_render_frame_host_ to be nullptr when we
2144 // aren't crossing process boundaries. If so, we just needed to handle the Web
2145 // UI committing above and we're done.
2146 if (!pending_render_frame_host_ && !speculative_render_frame_host_) {
2147 if (will_focus_location_bar) 2081 if (will_focus_location_bar)
2148 delegate_->SetFocusToLocationBar(false); 2082 delegate_->SetFocusToLocationBar(false);
2149 return; 2083 return;
2150 } 2084 }
2151 2085
2152 // Remember if the page was focused so we can focus the new renderer in 2086 // Remember if the page was focused so we can focus the new renderer in
2153 // that case. 2087 // that case.
2154 bool focus_render_view = !will_focus_location_bar && 2088 bool focus_render_view = !will_focus_location_bar &&
2155 render_frame_host_->GetView() && 2089 render_frame_host_->GetView() &&
2156 render_frame_host_->GetView()->HasFocus(); 2090 render_frame_host_->GetView()->HasFocus();
2157 2091
2158 bool is_main_frame = frame_tree_node_->IsMainFrame(); 2092 bool is_main_frame = frame_tree_node_->IsMainFrame();
2159 2093
2160 // Swap in the pending or speculative frame and make it active. Also ensure 2094 // Swap in the pending or speculative frame and make it active. Also ensure
2161 // the FrameTree stays in sync. 2095 // the FrameTree stays in sync.
2162 scoped_ptr<RenderFrameHostImpl> old_render_frame_host; 2096 scoped_ptr<RenderFrameHostImpl> old_render_frame_host;
2163 if (!browser_side_navigation) { 2097 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
2098 switches::kEnableBrowserSideNavigation)) {
2164 DCHECK(!speculative_render_frame_host_); 2099 DCHECK(!speculative_render_frame_host_);
2165 old_render_frame_host = 2100 old_render_frame_host =
2166 SetRenderFrameHost(pending_render_frame_host_.Pass()); 2101 SetRenderFrameHost(pending_render_frame_host_.Pass());
2167 } else { 2102 } else {
2168 // PlzNavigate 2103 // PlzNavigate
2169 DCHECK(speculative_render_frame_host_); 2104 DCHECK(speculative_render_frame_host_);
2170 old_render_frame_host = 2105 old_render_frame_host =
2171 SetRenderFrameHost(speculative_render_frame_host_.Pass()); 2106 SetRenderFrameHost(speculative_render_frame_host_.Pass());
2172 } 2107 }
2173 2108
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
2315 // If we are currently navigating cross-process, we want to get back to normal 2250 // If we are currently navigating cross-process, we want to get back to normal
2316 // and then navigate as usual. 2251 // and then navigate as usual.
2317 if (pending_render_frame_host_) 2252 if (pending_render_frame_host_)
2318 CancelPending(); 2253 CancelPending();
2319 2254
2320 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); 2255 SiteInstance* current_instance = render_frame_host_->GetSiteInstance();
2321 scoped_refptr<SiteInstance> new_instance = GetSiteInstanceForNavigation( 2256 scoped_refptr<SiteInstance> new_instance = GetSiteInstanceForNavigation(
2322 dest_url, source_instance, dest_instance, nullptr, transition, 2257 dest_url, source_instance, dest_instance, nullptr, transition,
2323 dest_is_restore, dest_is_view_source_mode); 2258 dest_is_restore, dest_is_view_source_mode);
2324 2259
2325 const NavigationEntry* current_entry =
2326 delegate_->GetLastCommittedNavigationEntryForRenderManager();
2327
2328 DCHECK(!pending_render_frame_host_); 2260 DCHECK(!pending_render_frame_host_);
2329 2261
2330 if (new_instance.get() != current_instance) { 2262 if (new_instance.get() != current_instance) {
2331 TRACE_EVENT_INSTANT2( 2263 TRACE_EVENT_INSTANT2(
2332 "navigation", 2264 "navigation",
2333 "RenderFrameHostManager::UpdateStateForNavigate:New SiteInstance", 2265 "RenderFrameHostManager::UpdateStateForNavigate:New SiteInstance",
2334 TRACE_EVENT_SCOPE_THREAD, 2266 TRACE_EVENT_SCOPE_THREAD,
2335 "current_instance id", current_instance->GetId(), 2267 "current_instance id", current_instance->GetId(),
2336 "new_instance id", new_instance->GetId()); 2268 "new_instance id", new_instance->GetId());
2337 2269
2270 // Clear any pending WebUI on the current RenderFrameHost as it won't
2271 // be used.
2272 render_frame_host_->DiscardPendingWebUI();
2273
2338 // New SiteInstance: create a pending RFH to navigate. 2274 // New SiteInstance: create a pending RFH to navigate.
2339 2275
2340 // This will possibly create (set to nullptr) a Web UI object for the 2276 CreatePendingRenderFrameHost(current_instance, new_instance.get(), dest_url,
2341 // pending page. We'll use this later to give the page special access. This 2277 bindings);
2342 // must happen before the new renderer is created below so it will get
2343 // bindings. It must also happen after the above conditional call to
2344 // CancelPending(), otherwise CancelPending may clear the pending_web_ui_
2345 // and the page will not have its bindings set appropriately.
2346 SetPendingWebUI(dest_url, bindings);
2347 CreatePendingRenderFrameHost(current_instance, new_instance.get());
2348 if (!pending_render_frame_host_) 2278 if (!pending_render_frame_host_)
2349 return nullptr; 2279 return nullptr;
2350 2280
2351 // Check if our current RFH is live before we set up a transition. 2281 // Check if our current RFH is live before we set up a transition.
2352 if (!render_frame_host_->IsRenderFrameLive()) { 2282 if (!render_frame_host_->IsRenderFrameLive()) {
2353 // The current RFH is not live. There's no reason to sit around with a 2283 // The current RFH is not live. There's no reason to sit around with a
2354 // sad tab or a newly created RFH while we wait for the pending RFH to 2284 // sad tab or a newly created RFH while we wait for the pending RFH to
2355 // navigate. Just switch to the pending RFH now and go back to normal. 2285 // navigate. Just switch to the pending RFH now and go back to normal.
2356 // (Note that we don't care about on{before}unload handlers if the current 2286 // (Note that we don't care about on{before}unload handlers if the current
2357 // RFH isn't live.) 2287 // RFH isn't live.)
2358 CommitPending(); 2288 CommitPending();
2359 return render_frame_host_.get(); 2289 return render_frame_host_.get();
2360 } 2290 }
2361 // Otherwise, it's safe to treat this as a pending cross-process transition. 2291 // Otherwise, it's safe to treat this as a pending cross-process transition.
2362 2292
2363 // We now have a pending RFH. 2293 // We now have a pending RFH and possibly an associated pending WebUI.
2364 DCHECK(pending_render_frame_host_); 2294 DCHECK(pending_render_frame_host_);
2295 DCHECK_EQ(pending_web_ui(), pending_render_frame_host_->web_ui());
2296 DCHECK(!pending_render_frame_host_->pending_web_ui());
2297 DCHECK(!render_frame_host_->pending_web_ui());
2365 2298
2366 // We need to wait until the beforeunload handler has run, unless we are 2299 // We need to wait until the beforeunload handler has run, unless we are
2367 // transferring an existing request (in which case it has already run). 2300 // transferring an existing request (in which case it has already run).
2368 // Suspend the new render view (i.e., don't let it send the cross-process 2301 // Suspend the new render view (i.e., don't let it send the cross-process
2369 // Navigate message) until we hear back from the old renderer's 2302 // Navigate message) until we hear back from the old renderer's
2370 // beforeunload handler. If the handler returns false, we'll have to 2303 // beforeunload handler. If the handler returns false, we'll have to
2371 // cancel the request. 2304 // cancel the request.
2372 // 2305 //
2373 DCHECK(!pending_render_frame_host_->are_navigations_suspended()); 2306 DCHECK(!pending_render_frame_host_->are_navigations_suspended());
2374 bool is_transfer = transferred_request_id != GlobalRequestID(); 2307 bool is_transfer = transferred_request_id != GlobalRequestID();
(...skipping 22 matching lines...) Expand all
2397 2330
2398 // Otherwise the same SiteInstance can be used. Navigate render_frame_host_. 2331 // Otherwise the same SiteInstance can be used. Navigate render_frame_host_.
2399 2332
2400 // It's possible to swap out the current RFH and then decide to navigate in it 2333 // It's possible to swap out the current RFH and then decide to navigate in it
2401 // anyway (e.g., a cross-process navigation that redirects back to the 2334 // anyway (e.g., a cross-process navigation that redirects back to the
2402 // original site). In that case, we have a proxy for the current RFH but 2335 // original site). In that case, we have a proxy for the current RFH but
2403 // haven't deleted it yet. The new navigation will swap it back in, so we can 2336 // haven't deleted it yet. The new navigation will swap it back in, so we can
2404 // delete the proxy. 2337 // delete the proxy.
2405 proxy_hosts_->Remove(new_instance.get()->GetId()); 2338 proxy_hosts_->Remove(new_instance.get()->GetId());
2406 2339
2407 if (ShouldReuseWebUI(current_entry, dest_url)) { 2340 render_frame_host_->UpdatePendingWebUI(dest_url, bindings);
2408 pending_web_ui_.reset(); 2341 DCHECK(pending_web_ui() == render_frame_host_->pending_web_ui());
2409 pending_and_current_web_ui_ = web_ui_->AsWeakPtr();
2410 } else {
2411 SetPendingWebUI(dest_url, bindings);
2412 // Make sure the new RenderViewHost has the right bindings.
2413 if (pending_web_ui() &&
2414 !render_frame_host_->GetProcess()->IsForGuestsOnly()) {
2415 render_frame_host_->render_view_host()->AllowBindings(
2416 pending_web_ui()->GetBindings());
2417 }
2418 }
2419 2342
2343 // If a pending WebUI was set on the current RenderFrameHost (be it a new one
2344 // or the reused current one) and the associated RenderFrame is alive, notify
2345 // the WebUI the RenderView is being reused.
2420 if (pending_web_ui() && render_frame_host_->IsRenderFrameLive()) { 2346 if (pending_web_ui() && render_frame_host_->IsRenderFrameLive()) {
2421 pending_web_ui()->RenderViewReused(render_frame_host_->render_view_host(), 2347 pending_web_ui()->RenderViewReused(render_frame_host_->render_view_host(),
2422 frame_tree_node_->IsMainFrame()); 2348 frame_tree_node_->IsMainFrame());
2423 } 2349 }
2424 2350
2425 // The renderer can exit view source mode when any error or cancellation 2351 // The renderer can exit view source mode when any error or cancellation
2426 // happen. We must overwrite to recover the mode. 2352 // happen. We must overwrite to recover the mode.
2427 if (dest_is_view_source_mode) { 2353 if (dest_is_view_source_mode) {
2428 render_frame_host_->render_view_host()->Send( 2354 render_frame_host_->render_view_host()->Send(
2429 new ViewMsg_EnableViewSourceMode( 2355 new ViewMsg_EnableViewSourceMode(
2430 render_frame_host_->render_view_host()->GetRoutingID())); 2356 render_frame_host_->render_view_host()->GetRoutingID()));
2431 } 2357 }
2432 2358
2433 return render_frame_host_.get(); 2359 return render_frame_host_.get();
2434 } 2360 }
2435 2361
2436 void RenderFrameHostManager::CancelPending() { 2362 void RenderFrameHostManager::CancelPending() {
2437 TRACE_EVENT1("navigation", "RenderFrameHostManager::CancelPending", 2363 TRACE_EVENT1("navigation", "RenderFrameHostManager::CancelPending",
2438 "FrameTreeNode id", frame_tree_node_->frame_tree_node_id()); 2364 "FrameTreeNode id", frame_tree_node_->frame_tree_node_id());
2365 render_frame_host_->DiscardPendingWebUI();
2439 DiscardUnusedFrame(UnsetPendingRenderFrameHost()); 2366 DiscardUnusedFrame(UnsetPendingRenderFrameHost());
2440 } 2367 }
2441 2368
2442 scoped_ptr<RenderFrameHostImpl> 2369 scoped_ptr<RenderFrameHostImpl>
2443 RenderFrameHostManager::UnsetPendingRenderFrameHost() { 2370 RenderFrameHostManager::UnsetPendingRenderFrameHost() {
2444 scoped_ptr<RenderFrameHostImpl> pending_render_frame_host = 2371 scoped_ptr<RenderFrameHostImpl> pending_render_frame_host =
2445 pending_render_frame_host_.Pass(); 2372 pending_render_frame_host_.Pass();
2446 2373
2447 RenderFrameDevToolsAgentHost::OnCancelPendingNavigation( 2374 RenderFrameDevToolsAgentHost::OnCancelPendingNavigation(
2448 pending_render_frame_host.get(), 2375 pending_render_frame_host.get(),
2449 render_frame_host_.get()); 2376 render_frame_host_.get());
2450 2377
2451 // We no longer need to prevent the process from exiting. 2378 // We no longer need to prevent the process from exiting.
2452 pending_render_frame_host->GetProcess()->RemovePendingView(); 2379 pending_render_frame_host->GetProcess()->RemovePendingView();
2453 2380
2454 pending_web_ui_.reset();
2455 pending_and_current_web_ui_.reset();
2456
2457 return pending_render_frame_host.Pass(); 2381 return pending_render_frame_host.Pass();
2458 } 2382 }
2459 2383
2460 scoped_ptr<RenderFrameHostImpl> RenderFrameHostManager::SetRenderFrameHost( 2384 scoped_ptr<RenderFrameHostImpl> RenderFrameHostManager::SetRenderFrameHost(
2461 scoped_ptr<RenderFrameHostImpl> render_frame_host) { 2385 scoped_ptr<RenderFrameHostImpl> render_frame_host) {
2462 // Swap the two. 2386 // Swap the two.
2463 scoped_ptr<RenderFrameHostImpl> old_render_frame_host = 2387 scoped_ptr<RenderFrameHostImpl> old_render_frame_host =
2464 render_frame_host_.Pass(); 2388 render_frame_host_.Pass();
2465 render_frame_host_ = render_frame_host.Pass(); 2389 render_frame_host_ = render_frame_host.Pass();
2466 2390
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
2621 if (rvh && !rvh->IsRenderViewLive()) { 2545 if (rvh && !rvh->IsRenderViewLive()) {
2622 EnsureRenderViewInitialized(rvh, instance); 2546 EnsureRenderViewInitialized(rvh, instance);
2623 } else { 2547 } else {
2624 // Create a swapped out RenderView in the given SiteInstance if none 2548 // Create a swapped out RenderView in the given SiteInstance if none
2625 // exists. Since an opener can point to a subframe, do this on the root 2549 // exists. Since an opener can point to a subframe, do this on the root
2626 // frame of the current opener's frame tree. 2550 // frame of the current opener's frame tree.
2627 if (SiteIsolationPolicy::IsSwappedOutStateForbidden()) { 2551 if (SiteIsolationPolicy::IsSwappedOutStateForbidden()) {
2628 frame_tree->root()->render_manager()->CreateRenderFrameProxy(instance); 2552 frame_tree->root()->render_manager()->CreateRenderFrameProxy(instance);
2629 } else { 2553 } else {
2630 frame_tree->root()->render_manager()->CreateRenderFrame( 2554 frame_tree->root()->render_manager()->CreateRenderFrame(
2631 instance, nullptr, CREATE_RF_SWAPPED_OUT | CREATE_RF_HIDDEN, 2555 instance, CREATE_RF_SWAPPED_OUT | CREATE_RF_HIDDEN, nullptr);
2632 nullptr);
2633 } 2556 }
2634 } 2557 }
2635 } 2558 }
2636 } 2559 }
2637 2560
2638 int RenderFrameHostManager::GetOpenerRoutingID(SiteInstance* instance) { 2561 int RenderFrameHostManager::GetOpenerRoutingID(SiteInstance* instance) {
2639 if (!frame_tree_node_->opener()) 2562 if (!frame_tree_node_->opener())
2640 return MSG_ROUTING_NONE; 2563 return MSG_ROUTING_NONE;
2641 2564
2642 return frame_tree_node_->opener() 2565 return frame_tree_node_->opener()
2643 ->render_manager() 2566 ->render_manager()
2644 ->GetRoutingIdForSiteInstance(instance); 2567 ->GetRoutingIdForSiteInstance(instance);
2645 } 2568 }
2646 2569
2647 } // namespace content 2570 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698