Bug 1453345 part 1. Switch session storage content scripts to not rely on XPCWrappedJS implementing nsIDOMEventListener. r=smaug
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 12 Apr 2018 00:03:44 -0400
changeset 412919 81d403264f0cd61686c0b842d6a1391b07c1ed43
parent 412918 72f15f83cdb6d373bccf3807c51173ec238668b3
child 412920 b7d33dbd5c48f59a6414951daa4f1a5e6a895e1c
push id33824
push userebalazs@mozilla.com
push dateThu, 12 Apr 2018 09:39:57 +0000
treeherdermozilla-central@246c614e1605 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1453345
milestone61.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 1453345 part 1. Switch session storage content scripts to not rely on XPCWrappedJS implementing nsIDOMEventListener. r=smaug MozReview-Commit-ID: LPYKxngcXJw
browser/components/sessionstore/nsISessionStoreUtils.idl
browser/components/sessionstore/nsSessionStoreUtils.cpp
--- a/browser/components/sessionstore/nsISessionStoreUtils.idl
+++ b/browser/components/sessionstore/nsISessionStoreUtils.idl
@@ -37,10 +37,11 @@ interface nsISessionStoreUtils : nsISupp
   /**
    * Creates and returns an event listener that filters events from dynamic
    * docShells. It forwards those from non-dynamic docShells to the given
    * |listener|.
    *
    * This is implemented as a native filter, rather than a JS-based one, for
    * performance reasons.
    */
-  nsIDOMEventListener createDynamicFrameEventFilter(in nsIDOMEventListener listener);
+  [implicit_jscontext]
+  nsIDOMEventListener createDynamicFrameEventFilter(in jsval listener);
 };
--- a/browser/components/sessionstore/nsSessionStoreUtils.cpp
+++ b/browser/components/sessionstore/nsSessionStoreUtils.cpp
@@ -1,36 +1,38 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsSessionStoreUtils.h"
 
 #include "mozilla/dom/Event.h"
+#include "mozilla/dom/EventListenerBinding.h"
+#include "mozilla/dom/ScriptSettings.h"
 #include "nsPIDOMWindow.h"
 #include "nsIDocShell.h"
 
 using namespace mozilla::dom;
 
 namespace {
 
 class DynamicFrameEventFilter final : public nsIDOMEventListener
 {
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_CLASS(DynamicFrameEventFilter)
 
-  explicit DynamicFrameEventFilter(nsIDOMEventListener* aListener)
+  explicit DynamicFrameEventFilter(EventListener* aListener)
     : mListener(aListener)
   { }
 
   NS_IMETHODIMP HandleEvent(nsIDOMEvent* aEvent) override
   {
     if (mListener && TargetInNonDynamicDocShell(aEvent)) {
-      mListener->HandleEvent(aEvent);
+      mListener->HandleEvent(*aEvent->InternalDOMEvent());
     }
 
     return NS_OK;
   }
 
 private:
   ~DynamicFrameEventFilter() { }
 
@@ -51,17 +53,17 @@ private:
       return false;
     }
 
     bool isDynamic = false;
     nsresult rv = docShell->GetCreatedDynamically(&isDynamic);
     return NS_SUCCEEDED(rv) && !isDynamic;
   }
 
-  nsCOMPtr<nsIDOMEventListener> mListener;
+  RefPtr<EventListener> mListener;
 };
 
 NS_IMPL_CYCLE_COLLECTION(DynamicFrameEventFilter, mListener)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DynamicFrameEventFilter)
   NS_INTERFACE_MAP_ENTRY(nsISupports)
   NS_INTERFACE_MAP_ENTRY(nsIDOMEventListener)
 NS_INTERFACE_MAP_END
@@ -109,18 +111,25 @@ nsSessionStoreUtils::ForEachNonDynamicCh
 
     aCallback->HandleFrame(item->GetWindow(), childOffset);
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsSessionStoreUtils::CreateDynamicFrameEventFilter(nsIDOMEventListener* aListener,
+nsSessionStoreUtils::CreateDynamicFrameEventFilter(JS::Handle<JS::Value> aListener,
+                                                   JSContext* aCx,
                                                    nsIDOMEventListener** aResult)
 {
-  NS_ENSURE_TRUE(aListener, NS_ERROR_INVALID_ARG);
+  if (NS_WARN_IF(!aListener.isObject())) {
+    return NS_ERROR_INVALID_ARG;
+  }
 
-  nsCOMPtr<nsIDOMEventListener> filter(new DynamicFrameEventFilter(aListener));
+  JS::Rooted<JSObject*> obj(aCx, &aListener.toObject());
+  RefPtr<EventListener> listener =
+    new EventListener(aCx, obj, GetIncumbentGlobal());
+
+  nsCOMPtr<nsIDOMEventListener> filter(new DynamicFrameEventFilter(listener));
   filter.forget(aResult);
 
   return NS_OK;
 }