Bug 1526802 - add openOptionsPage function to ext-mail.js. r=darktrojan
authorPing Chen <remotenonsense@gmail.com>
Wed, 08 Apr 2020 10:22:53 +1200
changeset 38741 7e335f6ec5031c49f4b455929196f1984d59f79e
parent 38740 aab13fd352ab560eb42d1d500db3df034863e93d
child 38742 25b29578a1467e2ad16bc9348ef9709210c0294e
push id401
push userclokep@gmail.com
push dateMon, 01 Jun 2020 20:41:59 +0000
reviewersdarktrojan
bugs1526802
Bug 1526802 - add openOptionsPage function to ext-mail.js. r=darktrojan
mail/components/extensions/parent/ext-mail.js
--- a/mail/components/extensions/parent/ext-mail.js
+++ b/mail/components/extensions/parent/ext-mail.js
@@ -124,16 +124,36 @@ global.clickModifiersFromEvent = event =
 
   if (event.ctrlKey && AppConstants.platform === "macosx") {
     modifiers.push("MacCtrl");
   }
 
   return modifiers;
 };
 
+global.openOptionsPage = extension => {
+  let window = windowTracker.topWindow;
+  if (!window) {
+    return Promise.reject({ message: "No browser window available" });
+  }
+
+  if (extension.manifest.options_ui.open_in_tab) {
+    window.switchToTabHavingURI(extension.manifest.options_ui.page, true, {
+      triggeringPrincipal: extension.principal,
+    });
+    return Promise.resolve();
+  }
+
+  let viewId = `addons://detail/${encodeURIComponent(
+    extension.id
+  )}/preferences`;
+
+  return window.openAddonsMgr(viewId);
+};
+
 global.makeWidgetId = id => {
   id = id.toLowerCase();
   // FIXME: This allows for collisions.
   return id.replace(/[^a-z0-9_-]/g, "_");
 };
 
 /**
  * Gets the tab browser for the tabmail tabInfo.