Commit 05f356ec authored by Lukasz Anforowicz's avatar Lukasz Anforowicz Committed by Commit Bot

Refactor ContentBrowserClient API exempting content scripts from CORB.

//services/network won't be able to directly use ContentBrowserClient,
so this CL refactors CORB-related parts of ContentBrowserClient in such
a way that the data they return in a browser-process can be easily
passed to the network service process.

Specifically, this CL changes the following ContentBrowserClient API:

  virtual bool ShouldBypassDocumentBlocking(const url::Origin& initiator,
                                            const GURL& url,
                                            ResourceType resource_type);

into:

  virtual const char* GetInitatorSchemeBypassingDocumentBlocking();

Bug: 792546
Change-Id: I39d88a97ff24d776319b2687837838fa594054c5
Tbr: rdevlin.cronin@chromium.org
Reviewed-on: https://chromium-review.googlesource.com/958041
Commit-Queue: Łukasz Anforowicz <lukasza@chromium.org>
Reviewed-by: default avatarNick Carter <nick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542897}
parent 950293c4
......@@ -1301,18 +1301,19 @@ bool ChromeContentBrowserClient::ShouldLockToOrigin(
return true;
}
bool ChromeContentBrowserClient::ShouldBypassDocumentBlocking(
const url::Origin& initiator,
const GURL& url,
ResourceType resource_type) {
const char*
ChromeContentBrowserClient::GetInitatorSchemeBypassingDocumentBlocking() {
#if BUILDFLAG(ENABLE_EXTENSIONS)
if (ChromeContentBrowserClientExtensionsPart::ShouldBypassDocumentBlocking(
initiator)) {
return true;
}
// Don't block responses for extension processes or for content scripts.
// TODO(creis): When every extension fetch (including content scripts) has
// been made to go through an extension-specific URLLoaderFactory, this
// mechanism ought to work by enumerating the host permissions from the
// extension manifest, and forwarding them on to the network service while
// brokering the URLLoaderFactory.
return extensions::kExtensionScheme;
#else
return nullptr;
#endif
return false;
}
// These are treated as WebUI schemes but do not get WebUI bindings. Also,
......
......@@ -111,10 +111,7 @@ class ChromeContentBrowserClient : public content::ContentBrowserClient {
const GURL& effective_site_url) override;
bool ShouldLockToOrigin(content::BrowserContext* browser_context,
const GURL& effective_site_url) override;
bool ShouldBypassDocumentBlocking(
const url::Origin& initiator,
const GURL& url,
content::ResourceType resource_type) override;
const char* GetInitatorSchemeBypassingDocumentBlocking() override;
void GetAdditionalWebUISchemes(
std::vector<std::string>* additional_schemes) override;
void GetAdditionalViewSourceSchemes(
......
......@@ -394,14 +394,6 @@ bool ChromeContentBrowserClientExtensionsPart::ShouldLockToOrigin(
return true;
}
bool ChromeContentBrowserClientExtensionsPart::ShouldBypassDocumentBlocking(
const url::Origin& initiator) {
// Don't block responses for extension processes or for content scripts.
// TODO(creis): This check can be made stricter by checking what the extension
// has access to.
return initiator.scheme() == extensions::kExtensionScheme;
}
// static
bool ChromeContentBrowserClientExtensionsPart::CanCommitURL(
content::RenderProcessHost* process_host, const GURL& url) {
......
......@@ -40,7 +40,6 @@ class ChromeContentBrowserClientExtensionsPart
const GURL& effective_site_url);
static bool ShouldLockToOrigin(content::BrowserContext* browser_context,
const GURL& effective_site_url);
static bool ShouldBypassDocumentBlocking(const url::Origin& initiator);
static bool CanCommitURL(content::RenderProcessHost* process_host,
const GURL& url);
static bool IsSuitableHost(Profile* profile,
......
......@@ -778,17 +778,21 @@ bool CrossSiteDocumentResourceHandler::ShouldBlockBasedOnHeaders(
if (initiator.scheme() == url::kFileScheme)
return false;
// Give embedder a chance to skip document blocking for this response.
const char* initiator_scheme_exception =
GetContentClient()
->browser()
->GetInitatorSchemeBypassingDocumentBlocking();
if (initiator_scheme_exception &&
initiator.scheme() == initiator_scheme_exception) {
return false;
}
// Only block if this is a request made from a renderer process.
const ResourceRequestInfoImpl* info = GetRequestInfo();
if (!info || info->GetChildID() == -1)
return false;
// Give embedder a chance to skip document blocking for this response.
if (GetContentClient()->browser()->ShouldBypassDocumentBlocking(
initiator, url, info->GetResourceType())) {
return false;
}
// Allow the response through if it has valid CORS headers.
std::string cors_header;
response->head.headers->GetNormalizedHeader("access-control-allow-origin",
......
......@@ -93,11 +93,8 @@ bool ContentBrowserClient::ShouldLockToOrigin(BrowserContext* browser_context,
return true;
}
bool ContentBrowserClient::ShouldBypassDocumentBlocking(
const url::Origin& initiator,
const GURL& url,
ResourceType resource_type) {
return false;
const char* ContentBrowserClient::GetInitatorSchemeBypassingDocumentBlocking() {
return nullptr;
}
void ContentBrowserClient::GetAdditionalViewSourceSchemes(
......
......@@ -257,12 +257,10 @@ class CONTENT_EXPORT ContentBrowserClient {
virtual bool ShouldLockToOrigin(BrowserContext* browser_context,
const GURL& effective_url);
// Returns true if the |initiator| origin should be allowed to receive a
// document at |url|, bypassing the usual blocking logic. Defaults to false.
// This is called on the IO thread.
virtual bool ShouldBypassDocumentBlocking(const url::Origin& initiator,
const GURL& url,
ResourceType resource_type);
// Returns the scheme of request initiator that should be ignored by
// cross-origin read blocking. nullptr can be returned to indicate that no
// exceptions should be granted based on initiator's scheme.
virtual const char* GetInitatorSchemeBypassingDocumentBlocking();
// Returns a list additional WebUI schemes, if any. These additional schemes
// act as aliases to the chrome: scheme. The additional schemes may or may
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment