Skip to content

Commit

Permalink
Backed out changeset b288a387f790 (bug 1425310) for causing Reflectio…
Browse files Browse the repository at this point in the history
…n related failures. CLOSED TREE
  • Loading branch information
chorotan committed Apr 21, 2023
1 parent 712972e commit d24a19d
Show file tree
Hide file tree
Showing 21 changed files with 131 additions and 409 deletions.
98 changes: 29 additions & 69 deletions dom/html/HTMLLinkElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,30 +311,36 @@ void HTMLLinkElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
aNameSpaceID, aName, aValue, aOldValue, aSubjectPrincipal, aNotify);
}

// Keep this and the arrays below in sync with ToLinkMask in LinkStyle.cpp.
#define SUPPORTED_REL_VALUES_BASE \
"prefetch", "dns-prefetch", "stylesheet", "next", "alternate", "preconnect", \
"icon", "search", nullptr

static const DOMTokenListSupportedToken sSupportedRelValueCombinations[][12] = {
{SUPPORTED_REL_VALUES_BASE},
{"manifest", SUPPORTED_REL_VALUES_BASE},
{"preload", SUPPORTED_REL_VALUES_BASE},
{"preload", "manifest", SUPPORTED_REL_VALUES_BASE},
{"modulepreload", SUPPORTED_REL_VALUES_BASE},
{"modulepreload", "manifest", SUPPORTED_REL_VALUES_BASE},
{"modulepreload", "preload", SUPPORTED_REL_VALUES_BASE},
{"modulepreload", "preload", "manifest", SUPPORTED_REL_VALUES_BASE}};
#undef SUPPORTED_REL_VALUES_BASE
static const DOMTokenListSupportedToken sSupportedRelValues[] = {
// Keep this and the one below in sync with ToLinkMask in
// LinkStyle.cpp.
// "preload" must come first because it can be disabled.
"preload", "prefetch", "dns-prefetch", "stylesheet",
"next", "alternate", "preconnect", "icon",
"search", "modulepreload", nullptr};

static const DOMTokenListSupportedToken sSupportedRelValuesWithManifest[] = {
// Keep this in sync with ToLinkMask in LinkStyle.cpp.
// "preload" and "manifest" must come first because they can be disabled.
"preload", "manifest", "prefetch", "dns-prefetch", "stylesheet", "next",
"alternate", "preconnect", "icon", "search", nullptr};

nsDOMTokenList* HTMLLinkElement::RelList() {
if (!mRelList) {
int index = (StaticPrefs::dom_manifest_enabled() ? 1 : 0) |
(StaticPrefs::network_preload() ? 2 : 0) |
(StaticPrefs::network_modulepreload() ? 4 : 0);

mRelList = new nsDOMTokenList(this, nsGkAtoms::rel,
sSupportedRelValueCombinations[index]);
auto preload = StaticPrefs::network_preload();
auto manifest = StaticPrefs::dom_manifest_enabled();
if (manifest && preload) {
mRelList = new nsDOMTokenList(this, nsGkAtoms::rel,
sSupportedRelValuesWithManifest);
} else if (manifest && !preload) {
mRelList = new nsDOMTokenList(this, nsGkAtoms::rel,
&sSupportedRelValuesWithManifest[1]);
} else if (!manifest && preload) {
mRelList = new nsDOMTokenList(this, nsGkAtoms::rel, sSupportedRelValues);
} else { // both false...drop preload
mRelList =
new nsDOMTokenList(this, nsGkAtoms::rel, &sSupportedRelValues[1]);
}
}
return mRelList;
}
Expand Down Expand Up @@ -484,10 +490,7 @@ void HTMLLinkElement::
}

if (linkTypes & eMODULE_PRELOAD) {
ScriptLoader* scriptLoader = OwnerDoc()->ScriptLoader();
ModuleLoader* moduleLoader = scriptLoader->GetModuleLoader();

if (!moduleLoader) {
if (!OwnerDoc()->ScriptLoader()->GetModuleLoader()) {
// For the print preview documents, at this moment it doesn't have module
// loader yet, as the (print preview) document is not attached to the
// nsIContentViewer yet, so it doesn't have the GlobalObject.
Expand All @@ -497,52 +500,9 @@ void HTMLLinkElement::
return;
}

if (!StaticPrefs::network_modulepreload()) {
// Keep behavior from https://phabricator.services.mozilla.com/D149371,
// prior to main implementation of modulepreload
moduleLoader->DisallowImportMaps();
return;
}

// https://html.spec.whatwg.org/multipage/semantics.html#processing-the-media-attribute
// TODO: apply this check for all linkTypes
nsAutoString media;
if (GetAttr(nsGkAtoms::media, media)) {
RefPtr<mozilla::dom::MediaList> mediaList =
mozilla::dom::MediaList::Create(NS_ConvertUTF16toUTF8(media));
if (!mediaList->Matches(*OwnerDoc())) {
return;
}
}

// TODO: per spec, apply this check for ePREFETCH as well
if (!HasNonEmptyAttr(nsGkAtoms::href)) {
return;
}

nsAutoString as;
GetAttr(nsGkAtoms::as, as);

nsAttrValue asAttr;
net::ParseAsValue(as, asAttr);

if (!net::IsScriptLikeOrInvalid(asAttr)) {
RefPtr<AsyncEventDispatcher> asyncDispatcher = new AsyncEventDispatcher(
this, u"error"_ns, CanBubble::eNo, ChromeOnlyDispatch::eNo);
asyncDispatcher->PostDOMEvent();
return;
}

nsCOMPtr<nsIURI> uri = GetURI();
if (!uri) {
return;
}

// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-modulepreload-module-script-graph
// Step 1. Disallow further import maps given settings object.
moduleLoader->DisallowImportMaps();

StartPreload(nsIContentPolicy::TYPE_SCRIPT);
OwnerDoc()->ScriptLoader()->GetModuleLoader()->DisallowImportMaps();
return;
}

Expand Down
7 changes: 3 additions & 4 deletions dom/script/ScriptLoadContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ class Element;
* the script does not need to be fetched first.
* * mIsXSLT
* Set if we are in an XSLT request.
* * mIsPreload
* * TODO: mIsPreload (will be moved from ScriptFetchOptions)
* Set for scripts that are preloaded in a
* <link rel="preload" as="script"> or <link rel="modulepreload">
* element.
* <link rel="preload" as="script"> element.
*
* In addition to describing how the ScriptLoadRequest will be loaded by the
* DOM ScriptLoader, the ScriptLoadContext contains fields that facilitate
Expand Down Expand Up @@ -114,7 +113,7 @@ class ScriptLoadContext : public JS::loader::LoadContextBase,
eDeferred,
eAsync,
eLinkPreload // this is a load initiated by <link rel="preload"
// as="script"> or <link rel="modulepreload"> tag
// as="script"> tag
};

void SetScriptMode(bool aDeferAttr, bool aAsyncAttr, bool aLinkPreload);
Expand Down
15 changes: 7 additions & 8 deletions dom/script/ScriptLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,12 +675,12 @@ nsresult ScriptLoader::StartLoadInternal(
aRequest->GetScriptLoadContext()->IsTracking()));

if (aRequest->GetScriptLoadContext()->IsLinkPreloadScript()) {
// This is <link rel="preload" as="script"> or <link rel="modulepreload">
// initiated speculative load, put it to the group that is not blocked by
// leaders and doesn't block follower at the same time. Giving it a much
// higher priority will make this request be processed ahead of other
// Unblocked requests, but with the same weight as Leaders. This will make
// us behave similar way for both http2 and http1.
// This is <link rel="preload" as="script"> initiated speculative load,
// put it to the group that is not blocked by leaders and doesn't block
// follower at the same time. Giving it a much higher priority will make
// this request be processed ahead of other Unblocked requests, but with
// the same weight as Leaders. This will make us behave similar way for
// both http2 and http1.
ScriptLoadContext::PrioritizeAsPreload(channel);
ScriptLoadContext::AddLoadBackgroundFlag(channel);
} else if (nsCOMPtr<nsIClassOfService> cos = do_QueryInterface(channel)) {
Expand Down Expand Up @@ -786,8 +786,7 @@ nsresult ScriptLoader::StartLoadInternal(
aRequest->mURI, aRequest->CORSMode(), aRequest->mKind);
aRequest->GetScriptLoadContext()->NotifyOpen(
key, channel, mDocument,
aRequest->GetScriptLoadContext()->IsLinkPreloadScript(),
aRequest->IsModuleRequest());
aRequest->GetScriptLoadContext()->IsLinkPreloadScript());

if (aEarlyHintPreloaderId) {
nsCOMPtr<nsIHttpChannelInternal> channelInternal =
Expand Down
11 changes: 1 addition & 10 deletions modules/libpref/init/StaticPrefList.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11634,21 +11634,12 @@
value: false
mirror: always

# Enables `<link rel="preload">` tag and `Link: rel=preload` response header
# handling.
# Enables `<link rel="preload">` tag and `Link: rel=preload` response header handling.
- name: network.preload
type: RelaxedAtomicBool
value: true
mirror: always

# Enables `<link rel="modulepreload">` tag and `Link: rel=modulepreload`
# response header handling. The latter is not yet implemented, see:
# https://bugzilla.mozilla.org/show_bug.cgi?id=1773056.
- name: network.modulepreload
type: RelaxedAtomicBool
value: true
mirror: always

# Enable 103 Early Hint status code (RFC 8297)
- name: network.early-hints.enabled
type: RelaxedAtomicBool
Expand Down
39 changes: 5 additions & 34 deletions netwerk/base/nsNetUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3716,30 +3716,11 @@ bool IsFontMimeType(const nsAString& aType) {
}

static const nsAttrValue::EnumTable kAsAttributeTable[] = {
{"", DESTINATION_INVALID},
{"audio", DESTINATION_AUDIO},
{"audioworklet", DESTINATION_AUDIOWORKLET},
{"document", DESTINATION_DOCUMENT},
{"embed", DESTINATION_EMBED},
{"font", DESTINATION_FONT},
{"frame", DESTINATION_FRAME},
{"iframe", DESTINATION_IFRAME},
{"image", DESTINATION_IMAGE},
{"manifest", DESTINATION_MANIFEST},
{"object", DESTINATION_OBJECT},
{"paintworklet", DESTINATION_PAINTWORKLET},
{"report", DESTINATION_REPORT},
{"script", DESTINATION_SCRIPT},
{"serviceworker", DESTINATION_SERVICEWORKER},
{"sharedworker", DESTINATION_SHAREDWORKER},
{"style", DESTINATION_STYLE},
{"track", DESTINATION_TRACK},
{"video", DESTINATION_VIDEO},
{"webidentity", DESTINATION_WEBIDENTITY},
{"worker", DESTINATION_WORKER},
{"xslt", DESTINATION_XSLT},
{"fetch", DESTINATION_FETCH},
{nullptr, 0}};
{"", DESTINATION_INVALID}, {"audio", DESTINATION_AUDIO},
{"font", DESTINATION_FONT}, {"image", DESTINATION_IMAGE},
{"script", DESTINATION_SCRIPT}, {"style", DESTINATION_STYLE},
{"track", DESTINATION_TRACK}, {"video", DESTINATION_VIDEO},
{"fetch", DESTINATION_FETCH}, {nullptr, 0}};

void ParseAsValue(const nsAString& aValue, nsAttrValue& aResult) {
DebugOnly<bool> success =
Expand Down Expand Up @@ -3775,16 +3756,6 @@ nsContentPolicyType AsValueToContentPolicy(const nsAttrValue& aValue) {
return nsIContentPolicy::TYPE_INVALID;
}

bool IsScriptLikeOrInvalid(const nsAttrValue& aValue) {
return aValue.GetEnumValue() == DESTINATION_INVALID ||
aValue.GetEnumValue() == DESTINATION_AUDIOWORKLET ||
aValue.GetEnumValue() == DESTINATION_PAINTWORKLET ||
aValue.GetEnumValue() == DESTINATION_SCRIPT ||
aValue.GetEnumValue() == DESTINATION_SERVICEWORKER ||
aValue.GetEnumValue() == DESTINATION_SHAREDWORKER ||
aValue.GetEnumValue() == DESTINATION_WORKER;
}

bool CheckPreloadAttrs(const nsAttrValue& aAs, const nsAString& aType,
const nsAString& aMedia,
mozilla::dom::Document* aDocument) {
Expand Down
6 changes: 0 additions & 6 deletions netwerk/base/nsNetUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -1019,32 +1019,26 @@ nsTArray<LinkHeader> ParseLinkHeader(const nsAString& aLinkData);
enum ASDestination : uint8_t {
DESTINATION_INVALID,
DESTINATION_AUDIO,
DESTINATION_AUDIOWORKLET,
DESTINATION_DOCUMENT,
DESTINATION_EMBED,
DESTINATION_FONT,
DESTINATION_FRAME,
DESTINATION_IFRAME,
DESTINATION_IMAGE,
DESTINATION_MANIFEST,
DESTINATION_OBJECT,
DESTINATION_PAINTWORKLET,
DESTINATION_REPORT,
DESTINATION_SCRIPT,
DESTINATION_SERVICEWORKER,
DESTINATION_SHAREDWORKER,
DESTINATION_STYLE,
DESTINATION_TRACK,
DESTINATION_VIDEO,
DESTINATION_WEBIDENTITY,
DESTINATION_WORKER,
DESTINATION_XSLT,
DESTINATION_FETCH
};

void ParseAsValue(const nsAString& aValue, nsAttrValue& aResult);
nsContentPolicyType AsValueToContentPolicy(const nsAttrValue& aValue);
bool IsScriptLikeOrInvalid(const nsAttrValue& aValue);

bool CheckPreloadAttrs(const nsAttrValue& aAs, const nsAString& aType,
const nsAString& aMedia,
Expand Down
8 changes: 4 additions & 4 deletions parser/html/nsHtml5SpeculativeLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,31 +63,31 @@ void nsHtml5SpeculativeLoad::Perform(nsHtml5TreeOpExecutor* aExecutor) {
aExecutor->PreloadScript(
mUrlOrSizes, mCharsetOrSrcset,
mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity,
mCrossOrigin, mMedia, mReferrerPolicyOrIntegrity, mAs,
mCrossOrigin, mMedia, mReferrerPolicyOrIntegrity,
mScriptReferrerPolicy, false, mIsAsync, mIsDefer, false,
mIsLinkPreload);
break;
case eSpeculativeLoadScriptFromHead:
aExecutor->PreloadScript(
mUrlOrSizes, mCharsetOrSrcset,
mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity,
mCrossOrigin, mMedia, mReferrerPolicyOrIntegrity, mAs,
mCrossOrigin, mMedia, mReferrerPolicyOrIntegrity,
mScriptReferrerPolicy, true, mIsAsync, mIsDefer, false,
mIsLinkPreload);
break;
case eSpeculativeLoadNoModuleScript:
aExecutor->PreloadScript(
mUrlOrSizes, mCharsetOrSrcset,
mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity,
mCrossOrigin, mMedia, mReferrerPolicyOrIntegrity, mAs,
mCrossOrigin, mMedia, mReferrerPolicyOrIntegrity,
mScriptReferrerPolicy, false, mIsAsync, mIsDefer, true,
mIsLinkPreload);
break;
case eSpeculativeLoadNoModuleScriptFromHead:
aExecutor->PreloadScript(
mUrlOrSizes, mCharsetOrSrcset,
mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity,
mCrossOrigin, mMedia, mReferrerPolicyOrIntegrity, mAs,
mCrossOrigin, mMedia, mReferrerPolicyOrIntegrity,
mScriptReferrerPolicy, true, mIsAsync, mIsDefer, true,
mIsLinkPreload);
break;
Expand Down
21 changes: 7 additions & 14 deletions parser/html/nsHtml5SpeculativeLoad.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ class nsHtml5SpeculativeLoad {
inline void InitScript(nsHtml5String aUrl, nsHtml5String aCharset,
nsHtml5String aType, nsHtml5String aCrossOrigin,
nsHtml5String aMedia, nsHtml5String aIntegrity,
nsHtml5String aAs, nsHtml5String aReferrerPolicy,
bool aParserInHead, bool aAsync, bool aDefer,
bool aNoModule, bool aLinkPreload) {
nsHtml5String aReferrerPolicy, bool aParserInHead,
bool aAsync, bool aDefer, bool aNoModule,
bool aLinkPreload) {
MOZ_ASSERT(mOpCode == eSpeculativeLoadUninitialized,
"Trying to reinitialize a speculative load!");
if (aNoModule) {
Expand All @@ -188,7 +188,6 @@ class nsHtml5SpeculativeLoad {
aCrossOrigin.ToString(mCrossOrigin);
aMedia.ToString(mMedia);
aIntegrity.ToString(mReferrerPolicyOrIntegrity);
aAs.ToString(mAs);
nsAutoString referrerPolicy;
aReferrerPolicy.ToString(referrerPolicy);
referrerPolicy =
Expand Down Expand Up @@ -335,8 +334,8 @@ class nsHtml5SpeculativeLoad {

/**
* True if and only if this is a speculative load initiated by <link
* rel="preload"> or <link rel="modulepreload"> tag encounter. Passed to the
* handling loader as an indication to raise the priority.
* rel="preload"> tag encounter. Passed to the handling loader as an
* indication to raise the priority.
*/
bool mIsLinkPreload;

Expand Down Expand Up @@ -388,8 +387,8 @@ class nsHtml5SpeculativeLoad {
* 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 type
* attribute.
* 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 mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity;
/**
Expand All @@ -407,12 +406,6 @@ class nsHtml5SpeculativeLoad {
* will be a void string.
*/
nsString mMedia;
/**
* If mOpCode is eSpeculativeLoadScript[FromHead] and the preload originated
* from <link rel="modulepreload">, this is the value of the "as" attribute.
* Otherwise, this will be a void string.
*/
nsString mAs;
/**
* If mOpCode is eSpeculativeLoadScript[FromHead] this represents the value
* of the "referrerpolicy" attribute. This field holds one of the values
Expand Down
Loading

0 comments on commit d24a19d

Please sign in to comment.