зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1048048 - add preload content policy types for scripts (r=baku)
This commit is contained in:
Родитель
ffddcba82d
Коммит
c938714dba
|
@ -223,10 +223,15 @@ nsresult
|
|||
nsScriptLoader::CheckContentPolicy(nsIDocument* aDocument,
|
||||
nsISupports *aContext,
|
||||
nsIURI *aURI,
|
||||
const nsAString &aType)
|
||||
const nsAString &aType,
|
||||
bool aIsPreLoad)
|
||||
{
|
||||
nsContentPolicyType contentPolicyType = aIsPreLoad
|
||||
? nsIContentPolicy::TYPE_INTERNAL_SCRIPT_PRELOAD
|
||||
: nsIContentPolicy::TYPE_INTERNAL_SCRIPT;
|
||||
|
||||
int16_t shouldLoad = nsIContentPolicy::ACCEPT;
|
||||
nsresult rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_INTERNAL_SCRIPT,
|
||||
nsresult rv = NS_CheckContentLoadPolicy(contentPolicyType,
|
||||
aURI,
|
||||
aDocument->NodePrincipal(),
|
||||
aContext,
|
||||
|
@ -249,7 +254,8 @@ nsresult
|
|||
nsScriptLoader::ShouldLoadScript(nsIDocument* aDocument,
|
||||
nsISupports* aContext,
|
||||
nsIURI* aURI,
|
||||
const nsAString &aType)
|
||||
const nsAString &aType,
|
||||
bool aIsPreLoad)
|
||||
{
|
||||
// Check that the containing page is allowed to load this URI.
|
||||
nsresult rv = nsContentUtils::GetSecurityManager()->
|
||||
|
@ -259,7 +265,7 @@ nsScriptLoader::ShouldLoadScript(nsIDocument* aDocument,
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// After the security manager, the content-policy stuff gets a veto
|
||||
rv = CheckContentPolicy(aDocument, aContext, aURI, aType);
|
||||
rv = CheckContentPolicy(aDocument, aContext, aURI, aType, aIsPreLoad);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
@ -274,7 +280,7 @@ nsScriptLoader::StartLoad(nsScriptLoadRequest *aRequest, const nsAString &aType,
|
|||
nsISupports *context = aRequest->mElement.get()
|
||||
? static_cast<nsISupports *>(aRequest->mElement.get())
|
||||
: static_cast<nsISupports *>(mDocument);
|
||||
nsresult rv = ShouldLoadScript(mDocument, context, aRequest->mURI, aType);
|
||||
nsresult rv = ShouldLoadScript(mDocument, context, aRequest->mURI, aType, aRequest->IsPreload());
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
@ -296,12 +302,16 @@ nsScriptLoader::StartLoad(nsScriptLoadRequest *aRequest, const nsAString &aType,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsContentPolicyType contentPolicyType = aRequest->IsPreload()
|
||||
? nsIContentPolicy::TYPE_INTERNAL_SCRIPT_PRELOAD
|
||||
: nsIContentPolicy::TYPE_INTERNAL_SCRIPT;
|
||||
|
||||
nsCOMPtr<nsIChannel> channel;
|
||||
rv = NS_NewChannel(getter_AddRefs(channel),
|
||||
aRequest->mURI,
|
||||
mDocument,
|
||||
nsILoadInfo::SEC_NORMAL,
|
||||
nsIContentPolicy::TYPE_INTERNAL_SCRIPT,
|
||||
contentPolicyType,
|
||||
loadGroup,
|
||||
prompter,
|
||||
nsIRequest::LOAD_NORMAL |
|
||||
|
@ -530,7 +540,7 @@ nsScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
|
|||
if (elementCharset.Equals(preloadCharset) &&
|
||||
ourCORSMode == request->mCORSMode &&
|
||||
ourRefPolicy == request->mReferrerPolicy) {
|
||||
rv = CheckContentPolicy(mDocument, aElement, request->mURI, type);
|
||||
rv = CheckContentPolicy(mDocument, aElement, request->mURI, type, false);
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
} else {
|
||||
// Drop the preload
|
||||
|
|
|
@ -354,7 +354,8 @@ public:
|
|||
static nsresult ShouldLoadScript(nsIDocument* aDocument,
|
||||
nsISupports* aContext,
|
||||
nsIURI* aURI,
|
||||
const nsAString &aType);
|
||||
const nsAString &aType,
|
||||
bool aIsPreLoad);
|
||||
|
||||
/**
|
||||
* Starts deferring deferred scripts and puts them in the mDeferredRequests
|
||||
|
@ -435,7 +436,8 @@ private:
|
|||
static nsresult CheckContentPolicy(nsIDocument* aDocument,
|
||||
nsISupports *aContext,
|
||||
nsIURI *aURI,
|
||||
const nsAString &aType);
|
||||
const nsAString &aType,
|
||||
bool aIsPreLoad);
|
||||
|
||||
/**
|
||||
* Start a load for aRequest's URI.
|
||||
|
|
|
@ -50,7 +50,7 @@ ResourceLoader.load = function(uri, doc) {
|
|||
// the '2' identifies this as a script load
|
||||
let ioChannel = ioService.newChannelFromURI2(uri, doc, doc.nodePrincipal,
|
||||
systemPrincipal, 0,
|
||||
Ci.nsIContentPolicy.TYPE_SCRIPT);
|
||||
Ci.nsIContentPolicy.TYPE_INTERNAL_SCRIPT);
|
||||
|
||||
ioChannel.loadGroup = doc.documentLoadGroup.QueryInterface(Ci.nsILoadGroup);
|
||||
ioChannel.notificationCallbacks = new RedirectHttpsOnly();
|
||||
|
|
|
@ -111,12 +111,12 @@ public:
|
|||
}
|
||||
|
||||
// Note that because there is no "serviceworker" RequestContext type, we can
|
||||
// use the external TYPE_SCRIPT content policy types when loading a service
|
||||
// use the TYPE_INTERNAL_SCRIPT content policy types when loading a service
|
||||
// worker.
|
||||
rv = NS_NewChannel(getter_AddRefs(mChannel),
|
||||
uri, aPrincipal,
|
||||
nsILoadInfo::SEC_NORMAL,
|
||||
nsIContentPolicy::TYPE_SCRIPT,
|
||||
nsIContentPolicy::TYPE_INTERNAL_SCRIPT,
|
||||
loadGroup);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
|
|
|
@ -3250,7 +3250,8 @@ XULDocument::LoadScript(nsXULPrototypeScript* aScriptProto, bool* aBlock)
|
|||
this,
|
||||
static_cast<nsIDocument*>(this),
|
||||
aScriptProto->mSrcURI,
|
||||
NS_LITERAL_STRING("application/x-javascript"));
|
||||
NS_LITERAL_STRING("application/x-javascript"),
|
||||
false);
|
||||
if (NS_FAILED(rv)) {
|
||||
*aBlock = false;
|
||||
return rv;
|
||||
|
|
Загрузка…
Ссылка в новой задаче