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 dest_url, | |
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, dest_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 |
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 new_instance_descriptor = | |
1077 SiteInstanceDescriptor(current_instance); | |
1060 if (ShouldTransitionCrossSite() || force_swap) { | 1078 if (ShouldTransitionCrossSite() || force_swap) { |
1061 new_instance = GetSiteInstanceForURL( | 1079 new_instance_descriptor = DetermineSiteInstanceForURL( |
1062 dest_url, source_instance, current_instance, dest_instance, | 1080 dest_url, source_instance, current_instance, dest_instance, transition, |
1063 transition, dest_is_restore, dest_is_view_source_mode, force_swap); | 1081 dest_is_restore, dest_is_view_source_mode, force_swap); |
1064 } | 1082 } |
1065 | 1083 |
1066 // If force_swap is true, we must use a different SiteInstance. If we didn't, | 1084 SiteInstance* new_instance = |
1067 // we would have two RenderFrameHosts in the same SiteInstance and the same | 1085 ConvertToSiteInstance(new_instance_descriptor, candidate_instance); |
1068 // frame, resulting in page_id conflicts for their NavigationEntries. | 1086 |
1087 // If |force_swap| is true, we must use a different SiteInstance than the | |
1088 // current one. If we didn't, we would have two RenderFrameHosts in the same | |
1089 // SiteInstance and the same frame, resulting in page_id conflicts for their | |
1090 // NavigationEntries. | |
1069 if (force_swap) | 1091 if (force_swap) |
1070 CHECK_NE(new_instance, current_instance); | 1092 CHECK_NE(new_instance, current_instance); |
1071 return new_instance; | 1093 return new_instance; |
1072 } | 1094 } |
1073 | 1095 |
1074 SiteInstance* RenderFrameHostManager::GetSiteInstanceForURL( | 1096 RenderFrameHostManager::SiteInstanceDescriptor |
1097 RenderFrameHostManager::DetermineSiteInstanceForURL( | |
1075 const GURL& dest_url, | 1098 const GURL& dest_url, |
1076 SiteInstance* source_instance, | 1099 SiteInstance* source_instance, |
1077 SiteInstance* current_instance, | 1100 SiteInstance* current_instance, |
1078 SiteInstance* dest_instance, | 1101 SiteInstance* dest_instance, |
1079 ui::PageTransition transition, | 1102 ui::PageTransition transition, |
1080 bool dest_is_restore, | 1103 bool dest_is_restore, |
1081 bool dest_is_view_source_mode, | 1104 bool dest_is_view_source_mode, |
1082 bool force_browsing_instance_swap) { | 1105 bool force_browsing_instance_swap) { |
1106 SiteInstanceImpl* current_instance_impl = | |
1107 static_cast<SiteInstanceImpl*>(current_instance); | |
1083 NavigationControllerImpl& controller = | 1108 NavigationControllerImpl& controller = |
1084 delegate_->GetControllerForRenderManager(); | 1109 delegate_->GetControllerForRenderManager(); |
1085 BrowserContext* browser_context = controller.GetBrowserContext(); | 1110 BrowserContext* browser_context = controller.GetBrowserContext(); |
1086 | 1111 |
1087 // If the entry has an instance already we should use it. | 1112 // If the entry has an instance already we should use it. |
1088 if (dest_instance) { | 1113 if (dest_instance) { |
1089 // If we are forcing a swap, this should be in a different BrowsingInstance. | 1114 // If we are forcing a swap, this should be in a different BrowsingInstance. |
1090 if (force_browsing_instance_swap) { | 1115 if (force_browsing_instance_swap) { |
1091 CHECK(!dest_instance->IsRelatedSiteInstance( | 1116 CHECK(!dest_instance->IsRelatedSiteInstance( |
1092 render_frame_host_->GetSiteInstance())); | 1117 render_frame_host_->GetSiteInstance())); |
1093 } | 1118 } |
1094 return dest_instance; | 1119 return SiteInstanceDescriptor(dest_instance); |
1095 } | 1120 } |
1096 | 1121 |
1097 // If a swap is required, we need to force the SiteInstance AND | 1122 // If a swap is required, we need to force the SiteInstance AND |
1098 // BrowsingInstance to be different ones, using CreateForURL. | 1123 // BrowsingInstance to be different ones, using CreateForURL. |
1099 if (force_browsing_instance_swap) | 1124 if (force_browsing_instance_swap) |
1100 return SiteInstance::CreateForURL(browser_context, dest_url); | 1125 return SiteInstanceDescriptor(dest_url, false, browser_context); |
1101 | 1126 |
1102 // (UGLY) HEURISTIC, process-per-site only: | 1127 // (UGLY) HEURISTIC, process-per-site only: |
1103 // | 1128 // |
1104 // If this navigation is generated, then it probably corresponds to a search | 1129 // If this navigation is generated, then it probably corresponds to a search |
1105 // query. Given that search results typically lead to users navigating to | 1130 // 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 | 1131 // other sites, we don't really want to use the search engine hostname to |
1107 // determine the site instance for this navigation. | 1132 // determine the site instance for this navigation. |
1108 // | 1133 // |
1109 // NOTE: This can be removed once we have a way to transition between | 1134 // NOTE: This can be removed once we have a way to transition between |
1110 // RenderViews in response to a link click. | 1135 // RenderViews in response to a link click. |
1111 // | 1136 // |
1112 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1137 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
1113 switches::kProcessPerSite) && | 1138 switches::kProcessPerSite) && |
1114 ui::PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_GENERATED)) { | 1139 ui::PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_GENERATED)) { |
1115 return current_instance; | 1140 return SiteInstanceDescriptor(current_instance_impl); |
1116 } | 1141 } |
1117 | 1142 |
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 | 1143 // 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 | 1144 // for this entry. We won't commit the SiteInstance to this site until the |
1123 // navigation commits (in DidNavigate), unless the navigation entry was | 1145 // navigation commits (in DidNavigate), unless the navigation entry was |
1124 // restored or it's a Web UI as described below. | 1146 // restored or it's a Web UI as described below. |
1125 if (!current_site_instance->HasSite()) { | 1147 if (!current_instance_impl->HasSite()) { |
1126 // If we've already created a SiteInstance for our destination, we don't | 1148 // 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 | 1149 // 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 | 1150 // do this check if the current_instance has a site, because for now, we |
1129 // want to compare against the current URL and not the SiteInstance's site. | 1151 // want to compare against the current URL and not the SiteInstance's site. |
1130 // In this case, there is no current URL, so comparing against the site is | 1152 // In this case, there is no current URL, so comparing against the site is |
1131 // ok. See additional comments below.) | 1153 // ok. See additional comments below.) |
1132 // | 1154 // |
1133 // Also, if the URL should use process-per-site mode and there is an | 1155 // 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 | 1156 // existing process for the site, we should use it. We can call |
1135 // GetRelatedSiteInstance() for this, which will eagerly set the site and | 1157 // GetRelatedSiteInstance() for this, which will eagerly set the site and |
1136 // thus use the correct process. | 1158 // thus use the correct process. |
1137 bool use_process_per_site = | 1159 bool use_process_per_site = |
1138 RenderProcessHost::ShouldUseProcessPerSite(browser_context, dest_url) && | 1160 RenderProcessHost::ShouldUseProcessPerSite(browser_context, dest_url) && |
1139 RenderProcessHostImpl::GetProcessHostForSite(browser_context, dest_url); | 1161 RenderProcessHostImpl::GetProcessHostForSite(browser_context, dest_url); |
1140 if (current_site_instance->HasRelatedSiteInstance(dest_url) || | 1162 if (current_instance_impl->HasRelatedSiteInstance(dest_url) || |
1141 use_process_per_site) { | 1163 use_process_per_site) { |
1142 return current_site_instance->GetRelatedSiteInstance(dest_url); | 1164 return SiteInstanceDescriptor(dest_url, true, browser_context); |
1143 } | 1165 } |
1144 | 1166 |
1145 // For extensions, Web UI URLs (such as the new tab page), and apps we do | 1167 // 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 | 1168 // 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 | 1169 // will have a RenderProcessHost of PRIV_NORMAL. Create a new SiteInstance |
1148 // this URL instead (with the correct process type). | 1170 // for this URL instead (with the correct process type). |
1149 if (current_site_instance->HasWrongProcessForURL(dest_url)) | 1171 if (current_instance_impl->HasWrongProcessForURL(dest_url)) |
1150 return current_site_instance->GetRelatedSiteInstance(dest_url); | 1172 return SiteInstanceDescriptor(dest_url, true, browser_context); |
1151 | 1173 |
1152 // View-source URLs must use a new SiteInstance and BrowsingInstance. | 1174 // View-source URLs must use a new SiteInstance and BrowsingInstance. |
1153 // TODO(nasko): This is the same condition as later in the function. This | 1175 // 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 | 1176 // should be taken into account when refactoring this method as part of |
1155 // http://crbug.com/123007. | 1177 // http://crbug.com/123007. |
1156 if (dest_is_view_source_mode) | 1178 if (dest_is_view_source_mode) |
1157 return SiteInstance::CreateForURL(browser_context, dest_url); | 1179 return SiteInstanceDescriptor(dest_url, false, browser_context); |
1158 | 1180 |
1159 // If we are navigating from a blank SiteInstance to a WebUI, make sure we | 1181 // If we are navigating from a blank SiteInstance to a WebUI, make sure we |
1160 // create a new SiteInstance. | 1182 // create a new SiteInstance. |
1161 if (WebUIControllerFactoryRegistry::GetInstance()->UseWebUIForURL( | 1183 if (WebUIControllerFactoryRegistry::GetInstance()->UseWebUIForURL( |
1162 browser_context, dest_url)) { | 1184 browser_context, dest_url)) { |
1163 return SiteInstance::CreateForURL(browser_context, dest_url); | 1185 return SiteInstanceDescriptor(dest_url, false, browser_context); |
1164 } | 1186 } |
1165 | 1187 |
1166 // Normally the "site" on the SiteInstance is set lazily when the load | 1188 // Normally the "site" on the SiteInstance is set lazily when the load |
1167 // actually commits. This is to support better process sharing in case | 1189 // 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 | 1190 // the site redirects to some other site: we want to use the destination |
1169 // site in the site instance. | 1191 // site in the site instance. |
1170 // | 1192 // |
1171 // In the case of session restore, as it loads all the pages immediately | 1193 // 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 | 1194 // we need to set the site first, otherwise after a restore none of the |
1173 // pages would share renderers in process-per-site. | 1195 // pages would share renderers in process-per-site. |
1174 // | 1196 // |
1175 // The embedder can request some urls never to be assigned to SiteInstance | 1197 // The embedder can request some urls never to be assigned to SiteInstance |
1176 // through the ShouldAssignSiteForURL() content client method, so that | 1198 // through the ShouldAssignSiteForURL() content client method, so that |
1177 // renderers created for particular chrome urls (e.g. the chrome-native:// | 1199 // renderers created for particular chrome urls (e.g. the chrome-native:// |
1178 // scheme) can be reused for subsequent navigations in the same WebContents. | 1200 // scheme) can be reused for subsequent navigations in the same WebContents. |
1179 // See http://crbug.com/386542. | 1201 // See http://crbug.com/386542. |
1180 if (dest_is_restore && | 1202 if (dest_is_restore && |
1181 GetContentClient()->browser()->ShouldAssignSiteForURL(dest_url)) { | 1203 GetContentClient()->browser()->ShouldAssignSiteForURL(dest_url)) { |
1182 current_site_instance->SetSite(dest_url); | 1204 current_instance_impl->SetSite(dest_url); |
1183 } | 1205 } |
1184 | 1206 |
1185 return current_site_instance; | 1207 return SiteInstanceDescriptor(current_instance_impl); |
1186 } | 1208 } |
1187 | 1209 |
1188 // Otherwise, only create a new SiteInstance for a cross-site navigation. | 1210 // Otherwise, only create a new SiteInstance for a cross-site navigation. |
1189 | 1211 |
1190 // TODO(creis): Once we intercept links and script-based navigations, we | 1212 // 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 | 1213 // 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 | 1214 // the same site, and it will be safe to compare the URL against the |
1193 // SiteInstance's site, as follows: | 1215 // SiteInstance's site, as follows: |
1194 // const GURL& current_url = current_instance->site(); | 1216 // const GURL& current_url = current_instance_impl->site(); |
1195 // For now, though, we're in a hybrid model where you only switch | 1217 // 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 | 1218 // 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. | 1219 // compare the entry's URL to the last committed entry's URL. |
1198 NavigationEntry* current_entry = controller.GetLastCommittedEntry(); | 1220 NavigationEntry* current_entry = controller.GetLastCommittedEntry(); |
1199 if (interstitial_page_) { | 1221 if (interstitial_page_) { |
1200 // The interstitial is currently the last committed entry, but we want to | 1222 // The interstitial is currently the last committed entry, but we want to |
1201 // compare against the last non-interstitial entry. | 1223 // compare against the last non-interstitial entry. |
1202 current_entry = controller.GetEntryAtOffset(-1); | 1224 current_entry = controller.GetEntryAtOffset(-1); |
1203 } | 1225 } |
1204 | 1226 |
1205 // View-source URLs must use a new SiteInstance and BrowsingInstance. | 1227 // 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 | 1228 // We don't need a swap when going from view-source to a debug URL like |
1207 // chrome://crash, however. | 1229 // chrome://crash, however. |
1208 // TODO(creis): Refactor this method so this duplicated code isn't needed. | 1230 // TODO(creis): Refactor this method so this duplicated code isn't needed. |
1209 // See http://crbug.com/123007. | 1231 // See http://crbug.com/123007. |
1210 if (current_entry && | 1232 if (current_entry && |
1211 current_entry->IsViewSourceMode() != dest_is_view_source_mode && | 1233 current_entry->IsViewSourceMode() != dest_is_view_source_mode && |
1212 !IsRendererDebugURL(dest_url)) { | 1234 !IsRendererDebugURL(dest_url)) { |
1213 return SiteInstance::CreateForURL(browser_context, dest_url); | 1235 return SiteInstanceDescriptor(dest_url, false, browser_context); |
1214 } | 1236 } |
1215 | 1237 |
1216 // Use the source SiteInstance in case of data URLs or about:blank pages, | 1238 // 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 | 1239 // because the content is then controlled and/or scriptable by the source |
1218 // SiteInstance. | 1240 // SiteInstance. |
1219 GURL about_blank(url::kAboutBlankURL); | 1241 GURL about_blank(url::kAboutBlankURL); |
1220 if (source_instance && | 1242 if (source_instance && |
1221 (dest_url == about_blank || dest_url.scheme() == url::kDataScheme)) | 1243 (dest_url == about_blank || dest_url.scheme() == url::kDataScheme)) { |
1222 return source_instance; | 1244 return SiteInstanceDescriptor(source_instance); |
1245 } | |
1223 | 1246 |
1224 // Use the current SiteInstance for same site navigations, as long as the | 1247 // 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 | 1248 // process type is correct. (The URL may have been installed as an app since |
1226 // the last time we visited it.) | 1249 // the last time we visited it.) |
1227 const GURL& current_url = | 1250 const GURL& current_url = |
1228 GetCurrentURLForSiteInstance(current_instance, current_entry); | 1251 GetCurrentURLForSiteInstance(current_instance_impl, current_entry); |
1229 if (SiteInstance::IsSameWebSite(browser_context, current_url, dest_url) && | 1252 if (SiteInstance::IsSameWebSite(browser_context, current_url, dest_url) && |
1230 !current_site_instance->HasWrongProcessForURL(dest_url)) { | 1253 !current_instance_impl->HasWrongProcessForURL(dest_url)) { |
1231 return current_instance; | 1254 return SiteInstanceDescriptor(current_instance_impl); |
1232 } | 1255 } |
1233 | 1256 |
1234 // Start the new renderer in a new SiteInstance, but in the current | 1257 // Start the new renderer in a new SiteInstance, but in the current |
1235 // BrowsingInstance. It is important to immediately give this new | 1258 // BrowsingInstance. It is important to immediately give this new |
1236 // SiteInstance to a RenderViewHost (if it is different than our current | 1259 // SiteInstance to a RenderViewHost (if it is different than our current |
1237 // SiteInstance), so that it is ref counted. This will happen in | 1260 // SiteInstance), so that it is ref counted. This will happen in |
1238 // CreateRenderView. | 1261 // CreateRenderView. |
1239 return current_instance->GetRelatedSiteInstance(dest_url); | 1262 return SiteInstanceDescriptor(dest_url, true, browser_context); |
1263 } | |
1264 | |
1265 SiteInstance* RenderFrameHostManager::ConvertToSiteInstance( | |
1266 const SiteInstanceDescriptor& descriptor, | |
1267 SiteInstance* candidate_instance) { | |
1268 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); | |
1269 | |
1270 // Note: If the |candidate_instance| matches the descriptor, it will already | |
1271 // be set to |descriptor.existing_site_instance|. | |
1272 if (descriptor.existing_site_instance) | |
1273 return descriptor.existing_site_instance; | |
1274 | |
1275 // Note: If the |candidate_instance| matches the descriptor, | |
1276 // GetRelatedSiteInstance will return it. | |
1277 if (descriptor.new_is_related_to_current) | |
1278 return current_instance->GetRelatedSiteInstance(descriptor.new_site_url); | |
1279 | |
1280 if (candidate_instance && | |
Charlie Reis
2015/04/02 21:23:25
nit: Add a comment saying that at this point, we n
carlosk
2015/04/03 16:11:19
Done.
| |
1281 !current_instance->IsRelatedSiteInstance(candidate_instance) && | |
1282 candidate_instance->GetSiteURL() == descriptor.new_site_url) { | |
1283 return candidate_instance; | |
1284 } | |
1285 | |
1286 return SiteInstance::CreateForURL( | |
1287 delegate_->GetControllerForRenderManager().GetBrowserContext(), | |
1288 descriptor.new_site_url); | |
1240 } | 1289 } |
1241 | 1290 |
1242 const GURL& RenderFrameHostManager::GetCurrentURLForSiteInstance( | 1291 const GURL& RenderFrameHostManager::GetCurrentURLForSiteInstance( |
1243 SiteInstance* current_instance, NavigationEntry* current_entry) { | 1292 SiteInstance* current_instance, NavigationEntry* current_entry) { |
1244 // If this is a subframe that is potentially out of process from its parent, | 1293 // 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 | 1294 // 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 | 1295 // current_entry's url is for the main frame and may be in a different site |
1247 // than this frame. | 1296 // than this frame. |
1248 // TODO(creis): Remove this when we can check the FrameNavigationEntry's url. | 1297 // TODO(creis): Remove this when we can check the FrameNavigationEntry's url. |
1249 // See http://crbug.com/369654 | 1298 // 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 | 1843 // If we are currently navigating cross-process, we want to get back to normal |
1795 // and then navigate as usual. | 1844 // and then navigate as usual. |
1796 if (cross_navigation_pending_) { | 1845 if (cross_navigation_pending_) { |
1797 if (pending_render_frame_host_) | 1846 if (pending_render_frame_host_) |
1798 CancelPending(); | 1847 CancelPending(); |
1799 cross_navigation_pending_ = false; | 1848 cross_navigation_pending_ = false; |
1800 } | 1849 } |
1801 | 1850 |
1802 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); | 1851 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); |
1803 scoped_refptr<SiteInstance> new_instance = GetSiteInstanceForNavigation( | 1852 scoped_refptr<SiteInstance> new_instance = GetSiteInstanceForNavigation( |
1804 dest_url, source_instance, dest_instance, transition, | 1853 dest_url, source_instance, dest_instance, nullptr, transition, |
1805 dest_is_restore, dest_is_view_source_mode); | 1854 dest_is_restore, dest_is_view_source_mode); |
1806 | 1855 |
1807 const NavigationEntry* current_entry = | 1856 const NavigationEntry* current_entry = |
1808 delegate_->GetLastCommittedNavigationEntryForRenderManager(); | 1857 delegate_->GetLastCommittedNavigationEntryForRenderManager(); |
1809 | 1858 |
1810 DCHECK(!cross_navigation_pending_); | 1859 DCHECK(!cross_navigation_pending_); |
1811 | 1860 |
1812 if (new_instance.get() != current_instance) { | 1861 if (new_instance.get() != current_instance) { |
1813 TRACE_EVENT_INSTANT2( | 1862 TRACE_EVENT_INSTANT2( |
1814 "navigation", | 1863 "navigation", |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2019 void RenderFrameHostManager::DeleteRenderFrameProxyHost( | 2068 void RenderFrameHostManager::DeleteRenderFrameProxyHost( |
2020 SiteInstance* instance) { | 2069 SiteInstance* instance) { |
2021 RenderFrameProxyHostMap::iterator iter = proxy_hosts_.find(instance->GetId()); | 2070 RenderFrameProxyHostMap::iterator iter = proxy_hosts_.find(instance->GetId()); |
2022 if (iter != proxy_hosts_.end()) { | 2071 if (iter != proxy_hosts_.end()) { |
2023 delete iter->second; | 2072 delete iter->second; |
2024 proxy_hosts_.erase(iter); | 2073 proxy_hosts_.erase(iter); |
2025 } | 2074 } |
2026 } | 2075 } |
2027 | 2076 |
2028 } // namespace content | 2077 } // namespace content |
OLD | NEW |