Bug 743198 part 5 - Check legacy event listener only if listener is found in the current group. draft
authorXidorn Quan <quanxunzhen@gmail.com>
Tue, 16 Feb 2016 09:23:52 +0800
changeset 331132 91ab70926e7f105a724a54ef4a6e890064fea6b3
parent 331131 2ab4a795e9f0dda71d51bb4ca05eafe7ab48c234
child 331133 bc7fb122b6eaea85142647e5b9c4f56819e3b67c
push id10905
push userxquan@mozilla.com
push dateTue, 16 Feb 2016 01:34:33 +0000
bugs743198
milestone47.0a1
Bug 743198 part 5 - Check legacy event listener only if listener is found in the current group. MozReview-Commit-ID: LL0bxS56vHv
dom/events/EventListenerManager.cpp
--- a/dom/events/EventListenerManager.cpp
+++ b/dom/events/EventListenerManager.cpp
@@ -1187,31 +1187,34 @@ EventListenerManager::HandleEventInterna
   }
 
   Maybe<nsAutoPopupStatePusher> popupStatePusher;
   if (mIsMainThreadELM) {
     popupStatePusher.emplace(Event::GetEventPopupControlState(aEvent, *aDOMEvent));
   }
 
   bool hasListener = false;
+  bool hasListenerForCurrentGroup = false;
   bool usingLegacyMessage = false;
   EventMessage eventMessage = aEvent->mMessage;
 
   while (true) {
     nsAutoTObserverArray<Listener, 2>::EndLimitedIterator iter(mListeners);
     Maybe<EventMessageAutoOverride> legacyAutoOverride;
     while (iter.HasMore()) {
       if (aEvent->mFlags.mImmediatePropagationStopped) {
         break;
       }
       Listener* listener = &iter.GetNext();
       // Check that the phase is same in event and event listener.
       // Handle only trusted events, except when listener permits untrusted events.
       if (ListenerCanHandle(listener, aEvent, eventMessage)) {
         hasListener = true;
+        hasListenerForCurrentGroup = hasListenerForCurrentGroup ||
+          listener->mFlags.mInSystemGroup == aEvent->mFlags.mInSystemGroup;
         if (listener->IsListening(aEvent) &&
             (aEvent->mFlags.mIsTrusted ||
              listener->mFlags.mAllowUntrustedEvents)) {
           if (!*aDOMEvent) {
             // This is tiny bit slow, but happens only once per event.
             nsCOMPtr<EventTarget> et =
               do_QueryInterface(aEvent->originalTarget);
             RefPtr<Event> event = EventDispatcher::CreateEvent(et, aPresContext,
@@ -1263,20 +1266,20 @@ EventListenerManager::HandleEventInterna
               timelines->AddMarkerForDocShell(
                 docShell, "DOMEvent", MarkerTracingType::END);
             }
           }
         }
       }
     }
 
-    // If we didn't find any matching listeners, and our event has a legacy
-    // version, we'll now switch to looking for that legacy version and we'll
-    // recheck our listeners.
-    if (hasListener || usingLegacyMessage) {
+    // If we didn't find any matching non-system listeners, and our
+    // event has a legacy version, we'll now switch to looking for
+    // that legacy version and we'll recheck our listeners.
+    if (hasListenerForCurrentGroup || usingLegacyMessage) {
       // (No need to recheck listeners, because we already found a match, or we
       // already rechecked them.)
       break;
     }
     EventMessage legacyEventMessage = GetLegacyEventMessage(eventMessage);
     if (legacyEventMessage == eventMessage) {
       break; // There's no legacy version of our event; no need to recheck.
     }