Bug 1484363: Treat FrameMessageManagers as chrome event targets. r=smaug
authorKris Maglione <maglione.k@gmail.com>
Fri, 17 Aug 2018 15:11:11 -0700
changeset 432225 777ba79e0e0a8cfbea6c3a9d2fe4ff9fdb58bb3c
parent 432224 b2814d1bbbd7fc10f79c32daeaf67b4c6d527e7a
child 432226 5477aa895b6c983f52325a3841571f4c4ba8f7f6
child 432266 3d54f2f451ca785ba616d4cba03b9efc004fd385
push id106675
push usermaglione.k@gmail.com
push dateSat, 18 Aug 2018 06:30:33 +0000
treeherdermozilla-inbound@777ba79e0e0a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1484363
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1484363: Treat FrameMessageManagers as chrome event targets. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D3663
dom/base/test/browser_bug1058164.js
dom/events/EventDispatcher.cpp
--- a/dom/base/test/browser_bug1058164.js
+++ b/dom/base/test/browser_bug1058164.js
@@ -46,21 +46,21 @@ function prepareForVisibilityEvents(brow
       order.push(type);
       checkSatisfied();
     };
 
     let checkFn = (e) => e.persisted;
 
     rmvHide = BrowserTestUtils.addContentEventListener(browser, "pagehide",
                                                        () => eventListener("pagehide"),
-                                                       {mozSystemGroup: true}, checkFn,
+                                                       {}, checkFn,
                                                        false, false);
     rmvShow = BrowserTestUtils.addContentEventListener(browser, "pageshow",
                                                        () => eventListener("pageshow"),
-                                                       {mozSystemGroup: true}, checkFn,
+                                                       {}, checkFn,
                                                        false, false);
   });
 }
 
 /**
  * Tests that frame scripts get pageshow / pagehide events when
  * swapping browser frameloaders (which occurs when moving a tab
  * into a different window).
@@ -90,17 +90,17 @@ add_task(async function test_swap_framel
   gBrowser.selectedTab = newTab;
   let emptyBrowser = newTab.linkedBrowser;
 
   // Wait for that initial browser to show its pageshow event if it hasn't
   // happened so that we don't confuse it with the other expected events.
   await ContentTask.spawn(emptyBrowser, {}, async() => {
     if (content.document.visibilityState === "hidden") {
       info("waiting for hidden emptyBrowser to pageshow");
-      await ContentTaskUtils.waitForEvent(content, "pageshow", {mozSystemGroup: true});
+      await ContentTaskUtils.waitForEvent(content, "pageshow", {});
     }
   });
 
   // The empty tab we just added show now fire a pagehide as its replaced,
   // and a pageshow once the swap is finished.
   let emptyBrowserPromise =
     prepareForVisibilityEvents(emptyBrowser, ["pagehide", "pageshow"]);
 
--- a/dom/events/EventDispatcher.cpp
+++ b/dom/events/EventDispatcher.cpp
@@ -7,16 +7,17 @@
 #include "nsPresContext.h"
 #include "nsContentUtils.h"
 #include "nsError.h"
 #include <new>
 #include "nsIContent.h"
 #include "nsIContentInlines.h"
 #include "nsIDocument.h"
 #include "nsINode.h"
+#include "nsIScriptObjectPrincipal.h"
 #include "nsPIDOMWindow.h"
 #include "AnimationEvent.h"
 #include "BeforeUnloadEvent.h"
 #include "ClipboardEvent.h"
 #include "CommandEvent.h"
 #include "CompositionEvent.h"
 #include "DeviceMotionEvent.h"
 #include "DragEvent.h"
@@ -99,32 +100,33 @@ private:
 static bool IsEventTargetChrome(EventTarget* aEventTarget,
                                 nsIDocument** aDocument = nullptr)
 {
   if (aDocument) {
     *aDocument = nullptr;
   }
 
   nsIDocument* doc = nullptr;
-  nsCOMPtr<nsINode> node = do_QueryInterface(aEventTarget);
-  if (node) {
+  if (nsCOMPtr<nsINode> node = do_QueryInterface(aEventTarget)) {
     doc = node->OwnerDoc();
-  } else {
-    nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(aEventTarget);
-    if (!window) {
-      return false;
-    }
+  } else if (nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(aEventTarget)) {
     doc = window->GetExtantDoc();
   }
 
   // nsContentUtils::IsChromeDoc is null-safe.
-  bool isChrome = nsContentUtils::IsChromeDoc(doc);
-  if (aDocument && doc) {
-    nsCOMPtr<nsIDocument> retVal = doc;
-    retVal.swap(*aDocument);
+  bool isChrome = false;
+  if (doc) {
+    isChrome = nsContentUtils::IsChromeDoc(doc);
+    if (aDocument) {
+      nsCOMPtr<nsIDocument> retVal = doc;
+      retVal.swap(*aDocument);
+    }
+  } else if (nsCOMPtr<nsIScriptObjectPrincipal> sop =
+              do_QueryInterface(aEventTarget->GetOwnerGlobal())) {
+    isChrome = nsContentUtils::IsSystemPrincipal(sop->GetPrincipal());
   }
   return isChrome;
 }
 
 
 // EventTargetChainItem represents a single item in the event target chain.
 class EventTargetChainItem
 {