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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 981 for (const auto& pair : proxy_hosts_) { | 981 for (const auto& pair : proxy_hosts_) { |
| 982 pair.second->Send( | 982 pair.second->Send( |
| 983 new FrameMsg_DidUpdateOrigin(pair.second->GetRoutingID(), origin, | 983 new FrameMsg_DidUpdateOrigin(pair.second->GetRoutingID(), origin, |
| 984 is_potentially_trustworthy_unique_origin)); | 984 is_potentially_trustworthy_unique_origin)); |
| 985 } | 985 } |
| 986 } | 986 } |
| 987 | 987 |
| 988 RenderFrameHostManager::SiteInstanceDescriptor::SiteInstanceDescriptor( | 988 RenderFrameHostManager::SiteInstanceDescriptor::SiteInstanceDescriptor( |
| 989 BrowserContext* browser_context, | 989 BrowserContext* browser_context, |
| 990 GURL dest_url, | 990 GURL dest_url, |
| 991 bool related_to_current) | 991 SiteInstanceRelation relation_to_current) |
| 992 : existing_site_instance(nullptr), | 992 : existing_site_instance(nullptr), relation(relation_to_current) { |
| 993 new_is_related_to_current(related_to_current) { | |
| 994 new_site_url = SiteInstance::GetSiteForURL(browser_context, dest_url); | 993 new_site_url = SiteInstance::GetSiteForURL(browser_context, dest_url); |
| 995 } | 994 } |
| 996 | 995 |
| 997 void RenderFrameHostManager::RenderProcessGone(SiteInstanceImpl* instance) { | 996 void RenderFrameHostManager::RenderProcessGone(SiteInstanceImpl* instance) { |
| 998 GetRenderFrameProxyHost(instance)->set_render_frame_proxy_created(false); | 997 GetRenderFrameProxyHost(instance)->set_render_frame_proxy_created(false); |
| 999 } | 998 } |
| 1000 | 999 |
| 1001 void RenderFrameHostManager::ActiveFrameCountIsZero( | 1000 void RenderFrameHostManager::ActiveFrameCountIsZero( |
| 1002 SiteInstanceImpl* site_instance) { | 1001 SiteInstanceImpl* site_instance) { |
| 1003 // |site_instance| no longer contains any active RenderFrameHosts, so we don't | 1002 // |site_instance| no longer contains any active RenderFrameHosts, so we don't |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1168 SiteInstanceDescriptor new_instance_descriptor = | 1167 SiteInstanceDescriptor new_instance_descriptor = |
| 1169 SiteInstanceDescriptor(current_instance); | 1168 SiteInstanceDescriptor(current_instance); |
| 1170 if (ShouldTransitionCrossSite() || force_swap) { | 1169 if (ShouldTransitionCrossSite() || force_swap) { |
| 1171 new_instance_descriptor = DetermineSiteInstanceForURL( | 1170 new_instance_descriptor = DetermineSiteInstanceForURL( |
| 1172 dest_url, source_instance, current_instance, dest_instance, transition, | 1171 dest_url, source_instance, current_instance, dest_instance, transition, |
| 1173 dest_is_restore, dest_is_view_source_mode, force_swap); | 1172 dest_is_restore, dest_is_view_source_mode, force_swap); |
| 1174 } | 1173 } |
| 1175 | 1174 |
| 1176 SiteInstance* new_instance = | 1175 SiteInstance* new_instance = |
| 1177 ConvertToSiteInstance(new_instance_descriptor, candidate_instance); | 1176 ConvertToSiteInstance(new_instance_descriptor, candidate_instance); |
| 1178 | |
| 1179 // If |force_swap| is true, we must use a different SiteInstance than the | 1177 // If |force_swap| is true, we must use a different SiteInstance than the |
| 1180 // current one. If we didn't, we would have two RenderFrameHosts in the same | 1178 // current one. If we didn't, we would have two RenderFrameHosts in the same |
| 1181 // SiteInstance and the same frame, resulting in page_id conflicts for their | 1179 // SiteInstance and the same frame, resulting in page_id conflicts for their |
| 1182 // NavigationEntries. | 1180 // NavigationEntries. |
| 1183 if (force_swap) | 1181 if (force_swap) |
| 1184 CHECK_NE(new_instance, current_instance); | 1182 CHECK_NE(new_instance, current_instance); |
| 1183 | |
| 1184 // |new_instance| may be a newly allocated SiteInstance. It is important to | |
| 1185 // immediately give this new SiteInstance to a RenderViewHost (if it is | |
| 1186 // different than our current SiteInstance), so that it is ref counted. | |
|
dcheng
2016/03/29 08:09:16
Perhaps this function should just return a scoped_
ncarter (slow)
2016/03/29 16:28:33
I agree, though obviously it doesn't belong in thi
dcheng
2016/03/29 17:06:59
scoped_refptr is already movable, so I think we ca
ncarter (slow)
2016/03/29 23:30:57
Acknowledged.
| |
| 1185 return new_instance; | 1187 return new_instance; |
| 1186 } | 1188 } |
| 1187 | 1189 |
| 1188 RenderFrameHostManager::SiteInstanceDescriptor | 1190 RenderFrameHostManager::SiteInstanceDescriptor |
| 1189 RenderFrameHostManager::DetermineSiteInstanceForURL( | 1191 RenderFrameHostManager::DetermineSiteInstanceForURL( |
| 1190 const GURL& dest_url, | 1192 const GURL& dest_url, |
| 1191 SiteInstance* source_instance, | 1193 SiteInstance* source_instance, |
| 1192 SiteInstance* current_instance, | 1194 SiteInstance* current_instance, |
| 1193 SiteInstance* dest_instance, | 1195 SiteInstance* dest_instance, |
| 1194 ui::PageTransition transition, | 1196 ui::PageTransition transition, |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1207 if (force_browsing_instance_swap) { | 1209 if (force_browsing_instance_swap) { |
| 1208 CHECK(!dest_instance->IsRelatedSiteInstance( | 1210 CHECK(!dest_instance->IsRelatedSiteInstance( |
| 1209 render_frame_host_->GetSiteInstance())); | 1211 render_frame_host_->GetSiteInstance())); |
| 1210 } | 1212 } |
| 1211 return SiteInstanceDescriptor(dest_instance); | 1213 return SiteInstanceDescriptor(dest_instance); |
| 1212 } | 1214 } |
| 1213 | 1215 |
| 1214 // If a swap is required, we need to force the SiteInstance AND | 1216 // If a swap is required, we need to force the SiteInstance AND |
| 1215 // BrowsingInstance to be different ones, using CreateForURL. | 1217 // BrowsingInstance to be different ones, using CreateForURL. |
| 1216 if (force_browsing_instance_swap) | 1218 if (force_browsing_instance_swap) |
| 1217 return SiteInstanceDescriptor(browser_context, dest_url, false); | 1219 return SiteInstanceDescriptor(browser_context, dest_url, |
| 1220 SiteInstanceRelation::UNRELATED); | |
| 1218 | 1221 |
| 1219 // (UGLY) HEURISTIC, process-per-site only: | 1222 // (UGLY) HEURISTIC, process-per-site only: |
| 1220 // | 1223 // |
| 1221 // If this navigation is generated, then it probably corresponds to a search | 1224 // If this navigation is generated, then it probably corresponds to a search |
| 1222 // query. Given that search results typically lead to users navigating to | 1225 // query. Given that search results typically lead to users navigating to |
| 1223 // other sites, we don't really want to use the search engine hostname to | 1226 // other sites, we don't really want to use the search engine hostname to |
| 1224 // determine the site instance for this navigation. | 1227 // determine the site instance for this navigation. |
| 1225 // | 1228 // |
| 1226 // NOTE: This can be removed once we have a way to transition between | 1229 // NOTE: This can be removed once we have a way to transition between |
| 1227 // RenderViews in response to a link click. | 1230 // RenderViews in response to a link click. |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1246 // | 1249 // |
| 1247 // Also, if the URL should use process-per-site mode and there is an | 1250 // Also, if the URL should use process-per-site mode and there is an |
| 1248 // existing process for the site, we should use it. We can call | 1251 // existing process for the site, we should use it. We can call |
| 1249 // GetRelatedSiteInstance() for this, which will eagerly set the site and | 1252 // GetRelatedSiteInstance() for this, which will eagerly set the site and |
| 1250 // thus use the correct process. | 1253 // thus use the correct process. |
| 1251 bool use_process_per_site = | 1254 bool use_process_per_site = |
| 1252 RenderProcessHost::ShouldUseProcessPerSite(browser_context, dest_url) && | 1255 RenderProcessHost::ShouldUseProcessPerSite(browser_context, dest_url) && |
| 1253 RenderProcessHostImpl::GetProcessHostForSite(browser_context, dest_url); | 1256 RenderProcessHostImpl::GetProcessHostForSite(browser_context, dest_url); |
| 1254 if (current_instance_impl->HasRelatedSiteInstance(dest_url) || | 1257 if (current_instance_impl->HasRelatedSiteInstance(dest_url) || |
| 1255 use_process_per_site) { | 1258 use_process_per_site) { |
| 1256 return SiteInstanceDescriptor(browser_context, dest_url, true); | 1259 return SiteInstanceDescriptor(browser_context, dest_url, |
| 1260 SiteInstanceRelation::RELATED); | |
| 1257 } | 1261 } |
| 1258 | 1262 |
| 1259 // For extensions, Web UI URLs (such as the new tab page), and apps we do | 1263 // For extensions, Web UI URLs (such as the new tab page), and apps we do |
| 1260 // not want to use the |current_instance_impl| if it has no site, since it | 1264 // not want to use the |current_instance_impl| if it has no site, since it |
| 1261 // will have a RenderProcessHost of PRIV_NORMAL. Create a new SiteInstance | 1265 // will have a RenderProcessHost of PRIV_NORMAL. Create a new SiteInstance |
| 1262 // for this URL instead (with the correct process type). | 1266 // for this URL instead (with the correct process type). |
| 1263 if (current_instance_impl->HasWrongProcessForURL(dest_url)) | 1267 if (current_instance_impl->HasWrongProcessForURL(dest_url)) |
| 1264 return SiteInstanceDescriptor(browser_context, dest_url, true); | 1268 return SiteInstanceDescriptor(browser_context, dest_url, |
| 1269 SiteInstanceRelation::RELATED); | |
| 1265 | 1270 |
| 1266 // View-source URLs must use a new SiteInstance and BrowsingInstance. | 1271 // View-source URLs must use a new SiteInstance and BrowsingInstance. |
| 1267 // TODO(nasko): This is the same condition as later in the function. This | 1272 // TODO(nasko): This is the same condition as later in the function. This |
| 1268 // should be taken into account when refactoring this method as part of | 1273 // should be taken into account when refactoring this method as part of |
| 1269 // http://crbug.com/123007. | 1274 // http://crbug.com/123007. |
| 1270 if (dest_is_view_source_mode) | 1275 if (dest_is_view_source_mode) |
| 1271 return SiteInstanceDescriptor(browser_context, dest_url, false); | 1276 return SiteInstanceDescriptor(browser_context, dest_url, |
| 1277 SiteInstanceRelation::UNRELATED); | |
| 1272 | 1278 |
| 1273 // If we are navigating from a blank SiteInstance to a WebUI, make sure we | 1279 // If we are navigating from a blank SiteInstance to a WebUI, make sure we |
| 1274 // create a new SiteInstance. | 1280 // create a new SiteInstance. |
| 1275 if (WebUIControllerFactoryRegistry::GetInstance()->UseWebUIForURL( | 1281 if (WebUIControllerFactoryRegistry::GetInstance()->UseWebUIForURL( |
| 1276 browser_context, dest_url)) { | 1282 browser_context, dest_url)) { |
| 1277 return SiteInstanceDescriptor(browser_context, dest_url, false); | 1283 return SiteInstanceDescriptor(browser_context, dest_url, |
| 1284 SiteInstanceRelation::UNRELATED); | |
| 1278 } | 1285 } |
| 1279 | 1286 |
| 1280 // Normally the "site" on the SiteInstance is set lazily when the load | 1287 // Normally the "site" on the SiteInstance is set lazily when the load |
| 1281 // actually commits. This is to support better process sharing in case | 1288 // actually commits. This is to support better process sharing in case |
| 1282 // the site redirects to some other site: we want to use the destination | 1289 // the site redirects to some other site: we want to use the destination |
| 1283 // site in the site instance. | 1290 // site in the site instance. |
| 1284 // | 1291 // |
| 1285 // In the case of session restore, as it loads all the pages immediately | 1292 // In the case of session restore, as it loads all the pages immediately |
| 1286 // we need to set the site first, otherwise after a restore none of the | 1293 // we need to set the site first, otherwise after a restore none of the |
| 1287 // pages would share renderers in process-per-site. | 1294 // pages would share renderers in process-per-site. |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 1317 } | 1324 } |
| 1318 | 1325 |
| 1319 // View-source URLs must use a new SiteInstance and BrowsingInstance. | 1326 // View-source URLs must use a new SiteInstance and BrowsingInstance. |
| 1320 // We don't need a swap when going from view-source to a debug URL like | 1327 // We don't need a swap when going from view-source to a debug URL like |
| 1321 // chrome://crash, however. | 1328 // chrome://crash, however. |
| 1322 // TODO(creis): Refactor this method so this duplicated code isn't needed. | 1329 // TODO(creis): Refactor this method so this duplicated code isn't needed. |
| 1323 // See http://crbug.com/123007. | 1330 // See http://crbug.com/123007. |
| 1324 if (current_entry && | 1331 if (current_entry && |
| 1325 current_entry->IsViewSourceMode() != dest_is_view_source_mode && | 1332 current_entry->IsViewSourceMode() != dest_is_view_source_mode && |
| 1326 !IsRendererDebugURL(dest_url)) { | 1333 !IsRendererDebugURL(dest_url)) { |
| 1327 return SiteInstanceDescriptor(browser_context, dest_url, false); | 1334 return SiteInstanceDescriptor(browser_context, dest_url, |
| 1335 SiteInstanceRelation::UNRELATED); | |
| 1328 } | 1336 } |
| 1329 | 1337 |
| 1330 // Use the source SiteInstance in case of data URLs or about:blank pages, | 1338 // Use the source SiteInstance in case of data URLs or about:blank pages, |
| 1331 // because the content is then controlled and/or scriptable by the source | 1339 // because the content is then controlled and/or scriptable by the source |
| 1332 // SiteInstance. | 1340 // SiteInstance. |
| 1333 GURL about_blank(url::kAboutBlankURL); | 1341 GURL about_blank(url::kAboutBlankURL); |
| 1334 if (source_instance && | 1342 if (source_instance && |
| 1335 (dest_url == about_blank || dest_url.scheme() == url::kDataScheme)) { | 1343 (dest_url == about_blank || dest_url.scheme() == url::kDataScheme)) { |
| 1336 return SiteInstanceDescriptor(source_instance); | 1344 return SiteInstanceDescriptor(source_instance); |
| 1337 } | 1345 } |
| 1338 | 1346 |
| 1339 // Use the current SiteInstance for same site navigations, as long as the | 1347 // Use the current SiteInstance for same site navigations. |
| 1340 // process type is correct. (The URL may have been installed as an app since | 1348 if (IsCurrentlySameSite(render_frame_host_.get(), dest_url)) |
| 1341 // the last time we visited it.) | 1349 return SiteInstanceDescriptor(render_frame_host_->GetSiteInstance()); |
| 1342 const GURL& current_url = GetCurrentURLForSiteInstance(current_instance_impl); | 1350 |
| 1343 if (SiteInstance::IsSameWebSite(browser_context, current_url, dest_url) && | 1351 if (SiteIsolationPolicy::IsTopDocumentIsolationEnabled()) { |
| 1344 !current_instance_impl->HasWrongProcessForURL(dest_url)) { | 1352 // TODO(nick): Looking at the main frame and openers is required for TDI |
| 1345 return SiteInstanceDescriptor(current_instance_impl); | 1353 // mode, but should be safe to enable unconditionally. |
| 1354 if (!frame_tree_node_->IsMainFrame()) { | |
| 1355 RenderFrameHostImpl* main_frame = | |
| 1356 frame_tree_node_->frame_tree()->root()->current_frame_host(); | |
| 1357 if (IsCurrentlySameSite(main_frame, dest_url)) | |
| 1358 return SiteInstanceDescriptor(main_frame->GetSiteInstance()); | |
| 1359 } | |
| 1360 | |
| 1361 if (frame_tree_node_->opener()) { | |
| 1362 RenderFrameHostImpl* opener_frame = | |
| 1363 frame_tree_node_->opener()->current_frame_host(); | |
| 1364 if (IsCurrentlySameSite(opener_frame, dest_url)) | |
| 1365 return SiteInstanceDescriptor(opener_frame->GetSiteInstance()); | |
| 1366 } | |
| 1367 } | |
| 1368 | |
| 1369 if (!frame_tree_node_->IsMainFrame() && | |
| 1370 SiteIsolationPolicy::IsTopDocumentIsolationEnabled() && | |
| 1371 !SiteInstanceImpl::DoesSiteRequireDedicatedProcess(browser_context, | |
| 1372 dest_url)) { | |
| 1373 // This is a cross-site subframe of a non-isolated origin, so place this | |
| 1374 // frame in the default subframe site instance. | |
| 1375 return SiteInstanceDescriptor( | |
| 1376 browser_context, dest_url, | |
| 1377 SiteInstanceRelation::RELATED_DEFAULT_SUBFRAME); | |
| 1346 } | 1378 } |
| 1347 | 1379 |
| 1348 // Start the new renderer in a new SiteInstance, but in the current | 1380 // Start the new renderer in a new SiteInstance, but in the current |
| 1349 // BrowsingInstance. It is important to immediately give this new | 1381 // BrowsingInstance. |
| 1350 // SiteInstance to a RenderViewHost (if it is different than our current | 1382 return SiteInstanceDescriptor(browser_context, dest_url, |
| 1351 // SiteInstance), so that it is ref counted. This will happen in | 1383 SiteInstanceRelation::RELATED); |
| 1352 // CreateRenderView. | |
| 1353 return SiteInstanceDescriptor(browser_context, dest_url, true); | |
| 1354 } | 1384 } |
| 1355 | 1385 |
| 1356 bool RenderFrameHostManager::IsRendererTransferNeededForNavigation( | 1386 bool RenderFrameHostManager::IsRendererTransferNeededForNavigation( |
| 1357 RenderFrameHostImpl* rfh, | 1387 RenderFrameHostImpl* rfh, |
| 1358 const GURL& dest_url) { | 1388 const GURL& dest_url) { |
| 1359 // A transfer is not needed if the current SiteInstance doesn't yet have a | 1389 // A transfer is not needed if the current SiteInstance doesn't yet have a |
| 1360 // site. This is the case for tests that use NavigateToURL. | 1390 // site. This is the case for tests that use NavigateToURL. |
| 1361 if (!rfh->GetSiteInstance()->HasSite()) | 1391 if (!rfh->GetSiteInstance()->HasSite()) |
| 1362 return false; | 1392 return false; |
| 1363 | 1393 |
| 1364 // We do not currently swap processes for navigations in webview tag guests. | 1394 // We do not currently swap processes for navigations in webview tag guests. |
| 1365 if (rfh->GetSiteInstance()->GetSiteURL().SchemeIs(kGuestScheme)) | 1395 if (rfh->GetSiteInstance()->GetSiteURL().SchemeIs(kGuestScheme)) |
| 1366 return false; | 1396 return false; |
| 1367 | 1397 |
| 1368 // Don't swap processes for extensions embedded in DevTools. See | 1398 // Don't swap processes for extensions embedded in DevTools. See |
| 1369 // https://crbug.com/564216. | 1399 // https://crbug.com/564216. |
| 1370 if (rfh->GetSiteInstance()->GetSiteURL().SchemeIs(kChromeDevToolsScheme)) { | 1400 if (rfh->GetSiteInstance()->GetSiteURL().SchemeIs(kChromeDevToolsScheme)) { |
| 1371 // TODO(nick): https://crbug.com/570483 Check to see if |dest_url| is a | 1401 // TODO(nick): https://crbug.com/570483 Check to see if |dest_url| is a |
| 1372 // devtools extension, and swap processes if not. | 1402 // devtools extension, and swap processes if not. |
| 1373 return false; | 1403 return false; |
| 1374 } | 1404 } |
| 1375 | 1405 |
| 1376 BrowserContext* context = rfh->GetSiteInstance()->GetBrowserContext(); | 1406 BrowserContext* context = rfh->GetSiteInstance()->GetBrowserContext(); |
| 1377 GURL effective_url = SiteInstanceImpl::GetEffectiveURL(context, dest_url); | 1407 GURL effective_url = SiteInstanceImpl::GetEffectiveURL(context, dest_url); |
| 1378 | 1408 |
| 1379 // TODO(nasko, nick): These following --site-per-process checks are | 1409 // TODO(nasko, nick): These following --site-per-process checks are |
| 1380 // overly simplistic. Update them to match all the cases | 1410 // overly simplistic. Update them to match all the cases |
| 1381 // considered by DetermineSiteInstanceForURL. | 1411 // considered by DetermineSiteInstanceForURL. |
| 1382 if (SiteInstance::IsSameWebSite(rfh->GetSiteInstance()->GetBrowserContext(), | 1412 if (IsCurrentlySameSite(rfh, dest_url)) { |
| 1383 rfh->GetSiteInstance()->GetSiteURL(), | 1413 // The same site, no transition needed for security purposes, and we must |
| 1384 dest_url)) { | 1414 // keep the same SiteInstance for correctness of synchronous scripting. |
| 1385 return false; // The same site, no transition needed. | 1415 return false; |
| 1386 } | 1416 } |
| 1387 | 1417 |
| 1388 // The sites differ. If either one requires a dedicated process, | 1418 // The sites differ. If either one requires a dedicated process, |
| 1389 // then a transfer is needed. | 1419 // then a transfer is needed. |
| 1390 return rfh->GetSiteInstance()->RequiresDedicatedProcess() || | 1420 if (rfh->GetSiteInstance()->RequiresDedicatedProcess() || |
| 1391 SiteInstanceImpl::DoesSiteRequireDedicatedProcess(context, | 1421 SiteInstanceImpl::DoesSiteRequireDedicatedProcess(context, |
| 1392 effective_url); | 1422 effective_url)) { |
| 1423 return true; | |
| 1424 } | |
| 1425 | |
| 1426 if (SiteIsolationPolicy::IsTopDocumentIsolationEnabled() && | |
| 1427 (!frame_tree_node_->IsMainFrame() || | |
| 1428 rfh->GetSiteInstance()->is_default_subframe_site_instance())) { | |
| 1429 // Always attempt a transfer in these cases. | |
| 1430 return true; | |
| 1431 } | |
| 1432 | |
| 1433 return false; | |
| 1393 } | 1434 } |
| 1394 | 1435 |
| 1395 SiteInstance* RenderFrameHostManager::ConvertToSiteInstance( | 1436 SiteInstance* RenderFrameHostManager::ConvertToSiteInstance( |
| 1396 const SiteInstanceDescriptor& descriptor, | 1437 const SiteInstanceDescriptor& descriptor, |
| 1397 SiteInstance* candidate_instance) { | 1438 SiteInstance* candidate_instance) { |
| 1398 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); | 1439 SiteInstanceImpl* current_instance = render_frame_host_->GetSiteInstance(); |
| 1399 | 1440 |
| 1400 // Note: If the |candidate_instance| matches the descriptor, it will already | 1441 // Note: If the |candidate_instance| matches the descriptor, it will already |
| 1401 // be set to |descriptor.existing_site_instance|. | 1442 // be set to |descriptor.existing_site_instance|. |
| 1402 if (descriptor.existing_site_instance) | 1443 if (descriptor.existing_site_instance) |
| 1403 return descriptor.existing_site_instance; | 1444 return descriptor.existing_site_instance; |
| 1404 | 1445 |
| 1405 // Note: If the |candidate_instance| matches the descriptor, | 1446 // Note: If the |candidate_instance| matches the descriptor, |
| 1406 // GetRelatedSiteInstance will return it. | 1447 // GetRelatedSiteInstance will return it. |
| 1407 if (descriptor.new_is_related_to_current) | 1448 if (descriptor.relation == SiteInstanceRelation::RELATED) |
| 1408 return current_instance->GetRelatedSiteInstance(descriptor.new_site_url); | 1449 return current_instance->GetRelatedSiteInstance(descriptor.new_site_url); |
| 1409 | 1450 |
| 1451 if (descriptor.relation == SiteInstanceRelation::RELATED_DEFAULT_SUBFRAME) | |
| 1452 return current_instance->GetDefaultSubframeSiteInstance(); | |
| 1453 | |
| 1410 // At this point we know an unrelated site instance must be returned. First | 1454 // At this point we know an unrelated site instance must be returned. First |
| 1411 // check if the candidate matches. | 1455 // check if the candidate matches. |
| 1412 if (candidate_instance && | 1456 if (candidate_instance && |
| 1413 !current_instance->IsRelatedSiteInstance(candidate_instance) && | 1457 !current_instance->IsRelatedSiteInstance(candidate_instance) && |
| 1414 candidate_instance->GetSiteURL() == descriptor.new_site_url) { | 1458 candidate_instance->GetSiteURL() == descriptor.new_site_url) { |
| 1415 return candidate_instance; | 1459 return candidate_instance; |
| 1416 } | 1460 } |
| 1417 | 1461 |
| 1418 // Otherwise return a newly created one. | 1462 // Otherwise return a newly created one. |
| 1419 return SiteInstance::CreateForURL( | 1463 return SiteInstance::CreateForURL( |
| 1420 delegate_->GetControllerForRenderManager().GetBrowserContext(), | 1464 delegate_->GetControllerForRenderManager().GetBrowserContext(), |
| 1421 descriptor.new_site_url); | 1465 descriptor.new_site_url); |
| 1422 } | 1466 } |
| 1423 | 1467 |
| 1424 const GURL& RenderFrameHostManager::GetCurrentURLForSiteInstance( | 1468 bool RenderFrameHostManager::IsCurrentlySameSite(RenderFrameHostImpl* candidate, |
| 1425 SiteInstance* current_instance) { | 1469 const GURL& dest_url) { |
| 1426 // Use the current RenderFrameHost's last successful URL if it has one. This | 1470 BrowserContext* browser_context = |
| 1427 // excludes commits of net errors, since net errors do not currently swap | 1471 delegate_->GetControllerForRenderManager().GetBrowserContext(); |
| 1428 // processes for transfer navigations. Thus, we compare against the last | |
| 1429 // successful commit when deciding whether to swap this time. | |
| 1430 // (Note: browser-initiated net errors do swap processes, but the frame's last | |
| 1431 // successful URL will be empty in that case, causing us to fall back to the | |
| 1432 // SiteInstance's URL below.) | |
| 1433 if (!render_frame_host_->last_successful_url().is_empty()) | |
| 1434 return render_frame_host_->last_successful_url(); | |
| 1435 | 1472 |
| 1436 // Fall back to the SiteInstance's Site URL if the FrameTreeNode doen't have a | 1473 // If the process type is incorrect, reject the candidate even if |dest_url| |
| 1437 // current URL. | 1474 // is same-site. (The URL may have been installed as an app since |
| 1438 return current_instance->GetSiteURL(); | 1475 // the last time we visited it.) |
| 1476 if (candidate->GetSiteInstance()->HasWrongProcessForURL(dest_url)) | |
| 1477 return false; | |
| 1478 | |
| 1479 // If we don't have a last successful URL, we can't trust the origin or URL | |
| 1480 // stored on the frame, so we fall back to GetSiteURL(). This case occurs | |
| 1481 // after commits of net errors, since net errors do not currently swap | |
| 1482 // processes for transfer navigations. Note: browser-initiated net errors do | |
| 1483 // swap processes, but the frame's last successful URL will still be empty in | |
| 1484 // that case. | |
| 1485 if (candidate->last_successful_url().is_empty()) { | |
| 1486 // TODO(creis): GetSiteURL() is not 100% accurate. Eliminate this fallback. | |
| 1487 return SiteInstance::IsSameWebSite( | |
| 1488 browser_context, candidate->GetSiteInstance()->GetSiteURL(), dest_url); | |
| 1489 } | |
| 1490 | |
| 1491 // In the common case, we use the RenderFrameHost's last successful URL. Thus, | |
| 1492 // we compare against the last successful commit when deciding whether to swap | |
| 1493 // this time. | |
| 1494 if (SiteInstance::IsSameWebSite(browser_context, | |
| 1495 candidate->last_successful_url(), dest_url)) { | |
| 1496 return true; | |
| 1497 } | |
| 1498 | |
| 1499 // It is possible that last_successful_url() was a nonstandard scheme (for | |
| 1500 // example, "about:blank"). If so, examine the replicated origin to determine | |
| 1501 // the site. | |
| 1502 if (!candidate->GetLastCommittedOrigin().unique() && | |
| 1503 SiteInstance::IsSameWebSite( | |
| 1504 browser_context, | |
| 1505 GURL(candidate->GetLastCommittedOrigin().Serialize()), dest_url)) { | |
| 1506 return true; | |
| 1507 } | |
| 1508 | |
| 1509 // Not same-site. | |
| 1510 return false; | |
| 1439 } | 1511 } |
| 1440 | 1512 |
| 1441 void RenderFrameHostManager::CreatePendingRenderFrameHost( | 1513 void RenderFrameHostManager::CreatePendingRenderFrameHost( |
| 1442 SiteInstance* old_instance, | 1514 SiteInstance* old_instance, |
| 1443 SiteInstance* new_instance) { | 1515 SiteInstance* new_instance) { |
| 1444 if (pending_render_frame_host_) | 1516 if (pending_render_frame_host_) |
| 1445 CancelPending(); | 1517 CancelPending(); |
| 1446 | 1518 |
| 1447 // The process for the new SiteInstance may (if we're sharing a process with | 1519 // The process for the new SiteInstance may (if we're sharing a process with |
| 1448 // another host that already initialized it) or may not (we have our own | 1520 // another host that already initialized it) or may not (we have our own |
| (...skipping 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2451 } else if (pending_render_frame_host_) { | 2523 } else if (pending_render_frame_host_) { |
| 2452 send_msg(pending_render_frame_host_.get(), | 2524 send_msg(pending_render_frame_host_.get(), |
| 2453 pending_render_frame_host_->GetRoutingID(), msg); | 2525 pending_render_frame_host_->GetRoutingID(), msg); |
| 2454 } | 2526 } |
| 2455 | 2527 |
| 2456 msg->set_routing_id(render_frame_host_->GetRoutingID()); | 2528 msg->set_routing_id(render_frame_host_->GetRoutingID()); |
| 2457 render_frame_host_->Send(msg); | 2529 render_frame_host_->Send(msg); |
| 2458 } | 2530 } |
| 2459 | 2531 |
| 2460 } // namespace content | 2532 } // namespace content |
| OLD | NEW |