Bug 1300811 - Part 1 - Convert PageAction to a class r?mixedpuppy draft
authorMatthew Wein <mwein@mozilla.com>
Mon, 12 Jun 2017 21:39:24 -0400
changeset 593751 d1d577cb9ba7deffeb052b3e4eeb74eb48bff944
parent 593717 b266a8d8fd595b84a7d6218d7b8c6b7af0b5027c
child 593752 9ccc5d5fc954519dbdb342420535e1c37253dc87
push id63787
push usermwein@mozilla.com
push dateWed, 14 Jun 2017 03:28:10 +0000
reviewersmixedpuppy
bugs1300811
milestone56.0a1
Bug 1300811 - Part 1 - Convert PageAction to a class r?mixedpuppy MozReview-Commit-ID: 8sMK98hoq84
mobile/android/components/extensions/ext-pageAction.js
--- 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);