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