This patch adds WebIDL bindings for the `scripting` namespace.
Note that `scripting.executeScript()` is excluded for now.
Differential Revision: https://phabricator.services.mozilla.com/D141463
* `js::HasInstance` now always forwards to `JS::InstanceofOperator` so call the latter directly.
* Move `InstanceofOperator` to the js namespace and remove it from the API (`JS_HasInstance` already exists).
Differential Revision: https://phabricator.services.mozilla.com/D142062
Currently only used to hide browser.runtime.getFrameID, which isn't going to be usable
in a background service worker anyway and it is not deprecated in MV3.
Differential Revision: https://phabricator.services.mozilla.com/D136951
Provide a way to use service workers as the background script in existing tests, possibly by only
requiring minimal changes to the existing test cases.
This patch includes:
- changes needed to detect when a test extension is being created for a test running in
the "background service worker mode" and automatically turn the background script into
a background service worker (instead of a background page) when not explicitly listed
in the test extension manifest
- a new mochitest-serviceworker.ini manifest where new or existing test files meant to be run on a
background service worker can be added to run them automatically in the "background service worker mode"
- a new test_verify_sw_mode.html smoke test that make sure the mochitest-serviceworker.ini manifest
is running in the expected mode.
- a new `sw-webextension` tag, which can be used locally to run a test file only in the
"background service worker mode"
- changes to test_ext_test.html to make it able to run in both background pages and background workers
- small tweaks to `test` API (both the WebIDL binding and the current bindings injected from privileged
js code, to better match each other behavior)
Differential Revision: https://phabricator.services.mozilla.com/D122536
Provide a way to use service workers as the background script in existing tests, possibly by only
requiring minimal changes to the existing test cases.
This patch includes:
- changes needed to detect when a test extension is being created for a test running in
the "background service worker mode" and automatically turn the background script into
a background service worker (instead of a background page) when not explicitly listed
in the test extension manifest
- a new mochitest-serviceworker.ini manifest where new or existing test files meant to be run on a
background service worker can be added to run them automatically in the "background service worker mode"
- a new test_verify_sw_mode.html smoke test that make sure the mochitest-serviceworker.ini manifest
is running in the expected mode.
- a new `sw-webextension` tag, which can be used locally to run a test file only in the
"background service worker mode"
- changes to test_ext_test.html to make it able to run in both background pages and background workers
- small tweaks to `test` API (both the WebIDL binding and the current bindings injected from privileged
js code, to better match each other behavior)
Differential Revision: https://phabricator.services.mozilla.com/D122536
This patch includes a proposed approach to keep track of the WebExtensions API event listeners
subscribed synchronously while the background service worker script was being loaded and executed,
because this are the listeners that we can assume to be available right after we spawn a worker
and be able to handle the API event that triggered the worker to be spawned.
The information about the "listeners subscribed synchronously while the worker script is being
loaded and executed" is then used by the ExtensionBrowser::HasWakeupEventListener method,
which will be called as part of handling the nsIServiceWorkerManager.wakeForExtensionAPIEvent
call.
Differential Revision: https://phabricator.services.mozilla.com/D130758
This patch includes a set of changes to the ServiceWorker internals to introduce a new
nsIServiceWorkerManager.wakeForExtensionAPIEvent method, to be used by the WebExtensions internals
to request an active background service worker to be spawned (if it is not yet) in response to
a WebExtension API event.
The new method gets as parameters:
- the scope URL for the extension background service worker to spawn
- WebExtensions API namespace and API event name which we are going to spawn an active worker for
and return a promise which would be:
- rejected if the worker could not be spawned
- resolved to a boolean if the worker was spawned successfully (or already running)
The value of the boolean value resolved is meant to represent if the worker did actually
have any listener subscribed for the given WebExtensions API event listener
(which the WebExtensions internals may then use to decide if it is worth to send that event
to be handled by the worker script or not).
In this patch the ExtensionBrowser::HasWakeupEventListener used to determine if an WebExtensions
API event was subscribed syncronously when the worker was being loaded is not implemented yet
and it is always returning false (a proposed implementation for that method is going to be
added in a separate patch part of this same bugzilla issue).
A unit test for the new proposed nsIServiceWorkerManager method is also part of a separate patch
(attached to this bugzilla issue as the child revision for this one).
Differential Revision: https://phabricator.services.mozilla.com/D130756
This patch includes changes needed to notify the WebExtensions internals
when a background service worker script has been fully loaded, through a
NotifyWorkerLoadedRunnable (dispatched as low priority) that calls a new
mozIExtensionAPIRequestHandler.onExtensionWorkerLoaded method.
Differential Revision: https://phabricator.services.mozilla.com/D124701
This patch introduce a new RequestInitWorkerRunnable that calls a new mozIExtensionAPIRequestHandler.initExtensionWorker
method, and a CreateAndDispatchInitWorkerRunnable helper function which will be used to send
this mozIExtensionAPIRequest from the worker thread to the main thread when the background
service worker is ready for being executed (but before its main scripts has been evaluated
in the newly created service worker global scope).
Differential Revision: https://phabricator.services.mozilla.com/D124699
This patch adds the ServiceWorkerInfo descriptor id to the property available in the
mozIExtensionServiceWorkerInfo.
The descriptor ID is an integer assigned on the main process to each ServiceWorkerPrivate instance,
which will allow us to verify in the main process that the worker running in the child process is
part of the expected service worker registration, and it is also still available when the worker
is already being destroyed, which makes it useful as the key used in the map of the extension
service worker context that we keep in the child extension process.
Differential Revision: https://phabricator.services.mozilla.com/D124698
This patch introduces the following changes:
- In WorkerPrivate::ExtensionAPIAllowed: removed assertion on StaticPrefs::extensions_backgroundServiceWorker_enabled_AtStartup,
replaced with just ignoring mExtensionAPIAllowed if the feature is turned out by prefs
- Added a new CreateAndDispatchWorkerDestroyedRunnable helper function to create and dispatch
a runnable (as a low priority one) to call a new mozIExtensionAPIRequestHandler.onExtensionWorkerDestroyed
method.
The service worker that has been destroyed is identified by its descriptor ID (the descriptor ID is an integer,
assigned on the main process to each ServiceWorkerPrivate instance, and still available when the worker is
already being destroyed).
Differential Revision: https://phabricator.services.mozilla.com/D124697
This patch includes changes needed to notify the WebExtensions internals
when a background service worker script has been fully loaded, through a
NotifyWorkerLoadedRunnable (dispatched as low priority) that calls a new
mozIExtensionAPIRequestHandler.onExtensionWorkerLoaded method.
Differential Revision: https://phabricator.services.mozilla.com/D124701
This patch introduce a new RequestInitWorkerRunnable that calls a new mozIExtensionAPIRequestHandler.initExtensionWorker
method, and a CreateAndDispatchInitWorkerRunnable helper function which will be used to send
this mozIExtensionAPIRequest from the worker thread to the main thread when the background
service worker is ready for being executed (but before its main scripts has been evaluated
in the newly created service worker global scope).
Differential Revision: https://phabricator.services.mozilla.com/D124699
This patch adds the ServiceWorkerInfo descriptor id to the property available in the
mozIExtensionServiceWorkerInfo.
The descriptor ID is an integer assigned on the main process to each ServiceWorkerPrivate instance,
which will allow us to verify in the main process that the worker running in the child process is
part of the expected service worker registration, and it is also still available when the worker
is already being destroyed, which makes it useful as the key used in the map of the extension
service worker context that we keep in the child extension process.
Differential Revision: https://phabricator.services.mozilla.com/D124698
This patch introduces the following changes:
- In WorkerPrivate::ExtensionAPIAllowed: removed assertion on StaticPrefs::extensions_backgroundServiceWorker_enabled_AtStartup,
replaced with just ignoring mExtensionAPIAllowed if the feature is turned out by prefs
- Added a new CreateAndDispatchWorkerDestroyedRunnable helper function to create and dispatch
a runnable (as a low priority one) to call a new mozIExtensionAPIRequestHandler.onExtensionWorkerDestroyed
method.
The service worker that has been destroyed is identified by its descriptor ID (the descriptor ID is an integer,
assigned on the main process to each ServiceWorkerPrivate instance, and still available when the worker is
already being destroyed).
Differential Revision: https://phabricator.services.mozilla.com/D124697
This patch introduce a new AssertMatchInternal to ExtensionTest, this method isn't exposed to
js callers through the webidl definition, it is meant to be used internally by the
AssertThrows and AssertRejects methods (which are instead both methods part of the ExtensionTest
webidl).
This patch also introduces small changes to ExtensionAPIRequestForwarder and RequestWorkerRunnable,
to allow AssertMatchInternal to accept as an optional parameter a serialized caller stack trace
(to be sent as part of the APIRequest forwarded from the worker thread to the main thread),
which is needed for AssertRejects (to include the strack trace retrieved when AssertRejects is
called, and then after the promise parameter has been rejected or resolved to send it as part
of the forwarded aPI request).
Differential Revision: https://phabricator.services.mozilla.com/D122033
This patch introduce a new method to ExtensionTest.h/.cpp that implements the parts of
browser.test.assertEq that needs to happen on the background service worker thread
(because the first two parameters are expected to not be always of types that can be structure cloned).
The C++ method is meant to follow closely enough what the current implementation is doing
in privileged JS code (See https://searchfox.org/mozilla-central/rev/00977c4e37865a92f1c15572ae4aea90e934b25b/toolkit/components/extensions/child/ext-test.js#169-186)
after that the C++ method calls the existing assertEq implementation, which will be actually be getting
the first 2 parameters already converted as strings (which will be already different if `expected` and
`actual` js values were different despite their stringified value may be looking the same, because the
method will add " (different)" to the stringified `actual` value if the two parameter were not strictly
equal).
The existing test.assertEq implementation will also take care to send the result of the assertion
to the parent process (which will make sure that the test case being executed will fail as expected),
as it happens for all other test API methods that are just forwarding their parameters to the
main thread through the pre-existing stub methods.
Differential Revision: https://phabricator.services.mozilla.com/D121890
This patch fixes a leak that I spotted while investigating a separate shutdown leak triggered by D121683
(This one is not strictly related to D121683, but apparently none of the xpcshell tests part of this
stack of patches reported it at a shutdown leak, nevertheless it was detected as a shutdown leak
while running the test_ext_identity.html mochitest on the background service worker, after
the other leak specific to D121683 was fixed, and after investigating it using cc logs and heapgraph's
find_roots.py I confirmed that it's a shutdown leak introduced here in RequestWorkerRunnable::ProcessHandlerResult).
Differential Revision: https://phabricator.services.mozilla.com/D122968
The extensions expect that ExtensionPort instances they get in the calls to the
port event listeners to always be the same, and to be also strictly equal to the
object port got from browser.runtime.connect or browser.runtime.onConnect:
```
const port = browser.runtime.connect();
port.onDisconnect.addListener(disconnectedPort => {
// port === disconnectedPort => true
});
```
This patch does add an extension port lookup map in the ExtensionBrowser
class and a new ExtensionBrowser::GetPort method which is responsible of
providing the expected behavior (returning an existing istance if one is
found in the lookup map).
Differential Revision: https://phabricator.services.mozilla.com/D107554