Bug 1498812 - Part 5: Allow registering System event listeners through nsSessionStoreUtils. r=nika
authorJan Henning <jh+bugzilla@buttercookie.de>
Fri, 11 Jan 2019 19:49:28 +0000
changeset 453549 710922bc053a
parent 453548 7b00521b6f31
child 453550 4eccacfc8801
push id35360
push usernbeleuzu@mozilla.com
push dateSat, 12 Jan 2019 09:39:47 +0000
treeherdermozilla-central@cb35977ae7a4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnika
bugs1498812
milestone66.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 1498812 - Part 5: Allow registering System event listeners through nsSessionStoreUtils. r=nika Our internal Visual Viewport scroll events are dispatched system group-only, so this is the only way to catch them. Differential Revision: https://phabricator.services.mozilla.com/D15686
toolkit/components/sessionstore/nsISessionStoreUtils.idl
toolkit/components/sessionstore/nsSessionStoreUtils.cpp
--- a/toolkit/components/sessionstore/nsISessionStoreUtils.idl
+++ b/toolkit/components/sessionstore/nsISessionStoreUtils.idl
@@ -46,32 +46,34 @@ interface nsISessionStoreUtils : nsISupp
    *
    * This is implemented as a native filter, rather than a JS-based one, for
    * performance reasons.
    */
   [implicit_jscontext]
   nsISupports addDynamicFrameFilteredListener(in EventTarget target,
                                               in AString type,
                                               in jsval listener,
-                                              in boolean useCapture);
+                                              in boolean useCapture,
+                                              [optional] in boolean mozSystemGroup);
 
   /**
    * Remove the passed-in filtered listener from the given event target, if it's
    * currently a listener for the given event type there.  The 'listener'
    * argument must be something that was returned by
    * addDynamicFrameFilteredListener.
    *
    * This is needed, instead of the normal removeEventListener, because the
    * caller doesn't actually have something that WebIDL considers an
    * EventListener.
    */
   void removeDynamicFrameFilteredListener(in EventTarget target,
                                           in AString type,
                                           in nsISupports listener,
-                                          in boolean useCapture);
+                                          in boolean useCapture,
+                                          [optional] in boolean mozSystemGroup);
 
   /*
    * Save the docShell.allow* properties
    */
   ACString collectDocShellCapabilities(in nsIDocShell docShell);
 
   /*
    * Restore the docShell.allow* properties
--- a/toolkit/components/sessionstore/nsSessionStoreUtils.cpp
+++ b/toolkit/components/sessionstore/nsSessionStoreUtils.cpp
@@ -111,49 +111,59 @@ nsSessionStoreUtils::ForEachNonDynamicCh
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSessionStoreUtils::AddDynamicFrameFilteredListener(
     EventTarget* aTarget, const nsAString& aType,
-    JS::Handle<JS::Value> aListener, bool aUseCapture, JSContext* aCx,
-    nsISupports** aResult) {
+    JS::Handle<JS::Value> aListener, bool aUseCapture, bool aMozSystemGroup,
+    JSContext* aCx, nsISupports** aResult) {
   if (NS_WARN_IF(!aListener.isObject())) {
     return NS_ERROR_INVALID_ARG;
   }
 
   NS_ENSURE_TRUE(aTarget, NS_ERROR_NO_INTERFACE);
 
   JS::Rooted<JSObject*> obj(aCx, &aListener.toObject());
   JS::Rooted<JSObject*> global(aCx, JS::CurrentGlobalOrNull(aCx));
   RefPtr<EventListener> listener =
       new EventListener(aCx, obj, global, GetIncumbentGlobal());
 
   nsCOMPtr<nsIDOMEventListener> filter(new DynamicFrameEventFilter(listener));
 
-  nsresult rv = aTarget->AddEventListener(aType, filter, aUseCapture);
+  nsresult rv;
+  if (aMozSystemGroup) {
+    rv = aTarget->AddSystemEventListener(aType, filter, aUseCapture);
+  } else {
+    rv = aTarget->AddEventListener(aType, filter, aUseCapture);
+  }
   NS_ENSURE_SUCCESS(rv, rv);
 
   filter.forget(aResult);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSessionStoreUtils::RemoveDynamicFrameFilteredListener(EventTarget* aTarget,
                                                         const nsAString& aType,
                                                         nsISupports* aListener,
-                                                        bool aUseCapture) {
+                                                        bool aUseCapture,
+                                                        bool aMozSystemGroup) {
   NS_ENSURE_TRUE(aTarget, NS_ERROR_NO_INTERFACE);
 
   nsCOMPtr<nsIDOMEventListener> listener = do_QueryInterface(aListener);
   NS_ENSURE_TRUE(listener, NS_ERROR_NO_INTERFACE);
 
-  aTarget->RemoveEventListener(aType, listener, aUseCapture);
+  if (aMozSystemGroup) {
+    aTarget->RemoveSystemEventListener(aType, listener, aUseCapture);
+  } else {
+    aTarget->RemoveEventListener(aType, listener, aUseCapture);
+  }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSessionStoreUtils::CollectDocShellCapabilities(
     nsIDocShell* aDocShell, nsACString& aDisallowCapabilities) {
   bool allow;