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

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

Issue 877343010: PlzNavigate: Fix WebUI creation logic for both cross and same site navigation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 // (see crbug.com/440266). 708 // (see crbug.com/440266).
709 if (current_site_instance == dest_site_instance.get() || 709 if (current_site_instance == dest_site_instance.get() ||
710 (!frame_tree_node_->IsMainFrame() && 710 (!frame_tree_node_->IsMainFrame() &&
711 !base::CommandLine::ForCurrentProcess()->HasSwitch( 711 !base::CommandLine::ForCurrentProcess()->HasSwitch(
712 switches::kSitePerProcess))) { 712 switches::kSitePerProcess))) {
713 // Reuse the current RFH if its SiteInstance matches the the navigation's 713 // Reuse the current RFH if its SiteInstance matches the the navigation's
714 // or if this is a subframe navigation. We only swap RFHs for subframes when 714 // or if this is a subframe navigation. We only swap RFHs for subframes when
715 // --site-per-process is enabled. 715 // --site-per-process is enabled.
716 CleanUpNavigation(); 716 CleanUpNavigation();
717 navigation_rfh = render_frame_host_.get(); 717 navigation_rfh = render_frame_host_.get();
718
719 // As site instances are the same, check if the WebUI should be reused
clamy 2015/02/05 16:54:27 nit: add a . at the end of the comment.
carlosk 2015/02/05 17:07:33 Done.
720 const NavigationEntry* current_navigation_entry =
721 delegate_->GetLastCommittedNavigationEntryForRenderManager();
722 bool should_reuse_web_ui_ = ShouldReuseWebUI(current_navigation_entry,
723 request.common_params().url);
724 if (!should_reuse_web_ui_) {
725 speculative_web_ui_ = CreateWebUI(request.common_params().url,
726 request.bindings());
727 // Make sure the current RenderViewHost has the right bindings.
728 if (speculative_web_ui() &&
729 !render_frame_host_->GetProcess()->IsIsolatedGuest()) {
730 render_frame_host_->render_view_host()->AllowBindings(
731 speculative_web_ui()->GetBindings());
732 }
733 }
718 } else { 734 } else {
719 // If the SiteInstance for the final URL doesn't match the one from the 735 // If the SiteInstance for the final URL doesn't match the one from the
720 // speculatively created RenderFrameHost, create a new RenderFrameHost using 736 // speculatively created RenderFrameHost, create a new RenderFrameHost using
721 // this new SiteInstance. 737 // this new SiteInstance.
722 if (!speculative_render_frame_host_ || 738 if (!speculative_render_frame_host_ ||
723 speculative_render_frame_host_->GetSiteInstance() != 739 speculative_render_frame_host_->GetSiteInstance() !=
724 dest_site_instance.get()) { 740 dest_site_instance.get()) {
725 CleanUpNavigation(); 741 CleanUpNavigation();
726 bool success = CreateSpeculativeRenderFrameHost( 742 bool success = CreateSpeculativeRenderFrameHost(
727 request.common_params().url, current_site_instance, 743 request.common_params().url, current_site_instance,
(...skipping 28 matching lines...) Expand all
756 return nullptr; 772 return nullptr;
757 } 773 }
758 } 774 }
759 775
760 cross_navigation_pending_ = navigation_rfh != render_frame_host_.get(); 776 cross_navigation_pending_ = navigation_rfh != render_frame_host_.get();
761 return navigation_rfh; 777 return navigation_rfh;
762 } 778 }
763 779
764 // PlzNavigate 780 // PlzNavigate
765 void RenderFrameHostManager::CleanUpNavigation() { 781 void RenderFrameHostManager::CleanUpNavigation() {
782 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
783 switches::kEnableBrowserSideNavigation));
784 speculative_web_ui_.reset();
785 should_reuse_web_ui_ = false;
766 if (speculative_render_frame_host_) 786 if (speculative_render_frame_host_)
767 DiscardUnusedFrame(UnsetSpeculativeRenderFrameHost()); 787 DiscardUnusedFrame(UnsetSpeculativeRenderFrameHost());
768 } 788 }
769 789
770 // PlzNavigate 790 // PlzNavigate
771 scoped_ptr<RenderFrameHostImpl> 791 scoped_ptr<RenderFrameHostImpl>
772 RenderFrameHostManager::UnsetSpeculativeRenderFrameHost() { 792 RenderFrameHostManager::UnsetSpeculativeRenderFrameHost() {
773 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( 793 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
774 switches::kEnableBrowserSideNavigation)); 794 switches::kEnableBrowserSideNavigation));
775 speculative_web_ui_.reset();
776 should_reuse_web_ui_ = false;
777 speculative_render_frame_host_->GetProcess()->RemovePendingView(); 795 speculative_render_frame_host_->GetProcess()->RemovePendingView();
778 return speculative_render_frame_host_.Pass(); 796 return speculative_render_frame_host_.Pass();
779 } 797 }
780 798
781 void RenderFrameHostManager::OnDidStartLoading() { 799 void RenderFrameHostManager::OnDidStartLoading() {
782 for (const auto& pair : proxy_hosts_) { 800 for (const auto& pair : proxy_hosts_) {
783 pair.second->Send( 801 pair.second->Send(
784 new FrameMsg_DidStartLoading(pair.second->GetRoutingID())); 802 new FrameMsg_DidStartLoading(pair.second->GetRoutingID()));
785 } 803 }
786 } 804 }
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 return render_frame_host.Pass(); 1274 return render_frame_host.Pass();
1257 } 1275 }
1258 1276
1259 // PlzNavigate 1277 // PlzNavigate
1260 bool RenderFrameHostManager::CreateSpeculativeRenderFrameHost( 1278 bool RenderFrameHostManager::CreateSpeculativeRenderFrameHost(
1261 const GURL& url, 1279 const GURL& url,
1262 SiteInstance* old_instance, 1280 SiteInstance* old_instance,
1263 SiteInstance* new_instance, 1281 SiteInstance* new_instance,
1264 int bindings) { 1282 int bindings) {
1265 CHECK(new_instance); 1283 CHECK(new_instance);
1266 CHECK_NE(old_instance, new_instance); 1284 CHECK_NE(old_instance, new_instance);
clamy 2015/02/05 16:54:27 Could you add a CHECK(!should_reuse_web_ui_) here?
carlosk 2015/02/05 17:07:33 Done.
1267 1285
1268 const NavigationEntry* current_navigation_entry = 1286 // Note: |speculative_web_ui_| must be initialized before starting the
1269 delegate_->GetLastCommittedNavigationEntryForRenderManager(); 1287 // |speculative_render_frame_host_| creation steps otherwise the WebUI
1270 // Note: |should_reuse_web_ui_| and |speculative_web_ui_| must be initialized 1288 // won't be properly initialized.
1271 // before trying to create the |speculative_render_frame_host_|. Otherwise the 1289 speculative_web_ui_ = CreateWebUI(url, bindings);
1272 // WebUI won't be properly initialized.
1273 bool should_reuse_web_ui_ = ShouldReuseWebUI(current_navigation_entry, url);
1274 if (!should_reuse_web_ui_)
1275 speculative_web_ui_ = CreateWebUI(url, bindings);
1276 1290
1277 int create_render_frame_flags = 0; 1291 int create_render_frame_flags = 0;
1278 int opener_route_id = 1292 int opener_route_id =
1279 CreateOpenerRenderViewsIfNeeded(old_instance, new_instance, 1293 CreateOpenerRenderViewsIfNeeded(old_instance, new_instance,
1280 &create_render_frame_flags); 1294 &create_render_frame_flags);
1281 1295
1282 if (frame_tree_node_->IsMainFrame()) 1296 if (frame_tree_node_->IsMainFrame())
1283 create_render_frame_flags |= CREATE_RF_FOR_MAIN_FRAME_NAVIGATION; 1297 create_render_frame_flags |= CREATE_RF_FOR_MAIN_FRAME_NAVIGATION;
1284 if (delegate_->IsHidden()) 1298 if (delegate_->IsHidden())
1285 create_render_frame_flags |= CREATE_RF_HIDDEN; 1299 create_render_frame_flags |= CREATE_RF_HIDDEN;
1286 speculative_render_frame_host_ = 1300 speculative_render_frame_host_ =
1287 CreateRenderFrame(new_instance, speculative_web_ui_.get(), 1301 CreateRenderFrame(new_instance, speculative_web_ui_.get(),
1288 opener_route_id, create_render_frame_flags, nullptr); 1302 opener_route_id, create_render_frame_flags, nullptr);
1289 1303
1290 if (!speculative_render_frame_host_) { 1304 if (!speculative_render_frame_host_) {
1291 should_reuse_web_ui_ = false;
1292 speculative_web_ui_.reset(); 1305 speculative_web_ui_.reset();
1293 return false; 1306 return false;
1294 } 1307 }
1295 return true; 1308 return true;
1296 } 1309 }
1297 1310
1298 scoped_ptr<RenderFrameHostImpl> RenderFrameHostManager::CreateRenderFrame( 1311 scoped_ptr<RenderFrameHostImpl> RenderFrameHostManager::CreateRenderFrame(
1299 SiteInstance* instance, 1312 SiteInstance* instance,
1300 WebUIImpl* web_ui, 1313 WebUIImpl* web_ui,
1301 int opener_route_id, 1314 int opener_route_id,
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
1714 } 1727 }
1715 1728
1716 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); 1729 SiteInstance* current_instance = render_frame_host_->GetSiteInstance();
1717 scoped_refptr<SiteInstance> new_instance = GetSiteInstanceForNavigation( 1730 scoped_refptr<SiteInstance> new_instance = GetSiteInstanceForNavigation(
1718 dest_url, source_instance, dest_instance, transition, 1731 dest_url, source_instance, dest_instance, transition,
1719 dest_is_restore, dest_is_view_source_mode); 1732 dest_is_restore, dest_is_view_source_mode);
1720 1733
1721 const NavigationEntry* current_entry = 1734 const NavigationEntry* current_entry =
1722 delegate_->GetLastCommittedNavigationEntryForRenderManager(); 1735 delegate_->GetLastCommittedNavigationEntryForRenderManager();
1723 1736
1737 DCHECK(!cross_navigation_pending_);
1738
carlosk 2015/02/05 16:09:06 I moved the 2 removed DCHECKs up here because it h
1724 if (new_instance.get() != current_instance) { 1739 if (new_instance.get() != current_instance) {
1725 TRACE_EVENT_INSTANT2( 1740 TRACE_EVENT_INSTANT2(
1726 "navigation", 1741 "navigation",
1727 "RenderFrameHostManager::UpdateStateForNavigate:New SiteInstance", 1742 "RenderFrameHostManager::UpdateStateForNavigate:New SiteInstance",
1728 TRACE_EVENT_SCOPE_THREAD, 1743 TRACE_EVENT_SCOPE_THREAD,
1729 "current_instance id", current_instance->GetId(), 1744 "current_instance id", current_instance->GetId(),
1730 "new_instance id", new_instance->GetId()); 1745 "new_instance id", new_instance->GetId());
1731 1746
1732 // New SiteInstance: create a pending RFH to navigate. 1747 // New SiteInstance: create a pending RFH to navigate.
1733 DCHECK(!cross_navigation_pending_);
1734 1748
1735 // This will possibly create (set to nullptr) a Web UI object for the 1749 // This will possibly create (set to nullptr) a Web UI object for the
1736 // pending page. We'll use this later to give the page special access. This 1750 // pending page. We'll use this later to give the page special access. This
1737 // must happen before the new renderer is created below so it will get 1751 // must happen before the new renderer is created below so it will get
1738 // bindings. It must also happen after the above conditional call to 1752 // bindings. It must also happen after the above conditional call to
1739 // CancelPending(), otherwise CancelPending may clear the pending_web_ui_ 1753 // CancelPending(), otherwise CancelPending may clear the pending_web_ui_
1740 // and the page will not have its bindings set appropriately. 1754 // and the page will not have its bindings set appropriately.
1741 SetPendingWebUI(dest_url, bindings); 1755 SetPendingWebUI(dest_url, bindings);
1742 CreatePendingRenderFrameHost(current_instance, new_instance.get(), 1756 CreatePendingRenderFrameHost(current_instance, new_instance.get(),
1743 frame_tree_node_->IsMainFrame()); 1757 frame_tree_node_->IsMainFrame());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1792 // old render view to run its beforeunload handler, since it doesn't 1806 // old render view to run its beforeunload handler, since it doesn't
1793 // otherwise know that the cross-site request is happening. This will 1807 // otherwise know that the cross-site request is happening. This will
1794 // trigger a call to OnBeforeUnloadACK with the reply. 1808 // trigger a call to OnBeforeUnloadACK with the reply.
1795 render_frame_host_->DispatchBeforeUnload(true); 1809 render_frame_host_->DispatchBeforeUnload(true);
1796 } 1810 }
1797 1811
1798 return pending_render_frame_host_.get(); 1812 return pending_render_frame_host_.get();
1799 } 1813 }
1800 1814
1801 // Otherwise the same SiteInstance can be used. Navigate render_frame_host_. 1815 // Otherwise the same SiteInstance can be used. Navigate render_frame_host_.
1802 DCHECK(!cross_navigation_pending_);
1803 1816
1804 // It's possible to swap out the current RFH and then decide to navigate in it 1817 // It's possible to swap out the current RFH and then decide to navigate in it
1805 // anyway (e.g., a cross-process navigation that redirects back to the 1818 // anyway (e.g., a cross-process navigation that redirects back to the
1806 // original site). In that case, we have a proxy for the current RFH but 1819 // original site). In that case, we have a proxy for the current RFH but
1807 // haven't deleted it yet. The new navigation will swap it back in, so we can 1820 // haven't deleted it yet. The new navigation will swap it back in, so we can
1808 // delete the proxy. 1821 // delete the proxy.
1809 DeleteRenderFrameProxyHost(new_instance.get()); 1822 DeleteRenderFrameProxyHost(new_instance.get());
1810 1823
1811 if (ShouldReuseWebUI(current_entry, dest_url)) { 1824 if (ShouldReuseWebUI(current_entry, dest_url)) {
1812 pending_web_ui_.reset(); 1825 pending_web_ui_.reset();
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1933 void RenderFrameHostManager::DeleteRenderFrameProxyHost( 1946 void RenderFrameHostManager::DeleteRenderFrameProxyHost(
1934 SiteInstance* instance) { 1947 SiteInstance* instance) {
1935 RenderFrameProxyHostMap::iterator iter = proxy_hosts_.find(instance->GetId()); 1948 RenderFrameProxyHostMap::iterator iter = proxy_hosts_.find(instance->GetId());
1936 if (iter != proxy_hosts_.end()) { 1949 if (iter != proxy_hosts_.end()) {
1937 delete iter->second; 1950 delete iter->second;
1938 proxy_hosts_.erase(iter); 1951 proxy_hosts_.erase(iter);
1939 } 1952 }
1940 } 1953 }
1941 1954
1942 } // namespace content 1955 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698