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

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: Minor changes from CR comments. 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.
nasko 2015/02/06 02:18:57 nit: s/site instance/SiteInstances/
carlosk 2015/02/06 10:37:58 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 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
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);
1285 CHECK(!should_reuse_web_ui_);
1267 1286
1268 const NavigationEntry* current_navigation_entry = 1287 // Note: |speculative_web_ui_| must be initialized before starting the
1269 delegate_->GetLastCommittedNavigationEntryForRenderManager(); 1288 // |speculative_render_frame_host_| creation steps otherwise the WebUI
1270 // Note: |should_reuse_web_ui_| and |speculative_web_ui_| must be initialized 1289 // won't be properly initialized.
1271 // before trying to create the |speculative_render_frame_host_|. Otherwise the 1290 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 1291
1277 int create_render_frame_flags = 0; 1292 int create_render_frame_flags = 0;
1278 int opener_route_id = 1293 int opener_route_id =
1279 CreateOpenerRenderViewsIfNeeded(old_instance, new_instance, 1294 CreateOpenerRenderViewsIfNeeded(old_instance, new_instance,
1280 &create_render_frame_flags); 1295 &create_render_frame_flags);
1281 1296
1282 if (frame_tree_node_->IsMainFrame()) 1297 if (frame_tree_node_->IsMainFrame())
1283 create_render_frame_flags |= CREATE_RF_FOR_MAIN_FRAME_NAVIGATION; 1298 create_render_frame_flags |= CREATE_RF_FOR_MAIN_FRAME_NAVIGATION;
1284 if (delegate_->IsHidden()) 1299 if (delegate_->IsHidden())
1285 create_render_frame_flags |= CREATE_RF_HIDDEN; 1300 create_render_frame_flags |= CREATE_RF_HIDDEN;
1286 speculative_render_frame_host_ = 1301 speculative_render_frame_host_ =
1287 CreateRenderFrame(new_instance, speculative_web_ui_.get(), 1302 CreateRenderFrame(new_instance, speculative_web_ui_.get(),
1288 opener_route_id, create_render_frame_flags, nullptr); 1303 opener_route_id, create_render_frame_flags, nullptr);
1289 1304
1290 if (!speculative_render_frame_host_) { 1305 if (!speculative_render_frame_host_) {
1291 should_reuse_web_ui_ = false;
1292 speculative_web_ui_.reset(); 1306 speculative_web_ui_.reset();
1293 return false; 1307 return false;
1294 } 1308 }
1295 return true; 1309 return true;
1296 } 1310 }
1297 1311
1298 scoped_ptr<RenderFrameHostImpl> RenderFrameHostManager::CreateRenderFrame( 1312 scoped_ptr<RenderFrameHostImpl> RenderFrameHostManager::CreateRenderFrame(
1299 SiteInstance* instance, 1313 SiteInstance* instance,
1300 WebUIImpl* web_ui, 1314 WebUIImpl* web_ui,
1301 int opener_route_id, 1315 int opener_route_id,
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
1714 } 1728 }
1715 1729
1716 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); 1730 SiteInstance* current_instance = render_frame_host_->GetSiteInstance();
1717 scoped_refptr<SiteInstance> new_instance = GetSiteInstanceForNavigation( 1731 scoped_refptr<SiteInstance> new_instance = GetSiteInstanceForNavigation(
1718 dest_url, source_instance, dest_instance, transition, 1732 dest_url, source_instance, dest_instance, transition,
1719 dest_is_restore, dest_is_view_source_mode); 1733 dest_is_restore, dest_is_view_source_mode);
1720 1734
1721 const NavigationEntry* current_entry = 1735 const NavigationEntry* current_entry =
1722 delegate_->GetLastCommittedNavigationEntryForRenderManager(); 1736 delegate_->GetLastCommittedNavigationEntryForRenderManager();
1723 1737
1738 DCHECK(!cross_navigation_pending_);
1739
1724 if (new_instance.get() != current_instance) { 1740 if (new_instance.get() != current_instance) {
1725 TRACE_EVENT_INSTANT2( 1741 TRACE_EVENT_INSTANT2(
1726 "navigation", 1742 "navigation",
1727 "RenderFrameHostManager::UpdateStateForNavigate:New SiteInstance", 1743 "RenderFrameHostManager::UpdateStateForNavigate:New SiteInstance",
1728 TRACE_EVENT_SCOPE_THREAD, 1744 TRACE_EVENT_SCOPE_THREAD,
1729 "current_instance id", current_instance->GetId(), 1745 "current_instance id", current_instance->GetId(),
1730 "new_instance id", new_instance->GetId()); 1746 "new_instance id", new_instance->GetId());
1731 1747
1732 // New SiteInstance: create a pending RFH to navigate. 1748 // New SiteInstance: create a pending RFH to navigate.
1733 DCHECK(!cross_navigation_pending_);
1734 1749
1735 // This will possibly create (set to nullptr) a Web UI object for the 1750 // 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 1751 // 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 1752 // 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 1753 // bindings. It must also happen after the above conditional call to
1739 // CancelPending(), otherwise CancelPending may clear the pending_web_ui_ 1754 // CancelPending(), otherwise CancelPending may clear the pending_web_ui_
1740 // and the page will not have its bindings set appropriately. 1755 // and the page will not have its bindings set appropriately.
1741 SetPendingWebUI(dest_url, bindings); 1756 SetPendingWebUI(dest_url, bindings);
1742 CreatePendingRenderFrameHost(current_instance, new_instance.get(), 1757 CreatePendingRenderFrameHost(current_instance, new_instance.get(),
1743 frame_tree_node_->IsMainFrame()); 1758 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 1807 // old render view to run its beforeunload handler, since it doesn't
1793 // otherwise know that the cross-site request is happening. This will 1808 // otherwise know that the cross-site request is happening. This will
1794 // trigger a call to OnBeforeUnloadACK with the reply. 1809 // trigger a call to OnBeforeUnloadACK with the reply.
1795 render_frame_host_->DispatchBeforeUnload(true); 1810 render_frame_host_->DispatchBeforeUnload(true);
1796 } 1811 }
1797 1812
1798 return pending_render_frame_host_.get(); 1813 return pending_render_frame_host_.get();
1799 } 1814 }
1800 1815
1801 // Otherwise the same SiteInstance can be used. Navigate render_frame_host_. 1816 // Otherwise the same SiteInstance can be used. Navigate render_frame_host_.
1802 DCHECK(!cross_navigation_pending_);
1803 1817
1804 // It's possible to swap out the current RFH and then decide to navigate in it 1818 // 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 1819 // 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 1820 // 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 1821 // haven't deleted it yet. The new navigation will swap it back in, so we can
1808 // delete the proxy. 1822 // delete the proxy.
1809 DeleteRenderFrameProxyHost(new_instance.get()); 1823 DeleteRenderFrameProxyHost(new_instance.get());
1810 1824
1811 if (ShouldReuseWebUI(current_entry, dest_url)) { 1825 if (ShouldReuseWebUI(current_entry, dest_url)) {
1812 pending_web_ui_.reset(); 1826 pending_web_ui_.reset();
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1933 void RenderFrameHostManager::DeleteRenderFrameProxyHost( 1947 void RenderFrameHostManager::DeleteRenderFrameProxyHost(
1934 SiteInstance* instance) { 1948 SiteInstance* instance) {
1935 RenderFrameProxyHostMap::iterator iter = proxy_hosts_.find(instance->GetId()); 1949 RenderFrameProxyHostMap::iterator iter = proxy_hosts_.find(instance->GetId());
1936 if (iter != proxy_hosts_.end()) { 1950 if (iter != proxy_hosts_.end()) {
1937 delete iter->second; 1951 delete iter->second;
1938 proxy_hosts_.erase(iter); 1952 proxy_hosts_.erase(iter);
1939 } 1953 }
1940 } 1954 }
1941 1955
1942 } // namespace content 1956 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698