Bug 1385548 - Part 2: Fix "tabEvent is undefined" exception for modals opened from a WebExtensions options_ui page. draft
authorLuca Greco <lgreco@mozilla.com>
Tue, 19 Sep 2017 16:05:27 +0200
changeset 667053 964d00cc765d396e1e88fd42bfa80e25fb6cf6e7
parent 667052 f6d878bb096bf0d3573dd22d662b68ca09fc4d22
child 667054 8129757327935c43713dbbf06a2523ac41ef2846
push id80600
push userluca.greco@alcacoop.it
push dateTue, 19 Sep 2017 16:57:34 +0000
bugs1385548
milestone57.0a1
Bug 1385548 - Part 2: Fix "tabEvent is undefined" exception for modals opened from a WebExtensions options_ui page. MozReview-Commit-ID: LEQDru7pbIC
browser/base/content/tabbrowser.xml
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -5989,16 +5989,34 @@
           // If this is a same-process modal dialog, then we're given its DOM
           // window as the event's target. For remote dialogs, we're given the
           // browser, but that's in the originalTarget and not the target,
           // because it's across the tabbrowser's XBL boundary.
           let tabForEvent = targetIsWindow ?
                             this._getTabForContentWindow(event.target.top) :
                             this.getTabForBrowser(event.originalTarget);
 
+          // If the tabForEvent is still undefined, check if the target is
+          // a WebExtension browser options_ui embedded in the about:addons page
+          // (See Bug 1385548 for rationale).
+          if (!tabForEvent) {
+            const window = event.target.ownerGlobal;
+            const principal = window.document.nodePrincipal;
+
+            // The add-on manager is a special case, since it contains extension
+            // options pages in <browser> frames.
+            if (Services.scriptSecurityManager.isSystemPrincipal(principal) &&
+                window.location.href === "about:addons" &&
+                event.target.tagName === "browser" &&
+                event.target.getAttribute("id") === "addon-options") {
+              // Focus the about:addons tab.
+              tabForEvent = this._getTabForContentWindow(window);
+            }
+          }
+
           // Focus window for beforeunload dialog so it is seen but don't
           // steal focus from other applications.
           if (event.detail &&
               event.detail.tabPrompt &&
               event.detail.inPermitUnload &&
               Services.focus.activeWindow)
             window.focus();