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