Commit Graph

222 Commits

Author SHA1 Message Date
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
Rob Wu
7c6379abff Bug 1295082 - BaseContext.extensionId -> BaseContext.extension.id r=kmag
MozReview-Commit-ID: 2tFVUwjyJQu
2016-08-16 14:29:52 -07:00
Rob Wu
6189daa99f 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
Rob Wu
bdf0a6a0a6 Bug 1287626,1288279 - Make IDs unique across processes r=billm
MozReview-Commit-ID: 78xgt8wqbng
2016-08-10 16:23:56 -07:00
Robert Helmer
c52c0f4a2c Bug 1279012 - implement onUpdateAvailable and runtime.reload() for WebExtensions r=aswan
MozReview-Commit-ID: KywrVkcRhzp
2016-08-02 09:37:01 -07:00
Wes Kocher
b9d5a32ad5 Merge inbound to central, a=merge 2016-08-12 13:44:29 -07:00
Kris Maglione
874e487954 Bug 1292369: Null out contentWindow properties when they point to a different inner window than the context belongs to. r=billm
MozReview-Commit-ID: LYQRxpU9vI8
2016-08-04 16:18:25 -07:00
Kris Maglione
d970e4c3c7 Bug 1293700: Make console object available to WebExtension internals. r=aswan
MozReview-Commit-ID: GyD4uo95gt6
2016-08-09 12:40:25 -07:00
Rob Wu
38d4ae8bfc Bug 1288276 - Close proxy context upon page reload, with tests r=billm
MozReview-Commit-ID: HB65DfQTGXd
2016-08-07 19:09:27 -07:00
Kris Maglione
aa06adc855 Bug 1290117: Call sendMessage response callback when there are no replies. r=robwu
MozReview-Commit-ID: 1BYD1CgZmvD
2016-08-06 14:21:10 -07:00
Jared Wein
ebf1ccbe46 Bug 1291855 - Enable the no-else-return rule for eslint. r=Felipe,kmag,mossop
MozReview-Commit-ID: DYOmE6xwMJh
2016-08-03 18:54:59 -04:00
Rob Wu
b52f567545 Bug 1286746 - Invoke sendMessage callback even if there are no listeners. r=kmag
MozReview-Commit-ID: HLIC3ZRcwRm
2016-07-14 20:34:40 -07:00
Rob Wu
80b02f6ee0 Bug 1286746 - Invoke port.onDisconnect if there are no onConnect listeners. r=kmag
MozReview-Commit-ID: DPs36oFm25J
2016-07-15 17:46:00 -07:00
Kris Maglione
56e8cb638f Bug 1274775 - Make sure background pages are created with a PresShell. r=billm
MozReview-Commit-ID: GLWg5aK47g5
2016-07-24 15:09:07 -07:00
Carsten "Tomcat" Book
9265f02f72 merge mozilla-inbound to mozilla-central a=merge 2016-07-21 16:24:36 +02:00
Till Schneidereit
e393dab409 Bug 911216 - Part 30: Enable SpiderMonkey Promise implementation. r=bz,efaust,bholley,Paolo,tromey,shu
Also contains folded version of the following patches that have to land at the same time with enabling the new implementation (or be backed out at the same time, if it comes to that):

Add Promise checks to test_xrayToJS.xul. r=bholley
Change Promise debugger hook tests to use Promise ctor instead of makeFakePromise. r=shu
Change DOM interface tests to assume Promise is an ES builtin, not a DOM one. r=bz
Remove some PromiseDebugging references. r=bz
Adapt promise rejections test to new xray-unwrapping error. r=bz
Fix expectations in browser_timelineMarkers tests. r=tromey
2016-07-21 12:06:30 +02:00
Rob Wu
e19087ccc7 Bug 1287245 - Ensure globally unique internal port IDs r=billm
MozReview-Commit-ID: FXNP5MadlMx
2016-07-15 21:44:03 -07:00
Iris Hsiao
5c3ef832ad Backed out changeset 7c026e26932d (bug 1287245) for Mochitest test_ext_background_runtime_connect_params.html failure 2016-07-20 11:04:45 +08:00
Rob Wu
da14dfd666 Bug 1287229 - port.disconnect should not throw r=billm
MozReview-Commit-ID: 7d8Zmb4OAd0
2016-07-15 22:46:42 -07:00
Rob Wu
ec2dab84e4 Bug 1287245 - Ensure globally unique internal port IDs r=billm
MozReview-Commit-ID: FXNP5MadlMx
2016-07-15 21:44:03 -07:00
Carsten "Tomcat" Book
e7b6762188 Backed out changeset a80fdfc128b0 (bug 911216) for high crash-rate on developers - RyanVM request 2016-07-18 16:14:59 +02:00
Carsten "Tomcat" Book
ac400ca3c2 merge mozilla-inbound to mozilla-central a=merge 2016-07-17 10:08:08 +02:00
Kris Maglione
e30a4f143e Bug 1272222: Use larger icons for browser actions in the menu panel. r=Gijs
MozReview-Commit-ID: 26lmlcrngPk
2016-07-13 15:16:00 -07:00
Till Schneidereit
b5a834f62f Bug 911216 - Part 30: Enable SpiderMonkey Promise implementation. r=bz,efaust,bholley,Paolo,tromey,shu
Also contains folded version of the following patches that have to land at the same time with enabling the new implementation (or be backed out at the same time, if it comes to that):

Add Promise checks to test_xrayToJS.xul. r=bholley
Change Promise debugger hook tests to use Promise ctor instead of makeFakePromise. r=shu
Change DOM interface tests to assume Promise is an ES builtin, not a DOM one. r=bz
Remove some PromiseDebugging references. r=bz
Adapt promise rejections test to new xray-unwrapping error. r=bz
Fix expectations in browser_timelineMarkers tests. r=tromey
2016-07-16 15:05:12 +02:00
Kris Maglione
8e28312be9 Bug 1284942: Don't fire message listeners for windows hidden in bfcache. r=aswan
MozReview-Commit-ID: KSqLt7Qqdkf
2016-07-06 17:14:02 -07:00
Matthew Wein
6206634766 Bug 1270742 - Add support for default_icon in chrome.pageAction r=kmag
MozReview-Commit-ID: D9uR0JUXJwx
2016-05-23 15:59:33 -07:00
Sebastian Hengst
1be0f90cda Backed out changeset 1008f5b88e6b (bug 1270742) for failing browser_ext_browserAction_context.js. r=backout 2016-06-24 13:00:31 +02:00