Bug 1532724 - Part 2: Handle HTML about:addons options page in APIs r=kmag a=jcristau
authorMark Striemer <mstriemer@mozilla.com>
Fri, 31 May 2019 16:21:02 +0000
changeset 536775 ec06ba3131eeb34a1c9a8e7753ebcbb389e28879
parent 536774 341cf2990acb03ec601d64db134bcf3243961cd4
child 536776 0b36ffd23e0d21c4d681f418d240e18f646b13de
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag, jcristau
bugs1532724
milestone68.0
Bug 1532724 - Part 2: Handle HTML about:addons options page in APIs r=kmag a=jcristau Differential Revision: https://phabricator.services.mozilla.com/D30731
browser/components/extensions/parent/ext-browser.js
browser/components/extensions/test/browser/browser_ext_runtime_openOptionsPage.js
toolkit/components/extensions/ExtensionParent.jsm
--- a/browser/components/extensions/parent/ext-browser.js
+++ b/browser/components/extensions/parent/ext-browser.js
@@ -651,17 +651,17 @@ class TabTracker extends TabTrackerBase 
 
     this.emit("tab-removed", {nativeTab, tabId, windowId, isWindowClosing, isPrivate: isPrivateTab(nativeTab)});
   }
 
   getBrowserData(browser) {
     let {gBrowser} = browser.ownerGlobal;
     // Some non-browser windows have gBrowser but not getTabForBrowser!
     if (!gBrowser || !gBrowser.getTabForBrowser) {
-      if (browser.ownerDocument.documentURI === "about:addons") {
+      if (browser.ownerGlobal.top.document.documentURI === "about:addons") {
         // When we're loaded into a <browser> inside about:addons, we need to go up
         // one more level.
         browser = browser.ownerGlobal.docShell.chromeEventHandler;
 
         ({gBrowser} = browser.ownerGlobal);
       } else {
         return {
           tabId: -1,
--- a/browser/components/extensions/test/browser/browser_ext_runtime_openOptionsPage.js
+++ b/browser/components/extensions/test/browser/browser_ext_runtime_openOptionsPage.js
@@ -54,19 +54,17 @@ async function loadExtension(options) {
     background: options.background,
   });
 
   await extension.startup();
 
   return extension;
 }
 
-add_task(async function test_inline_options() {
-  info(`Test options opened inline`);
-
+async function run_test_inline_options() {
   let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "http://example.com/");
 
   let extension = await loadExtension({
     manifest: {
       applications: {gecko: {id: "inline_options@tests.mozilla.org"}},
       "options_ui": {
         "page": "options.html",
       },
@@ -195,16 +193,27 @@ add_task(async function test_inline_opti
 
   extension.sendMessage("ports-done");
 
   await extension.awaitFinish("options-ui");
 
   await extension.unload();
 
   BrowserTestUtils.removeTab(tab);
+}
+
+add_task(async function test_inline_options() {
+  for (let htmlEnabled of [false, true]) {
+    info(`Test options opened inline ${htmlEnabled ? "HTML" : "XUL"} about:addons`);
+    await SpecialPowers.pushPrefEnv({
+      set: [["extensions.htmlaboutaddons.enabled", htmlEnabled]],
+    });
+    await run_test_inline_options();
+    await SpecialPowers.popPrefEnv();
+  }
 });
 
 add_task(async function test_tab_options() {
   info(`Test options opened in a tab`);
 
   let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "http://example.com/");
 
   let extension = await loadExtension({
--- a/toolkit/components/extensions/ExtensionParent.jsm
+++ b/toolkit/components/extensions/ExtensionParent.jsm
@@ -518,19 +518,24 @@ ProxyMessenger = {
       }
 
       let browser = tab.linkedBrowser || tab.browser;
 
       // Options panels in the add-on manager currently require
       // special-casing, since their message managers aren't currently
       // connected to the tab's top-level message manager. To deal with
       // this, we find the options <browser> for the tab, and use that
-      // directly, insteead.
+      // directly, instead.
       if (browser.currentURI.specIgnoringRef === "about:addons") {
-        let optionsBrowser = browser.contentDocument.querySelector(".inline-options-browser");
+        let htmlBrowser = browser.contentDocument.getElementById("html-view-browser");
+        // Look in the HTML browser first, if the HTML views aren't being used they
+        // won't have a browser.
+        let optionsBrowser =
+          htmlBrowser.contentDocument.getElementById("addon-inline-options") ||
+          browser.contentDocument.querySelector(".inline-options-browser");
         if (optionsBrowser) {
           browser = optionsBrowser;
         }
       }
 
       return {messageManager: browser.messageManager, xulBrowser: browser};
     }