Bug 1300811 - Part 1 - Convert PageAction to a class r?mixedpuppy
MozReview-Commit-ID: 8sMK98hoq84
--- a/mobile/android/components/extensions/ext-pageAction.js
+++ b/mobile/android/components/extensions/ext-pageAction.js
@@ -16,46 +16,45 @@ Cu.import("resource://gre/modules/Extens
var {
IconDetails,
} = ExtensionParent;
// WeakMap[Extension -> PageAction]
var pageActionMap = new WeakMap();
-function PageAction(options, extension) {
- this.id = null;
+class PageAction {
+ constructor(options, extension) {
+ this.id = null;
- this.extension = extension;
- this.icons = IconDetails.normalize({path: options.default_icon}, extension);
+ this.extension = extension;
+ this.icons = IconDetails.normalize({path: options.default_icon}, extension);
- this.popupUrl = options.default_popup;
+ this.popupUrl = options.default_popup;
- this.options = {
- title: options.default_title || extension.name,
- id: `{${extension.uuid}}`,
- clickCallback: () => {
- if (this.popupUrl) {
- let win = Services.wm.getMostRecentWindow("navigator:browser");
- win.BrowserApp.addTab(this.popupUrl, {
- selected: true,
- parentId: win.BrowserApp.selectedTab.id,
- });
- } else {
- this.emit("click", tabTracker.activeTab);
- }
- },
- };
+ this.options = {
+ title: options.default_title || extension.name,
+ id: `{${extension.uuid}}`,
+ clickCallback: () => {
+ if (this.popupUrl) {
+ let win = Services.wm.getMostRecentWindow("navigator:browser");
+ win.BrowserApp.addTab(this.popupUrl, {
+ selected: true,
+ parentId: win.BrowserApp.selectedTab.id,
+ });
+ } else {
+ this.emit("click", tabTracker.activeTab);
+ }
+ },
+ };
- this.shouldShow = false;
+ this.shouldShow = false;
+ EventEmitter.decorate(this);
+ }
- EventEmitter.decorate(this);
-}
-
-PageAction.prototype = {
show(tabId, context) {
if (this.id) {
return Promise.resolve();
}
if (this.options.icon) {
this.id = PageActions.add(this.options);
return Promise.resolve();
@@ -81,39 +80,39 @@ PageAction.prototype = {
this.options.icon = dataURI;
this.id = PageActions.add(this.options);
}
}).catch(() => {
return Promise.reject({
message: "Failed to load PageAction icon",
});
});
- },
+ }
hide(tabId) {
this.shouldShow = false;
if (this.id) {
PageActions.remove(this.id);
this.id = null;
}
- },
+ }
setPopup(tab, url) {
// TODO: Only set the popup for the specified tab once we have Tabs API support.
this.popupUrl = url;
- },
+ }
getPopup(tab) {
// TODO: Only return the popup for the specified tab once we have Tabs API support.
return this.popupUrl;
- },
+ }
shutdown() {
this.hide();
- },
+ }
};
this.pageAction = class extends ExtensionAPI {
onManifestEntry(entryName) {
let {extension} = this;
let {manifest} = extension;
let pageAction = new PageAction(manifest.page_action, extension);