Bug 1274520 part 1 - Add mozSystemGroup to EventListenerOptions for chrome and XBL to add listener in the system group. r=smaug draft
authorXidorn Quan <me@upsuper.org>
Mon, 23 May 2016 12:08:00 +1000
changeset 372664 6a40b3d0cec138f63ab3d91b068dbfeb45967c7e
parent 372663 a1afebd8d2e4e0b070fddb026134bd532a91d161
child 372665 f1755a506bf8f19a108b8750f5631958bd97c2a8
push id19556
push userxquan@mozilla.com
push dateSun, 29 May 2016 23:37:12 +0000
reviewerssmaug
bugs1274520
milestone49.0a1
Bug 1274520 part 1 - Add mozSystemGroup to EventListenerOptions for chrome and XBL to add listener in the system group. r=smaug MozReview-Commit-ID: 6DdLMEazWIC
dom/events/EventListenerManager.cpp
dom/webidl/EventTarget.webidl
--- a/dom/events/EventListenerManager.cpp
+++ b/dom/events/EventListenerManager.cpp
@@ -1333,16 +1333,29 @@ EventListenerManager::HandleEventInterna
 
 void
 EventListenerManager::Disconnect()
 {
   mTarget = nullptr;
   RemoveAllListeners();
 }
 
+static EventListenerFlags
+GetEventListenerFlagsFromOptions(const EventListenerOptions& aOptions)
+{
+  EventListenerFlags flags;
+  flags.mCapture = aOptions.mCapture;
+  if (aOptions.mMozSystemGroup) {
+    JSContext* cx = nsContentUtils::GetCurrentJSContext();
+    MOZ_ASSERT(cx, "Not being called from JS?");
+    flags.mInSystemGroup = IsChromeOrXBL(cx, nullptr);
+  }
+  return flags;
+}
+
 void
 EventListenerManager::AddEventListener(
                         const nsAString& aType,
                         const EventListenerHolder& aListenerHolder,
                         bool aUseCapture,
                         bool aWantsUntrusted)
 {
   EventListenerFlags flags;
@@ -1357,18 +1370,19 @@ EventListenerManager::AddEventListener(
                         const EventListenerHolder& aListenerHolder,
                         const dom::AddEventListenerOptionsOrBoolean& aOptions,
                         bool aWantsUntrusted)
 {
   EventListenerFlags flags;
   if (aOptions.IsBoolean()) {
     flags.mCapture = aOptions.GetAsBoolean();
   } else {
-    flags.mCapture = aOptions.GetAsAddEventListenerOptions().mCapture;
-    flags.mPassive = aOptions.GetAsAddEventListenerOptions().mPassive;
+    const auto& options = aOptions.GetAsAddEventListenerOptions();
+    flags = GetEventListenerFlagsFromOptions(options);
+    flags.mPassive = options.mPassive;
   }
   flags.mAllowUntrustedEvents = aWantsUntrusted;
   return AddEventListenerByType(aListenerHolder, aType, flags);
 }
 
 void
 EventListenerManager::RemoveEventListener(
                         const nsAString& aType,
@@ -1382,19 +1396,22 @@ EventListenerManager::RemoveEventListene
 
 void
 EventListenerManager::RemoveEventListener(
                         const nsAString& aType,
                         const EventListenerHolder& aListenerHolder,
                         const dom::EventListenerOptionsOrBoolean& aOptions)
 {
   EventListenerFlags flags;
-  flags.mCapture =
-    aOptions.IsBoolean() ? aOptions.GetAsBoolean()
-                         : aOptions.GetAsEventListenerOptions().mCapture;
+  if (aOptions.IsBoolean()) {
+    flags.mCapture = aOptions.GetAsBoolean();
+  } else {
+    const auto& options = aOptions.GetAsEventListenerOptions();
+    flags = GetEventListenerFlagsFromOptions(options);
+  }
   RemoveEventListenerByType(aListenerHolder, aType, flags);
 }
 
 void
 EventListenerManager::AddListenerForAllEvents(nsIDOMEventListener* aDOMListener,
                                               bool aUseCapture,
                                               bool aWantsUntrusted,
                                               bool aSystemEventGroup)
--- a/dom/webidl/EventTarget.webidl
+++ b/dom/webidl/EventTarget.webidl
@@ -8,16 +8,19 @@
  *
  * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
  * liability, trademark and document use rules apply.
  */
 
 
 dictionary EventListenerOptions {
   boolean capture = false;
+  /* This is a Mozilla extension only available in Chrome and XBL.
+     Setting to true make the listener be added to the system group. */
+  boolean mozSystemGroup = false;
 };
 
 dictionary AddEventListenerOptions : EventListenerOptions {
   boolean passive = false;
   boolean once = false;
 };
 
 [Exposed=(Window,Worker,WorkerDebugger,System)]