mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 08:15:31 +00:00
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 --HG-- extra : rebase_source : aede9c63e0f19d5b4c97022c0254b07603277aef
This commit is contained in:
parent
3451c2f756
commit
2cc8f66f57
@ -120,7 +120,6 @@ var ExtensionContext, GlobalManager;
|
|||||||
var Management = {
|
var Management = {
|
||||||
initialized: null,
|
initialized: null,
|
||||||
scopes: [],
|
scopes: [],
|
||||||
apis: [],
|
|
||||||
schemaApis: [],
|
schemaApis: [],
|
||||||
emitter: new EventEmitter(),
|
emitter: new EventEmitter(),
|
||||||
|
|
||||||
@ -162,27 +161,25 @@ var Management = {
|
|||||||
return this.initialized;
|
return this.initialized;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Called by an ext-*.js script to register an API. The |api|
|
/**
|
||||||
// parameter should be an object of the form:
|
* Called by an ext-*.js script to register an API.
|
||||||
// {
|
*
|
||||||
// tabs: {
|
* @param {string} namespace The API namespace.
|
||||||
// create: ...,
|
* Used to determine whether the API should be generated when the caller
|
||||||
// onCreated: ...
|
* 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
|
||||||
// This registers tabs.create and tabs.onCreated as part of the API.
|
* the create, update and remove methods to the tabs API.
|
||||||
registerAPI(api) {
|
*
|
||||||
this.apis.push({api});
|
* registerSchemaAPI("tabs", (context) => ({
|
||||||
},
|
* tabs: { create, update },
|
||||||
|
* }));
|
||||||
// Same as above, but only register the API is the add-on has the
|
* registerSchemaAPI("tabs", (context) => ({
|
||||||
// given permission.
|
* tabs: { remove },
|
||||||
registerPrivilegedAPI(permission, api) {
|
* }));
|
||||||
this.apis.push({api, permission});
|
*/
|
||||||
},
|
registerSchemaAPI(namespace, getAPI) {
|
||||||
|
this.schemaApis.push({namespace, getAPI});
|
||||||
registerSchemaAPI(namespace, api) {
|
|
||||||
this.schemaApis.push({namespace, api});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Mash together into a single object all the APIs registered by the
|
// Mash together into a single object all the APIs registered by the
|
||||||
@ -215,14 +212,9 @@ var Management = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
api = api.api(context);
|
api = api.getAPI(context);
|
||||||
copy(obj, api);
|
copy(obj, api);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let api of context.extension.apis) {
|
|
||||||
copy(obj, api.getAPI(context));
|
|
||||||
}
|
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -635,9 +627,6 @@ GlobalManager = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
injectInObject(context, defaultCallback, dest, namespaces = null) {
|
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);
|
let schemaApi = Management.generateAPIs(context, Management.schemaApis, namespaces);
|
||||||
|
|
||||||
// Add in any extra API namespaces which do not have implementations
|
// Add in any extra API namespaces which do not have implementations
|
||||||
@ -709,6 +698,9 @@ GlobalManager = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
Schemas.inject(dest, schemaWrapper);
|
Schemas.inject(dest, schemaWrapper);
|
||||||
|
|
||||||
|
let experimentalApis = Management.generateAPIs(context, context.extension.apis, namespaces);
|
||||||
|
injectAPI(experimentalApis, dest);
|
||||||
},
|
},
|
||||||
|
|
||||||
observe(document, topic, data) {
|
observe(document, topic, data) {
|
||||||
|
@ -48,7 +48,7 @@ var ExtensionAPIs = {
|
|||||||
|
|
||||||
let {script, schema} = api;
|
let {script, schema} = api;
|
||||||
|
|
||||||
let addonId = `${api}@experiments.addons.mozilla.org`;
|
let addonId = `${apiName}@experiments.addons.mozilla.org`;
|
||||||
api.sandbox = Cu.Sandbox(global, {
|
api.sandbox = Cu.Sandbox(global, {
|
||||||
wantXrays: false,
|
wantXrays: false,
|
||||||
sandboxName: script,
|
sandboxName: script,
|
||||||
|
Loading…
Reference in New Issue
Block a user