Commit graph

550 commits

Author SHA1 Message Date
Yulia Startsev
87c8288cb8 Bug 1247687 - Handle cancellation of long running modules; r=jonco
This is a slightly annoying thing that can happen. When we abruptly cancel (such as an infinitely
running script being forcibly terminated) we will be in a state where the EvaluateModule call will
finish _after_ the loader is destroyed. So, instead we track if there has been a forcible
cancelation, and exit early.

Depends on D155690

Differential Revision: https://phabricator.services.mozilla.com/D155568
2023-01-18 13:46:32 +00:00
Yulia Startsev
84728b24c9 Bug 1247687 - Use requestCredentials to set secFlags for modules; r=jonco
This implements the specified request credentials behavior from the spec, and is tested in wpt.

Depends on D155566

Differential Revision: https://phabricator.services.mozilla.com/D155690
2023-01-18 13:46:32 +00:00
Yulia Startsev
99b0e5f9bb Bug 1247687 - Implement requestCredentials for Module Workers; r=jonco
This weaves credentials through from the private to script creation.

Depends on D155567

Differential Revision: https://phabricator.services.mozilla.com/D155566
2023-01-18 13:46:31 +00:00
Yulia Startsev
221fd06fcd Bug 1247687 - Implement correct referrer for modules; r=jonco
In our implementation, we do not have "client" as a referrer, so we resolve the URI directly as part
of ScriptLoadRequest creation.

Depends on D147327

Differential Revision: https://phabricator.services.mozilla.com/D155567
2023-01-18 13:46:31 +00:00
Yulia Startsev
51e7e0e857 Bug 1247687 - Implement initial Static Module Loading for Workers; r=jonco
This is the first pass of getting static module loading to work. This roughly implements
https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-worklet/module-worker-script-graph --
without some of the settings objects correctly set.

Th WorkerModuleLoader itself is implementing step 5, with the StartFetch method handling moving the work back to the main thread. The algorithm in step 5 is generic to all modules.

Depends on D147329

Differential Revision: https://phabricator.services.mozilla.com/D147327
2023-01-18 13:46:30 +00:00
Yulia Startsev
24d2db5bf6 Bug 1247687 - Disallow ImportScripts from module workers; r=jonco
ImportScripts should be disallowed for module works, which are initialized in the following way:
`new Worker("url", { module:true})`. We set the WorkerType for workers accordingly, and can use that
to detect if import scripts are being incorrectly used.

Depends on D147326

Differential Revision: https://phabricator.services.mozilla.com/D147329
2023-01-18 13:46:30 +00:00
Yulia Startsev
56c6f79308 Bug 1247687 - Implement InitModuleLoader methods for WorkerScriptLoader and WorkerGlobalScope; r=jonco
This implements a method to initialize the moduleLoader for workers. This will initialize only once, for all worker types (module and classic).

Depends on D147324

Differential Revision: https://phabricator.services.mozilla.com/D147326
2023-01-18 13:46:29 +00:00
Jan Varga
72d9bf2d41 Bug 1808685 - Don't use SerialEventTargetGuard in workers code for now; r=dom-worker-reviewers,smaug
Differential Revision: https://phabricator.services.mozilla.com/D166048
2023-01-06 03:11:16 +00:00
Norisz Fay
8cf029b070 Backed out 15 changesets (bug 1247687) as requested by dev CLOSED TREE
Backed out changeset 81d052cabf84 (bug 1247687)
Backed out changeset d698041e5174 (bug 1247687)
Backed out changeset 2adf67f910e8 (bug 1247687)
Backed out changeset 0bc871906e97 (bug 1247687)
Backed out changeset 1700d5b79273 (bug 1247687)
Backed out changeset 31888ffde37a (bug 1247687)
Backed out changeset 9153182c650d (bug 1247687)
Backed out changeset 45de9ffeec19 (bug 1247687)
Backed out changeset 59207e959b7c (bug 1247687)
Backed out changeset 49f18430c465 (bug 1247687)
Backed out changeset 0ae1fd421d4f (bug 1247687)
Backed out changeset 7770ec4717fd (bug 1247687)
Backed out changeset 68b476066248 (bug 1247687)
Backed out changeset c94a9dc60dff (bug 1247687)
Backed out changeset 0ab366c6eaaf (bug 1247687)
2022-12-21 10:48:15 +02:00
Yulia Startsev
dcbacd54c8 Bug 1247687 - Implement csp for Module Workers; r=evilpie,asuth,rpl,ckerschb
Depends on D155691

Differential Revision: https://phabricator.services.mozilla.com/D156102
2022-12-20 20:56:15 +00:00
Yulia Startsev
ef3c7012f8 Bug 1247687 - Handle cancellation of long running modules; r=jonco
This is a slightly annoying thing that can happen. When we abruptly cancel (such as an infinitely
running script being forcibly terminated) we will be in a state where the EvaluateModule call will
finish _after_ the loader is destroyed. So, instead we track if there has been a forcible
cancelation, and exit early.

Depends on D155690

Differential Revision: https://phabricator.services.mozilla.com/D155568
2022-12-20 20:56:14 +00:00
Yulia Startsev
e35e35d3c0 Bug 1247687 - Use requestCredentials to set secFlags for modules; r=jonco
This implements the specified request credentials behavior from the spec, and is tested in wpt.

Depends on D155566

Differential Revision: https://phabricator.services.mozilla.com/D155690
2022-12-20 20:56:14 +00:00
Yulia Startsev
d625cafe6f Bug 1247687 - Implement requestCredentials for Module Workers; r=jonco
This weaves credentials through from the private to script creation.

Depends on D155567

Differential Revision: https://phabricator.services.mozilla.com/D155566
2022-12-20 20:56:13 +00:00
Yulia Startsev
a0b8b2351c Bug 1247687 - Implement correct referrer for modules; r=jonco
In our implementation, we do not have "client" as a referrer, so we resolve the URI directly as part
of ScriptLoadRequest creation.

Depends on D147327

Differential Revision: https://phabricator.services.mozilla.com/D155567
2022-12-20 20:56:13 +00:00
Yulia Startsev
83dd3f6844 Bug 1247687 - Implement initial Static Module Loading for Workers; r=jonco
This is the first pass of getting static module loading to work. This roughly implements
https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-worklet/module-worker-script-graph --
without some of the settings objects correctly set.

Th WorkerModuleLoader itself is implementing step 5, with the StartFetch method handling moving the work back to the main thread. The algorithm in step 5 is generic to all modules.

Depends on D147329

Differential Revision: https://phabricator.services.mozilla.com/D147327
2022-12-20 20:56:13 +00:00
Yulia Startsev
85669b74b0 Bug 1247687 - Disallow ImportScripts from module workers; r=jonco
ImportScripts should be disallowed for module works, which are initialized in the following way:
`new Worker("url", { module:true})`. We set the WorkerType for workers accordingly, and can use that
to detect if import scripts are being incorrectly used.

Depends on D147326

Differential Revision: https://phabricator.services.mozilla.com/D147329
2022-12-20 20:56:12 +00:00
Yulia Startsev
e859be10b8 Bug 1247687 - Implement InitModuleLoader methods for WorkerScriptLoader and WorkerGlobalScope; r=jonco
This implements a method to initialize the moduleLoader for workers. This will initialize only once, for all worker types (module and classic).

Depends on D147324

Differential Revision: https://phabricator.services.mozilla.com/D147326
2022-12-20 20:56:12 +00:00
Csoregi Natalia
c382c6a7ca Backed out 16 changesets (bug 1247687) for frequent string bundle related crashes with PDF viewer (bug 1806064). a=backout
Backed out changeset 721f612fd09f (bug 1247687)
Backed out changeset c6c5750cf713 (bug 1247687)
Backed out changeset 5d05ab0c7cde (bug 1247687)
Backed out changeset 2429599729cb (bug 1247687)
Backed out changeset 55f13fb4ee3f (bug 1247687)
Backed out changeset 354711cf113a (bug 1247687)
Backed out changeset 40b8abaf1c0b (bug 1247687)
Backed out changeset 0c9650a1ac48 (bug 1247687)
Backed out changeset e7b103c79b1a (bug 1247687)
Backed out changeset 4dbd510fb042 (bug 1247687)
Backed out changeset 9276c7e1ddd9 (bug 1247687)
Backed out changeset 6ee318df6641 (bug 1247687)
Backed out changeset 6c129bd72b61 (bug 1247687)
Backed out changeset 4b0a4fcc6894 (bug 1247687)
Backed out changeset 34680059b9f0 (bug 1247687)
Backed out changeset 85b827971a48 (bug 1247687)
2022-12-17 11:27:32 +02:00
Jan Varga
650c726cb3 Bug 1803062 - GetCurrentSerialEventTarget should return the nested event target when a sync loop is running; r=asuth
Differential Revision: https://phabricator.services.mozilla.com/D163841
2022-12-15 05:15:31 +00:00
Yulia Startsev
4916e53611 Bug 1247687 - Implement csp for Module Workers; r=evilpie,asuth,rpl,ckerschb
Depends on D155691

Differential Revision: https://phabricator.services.mozilla.com/D156102
2022-12-14 14:55:38 +00:00
Yulia Startsev
51d7d18a24 Bug 1247687 - Handle cancellation of long running modules; r=jonco
This is a slightly annoying thing that can happen. When we abruptly cancel (such as an infinitely
running script being forcibly terminated) we will be in a state where the EvaluateModule call will
finish _after_ the loader is destroyed. So, instead we track if there has been a forcible
cancelation, and exit early.

Depends on D155690

Differential Revision: https://phabricator.services.mozilla.com/D155568
2022-12-14 14:55:37 +00:00
Yulia Startsev
904f7c679e Bug 1247687 - Use requestCredentials to set secFlags for modules; r=jonco
This implements the specified request credentials behavior from the spec, and is tested in wpt.

Depends on D155566

Differential Revision: https://phabricator.services.mozilla.com/D155690
2022-12-14 14:55:37 +00:00
Yulia Startsev
5ac66699bc Bug 1247687 - Implement requestCredentials for Module Workers; r=jonco
This weaves credentials through from the private to script creation.

Depends on D155567

Differential Revision: https://phabricator.services.mozilla.com/D155566
2022-12-14 14:55:36 +00:00
Yulia Startsev
d3ca0aecd0 Bug 1247687 - Implement correct referrer for modules; r=jonco
In our implementation, we do not have "client" as a referrer, so we resolve the URI directly as part
of ScriptLoadRequest creation.

Depends on D147327

Differential Revision: https://phabricator.services.mozilla.com/D155567
2022-12-14 14:55:36 +00:00
Yulia Startsev
3d4f58ac76 Bug 1247687 - Implement initial Static Module Loading for Workers; r=jonco
This is the first pass of getting static module loading to work. This roughly implements
https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-worklet/module-worker-script-graph --
without some of the settings objects correctly set.

Th WorkerModuleLoader itself is implementing step 5, with the StartFetch method handling moving the work back to the main thread. The algorithm in step 5 is generic to all modules.

Depends on D147329

Differential Revision: https://phabricator.services.mozilla.com/D147327
2022-12-14 14:55:35 +00:00
Yulia Startsev
33b96ee278 Bug 1247687 - Disallow ImportScripts from module workers; r=jonco
ImportScripts should be disallowed for module works, which are initialized in the following way:
`new Worker("url", { module:true})`. We set the WorkerType for workers accordingly, and can use that
to detect if import scripts are being incorrectly used.

Depends on D147326

Differential Revision: https://phabricator.services.mozilla.com/D147329
2022-12-14 14:55:35 +00:00
Yulia Startsev
a40b702d6e Bug 1247687 - Implement InitModuleLoader methods for WorkerScriptLoader and WorkerGlobalScope; r=jonco
This implements a method to initialize the moduleLoader for workers. This will initialize only once, for all worker types (module and classic).

Depends on D147324

Differential Revision: https://phabricator.services.mozilla.com/D147326
2022-12-14 14:55:35 +00:00
Yulia
4763aa8e30 Bug 1247687 - Call EnsureAndLoadStringBundle from Worker ScriptLoaderRunnable; r=allstarschh
Depends on D163238

Differential Revision: https://phabricator.services.mozilla.com/D163239
2022-12-14 14:55:33 +00:00
Stanca Serban
591b091f05 Backed out changeset 6499b9cc1cfc (bug 1803062) for causing worker related failures. CLOSED TREE 2022-12-13 10:21:29 +02:00
Jan Varga
1b5145d00f Bug 1803062 - GetSerialEventTarget should return the nested event target when a sync loop is running; r=asuth
Differential Revision: https://phabricator.services.mozilla.com/D163841
2022-12-13 04:56:35 +00:00
Nika Layzell
8351f7cc2d Bug 1804093 - Part 5: Eliminate WorkerPrincipal and WorkletPrincipals, r=asuth
Differential Revision: https://phabricator.services.mozilla.com/D163856
2022-12-12 22:08:36 +00:00
Jan Varga
860132797b Bug 1803062 - Switch from ordinary bool errors to nsresult errors in code for handling sync loops; r=dom-worker-reviewers,smaug
Differential Revision: https://phabricator.services.mozilla.com/D163559
2022-12-12 16:09:12 +00:00
Yulia Startsev
efb8b72942 Bug 1801833 - ensure release request is only ever done in a lock; r=asuth
Differential Revision: https://phabricator.services.mozilla.com/D162759
2022-11-23 21:02:10 +00:00
Yulia Startsev
d2114afee2 Bug 1801344 - fix iteration over ThreadSafeRequestHandler; r=asuth
This fixes a build error. It was a bit tricker than I expected, comments are inline.

Differential Revision: https://phabricator.services.mozilla.com/D162578
2022-11-21 18:24:22 +00:00
Yulia Startsev
2a09430d95 Bug 1800496 - Revert mCacheCreator to being defined as part of ScriptLoaderRunnable; r=asuth
Previously, in the cancellation refactor, we removed knowledge of the list of scripts being loaded on the main thread. As a result of this, we could no longer clear the cache creator on the main thread after iterating over all requests. We can now do that once again, and it simplifies the code.

Differential Revision: https://phabricator.services.mozilla.com/D162220
2022-11-18 10:02:28 +00:00
Yulia Startsev
ddd2163a1b Bug 1800496 - Re-implement DispatchProcessPendingRequests; r=asuth
This brings back the "group" dispatch that existed before in https://searchfox.org/mozilla-central/rev/e0a7a014f3384ac1abc229d9961f244e3e70a52c/dom/workers/ScriptLoader.cpp#1027-1085

In my view, this is probably an optimization, but it may result in significant behavioral changes as timing has been a major issue with the cancellation refactor. What this does is, if two requests resolve in an order other than post order, then the requests will wait untill all of their dependencies have loaded before firing the dispatch. That means in some cases, we will have only one dispatch instead of two.

Differential Revision: https://phabricator.services.mozilla.com/D162219
2022-11-18 10:02:28 +00:00
Yulia Startsev
92dcd0556e Bug 1800496 - Re-introduce ScriptLoaderRunnable; r=asuth
The ScriptLoaderRunnable used to do double duty as both the runnable used to load a script, and as the data structure to hold on to loading information (what kind of worker, debugger status, etc, if we failed). The second half of these responsibilities remains with the WorkerScriptLoader. WorkerScriptLoader acts as a persistent data structure. ScriptLoaderRunnable is per batch of requests (such as ImportScripts, or a single module load). It works together with the ThreadSafeRequestHandle to load the script.

In the future, when we move to a single threaded implementation, ThreadSafeRequestHandle will likely be merged with WorkerLoadContext, but ScriptLoaderRunnable will stay as a datastructure to represent the batched request, and most of the existing fields (mSyncTarget, the request list) will stay. There is still some massaging to do here, but it gets closer to a final vision of how this should look.

Differential Revision: https://phabricator.services.mozilla.com/D162217
2022-11-18 10:02:27 +00:00
Yulia Startsev
a5b34cfc55 Bug 1800496 - Initial cancellation revert; r=asuth
This returns most of the behavior from https://searchfox.org/mozilla-central/rev/e0a7a014f3384ac1abc229d9961f244e3e70a52c/dom/workers/ScriptLoader.cpp#735-776

What is missing at this point is batch dispatching, as we once again cancel one-at-a-time rather than as a group.

Differential Revision: https://phabricator.services.mozilla.com/D162216
2022-11-18 10:02:27 +00:00
Yulia Startsev
1b7f8a5326 Bug 1800496 - Re-introduce channel tracking for cancellation; r=asuth
This was removed as part of an attempt to simplify worker cancellaton. However, this channel cancellation is important, as without it the timing changes when we finish a request. Without it, we continue to load a script, even after a worker has been shut down.

This tracking will help us reimplement cancellation.

Differential Revision: https://phabricator.services.mozilla.com/D162215
2022-11-18 10:02:26 +00:00
Yulia Startsev
32c96913a6 Bug 1800496 - Re-introduce Cycle Collected LoadContextBase for Workers; r=jonco
The non-cycle collected LoadContextBase caused failures for Module Workers. This reverts that change

Differential Revision: https://phabricator.services.mozilla.com/D162214
2022-11-18 10:02:26 +00:00
Yulia Startsev
2310f5b5b6 Bug 1800496 - Introduce ThreadSafeRequestHandle; r=asuth
This introduces a new datastructure that wraps the ScriptLoadRequest. Previously, we were using the WorkerLoadContext to access the request, and we made it not cycle collected in order to make it safe across threads. This, of course, broke module behavior, as the cycle needs to be broken in more places, and things get rather complex.

In the spirit of making everyone's life easier, the ThreadSafeRequestHandle exists as a way to move the request to the main thread, operate on it, and then return it to the worker. We no longer need to track and free the WorkerLoadContext. Once the ThreadSafeRequestHandle is returned to the worker, we release the request, and the handle is empty. There is a possibility that this will cause issues, so we should keep an eye on this. Alternatively, we can never release the ScriptLoadRequest and let the ThreadSafeRequestHandle clean it up on destruction.

In the case that we somehow end up releasing on the main thread, we will send a runnable to release the request correctly on the worker.

Differential Revision: https://phabricator.services.mozilla.com/D162213
2022-11-18 10:02:25 +00:00
Yulia Startsev
b122d68410 Bug 1800496 - Prep: Use nsISerialEventTarget for WorkerScriptLoader classes; r=dom-workers-and-storage-reviewers,asuth
We will be using the mSyncLoopTarget for module promises, and for returning to the worker thread
when cleaning up for ThreadSafeRequestHandle.

Differential Revision: https://phabricator.services.mozilla.com/D162212
2022-11-18 10:02:25 +00:00
Daniel Holbert
7f83cbcfba Bug 1800342: Make NS_NewPipe2 and NS_NewPipe infallible, to reflect reality. r=xpcom-reviewers,necko-reviewers,nika,kershaw
This patch doesn't change behavior; these APIs were already effectively
infallible, in the sense that it was impossible for them to return anything
other than NS_OK.

The actual API changes here are in xpcom/io/nsIPipe.idl and
xpcom/io/nsPipe3.cpp, and the rest of this patch is just updates to callsites,
removing code that handled failure-flavored return values from these functions.
(All of this removed code was already dead code, effectively.)

Differential Revision: https://phabricator.services.mozilla.com/D161947
2022-11-14 23:22:16 +00:00
Yulia Startsev
d2fa4ee51a Bug 1798667 - clear cache when finished with service worker scripts; r=asuth
I was over eager in introducing the strong pointers to WorkerLoadContext. It turns out that
previously when we were cycle collecting our ScriptLoadRequests, we were also cleaning up everything
related to WorkerLoadContext. Also, in an attempt to fix the cancellation for workers, We
accidentally stopped cleaning up the reference to the cache creator. This patch does the following:

1) cleans up the cache creator reference whenever we finish with a cache load handler. This is done
by calling Fail appropriately. This solves both bug 1798667 (we no longer reach NEW_URI if we fail)
and 1781295 (we no longer leak memory because things were not cleaned up properly).
2) Does no remove the back reference to WorkerLoadContext from the LoadRequest. It turns out that
this is sometimes necessary. There is a chance that we will accidently try to access the
WorkerLoadContext after cancellation. This actually causes problems later on in the module code.

Differential Revision: https://phabricator.services.mozilla.com/D161288
2022-11-04 15:04:27 +00:00
Yulia Startsev
088ae95178 Bug 1797327 - Use RefPtrs for all WorkerLoadContexts; r=asuth
As WorkerLoadContexts now inherit from a non-CC'd loadContextBase, we have two outcomes.
1) we need to break cycles with ScriptLoadRequests manually, so that ScriptLoadRequests can be collected (ScriptLoadRequests must be CC'd).
2) we can now have refptrs to WorkerLoadContexts in the CacheLoadHandler and NetworkLoadHandler classes, and remove any remaining raw pointers to ScriptLoadRequest/WorkerLoadContext. There are cases where the NetworkLoadHandler or CacheLoadHandler might outlive the Worker Loader, so having refpointers here should help us recover in those cases.

Differential Revision: https://phabricator.services.mozilla.com/D160334
2022-11-01 18:03:34 +00:00
Jan Varga
940cf12bc4 Bug 1791747 - AutoSyncLoopHolder::GetEventTarget should return nsISerialEventTarget (instead of nsIEventTarget); r=dom-worker-reviewers,smaug
Differential Revision: https://phabricator.services.mozilla.com/D157805
2022-10-28 06:18:10 +00:00
Yulia Startsev
e6ba9b8b31 Bug 1792984 - Introduce asserts and refptrs r=asuth
Differential Revision: https://phabricator.services.mozilla.com/D158425
2022-10-18 16:20:13 +00:00
Yulia Startsev
a23d8dce11 Bug 1792984 - Introduce aggressive cancellation r=asuth
Differential Revision: https://phabricator.services.mozilla.com/D158558
2022-10-18 16:20:12 +00:00
Iulian Moraru
160a1a400d Backed out 3 changesets (bug 1792984) for causing multiple failures. CLOSED TREE
Backed out changeset 82816b3aa215 (bug 1792984)
Backed out changeset 4e8cea95745a (bug 1792984)
Backed out changeset 44324c5af215 (bug 1792984)
2022-10-13 16:31:35 +03:00
Yulia Startsev
ea70cc191e Bug 1792984 - Introduce asserts r=asuth
Differential Revision: https://phabricator.services.mozilla.com/D158425
2022-10-13 10:53:48 +00:00