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() | |
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 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
886 case NOTIFICATION_RENDERER_PROCESS_CLOSING: | 893 case NOTIFICATION_RENDERER_PROCESS_CLOSING: |
887 RendererProcessClosing( | 894 RendererProcessClosing( |
888 Source<RenderProcessHost>(source).ptr()); | 895 Source<RenderProcessHost>(source).ptr()); |
889 break; | 896 break; |
890 | 897 |
891 default: | 898 default: |
892 NOTREACHED(); | 899 NOTREACHED(); |
893 } | 900 } |
894 } | 901 } |
895 | 902 |
903 RenderFrameHostManager::SiteInstanceDescriptor::SiteInstanceDescriptor( | |
904 GURL site_url, | |
Charlie Reis
2015/03/31 06:18:18
This is the wrong name if it's not already the Sit
carlosk
2015/03/31 16:38:19
Done.
| |
905 bool related_to_current, | |
906 BrowserContext* browser_context) | |
907 : existing_site_instance(nullptr), | |
908 new_is_related_to_current(related_to_current) { | |
909 new_site_url = SiteInstanceImpl::GetSiteForURL(browser_context, site_url); | |
910 } | |
911 | |
896 // static | 912 // static |
897 bool RenderFrameHostManager::ClearProxiesInSiteInstance( | 913 bool RenderFrameHostManager::ClearProxiesInSiteInstance( |
898 int32 site_instance_id, | 914 int32 site_instance_id, |
899 FrameTreeNode* node) { | 915 FrameTreeNode* node) { |
900 RenderFrameProxyHostMap::iterator iter = | 916 RenderFrameProxyHostMap::iterator iter = |
901 node->render_manager()->proxy_hosts_.find(site_instance_id); | 917 node->render_manager()->proxy_hosts_.find(site_instance_id); |
902 if (iter != node->render_manager()->proxy_hosts_.end()) { | 918 if (iter != node->render_manager()->proxy_hosts_.end()) { |
903 RenderFrameProxyHost* proxy = iter->second; | 919 RenderFrameProxyHost* proxy = iter->second; |
904 // Delete the proxy. If it is for a main frame (and thus the RFH is stored | 920 // Delete the proxy. If it is for a main frame (and thus the RFH is stored |
905 // in the proxy) and it was still pending swap out, move the RFH to the | 921 // in the proxy) and it was still pending swap out, move the RFH to the |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1018 (WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType( | 1034 (WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType( |
1019 controller.GetBrowserContext(), current_entry->GetURL()) == | 1035 controller.GetBrowserContext(), current_entry->GetURL()) == |
1020 WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType( | 1036 WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType( |
1021 controller.GetBrowserContext(), new_url)); | 1037 controller.GetBrowserContext(), new_url)); |
1022 } | 1038 } |
1023 | 1039 |
1024 SiteInstance* RenderFrameHostManager::GetSiteInstanceForNavigation( | 1040 SiteInstance* RenderFrameHostManager::GetSiteInstanceForNavigation( |
1025 const GURL& dest_url, | 1041 const GURL& dest_url, |
1026 SiteInstance* source_instance, | 1042 SiteInstance* source_instance, |
1027 SiteInstance* dest_instance, | 1043 SiteInstance* dest_instance, |
1044 SiteInstance* candidate_instance, | |
1028 ui::PageTransition transition, | 1045 ui::PageTransition transition, |
1029 bool dest_is_restore, | 1046 bool dest_is_restore, |
1030 bool dest_is_view_source_mode) { | 1047 bool dest_is_view_source_mode) { |
1031 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); | 1048 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); |
1032 SiteInstance* new_instance = current_instance; | |
1033 | 1049 |
1034 // We do not currently swap processes for navigations in webview tag guests. | 1050 // We do not currently swap processes for navigations in webview tag guests. |
1035 if (current_instance->GetSiteURL().SchemeIs(kGuestScheme)) | 1051 if (current_instance->GetSiteURL().SchemeIs(kGuestScheme)) |
1036 return current_instance; | 1052 return current_instance; |
1037 | 1053 |
1038 // Determine if we need a new BrowsingInstance for this entry. If true, this | 1054 // Determine if we need a new BrowsingInstance for this entry. If true, this |
Charlie Reis
2015/03/31 06:18:18
nit: Please do not add churn on these lines just t
carlosk
2015/03/31 16:38:19
I reverted it here but as below I'm also adding fu
Charlie Reis
2015/03/31 20:19:58
That's fine in the cases where you're actually cha
carlosk
2015/04/01 15:25:29
Sorry about that, I forgot about those. The plain
| |
1039 // implies that it will get a new SiteInstance (and likely process), and that | 1055 // implies that it will get a new SiteInstance (and likely process), and that |
1040 // other tabs in the current BrowsingInstance will be unable to script it. | 1056 // other tabs in the current BrowsingInstance will be unable to script it. |
1041 // This is used for cases that require a process swap even in the | 1057 // This is used for cases that require a process swap even in the |
1042 // process-per-tab model, such as WebUI pages. | 1058 // process-per-tab model, such as WebUI pages. |
1043 // TODO(clamy): Remove the dependency on the current entry. | 1059 // TODO(clamy): Remove the dependency on the current entry. |
1044 const NavigationEntry* current_entry = | 1060 const NavigationEntry* current_entry = |
1045 delegate_->GetLastCommittedNavigationEntryForRenderManager(); | 1061 delegate_->GetLastCommittedNavigationEntryForRenderManager(); |
1046 BrowserContext* browser_context = | 1062 BrowserContext* browser_context = |
1047 delegate_->GetControllerForRenderManager().GetBrowserContext(); | 1063 delegate_->GetControllerForRenderManager().GetBrowserContext(); |
1048 const GURL& current_effective_url = current_entry ? | 1064 const GURL& current_effective_url = current_entry ? |
1049 SiteInstanceImpl::GetEffectiveURL(browser_context, | 1065 SiteInstanceImpl::GetEffectiveURL(browser_context, |
1050 current_entry->GetURL()) : | 1066 current_entry->GetURL()) : |
1051 render_frame_host_->GetSiteInstance()->GetSiteURL(); | 1067 render_frame_host_->GetSiteInstance()->GetSiteURL(); |
1052 bool current_is_view_source_mode = current_entry ? | 1068 bool current_is_view_source_mode = current_entry ? |
1053 current_entry->IsViewSourceMode() : dest_is_view_source_mode; | 1069 current_entry->IsViewSourceMode() : dest_is_view_source_mode; |
1054 bool force_swap = ShouldSwapBrowsingInstancesForNavigation( | 1070 bool force_swap = ShouldSwapBrowsingInstancesForNavigation( |
1055 current_effective_url, | 1071 current_effective_url, |
1056 current_is_view_source_mode, | 1072 current_is_view_source_mode, |
1057 dest_instance, | 1073 dest_instance, |
1058 SiteInstanceImpl::GetEffectiveURL(browser_context, dest_url), | 1074 SiteInstanceImpl::GetEffectiveURL(browser_context, dest_url), |
1059 dest_is_view_source_mode); | 1075 dest_is_view_source_mode); |
1076 SiteInstanceDescriptor descriptor = SiteInstanceDescriptor(current_instance); | |
Charlie Reis
2015/03/31 06:18:18
descriptor isn't a useful name, since it's not cle
carlosk
2015/03/31 16:38:19
Done.
| |
1060 if (ShouldTransitionCrossSite() || force_swap) { | 1077 if (ShouldTransitionCrossSite() || force_swap) { |
1061 new_instance = GetSiteInstanceForURL( | 1078 descriptor = DetermineSiteInstanceForURL( |
1062 dest_url, source_instance, current_instance, dest_instance, | 1079 dest_url, source_instance, current_instance, dest_instance, transition, |
1063 transition, dest_is_restore, dest_is_view_source_mode, force_swap); | 1080 dest_is_restore, dest_is_view_source_mode, force_swap); |
1064 } | 1081 } |
1065 | 1082 |
1066 // If force_swap is true, we must use a different SiteInstance. If we didn't, | 1083 // If |force_swap| is true, we must use a different SiteInstance than the |
1067 // we would have two RenderFrameHosts in the same SiteInstance and the same | 1084 // current one. If we didn't, we would have two RenderFrameHosts in the same |
1068 // frame, resulting in page_id conflicts for their NavigationEntries. | 1085 // SiteInstance and the same frame, resulting in page_id conflicts for their |
1069 if (force_swap) | 1086 // NavigationEntries. |
1070 CHECK_NE(new_instance, current_instance); | 1087 if (force_swap) { |
1071 return new_instance; | 1088 if (descriptor.existing_site_instance) { |
1089 CHECK_NE(current_instance, descriptor.existing_site_instance); | |
1090 } else if (descriptor.new_is_related_to_current) { | |
1091 CHECK_NE(current_instance->GetSiteURL(), descriptor.new_site_url); | |
1092 } | |
1093 } | |
1094 | |
1095 return ConvertToSiteInstance(descriptor, candidate_instance); | |
Charlie Reis
2015/03/31 06:18:18
If we put the ConvertToSiteInstance call earlier (
carlosk
2015/03/31 16:38:19
Done.
| |
1072 } | 1096 } |
1073 | 1097 |
1074 SiteInstance* RenderFrameHostManager::GetSiteInstanceForURL( | 1098 RenderFrameHostManager::SiteInstanceDescriptor |
1099 RenderFrameHostManager::DetermineSiteInstanceForURL( | |
1075 const GURL& dest_url, | 1100 const GURL& dest_url, |
1076 SiteInstance* source_instance, | 1101 SiteInstance* source_instance, |
1077 SiteInstance* current_instance, | 1102 SiteInstance* current_instance, |
1078 SiteInstance* dest_instance, | 1103 SiteInstance* dest_instance, |
1079 ui::PageTransition transition, | 1104 ui::PageTransition transition, |
1080 bool dest_is_restore, | 1105 bool dest_is_restore, |
1081 bool dest_is_view_source_mode, | 1106 bool dest_is_view_source_mode, |
1082 bool force_browsing_instance_swap) { | 1107 bool force_browsing_instance_swap) { |
1108 SiteInstanceImpl* current_instance_impl = | |
1109 static_cast<SiteInstanceImpl*>(current_instance); | |
1083 NavigationControllerImpl& controller = | 1110 NavigationControllerImpl& controller = |
1084 delegate_->GetControllerForRenderManager(); | 1111 delegate_->GetControllerForRenderManager(); |
1085 BrowserContext* browser_context = controller.GetBrowserContext(); | 1112 BrowserContext* browser_context = controller.GetBrowserContext(); |
1086 | 1113 |
1087 // If the entry has an instance already we should use it. | 1114 // If the entry has an instance already we should use it. |
1088 if (dest_instance) { | 1115 if (dest_instance) { |
1089 // If we are forcing a swap, this should be in a different BrowsingInstance. | 1116 // If we are forcing a swap, this should be in a different BrowsingInstance. |
1090 if (force_browsing_instance_swap) { | 1117 if (force_browsing_instance_swap) { |
1091 CHECK(!dest_instance->IsRelatedSiteInstance( | 1118 CHECK(!dest_instance->IsRelatedSiteInstance( |
1092 render_frame_host_->GetSiteInstance())); | 1119 render_frame_host_->GetSiteInstance())); |
1093 } | 1120 } |
1094 return dest_instance; | 1121 return SiteInstanceDescriptor(dest_instance); |
1095 } | 1122 } |
1096 | 1123 |
1097 // If a swap is required, we need to force the SiteInstance AND | 1124 // If a swap is required, we need to force the SiteInstance AND |
1098 // BrowsingInstance to be different ones, using CreateForURL. | 1125 // BrowsingInstance to be different ones, using CreateForURL. |
1099 if (force_browsing_instance_swap) | 1126 if (force_browsing_instance_swap) |
1100 return SiteInstance::CreateForURL(browser_context, dest_url); | 1127 return SiteInstanceDescriptor(dest_url, false, browser_context); |
1101 | 1128 |
1102 // (UGLY) HEURISTIC, process-per-site only: | 1129 // (UGLY) HEURISTIC, process-per-site only: |
1103 // | 1130 // |
1104 // If this navigation is generated, then it probably corresponds to a search | 1131 // If this navigation is generated, then it probably corresponds to a search |
1105 // query. Given that search results typically lead to users navigating to | 1132 // 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 | 1133 // other sites, we don't really want to use the search engine hostname to |
1107 // determine the site instance for this navigation. | 1134 // determine the site instance for this navigation. |
1108 // | 1135 // |
1109 // NOTE: This can be removed once we have a way to transition between | 1136 // NOTE: This can be removed once we have a way to transition between |
1110 // RenderViews in response to a link click. | 1137 // RenderViews in response to a link click. |
1111 // | 1138 // |
1112 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1139 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
1113 switches::kProcessPerSite) && | 1140 switches::kProcessPerSite) && |
1114 ui::PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_GENERATED)) { | 1141 ui::PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_GENERATED)) { |
1115 return current_instance; | 1142 return SiteInstanceDescriptor(current_instance_impl); |
1116 } | 1143 } |
1117 | 1144 |
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 | 1145 // 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 | 1146 // for this entry. We won't commit the SiteInstance to this site until the |
1123 // navigation commits (in DidNavigate), unless the navigation entry was | 1147 // navigation commits (in DidNavigate), unless the navigation entry was |
1124 // restored or it's a Web UI as described below. | 1148 // restored or it's a Web UI as described below. |
1125 if (!current_site_instance->HasSite()) { | 1149 if (!current_instance_impl->HasSite()) { |
1126 // If we've already created a SiteInstance for our destination, we don't | 1150 // 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 | 1151 // 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 | 1152 // 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. | 1153 // 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 | 1154 // site. In this case, there is no current URL, so comparing against the |
1131 // ok. See additional comments below.) | 1155 // site is ok. See additional comments below.) |
1132 // | 1156 // |
1133 // Also, if the URL should use process-per-site mode and there is an | 1157 // 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 | 1158 // existing process for the site, we should use it. We can call |
1135 // GetRelatedSiteInstance() for this, which will eagerly set the site and | 1159 // GetRelatedSiteInstance() for this, which will eagerly set the site and |
1136 // thus use the correct process. | 1160 // thus use the correct process. |
1137 bool use_process_per_site = | 1161 bool use_process_per_site = |
1138 RenderProcessHost::ShouldUseProcessPerSite(browser_context, dest_url) && | 1162 RenderProcessHost::ShouldUseProcessPerSite(browser_context, dest_url) && |
1139 RenderProcessHostImpl::GetProcessHostForSite(browser_context, dest_url); | 1163 RenderProcessHostImpl::GetProcessHostForSite(browser_context, dest_url); |
1140 if (current_site_instance->HasRelatedSiteInstance(dest_url) || | 1164 if (current_instance_impl->HasRelatedSiteInstance(dest_url) || |
1141 use_process_per_site) { | 1165 use_process_per_site) { |
1142 return current_site_instance->GetRelatedSiteInstance(dest_url); | 1166 return SiteInstanceDescriptor(dest_url, true, browser_context); |
1143 } | 1167 } |
1144 | 1168 |
1145 // For extensions, Web UI URLs (such as the new tab page), and apps we do | 1169 // 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 | 1170 // 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 | 1171 // will have a RenderProcessHost of PRIV_NORMAL. Create a new SiteInstance |
1148 // this URL instead (with the correct process type). | 1172 // for this URL instead (with the correct process type). |
1149 if (current_site_instance->HasWrongProcessForURL(dest_url)) | 1173 if (current_instance_impl->HasWrongProcessForURL(dest_url)) |
1150 return current_site_instance->GetRelatedSiteInstance(dest_url); | 1174 return SiteInstanceDescriptor(dest_url, true, browser_context); |
1151 | 1175 |
1152 // View-source URLs must use a new SiteInstance and BrowsingInstance. | 1176 // View-source URLs must use a new SiteInstance and BrowsingInstance. |
1153 // TODO(nasko): This is the same condition as later in the function. This | 1177 // 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 | 1178 // should be taken into account when refactoring this method as part of |
1155 // http://crbug.com/123007. | 1179 // http://crbug.com/123007. |
1156 if (dest_is_view_source_mode) | 1180 if (dest_is_view_source_mode) |
1157 return SiteInstance::CreateForURL(browser_context, dest_url); | 1181 return SiteInstanceDescriptor(dest_url, false, browser_context); |
1158 | 1182 |
1159 // If we are navigating from a blank SiteInstance to a WebUI, make sure we | 1183 // If we are navigating from a blank SiteInstance to a WebUI, make sure we |
1160 // create a new SiteInstance. | 1184 // create a new SiteInstance. |
1161 if (WebUIControllerFactoryRegistry::GetInstance()->UseWebUIForURL( | 1185 if (WebUIControllerFactoryRegistry::GetInstance()->UseWebUIForURL( |
1162 browser_context, dest_url)) { | 1186 browser_context, dest_url)) { |
1163 return SiteInstance::CreateForURL(browser_context, dest_url); | 1187 return SiteInstanceDescriptor(dest_url, false, browser_context); |
1164 } | 1188 } |
1165 | 1189 |
1166 // Normally the "site" on the SiteInstance is set lazily when the load | 1190 // Normally the "site" on the SiteInstance is set lazily when the load |
1167 // actually commits. This is to support better process sharing in case | 1191 // 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 | 1192 // the site redirects to some other site: we want to use the destination |
1169 // site in the site instance. | 1193 // site in the site instance. |
1170 // | 1194 // |
1171 // In the case of session restore, as it loads all the pages immediately | 1195 // 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 | 1196 // we need to set the site first, otherwise after a restore none of the |
1173 // pages would share renderers in process-per-site. | 1197 // pages would share renderers in process-per-site. |
1174 // | 1198 // |
1175 // The embedder can request some urls never to be assigned to SiteInstance | 1199 // The embedder can request some urls never to be assigned to SiteInstance |
1176 // through the ShouldAssignSiteForURL() content client method, so that | 1200 // through the ShouldAssignSiteForURL() content client method, so that |
1177 // renderers created for particular chrome urls (e.g. the chrome-native:// | 1201 // renderers created for particular chrome urls (e.g. the chrome-native:// |
1178 // scheme) can be reused for subsequent navigations in the same WebContents. | 1202 // scheme) can be reused for subsequent navigations in the same WebContents. |
1179 // See http://crbug.com/386542. | 1203 // See http://crbug.com/386542. |
1180 if (dest_is_restore && | 1204 if (dest_is_restore && |
1181 GetContentClient()->browser()->ShouldAssignSiteForURL(dest_url)) { | 1205 GetContentClient()->browser()->ShouldAssignSiteForURL(dest_url)) { |
1182 current_site_instance->SetSite(dest_url); | 1206 current_instance_impl->SetSite(dest_url); |
1183 } | 1207 } |
1184 | 1208 |
1185 return current_site_instance; | 1209 return SiteInstanceDescriptor(current_instance_impl); |
1186 } | 1210 } |
1187 | 1211 |
1188 // Otherwise, only create a new SiteInstance for a cross-site navigation. | 1212 // Otherwise, only create a new SiteInstance for a cross-site navigation. |
1189 | 1213 |
1190 // TODO(creis): Once we intercept links and script-based navigations, we | 1214 // 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 | 1215 // 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 | 1216 // the same site, and it will be safe to compare the URL against the |
1193 // SiteInstance's site, as follows: | 1217 // SiteInstance's site, as follows: |
1194 // const GURL& current_url = current_instance->site(); | 1218 // const GURL& current_url = current_instance_impl->site(); |
1195 // For now, though, we're in a hybrid model where you only switch | 1219 // 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 | 1220 // 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. | 1221 // compare the entry's URL to the last committed entry's URL. |
1198 NavigationEntry* current_entry = controller.GetLastCommittedEntry(); | 1222 NavigationEntry* current_entry = controller.GetLastCommittedEntry(); |
1199 if (interstitial_page_) { | 1223 if (interstitial_page_) { |
1200 // The interstitial is currently the last committed entry, but we want to | 1224 // The interstitial is currently the last committed entry, but we want to |
1201 // compare against the last non-interstitial entry. | 1225 // compare against the last non-interstitial entry. |
1202 current_entry = controller.GetEntryAtOffset(-1); | 1226 current_entry = controller.GetEntryAtOffset(-1); |
1203 } | 1227 } |
1204 | 1228 |
1205 // View-source URLs must use a new SiteInstance and BrowsingInstance. | 1229 // 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 | 1230 // We don't need a swap when going from view-source to a debug URL like |
1207 // chrome://crash, however. | 1231 // chrome://crash, however. |
1208 // TODO(creis): Refactor this method so this duplicated code isn't needed. | 1232 // TODO(creis): Refactor this method so this duplicated code isn't needed. |
1209 // See http://crbug.com/123007. | 1233 // See http://crbug.com/123007. |
1210 if (current_entry && | 1234 if (current_entry && |
1211 current_entry->IsViewSourceMode() != dest_is_view_source_mode && | 1235 current_entry->IsViewSourceMode() != dest_is_view_source_mode && |
1212 !IsRendererDebugURL(dest_url)) { | 1236 !IsRendererDebugURL(dest_url)) { |
1213 return SiteInstance::CreateForURL(browser_context, dest_url); | 1237 return SiteInstanceDescriptor(dest_url, false, browser_context); |
1214 } | 1238 } |
1215 | 1239 |
1216 // Use the source SiteInstance in case of data URLs or about:blank pages, | 1240 // 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 | 1241 // because the content is then controlled and/or scriptable by the source |
1218 // SiteInstance. | 1242 // SiteInstance. |
1219 GURL about_blank(url::kAboutBlankURL); | 1243 GURL about_blank(url::kAboutBlankURL); |
1220 if (source_instance && | 1244 if (source_instance && |
1221 (dest_url == about_blank || dest_url.scheme() == url::kDataScheme)) | 1245 (dest_url == about_blank || dest_url.scheme() == url::kDataScheme)) { |
1222 return source_instance; | 1246 return SiteInstanceDescriptor(source_instance); |
1247 } | |
1223 | 1248 |
1224 // Use the current SiteInstance for same site navigations, as long as the | 1249 // 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 | 1250 // process type is correct. (The URL may have been installed as an app since |
1226 // the last time we visited it.) | 1251 // the last time we visited it.) |
1227 const GURL& current_url = | 1252 const GURL& current_url = |
1228 GetCurrentURLForSiteInstance(current_instance, current_entry); | 1253 GetCurrentURLForSiteInstance(current_instance_impl, current_entry); |
1229 if (SiteInstance::IsSameWebSite(browser_context, current_url, dest_url) && | 1254 if (SiteInstance::IsSameWebSite(browser_context, current_url, dest_url) && |
1230 !current_site_instance->HasWrongProcessForURL(dest_url)) { | 1255 !current_instance_impl->HasWrongProcessForURL(dest_url)) { |
1231 return current_instance; | 1256 return SiteInstanceDescriptor(current_instance_impl); |
1232 } | 1257 } |
1233 | 1258 |
1234 // Start the new renderer in a new SiteInstance, but in the current | 1259 // Start the new renderer in a new SiteInstance, but in the current |
1235 // BrowsingInstance. It is important to immediately give this new | 1260 // BrowsingInstance. It is important to immediately give this new |
1236 // SiteInstance to a RenderViewHost (if it is different than our current | 1261 // SiteInstance to a RenderViewHost (if it is different than our current |
1237 // SiteInstance), so that it is ref counted. This will happen in | 1262 // SiteInstance), so that it is ref counted. This will happen in |
1238 // CreateRenderView. | 1263 // CreateRenderView. |
1239 return current_instance->GetRelatedSiteInstance(dest_url); | 1264 return SiteInstanceDescriptor(dest_url, true, browser_context); |
1265 } | |
1266 | |
1267 SiteInstance* RenderFrameHostManager::ConvertToSiteInstance( | |
1268 const SiteInstanceDescriptor& descriptor, | |
1269 SiteInstance* candidate_instance) { | |
1270 BrowserContext* browser_context = | |
Charlie Reis
2015/03/31 06:18:18
We don't need this until the last line, and most o
carlosk
2015/03/31 16:38:19
Done.
| |
1271 delegate_->GetControllerForRenderManager().GetBrowserContext(); | |
1272 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); | |
1273 | |
1274 if (candidate_instance) { | |
Charlie Reis
2015/03/31 06:18:18
This control flow seems odd to me. The only case
carlosk
2015/03/31 16:38:19
Yes, I didn't notice the coincidences in logic tha
| |
1275 if (descriptor.existing_site_instance && | |
1276 descriptor.existing_site_instance == candidate_instance) { | |
1277 return candidate_instance; | |
1278 } | |
1279 bool candidate_is_related = | |
1280 render_frame_host_->GetSiteInstance()->IsRelatedSiteInstance( | |
Charlie Reis
2015/03/31 06:18:18
You've already declared current_instance, so there
carlosk
2015/03/31 16:38:19
Done.
| |
1281 candidate_instance); | |
1282 if (descriptor.new_is_related_to_current == candidate_is_related && | |
1283 candidate_instance->GetSiteURL() == descriptor.new_site_url) { | |
1284 // At this point there's two possibilities a) the new site should be | |
1285 // related and the candidate effectively is or b) the new site should not | |
1286 // be related and the candidate is not. In either case we need to verify | |
1287 // if the site URL matches the candidate's. | |
1288 return candidate_instance; | |
1289 } | |
1290 } | |
1291 | |
1292 if (descriptor.existing_site_instance) | |
1293 return descriptor.existing_site_instance; | |
1294 | |
1295 if (descriptor.new_is_related_to_current) { | |
Charlie Reis
2015/03/31 06:18:19
No braces.
carlosk
2015/03/31 16:38:19
Done.
| |
1296 return current_instance->GetRelatedSiteInstance(descriptor.new_site_url); | |
1297 } | |
1298 | |
1299 return SiteInstance::CreateForURL(browser_context, descriptor.new_site_url); | |
1240 } | 1300 } |
1241 | 1301 |
1242 const GURL& RenderFrameHostManager::GetCurrentURLForSiteInstance( | 1302 const GURL& RenderFrameHostManager::GetCurrentURLForSiteInstance( |
1243 SiteInstance* current_instance, NavigationEntry* current_entry) { | 1303 SiteInstance* current_instance, NavigationEntry* current_entry) { |
1244 // If this is a subframe that is potentially out of process from its parent, | 1304 // 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 | 1305 // 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 | 1306 // current_entry's url is for the main frame and may be in a different site |
1247 // than this frame. | 1307 // than this frame. |
1248 // TODO(creis): Remove this when we can check the FrameNavigationEntry's url. | 1308 // TODO(creis): Remove this when we can check the FrameNavigationEntry's url. |
1249 // See http://crbug.com/369654 | 1309 // 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 | 1854 // If we are currently navigating cross-process, we want to get back to normal |
1795 // and then navigate as usual. | 1855 // and then navigate as usual. |
1796 if (cross_navigation_pending_) { | 1856 if (cross_navigation_pending_) { |
1797 if (pending_render_frame_host_) | 1857 if (pending_render_frame_host_) |
1798 CancelPending(); | 1858 CancelPending(); |
1799 cross_navigation_pending_ = false; | 1859 cross_navigation_pending_ = false; |
1800 } | 1860 } |
1801 | 1861 |
1802 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); | 1862 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); |
1803 scoped_refptr<SiteInstance> new_instance = GetSiteInstanceForNavigation( | 1863 scoped_refptr<SiteInstance> new_instance = GetSiteInstanceForNavigation( |
1804 dest_url, source_instance, dest_instance, transition, | 1864 dest_url, source_instance, dest_instance, nullptr, transition, |
1805 dest_is_restore, dest_is_view_source_mode); | 1865 dest_is_restore, dest_is_view_source_mode); |
1806 | 1866 |
1807 const NavigationEntry* current_entry = | 1867 const NavigationEntry* current_entry = |
1808 delegate_->GetLastCommittedNavigationEntryForRenderManager(); | 1868 delegate_->GetLastCommittedNavigationEntryForRenderManager(); |
1809 | 1869 |
1810 DCHECK(!cross_navigation_pending_); | 1870 DCHECK(!cross_navigation_pending_); |
1811 | 1871 |
1812 if (new_instance.get() != current_instance) { | 1872 if (new_instance.get() != current_instance) { |
1813 TRACE_EVENT_INSTANT2( | 1873 TRACE_EVENT_INSTANT2( |
1814 "navigation", | 1874 "navigation", |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2019 void RenderFrameHostManager::DeleteRenderFrameProxyHost( | 2079 void RenderFrameHostManager::DeleteRenderFrameProxyHost( |
2020 SiteInstance* instance) { | 2080 SiteInstance* instance) { |
2021 RenderFrameProxyHostMap::iterator iter = proxy_hosts_.find(instance->GetId()); | 2081 RenderFrameProxyHostMap::iterator iter = proxy_hosts_.find(instance->GetId()); |
2022 if (iter != proxy_hosts_.end()) { | 2082 if (iter != proxy_hosts_.end()) { |
2023 delete iter->second; | 2083 delete iter->second; |
2024 proxy_hosts_.erase(iter); | 2084 proxy_hosts_.erase(iter); |
2025 } | 2085 } |
2026 } | 2086 } |
2027 | 2087 |
2028 } // namespace content | 2088 } // namespace content |
OLD | NEW |