mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-06 23:37:31 +09:00
Issue #618: Pass down referrer and referrer policy when fetching modules.
Because the spec says so.
This commit is contained in:
parent
97617a3ab1
commit
684f4824da
4 changed files with 42 additions and 25 deletions
|
|
@ -28,13 +28,17 @@ ModuleLoadRequest::ModuleLoadRequest(nsIURI* aURI,
|
||||||
uint32_t aVersion,
|
uint32_t aVersion,
|
||||||
CORSMode aCORSMode,
|
CORSMode aCORSMode,
|
||||||
const SRIMetadata &aIntegrity,
|
const SRIMetadata &aIntegrity,
|
||||||
|
nsIURI* aReferrer,
|
||||||
|
mozilla::net::ReferrerPolicy aReferrerPolicy,
|
||||||
ScriptLoader* aLoader)
|
ScriptLoader* aLoader)
|
||||||
: ScriptLoadRequest(ScriptKind::Module,
|
: ScriptLoadRequest(ScriptKind::Module,
|
||||||
aURI,
|
aURI,
|
||||||
aElement,
|
aElement,
|
||||||
aVersion,
|
aVersion,
|
||||||
aCORSMode,
|
aCORSMode,
|
||||||
aIntegrity),
|
aIntegrity,
|
||||||
|
aReferrer,
|
||||||
|
aReferrerPolicy),
|
||||||
mIsTopLevel(true),
|
mIsTopLevel(true),
|
||||||
mLoader(aLoader),
|
mLoader(aLoader),
|
||||||
mVisitedSet(new VisitedURLSet())
|
mVisitedSet(new VisitedURLSet())
|
||||||
|
|
@ -49,7 +53,9 @@ ModuleLoadRequest::ModuleLoadRequest(nsIURI* aURI,
|
||||||
aParent->mElement,
|
aParent->mElement,
|
||||||
aParent->mJSVersion,
|
aParent->mJSVersion,
|
||||||
aParent->mCORSMode,
|
aParent->mCORSMode,
|
||||||
aParent->mIntegrity),
|
aParent->mIntegrity,
|
||||||
|
aParent->mURI,
|
||||||
|
aParent->mReferrerPolicy),
|
||||||
mIsTopLevel(false),
|
mIsTopLevel(false),
|
||||||
mLoader(aParent->mLoader),
|
mLoader(aParent->mLoader),
|
||||||
mVisitedSet(aParent->mVisitedSet)
|
mVisitedSet(aParent->mVisitedSet)
|
||||||
|
|
@ -57,7 +63,6 @@ ModuleLoadRequest::ModuleLoadRequest(nsIURI* aURI,
|
||||||
MOZ_ASSERT(mVisitedSet->Contains(aURI));
|
MOZ_ASSERT(mVisitedSet->Contains(aURI));
|
||||||
|
|
||||||
mIsInline = false;
|
mIsInline = false;
|
||||||
mReferrerPolicy = aParent->mReferrerPolicy;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModuleLoadRequest::Cancel()
|
void ModuleLoadRequest::Cancel()
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,8 @@ public:
|
||||||
uint32_t aVersion,
|
uint32_t aVersion,
|
||||||
CORSMode aCORSMode,
|
CORSMode aCORSMode,
|
||||||
const SRIMetadata& aIntegrity,
|
const SRIMetadata& aIntegrity,
|
||||||
|
nsIURI* aReferrer,
|
||||||
|
mozilla::net::ReferrerPolicy,
|
||||||
ScriptLoader* aLoader);
|
ScriptLoader* aLoader);
|
||||||
|
|
||||||
// Create a module load request for an imported module.
|
// Create a module load request for an imported module.
|
||||||
|
|
|
||||||
|
|
@ -1043,7 +1043,7 @@ ScriptLoader::StartLoad(ScriptLoadRequest *aRequest, const nsAString &aType,
|
||||||
httpChannel->SetRequestHeader(NS_LITERAL_CSTRING("Accept"),
|
httpChannel->SetRequestHeader(NS_LITERAL_CSTRING("Accept"),
|
||||||
NS_LITERAL_CSTRING("*/*"),
|
NS_LITERAL_CSTRING("*/*"),
|
||||||
false);
|
false);
|
||||||
httpChannel->SetReferrerWithPolicy(mDocument->GetDocumentURI(),
|
httpChannel->SetReferrerWithPolicy(aRequest->mReferrer,
|
||||||
aRequest->mReferrerPolicy);
|
aRequest->mReferrerPolicy);
|
||||||
|
|
||||||
nsCOMPtr<nsIHttpChannelInternal> internalChannel(do_QueryInterface(httpChannel));
|
nsCOMPtr<nsIHttpChannelInternal> internalChannel(do_QueryInterface(httpChannel));
|
||||||
|
|
@ -1175,16 +1175,21 @@ ScriptLoader::CreateLoadRequest(ScriptKind aKind,
|
||||||
nsIURI* aURI,
|
nsIURI* aURI,
|
||||||
nsIScriptElement* aElement,
|
nsIScriptElement* aElement,
|
||||||
uint32_t aVersion, CORSMode aCORSMode,
|
uint32_t aVersion, CORSMode aCORSMode,
|
||||||
const SRIMetadata &aIntegrity)
|
const SRIMetadata& aIntegrity,
|
||||||
|
mozilla::net::ReferrerPolicy aReferrerPolicy)
|
||||||
{
|
{
|
||||||
|
nsIURI* referrer = mDocument->GetDocumentURI();
|
||||||
|
|
||||||
if (aKind == ScriptKind::Classic) {
|
if (aKind == ScriptKind::Classic) {
|
||||||
return new ScriptLoadRequest(aKind, aURI, aElement,
|
return new ScriptLoadRequest(aKind, aURI, aElement,
|
||||||
aVersion, aCORSMode,
|
aVersion, aCORSMode,
|
||||||
aIntegrity);
|
aIntegrity,
|
||||||
|
referrer, aReferrerPolicy);
|
||||||
}
|
}
|
||||||
|
|
||||||
MOZ_ASSERT(aKind == ScriptKind::Module);
|
MOZ_ASSERT(aKind == ScriptKind::Module);
|
||||||
return new ModuleLoadRequest(aURI, aElement, aVersion, aCORSMode, aIntegrity, this);
|
return new ModuleLoadRequest(aURI, aElement, aVersion, aCORSMode,
|
||||||
|
aIntegrity, referrer, aReferrerPolicy, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
@ -1253,6 +1258,7 @@ ScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
|
||||||
// Step 15. and later in the HTML5 spec
|
// Step 15. and later in the HTML5 spec
|
||||||
nsresult rv = NS_OK;
|
nsresult rv = NS_OK;
|
||||||
RefPtr<ScriptLoadRequest> request;
|
RefPtr<ScriptLoadRequest> request;
|
||||||
|
mozilla::net::ReferrerPolicy ourRefPolicy = mDocument->GetReferrerPolicy();
|
||||||
if (aElement->GetScriptExternal()) {
|
if (aElement->GetScriptExternal()) {
|
||||||
// external script
|
// external script
|
||||||
nsCOMPtr<nsIURI> scriptURI = aElement->GetScriptURI();
|
nsCOMPtr<nsIURI> scriptURI = aElement->GetScriptURI();
|
||||||
|
|
@ -1265,7 +1271,6 @@ ScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Double-check that the preload matches what we're asked to load now.
|
// Double-check that the preload matches what we're asked to load now.
|
||||||
mozilla::net::ReferrerPolicy ourRefPolicy = mDocument->GetReferrerPolicy();
|
|
||||||
CORSMode ourCORSMode = aElement->GetCORSMode();
|
CORSMode ourCORSMode = aElement->GetCORSMode();
|
||||||
nsTArray<PreloadInfo>::index_type i =
|
nsTArray<PreloadInfo>::index_type i =
|
||||||
mPreloads.IndexOf(scriptURI.get(), 0, PreloadURIComparator());
|
mPreloads.IndexOf(scriptURI.get(), 0, PreloadURIComparator());
|
||||||
|
|
@ -1320,9 +1325,9 @@ ScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
|
||||||
}
|
}
|
||||||
|
|
||||||
request = CreateLoadRequest(scriptKind, scriptURI, aElement,
|
request = CreateLoadRequest(scriptKind, scriptURI, aElement,
|
||||||
version, ourCORSMode, sriMetadata);
|
version, ourCORSMode, sriMetadata,
|
||||||
|
ourRefPolicy);
|
||||||
request->mIsInline = false;
|
request->mIsInline = false;
|
||||||
request->mReferrerPolicy = ourRefPolicy;
|
|
||||||
|
|
||||||
// set aScriptFromHead to false so we don't treat non preloaded scripts as
|
// set aScriptFromHead to false so we don't treat non preloaded scripts as
|
||||||
// blockers for full page load. See bug 792438.
|
// blockers for full page load. See bug 792438.
|
||||||
|
|
@ -1440,10 +1445,11 @@ ScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inline scripts ignore ther CORS mode and are always CORS_NONE
|
// Inline scripts ignore ther CORS mode and are always CORS_NONE.
|
||||||
request = CreateLoadRequest(scriptKind, mDocument->GetDocumentURI(), aElement,
|
request = CreateLoadRequest(scriptKind, mDocument->GetDocumentURI(), aElement,
|
||||||
version, CORS_NONE,
|
version, CORS_NONE,
|
||||||
SRIMetadata()); // SRI doesn't apply
|
SRIMetadata(), // SRI doesn't apply
|
||||||
|
ourRefPolicy);
|
||||||
request->mJSVersion = version;
|
request->mJSVersion = version;
|
||||||
request->mIsInline = true;
|
request->mIsInline = true;
|
||||||
request->mLineNo = aElement->GetScriptLineNumber();
|
request->mLineNo = aElement->GetScriptLineNumber();
|
||||||
|
|
@ -2578,9 +2584,9 @@ ScriptLoader::PreloadURI(nsIURI *aURI, const nsAString &aCharset,
|
||||||
|
|
||||||
RefPtr<ScriptLoadRequest> request =
|
RefPtr<ScriptLoadRequest> request =
|
||||||
CreateLoadRequest(ScriptKind::Classic, aURI, nullptr, 0,
|
CreateLoadRequest(ScriptKind::Classic, aURI, nullptr, 0,
|
||||||
Element::StringToCORSMode(aCrossOrigin), sriMetadata);
|
Element::StringToCORSMode(aCrossOrigin), sriMetadata,
|
||||||
|
aReferrerPolicy);
|
||||||
request->mIsInline = false;
|
request->mIsInline = false;
|
||||||
request->mReferrerPolicy = aReferrerPolicy;
|
|
||||||
|
|
||||||
nsresult rv = StartLoad(request, aType, aScriptFromHead);
|
nsresult rv = StartLoad(request, aType, aScriptFromHead);
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,9 @@ public:
|
||||||
nsIScriptElement* aElement,
|
nsIScriptElement* aElement,
|
||||||
uint32_t aVersion,
|
uint32_t aVersion,
|
||||||
mozilla::CORSMode aCORSMode,
|
mozilla::CORSMode aCORSMode,
|
||||||
const mozilla::dom::SRIMetadata &aIntegrity)
|
const mozilla::dom::SRIMetadata& aIntegrity,
|
||||||
|
nsIURI* aReferrer,
|
||||||
|
mozilla::net::ReferrerPolicy aReferrerPolicy)
|
||||||
: mKind(aKind),
|
: mKind(aKind),
|
||||||
mElement(aElement),
|
mElement(aElement),
|
||||||
mProgress(Progress::Loading),
|
mProgress(Progress::Loading),
|
||||||
|
|
@ -86,7 +88,8 @@ public:
|
||||||
mLineNo(1),
|
mLineNo(1),
|
||||||
mCORSMode(aCORSMode),
|
mCORSMode(aCORSMode),
|
||||||
mIntegrity(aIntegrity),
|
mIntegrity(aIntegrity),
|
||||||
mReferrerPolicy(mozilla::net::RP_Default)
|
mReferrer(aReferrer),
|
||||||
|
mReferrerPolicy(aReferrerPolicy)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -173,7 +176,8 @@ public:
|
||||||
int32_t mLineNo;
|
int32_t mLineNo;
|
||||||
const mozilla::CORSMode mCORSMode;
|
const mozilla::CORSMode mCORSMode;
|
||||||
const mozilla::dom::SRIMetadata mIntegrity;
|
const mozilla::dom::SRIMetadata mIntegrity;
|
||||||
mozilla::net::ReferrerPolicy mReferrerPolicy;
|
const nsCOMPtr<nsIURI> mReferrer;
|
||||||
|
const mozilla::net::ReferrerPolicy mReferrerPolicy;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ScriptLoadRequestList : private mozilla::LinkedList<ScriptLoadRequest>
|
class ScriptLoadRequestList : private mozilla::LinkedList<ScriptLoadRequest>
|
||||||
|
|
@ -470,13 +474,13 @@ public:
|
||||||
private:
|
private:
|
||||||
virtual ~ScriptLoader();
|
virtual ~ScriptLoader();
|
||||||
|
|
||||||
ScriptLoadRequest* CreateLoadRequest(
|
ScriptLoadRequest* CreateLoadRequest(ScriptKind aKind,
|
||||||
ScriptKind aKind,
|
|
||||||
nsIURI* aURI,
|
nsIURI* aURI,
|
||||||
nsIScriptElement* aElement,
|
nsIScriptElement* aElement,
|
||||||
uint32_t aVersion,
|
uint32_t aVersion,
|
||||||
mozilla::CORSMode aCORSMode,
|
mozilla::CORSMode aCORSMode,
|
||||||
const mozilla::dom::SRIMetadata &aIntegrity);
|
const mozilla::dom::SRIMetadata& aIntegrity,
|
||||||
|
mozilla::net::ReferrerPolicy aReferrerPolicy);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unblocks the creator parser of the parser-blocking scripts.
|
* Unblocks the creator parser of the parser-blocking scripts.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue