| Index: content/browser/loader/cross_site_resource_handler.cc
|
| diff --git a/content/browser/loader/cross_site_resource_handler.cc b/content/browser/loader/cross_site_resource_handler.cc
|
| index ebf40eb023a6abfd0047b64e11de9ef04dd57eb7..d68fb9b7dd5378b7f4d4eef351be5ac09251230f 100644
|
| --- a/content/browser/loader/cross_site_resource_handler.cc
|
| +++ b/content/browser/loader/cross_site_resource_handler.cc
|
| @@ -16,6 +16,7 @@
|
| #include "content/browser/loader/resource_dispatcher_host_impl.h"
|
| #include "content/browser/loader/resource_request_info_impl.h"
|
| #include "content/browser/site_instance_impl.h"
|
| +#include "content/common/site_isolation_policy.h"
|
| #include "content/public/browser/browser_thread.h"
|
| #include "content/public/browser/content_browser_client.h"
|
| #include "content/public/browser/global_request_id.h"
|
| @@ -71,8 +72,7 @@ void OnCrossSiteResponseHelper(const CrossSiteResponseParams& params) {
|
| // We should only swap processes for subframes in --site-per-process mode.
|
| // CrossSiteResourceHandler is not installed on subframe requests in
|
| // default Chrome.
|
| - CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
|
| - switches::kSitePerProcess));
|
| + CHECK(SiteIsolationPolicy::AreCrossProcessFramesPossible());
|
| }
|
| rfh->OnCrossSiteResponse(
|
| params.global_request_id, cross_site_transferring_request.Pass(),
|
| @@ -87,8 +87,7 @@ void OnCrossSiteResponseHelper(const CrossSiteResponseParams& params) {
|
|
|
| // Returns whether a transfer is needed by doing a check on the UI thread.
|
| bool CheckNavigationPolicyOnUI(GURL url, int process_id, int render_frame_id) {
|
| - CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
|
| - switches::kSitePerProcess));
|
| + CHECK(SiteIsolationPolicy::AreCrossProcessFramesPossible());
|
| RenderFrameHostImpl* rfh =
|
| RenderFrameHostImpl::FromID(process_id, render_frame_id);
|
| if (!rfh)
|
| @@ -99,12 +98,18 @@ bool CheckNavigationPolicyOnUI(GURL url, int process_id, int render_frame_id) {
|
| if (!rfh->GetSiteInstance()->HasSite())
|
| return false;
|
|
|
| - // TODO(nasko): This check is very simplistic and is used temporarily only
|
| - // for --site-per-process. It should be updated to match the check performed
|
| - // by RenderFrameHostManager::UpdateStateForNavigate.
|
| - return !SiteInstance::IsSameWebSite(
|
| - rfh->GetSiteInstance()->GetBrowserContext(),
|
| - rfh->GetSiteInstance()->GetSiteURL(), url);
|
| + // TODO(nasko, nick): These following --site-per-process checks are
|
| + // overly simplistic. Update them to match all the cases
|
| + // considered by RenderFrameHostManager::DetermineSiteInstanceForURL.
|
| + if (SiteInstance::IsSameWebSite(rfh->GetSiteInstance()->GetBrowserContext(),
|
| + rfh->GetSiteInstance()->GetSiteURL(), url)) {
|
| + return false; // The same site, no transition needed.
|
| + }
|
| +
|
| + // The sites differ. If either one requires a dedicated process,
|
| + // then a transfer is needed.
|
| + return rfh->GetSiteInstance()->RequiresDedicatedProcess() ||
|
| + SiteIsolationPolicy::DoesSiteRequireDedicatedProcess(url);
|
| }
|
|
|
| } // namespace
|
| @@ -159,12 +164,12 @@ bool CrossSiteResourceHandler::OnNormalResponseStarted(
|
|
|
| ResourceRequestInfoImpl* info = GetRequestInfo();
|
|
|
| - // We only need to pause the response if a transfer to a different process is
|
| - // required. Other cross-process navigations can proceed immediately, since
|
| - // we run the unload handler at commit time.
|
| - // Note that a process swap may no longer be necessary if we transferred back
|
| - // into the original process due to a redirect.
|
| - bool should_transfer =
|
| + // The content embedder can decide that a transfer to a different process is
|
| + // required for this URL. If so, pause the response now. Other cross process
|
| + // navigations can proceed immediately, since we run the unload handler at
|
| + // commit time. Note that a process swap may no longer be necessary if we
|
| + // transferred back into the original process due to a redirect.
|
| + bool definitely_transfer =
|
| GetContentClient()->browser()->ShouldSwapProcessesForRedirect(
|
| info->GetContext(), request()->original_url(), request()->url());
|
|
|
| @@ -189,30 +194,33 @@ bool CrossSiteResourceHandler::OnNormalResponseStarted(
|
| return next_handler_->OnResponseStarted(response, defer);
|
| }
|
|
|
| - // When the --site-per-process flag is passed, we transfer processes for
|
| - // cross-site navigations. This is skipped if a transfer is already required
|
| - // or for WebUI processes for now, since pages like the NTP host multiple
|
| - // cross-site WebUI iframes.
|
| - if (!should_transfer &&
|
| - base::CommandLine::ForCurrentProcess()->HasSwitch(
|
| - switches::kSitePerProcess) &&
|
| + if (definitely_transfer) {
|
| + // Now that we know a transfer is needed and we have something to commit, we
|
| + // pause to let the UI thread set up the transfer.
|
| + StartCrossSiteTransition(response);
|
| +
|
| + // Defer loading until after the new renderer process has issued a
|
| + // corresponding request.
|
| + *defer = true;
|
| + OnDidDefer();
|
| + return true;
|
| + }
|
| +
|
| + // In the site-per-process model, we may also decide (independently from the
|
| + // content embedder's ShouldSwapProcessesForRedirect decision above) that a
|
| + // process transfer is needed. For that we need to consult the navigation
|
| + // policy on the UI thread, so pause the response. Process transfers are
|
| + // skipped for WebUI processes for now, since e.g. chrome://settings has
|
| + // multiple "cross-site" chrome:// frames, and that doesn't yet work cross-
|
| + // process.
|
| + if (SiteIsolationPolicy::AreCrossProcessFramesPossible() &&
|
| !ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
|
| info->GetChildID())) {
|
| return DeferForNavigationPolicyCheck(info, response, defer);
|
| }
|
|
|
| - if (!should_transfer)
|
| - return next_handler_->OnResponseStarted(response, defer);
|
| -
|
| - // Now that we know a transfer is needed and we have something to commit, we
|
| - // pause to let the UI thread set up the transfer.
|
| - StartCrossSiteTransition(response);
|
| -
|
| - // Defer loading until after the new renderer process has issued a
|
| - // corresponding request.
|
| - *defer = true;
|
| - OnDidDefer();
|
| - return true;
|
| + // No deferral needed. Pass the response through.
|
| + return next_handler_->OnResponseStarted(response, defer);
|
| }
|
|
|
| void CrossSiteResourceHandler::ResumeOrTransfer(bool is_transfer) {
|
|
|