Commit Graph
55 Commits
Author SHA1 Message Date
agoloman c75e2e420f Revert "Bug 2020707, Bug 2020704 - Part 6: Update test expectations now that speculationrules scripts are supported. r=dom-core-reviewers,jjaschke" for causing bc failures @browser_misused_characters_in_strings.js.
This reverts commit 524a1fc191.

Revert "Bug 2020707 - Part 5: Gate speculation rules script support behind a pref. r=dom-core-reviewers,jjaschke"

This reverts commit 11741d18ad.

Revert "Bug 2020707 - Part 4: Unregister speculation rules when their script element is removed. r=dom-core-reviewers,hsivonen"

This reverts commit 5202943dc9.

Revert "Bug 2020707 - Part 3: Report an exception if speculation rules parsing fails. r=dom-core-reviewers,jjaschke"

This reverts commit 70c5aa5425.

Revert "Bug 2020707 - Part 2: Add support for speculationrules script type. r=dom-core-reviewers,jjaschke"

This reverts commit 65b30a350b.

Revert "Bug 2020707 - Part 1: Allow speculation rules to be registered to the document from scripts. r=hsivonen,jjaschke"

This reverts commit 28c7050de9.

Revert "Bug 2020704 - Part 2: Add parser for speculation rule sets. r=hsivonen,jjaschke"

This reverts commit eabb8c6eb3.

Revert "Bug 2020704 - Part 1: Add speculation rules crate. r=dom-core-reviewers,jjaschke"

This reverts commit cd65bed005.
2026-06-12 06:28:05 +00:00
Adam Vandolder 11741d18ad Bug 2020707 - Part 5: Gate speculation rules script support behind a pref. r=dom-core-reviewers,jjaschke
Differential Revision: https://phabricator.services.mozilla.com/D305775
2026-06-12 04:48:34 +00:00
Adam Vandolder 65b30a350b Bug 2020707 - Part 2: Add support for speculationrules script type. r=dom-core-reviewers,jjaschke
Differential Revision: https://phabricator.services.mozilla.com/D286178
2026-06-12 04:48:27 +00:00
Olli Pettay 05c9d79ee7 Bug 2044400 - moving text nodes to script element should not run the script, r=dom-core,jjaschke
Differential Revision: https://phabricator.services.mozilla.com/D304136
2026-06-03 01:03:54 +00:00
Emilio Cobos Álvarez 540e192403 Bug 2025402. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D289495
2026-03-26 12:28:34 +00:00
Sylvestre Ledru 9eb1a31a98 Bug 2023419 - Remove Emacs/Vim modelines from dom/ r=emilio,media-playback-reviewers,webidl,padenot
replaced by .editorconfig
# ignore-this-changeset

Differential Revision: https://phabricator.services.mozilla.com/D287843
2026-03-16 21:02:32 +00:00
Frédéric Wang d2478ad5f9 Bug 1997818 - Improve parser blocking for ScriptElement::MaybeProcessScript(). r=smaug
When processing a non-trusted inline script, we must run a TrustedTypes
default policy callback on the source text, which in particular may:
- Generally be executed asynchronously in a script runner (thus
  requiring to block the parser in the meantime).
- Modify the script type, for example between classic and module (thus
  changing the expected blocking behavior for the parser).

Currently, ScriptElement::MaybeProcessScript() returns a boolean
telling callers whether they need to block the parser. Most callers
ignore it but for those that don't, the behavior described above make it
impossible to know the correct desired returned value in advance for
non-trusted inline scripts. Current code always always tell callers not
to block the parser, which is incorrect and causing assertion failures.

This patch adds an optional nsIParser argument to MaybeProcessScript(),
which becomes responsible of blocking the parser when needed. For
external and trusted inline scripts we can continue to try and process
the script immediately and use the result to determine whether to block
the parser. Similarly, for non-trusted inline scripts in context where
it is safe to run script, we can run the default policy callback before
the processing attempt and blocking decision.

For non-trusted inline scripts with a default policy callback that need
to be executed in a script runner, we always block the parser while
waiting that script runner to be executed and only decide to unblock it
after the attempt to process the script.

Differential Revision: https://phabricator.services.mozilla.com/D272372
2025-12-08 14:08:33 +00:00
Frédéric Wang 5641e22232 Bug 2001929 Don't use a AddScriptRunner when processing untrusted inline scripts in a document without TrustedTypes enforcement. r=smaug
Currently, for untrusted inline scripts, ScriptElement's
MaybeProcessScript() will always:

1) Run GetTrustedTypesCompliantInlineScriptText() in a script runner.
2) Call MaybeProcessScript(nsAString&) with the retrieved source.
3) Return false to indicate parser should not be blocked.

In various cases (no CSP enforcement, web extension, UA widget, etc),
step 1 won't actually run the default policy and the raw string will
be used instead. Consequently, we can just do the same processing as
for trusted script i.e. immediately call and return the result of
MaybeProcessScript(nsAString&), lazily retrieving the source text.

Note that step 3 is incorrect in cases when a script runner is still
needed, but this will be handled in bug 1997818.

Differential Revision: https://phabricator.services.mozilla.com/D273776
2025-12-08 11:48:09 +00:00
Henri Sivonen b1685935b1 Bug 1968903 - Avoid creating script and CSS loaders for documents loaded as data. r=firefox-style-system-reviewers,emilio,layout-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D264779
2025-10-20 15:49:01 +00:00
Cristina Horotan f21b53b704 Revert "Bug 1968903 - Avoid creating script and CSS loaders for documents loaded as data. r=firefox-style-system-reviewers,emilio,layout-reviewers" for causing bug 1991800
This reverts commit 6cbdfe15a0.
2025-10-01 07:15:03 +00:00
Henri Sivonen 6cbdfe15a0 Bug 1968903 - Avoid creating script and CSS loaders for documents loaded as data. r=firefox-style-system-reviewers,emilio,layout-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D264779
2025-09-30 10:27:43 +00:00
agoloman 0a11d7413f Revert "Bug 1968903 - Avoid creating script and CSS loaders for documents loaded as data. r=firefox-style-system-reviewers,emilio,layout-reviewers" for causing multiple wpt failures.
This reverts commit f83cb28789.
2025-09-30 09:25:22 +00:00
Henri Sivonen f83cb28789 Bug 1968903 - Avoid creating script and CSS loaders for documents loaded as data. r=firefox-style-system-reviewers,emilio,layout-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D264779
2025-09-30 07:45:53 +00:00
Frédéric Wang 9a0ef0f5ea Bug 1986632 - Exempt (isolated) WebExtension content scripts from trusted types policies. r=smaug,webidl,robwu,dom-worker-reviewers,asuth
This is a follow-up of bug 1947732, covering the remaining Trusted Types checks:

- Document.write/writeln
- WorkerGlobalScope.importScripts
- eval and new Functions
- script enforcement
- pre-navigation check

Differential Revision: https://phabricator.services.mozilla.com/D263688
2025-09-26 17:34:04 +00:00
Masayuki Nakano f8236195a0 Bug 769207 - part 3: Make nsIMutationObserver use AttrModType r=smaug,dom-core,firefox-style-system-reviewers,layout-reviewers,emilio
Differential Revision: https://phabricator.services.mozilla.com/D263054
2025-09-08 00:27:40 +00:00
Frédéric Wang 163aea67f3 Bug 1928932 - Part 2 - Implement enforcements for untrusted script elements. r=smaug
Spec: https://w3c.github.io/trusted-types/dist/spec/#enforcement-in-scripts
PR: https://github.com/w3c/trusted-types/pull/579/

Differential Revision: https://phabricator.services.mozilla.com/D251855
2025-09-02 20:04:40 +00:00
Edgar Chen d9023d2f74 Bug 1973704 - Run microtask checkpoint before prepare-the-script-element steps in parser; r=smaug,hsivonen
Differential Revision: https://phabricator.services.mozilla.com/D259225
2025-08-14 04:43:16 +00:00
Emilio Cobos Álvarez 791917d8af Bug 1976665 - Sort headers in dom/. r=dom-core,media-playback-reviewers,webrtc-reviewers,dom-storage-reviewers,padenot,janv,smaug,jesup,jib
Most changes are automated. Relevant bit is dom/.clang-format. I had to
manually disable clang-format in a few places where importing external
files and so on that aren't self-contained, and fix a couple includes /
forward declarations.

Differential Revision: https://phabricator.services.mozilla.com/D256800
2025-08-05 11:47:34 +00:00
Frédéric Wang 4cca1cbaa3 Bug 1928932 - Part 1 - Add an mIsTrusted flag on script elements. r=smaug,credential-management-reviewers,dimi
This flag can be modified when notifying for character data change,
content appending, content insertion and content removal by specifying
a MutationEffectOnScript flag. By default callers other than the HTML5
parsers always specify "drop trustworthiness" but mIsTrusted flag is not
used anyway, so there is no behavior change.

Spec: https://w3c.github.io/trusted-types/dist/spec/#enforcement-in-scripts
PR: https://github.com/w3c/trusted-types/pull/579/

Differential Revision: https://phabricator.services.mozilla.com/D252020
2025-06-27 15:23:24 +00:00
Cosmin Sabou a15f457eb6 Revert "Bug 1928932 - Part 1 - Add an mIsTrusted flag on script elements. r=smaug,credential-management-reviewers,dimi" for causing macOS build bustages on nsMenuGroupOwnerX.mm
This reverts commit ce2493cdd4.
2025-06-27 12:30:03 +00:00
Frédéric Wang ce2493cdd4 Bug 1928932 - Part 1 - Add an mIsTrusted flag on script elements. r=smaug,credential-management-reviewers,dimi
This flag can be modified when notifying for character data change,
content appending, content insertion and content removal by specifying
a MutationEffectOnScript flag. By default callers other than the HTML5
parsers always specify "drop trustworthiness" but mIsTrusted flag is not
used anyway, so there is no behavior change.

Spec: https://w3c.github.io/trusted-types/dist/spec/#enforcement-in-scripts
PR: https://github.com/w3c/trusted-types/pull/579/

Differential Revision: https://phabricator.services.mozilla.com/D252020
2025-06-27 11:18:48 +00:00
Frédéric Wang 5b2f8ce346 Bug 1972280 - Test whether script's text is non-empty in ScriptElement::MaybeProcessScript. r=smaug
Currently logic is duplicated in HTMLScriptElement and SVGScriptElement's
HasScriptContent() implementations. Rename these methods to only check
hether we have external script content, and move the check for inline
script content directly in ScriptElement::MaybeProcessScript.

Differential Revision: https://phabricator.services.mozilla.com/D253789
2025-06-17 09:36:12 +00:00
Andrew McCreight c93eafe89d Bug 1286026 - Don't warn for invalid WebGL script types, and include the invalid script type. r=dom-core,farre
This patch changes the invalid script tag warning to actually include the
invalid tag, which makes it easier to understand what is going wrong.

WebGL pages use invalid types on script elements to store strings. These three
specific strings are used in hundreds of places in our WebGL tests, so don't
warn for them. The first two can be found in WebGL tutorials, so this seems like
an actual convention. "text/something-not-javascript" looks like it is only
used in the WebGL conformance tests, but it is clearly deliberately invalid
so skip warning for it, too, in the interests of reducing warning spam.

I didn't use NS_WARNING_ASSERTION here because that includes the entire
expression that failed, and that is large and not very useful.

Differential Revision: https://phabricator.services.mozilla.com/D212799
2024-06-07 13:15:28 +00:00
Tom Schuster 694c3e8534 Bug 1872839 - Remove aMimeTypeGuess parameter from nsIContentPolicy. r=freddyb
Differential Revision: https://phabricator.services.mozilla.com/D197794
2024-01-08 15:47:42 +00:00
Henri Sivonen 5d0c7d7cd6 Bug 1846178 - Use the async/defer (non-blocking) HTML parser code path for module scripts. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D185797
2023-09-15 07:53:16 +00:00
Norisz Fay 98abe042d7 Backed out changeset 4a4d5e64aec5 (bug 1846178) for causing mochitest failures on test_script_loader_js_cache.html/cache_module.html CLOSED TREE 2023-08-23 11:19:39 +03:00
Henri Sivonen f77548b084 Bug 1846178 - Use the async/defer (non-blocking) HTML parser code path for module scripts. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D185797
2023-08-23 07:11:47 +00:00
Emilio Cobos Álvarez 529c9ee321 Bug 1839922 - Remove usage of {Has,Get}Attr(kNameSpaceID_None, ..). r=edgar
We have more readable and faster versions (that just omit the namespace
arg).

Mostly done via sed, with a couple helpers to use the faster lookups
where possible.

Differential Revision: https://phabricator.services.mozilla.com/D181795
2023-06-23 10:01:32 +00:00
CanadaHonk 23e171e2af Bug 1834134 - Create base ScriptElement GetScriptType method r=peterv
SVG and HTML ScriptElements now use a new base GetScriptType common
method instead of an individual duplicate implementation.

Make a big (unimportant) meta bug to do more of this later?
(avoids code duplication between SVG and HTML, updates old SVG code).

160 WPT subtests newly pass (100% in this test file) 🎉

Differential Revision: https://phabricator.services.mozilla.com/D180200
2023-06-22 19:42:30 +00:00
Adam Vandolder bec905b437 Bug 1827512 - Properly handle type and src attribute changes on script tags. r=smaug
Modifies the preparation of script tags in order to better follow the
specification. Now, scripts are only considered to have already started
if they have a valid type when being prepared, and only changes to the
src attribute trigger script preparation, instead of for all attributes.
This allows script tags to be re-run after their type and src are
modified, if they haven't run already.

Differential Revision: https://phabricator.services.mozilla.com/D175795
2023-06-14 04:00:09 +00:00
Nicolas Chevobbe 26e193b4f7 Bug 1818768 - Turn ScriptLoadContext mLineNo unsigned. r=hsivonen.
Differential Revision: https://phabricator.services.mozilla.com/D170919
2023-02-28 12:07:31 +00:00
Adam Vandolder de848dc97f Bug 1632975 - Run microtask checkpoint before processing script. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D162261
2022-11-17 20:11:23 +00:00
Cristian Tuns 1c2ac70ddb Backed out changeset dd72eb737d96 (bug 1632975) for causing Bug 1800981 CLOSED TREE 2022-11-16 19:15:14 -05:00
Adam Vandolder 488ac43500 Bug 1632975 - Run microtask checkpoint before processing script. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D160988
2022-11-15 20:24:15 +00:00
Adam Vandolder fcf4d44734 Bug 1784187 - Process scripts even if they contain no text content. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D156086
2022-10-05 15:16:28 +00:00
Jan-Niklas Jaeschke a88c7c233d Bug 1777925: Replaced MutationObserver array container type with linked list. r=smaug
Deletion of mutation observers from a list resulted in O(n^2) behavior and could lead to massive freezes.
This is resolved by using a LinkedList instead, reducing complexity to O(n).

A safely iterable doubly linked list was implemented based on `mozilla::DoublyLinkedList`,
allowing to insert and remove elements while iterating the list.

Due to the nature of `mozilla::DoublyLinkedList`, every Mutation Observer now inherits `mozilla::DoublyLinkedListElement<T>`.
This implies that a Mutation Observer can only be part of one DoublyLinkedList.
This conflicts with some Mutation Observers, which are being added to multiple `nsINode`s.
To continue supporting this, new MutationObserver base classes `nsMultiMutationObserver` and `nsStubMultiMutationObserver` are introduced,
which create `MutationObserverWrapper` objects each time they are added to a `nsINode`.
The wrapper objects forward every call to the actual observer.

Differential Revision: https://phabricator.services.mozilla.com/D157031
2022-09-21 11:31:44 +00:00
Simon Giesecke 46908cfb51 Bug 1660470 - Add missing include directives/forward declarations. r=nika
Differential Revision: https://phabricator.services.mozilla.com/D87865
2020-11-23 16:21:38 +00:00
Simon Giesecke a69d79b6db Bug 1648010 - Replace uses of NS_LITERAL_STRING/NS_LITERAL_CSTRING macros by _ns literals. r=geckoview-reviewers,jgilbert,agi,hsivonen,froydnj
Differential Revision: https://phabricator.services.mozilla.com/D80860
2020-07-01 08:29:29 +00:00
Boris Zbarsky 490a516cd4 Bug 325352 part 1. Align our "defined insertion point" concept more closely with the spec's "script nesting level" concept. r=hsivonen
This also exposes an accessor for whether the parser has a nonzero script nesting level.

Differential Revision: https://phabricator.services.mozilla.com/D30313
2019-05-08 06:10:47 +00:00
Ryan Hunt ad7b7dbb30 Bug 1523969 part 6 - Move method definition inline comments to new line in 'dom/'. r=nika
Differential Revision: https://phabricator.services.mozilla.com/D21106
2019-02-25 16:05:29 -06:00
Emilio Cobos Álvarez dc336a73ba Bug 1517241 - Rename nsIDocument to mozilla::dom::Document. r=smaug
Summary: Really sorry for the size of the patch. It's mostly automatic
s/nsIDocument/Document/ but I had to fix up in a bunch of places manually to
add the right namespacing and such.

Overall it's not a very interesting patch I think.

nsDocument.cpp turns into Document.cpp, nsIDocument.h into Document.h and
nsIDocumentInlines.h into DocumentInlines.h.

I also changed a bunch of nsCOMPtr usage to RefPtr, but not all of it.

While fixing up some of the bits I also removed some unneeded OwnerDoc() null
checks and such, but I didn't do anything riskier than that.
2019-01-03 17:48:33 +01:00
Sylvestre Ledru e5a134f73a Bug 1511181 - Reformat everything to the Google coding style r=ehsan a=clang-format
# ignore-this-changeset
2018-11-30 11:46:48 +01:00
Emilio Cobos Álvarez 0348c342b8 Bug 1470930: Use enums for passing arguments for event dispatch. r=smaug
MozReview-Commit-ID: DsNuF7GAflJ
2018-06-26 18:22:06 +02:00
Emilio Cobos Álvarez 0ff849122a Bug 1442207: Remove unneeded arguments to nsIMutationObserver. r=smaug
aDocument is always content->OwnerDoc().
aContainer is always content->GetParent().

Differential Revision: https://phabricator.services.mozilla.com/D664

MozReview-Commit-ID: 4xwPCOnhyIL
2018-03-01 22:45:17 +01:00
Emilio Cobos Álvarez 7a79ccba52 Bug 1441547: Make character data change notifications use a const reference for the info parameter. r=smaug
It's not intended to be mutated.

MozReview-Commit-ID: 5nkD1YkidlV
2018-02-27 15:30:27 +01:00
Jon Coppeard 69ebe1854a Bug 1361369 - Allow async attribute on inline module scripts r=smaug 2018-01-08 15:17:34 +00:00
Jon Coppeard 01fbc05c08 Bug 1421259 - Fix error events fired when loading JS module dependencies fail r=baku 2017-12-01 13:12:48 +00:00
Nicholas Nethercote 7dbfdaf890 Bug 1400460 - Rename nsIAtom as nsAtom. r=hiro.
(Path is actually r=froydnj.)

Bug 1400459 devirtualized nsIAtom so that it is no longer a subclass of
nsISupports. This means that nsAtom is now a better name for it than nsIAtom.

MozReview-Commit-ID: 91U22X2NydP
2017-10-03 09:05:19 +11:00
Catalin Badea fc6ab5f0ea Bug 651120 - Remove index argument from content removed/appended/inserted notifications. r=peterv 2017-10-03 11:09:08 +01:00
Andrea Marchesini d4f5a2f5ea Bug 1362119 - part 2 - Fixing the code style in dom/script, r=ehsan 2017-05-08 08:25:03 +02:00