mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 19:35:51 +00:00
Bug 1385907 - Combine exclusive fields of nsHtml5SpeculativeLoad. r=hsivonen
This commit is contained in:
parent
10d6dbd3e6
commit
bfdced6e8c
@ -25,16 +25,18 @@ nsHtml5SpeculativeLoad::Perform(nsHtml5TreeOpExecutor* aExecutor)
|
||||
{
|
||||
switch (mOpCode) {
|
||||
case eSpeculativeLoadBase:
|
||||
aExecutor->SetSpeculationBase(mUrl);
|
||||
aExecutor->SetSpeculationBase(mUrlOrSizes);
|
||||
break;
|
||||
case eSpeculativeLoadCSP:
|
||||
aExecutor->AddSpeculationCSP(mMetaCSP);
|
||||
aExecutor->AddSpeculationCSP(mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity);
|
||||
break;
|
||||
case eSpeculativeLoadMetaReferrer:
|
||||
aExecutor->SetSpeculationReferrerPolicy(mReferrerPolicy);
|
||||
aExecutor->SetSpeculationReferrerPolicy(mReferrerPolicyOrIntegrity);
|
||||
break;
|
||||
case eSpeculativeLoadImage:
|
||||
aExecutor->PreloadImage(mUrl, mCrossOrigin, mSrcset, mSizes, mReferrerPolicy);
|
||||
aExecutor->PreloadImage(mUrlOrSizes, mCrossOriginOrMedia, mCharsetOrSrcset,
|
||||
mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity,
|
||||
mReferrerPolicyOrIntegrity);
|
||||
break;
|
||||
case eSpeculativeLoadOpenPicture:
|
||||
aExecutor->PreloadOpenPicture();
|
||||
@ -43,44 +45,47 @@ nsHtml5SpeculativeLoad::Perform(nsHtml5TreeOpExecutor* aExecutor)
|
||||
aExecutor->PreloadEndPicture();
|
||||
break;
|
||||
case eSpeculativeLoadPictureSource:
|
||||
aExecutor->PreloadPictureSource(mSrcset, mSizes, mTypeOrCharsetSourceOrDocumentMode,
|
||||
mMedia);
|
||||
aExecutor->PreloadPictureSource(mCharsetOrSrcset, mUrlOrSizes,
|
||||
mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity,
|
||||
mCrossOriginOrMedia);
|
||||
break;
|
||||
case eSpeculativeLoadScript:
|
||||
aExecutor->PreloadScript(mUrl, mCharset, mTypeOrCharsetSourceOrDocumentMode,
|
||||
mCrossOrigin, mIntegrity, false);
|
||||
aExecutor->PreloadScript(mUrlOrSizes, mCharsetOrSrcset,
|
||||
mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity,
|
||||
mCrossOriginOrMedia, mReferrerPolicyOrIntegrity, false);
|
||||
break;
|
||||
case eSpeculativeLoadScriptFromHead:
|
||||
aExecutor->PreloadScript(mUrl, mCharset, mTypeOrCharsetSourceOrDocumentMode,
|
||||
mCrossOrigin, mIntegrity, true);
|
||||
aExecutor->PreloadScript(mUrlOrSizes, mCharsetOrSrcset,
|
||||
mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity,
|
||||
mCrossOriginOrMedia, mReferrerPolicyOrIntegrity, true);
|
||||
break;
|
||||
case eSpeculativeLoadStyle:
|
||||
aExecutor->PreloadStyle(mUrl, mCharset, mCrossOrigin, mReferrerPolicy,
|
||||
mIntegrity);
|
||||
aExecutor->PreloadStyle(mUrlOrSizes, mCharsetOrSrcset, mCrossOriginOrMedia, mReferrerPolicyOrIntegrity,
|
||||
mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity);
|
||||
break;
|
||||
case eSpeculativeLoadManifest:
|
||||
aExecutor->ProcessOfflineManifest(mUrl);
|
||||
aExecutor->ProcessOfflineManifest(mUrlOrSizes);
|
||||
break;
|
||||
case eSpeculativeLoadSetDocumentCharset: {
|
||||
nsAutoCString narrowName;
|
||||
CopyUTF16toUTF8(mCharset, narrowName);
|
||||
NS_ASSERTION(mTypeOrCharsetSourceOrDocumentMode.Length() == 1,
|
||||
CopyUTF16toUTF8(mCharsetOrSrcset, narrowName);
|
||||
NS_ASSERTION(mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity.Length() == 1,
|
||||
"Unexpected charset source string");
|
||||
int32_t intSource = (int32_t)mTypeOrCharsetSourceOrDocumentMode.First();
|
||||
int32_t intSource = (int32_t)mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity.First();
|
||||
aExecutor->SetDocumentCharsetAndSource(Encoding::ForName(narrowName),
|
||||
intSource);
|
||||
}
|
||||
break;
|
||||
case eSpeculativeLoadSetDocumentMode: {
|
||||
NS_ASSERTION(mTypeOrCharsetSourceOrDocumentMode.Length() == 1,
|
||||
NS_ASSERTION(mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity.Length() == 1,
|
||||
"Unexpected document mode string");
|
||||
nsHtml5DocumentMode mode =
|
||||
(nsHtml5DocumentMode)mTypeOrCharsetSourceOrDocumentMode.First();
|
||||
(nsHtml5DocumentMode)mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity.First();
|
||||
aExecutor->SetDocumentMode(mode);
|
||||
}
|
||||
break;
|
||||
case eSpeculativeLoadPreconnect:
|
||||
aExecutor->Preconnect(mUrl, mCrossOrigin);
|
||||
aExecutor->Preconnect(mUrlOrSizes, mCrossOriginOrMedia);
|
||||
break;
|
||||
default:
|
||||
NS_NOTREACHED("Bogus speculative load.");
|
||||
|
@ -40,7 +40,7 @@ class nsHtml5SpeculativeLoad {
|
||||
NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
|
||||
"Trying to reinitialize a speculative load!");
|
||||
mOpCode = eSpeculativeLoadBase;
|
||||
aUrl.ToString(mUrl);
|
||||
aUrl.ToString(mUrlOrSizes);
|
||||
}
|
||||
|
||||
inline void InitMetaCSP(nsHtml5String aCSP)
|
||||
@ -50,7 +50,7 @@ class nsHtml5SpeculativeLoad {
|
||||
mOpCode = eSpeculativeLoadCSP;
|
||||
nsString csp; // Not Auto, because using it to hold nsStringBuffer*
|
||||
aCSP.ToString(csp);
|
||||
mMetaCSP.Assign(
|
||||
mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity.Assign(
|
||||
nsContentUtils::TrimWhitespace<nsContentUtils::IsHTMLWhitespace>(csp));
|
||||
}
|
||||
|
||||
@ -62,7 +62,7 @@ class nsHtml5SpeculativeLoad {
|
||||
nsString
|
||||
referrerPolicy; // Not Auto, because using it to hold nsStringBuffer*
|
||||
aReferrerPolicy.ToString(referrerPolicy);
|
||||
mReferrerPolicy.Assign(
|
||||
mReferrerPolicyOrIntegrity.Assign(
|
||||
nsContentUtils::TrimWhitespace<nsContentUtils::IsHTMLWhitespace>(
|
||||
referrerPolicy));
|
||||
}
|
||||
@ -76,16 +76,16 @@ class nsHtml5SpeculativeLoad {
|
||||
NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
|
||||
"Trying to reinitialize a speculative load!");
|
||||
mOpCode = eSpeculativeLoadImage;
|
||||
aUrl.ToString(mUrl);
|
||||
aCrossOrigin.ToString(mCrossOrigin);
|
||||
aUrl.ToString(mUrlOrSizes);
|
||||
aCrossOrigin.ToString(mCrossOriginOrMedia);
|
||||
nsString
|
||||
referrerPolicy; // Not Auto, because using it to hold nsStringBuffer*
|
||||
aReferrerPolicy.ToString(referrerPolicy);
|
||||
mReferrerPolicy.Assign(
|
||||
mReferrerPolicyOrIntegrity.Assign(
|
||||
nsContentUtils::TrimWhitespace<nsContentUtils::IsHTMLWhitespace>(
|
||||
referrerPolicy));
|
||||
aSrcset.ToString(mSrcset);
|
||||
aSizes.ToString(mSizes);
|
||||
aSrcset.ToString(mCharsetOrSrcset);
|
||||
aSizes.ToString(mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity);
|
||||
}
|
||||
|
||||
// <picture> elements have multiple <source> nodes followed by an <img>,
|
||||
@ -117,10 +117,10 @@ class nsHtml5SpeculativeLoad {
|
||||
NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
|
||||
"Trying to reinitialize a speculative load!");
|
||||
mOpCode = eSpeculativeLoadPictureSource;
|
||||
aSrcset.ToString(mSrcset);
|
||||
aSizes.ToString(mSizes);
|
||||
aType.ToString(mTypeOrCharsetSourceOrDocumentMode);
|
||||
aMedia.ToString(mMedia);
|
||||
aSrcset.ToString(mCharsetOrSrcset);
|
||||
aSizes.ToString(mUrlOrSizes);
|
||||
aType.ToString(mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity);
|
||||
aMedia.ToString(mCrossOriginOrMedia);
|
||||
}
|
||||
|
||||
inline void InitScript(nsHtml5String aUrl,
|
||||
@ -134,11 +134,11 @@ class nsHtml5SpeculativeLoad {
|
||||
"Trying to reinitialize a speculative load!");
|
||||
mOpCode = aParserInHead ?
|
||||
eSpeculativeLoadScriptFromHead : eSpeculativeLoadScript;
|
||||
aUrl.ToString(mUrl);
|
||||
aCharset.ToString(mCharset);
|
||||
aType.ToString(mTypeOrCharsetSourceOrDocumentMode);
|
||||
aCrossOrigin.ToString(mCrossOrigin);
|
||||
aIntegrity.ToString(mIntegrity);
|
||||
aUrl.ToString(mUrlOrSizes);
|
||||
aCharset.ToString(mCharsetOrSrcset);
|
||||
aType.ToString(mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity);
|
||||
aCrossOrigin.ToString(mCrossOriginOrMedia);
|
||||
aIntegrity.ToString(mReferrerPolicyOrIntegrity);
|
||||
}
|
||||
|
||||
inline void InitStyle(nsHtml5String aUrl,
|
||||
@ -150,11 +150,11 @@ class nsHtml5SpeculativeLoad {
|
||||
NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
|
||||
"Trying to reinitialize a speculative load!");
|
||||
mOpCode = eSpeculativeLoadStyle;
|
||||
aUrl.ToString(mUrl);
|
||||
aCharset.ToString(mCharset);
|
||||
aCrossOrigin.ToString(mCrossOrigin);
|
||||
aReferrerPolicy.ToString(mReferrerPolicy);
|
||||
aIntegrity.ToString(mIntegrity);
|
||||
aUrl.ToString(mUrlOrSizes);
|
||||
aCharset.ToString(mCharsetOrSrcset);
|
||||
aCrossOrigin.ToString(mCrossOriginOrMedia);
|
||||
aReferrerPolicy.ToString(mReferrerPolicyOrIntegrity);
|
||||
aIntegrity.ToString(mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -173,7 +173,7 @@ class nsHtml5SpeculativeLoad {
|
||||
NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
|
||||
"Trying to reinitialize a speculative load!");
|
||||
mOpCode = eSpeculativeLoadManifest;
|
||||
aUrl.ToString(mUrl);
|
||||
aUrl.ToString(mUrlOrSizes);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -192,8 +192,8 @@ class nsHtml5SpeculativeLoad {
|
||||
NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
|
||||
"Trying to reinitialize a speculative load!");
|
||||
mOpCode = eSpeculativeLoadSetDocumentCharset;
|
||||
CopyUTF8toUTF16(aCharset, mCharset);
|
||||
mTypeOrCharsetSourceOrDocumentMode.Assign((char16_t)aCharsetSource);
|
||||
CopyUTF8toUTF16(aCharset, mCharsetOrSrcset);
|
||||
mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity.Assign((char16_t)aCharsetSource);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -207,7 +207,7 @@ class nsHtml5SpeculativeLoad {
|
||||
NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
|
||||
"Trying to reinitialize a speculative load!");
|
||||
mOpCode = eSpeculativeLoadSetDocumentMode;
|
||||
mTypeOrCharsetSourceOrDocumentMode.Assign((char16_t)aMode);
|
||||
mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity.Assign((char16_t)aMode);
|
||||
}
|
||||
|
||||
inline void InitPreconnect(nsHtml5String aUrl, nsHtml5String aCrossOrigin)
|
||||
@ -215,63 +215,58 @@ class nsHtml5SpeculativeLoad {
|
||||
NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
|
||||
"Trying to reinitialize a speculative load!");
|
||||
mOpCode = eSpeculativeLoadPreconnect;
|
||||
aUrl.ToString(mUrl);
|
||||
aCrossOrigin.ToString(mCrossOrigin);
|
||||
aUrl.ToString(mUrlOrSizes);
|
||||
aCrossOrigin.ToString(mCrossOriginOrMedia);
|
||||
}
|
||||
|
||||
void Perform(nsHtml5TreeOpExecutor* aExecutor);
|
||||
|
||||
private:
|
||||
eHtml5SpeculativeLoad mOpCode;
|
||||
nsString mUrl;
|
||||
nsString mReferrerPolicy;
|
||||
nsString mMetaCSP;
|
||||
|
||||
/* If mOpCode is eSpeculativeLoadPictureSource, this is the value of the
|
||||
* "sizes" attribute. If the attribute is not set, this will be a void
|
||||
* string. Otherwise it empty or the value of the url.
|
||||
*/
|
||||
nsString mUrlOrSizes;
|
||||
/**
|
||||
* If mOpCode is eSpeculativeLoadScript[FromHead], this is the value of the
|
||||
* "integrity" attribute. If the attribute is not set, this will be a void
|
||||
* string. Otherwise it is empty or the value of the referrer policy.
|
||||
*/
|
||||
nsString mReferrerPolicyOrIntegrity;
|
||||
/**
|
||||
* If mOpCode is eSpeculativeLoadStyle or eSpeculativeLoadScript[FromHead]
|
||||
* then this is the value of the "charset" attribute. For
|
||||
* eSpeculativeLoadSetDocumentCharset it is the charset that the
|
||||
* document's charset is being set to. Otherwise it's empty.
|
||||
* document's charset is being set to. If mOpCode is eSpeculativeLoadImage
|
||||
* or eSpeculativeLoadPictureSource, this is the value of the "srcset" attribute.
|
||||
* If the attribute is not set, this will be a void string. Otherwise it's empty.
|
||||
*/
|
||||
nsString mCharset;
|
||||
nsString mCharsetOrSrcset;
|
||||
/**
|
||||
* If mOpCode is eSpeculativeLoadSetDocumentCharset, this is a
|
||||
* one-character string whose single character's code point is to be
|
||||
* interpreted as a charset source integer. If mOpCode is
|
||||
* eSpeculativeLoadSetDocumentMode, this is a one-character string whose
|
||||
* single character's code point is to be interpreted as an
|
||||
* nsHtml5DocumentMode. Otherwise, it is empty or the value of the type
|
||||
* attribute.
|
||||
* nsHtml5DocumentMode. If mOpCode is eSpeculativeLoadCSP, this is a meta
|
||||
* element's CSP value. If mOpCode is eSpeculativeLoadImage, this is the
|
||||
* value of the "sizes" attribute. If the attribute is not set, this will
|
||||
* be a void string. If mOpCode is eSpeculativeLoadStyle, this
|
||||
* is the value of the "integrity" attribute. If the attribute is not set,
|
||||
* this will be a void string. Otherwise it is empty or the value of the
|
||||
* referrer policy. Otherwise, it is empty or the value of the type attribute.
|
||||
*/
|
||||
nsString mTypeOrCharsetSourceOrDocumentMode;
|
||||
nsString mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity;
|
||||
/**
|
||||
* If mOpCode is eSpeculativeLoadImage or eSpeculativeLoadScript[FromHead]
|
||||
* or eSpeculativeLoadPreconnect this is the value of the "crossorigin"
|
||||
* attribute. If the attribute is not set, this will be a void string.
|
||||
* If mOpCode is eSpeculativeLoadPictureSource, this is the value of the
|
||||
* "media" attribute. If the attribute is not set, this will be a void string.
|
||||
*/
|
||||
nsString mCrossOrigin;
|
||||
/**
|
||||
* If mOpCode is eSpeculativeLoadImage or eSpeculativeLoadPictureSource,
|
||||
* this is the value of "srcset" attribute. If the attribute is not set,
|
||||
* this will be a void string.
|
||||
*/
|
||||
nsString mSrcset;
|
||||
/**
|
||||
* If mOpCode is eSpeculativeLoadPictureSource, this is the value of "sizes"
|
||||
* attribute. If the attribute is not set, this will be a void string.
|
||||
*/
|
||||
nsString mSizes;
|
||||
/**
|
||||
* If mOpCode is eSpeculativeLoadPictureSource, this is the value of "media"
|
||||
* attribute. If the attribute is not set, this will be a void string.
|
||||
*/
|
||||
nsString mMedia;
|
||||
/**
|
||||
* If mOpCode is eSpeculativeLoadScript[FromHead], this is the value of the
|
||||
* "integrity" attribute. If the attribute is not set, this will be a void
|
||||
* string.
|
||||
*/
|
||||
nsString mIntegrity;
|
||||
nsString mCrossOriginOrMedia;
|
||||
};
|
||||
|
||||
#endif // nsHtml5SpeculativeLoad_h
|
||||
|
Loading…
Reference in New Issue
Block a user