Commit Graph

198 Commits

Author SHA1 Message Date
Kris Maglione
89425f013c Bug 1315575: Part 1 - More cleanup. r=aswan
MozReview-Commit-ID: KdAplJGH9Hy
2016-11-06 17:28:16 -08:00
Wes Kocher
ffa634077a Backed out changeset 045ce2ca1b7d (bug 1303798) for test_ext_webrequest_upload.html failures a=backout 2016-11-07 12:00:28 -08:00
Kris Maglione
59d8645f01 Bug 1303798: Correctly propagate addListener errors from WebRequest.jsm to extension. r=mixedpuppy
MozReview-Commit-ID: BTTNaaAdBs5
2016-11-06 18:08:46 -08:00
Kris Maglione
bec1b361f5 Bug 1312690: Lazily initialize extension APIs. r=aswan
MozReview-Commit-ID: 2ofzT6wPvus
2016-11-02 19:21:04 -07:00
Kris Maglione
e10c4436dc Bug 1312690: Lazily initialize schema bindings. r=aswan
MozReview-Commit-ID: GoVUlANCgHg
2016-11-02 19:09:04 -07:00
Kris Maglione
6fd3e7cc09 Bug 1312690: Cleanup. r=aswan
MozReview-Commit-ID: IorfzVPKyIE
2016-10-30 19:54:23 -07:00
Rob Wu
21eaf53406 Bug 1299411 - Move native messaging to child process r=kmag
Move `runtime.connectNative` and `runtime.sendNativeMessage` to
`addon_child`. Note: This does not change the behavior for launching the
native app, it is still launched from the main process.

Now ExtensionUtils's Port is also used for native messaging ports. Now
the behavior of `runtime.connect` and `runtime.connectNative` are
identical from the extension's perspective.
In particular:
- `disconnect()` does not throw when called again (bug 1287229).
- `onDisconnect` is called with error messages (tests will be added in
  the next commit).

MozReview-Commit-ID: AyU9amiLeoL
2016-09-24 13:25:56 +02:00
Rob Wu
185ab2435d Bug 1299411 - Propagate errors to port.onDisconnect via port.error r=kmag
In Chrome, runtime.lastError is set when the port is disconnected
due to an error.
Here in Firefox we choose to set a new property "error" on the port
if the port disconnected due to an error.
Since onDisconnect fires at most once, port.error is set only once.

MozReview-Commit-ID: EPaVtV4WkcQ
2016-09-30 22:42:28 +02:00
Rob Wu
cf86efcccd Bug 1299411 - Unify fire and fireWithoutClone. r=kmag
Unify implementation of fire and fireWithoutClone. `fireWithoutClone`
was running the callbacks synchronously.  After this commit the callback
is run asynchronously. This is safe because the only user of this method
is `Port`'s `onDisconnect`.

MozReview-Commit-ID: 1kiYavsu3e7
2016-09-24 11:48:43 +02:00
Rob Wu
1a903f50f2 Bug 1299411 - Pass port parameter to port.onMessage r=kmag
This should have been a part of bug 1298810, but that only set the
argument for native messaging ports, which does not use Port from
ExtensionUtils. The port parameter must also be included in runtime's
Port.onMessage to avoid regressions when the port implementations are
unified and native messaging starts using runtime's Port.

Note that starting from this commit, multiple onMessage listeners
receive the same (cloned) message instead of a new clone per listener.
This is a side effect of using `fire.withoutClone` instead of `fire`:
`fire` clones all parameters, but ports are not cloneable so we have
to use `fire.withoutClone` instead. This change with regards to message
cloning is fully compatible with Chrome's messaging API (which also
passes the same message object to all `port.onMessage` calls).

MozReview-Commit-ID: AUDuUKHkXCM
2016-09-24 11:34:26 +02:00
Rob Wu
1a532a92e1 Bug 1299411 - Decouple Port implementation from API r=aswan
Decoupled the API from the implementation. From now on it is possible
to create Port instances without generating an API. This allows us to
internally use Ports to pass around messages with minimal overhead
(in the form of unnecessary clones of messages).
This will be used by native messaging.

This commit has no behavioral change, it is mostly moving around some
code and storing the internal message listener in a set.

MozReview-Commit-ID: 4h0LNJvTH9R
2016-09-24 11:16:32 +02:00
Rob Wu
a5e3a4826d Bug 1287007 - Remove .contentWindow from ProxyContext r=billm
MozReview-Commit-ID: ASNigrM07yz
2016-09-13 16:02:03 -07:00
Rob Wu
9ebbb4a33c Bug 1287007 - Fix "onclick" in contextMenus, to child. r=billm
Main thing: Making contextMenus implementation webext-oop compatible.

Preparation:

- Add getParentEvent to ChildAPIManager to allow use of remote events.
- Introduce `addon_parent_only` to "allowedContexts" to only generate a
  schema API in the main process.
- Do not fill in `null` for missing keys if the schema declares a key as
  `"optional": "omit-key-if-missing"`. This is needed for the second
  point in the next list.

Drive-by fixes:

- Ensure that the "onclick" handler is erased when a context closes.
- Do not clear the "onclick" handler in `contextMenus.update` if the
  onclick key has been omitted (parity with Chrome).
- Remove some unnecessary `Promise.resolve()`
- Add extensive set of tests that check the behavior of the contextMenus
  APIs with regards to the onclick attribute in various scenarios.

MozReview-Commit-ID: A5f3AUQzU8T
2016-09-12 18:26:03 -07:00
Rob Wu
12eef95584 Bug 1287007 - Set the principal in ChildAPIManager r=billm
The `browser.downloads.download` API takes a "url" parameter. The schema
file at downloads.json defines the type to be "url". This means that the
parameter is checked with `context.checkLoadURL(url)` in Schemas.jsm.
This method uses the principal of the object that was passed to
`Schemas.inject`.

Currently, this works just fine because the `schemaWrapper` in
Extension.jsm returns the context's principal.
But when we move to using the ChildAPIManager, the principal is not
defined and Schemas.jsm will fall back to a Null principal.

As a result, the test_ext_downloads_download.js fails because the
blob:-URL with the extension origin cannot be loaded by a null
principal. To fix this, the context's principal must be set.

MozReview-Commit-ID: FmpqYfPemyY
2016-09-07 20:35:39 -07:00
Rob Wu
0e978724ec Bug 1287007 - Introduce ChildAPIManager to addon code r=billm
This is the bare minimum to separate the generation of addon_parent and
addon_child APIs. Now it is possible to have methods with the same name
but different implementations in the parent and child.

Many APIs are not compatible with the proxied API implementation, so
they temporarily fall back to directly invoking the parent API, just as
before this commit.

MozReview-Commit-ID: fwuZUvD8tY
2016-09-05 18:57:38 -07:00
Rob Wu
a092f43273 Bug 1287007 - Do not neuter error messages from the same principal r=billm
With an upcoming change that introduces another ProxyContext,
errors from a different scope may bubble up. These messages should
be reported, not replaced with "An unexpected error occurred".

MozReview-Commit-ID: ByUktVkhDyx
2016-09-05 17:04:28 -07:00
Rob Wu
28a2ff2afa Bug 1287007 - Allow local implementations to call remote implementations r=billm
- Add callParentFunctionNoReturn / callParentAsyncFunction to
  ChildAPIManager to implement remote calls.

- Add in-process browser.test implementation that uses this.

- Add tests to verify that the browser.test.assert* methods with
  the `allowAmbiguousOptionalArguments` schema attribute are working
  with objects that cannot be passed as-is over IPC.
  (except test.sendMessage, because stringifying the arguments has an
   observable impact on test behavior)

MozReview-Commit-ID: 6cFVgmFfU93
2016-09-04 02:29:48 -07:00
Rob Wu
c387ffc1f8 Bug 1287007 - Fix some flaws in ProxyAPIImplementation r=billm
- removeListener: There is no set.remove, use set.delete.
- Async callbacks: Do not unconditionally turn the result in a
  SpreadArgs because it causes the result to unconditionally
  be wrapped in an array (+test).

MozReview-Commit-ID: LqwtBsHWJJr
2016-09-01 21:10:18 -07:00
Kris Maglione
d4f9daf879 Bug 1287209: Handle popup and options browser resizing using a frame script. r=aswan
MozReview-Commit-ID: DIfynklqrus
2016-10-20 15:27:51 -07:00
Phil Ringnalda
12b5bd3b6d Backed out 2 changesets (bug 1287209) for failures in browser_ext_pageAction_popup_resize.js
Backed out changeset 50dcca551b63 (bug 1287209)
Backed out changeset cc7503f09572 (bug 1287209)

MozReview-Commit-ID: A5q4SnWzgOa
2016-10-20 19:23:33 -07:00
Kris Maglione
967a70173c Bug 1287209: Handle popup and options browser resizing using a frame script. r=aswan
MozReview-Commit-ID: DIfynklqrus
2016-10-20 15:27:51 -07:00
Wes Kocher
8bf7d8ac8b Backed out 2 changesets (bug 1287209) for browser_ext_commands_execute_browser_action.js leaks a=backout
Backed out changeset a6787db4d131 (bug 1287209)
Backed out changeset 7ea8213113d7 (bug 1287209)
2016-10-20 14:37:12 -07:00
Kris Maglione
ddb12899fc Bug 1287209: Handle popup and options browser resizing using a frame script. r=aswan
MozReview-Commit-ID: DIfynklqrus
2016-10-20 09:57:13 -07:00
Sebastian Hengst
b8a5819c2d Backed out changeset 68806639c031 (bug 1287209) for failing browser-chrome test browser_ext_popup_corners.js. r=backout 2016-10-20 09:17:03 +02:00
Kris Maglione
c0448e9939 Bug 1287209: Handle popup and options browser resizing using a frame script. r=aswan
MozReview-Commit-ID: DIfynklqrus
2016-10-19 20:19:43 -07:00
Kris Maglione
c2be3319a7 Bug 1246034: Part 1 - [webext] Add a helper function to trigger a browserAction. r=jaws
MozReview-Commit-ID: JUW6oUpWiN4
2016-09-07 11:05:11 +01:00
Rob Wu
b60b96622e Bug 1302020 - Add filter to Messenger + fix code documentation r=billm
- 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
2016-09-11 22:38:40 -07:00
Matthew Wein
c26b978847 Bug 1302898 - Rename 'restrictions' to 'allowedContexts' r=kmag
All tests pass locally.

MozReview-Commit-ID: 5dPPthlPT6i
2016-09-19 17:36:46 -07:00
Matthew Wein
fec69037f1 Bug 1302898 - Make the schema restrictions array non-nullable. r=kmag
MozReview-Commit-ID: Lk8TGsqC4WC
2016-09-14 17:02:06 -07:00
Rob Wu
91820391f9 Bug 1298979 - Add ProxyMessenger, change message managers and getSender r=billm
- 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
2016-08-25 17:08:08 -07:00
Rob Wu
4ef11b3d36 Bug 1298979 - Use MessageChannel to implement runtime.Port r=billm
- 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
2016-08-31 01:08:08 -07:00
Rob Wu
54d9a3f8eb Bug 1298979 - Test sender equality by contextId r=kmag
`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
2016-09-06 04:35:35 -07:00
Rob Wu
73fc02545f Bug 1298979 - Properly dispose EventManager r=billm
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
2016-08-31 01:01:42 -07:00
Kris Maglione
7a7eda1b22 Bug 1298939: Don't register cleanup functions for listeners until the first time they're added. r=rpl
MozReview-Commit-ID: Ai8MxlB2qSb
2016-08-26 16:58:54 -07:00
Kris Maglione
31297b2525 Bug 1298939: Don't initialize APIs that the extension does not have permissions for. r=rpl
MozReview-Commit-ID: Y0MTBL1z2O
2016-09-01 13:04:54 -07:00
Rob Wu
4d5d4452a8 Bug 1286124 - Part 2/2 - Do not deliver messages to the sender's frame r=kmag
MozReview-Commit-ID: 8xZPDIJyMEo
2016-07-13 21:33:56 -07:00
Rob Wu
4014c9af7b Bug 1287010 - s/Extension:RemoveListener/API:RemoveListener/ r=billm
This fix is not related to the referenced bug but came up during review.

MozReview-Commit-ID: IjrxWzkLIq1
2016-08-24 16:09:43 -07:00
Rob Wu
8eb396a770 Bug 1287010 - Add test for SchemaAPIManager's loadScript r=billm
And change `this.global.Object.create(null)` to
`Cu.createObjectIn(this.global)`. The tests pass either way, but
`Cu.createObjectIn` is more explicit.

MozReview-Commit-ID: LmL6rTru5zZ
2016-08-24 15:40:35 -07:00
Rob Wu
becfb68e93 Bug 1287010 - Refactor shouldInject / pathObj r=billm
Split the `shouldInject` method into separate methods:
- `shouldInject` to determine whether the API (or namespace)
  should be injected.
- `getImplementation` to return the actual implementation.

Introduced `SchemaAPIInterface` for documentation purposes, and
two concrete implementations `LocalAPIImplementation` and
`ProxyAPIImplementation` which provide the functionality to run a local
and remote implementation of the API for which the schema API is
generated, respectively. These classes store the necessary details for
the invocation, so the methods that were formerly in the `Context` in
Schemas.jsm no longer get the `pathObj`, `path` or `name` parameters.

And merge the `path` and `name` in the implementation of remote APIs
because there is no need for having them separate, as the callers and
callees often did redundant pre/post-processing on `data.path` because
of the way it was implemented.

MozReview-Commit-ID: isbG9i9pNP
2016-08-24 01:03:49 -07:00
Rob Wu
a430263825 Bug 1287010 - Use sandbox instead of JSM for global separation r=billm
MozReview-Commit-ID: GSqmh0xC2hW
2016-08-23 16:19:33 -07:00
Rob Wu
fc61c013eb Bug 1287010 - Prepare for moving content script APIs to schemas r=billm
- By default, schema APIs are not injected in content scripts unless
  the JSON schema sets the "restrictions" attribute to `["content"]`.
- Added the "restrictions" attribute to the storage and test schemas.
  Other APIs will follow in subsequent commits and make use of the
  primitives introduced in this commit.

MozReview-Commit-ID: 1rNjQap0BiM
2016-08-18 17:46:57 -07:00
Rob Wu
488a453294 Bug 1287010 - Move Management logic to SchemaAPIManager r=billm
- Moved Management logic to ExtensionUtils (as SchemaAPIManager) so that
  the logic can be used by addon and content processes.
- Remove the `context.extension.hasPermission(api.permission)` check in
  `generateAPIs` because the only user (`registeredPrivilegedAPI`) was
  removed before in bug 1295082.
- Add new category "webextension-scripts-content", intended for
  registering the few scripts that must be loaded in a content process.

MozReview-Commit-ID: 81nhblV8YE6
2016-08-17 17:51:21 -07:00
Rob Wu
812e170fe8 Bug 1287010 - Make environment of Context explicit. r=billm
- Add `envType` to BaseContext.
 - Pass an explicit envType to all `registerSchemaAPI` invocations.
 - The factories passed to `registerSchemaAPI` will be split up later, so
   that content scripts (`content_child`) and addon pages can share
   common implementations.
 - The factories that implement the addon API will also be split up,
   to separate code running in the main process (`addon_parent`) from
   code running in a child process (`addon_child`).
 - Remove the use of a hardcoded list of `namespaces` from ProxyContext.
   Now `envType` is used to specify whether an API should be activated.

MozReview-Commit-ID: Jiff8HIwG92
2016-08-16 15:51:50 -07:00
Rob Wu
42e49c6137 Bug 1287010 - Add pathObj parameter to Schemas r=billm
Local wrappers currently look up the API object over and over again
whenever a schema API is invoked. This can be optimized by re-using
the lookup result from a `shouldInject` invocation, which is passed
as the `pathObj` parameter to the wrapper methods.

This commit adds the necessary changes and tests to allow this to
happen, but does not modify the wrapper in Extension.jsm yet.

Also, this construction allows the `ChildAPIManager` to use a local
implementation if available and fall back to a remote implementation
otherwise.

MozReview-Commit-ID: C9gm7A9Zppb
2016-08-19 00:35:07 -07:00
Kris Maglione
007774bc99 Bug 1259093: Follow-up: Fix another test race. r=me
MozReview-Commit-ID: 3DsTcQli8Ga
2016-08-20 14:00:37 -07:00
Kris Maglione
bfd63ddac8 Bug 1259093: Part 3 - Preload browserAction popups to prevent flicker during opening. r=Gijs r=jaws r=bwinton f=mattw
MozReview-Commit-ID: EpAKLV8VPTn
2016-08-19 12:29:11 -07:00
Rob Wu
98a49ff299 Bug 1295082 - BaseContext.extensionId -> BaseContext.extension.id r=kmag
MozReview-Commit-ID: 2tFVUwjyJQu
2016-08-16 14:29:52 -07:00
Rob Wu
6efdd88867 Bug 1295082 - Put Extension in BaseContext r=kmag
ExtensionContext in Extension.jsm has |extension| as an instance member,
so use it instead of passing |extension| to registerSchemaAPI's
callback.

And to make sure that this pattern also works in content processes, move
the |extension| member to BaseContext.

MozReview-Commit-ID: BgsGGCPQxJR
2016-08-15 01:04:58 -07:00
Sebastian Hengst
c7a498ffbd Backed out changeset 0ce1cc39aa3d (bug 1295082) for timing out in test_ext_schemas_api_injection.js. r=backout 2016-08-18 16:47:09 +02:00
Sebastian Hengst
ff21875b1a Backed out changeset dc7b09331202 (bug 1295082) 2016-08-18 16:46:30 +02:00