зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1331742 - Part 3 - Create and register ext-browserAction.js r=mixedpuppy
MozReview-Commit-ID: CGR4689b6oo --HG-- extra : rebase_source : 912519c647c2051d03307f52ca778efb1f9e7480
This commit is contained in:
Родитель
35c2d73d83
Коммит
0bb36b786b
|
@ -47,6 +47,15 @@ extensions.on("page-shutdown", (type, context) => {
|
|||
|
||||
|
||||
extensions.registerModules({
|
||||
browserAction: {
|
||||
url: "chrome://browser/content/ext-browserAction.js",
|
||||
schema: "chrome://browser/content/schemas/browser_action.json",
|
||||
scopes: ["addon_parent"],
|
||||
manifest: ["browser_action"],
|
||||
paths: [
|
||||
["browserAction"],
|
||||
],
|
||||
},
|
||||
pageAction: {
|
||||
url: "chrome://browser/content/ext-pageAction.js",
|
||||
schema: "chrome://browser/content/schemas/page_action.json",
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
||||
/* vim: set sts=2 sw=2 et tw=80: */
|
||||
"use strict";
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "EventEmitter",
|
||||
"resource://devtools/shared/event-emitter.js");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "Services",
|
||||
"resource://gre/modules/Services.jsm");
|
||||
|
||||
// Import the android BrowserActions module.
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "BrowserActions",
|
||||
"resource://gre/modules/BrowserActions.jsm");
|
||||
|
||||
// WeakMap[Extension -> BrowserAction]
|
||||
var browserActionMap = new WeakMap();
|
||||
|
||||
class BrowserAction {
|
||||
constructor(options, extension) {
|
||||
this.id = `{${extension.uuid}}`;
|
||||
this.name = options.default_title || extension.name;
|
||||
BrowserActions.register(this);
|
||||
EventEmitter.decorate(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Required by the BrowserActions module. This event will get
|
||||
* called whenever the browser action is clicked on.
|
||||
*/
|
||||
onClicked() {
|
||||
this.emit("click", tabTracker.activeTab);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister the browser action from the BrowserActions module.
|
||||
*/
|
||||
shutdown() {
|
||||
BrowserActions.unregister(this.id);
|
||||
}
|
||||
}
|
||||
|
||||
this.browserAction = class extends ExtensionAPI {
|
||||
onManifestEntry(entryName) {
|
||||
let {extension} = this;
|
||||
let {manifest} = extension;
|
||||
|
||||
let browserAction = new BrowserAction(manifest.browser_action, extension);
|
||||
browserActionMap.set(extension, browserAction);
|
||||
}
|
||||
|
||||
onShutdown(reason) {
|
||||
let {extension} = this;
|
||||
|
||||
if (browserActionMap.has(extension)) {
|
||||
browserActionMap.get(extension).shutdown();
|
||||
browserActionMap.delete(extension);
|
||||
}
|
||||
}
|
||||
|
||||
getAPI(context) {
|
||||
const {extension} = context;
|
||||
const {tabManager} = extension;
|
||||
|
||||
return {
|
||||
browserAction: {
|
||||
onClicked: new SingletonEventManager(context, "browserAction.onClicked", fire => {
|
||||
let listener = (event, tab) => {
|
||||
fire.async(tabManager.convert(tab));
|
||||
};
|
||||
browserActionMap.get(extension).on("click", listener);
|
||||
return () => {
|
||||
browserActionMap.get(extension).off("click", listener);
|
||||
};
|
||||
}).api(),
|
||||
},
|
||||
};
|
||||
}
|
||||
};
|
|
@ -6,6 +6,7 @@ chrome.jar:
|
|||
content/ext-android.js
|
||||
content/ext-c-android.js
|
||||
content/ext-c-tabs.js
|
||||
content/ext-browserAction.js
|
||||
content/ext-pageAction.js
|
||||
content/ext-tabs.js
|
||||
content/ext-utils.js
|
||||
|
|
Загрузка…
Ссылка в новой задаче