Bug 1500881 - Use new EventManager constructor. r=mkmelin
authorGeoff Lankow <geoff@darktrojan.net>
Tue, 23 Oct 2018 21:36:36 +1300
changeset 33544 02352ad526d3ae67e6f3254ff468b253c9ea353f
parent 33543 8f2aaabd3130c106bd569bd7ed4186d434f9f97e
child 33545 e51fe5c93b88ba50efe167c4883e3394a1c0c4d3
push id388
push userclokep@gmail.com
push dateMon, 28 Jan 2019 20:54:56 +0000
reviewersmkmelin
bugs1500881
Bug 1500881 - Use new EventManager constructor. r=mkmelin
mail/components/extensions/parent/ext-mail.js
mail/components/extensions/parent/ext-tabs.js
mail/components/extensions/parent/ext-windows.js
--- a/mail/components/extensions/parent/ext-mail.js
+++ b/mail/components/extensions/parent/ext-mail.js
@@ -175,24 +175,28 @@ class WindowTracker extends WindowTracke
  * @param {string} name
  *        The API name of the event manager, e.g.,"runtime.onMessage".
  * @param {string} event
  *        The name of the DOM event to listen for.
  * @param {function} listener
  *        The listener function to call when a DOM event is received.
  */
 global.WindowEventManager = class extends EventManager {
-  constructor(context, name, event, listener) {
-    super(context, name, fire => {
-      let listener2 = listener.bind(null, fire);
+  constructor({ context, name, event, listener }) {
+    super({
+      context,
+      name,
+      listener: (fire) => {
+        let listener2 = listener.bind(null, fire);
 
-      windowTracker.addListener(event, listener2);
-      return () => {
-        windowTracker.removeListener(event, listener2);
-      };
+        windowTracker.addListener(event, listener2);
+        return () => {
+          windowTracker.removeListener(event, listener2);
+        };
+      },
     });
   }
 };
 
 /**
  * Tracks the opening and closing of tabs and maps them between their numeric WebExtension ID and
  * the native tab info objects.
  */
--- a/mail/components/extensions/parent/ext-tabs.js
+++ b/mail/components/extensions/parent/ext-tabs.js
@@ -82,17 +82,17 @@ const allProperties = new Set([
   "title",
 ]);
 const restricted = new Set(["url", "favIconUrl", "title"]);
 
 /**
  * An EventManager for the tabs.onUpdated listener.
  */
 class TabsUpdateFilterEventManager extends EventManager {
-  constructor(context) {
+  constructor({ context }) {
     let { extension } = context;
     let { tabManager } = extension;
 
     let register = (fire, filterProps) => {
       let filter = { ...filterProps };
       if (filter.urls) {
         filter.urls = new MatchPatternSet(filter.urls);
       }
@@ -356,17 +356,17 @@ this.tabs = class extends ExtensionAPI {
 
             windowTracker.addListener("TabMove", moveListener);
             return () => {
               windowTracker.removeListener("TabMove", moveListener);
             };
           },
         }).api(),
 
-        onUpdated: new TabsUpdateFilterEventManager(context).api(),
+        onUpdated: new TabsUpdateFilterEventManager({ context }).api(),
 
         async create(createProperties) {
           let window = createProperties.windowId === null
               ? windowTracker.topNormalWindow
               : windowTracker.getWindow(createProperties.windowId, context);
           let tabmail = window.document.getElementById("tabmail");
 
           let url;
--- a/mail/components/extensions/parent/ext-windows.js
+++ b/mail/components/extensions/parent/ext-windows.js
@@ -6,22 +6,32 @@
 /* import-globals-from ext-mail.js */
 this.windows = class extends ExtensionAPI {
   getAPI(context) {
     const { extension } = context;
     const { windowManager } = extension;
 
     return {
       windows: {
-        onCreated: new WindowEventManager(context, "windows.onCreated", "domwindowopened", (fire, window) => {
-          fire.async(windowManager.convert(window));
+        onCreated: new WindowEventManager({
+          context,
+          name: "windows.onCreated",
+          event: "domwindowopened",
+          listener: (fire, window) => {
+            fire.async(windowManager.convert(window));
+          },
         }).api(),
 
-        onRemoved: new WindowEventManager(context, "windows.onRemoved", "domwindowclosed", (fire, window) => {
-          fire.async(windowTracker.getId(window));
+        onRemoved: new WindowEventManager({
+          context,
+          name: "windows.onRemoved",
+          event: "domwindowclosed",
+          listener: (fire, window) => {
+            fire.async(windowTracker.getId(window));
+          },
         }).api(),
 
         onFocusChanged: new EventManager({
           context,
           name: "windows.onFocusChanged",
           register: fire => {
             // Keep track of the last windowId used to fire an onFocusChanged event
             let lastOnFocusChangedWindowId;