Read-only Git mirror of the Mercurial gecko repositories at https://hg.mozilla.org. How to contribute: https://firefox-source-docs.mozilla.org/contributing/contribution_quickref.html
Go to file
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
.cargo Backed out changeset 34fddbf97cc7 (bug 1669055) for bustages complaining about rust. CLOSED TREE 2020-10-07 01:44:54 +03:00
.vscode Bug 1656740 - Integrate clangd in vscode for C++ language support. r=froydnj 2020-08-06 06:25:17 +00:00
accessible Bug 1666380: Add support for AXTextFieldSearchKey to VO rotor r=eeejay 2020-10-06 18:50:31 +00:00
browser Bug 1668980 - Try browserStopped instead of browserLoaded to avoid intermittent. r=emalysz 2020-10-07 02:10:26 +00:00
build Backed out 5 changesets (bug 1662564, bug 1664922, bug 1440203) for Valgrind bustages. CLOSED TREE 2020-10-07 08:38:13 +03:00
caps 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
chrome 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
config Backed out 5 changesets (bug 1662564, bug 1664922, bug 1440203) for Valgrind bustages. CLOSED TREE 2020-10-07 08:38:13 +03:00
devtools Bug 1669592 - [devtools] Cleanup debugger/package.json dependencies list r=jdescottes 2020-10-07 15:51:36 +00:00
docs Bug 1667436 - Merge content of docs/setup/mach.rst into existing documentation r=firefox-build-system-reviewers,mhentges DONTBUILD 2020-10-05 16:51:41 +00:00
docshell Bug 1660342 - Add more assertions around host state, r=kmag 2020-09-16 04:43:54 +00:00
dom Bug 1662925 - Make SW fetch events properly queue. r=dom-workers-and-storage-reviewers,janv 2020-10-07 16:02:24 +00:00
editor Bug 1668757 - Fix lifetime extension issues with 0-length literals. r=xpcom-reviewers,nika 2020-10-06 15:03:01 +00:00
extensions 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
gfx no bug - Fix more docs warnings (404) r=firefox-source-docs-reviewers,championshuttler DONTBUILD 2020-10-07 15:30:36 +00:00
gradle/wrapper
hal Bug 1664374 - Replace MOZ_MUST_USE with [[nodiscard]] in hal. r=gsvelto 2020-09-11 06:35:02 +00:00
image Bug 1530990 - Remove dead code r=jwatt 2020-10-07 08:40:25 +00:00
intl Bug 1617369 - Reformat recent rust changes with rustfmt r=emilio,webdriver-reviewers,necko-reviewers,dragana,whimboo 2020-10-06 16:12:13 +00:00
ipc Backed out 5 changesets (bug 1662564, bug 1664922, bug 1440203) for Valgrind bustages. CLOSED TREE 2020-10-07 08:38:13 +03:00
js Merge autoland to mozilla-central a=merge 2020-10-07 18:45:09 +03:00
layout Bug 1666497 - Don't flush layout from popuppositioned events. r=mconley,Gijs,smaug 2020-10-06 16:28:41 +00:00
media Bug 1669450 - Update libsoundtouch to a911a1. r=chunmin 2020-10-07 09:40:58 +00:00
memory Bug 1668421 - Improve a use of fallible in jemalloc r=glandium 2020-10-05 00:49:22 +00:00
mfbt Bug 1519636 - Reformat recent changes to the Google coding style r=andi,necko-reviewers,dragana 2020-10-06 16:12:00 +00:00
mobile Bug 1663039 - [2.0] Add GV test to verify autofillEnabled setting is respected. r=geckoview-reviewers,agi 2020-10-06 17:53:14 +00:00
modules Backed out 3 changesets (bug 1669531, bug 1669530, bug 1669532) for causing bustages on StaticPrefList.yaml. CLOSED TREE 2020-10-06 23:46:24 +03:00
mozglue Bug 1668057: Allow DLL interceptor to patch 64-bit immediate MOVs r=tkikuchi 2020-10-05 22:25:44 +00:00
netwerk Backed out changeset da4cf62e21fb (bug 1668851) for perma failures on browser_cdp.js. CLOSED TREE 2020-10-07 15:08:01 +03:00
nsprpub Bug 1660371 - NSPR_4_29_RTM. r=kjacobs UPGRADE_NSPR_RELEASE DONTBUILD 2020-09-17 15:26:54 +00:00
other-licenses Bug 1663217 - Remove MOZ_MUST_USE comment from NSIS BitsUtils.cpp. r=agashlin 2020-09-09 17:23:34 +00:00
parser 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
python Bug 1669471 - Get rid of DeprecationWarning in file_generate.py r=firefox-build-system-reviewers,mhentges 2020-10-06 16:38:29 +00:00
remote Bug 1669230 - [remote] Remove --remote-debugger command line argument. r=remote-protocol-reviewers,jgraham 2020-10-07 13:50:57 +00:00
security Bug 1652713 - Implement fallback mechanism when echConfig is enabled, r=dragana,necko-reviewers 2020-10-06 20:06:55 +00:00
services No Bug, mozilla-central repo-update HSTS HPKP remote-settings - a=repo-update r=jcristau 2020-10-06 10:21:24 +00:00
servo Backed out changeset 20fadec3e9dc (bug 1187682) for perma failures on layout/reftests/mathml/stretchy-munderover-1c.html. CLOSED TREE 2020-10-02 17:11:33 +03:00
startupcache Bug 1656261 - Back out all recent StartupCache work r=RyanVM 2020-09-14 17:00:53 +00:00
storage Bug 1663924 - Split BorrowedStatement from CachedStatement. r=dom-workers-and-storage-reviewers,janv 2020-09-29 10:57:19 +00:00
taskcluster Bug 1668908 - beta to release migration needs to unset EARLY_BETA_OR_EARLIER. r=releng-reviewers,jlorenzo DONTBUILD 2020-10-06 13:21:30 +00:00
testing Bug 1669652 - Fix llvm-symbolizer path encoding. r=gbrown 2020-10-07 13:49:41 +00:00
third_party Backed out changeset 34fddbf97cc7 (bug 1669055) for bustages complaining about rust. CLOSED TREE 2020-10-07 01:44:54 +03:00
toolkit Backed out 2 changesets (bug 1664517) for very frequently failures on browser_aboutprocesses.js. CLOSED TREE 2020-10-07 17:54:15 +03:00
tools no bug - Fix more docs warnings (404) r=firefox-source-docs-reviewers,championshuttler DONTBUILD 2020-10-07 15:30:36 +00:00
uriloader Bug 1653026 - Added HTTPS-Only Mode upgrade info to browser UI state. r=mattwoodrow,necko-reviewers,dragana 2020-10-06 00:34:55 +00:00
view
widget Bug 1666497 - Don't flush layout from popuppositioned events. r=mconley,Gijs,smaug 2020-10-06 16:28:41 +00:00
xpcom Backed out 2 changesets (bug 1668825) for build bustages on TracingAPI.h. CLOSED TREE 2020-10-07 14:34:10 +03:00
xpfe/appshell Bug 1667081 - Part 3: Remove windowLowered in nsIFocusManager; r=hsivonen 2020-09-29 07:21:34 +00:00
.arcconfig
.babel-eslint.rc.js Bug 1620537 - Upgrade to ESLint 7.5.0, remove now unnecessary Babel plugins. r=mossop 2020-07-24 21:37:12 +00:00
.clang-format
.clang-format-ignore Bug 1667674 - [Wayland] Support public primary-selection unstable protocol. r=stransky 2020-10-02 09:13:06 +00:00
.cron.yml Backed out changeset a7713a786523 (bug 1668605) in order to enable m-c nightlies a=backout DONTBUILD 2020-10-03 12:48:32 +03:00
.eslintignore Bug 1665713 - pt1 - move dom/media/tests/mochitest to dom/media/webrtc/tests/mochitests. r=ng 2020-10-02 16:30:58 +00:00
.eslintrc.js Bug 1665713 - pt3 - fix js lint issues resulting from moving mochitest directory. r=ng 2020-10-02 16:29:35 +00:00
.flake8 Bug 1622686 - Make testing/web-platform flake8 compliant. r=sylvestre,jgraham 2020-09-29 14:22:49 +00:00
.git-blame-ignore-revs
.gitattributes
.gitignore Bug 1663372 - Ignore toolchains.json file with git. r=glandium 2020-09-25 13:09:50 +00:00
.hg-annotate-ignore-revs
.hg-format-source
.hgignore Bug 1658396 - Make hg ignore newtab node_modules, r=Mardak 2020-08-10 23:32:15 +00:00
.hgtags No bug - tagging cecca8e309497b6a0e7d2ab52a4956d7e48c91f6 with FIREFOX_NIGHTLY_82_END a=release DONTBUILD CLOSED TREE 2020-09-21 14:12:19 +00:00
.lldbinit
.mailmap
.prettierignore
.prettierrc
.taskcluster.yml Bug 1666809 - Insert decision task indexes directly via taskluster API rather than index-task, r=taskgraph-reviewers,aki 2020-09-24 19:19:36 +00:00
.trackerignore
.yamllint
.ycm_extra_conf.py
aclocal.m4
AUTHORS
build.gradle Bug 1553459 - Migrate to AndroidX r=geckoview-reviewers,agi 2020-09-18 22:29:04 +00:00
Cargo.lock Backed out changeset 34fddbf97cc7 (bug 1669055) for bustages complaining about rust. CLOSED TREE 2020-10-07 01:44:54 +03:00
Cargo.toml Backed out changeset 34fddbf97cc7 (bug 1669055) for bustages complaining about rust. CLOSED TREE 2020-10-07 01:44:54 +03:00
client.mk Bug 1660614 - Upgrade sccache to pick up more resilient behavior in the presence of cache read failures r=froydnj 2020-08-25 21:16:53 +00:00
client.py Bug 1650306 - Address the defects found by the pylint/no-else-return rule. r=sylvestre 2020-07-08 09:24:49 +00:00
CLOBBER Update configs. IGNORE BROKEN CHANGESETS CLOSED TREE NO BUG a=release ba=release 2020-08-24 14:18:41 +00:00
configure.in
configure.py Bug 1664077 - Remove _NON_GLOBAL_ACDEFINES. r=firefox-build-system-reviewers,mhentges,rstewart 2020-09-15 14:25:14 +00:00
GNUmakefile
gradle.properties Bug 1553459 - Migrate to AndroidX r=geckoview-reviewers,agi 2020-09-18 22:29:04 +00:00
gradlew
gradlew.bat
LEGAL
LICENSE
mach Bug 1638974 - Run 'mach mochitest' with Python 3; r=bc 2020-09-28 16:30:33 +00:00
Makefile.in Bug 1664077 - Remove xpcom-private.h. r=sg 2020-09-15 14:53:10 +00:00
moz.build Bug 1665854 - fx doc: Various improvements + configuration + fixes in the doc r=firefox-build-system-reviewers,rstewart 2020-09-22 06:26:17 +00:00
moz.configure Bug 1667892 - Move search for wget binary from old-configure to Python configure r=dmajor 2020-09-30 15:37:21 +00:00
mozilla-config.h.in
old-configure.in Bug 1667892 - Move search for wget binary from old-configure to Python configure r=dmajor 2020-09-30 15:37:21 +00:00
package-lock.json Bug 1668274 - update eslint, eslint-plugin-no-unsanitized and mocha to allow use of logical assignment operators, r=Standard8 2020-10-02 18:00:40 +00:00
package.json Bug 1668274 - update eslint, eslint-plugin-no-unsanitized and mocha to allow use of logical assignment operators, r=Standard8 2020-10-02 18:00:40 +00:00
README.txt Bug 1659631 - readme: update the wording to firefox, DONTBUILD.r=sylvestre 2020-08-18 04:04:36 +00:00
settings.gradle Backed out changeset d0ff30e1d830 (bug 1650692) for toolchains failures on ImageDecoderTest.kt. CLOSED TREE 2020-07-15 07:42:37 +03:00
substitute-local-geckoview.gradle
test.mozbuild

An explanation of the Firefox Source Code Directory Structure and links to
project pages with documentation can be found at:

    https://firefox-source-docs.mozilla.org/contributing/directory_structure.html

For information on how to build Firefox from the source code and create the patch see:

    https://firefox-source-docs.mozilla.org/contributing/contribution_quickref.html

If you have a question about developing Firefox, and can't find the solution
on https://firefox-source-docs.mozilla.org/, you can try asking your question on Matrix at chat.mozilla.org in `Introduction` (https://chat.mozilla.org/#/room/#introduction:mozilla.org) channel.


Nightly development builds can be downloaded from:

    https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central/
            - or -
    https://www.mozilla.org/firefox/channel/desktop/#nightly

Keep in mind that nightly builds, which are used by Firefox developers for
testing, may be buggy.