OLD | NEW |
---|---|
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 725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
736 } | 736 } |
737 | 737 |
738 // PlzNavigate | 738 // PlzNavigate |
739 RenderFrameHostImpl* RenderFrameHostManager::GetFrameHostForNavigation( | 739 RenderFrameHostImpl* RenderFrameHostManager::GetFrameHostForNavigation( |
740 const NavigationRequest& request) { | 740 const NavigationRequest& request) { |
741 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( | 741 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( |
742 switches::kEnableBrowserSideNavigation)); | 742 switches::kEnableBrowserSideNavigation)); |
743 | 743 |
744 SiteInstance* current_site_instance = render_frame_host_->GetSiteInstance(); | 744 SiteInstance* current_site_instance = render_frame_host_->GetSiteInstance(); |
745 | 745 |
746 SiteInstance* candidate_site_instance = | |
747 speculative_render_frame_host_ | |
748 ? speculative_render_frame_host_->GetSiteInstance() | |
Charlie Reis
2015/03/25 00:09:25
Style nit: All of the other uses of the ternary op
carlosk
2015/03/30 14:37:37
This has been git-cl-format-ed.
| |
749 : nullptr; | |
750 | |
746 scoped_refptr<SiteInstance> dest_site_instance = GetSiteInstanceForNavigation( | 751 scoped_refptr<SiteInstance> dest_site_instance = GetSiteInstanceForNavigation( |
747 request.common_params().url, request.source_site_instance(), | 752 request.common_params().url, request.source_site_instance(), |
748 request.dest_site_instance(), request.common_params().transition, | 753 request.dest_site_instance(), candidate_site_instance, |
754 request.common_params().transition, | |
749 request.restore_type() != NavigationEntryImpl::RESTORE_NONE, | 755 request.restore_type() != NavigationEntryImpl::RESTORE_NONE, |
750 request.is_view_source()); | 756 request.is_view_source()); |
757 | |
751 // The appropriate RenderFrameHost to commit the navigation. | 758 // The appropriate RenderFrameHost to commit the navigation. |
752 RenderFrameHostImpl* navigation_rfh = nullptr; | 759 RenderFrameHostImpl* navigation_rfh = nullptr; |
753 | 760 |
754 // Renderer-initiated navigations that may require a SiteInstance swap are | 761 // Renderer-initiated navigations that may require a SiteInstance swap are |
755 // sent to the browser via the OpenURL IPC and are afterwards treated as | 762 // sent to the browser via the OpenURL IPC and are afterwards treated as |
756 // browser-initiated navigations. NavigationRequests marked as | 763 // browser-initiated navigations. NavigationRequests marked as |
757 // renderer-initiated are created by receiving a BeginNavigation IPC, and will | 764 // renderer-initiated are created by receiving a BeginNavigation IPC, and will |
758 // then proceed in the same renderer that sent the IPC due to the condition | 765 // then proceed in the same renderer that sent the IPC due to the condition |
759 // below. | 766 // below. |
760 // TODO(carlosk): Once there is support for cross-process scripting check for | 767 // TODO(carlosk): Once there is support for cross-process scripting check for |
761 // non-browser-initiated navigations should be removed (see crbug.com/440266). | 768 // non-browser-initiated navigations should be removed (see crbug.com/440266). |
762 if (current_site_instance == dest_site_instance.get() || | 769 if (current_site_instance == dest_site_instance.get() || |
763 !request.browser_initiated() || | 770 !request.browser_initiated() || |
764 (!frame_tree_node_->IsMainFrame() && | 771 (!frame_tree_node_->IsMainFrame() && |
765 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 772 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
766 switches::kSitePerProcess))) { | 773 switches::kSitePerProcess))) { |
767 // Reuse the current RFH if its SiteInstance matches the the navigation's | 774 // Reuse the current RFH if its SiteInstance matches the the navigation's |
768 // or if this is a subframe navigation. We only swap RFHs for subframes when | 775 // or if this is a subframe navigation. We only swap RFHs for subframes when |
769 // --site-per-process is enabled. | 776 // --site-per-process is enabled. |
770 CleanUpNavigation(); | 777 CleanUpNavigation(); |
771 navigation_rfh = render_frame_host_.get(); | 778 navigation_rfh = render_frame_host_.get(); |
772 | 779 |
773 // As SiteInstances are the same, check if the WebUI should be reused. | 780 // As SiteInstances are the same, check if the WebUI should be reused. |
774 const NavigationEntry* current_navigation_entry = | 781 const NavigationEntry* current_navigation_entry = |
775 delegate_->GetLastCommittedNavigationEntryForRenderManager(); | 782 delegate_->GetLastCommittedNavigationEntryForRenderManager(); |
776 bool should_reuse_web_ui_ = ShouldReuseWebUI(current_navigation_entry, | 783 should_reuse_web_ui_ = ShouldReuseWebUI(current_navigation_entry, |
Charlie Reis
2015/03/25 00:09:25
Thanks for catching this! This is a potentially n
carlosk
2015/03/30 14:37:37
It's been pulled into crrev.com/1012863004.
This
| |
777 request.common_params().url); | 784 request.common_params().url); |
778 if (!should_reuse_web_ui_) { | 785 if (!should_reuse_web_ui_) { |
779 speculative_web_ui_ = CreateWebUI(request.common_params().url, | 786 speculative_web_ui_ = CreateWebUI(request.common_params().url, |
780 request.bindings()); | 787 request.bindings()); |
781 // Make sure the current RenderViewHost has the right bindings. | 788 // Make sure the current RenderViewHost has the right bindings. |
782 if (speculative_web_ui() && | 789 if (speculative_web_ui() && |
783 !render_frame_host_->GetProcess()->IsIsolatedGuest()) { | 790 !render_frame_host_->GetProcess()->IsIsolatedGuest()) { |
784 render_frame_host_->render_view_host()->AllowBindings( | 791 render_frame_host_->render_view_host()->AllowBindings( |
785 speculative_web_ui()->GetBindings()); | 792 speculative_web_ui()->GetBindings()); |
786 } | 793 } |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1018 (WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType( | 1025 (WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType( |
1019 controller.GetBrowserContext(), current_entry->GetURL()) == | 1026 controller.GetBrowserContext(), current_entry->GetURL()) == |
1020 WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType( | 1027 WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType( |
1021 controller.GetBrowserContext(), new_url)); | 1028 controller.GetBrowserContext(), new_url)); |
1022 } | 1029 } |
1023 | 1030 |
1024 SiteInstance* RenderFrameHostManager::GetSiteInstanceForNavigation( | 1031 SiteInstance* RenderFrameHostManager::GetSiteInstanceForNavigation( |
1025 const GURL& dest_url, | 1032 const GURL& dest_url, |
1026 SiteInstance* source_instance, | 1033 SiteInstance* source_instance, |
1027 SiteInstance* dest_instance, | 1034 SiteInstance* dest_instance, |
1035 SiteInstance* candidate_instance, | |
1036 ui::PageTransition transition, | |
1037 bool dest_is_restore, | |
1038 bool dest_is_view_source_mode) { | |
1039 SiteInstanceDescriptor descriptor = DetermineSiteInstanceForURL( | |
1040 dest_url, source_instance, dest_instance, transition, dest_is_restore, | |
1041 dest_is_view_source_mode); | |
1042 | |
1043 BrowserContext* browser_context = | |
Charlie Reis
2015/03/25 00:09:25
The rest of this function feels like it should be
carlosk
2015/03/30 14:37:37
I consolidated some methods as you suggested and r
Charlie Reis
2015/03/31 06:18:18
Yes, I meant a private method in RFHM, as you've d
| |
1044 delegate_->GetControllerForRenderManager().GetBrowserContext(); | |
1045 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); | |
1046 | |
1047 if (candidate_instance && | |
1048 SiteInstanceMatchesDescription(candidate_instance, descriptor)) { | |
1049 return candidate_instance; | |
1050 } | |
1051 | |
1052 if (descriptor.existent_site_instance) | |
1053 return descriptor.existent_site_instance; | |
1054 | |
1055 if (descriptor.new_site_is_related_to_current) { | |
1056 return current_instance->GetRelatedSiteInstance(descriptor.new_site_url); | |
1057 } | |
1058 | |
1059 return SiteInstance::CreateForURL(browser_context, descriptor.new_site_url); | |
1060 } | |
1061 | |
1062 // PlzNavigate | |
1063 bool RenderFrameHostManager::SiteInstanceMatchesDescription( | |
carlosk
2015/03/24 15:30:05
The merge of GetSiteInstanceForNavigation with IsC
| |
1064 SiteInstance* candidate_instance, | |
1065 const SiteInstanceDescriptor& descriptor) { | |
1066 CHECK(candidate_instance); | |
1067 | |
1068 if (descriptor.existent_site_instance) | |
1069 return descriptor.existent_site_instance == candidate_instance; | |
1070 | |
1071 bool candidate_is_related = | |
1072 render_frame_host_->GetSiteInstance()->IsRelatedSiteInstance( | |
1073 candidate_instance); | |
1074 | |
1075 // Note: this handles both the cases when a) the new site should be related | |
1076 // and the candidate is and b) the new site should not be related and the | |
1077 // candidate is not. Hence the equality check between two boolean values. | |
1078 if (descriptor.new_site_is_related_to_current == candidate_is_related) { | |
Charlie Reis
2015/03/25 00:09:25
This code feels like it's trying to be too clever,
carlosk
2015/03/30 14:37:37
As I finally merged this method into the new descr
Charlie Reis
2015/03/31 06:18:18
I don't agree with this conclusion. There are tim
| |
1079 return (candidate_instance->GetSiteURL() == | |
1080 SiteInstanceImpl::GetSiteForURL( | |
Charlie Reis
2015/03/25 00:09:25
This seems wrong to me. We shouldn't need to call
carlosk
2015/03/30 14:37:38
You meant that this conversion (from destination U
| |
1081 delegate_->GetControllerForRenderManager().GetBrowserContext(), | |
1082 descriptor.new_site_url)); | |
1083 } | |
1084 | |
1085 return false; | |
1086 } | |
1087 | |
1088 RenderFrameHostManager::SiteInstanceDescriptor | |
1089 RenderFrameHostManager::DetermineSiteInstanceForURL( | |
1090 const GURL& dest_url, | |
1091 SiteInstance* source_instance, | |
1092 SiteInstance* dest_instance, | |
1028 ui::PageTransition transition, | 1093 ui::PageTransition transition, |
1029 bool dest_is_restore, | 1094 bool dest_is_restore, |
1030 bool dest_is_view_source_mode) { | 1095 bool dest_is_view_source_mode) { |
1031 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); | 1096 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); |
1032 SiteInstance* new_instance = current_instance; | 1097 SiteInstanceDescriptor descriptor = SiteInstanceDescriptor(current_instance); |
1098 bool force_browsing_instance_swap = false; | |
Charlie Reis
2015/03/25 00:09:25
This isn't needed this early.
carlosk
2015/03/30 14:37:37
It needed to be defined here but with the eliminat
| |
1033 | 1099 |
1034 // We do not currently swap processes for navigations in webview tag guests. | 1100 // We do not currently swap processes for navigations in webview tag guests. |
1035 if (current_instance->GetSiteURL().SchemeIs(kGuestScheme)) | 1101 if (!current_instance->GetSiteURL().SchemeIs(kGuestScheme)) { |
1036 return current_instance; | 1102 // Determine if we need a new BrowsingInstance for this entry. If true, this |
Charlie Reis
2015/03/25 00:09:25
In many places, we intentionally return early, to
carlosk
2015/03/30 14:37:38
Done.
| |
1037 | 1103 // implies that it will get a new SiteInstance (and likely process), and |
1038 // Determine if we need a new BrowsingInstance for this entry. If true, this | 1104 // that other tabs in the current BrowsingInstance will be unable to script |
1039 // implies that it will get a new SiteInstance (and likely process), and that | 1105 // it. This is used for cases that require a process swap even in the |
1040 // other tabs in the current BrowsingInstance will be unable to script it. | 1106 // process-per-tab model, such as WebUI pages. |
1041 // This is used for cases that require a process swap even in the | 1107 // TODO(clamy): Remove the dependency on the current entry. |
1042 // process-per-tab model, such as WebUI pages. | 1108 NavigationEntry* current_entry = |
1043 // TODO(clamy): Remove the dependency on the current entry. | 1109 delegate_->GetLastCommittedNavigationEntryForRenderManager(); |
1044 const NavigationEntry* current_entry = | 1110 BrowserContext* browser_context = |
1045 delegate_->GetLastCommittedNavigationEntryForRenderManager(); | 1111 delegate_->GetControllerForRenderManager().GetBrowserContext(); |
1046 BrowserContext* browser_context = | 1112 const GURL& current_effective_url = |
1047 delegate_->GetControllerForRenderManager().GetBrowserContext(); | 1113 current_entry ? SiteInstanceImpl::GetEffectiveURL( |
1048 const GURL& current_effective_url = current_entry ? | 1114 browser_context, current_entry->GetURL()) |
1049 SiteInstanceImpl::GetEffectiveURL(browser_context, | 1115 : current_instance->GetSiteURL(); |
1050 current_entry->GetURL()) : | 1116 bool current_is_view_source_mode = current_entry |
1051 render_frame_host_->GetSiteInstance()->GetSiteURL(); | 1117 ? current_entry->IsViewSourceMode() |
1052 bool current_is_view_source_mode = current_entry ? | 1118 : dest_is_view_source_mode; |
1053 current_entry->IsViewSourceMode() : dest_is_view_source_mode; | 1119 force_browsing_instance_swap = ShouldSwapBrowsingInstancesForNavigation( |
1054 bool force_swap = ShouldSwapBrowsingInstancesForNavigation( | 1120 current_effective_url, current_is_view_source_mode, dest_instance, |
1055 current_effective_url, | 1121 SiteInstanceImpl::GetEffectiveURL(browser_context, dest_url), |
1056 current_is_view_source_mode, | 1122 dest_is_view_source_mode); |
1057 dest_instance, | 1123 if (ShouldTransitionCrossSite() || force_browsing_instance_swap) { |
1058 SiteInstanceImpl::GetEffectiveURL(browser_context, dest_url), | 1124 descriptor = DetermineSiteInstanceForURLInternal( |
1059 dest_is_view_source_mode); | 1125 dest_url, source_instance, current_instance, dest_instance, |
1060 if (ShouldTransitionCrossSite() || force_swap) { | 1126 transition, dest_is_restore, dest_is_view_source_mode, |
1061 new_instance = GetSiteInstanceForURL( | 1127 force_browsing_instance_swap); |
1062 dest_url, source_instance, current_instance, dest_instance, | 1128 } |
1063 transition, dest_is_restore, dest_is_view_source_mode, force_swap); | |
1064 } | 1129 } |
1065 | 1130 |
1066 // If force_swap is true, we must use a different SiteInstance. If we didn't, | 1131 // If |force_browsing_instance_swap| is true, we must use a different |
1067 // we would have two RenderFrameHosts in the same SiteInstance and the same | 1132 // SiteInstance than the current one. If we didn't, we would have two |
1068 // frame, resulting in page_id conflicts for their NavigationEntries. | 1133 // RenderFrameHosts in the same SiteInstance and the same frame, resulting in |
1069 if (force_swap) | 1134 // page_id conflicts for their NavigationEntries. |
1070 CHECK_NE(new_instance, current_instance); | 1135 if (force_browsing_instance_swap && descriptor.existent_site_instance) |
1071 return new_instance; | 1136 CHECK_NE(current_instance, descriptor.existent_site_instance); |
Charlie Reis
2015/03/25 00:09:25
This new check is not sufficient. If descriptor h
carlosk
2015/03/30 14:37:37
It is indeed a possible outcome and I updated the
Charlie Reis
2015/03/31 06:18:18
I was referring to the case that descriptor.existe
carlosk
2015/03/31 16:38:19
Yes, I had understood that.
| |
1137 | |
1138 return descriptor; | |
1072 } | 1139 } |
1073 | 1140 |
1074 SiteInstance* RenderFrameHostManager::GetSiteInstanceForURL( | 1141 RenderFrameHostManager::SiteInstanceDescriptor |
1142 RenderFrameHostManager::DetermineSiteInstanceForURLInternal( | |
1075 const GURL& dest_url, | 1143 const GURL& dest_url, |
1076 SiteInstance* source_instance, | 1144 SiteInstance* source_instance, |
1077 SiteInstance* current_instance, | 1145 SiteInstance* current_instance, |
1078 SiteInstance* dest_instance, | 1146 SiteInstance* dest_instance, |
1079 ui::PageTransition transition, | 1147 ui::PageTransition transition, |
1080 bool dest_is_restore, | 1148 bool dest_is_restore, |
1081 bool dest_is_view_source_mode, | 1149 bool dest_is_view_source_mode, |
1082 bool force_browsing_instance_swap) { | 1150 bool force_browsing_instance_swap) { |
1151 SiteInstanceImpl* current_instance_impl = | |
1152 static_cast<SiteInstanceImpl*>(current_instance); | |
1083 NavigationControllerImpl& controller = | 1153 NavigationControllerImpl& controller = |
1084 delegate_->GetControllerForRenderManager(); | 1154 delegate_->GetControllerForRenderManager(); |
1085 BrowserContext* browser_context = controller.GetBrowserContext(); | 1155 BrowserContext* browser_context = controller.GetBrowserContext(); |
1086 | 1156 |
1087 // If the entry has an instance already we should use it. | 1157 // If the entry has an instance already we should use it. |
1088 if (dest_instance) { | 1158 if (dest_instance) { |
1089 // If we are forcing a swap, this should be in a different BrowsingInstance. | 1159 // If we are forcing a swap, this should be in a different BrowsingInstance. |
1090 if (force_browsing_instance_swap) { | 1160 if (force_browsing_instance_swap) { |
1091 CHECK(!dest_instance->IsRelatedSiteInstance( | 1161 CHECK(!dest_instance->IsRelatedSiteInstance( |
1092 render_frame_host_->GetSiteInstance())); | 1162 render_frame_host_->GetSiteInstance())); |
1093 } | 1163 } |
1094 return dest_instance; | 1164 return SiteInstanceDescriptor(dest_instance); |
1095 } | 1165 } |
1096 | 1166 |
1097 // If a swap is required, we need to force the SiteInstance AND | 1167 // If a swap is required, we need to force the SiteInstance AND |
1098 // BrowsingInstance to be different ones, using CreateForURL. | 1168 // BrowsingInstance to be different ones, using CreateForURL. |
1099 if (force_browsing_instance_swap) | 1169 if (force_browsing_instance_swap) |
1100 return SiteInstance::CreateForURL(browser_context, dest_url); | 1170 return SiteInstanceDescriptor(dest_url, false); |
1101 | 1171 |
1102 // (UGLY) HEURISTIC, process-per-site only: | 1172 // (UGLY) HEURISTIC, process-per-site only: |
1103 // | 1173 // |
1104 // If this navigation is generated, then it probably corresponds to a search | 1174 // If this navigation is generated, then it probably corresponds to a search |
1105 // query. Given that search results typically lead to users navigating to | 1175 // query. Given that search results typically lead to users navigating to |
1106 // other sites, we don't really want to use the search engine hostname to | 1176 // other sites, we don't really want to use the search engine hostname to |
1107 // determine the site instance for this navigation. | 1177 // determine the site instance for this navigation. |
1108 // | 1178 // |
1109 // NOTE: This can be removed once we have a way to transition between | 1179 // NOTE: This can be removed once we have a way to transition between |
1110 // RenderViews in response to a link click. | 1180 // RenderViews in response to a link click. |
1111 // | 1181 // |
1112 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1182 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
1113 switches::kProcessPerSite) && | 1183 switches::kProcessPerSite) && |
1114 ui::PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_GENERATED)) { | 1184 ui::PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_GENERATED)) { |
1115 return current_instance; | 1185 return SiteInstanceDescriptor(current_instance_impl); |
1116 } | 1186 } |
1117 | 1187 |
1118 SiteInstanceImpl* current_site_instance = | |
1119 static_cast<SiteInstanceImpl*>(current_instance); | |
1120 | |
1121 // If we haven't used our SiteInstance (and thus RVH) yet, then we can use it | 1188 // If we haven't used our SiteInstance (and thus RVH) yet, then we can use it |
1122 // for this entry. We won't commit the SiteInstance to this site until the | 1189 // for this entry. We won't commit the SiteInstance to this site until the |
1123 // navigation commits (in DidNavigate), unless the navigation entry was | 1190 // navigation commits (in DidNavigate), unless the navigation entry was |
1124 // restored or it's a Web UI as described below. | 1191 // restored or it's a Web UI as described below. |
1125 if (!current_site_instance->HasSite()) { | 1192 if (!current_instance_impl->HasSite()) { |
1126 // If we've already created a SiteInstance for our destination, we don't | 1193 // If we've already created a SiteInstance for our destination, we don't |
1127 // want to use this unused SiteInstance; use the existing one. (We don't | 1194 // want to use this unused SiteInstance; use the existing one. (We don't |
1128 // do this check if the current_instance has a site, because for now, we | 1195 // do this check if the current_instance_impl has a site, because for now, |
1129 // want to compare against the current URL and not the SiteInstance's site. | 1196 // we want to compare against the current URL and not the SiteInstance's |
1130 // In this case, there is no current URL, so comparing against the site is | 1197 // site. In this case, there is no current URL, so comparing against the |
1131 // ok. See additional comments below.) | 1198 // site is ok. See additional comments below.) |
1132 // | 1199 // |
1133 // Also, if the URL should use process-per-site mode and there is an | 1200 // Also, if the URL should use process-per-site mode and there is an |
1134 // existing process for the site, we should use it. We can call | 1201 // existing process for the site, we should use it. We can call |
1135 // GetRelatedSiteInstance() for this, which will eagerly set the site and | 1202 // GetRelatedSiteInstance() for this, which will eagerly set the site and |
1136 // thus use the correct process. | 1203 // thus use the correct process. |
1137 bool use_process_per_site = | 1204 bool use_process_per_site = |
1138 RenderProcessHost::ShouldUseProcessPerSite(browser_context, dest_url) && | 1205 RenderProcessHost::ShouldUseProcessPerSite(browser_context, dest_url) && |
1139 RenderProcessHostImpl::GetProcessHostForSite(browser_context, dest_url); | 1206 RenderProcessHostImpl::GetProcessHostForSite(browser_context, dest_url); |
1140 if (current_site_instance->HasRelatedSiteInstance(dest_url) || | 1207 if (current_instance_impl->HasRelatedSiteInstance(dest_url) || |
1141 use_process_per_site) { | 1208 use_process_per_site) { |
1142 return current_site_instance->GetRelatedSiteInstance(dest_url); | 1209 return SiteInstanceDescriptor(dest_url, true); |
1143 } | 1210 } |
1144 | 1211 |
1145 // For extensions, Web UI URLs (such as the new tab page), and apps we do | 1212 // For extensions, Web UI URLs (such as the new tab page), and apps we do |
1146 // not want to use the current_instance if it has no site, since it will | 1213 // not want to use the current_instance_impl if it has no site, since it |
1147 // have a RenderProcessHost of PRIV_NORMAL. Create a new SiteInstance for | 1214 // will have a RenderProcessHost of PRIV_NORMAL. Create a new SiteInstance |
1148 // this URL instead (with the correct process type). | 1215 // for this URL instead (with the correct process type). |
1149 if (current_site_instance->HasWrongProcessForURL(dest_url)) | 1216 if (current_instance_impl->HasWrongProcessForURL(dest_url)) |
1150 return current_site_instance->GetRelatedSiteInstance(dest_url); | 1217 return SiteInstanceDescriptor(dest_url, true); |
1151 | 1218 |
1152 // View-source URLs must use a new SiteInstance and BrowsingInstance. | 1219 // View-source URLs must use a new SiteInstance and BrowsingInstance. |
1153 // TODO(nasko): This is the same condition as later in the function. This | 1220 // TODO(nasko): This is the same condition as later in the function. This |
1154 // should be taken into account when refactoring this method as part of | 1221 // should be taken into account when refactoring this method as part of |
1155 // http://crbug.com/123007. | 1222 // http://crbug.com/123007. |
1156 if (dest_is_view_source_mode) | 1223 if (dest_is_view_source_mode) |
1157 return SiteInstance::CreateForURL(browser_context, dest_url); | 1224 return SiteInstanceDescriptor(dest_url, false); |
1158 | 1225 |
1159 // If we are navigating from a blank SiteInstance to a WebUI, make sure we | 1226 // If we are navigating from a blank SiteInstance to a WebUI, make sure we |
1160 // create a new SiteInstance. | 1227 // create a new SiteInstance. |
1161 if (WebUIControllerFactoryRegistry::GetInstance()->UseWebUIForURL( | 1228 if (WebUIControllerFactoryRegistry::GetInstance()->UseWebUIForURL( |
1162 browser_context, dest_url)) { | 1229 browser_context, dest_url)) { |
1163 return SiteInstance::CreateForURL(browser_context, dest_url); | 1230 return SiteInstanceDescriptor(dest_url, false); |
1164 } | 1231 } |
1165 | 1232 |
1166 // Normally the "site" on the SiteInstance is set lazily when the load | 1233 // Normally the "site" on the SiteInstance is set lazily when the load |
1167 // actually commits. This is to support better process sharing in case | 1234 // actually commits. This is to support better process sharing in case |
1168 // the site redirects to some other site: we want to use the destination | 1235 // the site redirects to some other site: we want to use the destination |
1169 // site in the site instance. | 1236 // site in the site instance. |
1170 // | 1237 // |
1171 // In the case of session restore, as it loads all the pages immediately | 1238 // In the case of session restore, as it loads all the pages immediately |
1172 // we need to set the site first, otherwise after a restore none of the | 1239 // we need to set the site first, otherwise after a restore none of the |
1173 // pages would share renderers in process-per-site. | 1240 // pages would share renderers in process-per-site. |
1174 // | 1241 // |
1175 // The embedder can request some urls never to be assigned to SiteInstance | 1242 // The embedder can request some urls never to be assigned to SiteInstance |
1176 // through the ShouldAssignSiteForURL() content client method, so that | 1243 // through the ShouldAssignSiteForURL() content client method, so that |
1177 // renderers created for particular chrome urls (e.g. the chrome-native:// | 1244 // renderers created for particular chrome urls (e.g. the chrome-native:// |
1178 // scheme) can be reused for subsequent navigations in the same WebContents. | 1245 // scheme) can be reused for subsequent navigations in the same WebContents. |
1179 // See http://crbug.com/386542. | 1246 // See http://crbug.com/386542. |
1180 if (dest_is_restore && | 1247 if (dest_is_restore && |
1181 GetContentClient()->browser()->ShouldAssignSiteForURL(dest_url)) { | 1248 GetContentClient()->browser()->ShouldAssignSiteForURL(dest_url)) { |
1182 current_site_instance->SetSite(dest_url); | 1249 current_instance_impl->SetSite(dest_url); |
carlosk
2015/03/24 15:30:06
This whole method seems to be mostly read-only (I
Charlie Reis
2015/03/25 00:09:25
Yes, Camille had a CL that ran into this as well.
carlosk
2015/03/30 14:37:37
Acknowledged.
| |
1183 } | 1250 } |
1184 | 1251 |
1185 return current_site_instance; | 1252 return SiteInstanceDescriptor(current_instance_impl); |
1186 } | 1253 } |
1187 | 1254 |
1188 // Otherwise, only create a new SiteInstance for a cross-site navigation. | 1255 // Otherwise, only create a new SiteInstance for a cross-site navigation. |
1189 | 1256 |
1190 // TODO(creis): Once we intercept links and script-based navigations, we | 1257 // TODO(creis): Once we intercept links and script-based navigations, we |
1191 // will be able to enforce that all entries in a SiteInstance actually have | 1258 // will be able to enforce that all entries in a SiteInstance actually have |
1192 // the same site, and it will be safe to compare the URL against the | 1259 // the same site, and it will be safe to compare the URL against the |
1193 // SiteInstance's site, as follows: | 1260 // SiteInstance's site, as follows: |
1194 // const GURL& current_url = current_instance->site(); | 1261 // const GURL& current_url = current_instance_impl->site(); |
1195 // For now, though, we're in a hybrid model where you only switch | 1262 // For now, though, we're in a hybrid model where you only switch |
1196 // SiteInstances if you type in a cross-site URL. This means we have to | 1263 // SiteInstances if you type in a cross-site URL. This means we have to |
1197 // compare the entry's URL to the last committed entry's URL. | 1264 // compare the entry's URL to the last committed entry's URL. |
1198 NavigationEntry* current_entry = controller.GetLastCommittedEntry(); | 1265 NavigationEntry* current_entry = controller.GetLastCommittedEntry(); |
1199 if (interstitial_page_) { | 1266 if (interstitial_page_) { |
1200 // The interstitial is currently the last committed entry, but we want to | 1267 // The interstitial is currently the last committed entry, but we want to |
1201 // compare against the last non-interstitial entry. | 1268 // compare against the last non-interstitial entry. |
1202 current_entry = controller.GetEntryAtOffset(-1); | 1269 current_entry = controller.GetEntryAtOffset(-1); |
1203 } | 1270 } |
1204 | 1271 |
1205 // View-source URLs must use a new SiteInstance and BrowsingInstance. | 1272 // View-source URLs must use a new SiteInstance and BrowsingInstance. |
1206 // We don't need a swap when going from view-source to a debug URL like | 1273 // We don't need a swap when going from view-source to a debug URL like |
1207 // chrome://crash, however. | 1274 // chrome://crash, however. |
1208 // TODO(creis): Refactor this method so this duplicated code isn't needed. | 1275 // TODO(creis): Refactor this method so this duplicated code isn't needed. |
1209 // See http://crbug.com/123007. | 1276 // See http://crbug.com/123007. |
1210 if (current_entry && | 1277 if (current_entry && |
1211 current_entry->IsViewSourceMode() != dest_is_view_source_mode && | 1278 current_entry->IsViewSourceMode() != dest_is_view_source_mode && |
1212 !IsRendererDebugURL(dest_url)) { | 1279 !IsRendererDebugURL(dest_url)) { |
1213 return SiteInstance::CreateForURL(browser_context, dest_url); | 1280 return SiteInstanceDescriptor(dest_url, false); |
1214 } | 1281 } |
1215 | 1282 |
1216 // Use the source SiteInstance in case of data URLs or about:blank pages, | 1283 // Use the source SiteInstance in case of data URLs or about:blank pages, |
1217 // because the content is then controlled and/or scriptable by the source | 1284 // because the content is then controlled and/or scriptable by the source |
1218 // SiteInstance. | 1285 // SiteInstance. |
1219 GURL about_blank(url::kAboutBlankURL); | 1286 GURL about_blank(url::kAboutBlankURL); |
1220 if (source_instance && | 1287 if (source_instance && |
1221 (dest_url == about_blank || dest_url.scheme() == url::kDataScheme)) | 1288 (dest_url == about_blank || dest_url.scheme() == url::kDataScheme)) { |
1222 return source_instance; | 1289 return SiteInstanceDescriptor(source_instance); |
1290 } | |
1223 | 1291 |
1224 // Use the current SiteInstance for same site navigations, as long as the | 1292 // Use the current SiteInstance for same site navigations, as long as the |
1225 // process type is correct. (The URL may have been installed as an app since | 1293 // process type is correct. (The URL may have been installed as an app since |
1226 // the last time we visited it.) | 1294 // the last time we visited it.) |
1227 const GURL& current_url = | 1295 const GURL& current_url = |
1228 GetCurrentURLForSiteInstance(current_instance, current_entry); | 1296 GetCurrentURLForSiteInstance(current_instance_impl, current_entry); |
1229 if (SiteInstance::IsSameWebSite(browser_context, current_url, dest_url) && | 1297 if (SiteInstance::IsSameWebSite(browser_context, current_url, dest_url) && |
1230 !current_site_instance->HasWrongProcessForURL(dest_url)) { | 1298 !current_instance_impl->HasWrongProcessForURL(dest_url)) { |
1231 return current_instance; | 1299 return SiteInstanceDescriptor(current_instance_impl); |
1232 } | 1300 } |
1233 | 1301 |
1234 // Start the new renderer in a new SiteInstance, but in the current | 1302 // Start the new renderer in a new SiteInstance, but in the current |
1235 // BrowsingInstance. It is important to immediately give this new | 1303 // BrowsingInstance. It is important to immediately give this new |
1236 // SiteInstance to a RenderViewHost (if it is different than our current | 1304 // SiteInstance to a RenderViewHost (if it is different than our current |
1237 // SiteInstance), so that it is ref counted. This will happen in | 1305 // SiteInstance), so that it is ref counted. This will happen in |
1238 // CreateRenderView. | 1306 // CreateRenderView. |
1239 return current_instance->GetRelatedSiteInstance(dest_url); | 1307 return SiteInstanceDescriptor(dest_url, true); |
1240 } | 1308 } |
1241 | 1309 |
1242 const GURL& RenderFrameHostManager::GetCurrentURLForSiteInstance( | 1310 const GURL& RenderFrameHostManager::GetCurrentURLForSiteInstance( |
1243 SiteInstance* current_instance, NavigationEntry* current_entry) { | 1311 SiteInstance* current_instance, NavigationEntry* current_entry) { |
1244 // If this is a subframe that is potentially out of process from its parent, | 1312 // If this is a subframe that is potentially out of process from its parent, |
1245 // don't consider using current_entry's url for SiteInstance selection, since | 1313 // don't consider using current_entry's url for SiteInstance selection, since |
1246 // current_entry's url is for the main frame and may be in a different site | 1314 // current_entry's url is for the main frame and may be in a different site |
1247 // than this frame. | 1315 // than this frame. |
1248 // TODO(creis): Remove this when we can check the FrameNavigationEntry's url. | 1316 // TODO(creis): Remove this when we can check the FrameNavigationEntry's url. |
1249 // See http://crbug.com/369654 | 1317 // See http://crbug.com/369654 |
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1794 // If we are currently navigating cross-process, we want to get back to normal | 1862 // If we are currently navigating cross-process, we want to get back to normal |
1795 // and then navigate as usual. | 1863 // and then navigate as usual. |
1796 if (cross_navigation_pending_) { | 1864 if (cross_navigation_pending_) { |
1797 if (pending_render_frame_host_) | 1865 if (pending_render_frame_host_) |
1798 CancelPending(); | 1866 CancelPending(); |
1799 cross_navigation_pending_ = false; | 1867 cross_navigation_pending_ = false; |
1800 } | 1868 } |
1801 | 1869 |
1802 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); | 1870 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); |
1803 scoped_refptr<SiteInstance> new_instance = GetSiteInstanceForNavigation( | 1871 scoped_refptr<SiteInstance> new_instance = GetSiteInstanceForNavigation( |
1804 dest_url, source_instance, dest_instance, transition, | 1872 dest_url, source_instance, dest_instance, nullptr, transition, |
1805 dest_is_restore, dest_is_view_source_mode); | 1873 dest_is_restore, dest_is_view_source_mode); |
1806 | 1874 |
1807 const NavigationEntry* current_entry = | 1875 const NavigationEntry* current_entry = |
1808 delegate_->GetLastCommittedNavigationEntryForRenderManager(); | 1876 delegate_->GetLastCommittedNavigationEntryForRenderManager(); |
1809 | 1877 |
1810 DCHECK(!cross_navigation_pending_); | 1878 DCHECK(!cross_navigation_pending_); |
1811 | 1879 |
1812 if (new_instance.get() != current_instance) { | 1880 if (new_instance.get() != current_instance) { |
1813 TRACE_EVENT_INSTANT2( | 1881 TRACE_EVENT_INSTANT2( |
1814 "navigation", | 1882 "navigation", |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2019 void RenderFrameHostManager::DeleteRenderFrameProxyHost( | 2087 void RenderFrameHostManager::DeleteRenderFrameProxyHost( |
2020 SiteInstance* instance) { | 2088 SiteInstance* instance) { |
2021 RenderFrameProxyHostMap::iterator iter = proxy_hosts_.find(instance->GetId()); | 2089 RenderFrameProxyHostMap::iterator iter = proxy_hosts_.find(instance->GetId()); |
2022 if (iter != proxy_hosts_.end()) { | 2090 if (iter != proxy_hosts_.end()) { |
2023 delete iter->second; | 2091 delete iter->second; |
2024 proxy_hosts_.erase(iter); | 2092 proxy_hosts_.erase(iter); |
2025 } | 2093 } |
2026 } | 2094 } |
2027 | 2095 |
2028 } // namespace content | 2096 } // namespace content |
OLD | NEW |