gecko-dev/dom/serviceworkers
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
..
test Bug 1664542 - Part 2: Test client.openWindow/COOP+COEP, r=asuth 2020-09-24 16:34:28 +00:00
FetchEventOpChild.cpp 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
FetchEventOpChild.h Bug 1615155 - Don't generate default `Recv__delete__` if there are args. r=nika 2020-02-18 20:46:21 +00:00
FetchEventOpParent.cpp Bug 1662925 - Make SW fetch events properly queue. r=dom-workers-and-storage-reviewers,janv 2020-10-07 16:02:24 +00:00
FetchEventOpParent.h Bug 1662925 - Make SW fetch events properly queue. r=dom-workers-and-storage-reviewers,janv 2020-10-07 16:02:24 +00:00
FetchEventOpProxyChild.cpp Bug 1637500 - P2. Rename methods as they are not always dealing with "threads". r=froydnj 2020-06-23 05:05:36 +00:00
FetchEventOpProxyChild.h Bug 1627892 - Make InternalRequest derive from SafeRefCounted. r=dom-workers-and-storage-reviewers,perry 2020-05-11 12:10:53 +00:00
FetchEventOpProxyParent.cpp Bug 1662925 - Make SW fetch events properly queue. r=dom-workers-and-storage-reviewers,janv 2020-10-07 16:02:24 +00:00
FetchEventOpProxyParent.h Bug 1662925 - Make SW fetch events properly queue. r=dom-workers-and-storage-reviewers,janv 2020-10-07 16:02:24 +00:00
IPCServiceWorkerDescriptor.ipdlh Bug 1654469 - Stop generating operator==/operator != for IPDL structs/unions by default. r=nika 2020-07-22 17:24:33 +00:00
IPCServiceWorkerRegistrationDescriptor.ipdlh Bug 1654469 - Stop generating operator==/operator != for IPDL structs/unions by default. r=nika 2020-07-22 17:24:33 +00:00
PFetchEventOp.ipdl
PFetchEventOpProxy.ipdl
PServiceWorker.ipdl Bug 1640606 - Throw while de-serializing instead of serializing if message contains a shared memory object; r=baku,dom-workers-and-storage-reviewers,edenchuang 2020-07-13 08:43:27 +00:00
PServiceWorkerContainer.ipdl
PServiceWorkerManager.ipdl
PServiceWorkerRegistration.ipdl Bug 1604943 - ServiceWorkerRegistration.update should capture newest worker script URL at call-time r=dom-workers-and-storage-reviewers,asuth 2020-01-08 03:21:27 +00:00
PServiceWorkerUpdater.ipdl
RemoteServiceWorkerContainerImpl.cpp Bug 1615022 part 2. Require an rvalue reference to reject a Promise with an ErrorResult. r=farre,kvark 2020-02-14 15:42:30 +00:00
RemoteServiceWorkerContainerImpl.h
RemoteServiceWorkerImpl.cpp Bug 1640606 - Throw while de-serializing instead of serializing if message contains a shared memory object; r=baku,dom-workers-and-storage-reviewers,edenchuang 2020-07-13 08:43:27 +00:00
RemoteServiceWorkerImpl.h
RemoteServiceWorkerRegistrationImpl.cpp Bug 1615022 part 2. Require an rvalue reference to reject a Promise with an ErrorResult. r=farre,kvark 2020-02-14 15:42:30 +00:00
RemoteServiceWorkerRegistrationImpl.h Bug 1604943 - ServiceWorkerRegistration.update should capture newest worker script URL at call-time r=dom-workers-and-storage-reviewers,asuth 2020-01-08 03:21:27 +00:00
ServiceWorker.cpp Bug 1640606 - Throw while de-serializing instead of serializing if message contains a shared memory object; r=baku,dom-workers-and-storage-reviewers,edenchuang 2020-07-13 08:43:27 +00:00
ServiceWorker.h
ServiceWorkerActors.cpp
ServiceWorkerActors.h
ServiceWorkerChild.cpp
ServiceWorkerChild.h
ServiceWorkerCloneData.cpp Bug 1640606 - Throw while de-serializing instead of serializing if message contains a shared memory object; r=baku,dom-workers-and-storage-reviewers,edenchuang 2020-07-13 08:43:27 +00:00
ServiceWorkerCloneData.h Bug 1640606 - Throw while de-serializing instead of serializing if message contains a shared memory object; r=baku,dom-workers-and-storage-reviewers,edenchuang 2020-07-13 08:43:27 +00:00
ServiceWorkerContainer.cpp Bug 1609920 - part 2: Guard ServiceWorkerContainer::Register to allow/disallow moz-extension scheme based on prefs. r=dom-workers-and-storage-reviewers,asuth,webidl,smaug 2020-07-03 10:14:42 +00:00
ServiceWorkerContainer.h Bug 1609920 - part 2: Guard ServiceWorkerContainer::Register to allow/disallow moz-extension scheme based on prefs. r=dom-workers-and-storage-reviewers,asuth,webidl,smaug 2020-07-03 10:14:42 +00:00
ServiceWorkerContainerChild.cpp
ServiceWorkerContainerChild.h
ServiceWorkerContainerImpl.cpp
ServiceWorkerContainerImpl.h
ServiceWorkerContainerParent.cpp Bug 1637500 - P2. Rename methods as they are not always dealing with "threads". r=froydnj 2020-06-23 05:05:36 +00:00
ServiceWorkerContainerParent.h
ServiceWorkerContainerProxy.cpp Bug 1620594 - Part 2: Use SchedulerGroup::Dispatch instead of SystemGroup::Dispatch. r=nika 2020-04-07 15:16:33 +00:00
ServiceWorkerContainerProxy.h
ServiceWorkerDescriptor.cpp Bug 1635399 - Function PrincipalInfoToPrincipal now returns Result<nsCOMPtr<nsIPrincipal>, nsresult> r=ckerschb 2020-05-12 19:02:05 +00:00
ServiceWorkerDescriptor.h Bug 1635399 - Function PrincipalInfoToPrincipal now returns Result<nsCOMPtr<nsIPrincipal>, nsresult> r=ckerschb 2020-05-12 19:02:05 +00:00
ServiceWorkerEvents.cpp 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
ServiceWorkerEvents.h Bug 1264175 - remove FetchEvent.isReload r=dom-workers-and-storage-reviewers,valentin,sg,bzbarsky 2020-01-25 00:05:12 +00:00
ServiceWorkerIPCUtils.h
ServiceWorkerImpl.cpp
ServiceWorkerImpl.h
ServiceWorkerInfo.cpp Bug 1595964 Part 1 - Add nsIServiceWorkerRegistrationInfo.evaluatingWorker, r=asuth. 2019-12-07 18:18:07 +00:00
ServiceWorkerInfo.h Bug 1407276 - Avoid creating InterceptedHttpChannel if the service worker has no fetch event handler r=dom-workers-and-storage-reviewers,asuth 2020-03-12 20:53:28 +00:00
ServiceWorkerInterceptController.cpp Bug 1635399 - Function PrincipalInfoToPrincipal now returns Result<nsCOMPtr<nsIPrincipal>, nsresult> r=ckerschb 2020-05-12 19:02:05 +00:00
ServiceWorkerInterceptController.h
ServiceWorkerJob.cpp Bug 1654992 - Use std::move instead of SwapElements where possible. r=froydnj 2020-08-04 11:27:07 +00:00
ServiceWorkerJob.h Bug 1606157 - ServiceWorkerJob notify callbacks its being discarded r=asuth 2020-01-11 04:21:41 +00:00
ServiceWorkerJobQueue.cpp Bug 1613985 - Use default for equivalent-to-default constructors/destructors in dom/serviceworkers. r=dom-workers-and-storage-reviewers,janv 2020-02-12 10:52:29 +00:00
ServiceWorkerJobQueue.h
ServiceWorkerManager.cpp 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
ServiceWorkerManager.h 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
ServiceWorkerManagerChild.cpp Bug 1635399 - Function PrincipalInfoToPrincipal now returns Result<nsCOMPtr<nsIPrincipal>, nsresult> r=ckerschb 2020-05-12 19:02:05 +00:00
ServiceWorkerManagerChild.h Bug 1613985 - Use default for equivalent-to-default constructors/destructors in dom/serviceworkers. r=dom-workers-and-storage-reviewers,janv 2020-02-12 10:52:29 +00:00
ServiceWorkerManagerParent.cpp Bug 1637500 - P2. Rename methods as they are not always dealing with "threads". r=froydnj 2020-06-23 05:05:36 +00:00
ServiceWorkerManagerParent.h
ServiceWorkerManagerService.cpp Bug 1635399 - Function PrincipalInfoToPrincipal now returns Result<nsCOMPtr<nsIPrincipal>, nsresult> r=ckerschb 2020-05-12 19:02:05 +00:00
ServiceWorkerManagerService.h
ServiceWorkerOp.cpp Bug 1662251 - stop assigning from NS_Convert* values, mostly; r=sg 2020-09-02 09:54:37 +00:00
ServiceWorkerOp.h Bug 1662526 - Exec method of the ServiceWorkerOp subclasses should return true when a dispatch did not fail. r=asuth 2020-09-01 18:58:26 +00:00
ServiceWorkerOpArgs.ipdlh Bug 1640606 - Throw while de-serializing instead of serializing if message contains a shared memory object; r=baku,dom-workers-and-storage-reviewers,edenchuang 2020-07-13 08:43:27 +00:00
ServiceWorkerOpPromise.h Bug 1662925 - Make SW fetch events properly queue. r=dom-workers-and-storage-reviewers,janv 2020-10-07 16:02:24 +00:00
ServiceWorkerParent.cpp Bug 1640606 - Throw while de-serializing instead of serializing if message contains a shared memory object; r=baku,dom-workers-and-storage-reviewers,edenchuang 2020-07-13 08:43:27 +00:00
ServiceWorkerParent.h Bug 1640606 - Throw while de-serializing instead of serializing if message contains a shared memory object; r=baku,dom-workers-and-storage-reviewers,edenchuang 2020-07-13 08:43:27 +00:00
ServiceWorkerPrivate.cpp 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
ServiceWorkerPrivate.h Bug 1648010 - Fix uses of NS_LITERAL_STRING with C string literals. r=geckoview-reviewers,agi,froydnj 2020-07-01 08:34:12 +00:00
ServiceWorkerPrivateImpl.cpp 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
ServiceWorkerPrivateImpl.h Bug 1611046 - add ServiceWorker shutdown progress tracking r=dom-workers-and-storage-reviewers,asuth 2020-01-29 10:08:35 +00:00
ServiceWorkerProxy.cpp Bug 1637500 - P2. Rename methods as they are not always dealing with "threads". r=froydnj 2020-06-23 05:05:36 +00:00
ServiceWorkerProxy.h
ServiceWorkerRegisterJob.cpp Bug 1613985 - Use default for equivalent-to-default constructors/destructors in dom/serviceworkers. r=dom-workers-and-storage-reviewers,janv 2020-02-12 10:52:29 +00:00
ServiceWorkerRegisterJob.h
ServiceWorkerRegistrar.cpp Bug 1648010 - Fix uses of NS_LITERAL_STRING with C string literals. r=geckoview-reviewers,agi,froydnj 2020-07-01 08:34:12 +00:00
ServiceWorkerRegistrar.h Bug 1648010 - Fix uses of NS_LITERAL_STRING with C string literals. r=geckoview-reviewers,agi,froydnj 2020-07-01 08:34:12 +00:00
ServiceWorkerRegistrarTypes.ipdlh
ServiceWorkerRegistration.cpp Bug 1654992 - Use std::move instead of SwapElements where possible. r=froydnj 2020-08-04 11:27:07 +00:00
ServiceWorkerRegistration.h Bug 1604943 - ServiceWorkerRegistration.update should capture newest worker script URL at call-time r=dom-workers-and-storage-reviewers,asuth 2020-01-08 03:21:27 +00:00
ServiceWorkerRegistrationChild.cpp
ServiceWorkerRegistrationChild.h
ServiceWorkerRegistrationDescriptor.cpp Bug 1635399 - Function PrincipalInfoToPrincipal now returns Result<nsCOMPtr<nsIPrincipal>, nsresult> r=ckerschb 2020-05-12 19:02:05 +00:00
ServiceWorkerRegistrationDescriptor.h Bug 1635399 - Function PrincipalInfoToPrincipal now returns Result<nsCOMPtr<nsIPrincipal>, nsresult> r=ckerschb 2020-05-12 19:02:05 +00:00
ServiceWorkerRegistrationImpl.cpp Bug 1635399 - Function PrincipalInfoToPrincipal now returns Result<nsCOMPtr<nsIPrincipal>, nsresult> r=ckerschb 2020-05-12 19:02:05 +00:00
ServiceWorkerRegistrationImpl.h Bug 1604943 - ServiceWorkerRegistration.update should capture newest worker script URL at call-time r=dom-workers-and-storage-reviewers,asuth 2020-01-08 03:21:27 +00:00
ServiceWorkerRegistrationInfo.cpp Bug 1654992 - Use std::move instead of SwapElements where possible. r=froydnj 2020-08-04 11:27:07 +00:00
ServiceWorkerRegistrationInfo.h Bug 1653229 - Remove unnecessary includes for BindingUtils.h. r=jgilbert 2020-07-22 15:12:10 +00:00
ServiceWorkerRegistrationListener.h
ServiceWorkerRegistrationParent.cpp Bug 1637500 - P2. Rename methods as they are not always dealing with "threads". r=froydnj 2020-06-23 05:05:36 +00:00
ServiceWorkerRegistrationParent.h Bug 1604943 - ServiceWorkerRegistration.update should capture newest worker script URL at call-time r=dom-workers-and-storage-reviewers,asuth 2020-01-08 03:21:27 +00:00
ServiceWorkerRegistrationProxy.cpp Bug 1637500 - P2. Rename methods as they are not always dealing with "threads". r=froydnj 2020-06-23 05:05:36 +00:00
ServiceWorkerRegistrationProxy.h Bug 1604943 - ServiceWorkerRegistration.update should capture newest worker script URL at call-time r=dom-workers-and-storage-reviewers,asuth 2020-01-08 03:21:27 +00:00
ServiceWorkerScriptCache.cpp 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
ServiceWorkerScriptCache.h Bug 1600545 - Remove useless inclusions of header files generated from IDL files in dom/ r=Ehsan 2019-12-06 09:24:56 +00:00
ServiceWorkerShutdownBlocker.cpp Bug 1648010 - Fix uses of NS_LITERAL_STRING with C string literals. r=geckoview-reviewers,agi,froydnj 2020-07-01 08:34:12 +00:00
ServiceWorkerShutdownBlocker.h Bug 1588152 - allow unclean ServiceWorker shutdown on beta/release builds r=asuth 2020-02-20 23:42:50 +00:00
ServiceWorkerShutdownState.cpp Bug 1620594 - Part 2: Use SchedulerGroup::Dispatch instead of SystemGroup::Dispatch. r=nika 2020-04-07 15:16:33 +00:00
ServiceWorkerShutdownState.h Bug 1611046 - add ServiceWorker shutdown progress tracking r=dom-workers-and-storage-reviewers,asuth 2020-01-29 10:08:35 +00:00
ServiceWorkerUnregisterCallback.cpp
ServiceWorkerUnregisterCallback.h
ServiceWorkerUnregisterJob.cpp 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
ServiceWorkerUnregisterJob.h
ServiceWorkerUpdateJob.cpp 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
ServiceWorkerUpdateJob.h Bug 1604943 - ServiceWorkerRegistration.update should capture newest worker script URL at call-time r=dom-workers-and-storage-reviewers,asuth 2020-01-08 03:21:27 +00:00
ServiceWorkerUpdaterChild.cpp
ServiceWorkerUpdaterChild.h
ServiceWorkerUpdaterParent.cpp
ServiceWorkerUpdaterParent.h
ServiceWorkerUtils.cpp Bug 1667176 - Miscellaneous unified build fixes. r=mattwoodrow 2020-09-25 08:57:23 +00:00
ServiceWorkerUtils.h Bug 1626570 - Improve handling of copying arrays in dom/serviceworkers/. r=dom-workers-and-storage-reviewers,ytausky 2020-05-11 08:22:14 +00:00
moz.build Bug 1363541 - Modernize the PermissionManager - part 4 - mozilla namespace, r=timhuang 2020-04-11 13:42:12 +00:00