Bug 1385548 - Part 2: Fix "tabEvent is undefined" exception for modals opened from a WebExtensions options_ui page.
MozReview-Commit-ID: LEQDru7pbIC
--- 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();