author | Sebastian Hengst <archaeopteryx@coole-files.de> |
Thu, 18 Aug 2016 16:46:26 +0200 | |
changeset 309949 | cbe853256aae7038964204fbee48bd8298da3733 |
parent 309948 | d09a610855c10923cddfc6334bbfe2a4bec9ba4a |
child 309950 | 4ccd5f15a01d1eca664c94340fccf490b6a2ad30 |
push id | 30575 |
push user | ryanvm@gmail.com |
push date | Fri, 19 Aug 2016 13:46:06 +0000 |
treeherder | mozilla-central@3da4d64410c0 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
bugs | 1295082 |
milestone | 51.0a1 |
backs out | 7c4c98ac6b3f4ff180de8ead6500d520e06d4d0a |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
toolkit/components/extensions/Extension.jsm | file | annotate | diff | comparison | revisions | |
toolkit/components/extensions/ExtensionAPI.jsm | file | annotate | diff | comparison | revisions |
--- a/toolkit/components/extensions/Extension.jsm +++ b/toolkit/components/extensions/Extension.jsm @@ -115,16 +115,17 @@ const COMMENT_REGEXP = new RegExp(String var scriptScope = this; var ExtensionContext, GlobalManager; // This object loads the ext-*.js scripts that define the extension API. var Management = { initialized: null, scopes: [], + apis: [], schemaApis: [], emitter: new EventEmitter(), // Loads all the ext-*.js scripts currently registered. lazyInit() { if (this.initialized) { return this.initialized; } @@ -156,35 +157,37 @@ var Management = { // Save the scope to avoid it being garbage collected. this.scopes.push(scope); } this.initialized = promise; return this.initialized; }, - /** - * Called by an ext-*.js script to register an API. - * - * @param {string} namespace The API namespace. - * Used to determine whether the API should be generated when the caller - * requests a subset of the available APIs (e.g. in content scripts). - * @param {function(BaseContext)} getAPI A function that returns an object - * that will be merged with |chrome| and |browser|. The next example adds - * the create, update and remove methods to the tabs API. - * - * registerSchemaAPI("tabs", (context) => ({ - * tabs: { create, update }, - * })); - * registerSchemaAPI("tabs", (context) => ({ - * tabs: { remove }, - * })); - */ - registerSchemaAPI(namespace, getAPI) { - this.schemaApis.push({namespace, getAPI}); + // Called by an ext-*.js script to register an API. The |api| + // parameter should be an object of the form: + // { + // tabs: { + // create: ..., + // onCreated: ... + // } + // } + // This registers tabs.create and tabs.onCreated as part of the API. + registerAPI(api) { + this.apis.push({api}); + }, + + // Same as above, but only register the API is the add-on has the + // given permission. + registerPrivilegedAPI(permission, api) { + this.apis.push({api, permission}); + }, + + registerSchemaAPI(namespace, api) { + this.schemaApis.push({namespace, api}); }, // Mash together into a single object all the APIs registered by the // functions above. Return the merged object. generateAPIs(context, apis, namespaces = null) { let obj = {}; // Recursively copy properties from source to dest. @@ -207,19 +210,24 @@ var Management = { continue; } if (api.permission) { if (!context.extension.hasPermission(api.permission)) { continue; } } - api = api.getAPI(context); + api = api.api(context); copy(obj, api); } + + for (let api of context.extension.apis) { + copy(obj, api.getAPI(context)); + } + return obj; }, // The ext-*.js scripts can ask to be notified for certain hooks. on(hook, callback) { this.emitter.on(hook, callback); }, @@ -622,16 +630,19 @@ GlobalManager = { } }, getExtension(extensionId) { return this.extensionMap.get(extensionId); }, injectInObject(context, defaultCallback, dest, namespaces = null) { + let api = Management.generateAPIs(context, Management.apis, namespaces); + injectAPI(api, dest); + let schemaApi = Management.generateAPIs(context, Management.schemaApis, namespaces); // Add in any extra API namespaces which do not have implementations // outside of their schema file. schemaApi.extensionTypes = {}; let schemaWrapper = { get principal() { @@ -693,19 +704,16 @@ GlobalManager = { removeListener(path, name, listener) { findPathInObject(schemaApi, path)[name].removeListener.call(null, listener); }, hasListener(path, name, listener) { return findPathInObject(schemaApi, path)[name].hasListener.call(null, listener); }, }; Schemas.inject(dest, schemaWrapper); - - let experimentalApis = Management.generateAPIs(context, context.extension.apis, namespaces); - injectAPI(experimentalApis, dest); }, observe(document, topic, data) { let contentWindow = document.defaultView; if (!contentWindow) { return; }
--- a/toolkit/components/extensions/ExtensionAPI.jsm +++ b/toolkit/components/extensions/ExtensionAPI.jsm @@ -43,17 +43,17 @@ var ExtensionAPIs = { let api = this.apis.get(apiName); if (api.loadPromise) { return api.loadPromise; } let {script, schema} = api; - let addonId = `${apiName}@experiments.addons.mozilla.org`; + let addonId = `${api}@experiments.addons.mozilla.org`; api.sandbox = Cu.Sandbox(global, { wantXrays: false, sandboxName: script, addonId, metadata: {addonID: addonId}, }); api.sandbox.ExtensionAPI = ExtensionAPI;