Bug 1385548 - Part 3: Fix exception raised by calling target.contains on the gBrowser stub defined in "about:addons". draft
authorLuca Greco <lgreco@mozilla.com>
Tue, 19 Sep 2017 16:07:59 +0200
changeset 667054 8129757327935c43713dbbf06a2523ac41ef2846
parent 667053 964d00cc765d396e1e88fd42bfa80e25fb6cf6e7
child 667055 e65bc2cd702f20c6ad7a247541c6785ef6f25702
push id80600
push userluca.greco@alcacoop.it
push dateTue, 19 Sep 2017 16:57:34 +0000
bugs1385548
milestone57.0a1
Bug 1385548 - Part 3: Fix exception raised by calling target.contains on the gBrowser stub defined in "about:addons". MozReview-Commit-ID: zvcyHIqjNR
toolkit/components/addoncompat/RemoteAddonsParent.jsm
--- a/toolkit/components/addoncompat/RemoteAddonsParent.jsm
+++ b/toolkit/components/addoncompat/RemoteAddonsParent.jsm
@@ -436,16 +436,30 @@ var EventTargetParent = {
         return target;
       } else if (target.localName == "tab") {
         return target.linkedBrowser;
       }
 
       // Check if |target| is somewhere on the patch from the
       // <tabbrowser> up to the root element.
       let window = target.ownerGlobal;
+
+      // Prevents the fake about:addons gBrowser to be checked
+      // using target.contains, because it raises an exception if gBrowser
+      // is not a Node as expected by a tabbrowser gBrowser.
+      // (See Bug 1385548 for rationale).
+      if (window) {
+        let principal = window.document.nodePrincipal;
+        if (Services.scriptSecurityManager.isSystemPrincipal(principal) &&
+            window.location.href === "about:addons" &&
+            window.gBrowser) {
+          return null;
+        }
+      }
+
       if (window && target.contains(window.gBrowser)) {
         return window;
       }
     }
 
     return null;
   },