Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(717)

Unified Diff: content/browser/loader/cross_site_resource_handler.cc

Issue 1208143002: Move existing kSitePerProcess checks to a policy-oracle object (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@swapped_out_cmdline_checks
Patch Set: Partial fixes to Nasko's comments. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..7f3208e25fe03232be9c10ec187e4cd1b437fd72 100644
--- a/content/browser/loader/cross_site_resource_handler.cc
+++ b/content/browser/loader/cross_site_resource_handler.cc
@@ -23,6 +23,7 @@
#include "content/public/browser/site_instance.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/resource_response.h"
+#include "content/public/common/site_isolation_policy.h"
#include "content/public/common/url_constants.h"
#include "net/http/http_response_headers.h"
#include "net/url_request/url_request.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,32 @@ 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
+ 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 pages like the NTP host multiple
Charlie Reis 2015/07/13 22:13:14 While we're here, let's fix this wording: the NTP
ncarter (slow) 2015/07/20 17:45:46 Done.
// cross-site WebUI iframes.
- if (!should_transfer &&
- base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kSitePerProcess) &&
+ 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) {

Powered by Google App Engine
This is Rietveld 408576698