Commit Graph

277 Commits

Author SHA1 Message Date
Rob Wu
e435eadbb2 Bug 1298979 - Check whether ProxyContext exists before using it r=billm
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
2016-08-25 19:36:30 -07:00
Rob Wu
41872d2a0a Bug 1298979 - Fix LegacyExtensionContext r=aswan
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
2016-09-06 01:48:58 -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
b725840b0b Bug 1298979 - Decouple ProxyContext from ExtensionContext r=billm
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
2016-08-24 23:29:29 -07:00
Luca Greco
36fc29ed1f Bug 1252215 - [webext] Add Embedded Extensions helper to LegacyExtensionsUtils. r=aswan,kmag
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
2016-08-29 15:56:02 +02:00
Luca Greco
ead728d5ad Bug 1252215 - [webext] LegacyExtensionsUtils JSM module and LegacyExtensionContext helper. r=aswan,kmag
- 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
2016-08-24 18:31:36 +02: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
Kris Maglione
b52d0dd49e Bug 1299256: Fix performance issues when stripping comments from large locale files. r=rpl
MozReview-Commit-ID: H7IfBnQ4KnO
2016-08-30 12:24:23 -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
11db14b054 Bug 1287010 - Extension.jsm optimization: Use pathObj r=billm
The API implementation is already available upfront when the schema API
is generated, so `pathObj` has the implementation and can be used
instead of looking up the implementation over and over again with
`findPathInObject`.

MozReview-Commit-ID: FnCIyoaxgA4
2016-08-20 15:37:43 -07:00
Rob Wu
f600b2cf99 Bug 1287010 - Use schema-generated extension, split ext-extension.js r=billm
- This was the last non-schema-generated API in content scripts.

MozReview-Commit-ID: FaIOCHoircf
2016-08-18 19:19:40 -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
Rob Wu
a68fdede92 Bug 1287010 - Use minimal global scope for ext-*.js scripts r=billm
Currently there is a tight coupling between registered APIs because they
share the same global scope, and the dependencies between the modules
that use these globals are not explicit. Consequently, it would be
possible for APIs to break when the registered APIs run in separate
processes, because then there are separate global scopes.
To mitigate this issue, this patch isolates the global namespaces of
API registrations in different environments, starting with the "chrome"
process. Content and addon processes will follow later.

A new JSM is introduced to avoid hidden dependencies between ext-*.js
and the script loader. ExtensionUtils.jsm would be a natural choice for
this shared utility method, but cannot be used because its local
`EventEmitter` implementation conflicts with the `EventEmitter` import
in ext-tabs.js.

So, this patch provides isolation of global variables declared through
`globals.XXX = ...`, but does not provide isolation for `Cu.import`-ed
logic. Ideally `Cu.import` should always use its second argument to
prevent inadvertent namespace pollution.

MozReview-Commit-ID: 1DTZaKOaeSE
2016-08-17 20:28:19 -07:00
Andrew Swan
ffbad6824f Bug 1297229 Run experiments APIs through schemas r=kmag
It is not directly related to the current bug but I added a test
for browser.extentionTypes while I was here.

MozReview-Commit-ID: 2XifKm3ZhrY
2016-08-22 16:50:32 -07:00
Hector Zhao
538abb2038 Bug 1295894 - Show localized strings for browserAction/pageAction title. r=kmag
MozReview-Commit-ID: 1SMd3cnUOH4
2016-08-17 14:39:33 +08:00
Rob Wu
b36ca744fc Bug 1286712 - Remove unused ExtensionContext and GlobalManager globals r=billm
The presence of these globals interfere with the attempt to get ext-*.js
scripts to load in a content process because these globals are only
available in the main process.

MozReview-Commit-ID: 7syjAGcuUnu
2016-08-16 22:05:05 -07:00
Rob Wu
b37ee71c9a Bug 1293132 - Document and enforce contract for Schemas.inject and Schemas.normalize r=kmag
MozReview-Commit-ID: KgSrgHttwrI
2016-08-07 18:36:36 -07:00
Rob Wu
8cbae07e24 Bug 1295082 - Minor fixups for experimental WebExtensions APIs r=kmag
- Remove unused registerAPI and registerPrivilegedAPI
- Generate the APIs just once.
- Fix typo in addon ID.

MozReview-Commit-ID: rdiiIxHMsm
2016-08-18 13:58:30 -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
4efcf6be95 Backed out changeset d71c400313a2 (bug 1293132) for failing test_ext_schemas_api_injection.js on Android's Sets test. r=backout 2016-08-18 18:27:34 +02: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
0653534c29 Backed out changeset 7c4c98ac6b3f (bug 1295082) 2016-08-18 16:46:26 +02:00
Rob Wu
cfcfbf0fa2 Bug 1293132 - Document contract for Schemas.inject and Schemas.normalize r=kmag
MozReview-Commit-ID: KgSrgHttwrI
2016-08-07 18:36:36 -07:00
Rob Wu
d32dcb8f44 Bug 1295082 - Minor fixups for experimental WebExtensions APIs r=kmag
- Remove unused registerAPI and registerPrivilegedAPI
- Generate the APIs just once.
- Fix typo in addon ID.

MozReview-Commit-ID: rdiiIxHMsm
2016-08-16 14:31:28 -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
c37b6fdf35 Bug 1288901 - Create ExtensionContext at document-element-inserted r=billm
MozReview-Commit-ID: 9ZQWmNjoAXA
2016-08-07 19:10:01 -07:00
Rob Wu
d5bc9c78b6 Bug 1288901 - Destroy ExtensionContext at inner window destruction instead of unload r=billm
MozReview-Commit-ID: 4JI7PpAj9xd
2016-08-07 19:09:56 -07:00
Luca Greco
fbae6b3141 Bug 1290901 - [webext] Allow APIs implementation to return null when the API should not be injected in a context. r=aswan
needed to be able to return null when the registered schema API should not be available
based on the context type instead of WebExtensions permissions.

MozReview-Commit-ID: G8w8ZYzmA7S
2016-08-02 04:00:06 +02:00
Luca Greco
c2292f3b1f Bug 1290901 - [webext] Handle nested namespaced API schema. r=aswan
MozReview-Commit-ID: H26E8ZwLrqJ
2016-08-15 15:34:43 +02: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
Andrew Swan
1206774e48 Bug 1286908 Remove id allocation from SpecialPowers loadExtension() r=kmag
Prior to this change, SpecialPowers used the extension id to identiy
extension instances in inter-process messaging.  This required that
an id be allocated from the content process side when loadExtension()
was called, but that made it impossible to test code that exercises the
code path in the AddonManager that allocates ids for extensions that do
not include an id in the manifest (it also made the loadExtension() api
clunky).

With this change, SpecialPowers allocates an internal identifier for
messaging, but this identifier is separate from extension ids.
Confusingly, we still store the actual extension id in an id property
on the object returned by loadExtension(), but there are enough tests
that reference this that it would be unnecessarily disruptive to get
rid of it so it stays for now...

MozReview-Commit-ID: G6xk1mBJJL8
2016-08-02 16:04:37 -07:00
Kris Maglione
ddc33568c0 Bug 1289527: Hide browserAction and pageAction namespaces when relevant manifest entries are missing. r=aswan
MozReview-Commit-ID: 2gx0pLkHaVJ
2016-08-06 14:43:58 -07:00
Andrew Swan
6782607111 Bug 1213990 Clear storage when webextension is uninstalled r=kmag
MozReview-Commit-ID: BeMOxOCSeru
2016-08-01 16:30:18 -07:00
Andrew Swan
654dc6ea8b Bug 1213990 Convert getExtensionUUID to UUIDMap r=kmag
MozReview-Commit-ID: 9VVNa0pjx8g
2016-08-07 09:53:36 -07:00
Andrew Swan
c1773fbf09 Bug 1213990 Do immediate uninstall for test webextensions r=kmag
MozReview-Commit-ID: 9vcAfPhRYFi
2016-07-22 10:16:55 -07:00
Kris Maglione
aeb04c78d9 Bug 1263011: Part 2 - Implement WebExtensions Experiments prototype. r=aswan
MozReview-Commit-ID: 4KO4cCLRsLf
2016-08-05 14:20:54 -07:00
Kris Maglione
b3728ad952 Bug 1263011: Part 1 - Refactor Extension and ExtensionData to use ES6 classes. r=aswan
MozReview-Commit-ID: f5NqRuPLU7
2016-06-17 16:02:16 +01:00
Kris Maglione
8c8a33c571 Bug 1288979: Always convert badge background color to a ColorTuple. r=aswan
MozReview-Commit-ID: CWmaa9wwQLD
2016-08-04 14:50:52 -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
Wes Kocher
e600667862 Backed out 3 changesets (bug 1213990) for problems in browser_ext_pageAction_context.js a=bustage CLOSED TREE
Backed out changeset c9b70a1998fc (bug 1213990)
Backed out changeset ffc2455a9135 (bug 1213990)
Backed out changeset 3223d0970b9a (bug 1213990)
2016-08-03 13:49:50 -07:00
Alexandre Lissy
b2834a3543 Bug 1284674 - Remove NUWA r=cyu
MozReview-Commit-ID: GyMRNzOBKw6
2016-08-02 14:54:00 +02:00
Andrew Swan
b7b02bc2d0 Bug 1213990 Clear storage when webextension is uninstalled r=kmag
MozReview-Commit-ID: BeMOxOCSeru
2016-08-01 16:30:18 -07:00
Andrew Swan
ecd926c70a Bug 1213990 Convert getExtensionUUID to UUIDMap r=kmag
MozReview-Commit-ID: 9VVNa0pjx8g
2016-08-03 09:17:24 -07:00
Andrew Swan
948a6a5cc9 Bug 1213990 Do immediate uninstall for test webextensions r=kmag
MozReview-Commit-ID: 9vcAfPhRYFi
2016-07-22 10:16:55 -07:00
Wes Kocher
4316d9744a Backed out 3 changesets (bug 1213990) for webextension failures a=backout
Backed out changeset 2b1fdeff506d (bug 1213990)
Backed out changeset 157efae8dd8a (bug 1213990)
Backed out changeset ea870f4c5a61 (bug 1213990)
2016-08-02 10:51:06 -07:00
Andrew Swan
9317fd97ab Bug 1213990 Clear storage when webextension is uninstalled r=kmag
MozReview-Commit-ID: BeMOxOCSeru
2016-08-01 16:30:18 -07:00