gecko-dev/dom
Andrew Sutherland c4e657f4da Bug 1662925 - Make SW fetch events properly queue. r=dom-workers-and-storage-reviewers,janv
Excerpting some documentation I wrote up for an OVERVIEW.md for Service
Workers for this exact use situation below.  The basic situation of this patch
is that we were trying to create the FetchEventOpProxyParent immediately
before the managing PRemoteWorker instance existed, which isn't a thing we can
do.  Because FetchEvent ops are more complicated they require somewhat more
unique handling, but it should have been unified with the PendingOp
infrastructure and was not.  The one notable thing going on actor-wise is that
the request body (if present) requires special RemoteLazyInputStream
serialization and this is something that can only be done once we have the
RemoteWorkerParent.  See https://phabricator.services.mozilla.com/D73173 and
its commit message and my "Restating" blocks for more context.


### Threads and Proxies

#### Main Thread

ServiceWorkerManager's authoritative ServiceWorker state lives on the main
thread in the parent process.  This is due to a combination of legacy factors
and that currently the nsHttpChannel AsyncOpen logic where navigation
interception occurs must be on the main thread.

#### IPDL Background Thread

The IPDL Background Thread is the thread where PBackground parent actors are
created.  Because IPDL actors are explicitly tied to the thread they are created
on and PBackground is the only top-level protocol created for use by DOM
Workers, this thread is the natural home for book-keeping and authoritative
state for APIs that are accessed via PBackground-managed protocols.  For
example, IndexedDB and other QuotaManager-managed storage APIs.

The Remote Worker APIs are all PBackground managed and so all messages sent via
the Remote Worker API need to be sent from the IPDL Background thread.

#### Main Thread to IPDL Background Proxies

There are 2 ways to get data from the main thread to the IPDL Background thread:
either via direct runnable dispatch or via IPDL IPC.  We use IPDL IPC (which
has optimizations for same-process communication).

The following interfaces exist exclusively to proxy requests from the
ServiceWorkerManager on the main thread to the IPDL Background thread.
- `PRemoteWorkerController` is a proxy wrapper around the
  `RemoteWorkerController` API exposed on the IPDL Background thread.
- `PFetchEventOp` is paired with `PFetchEventOpProxy` managed by the above
  `PRemoteWorkerController`.  `PFetchEventOp` gets the data to the IPDL
  Background thread from the main thread, then `PFetchEventOpProxy` gets the
  data down to the content process.

## Non-Fetch ServiceWorker events AKA ExtendableEvents
How non-fetch events are dispatched to the serviceworker (including the IPC).

Because ServiceWorkers are intended to be shutdown and restarted on demand and
most event processing is asynchronous, there needs to be a way to track
outstanding requests and for content logic to indicate when it is done
processing requests.  `ExtendableEvent`s are the mechanism for this.  A method
`waitUntil(promise)` adds promises to be track as long as the event is still
"active".

This straightforward lifecycle means that these events map well to our IPC
async return value mechanism.  This is used by
`PRemoteWorker::ExecServiceWorkerOp`.

## Fetch events and FetchEvent.respondWith()

`FetchEvent`s have a different lifecycle and dataflow than regular
`ExtendableEvents`.  They expose a `respondWith()` method that will eventually
resolve with a fetch `Response` object that potentially needs to be propagated
before the ExtendableEvent is no longer active.  (The response will never be
propagated after `waitUntil()` settles because every call to `respondWith()`
implicitly calls `waitUntil()`.)

From an IPC perspective, this means that `FetchEvent` instances need their own
IPC actor rather than being able to depend on the async return value mechanism
of IPDL.  That's why `PFetchEventOpProxy` exists and is managed by
`PRemoteWorker`.

Differential Revision: https://phabricator.services.mozilla.com/D92021
2020-10-07 16:02:24 +00:00
..
abort Bug 1660954. r=smaug 2020-09-21 22:11:19 +00:00
animation Bug 1666617 - Add an observer description argument to AddRefreshObserver. r=smaug 2020-09-25 02:36:29 +00:00
audiochannel
base Bug 1666683 - Part 6: Add ScriptPreloader::FillCompileOptionsForCachedScript. r=tcampbell,kmag 2020-10-06 21:16:57 +00:00
battery
bindings Bug 1668825 - Remove unused onChild return value r=sfink 2020-10-05 07:55:13 +00:00
broadcastchannel Bug 1665165 - Disable some bfcache tests on Fission, r=jesup 2020-09-17 17:36:24 +00:00
browser-element Bug 1651519: Part 2 - Also remove nsIDOMWindowUtils::outerWindowID. r=nika,geckoview-reviewers,agi 2020-08-17 20:22:12 +00:00
cache Bug 1666219 - Renamed QM_TRY_VAR etc. to QM_TRY_UNWRAP etc. r=dom-workers-and-storage-reviewers,ttung,janv 2020-10-02 13:23:49 +00:00
canvas Bug 1663214 - Explain what format/types ReadPixels expects. r=lsalzman 2020-10-06 19:02:58 +00:00
chrome-webidl Bug 1662839 - Set author style disabled state correctly on newly created iframes. r=mattwoodrow 2020-10-04 03:25:16 +00:00
clients Bug 1664542 - Part 1: Fix client.openWindow/COOP+COEP crash, r=asuth 2020-09-24 16:34:26 +00:00
commandhandler
console Bug 1650145 - Replace all value uses of Empty[C]String by 0-length _ns literals. r=froydnj,geckoview-reviewers,agi 2020-09-23 15:17:15 +00:00
credentialmanagement
crypto
debugger
docs Bug 1667831 - doc: refresh links as many pages moved in-tree r=firefox-source-docs-reviewers,ahal DONTBUILD 2020-09-29 17:53:54 +00:00
encoding
events Bug 1666497 - Don't flush layout from popuppositioned events. r=mconley,Gijs,smaug 2020-10-06 16:28:41 +00:00
fetch Bug 1650145 - Replace all value uses of Empty[C]String by 0-length _ns literals. r=froydnj,geckoview-reviewers,agi 2020-09-23 15:17:15 +00:00
file Bug 1589337 - Use nsIClassInfoImpl in nsSimpleURI and children r=necko-reviewers,kershaw,xpcom-reviewers,nika 2020-09-29 11:41:26 +00:00
filehandle
filesystem Bug 1650145 - Replace all value uses of Empty[C]String by 0-length _ns literals. r=froydnj,geckoview-reviewers,agi 2020-09-23 15:17:15 +00:00
flex Bug 1667594 - Avoid including nsLayoutUtils.h in nsContainerFrame.h. r=emilio 2020-09-26 18:19:14 +00:00
gamepad Bug 1660660 - Fix deadlock in gamepad initialization code. r=cmartin 2020-08-24 17:06:58 +00:00
geolocation
grid
html Bug 1660928 - Record video play time telemetry if we had a non-empty video track at any point. r=jya 2020-10-06 01:47:14 +00:00
imptests
indexedDB Bug 1653276 - Ensure that IndexedDB operations are cancelled when nsGlobalWindowInner::FreeInnerObjects is called. r=dom-workers-and-storage-reviewers,janv 2020-10-07 14:38:50 +00:00
interfaces Bug 1667081 - Part 9: Remove SetFocusedWindowWithCallerType in nsIFocusManager; r=hsivonen 2020-09-29 07:22:45 +00:00
ipc Bug 1661364 - Part 6: Give the recycled process background process priority, r=kmag,jesup 2020-09-14 13:45:49 +00:00
jsurl Bug 1589337 - Use nsIClassInfoImpl in nsSimpleURI and children r=necko-reviewers,kershaw,xpcom-reviewers,nika 2020-09-29 11:41:26 +00:00
l10n Bug 1666419: Assert IsSafeToRunScript. r=emilio 2020-09-28 06:29:44 +00:00
locales Bug 1657701 - Localize the media control Firefox is now playing fallback text r=alwu,zbraniecki 2020-10-02 10:02:00 +00:00
localstorage Bug 1666219 - Renamed QM_TRY_VAR etc. to QM_TRY_UNWRAP etc. r=dom-workers-and-storage-reviewers,ttung,janv 2020-10-02 13:23:49 +00:00
manifest
mathml Bug 1667719: Add preferences, warnings and telemetry for the scriptminsize and scriptsizemultiplier attributes. r=emilio 2020-09-28 14:12:27 +00:00
media Bug 1669406 - add pref to blocklist codecs for WebRTC testing;r=dminor 2020-10-07 14:26:37 +00:00
messagechannel Bug 1650145 - Replace all value uses of Empty[C]String by 0-length _ns literals. r=froydnj,geckoview-reviewers,agi 2020-09-23 15:17:15 +00:00
midi
network Bug 1650145 - Replace all value uses of Empty[C]String by 0-length _ns literals. r=froydnj,geckoview-reviewers,agi 2020-09-23 15:17:15 +00:00
notification Bug 1650145 - Replace all value uses of Empty[C]String by 0-length _ns literals. r=froydnj,geckoview-reviewers,agi 2020-09-23 15:17:15 +00:00
offline Bug 1665355 - Don't throw on appcache.update() if the storage is disabled r=baku 2020-09-18 13:57:11 +00:00
payments Bug 1665252 - remove allowpaymentrequest attribute from HTMLIFrameElement r=dom-workers-and-storage-reviewers,smaug,asuth 2020-10-05 05:45:38 +00:00
performance Backed out 10 changesets (bug 1518999) for GeckoView failures in PanZoomControllerTest.scroll. CLOSED TREE 2020-09-17 02:58:34 +03:00
permission
plugins Bug 1667863 - Replace AppendToString of IntSizeTyped with ostream usage. r=mattwoodrow 2020-09-29 02:58:35 +00:00
power Bug 1659060 - part1 : treat lock visible if corresponding document has in use picture-in-picture element. r=bryce,smaug 2020-09-23 23:34:12 +00:00
presentation Bug 1265275 - Removed 'using namespace mozilla;' and 'using namespace mozilla::dom;' wih namespace mozilla {..} namespace dom {..} in PresentationSessionInfo.cpp r=smaug 2020-10-06 10:33:16 +00:00
prio
promise Bug 1666419: Assert IsSafeToRunScript. r=emilio 2020-09-28 06:29:44 +00:00
prototype Bug 1650145 - Replace all value uses of Empty[C]String by 0-length _ns literals. r=froydnj,geckoview-reviewers,agi 2020-09-23 15:17:15 +00:00
push Bug 1650145 - Replace all value uses of Empty[C]String by 0-length _ns literals. r=froydnj,geckoview-reviewers,agi 2020-09-23 15:17:15 +00:00
quota Bug 1666219 - Renamed QM_TRY_VAR etc. to QM_TRY_UNWRAP etc. r=dom-workers-and-storage-reviewers,ttung,janv 2020-10-02 13:23:49 +00:00
reporting Bug 1657033 - Use Span<const char> in JSONWriter - r=froydnj 2020-09-14 02:33:20 +00:00
res
script Bug 1667915 - Separate marker category from marker options - r=gregtatum 2020-10-01 11:02:23 +00:00
security Backed out changeset aaf5c5213d8d (bug 1665062) for perma failures on test_http_background_auth_request.html. CLOSED TREE 2020-10-07 17:51:55 +03:00
serviceworkers Bug 1662925 - Make SW fetch events properly queue. r=dom-workers-and-storage-reviewers,janv 2020-10-07 16:02:24 +00:00
simpledb Bug 1666219 - Renamed QM_TRY_VAR etc. to QM_TRY_UNWRAP etc. r=dom-workers-and-storage-reviewers,ttung,janv 2020-10-02 13:23:49 +00:00
smil Bug 1666617 - Add an observer description argument to AddRefreshObserver. r=smaug 2020-09-25 02:36:29 +00:00
storage Bug 1650145 - Replace all value uses of Empty[C]String by 0-length _ns literals. r=froydnj,geckoview-reviewers,agi 2020-09-23 15:17:15 +00:00
svg Bug 1668942 - Fix image onload attribute r=jwatt 2020-10-07 12:47:31 +00:00
system Bug 1650145 - Replace all value uses of Empty[C]String by 0-length _ns literals. r=froydnj,geckoview-reviewers,agi 2020-09-23 15:17:15 +00:00
tests Backed out 2 changesets (bug 1549418) for causing android bpgo exceptions. CLOSED TREE 2020-10-03 13:35:35 +03:00
u2f Bug 1663365 - Move |JSJitInfo| out of jsfriendapi.h to its own experimental header. r=jandem 2020-09-08 22:52:34 +00:00
url Bug 1662251 - stop assigning from NS_Convert* values, mostly; r=sg 2020-09-02 09:54:37 +00:00
vr Bug 1666617 - Add an observer description argument to AddRefreshObserver. r=smaug 2020-09-25 02:36:29 +00:00
webauthn Bug 1540309 - Track browsing context for the WebAuthn UX prompts r=nhnt11 2020-10-05 22:20:41 +00:00
webbrowserpersist Bug 1668414 - Also handle <source srcset>. r=edgar 2020-10-05 13:44:48 +00:00
webgpu
webidl Bug 1666497 - Don't flush layout from popuppositioned events. r=mconley,Gijs,smaug 2020-10-06 16:28:41 +00:00
webshare
websocket Bug 1668248 - Use fallible string operations in WebSocket::Send. r=valentin 2020-10-02 12:42:06 +00:00
workers Bug 1662925 - Make SW fetch events properly queue. r=dom-workers-and-storage-reviewers,janv 2020-10-07 16:02:24 +00:00
worklet
xhr Bug 1668357 - Disable tests which fail when fission and session-history-in-parent are enabled, r=peterv,marionette-reviewers,whimboo 2020-10-01 10:23:47 +00:00
xml Bug 1667510 - Make UA widgets in print documents more static. r=smaug 2020-09-29 10:31:48 +00:00
xslt Bug 1668757 - Fix lifetime extension issues with 0-length literals. r=xpcom-reviewers,nika 2020-10-06 15:03:01 +00:00
xul Bug 1666683 - Part 5: Add options parameter to nsXPConnect::ReadScript. r=tcampbell,kmag 2020-10-07 04:46:55 +00:00
jar.mn
moz.build