- Make all keys in `filter` mandatory.
- Add `optionalFilter` to Messenger to take over the role of the former
`filter` parameter.
- Add documentation to Messenger to explain what it really does.
- Fix type comments. Many message message managers were declared as a
sender, while they are at most a receiver (e.g. `Services.pppm`).
MozReview-Commit-ID: ILDnP2qDIK9
This patch allows specifying an OriginAttributes when creating a sandbox
using Components.utils.Sandbox() by specifying an originAttributes
member on the options dictionary.
If an OA is specified in this way, it is used for creating codebase
principals from the string arguments passed to the function. Otherwise,
if one or more principals are passed in the array argument to Sandbox(),
the OA of the principal(s) is used to construct codebase principals from
the strings inside the array. In this case, we check to make sure that
all of the passed principals have the same OA, otherwise we'll throw an
exception.
In case no explicit OA is specified and no principals are passed in the
array argument, we create the codebase principals using a default OA.
- Use the frame's message manager to direct messages via the
ProxyMessenger to the right tab instead of directly to the tab.
- Put the implementation in a separate file that is only loaded in
child processes (in the future).
- Explicitly list all addon-process specific files in a new category
instead of reusing the content one.
MozReview-Commit-ID: 8oIMx9ol7Tl
Checks what happens before closing a window or removing a frame:
- Tests that sendMessage/connect is received by the extension.
- Tests that any responses from the extension is not received by the
sending script (of the closing context).
MozReview-Commit-ID: 9VwCpRmaZOO
Due to asynchronicity or malice we can receive messages for unknown
ProxyContexts. Immediately reject such messages.
(this addresses https://bugzil.la/1288902#c3)
MozReview-Commit-ID: GEgkZC8CUEG
LegacyExtensionContext should inherit from BaseContext instead of
ExtensionContext, because the latter is moving to a separate process.
Remove the optional `url` parameter because the context is not a frame.
`url` is assigned to `sender.url`, which should only be set for frames.
The sender is only used in extension messaging when `runtime.connect` or
`runtime.sendMessage` are used (where `sender.url` is visible at the
receiver). Since legacy extensions don't send messages, there is no
point at all in setting the `url` value.
MozReview-Commit-ID: FJboNC2SZh0
- Introduce a proxy for IPC messages to allow the following APIs
to be run out-of-process (ProxyMessenger):
* runtime.connect
* runtime.sendMessage
* tabs.connect
* tabs.sendMessage
* runtime.onConnect
* runtime.onMessage
- Update getSender in ext-tabs, make it independent of the context
(in particular do not throw an error when a message is received while
the tab is gone), and move it from MessageChannel to ProxyMessenger to
make sure that it works in webext-oop. MessageChannel lives in a child
process, whereas the TabManager (used by getSender) requires data from
the main process.
- Set the third parameter of `addMessageListener` to true in some places
to make sure that messages get delivered even after unloading the
context. This is needed for the next two points.
- Put the `messageManager` property in BaseContext, and let it be set by
`setContentWindow` - runtime.sendMessage/connect and tabs.sendMessage/
connect depends on this property, and using the frame message manager
makes sense.
- Unconditionally use the frame message manager in
runtime.sendMessage/connect instead of sometimes the cpmm.
MozReview-Commit-ID: 4QkPnlMOkjS
To allow ExtensionContext to be refactored, we first need to remove the
dependency of ProxyContext on ExtensionContext.
With the decoupling, we can make setContentWindow unconditional and
remove externallyVisible. Let's clean up later.
MozReview-Commit-ID: 1KmSQpxFTVK
- Add new responseType RESPONSE_NONE to MessageChannel to signal no
expected reply.
- Modify Port to use MessageChannel instead of message managers.
- Include the `port` object to the disconnect event of ports because
Chrome does it too.
- Replace use of `contentWindow` with `cloneScope` to make the Port
independent of documents.
- Move registration of context destruction from `api()` to the
constructor to make sure that the disconnect listener is properly
removed if for some reason the `api` method is never called.
MozReview-Commit-ID: 9LCo5x1kEbH
`this.sender` has a tabId, `sender.tab` has a tab object. Therefore
they are not equal, and as a result messages were sent to the same
frame. Fixed by relying on contextId, which is unique across processes
since bug 1288279.
MozReview-Commit-ID: 8jMoXiBfp6l
callbacks is not an array but a Set, and Object.freeze does not prevent
modification of the list/set. Also, merely overwriting the callback set
is not sufficient to prevent callbacks from being run after the context
is closed (`fireWithoutClone`) because the set being iterated is still
filled with callbacks. And keeping the callbacks around may keep strong
references around and hinder GC.
To fix this, the set of callbacks is cleared (which invalidates the
iterator and ends the loop), and register/unregister are nulled.
Also add an explicit check to prevent callbacks from being registered
after unloading a context.
MozReview-Commit-ID: 4i2ojkbYAX9
This patch introduces helper for the embedding of a webextension (and new related tests).
The new exported helpers are going to be integrated in the XPIProvider
to provide the Embedded WebExtension to the Legacy Extensions which
have enabled it in their install.rdf
MozReview-Commit-ID: 7M1DRkXjGat
- this new module contains helpers to be able to receive connections
originated from a webextension context from a legacy extension context
(implemented by the `LegacyExtensionContext` class exported from
this new jsm module)
- two new test files (an xpcshell-test and a mochitest-browser) ensures that the LegacyExtensionContext can receive a Port
object and exchange messages with a background page and a content script (the content script test
is in a different test file because it doesn't currently work on android, because it needs
the browser.tabs API and the TabManager internal helper)
MozReview-Commit-ID: DS1NTXk0fB6