зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1627263 - Propagate nonce attribute from Link header preloads to loaders. r=necko-reviewers,kershaw
Differential Revision: https://phabricator.services.mozilla.com/D183968
This commit is contained in:
Родитель
90a29a13ea
Коммит
ed711958ea
|
@ -311,14 +311,14 @@ nsresult nsContentSink::ProcessLinkFromHeader(const net::LinkHeader& aHeader,
|
||||||
|
|
||||||
if (linkTypes & LinkStyle::ePRELOAD) {
|
if (linkTypes & LinkStyle::ePRELOAD) {
|
||||||
PreloadHref(aHeader.mHref, aHeader.mAs, aHeader.mType, aHeader.mMedia,
|
PreloadHref(aHeader.mHref, aHeader.mAs, aHeader.mType, aHeader.mMedia,
|
||||||
aHeader.mIntegrity, aHeader.mSrcset, aHeader.mSizes,
|
aHeader.mNonce, aHeader.mIntegrity, aHeader.mSrcset,
|
||||||
aHeader.mCrossOrigin, aHeader.mReferrerPolicy,
|
aHeader.mSizes, aHeader.mCrossOrigin, aHeader.mReferrerPolicy,
|
||||||
aEarlyHintPreloaderId);
|
aEarlyHintPreloaderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((linkTypes & LinkStyle::eMODULE_PRELOAD) &&
|
if ((linkTypes & LinkStyle::eMODULE_PRELOAD) &&
|
||||||
mDocument->ScriptLoader()->GetModuleLoader()) {
|
mDocument->ScriptLoader()->GetModuleLoader()) {
|
||||||
PreloadModule(aHeader.mHref, aHeader.mAs, aHeader.mMedia,
|
PreloadModule(aHeader.mHref, aHeader.mAs, aHeader.mMedia, aHeader.mNonce,
|
||||||
aHeader.mIntegrity, aHeader.mCrossOrigin,
|
aHeader.mIntegrity, aHeader.mCrossOrigin,
|
||||||
aHeader.mReferrerPolicy, aEarlyHintPreloaderId);
|
aHeader.mReferrerPolicy, aEarlyHintPreloaderId);
|
||||||
}
|
}
|
||||||
|
@ -420,6 +420,7 @@ void nsContentSink::PrefetchHref(const nsAString& aHref, const nsAString& aAs,
|
||||||
|
|
||||||
void nsContentSink::PreloadHref(const nsAString& aHref, const nsAString& aAs,
|
void nsContentSink::PreloadHref(const nsAString& aHref, const nsAString& aAs,
|
||||||
const nsAString& aType, const nsAString& aMedia,
|
const nsAString& aType, const nsAString& aMedia,
|
||||||
|
const nsAString& aNonce,
|
||||||
const nsAString& aIntegrity,
|
const nsAString& aIntegrity,
|
||||||
const nsAString& aSrcset,
|
const nsAString& aSrcset,
|
||||||
const nsAString& aSizes, const nsAString& aCORS,
|
const nsAString& aSizes, const nsAString& aCORS,
|
||||||
|
@ -449,12 +450,13 @@ void nsContentSink::PreloadHref(const nsAString& aHref, const nsAString& aAs,
|
||||||
}
|
}
|
||||||
|
|
||||||
mDocument->Preloads().PreloadLinkHeader(
|
mDocument->Preloads().PreloadLinkHeader(
|
||||||
uri, aHref, policyType, aAs, aType, aIntegrity, aSrcset, aSizes, aCORS,
|
uri, aHref, policyType, aAs, aType, aNonce, aIntegrity, aSrcset, aSizes,
|
||||||
aReferrerPolicy, aEarlyHintPreloaderId);
|
aCORS, aReferrerPolicy, aEarlyHintPreloaderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void nsContentSink::PreloadModule(const nsAString& aHref, const nsAString& aAs,
|
void nsContentSink::PreloadModule(const nsAString& aHref, const nsAString& aAs,
|
||||||
const nsAString& aMedia,
|
const nsAString& aMedia,
|
||||||
|
const nsAString& aNonce,
|
||||||
const nsAString& aIntegrity,
|
const nsAString& aIntegrity,
|
||||||
const nsAString& aCORS,
|
const nsAString& aCORS,
|
||||||
const nsAString& aReferrerPolicy,
|
const nsAString& aReferrerPolicy,
|
||||||
|
@ -493,7 +495,7 @@ void nsContentSink::PreloadModule(const nsAString& aHref, const nsAString& aAs,
|
||||||
|
|
||||||
mDocument->Preloads().PreloadLinkHeader(
|
mDocument->Preloads().PreloadLinkHeader(
|
||||||
uri, aHref, nsIContentPolicy::TYPE_SCRIPT, u"script"_ns, u"module"_ns,
|
uri, aHref, nsIContentPolicy::TYPE_SCRIPT, u"script"_ns, u"module"_ns,
|
||||||
aIntegrity, u""_ns, u""_ns, aCORS, aReferrerPolicy,
|
aNonce, aIntegrity, u""_ns, u""_ns, aCORS, aReferrerPolicy,
|
||||||
aEarlyHintPreloaderId);
|
aEarlyHintPreloaderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -137,14 +137,15 @@ class nsContentSink : public nsICSSLoaderObserver,
|
||||||
const nsAString& aType, const nsAString& aMedia);
|
const nsAString& aType, const nsAString& aMedia);
|
||||||
void PreloadHref(const nsAString& aHref, const nsAString& aAs,
|
void PreloadHref(const nsAString& aHref, const nsAString& aAs,
|
||||||
const nsAString& aType, const nsAString& aMedia,
|
const nsAString& aType, const nsAString& aMedia,
|
||||||
const nsAString& aIntegrity, const nsAString& aSrcset,
|
const nsAString& aNonce, const nsAString& aIntegrity,
|
||||||
const nsAString& aSizes, const nsAString& aCORS,
|
const nsAString& aSrcset, const nsAString& aSizes,
|
||||||
const nsAString& aReferrerPolicy,
|
const nsAString& aCORS, const nsAString& aReferrerPolicy,
|
||||||
uint64_t aEarlyHintPreloaderId);
|
uint64_t aEarlyHintPreloaderId);
|
||||||
|
|
||||||
void PreloadModule(const nsAString& aHref, const nsAString& aAs,
|
void PreloadModule(const nsAString& aHref, const nsAString& aAs,
|
||||||
const nsAString& aMedia, const nsAString& aIntegrity,
|
const nsAString& aMedia, const nsAString& aNonce,
|
||||||
const nsAString& aCORS, const nsAString& aReferrerPolicy,
|
const nsAString& aIntegrity, const nsAString& aCORS,
|
||||||
|
const nsAString& aReferrerPolicy,
|
||||||
uint64_t aEarlyHintPreloaderId);
|
uint64_t aEarlyHintPreloaderId);
|
||||||
|
|
||||||
// For PrefetchDNS() aHref can either be the usual
|
// For PrefetchDNS() aHref can either be the usual
|
||||||
|
|
|
@ -759,6 +759,7 @@ struct ParamTraits<mozilla::net::LinkHeader> {
|
||||||
WriteParam(aWriter, aParam.mHref);
|
WriteParam(aWriter, aParam.mHref);
|
||||||
WriteParam(aWriter, aParam.mRel);
|
WriteParam(aWriter, aParam.mRel);
|
||||||
WriteParam(aWriter, aParam.mTitle);
|
WriteParam(aWriter, aParam.mTitle);
|
||||||
|
WriteParam(aWriter, aParam.mNonce);
|
||||||
WriteParam(aWriter, aParam.mIntegrity);
|
WriteParam(aWriter, aParam.mIntegrity);
|
||||||
WriteParam(aWriter, aParam.mSrcset);
|
WriteParam(aWriter, aParam.mSrcset);
|
||||||
WriteParam(aWriter, aParam.mSizes);
|
WriteParam(aWriter, aParam.mSizes);
|
||||||
|
@ -778,6 +779,9 @@ struct ParamTraits<mozilla::net::LinkHeader> {
|
||||||
if (!ReadParam(aReader, &aResult->mTitle)) {
|
if (!ReadParam(aReader, &aResult->mTitle)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (!ReadParam(aReader, &aResult->mNonce)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (!ReadParam(aReader, &aResult->mIntegrity)) {
|
if (!ReadParam(aReader, &aResult->mIntegrity)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3503,6 +3503,7 @@ void LinkHeader::Reset() {
|
||||||
mHref.Truncate();
|
mHref.Truncate();
|
||||||
mRel.Truncate();
|
mRel.Truncate();
|
||||||
mTitle.Truncate();
|
mTitle.Truncate();
|
||||||
|
mNonce.Truncate();
|
||||||
mIntegrity.Truncate();
|
mIntegrity.Truncate();
|
||||||
mSrcset.Truncate();
|
mSrcset.Truncate();
|
||||||
mSizes.Truncate();
|
mSizes.Truncate();
|
||||||
|
@ -3532,9 +3533,10 @@ nsresult LinkHeader::NewResolveHref(nsIURI** aOutURI, nsIURI* aBaseURI) const {
|
||||||
|
|
||||||
bool LinkHeader::operator==(const LinkHeader& rhs) const {
|
bool LinkHeader::operator==(const LinkHeader& rhs) const {
|
||||||
return mHref == rhs.mHref && mRel == rhs.mRel && mTitle == rhs.mTitle &&
|
return mHref == rhs.mHref && mRel == rhs.mRel && mTitle == rhs.mTitle &&
|
||||||
mIntegrity == rhs.mIntegrity && mSrcset == rhs.mSrcset &&
|
mNonce == rhs.mNonce && mIntegrity == rhs.mIntegrity &&
|
||||||
mSizes == rhs.mSizes && mType == rhs.mType && mMedia == rhs.mMedia &&
|
mSrcset == rhs.mSrcset && mSizes == rhs.mSizes && mType == rhs.mType &&
|
||||||
mAnchor == rhs.mAnchor && mCrossOrigin == rhs.mCrossOrigin &&
|
mMedia == rhs.mMedia && mAnchor == rhs.mAnchor &&
|
||||||
|
mCrossOrigin == rhs.mCrossOrigin &&
|
||||||
mReferrerPolicy == rhs.mReferrerPolicy && mAs == rhs.mAs;
|
mReferrerPolicy == rhs.mReferrerPolicy && mAs == rhs.mAs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3741,6 +3743,11 @@ nsTArray<LinkHeader> ParseLinkHeader(const nsAString& aLinkData) {
|
||||||
if (header.mReferrerPolicy.IsEmpty()) {
|
if (header.mReferrerPolicy.IsEmpty()) {
|
||||||
header.mReferrerPolicy = value;
|
header.mReferrerPolicy = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else if (attr.LowerCaseEqualsLiteral("nonce")) {
|
||||||
|
if (header.mNonce.IsEmpty()) {
|
||||||
|
header.mNonce = value;
|
||||||
|
}
|
||||||
} else if (attr.LowerCaseEqualsLiteral("integrity")) {
|
} else if (attr.LowerCaseEqualsLiteral("integrity")) {
|
||||||
if (header.mIntegrity.IsEmpty()) {
|
if (header.mIntegrity.IsEmpty()) {
|
||||||
header.mIntegrity = value;
|
header.mIntegrity = value;
|
||||||
|
|
|
@ -1002,6 +1002,7 @@ struct LinkHeader {
|
||||||
nsString mHref;
|
nsString mHref;
|
||||||
nsString mRel;
|
nsString mRel;
|
||||||
nsString mTitle;
|
nsString mTitle;
|
||||||
|
nsString mNonce;
|
||||||
nsString mIntegrity;
|
nsString mIntegrity;
|
||||||
nsString mSrcset;
|
nsString mSrcset;
|
||||||
nsString mSizes;
|
nsString mSizes;
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[link-header-preload-nonce.html]
|
|
||||||
expected:
|
|
||||||
if (os == "android") and fission: [OK, TIMEOUT]
|
|
||||||
[with nonce]
|
|
||||||
expected: FAIL
|
|
|
@ -114,8 +114,9 @@ already_AddRefed<PreloaderBase> PreloadService::PreloadLinkElement(
|
||||||
|
|
||||||
void PreloadService::PreloadLinkHeader(
|
void PreloadService::PreloadLinkHeader(
|
||||||
nsIURI* aURI, const nsAString& aURL, nsContentPolicyType aPolicyType,
|
nsIURI* aURI, const nsAString& aURL, nsContentPolicyType aPolicyType,
|
||||||
const nsAString& aAs, const nsAString& aType, const nsAString& aIntegrity,
|
const nsAString& aAs, const nsAString& aType, const nsAString& aNonce,
|
||||||
const nsAString& aSrcset, const nsAString& aSizes, const nsAString& aCORS,
|
const nsAString& aIntegrity, const nsAString& aSrcset,
|
||||||
|
const nsAString& aSizes, const nsAString& aCORS,
|
||||||
const nsAString& aReferrerPolicy, uint64_t aEarlyHintPreloaderId) {
|
const nsAString& aReferrerPolicy, uint64_t aEarlyHintPreloaderId) {
|
||||||
if (aPolicyType == nsIContentPolicy::TYPE_INVALID) {
|
if (aPolicyType == nsIContentPolicy::TYPE_INVALID) {
|
||||||
MOZ_ASSERT_UNREACHABLE("Caller should check");
|
MOZ_ASSERT_UNREACHABLE("Caller should check");
|
||||||
|
@ -127,8 +128,7 @@ void PreloadService::PreloadLinkHeader(
|
||||||
}
|
}
|
||||||
|
|
||||||
PreloadOrCoalesce(aURI, aURL, aPolicyType, aAs, aType, u""_ns, aSrcset,
|
PreloadOrCoalesce(aURI, aURL, aPolicyType, aAs, aType, u""_ns, aSrcset,
|
||||||
aSizes, /* aNonce = */ u""_ns, aIntegrity, aCORS,
|
aSizes, aNonce, aIntegrity, aCORS, aReferrerPolicy,
|
||||||
aReferrerPolicy,
|
|
||||||
/* aFromHeader = */ true, aEarlyHintPreloaderId);
|
/* aFromHeader = */ true, aEarlyHintPreloaderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,9 +72,9 @@ class PreloadService {
|
||||||
// AsyncOpen.
|
// AsyncOpen.
|
||||||
void PreloadLinkHeader(nsIURI* aURI, const nsAString& aURL,
|
void PreloadLinkHeader(nsIURI* aURI, const nsAString& aURL,
|
||||||
nsContentPolicyType aPolicyType, const nsAString& aAs,
|
nsContentPolicyType aPolicyType, const nsAString& aAs,
|
||||||
const nsAString& aType, const nsAString& aIntegrity,
|
const nsAString& aType, const nsAString& aNonce,
|
||||||
const nsAString& aSrcset, const nsAString& aSizes,
|
const nsAString& aIntegrity, const nsAString& aSrcset,
|
||||||
const nsAString& aCORS,
|
const nsAString& aSizes, const nsAString& aCORS,
|
||||||
const nsAString& aReferrerPolicy,
|
const nsAString& aReferrerPolicy,
|
||||||
uint64_t aEarlyHintPreloaderId);
|
uint64_t aEarlyHintPreloaderId);
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче