Skip to content

Commit 3a69633

Browse files
committed
Bug 1940382 - Part 3: Don't preload json modules. r=dom-core,necko-reviewers,valentin,farre
Implement whatwg/html#10212 Disallow preloading for "json". https://html.spec.whatwg.org/#translate-a-preload-destination And add mime-type check for JSON files. Differential Revision: https://phabricator.services.mozilla.com/D234849
1 parent 165bb66 commit 3a69633

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

dom/html/HTMLLinkElement.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,27 @@ void HTMLLinkElement::
481481
return;
482482
}
483483

484+
// https://html.spec.whatwg.org/#translate-a-preload-destination
485+
// If destination is not "fetch", "font", "image", "script", "style", or
486+
// "track", then return null.
487+
int16_t asValue = asAttr.GetEnumValue();
488+
if (asValue != net::DESTINATION_FETCH &&
489+
asValue != net::DESTINATION_FONT &&
490+
asValue != net::DESTINATION_IMAGE &&
491+
asValue != net::DESTINATION_SCRIPT &&
492+
asValue != net::DESTINATION_STYLE &&
493+
asValue != net::DESTINATION_TRACK) {
494+
// TODO: Currently the spec doesn't define an event handler to be called
495+
// , but this is under discussion.
496+
// See: https://github.com/whatwg/html/issues/10940
497+
//
498+
// Post a "load" event here to match the legacy behavior.
499+
RefPtr<AsyncEventDispatcher> asyncDispatcher = new AsyncEventDispatcher(
500+
this, u"load"_ns, CanBubble::eNo, ChromeOnlyDispatch::eNo);
501+
asyncDispatcher->PostDOMEvent();
502+
return;
503+
}
504+
484505
StartPreload(policyType);
485506
return;
486507
}

netwerk/base/nsNetUtil.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3995,6 +3995,9 @@ bool CheckPreloadAttrs(const nsAttrValue& aAs, const nsAString& aType,
39953995
if (policyType == nsIContentPolicy::TYPE_STYLESHEET) {
39963996
return type.EqualsASCII("text/css");
39973997
}
3998+
if (policyType == nsIContentPolicy::TYPE_JSON) {
3999+
return nsContentUtils::IsJsonMimeType(type);
4000+
}
39984001
return false;
39994002
}
40004003

testing/web-platform/meta/fetch/api/request/destination/fetch-destination.https.html.ini

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@
33
expected:
44
if (os == "win") and debug: [OK, ERROR]
55
if (os == "android") and not debug: [OK, ERROR]
6-
[HTMLLinkElement with rel=preload and as=audio fetches with a "audio" Request.destination]
7-
expected: FAIL
8-
9-
[HTMLLinkElement with rel=preload and as=video fetches with a "video" Request.destination]
10-
expected: FAIL
11-
126
[HTMLLinkElement with rel=preload and as=track fetches with a "track" Request.destination]
137
expected: FAIL
148

testing/web-platform/meta/preload/preload-type-match.html.ini

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,3 @@
5757
[Preload with {as=script; type=text/javascript1.1} should load when retrieved resource is a script]
5858
expected:
5959
if (processor == "x86") and (os == "win") and not debug: [PASS, FAIL]
60-
61-
[Preload with {as=json; type=application/json} should load when retrieved resource is a json]
62-
expected: FAIL
63-
64-
[Preload with {as=json; type=text/json} should load when retrieved resource is a json]
65-
expected: FAIL
66-
67-
[Preload with {as=json; type=application/geo+json} should load when retrieved resource is a json]
68-
expected: FAIL

0 commit comments

Comments
 (0)