Bug 1449631 part 2. Remove nsIDOMEventTarget::RemoveEventListener. r=smaug
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 05 Apr 2018 13:42:40 -0400
changeset 411924 34f06ffa0c0e0fe214d8cc9531c8a17654138fbc
parent 411923 0e9e38b63ba46d90e0cc5410b99f085269a0f6d3
child 411925 059872bf21beb529dc3552b3953474d007e76423
push id101783
push userbzbarsky@mozilla.com
push dateThu, 05 Apr 2018 17:44:01 +0000
treeherdermozilla-inbound@d32c2aed2886 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1449631
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 1449631 part 2. Remove nsIDOMEventTarget::RemoveEventListener. r=smaug We can't have a null content in ScrollbarActivity::StopListeningForScrollAreaEvents, because only viewport frames have a null GetContent(). MozReview-Commit-ID: 9iAg0ivVqqG
accessible/generic/RootAccessible.cpp
dom/base/nsGlobalWindowInner.cpp
dom/base/nsGlobalWindowInner.h
dom/base/nsGlobalWindowOuter.cpp
dom/base/nsGlobalWindowOuter.h
dom/base/nsINode.cpp
dom/base/nsINode.h
dom/base/nsWindowRoot.cpp
dom/base/nsWindowRoot.h
dom/events/DOMEventTargetHelper.cpp
dom/events/DOMEventTargetHelper.h
dom/events/EventTarget.cpp
dom/events/EventTarget.h
dom/interfaces/events/nsIDOMEventTarget.idl
dom/webauthn/WebAuthnManagerBase.cpp
dom/xhr/XMLHttpRequestWorker.cpp
editor/libeditor/HTMLAbsPositionEditor.cpp
editor/libeditor/HTMLAnonymousNodeEditor.cpp
editor/libeditor/HTMLEditor.cpp
editor/libeditor/HTMLEditorObjectResizer.cpp
editor/libeditor/HTMLInlineTableEditor.cpp
layout/base/MobileViewportManager.cpp
layout/base/MobileViewportManager.h
layout/base/ZoomConstraintsClient.h
layout/generic/ScrollbarActivity.cpp
layout/generic/ScrollbarActivity.h
--- a/accessible/generic/RootAccessible.cpp
+++ b/accessible/generic/RootAccessible.cpp
@@ -203,18 +203,17 @@ RootAccessible::AddEventListeners()
 nsresult
 RootAccessible::RemoveEventListeners()
 {
   nsCOMPtr<EventTarget> target = mDocumentNode;
   if (target) {
     for (const char* const* e = kEventTypes,
                    * const* e_end = ArrayEnd(kEventTypes);
          e < e_end; ++e) {
-      nsresult rv = target->RemoveEventListener(NS_ConvertASCIItoUTF16(*e), this, true);
-      NS_ENSURE_SUCCESS(rv, rv);
+      target->RemoveEventListener(NS_ConvertASCIItoUTF16(*e), this, true);
     }
   }
 
   // Do this before removing clearing caret accessible, so that it can use
   // shutdown the caret accessible's selection listener
   DocAccessible::RemoveEventListeners();
   return NS_OK;
 }
--- a/dom/base/nsGlobalWindowInner.cpp
+++ b/dom/base/nsGlobalWindowInner.cpp
@@ -4476,27 +4476,16 @@ nsGlobalWindowInner::Btoa(const nsAStrin
 //*****************************************************************************
 
 nsPIDOMWindowOuter*
 nsGlobalWindowInner::GetOwnerGlobalForBindings()
 {
   return nsPIDOMWindowOuter::GetFromCurrentInner(this);
 }
 
-NS_IMETHODIMP
-nsGlobalWindowInner::RemoveEventListener(const nsAString& aType,
-                                         nsIDOMEventListener* aListener,
-                                         bool aUseCapture)
-{
-  if (RefPtr<EventListenerManager> elm = GetExistingListenerManager()) {
-    elm->RemoveEventListener(aType, aListener, aUseCapture);
-  }
-  return NS_OK;
-}
-
 NS_IMPL_REMOVE_SYSTEM_EVENT_LISTENER(nsGlobalWindowInner)
 
 NS_IMETHODIMP
 nsGlobalWindowInner::DispatchEvent(nsIDOMEvent* aEvent, bool* aRetVal)
 {
   if (!IsCurrentInnerWindow()) {
     NS_WARNING("DispatchEvent called on non-current inner window, dropping. "
                "Please check the window in the caller instead.");
--- a/dom/base/nsGlobalWindowInner.h
+++ b/dom/base/nsGlobalWindowInner.h
@@ -319,17 +319,16 @@ public:
   NS_DECL_NSIDOMEVENTTARGET
 
   virtual mozilla::EventListenerManager*
     GetExistingListenerManager() const override;
 
   virtual mozilla::EventListenerManager*
     GetOrCreateListenerManager() override;
 
-  using mozilla::dom::EventTarget::RemoveEventListener;
   virtual void AddEventListener(const nsAString& aType,
                                 mozilla::dom::EventListener* aListener,
                                 const mozilla::dom::AddEventListenerOptionsOrBoolean& aOptions,
                                 const mozilla::dom::Nullable<bool>& aWantsUntrusted,
                                 mozilla::ErrorResult& aRv) override;
   virtual nsPIDOMWindowOuter* GetOwnerGlobalForBindings() override;
 
   virtual nsIGlobalObject* GetOwnerGlobal() const override;
--- a/dom/base/nsGlobalWindowOuter.cpp
+++ b/dom/base/nsGlobalWindowOuter.cpp
@@ -6470,24 +6470,16 @@ nsGlobalWindowOuter::FindOuter(const nsA
 //*****************************************************************************
 
 nsPIDOMWindowOuter*
 nsGlobalWindowOuter::GetOwnerGlobalForBindings()
 {
   return this;
 }
 
-NS_IMETHODIMP
-nsGlobalWindowOuter::RemoveEventListener(const nsAString& aType,
-                                         nsIDOMEventListener* aListener,
-                                         bool aUseCapture)
-{
-  FORWARD_TO_INNER(RemoveEventListener, (aType, aListener, aUseCapture), NS_OK);
-}
-
 NS_IMPL_REMOVE_SYSTEM_EVENT_LISTENER(nsGlobalWindowOuter)
 
 NS_IMETHODIMP
 nsGlobalWindowOuter::DispatchEvent(nsIDOMEvent* aEvent, bool* aRetVal)
 {
   FORWARD_TO_INNER(DispatchEvent, (aEvent, aRetVal), NS_OK);
 }
 
--- a/dom/base/nsGlobalWindowOuter.h
+++ b/dom/base/nsGlobalWindowOuter.h
@@ -276,17 +276,16 @@ public:
   NS_DECL_NSIDOMEVENTTARGET
 
   virtual mozilla::EventListenerManager*
     GetExistingListenerManager() const override;
 
   virtual mozilla::EventListenerManager*
     GetOrCreateListenerManager() override;
 
-  using mozilla::dom::EventTarget::RemoveEventListener;
   virtual void AddEventListener(const nsAString& aType,
                                 mozilla::dom::EventListener* aListener,
                                 const mozilla::dom::AddEventListenerOptionsOrBoolean& aOptions,
                                 const mozilla::dom::Nullable<bool>& aWantsUntrusted,
                                 mozilla::ErrorResult& aRv) override;
   virtual nsPIDOMWindowOuter* GetOwnerGlobalForBindings() override;
 
   virtual nsIGlobalObject* GetOwnerGlobal() const override;
--- a/dom/base/nsINode.cpp
+++ b/dom/base/nsINode.cpp
@@ -1084,28 +1084,16 @@ nsINode::AddSystemEventListener(const ns
        !nsContentUtils::IsChromeDoc(OwnerDoc()))) {
     aWantsUntrusted = true;
   }
 
   return NS_AddSystemEventListener(this, aType, aListener, aUseCapture,
                                    aWantsUntrusted);
 }
 
-NS_IMETHODIMP
-nsINode::RemoveEventListener(const nsAString& aType,
-                             nsIDOMEventListener* aListener,
-                             bool aUseCapture)
-{
-  EventListenerManager* elm = GetExistingListenerManager();
-  if (elm) {
-    elm->RemoveEventListener(aType, aListener, aUseCapture);
-  }
-  return NS_OK;
-}
-
 NS_IMPL_REMOVE_SYSTEM_EVENT_LISTENER(nsINode)
 
 nsresult
 nsINode::GetEventTargetParent(EventChainPreVisitor& aVisitor)
 {
   MOZ_ASSERT_UNREACHABLE("GetEventTargetParent is only here so that we can "
                          "use the NS_DECL_NSIDOMTARGET macro");
   return NS_ERROR_NOT_IMPLEMENTED;
--- a/dom/base/nsINode.h
+++ b/dom/base/nsINode.h
@@ -1024,17 +1024,16 @@ public:
    */
   NS_DECL_NSIDOMEVENTTARGET
 
   virtual mozilla::EventListenerManager*
     GetExistingListenerManager() const override;
   virtual mozilla::EventListenerManager*
     GetOrCreateListenerManager() override;
 
-  using mozilla::dom::EventTarget::RemoveEventListener;
   using nsIDOMEventTarget::AddEventListener;
   virtual void AddEventListener(const nsAString& aType,
                                 mozilla::dom::EventListener* aListener,
                                 const mozilla::dom::AddEventListenerOptionsOrBoolean& aOptions,
                                 const mozilla::dom::Nullable<bool>& aWantsUntrusted,
                                 mozilla::ErrorResult& aRv) override;
   using nsIDOMEventTarget::AddSystemEventListener;
 
--- a/dom/base/nsWindowRoot.cpp
+++ b/dom/base/nsWindowRoot.cpp
@@ -67,25 +67,16 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(
   NS_INTERFACE_MAP_ENTRY(mozilla::dom::EventTarget)
 NS_INTERFACE_MAP_END
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsWindowRoot)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsWindowRoot)
 
 NS_IMPL_DOMTARGET_DEFAULTS(nsWindowRoot)
 
-NS_IMETHODIMP
-nsWindowRoot::RemoveEventListener(const nsAString& aType, nsIDOMEventListener* aListener, bool aUseCapture)
-{
-  if (RefPtr<EventListenerManager> elm = GetExistingListenerManager()) {
-    elm->RemoveEventListener(aType, aListener, aUseCapture);
-  }
-  return NS_OK;
-}
-
 NS_IMPL_REMOVE_SYSTEM_EVENT_LISTENER(nsWindowRoot)
 
 NS_IMETHODIMP
 nsWindowRoot::DispatchEvent(nsIDOMEvent* aEvt, bool *aRetVal)
 {
   nsEventStatus status = nsEventStatus_eIgnore;
   nsresult rv =  EventDispatcher::DispatchDOMEvent(
     static_cast<EventTarget*>(this), nullptr, aEvt, nullptr, &status);
--- a/dom/base/nsWindowRoot.h
+++ b/dom/base/nsWindowRoot.h
@@ -27,17 +27,16 @@ public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_NSIDOMEVENTTARGET
 
   virtual mozilla::EventListenerManager*
     GetExistingListenerManager() const override;
   virtual mozilla::EventListenerManager*
     GetOrCreateListenerManager() override;
 
-  using mozilla::dom::EventTarget::RemoveEventListener;
   virtual void AddEventListener(const nsAString& aType,
                                 mozilla::dom::EventListener* aListener,
                                 const mozilla::dom::AddEventListenerOptionsOrBoolean& aOptions,
                                 const mozilla::dom::Nullable<bool>& aWantsUntrusted,
                                 mozilla::ErrorResult& aRv) override;
 
   // nsPIWindowRoot
 
--- a/dom/events/DOMEventTargetHelper.cpp
+++ b/dom/events/DOMEventTargetHelper.cpp
@@ -170,29 +170,16 @@ DOMEventTargetHelper::GetDocumentIfCurre
   nsPIDOMWindowInner* win = GetWindowIfCurrent();
   if (!win) {
     return nullptr;
   }
 
   return win->GetDoc();
 }
 
-NS_IMETHODIMP
-DOMEventTargetHelper::RemoveEventListener(const nsAString& aType,
-                                          nsIDOMEventListener* aListener,
-                                          bool aUseCapture)
-{
-  EventListenerManager* elm = GetExistingListenerManager();
-  if (elm) {
-    elm->RemoveEventListener(aType, aListener, aUseCapture);
-  }
-
-  return NS_OK;
-}
-
 NS_IMPL_REMOVE_SYSTEM_EVENT_LISTENER(DOMEventTargetHelper)
 
 NS_IMETHODIMP
 DOMEventTargetHelper::AddEventListener(const nsAString& aType,
                                        nsIDOMEventListener* aListener,
                                        bool aUseCapture,
                                        bool aWantsUntrusted,
                                        uint8_t aOptionalArgc)
--- a/dom/events/DOMEventTargetHelper.h
+++ b/dom/events/DOMEventTargetHelper.h
@@ -68,17 +68,17 @@ public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS(DOMEventTargetHelper)
 
   NS_DECL_NSIDOMEVENTTARGET
 
   virtual EventListenerManager* GetExistingListenerManager() const override;
   virtual EventListenerManager* GetOrCreateListenerManager() override;
 
-  using dom::EventTarget::RemoveEventListener;
+  using EventTarget::AddEventListener;
   virtual void AddEventListener(const nsAString& aType,
                                 dom::EventListener* aListener,
                                 const dom::AddEventListenerOptionsOrBoolean& aOptions,
                                 const dom::Nullable<bool>& aWantsUntrusted,
                                 ErrorResult& aRv) override;
 
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_DOMEVENTTARGETHELPER_IID)
 
@@ -234,19 +234,16 @@ NS_DEFINE_STATIC_IID_ACCESSOR(DOMEventTa
  */
 #define NS_FORWARD_NSIDOMEVENTTARGET_NOGETEVENTTARGETPARENT(_to) \
   NS_IMETHOD AddEventListener(const nsAString & type, nsIDOMEventListener *listener, bool useCapture, bool wantsUntrusted, uint8_t _argc) override { \
     return _to AddEventListener(type, listener, useCapture, wantsUntrusted, _argc); \
   } \
   NS_IMETHOD AddSystemEventListener(const nsAString & type, nsIDOMEventListener *listener, bool aUseCapture, bool aWantsUntrusted, uint8_t _argc) override { \
     return _to AddSystemEventListener(type, listener, aUseCapture, aWantsUntrusted, _argc); \
   } \
-  NS_IMETHOD RemoveEventListener(const nsAString & type, nsIDOMEventListener *listener, bool useCapture) override { \
-    return _to RemoveEventListener(type, listener, useCapture); \
-  } \
   NS_IMETHOD RemoveSystemEventListener(const nsAString & type, nsIDOMEventListener *listener, bool aUseCapture) override { \
     return _to RemoveSystemEventListener(type, listener, aUseCapture); \
   } \
   NS_IMETHOD DispatchEvent(nsIDOMEvent *evt, bool *_retval) override { \
     return _to DispatchEvent(evt, _retval); \
   } \
   virtual mozilla::dom::EventTarget* GetTargetForDOMEvent() { \
     return _to GetTargetForDOMEvent(); \
@@ -272,17 +269,16 @@ NS_DEFINE_STATIC_IID_ACCESSOR(DOMEventTa
     return _to GetExistingListenerManager(); \
   } \
   virtual nsIScriptContext * GetContextForEventHandlers(nsresult *aRv) { \
     return _to GetContextForEventHandlers(aRv); \
   }
 
 #define NS_REALLY_FORWARD_NSIDOMEVENTTARGET(_class) \
   using _class::AddEventListener;                   \
-  using _class::RemoveEventListener;                \
   NS_FORWARD_NSIDOMEVENTTARGET(_class::)            \
   virtual mozilla::EventListenerManager*            \
   GetOrCreateListenerManager() override {           \
     return _class::GetOrCreateListenerManager();    \
   }                                                 \
   virtual mozilla::EventListenerManager*            \
   GetExistingListenerManager() const override {     \
     return _class::GetExistingListenerManager();    \
--- a/dom/events/EventTarget.cpp
+++ b/dom/events/EventTarget.cpp
@@ -34,16 +34,27 @@ EventTarget::RemoveEventListener(const n
                                  ErrorResult& aRv)
 {
   EventListenerManager* elm = GetExistingListenerManager();
   if (elm) {
     elm->RemoveEventListener(aType, aListener, aOptions);
   }
 }
 
+void
+EventTarget::RemoveEventListener(const nsAString& aType,
+                                 nsIDOMEventListener* aListener,
+                                 bool aUseCapture)
+{
+  EventListenerManager* elm = GetExistingListenerManager();
+  if (elm) {
+    elm->RemoveEventListener(aType, aListener, aUseCapture);
+  }
+}
+
 EventHandlerNonNull*
 EventTarget::GetEventHandler(nsAtom* aType, const nsAString& aTypeString)
 {
   EventListenerManager* elm = GetExistingListenerManager();
   return elm ? elm->GetEventHandler(aType, aTypeString) : nullptr;
 }
 
 void
--- a/dom/events/EventTarget.h
+++ b/dom/events/EventTarget.h
@@ -42,27 +42,34 @@ class EventTarget : public nsIDOMEventTa
 {
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_EVENTTARGET_IID)
 
   // WebIDL API
   static already_AddRefed<EventTarget> Constructor(const GlobalObject& aGlobal,
                                                    ErrorResult& aRv);
   using nsIDOMEventTarget::AddEventListener;
-  using nsIDOMEventTarget::RemoveEventListener;
   using nsIDOMEventTarget::DispatchEvent;
   virtual void AddEventListener(const nsAString& aType,
                                 EventListener* aCallback,
                                 const AddEventListenerOptionsOrBoolean& aOptions,
                                 const Nullable<bool>& aWantsUntrusted,
                                 ErrorResult& aRv) = 0;
-  virtual void RemoveEventListener(const nsAString& aType,
-                                   EventListener* aCallback,
-                                   const EventListenerOptionsOrBoolean& aOptions,
-                                   ErrorResult& aRv);
+  void RemoveEventListener(const nsAString& aType,
+                           EventListener* aCallback,
+                           const EventListenerOptionsOrBoolean& aOptions,
+                           ErrorResult& aRv);
+  /**
+   * This method allows the removal of event listeners represented by
+   * nsIDOMEventListener from the event target, with the same semantics as the
+   * standard RemoveEventListener.
+   */
+  void RemoveEventListener(const nsAString& aType,
+                           nsIDOMEventListener* aListener,
+                           bool aUseCapture);
   bool DispatchEvent(Event& aEvent, CallerType aCallerType, ErrorResult& aRv);
 
   nsIGlobalObject* GetParentObject() const
   {
     return GetOwnerGlobal();
   }
 
   // Note, this takes the type in onfoo form!
--- a/dom/interfaces/events/nsIDOMEventTarget.idl
+++ b/dom/interfaces/events/nsIDOMEventTarget.idl
@@ -135,40 +135,16 @@ interface nsIDOMEventTarget : nsISupport
                                   bool aWantsUntrusted)
   {
     return AddSystemEventListener(aType, aListener, aUseCapture,
                                   aWantsUntrusted, 2);
   }
 %}
 
   /**
-   * This method allows the removal of event listeners from the event 
-   * target. If an EventListener is removed from an EventTarget while it 
-   * is processing an event, it will not be triggered by the current actions. 
-   * EventListeners can never be invoked after being removed.
-   * Calling removeEventListener with arguments which do not identify any 
-   * currently registered EventListener on the EventTarget has no effect.
-   *
-   * @param   type Specifies the event type of the EventListener being 
-   *               removed.
-   * @param   listener The EventListener parameter indicates the 
-   *                   EventListener to be removed.
-   * @param   useCapture Specifies whether the EventListener being 
-   *                     removed was registered as a capturing listener or 
-   *                     not. If a listener was registered twice, one with 
-   *                     capture and one without, each must be removed 
-   *                     separately. Removal of a capturing listener does 
-   *                     not affect a non-capturing version of the same 
-   *                     listener, and vice versa.
-   */
-  void                     removeEventListener(in DOMString type,
-                                               in nsIDOMEventListener listener,
-                                               [optional] in boolean useCapture);
-
-  /**
    * removeSystemEventListener() should be used if you have used
    * addSystemEventListener().
    */
   [noscript] void          removeSystemEventListener(
                              in DOMString type,
                              in nsIDOMEventListener listener,
                              [optional] in boolean aUseCapture);
 
--- a/dom/webauthn/WebAuthnManagerBase.cpp
+++ b/dom/webauthn/WebAuthnManagerBase.cpp
@@ -107,23 +107,20 @@ WebAuthnManagerBase::StopListeningForVis
     return;
   }
 
   nsCOMPtr<EventTarget> windowRoot = outer->GetTopWindowRoot();
   if (NS_WARN_IF(!windowRoot)) {
     return;
   }
 
-  nsresult rv = windowRoot->RemoveEventListener(kDeactivateEvent, this,
-                                                /* use capture */ true);
-  Unused << NS_WARN_IF(NS_FAILED(rv));
-
-  rv = windowRoot->RemoveEventListener(kVisibilityChange, this,
-                                       /* use capture */ true);
-  Unused << NS_WARN_IF(NS_FAILED(rv));
+  windowRoot->RemoveEventListener(kDeactivateEvent, this,
+                                  /* use capture */ true);
+  windowRoot->RemoveEventListener(kVisibilityChange, this,
+                                  /* use capture */ true);
 }
 
 NS_IMETHODIMP
 WebAuthnManagerBase::HandleEvent(nsIDOMEvent* aEvent)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aEvent);
 
--- a/dom/xhr/XMLHttpRequestWorker.cpp
+++ b/dom/xhr/XMLHttpRequestWorker.cpp
@@ -942,35 +942,34 @@ Proxy::AddRemoveEventListeners(bool aUpl
 {
   AssertIsOnMainThread();
 
   NS_ASSERTION(!aUpload ||
                (mUploadEventListenersAttached && !aAdd) ||
                (!mUploadEventListenersAttached && aAdd),
                "Messed up logic for upload listeners!");
 
-  DOMEventTargetHelper* targetHelper =
+  RefPtr<DOMEventTargetHelper> targetHelper =
     aUpload ?
     static_cast<XMLHttpRequestUpload*>(mXHRUpload.get()) :
     static_cast<XMLHttpRequestEventTarget*>(mXHR.get());
   MOZ_ASSERT(targetHelper, "This should never fail!");
-  nsCOMPtr<nsIDOMEventTarget> target = targetHelper;
 
   uint32_t lastEventType = aUpload ? STRING_LAST_EVENTTARGET : STRING_LAST_XHR;
 
   nsAutoString eventType;
   for (uint32_t index = 0; index <= lastEventType; index++) {
     eventType = NS_ConvertASCIItoUTF16(sEventStrings[index]);
     if (aAdd) {
-      if (NS_FAILED(target->AddEventListener(eventType, this, false))) {
+      if (NS_FAILED(targetHelper->AddEventListener(eventType, this, false))) {
         return false;
       }
     }
-    else if (NS_FAILED(target->RemoveEventListener(eventType, this, false))) {
-      return false;
+    else {
+      targetHelper->RemoveEventListener(eventType, this, false);
     }
   }
 
   if (aUpload) {
     mUploadEventListenersAttached = aAdd;
   }
 
   return true;
@@ -1057,19 +1056,17 @@ Proxy::HandleEvent(nsIDOMEvent* aEvent)
 NS_IMPL_ISUPPORTS_INHERITED(LoadStartDetectionRunnable, Runnable,
                                                         nsIDOMEventListener)
 
 NS_IMETHODIMP
 LoadStartDetectionRunnable::Run()
 {
   AssertIsOnMainThread();
 
-  if (NS_FAILED(mXHR->RemoveEventListener(mEventType, this, false))) {
-    NS_WARNING("Failed to remove event listener!");
-  }
+  mXHR->RemoveEventListener(mEventType, this, false);
 
   if (!mReceivedLoadStart) {
     if (mProxy->mOutstandingSendCount > 1) {
       mProxy->mOutstandingSendCount--;
     } else if (mProxy->mOutstandingSendCount == 1) {
       mProxy->Reset();
 
       RefPtr<ProxyCompleteRunnable> runnable =
--- a/editor/libeditor/HTMLAbsPositionEditor.cpp
+++ b/editor/libeditor/HTMLAbsPositionEditor.cpp
@@ -12,29 +12,29 @@
 #include "TextEditUtils.h"
 #include "mozilla/EditAction.h"
 #include "mozilla/EditorUtils.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/TextEditRules.h"
 #include "mozilla/dom/CSSPrimitiveValueBinding.h"
 #include "mozilla/dom/Selection.h"
 #include "mozilla/dom/Element.h"
+#include "mozilla/dom/EventTarget.h"
 #include "mozilla/mozalloc.h"
 #include "nsAString.h"
 #include "nsAlgorithm.h"
 #include "nsCOMPtr.h"
 #include "nsComputedDOMStyle.h"
 #include "nsDebug.h"
 #include "nsError.h"
 #include "nsGkAtoms.h"
 #include "nsIContent.h"
 #include "nsROCSSPrimitiveValue.h"
 #include "nsIDOMElement.h"
 #include "nsIDOMEventListener.h"
-#include "nsIDOMEventTarget.h"
 #include "nsDOMCSSRGBColor.h"
 #include "nsIDOMWindow.h"
 #include "nsIHTMLObjectResizer.h"
 #include "nsINode.h"
 #include "nsIPresShell.h"
 #include "nsISupportsImpl.h"
 #include "nsISupportsUtils.h"
 #include "nsLiteralString.h"
@@ -378,24 +378,22 @@ HTMLEditor::EndMoving()
   if (mPositioningShadow) {
     nsCOMPtr<nsIPresShell> ps = GetPresShell();
     NS_ENSURE_TRUE(ps, NS_ERROR_NOT_INITIALIZED);
 
     DeleteRefToAnonymousNode(Move(mPositioningShadow), ps);
 
     mPositioningShadow = nullptr;
   }
-  nsCOMPtr<nsIDOMEventTarget> piTarget = GetDOMEventTarget();
+  RefPtr<EventTarget> piTarget = GetDOMEventTarget();
 
   if (piTarget && mMouseMotionListenerP) {
-    DebugOnly<nsresult> rv =
-      piTarget->RemoveEventListener(NS_LITERAL_STRING("mousemove"),
-                                    mMouseMotionListenerP,
-                                    false);
-    NS_ASSERTION(NS_SUCCEEDED(rv), "failed to remove mouse motion listener");
+    piTarget->RemoveEventListener(NS_LITERAL_STRING("mousemove"),
+				  mMouseMotionListenerP,
+				  false);
   }
   mMouseMotionListenerP = nullptr;
 
   mGrabberClicked = false;
   mIsMoving = false;
   RefPtr<Selection> selection = GetSelection();
   if (!selection) {
     return NS_ERROR_NOT_INITIALIZED;
--- a/editor/libeditor/HTMLAnonymousNodeEditor.cpp
+++ b/editor/libeditor/HTMLAnonymousNodeEditor.cpp
@@ -2,28 +2,28 @@
  * 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 "mozilla/HTMLEditor.h"
 
 #include "mozilla/Attributes.h"
 #include "mozilla/dom/CSSPrimitiveValueBinding.h"
 #include "mozilla/dom/Element.h"
+#include "mozilla/dom/EventTarget.h"
 #include "mozilla/mozalloc.h"
 #include "nsAString.h"
 #include "nsCOMPtr.h"
 #include "nsComputedDOMStyle.h"
 #include "nsDebug.h"
 #include "nsError.h"
 #include "nsGenericHTMLElement.h"
 #include "nsGkAtoms.h"
 #include "nsAtom.h"
 #include "nsIContent.h"
 #include "nsID.h"
-#include "nsIDOMEventTarget.h"
 #include "nsIDOMWindow.h"
 #include "nsIDocument.h"
 #include "nsIDocumentObserver.h"
 #include "nsIHTMLAbsPosEditor.h"
 #include "nsIHTMLInlineTableEditor.h"
 #include "nsIHTMLObjectResizer.h"
 #include "nsStubMutationObserver.h"
 #include "nsINode.h"
@@ -238,19 +238,18 @@ HTMLEditor::CreateAnonymousElement(nsAto
 // Removes event listener and calls DeleteRefToAnonymousNode.
 void
 HTMLEditor::RemoveListenerAndDeleteRef(const nsAString& aEvent,
                                        nsIDOMEventListener* aListener,
                                        bool aUseCapture,
                                        ManualNACPtr aElement,
                                        nsIPresShell* aShell)
 {
-  nsCOMPtr<nsIDOMEventTarget> evtTarget(do_QueryInterface(aElement));
-  if (evtTarget) {
-    evtTarget->RemoveEventListener(aEvent, aListener, aUseCapture);
+  if (aElement) {
+    aElement->RemoveEventListener(aEvent, aListener, aUseCapture);
   }
   DeleteRefToAnonymousNode(Move(aElement), aShell);
 }
 
 // Deletes all references to an anonymous element
 void
 HTMLEditor::DeleteRefToAnonymousNode(ManualNACPtr aContent,
                                      nsIPresShell* aShell)
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -22,17 +22,16 @@
 #include "HTMLEditUtils.h"
 #include "HTMLURIRefObject.h"
 #include "StyleSheetTransactions.h"
 #include "TextEditUtils.h"
 #include "TypeInState.h"
 
 #include "nsIDOMDocument.h"
 #include "nsIDocumentInlines.h"
-#include "nsIDOMEventTarget.h"
 #include "nsISelectionController.h"
 #include "nsILinkHandler.h"
 #include "nsIInlineSpellChecker.h"
 
 #include "mozilla/css/Loader.h"
 
 #include "nsIContent.h"
 #include "nsIContentIterator.h"
@@ -459,17 +458,17 @@ HTMLEditor::InstallEventListeners()
 
 void
 HTMLEditor::RemoveEventListeners()
 {
   if (!IsInitialized()) {
     return;
   }
 
-  nsCOMPtr<nsIDOMEventTarget> target = GetDOMEventTarget();
+  RefPtr<EventTarget> target = GetDOMEventTarget();
 
   if (target) {
     // Both mMouseMotionListenerP and mResizeEventListenerP can be
     // registerd with other targets than the DOM event receiver that
     // we can reach from here. But nonetheless, unregister the event
     // listeners with the DOM event reveiver (if it's registerd with
     // other targets, it'll get unregisterd once the target goes
     // away).
--- a/editor/libeditor/HTMLEditorObjectResizer.cpp
+++ b/editor/libeditor/HTMLEditorObjectResizer.cpp
@@ -9,29 +9,29 @@
 #include "HTMLEditUtils.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/EditorUtils.h"
 #include "mozilla/LookAndFeel.h"
 #include "mozilla/MathAlgorithms.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/mozalloc.h"
 #include "mozilla/dom/MouseEvent.h"
+#include "mozilla/dom/EventTarget.h"
 #include "nsAString.h"
 #include "nsAlgorithm.h"
 #include "nsCOMPtr.h"
 #include "nsDebug.h"
 #include "nsError.h"
 #include "nsGkAtoms.h"
 #include "nsAtom.h"
 #include "nsIContent.h"
 #include "nsID.h"
 #include "nsIDOMDocument.h"
 #include "nsIDOMElement.h"
 #include "nsIDOMEvent.h"
-#include "nsIDOMEventTarget.h"
 #include "nsIDocument.h"
 #include "nsIPresShell.h"
 #include "nsISupportsUtils.h"
 #include "nsPIDOMWindow.h"
 #include "nsReadableUtils.h"
 #include "nsString.h"
 #include "nsStringFwd.h"
 #include "nscore.h"
@@ -408,40 +408,37 @@ HTMLEditor::HideResizers()
   if (mActivatedHandle) {
     mActivatedHandle->UnsetAttr(kNameSpaceID_None, nsGkAtoms::_moz_activated,
                                 true);
     mActivatedHandle = nullptr;
   }
 
   // don't forget to remove the listeners !
 
-  nsCOMPtr<nsIDOMEventTarget> target = GetDOMEventTarget();
+  // nsCOMPtr so we can do_QueryInterface into it.
+  nsCOMPtr<EventTarget> target = GetDOMEventTarget();
 
   if (target && mMouseMotionListenerP) {
-    DebugOnly<nsresult> rv =
-      target->RemoveEventListener(NS_LITERAL_STRING("mousemove"),
-                                  mMouseMotionListenerP, true);
-    NS_ASSERTION(NS_SUCCEEDED(rv), "failed to remove mouse motion listener");
+    target->RemoveEventListener(NS_LITERAL_STRING("mousemove"),
+                                mMouseMotionListenerP, true);
   }
   mMouseMotionListenerP = nullptr;
 
   nsCOMPtr<nsIDocument> doc = GetDocument();
   if (!doc) {
     return NS_ERROR_NULL_POINTER;
   }
   target = do_QueryInterface(doc->GetWindow());
   if (!target) {
     return NS_ERROR_NULL_POINTER;
   }
 
   if (mResizeEventListenerP) {
-    DebugOnly<nsresult> rv =
-      target->RemoveEventListener(NS_LITERAL_STRING("resize"),
-                                  mResizeEventListenerP, false);
-    NS_ASSERTION(NS_SUCCEEDED(rv), "failed to remove resize event listener");
+    target->RemoveEventListener(NS_LITERAL_STRING("resize"),
+                                mResizeEventListenerP, false);
   }
   mResizeEventListenerP = nullptr;
 
   mResizedObject->UnsetAttr(kNameSpaceID_None, nsGkAtoms::_moz_resizing, true);
   mResizedObject = nullptr;
 
   return NS_OK;
 }
--- a/editor/libeditor/HTMLInlineTableEditor.cpp
+++ b/editor/libeditor/HTMLInlineTableEditor.cpp
@@ -183,20 +183,19 @@ HTMLEditor::AddMouseClickListener(Elemen
     evtTarget->AddEventListener(NS_LITERAL_STRING("click"),
                                 mEventListener, true);
   }
 }
 
 void
 HTMLEditor::RemoveMouseClickListener(Element* aElement)
 {
-  nsCOMPtr<nsIDOMEventTarget> evtTarget(do_QueryInterface(aElement));
-  if (evtTarget) {
-    evtTarget->RemoveEventListener(NS_LITERAL_STRING("click"),
-                                   mEventListener, true);
+  if (aElement) {
+    aElement->RemoveEventListener(NS_LITERAL_STRING("click"),
+                                  mEventListener, true);
   }
 }
 
 NS_IMETHODIMP
 HTMLEditor::RefreshInlineTableEditingUI()
 {
   if (!mInlineEditedCell) {
    return NS_OK;
--- a/layout/base/MobileViewportManager.cpp
+++ b/layout/base/MobileViewportManager.cpp
@@ -4,16 +4,17 @@
  * 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 "MobileViewportManager.h"
 
 #include "gfxPrefs.h"
 #include "LayersLogging.h"
 #include "mozilla/PresShell.h"
+#include "mozilla/dom/EventTarget.h"
 #include "nsIDOMEvent.h"
 #include "nsIFrame.h"
 #include "nsLayoutUtils.h"
 #include "nsViewManager.h"
 #include "nsViewportInfo.h"
 #include "UnitTransforms.h"
 #include "nsIDocument.h"
 
--- a/layout/base/MobileViewportManager.h
+++ b/layout/base/MobileViewportManager.h
@@ -8,21 +8,26 @@
 #define MobileViewportManager_h_
 
 #include "mozilla/Maybe.h"
 #include "nsCOMPtr.h"
 #include "nsIDOMEventListener.h"
 #include "nsIObserver.h"
 #include "Units.h"
 
-class nsIDOMEventTarget;
 class nsIDocument;
 class nsIPresShell;
 class nsViewportInfo;
 
+namespace mozilla {
+namespace dom {
+class EventTarget;
+} // namespace dom
+} // namespace mozilla
+
 class MobileViewportManager final : public nsIDOMEventListener
                                   , public nsIObserver
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIDOMEVENTLISTENER
   NS_DECL_NSIOBSERVER
 
@@ -86,17 +91,17 @@ private:
   void UpdateSPCSPS(const mozilla::ScreenIntSize& aDisplaySize,
                     const mozilla::CSSToScreenScale& aZoom);
 
   /* Updates the displayport margins for the presShell's root scrollable frame */
   void UpdateDisplayPortMargins();
 
   nsCOMPtr<nsIDocument> mDocument;
   nsIPresShell* MOZ_NON_OWNING_REF mPresShell; // raw ref since the presShell owns this
-  nsCOMPtr<nsIDOMEventTarget> mEventTarget;
+  nsCOMPtr<mozilla::dom::EventTarget> mEventTarget;
   bool mIsFirstPaint;
   bool mPainted;
   mozilla::LayoutDeviceIntSize mDisplaySize;
   mozilla::CSSSize mMobileViewportSize;
   mozilla::Maybe<float> mRestoreResolution;
   mozilla::Maybe<mozilla::ScreenIntSize> mRestoreDisplaySize;
 };
 
--- a/layout/base/ZoomConstraintsClient.h
+++ b/layout/base/ZoomConstraintsClient.h
@@ -8,20 +8,25 @@
 #define ZoomConstraintsClient_h_
 
 #include "FrameMetrics.h"
 #include "mozilla/Maybe.h"
 #include "nsIDOMEventListener.h"
 #include "nsIObserver.h"
 #include "nsWeakPtr.h"
 
-class nsIDOMEventTarget;
 class nsIDocument;
 class nsIPresShell;
 
+namespace mozilla {
+namespace dom {
+class EventTarget;
+} // namespace dom
+} // namespace mozilla
+
 class ZoomConstraintsClient final : public nsIDOMEventListener,
                                     public nsIObserver
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIDOMEVENTLISTENER
   NS_DECL_NSIOBSERVER
 
@@ -35,13 +40,13 @@ public:
   void Destroy();
   void ScreenSizeChanged();
 
 private:
   void RefreshZoomConstraints();
 
   nsCOMPtr<nsIDocument> mDocument;
   nsIPresShell* MOZ_NON_OWNING_REF mPresShell; // raw ref since the presShell owns this
-  nsCOMPtr<nsIDOMEventTarget> mEventTarget;
+  nsCOMPtr<mozilla::dom::EventTarget> mEventTarget;
   mozilla::Maybe<mozilla::layers::ScrollableLayerGuid> mGuid;
 };
 
 #endif
--- a/layout/generic/ScrollbarActivity.cpp
+++ b/layout/generic/ScrollbarActivity.cpp
@@ -186,18 +186,18 @@ ScrollbarActivity::HandleEventForScrollb
 }
 
 void
 ScrollbarActivity::StartListeningForScrollbarEvents()
 {
   if (mListeningForScrollbarEvents)
     return;
 
-  mHorizontalScrollbar = do_QueryInterface(GetHorizontalScrollbar());
-  mVerticalScrollbar = do_QueryInterface(GetVerticalScrollbar());
+  mHorizontalScrollbar = GetHorizontalScrollbar();
+  mVerticalScrollbar = GetVerticalScrollbar();
 
   AddScrollbarEventListeners(mHorizontalScrollbar);
   AddScrollbarEventListeners(mVerticalScrollbar);
 
   mListeningForScrollbarEvents = true;
 }
 
 void
@@ -232,36 +232,33 @@ ScrollbarActivity::StartListeningForScro
 
 void
 ScrollbarActivity::StopListeningForScrollAreaEvents()
 {
   if (!mListeningForScrollAreaEvents)
     return;
 
   nsIFrame* scrollArea = do_QueryFrame(mScrollableFrame);
-  nsCOMPtr<nsIDOMEventTarget> scrollAreaTarget = do_QueryInterface(scrollArea->GetContent());
-  if (scrollAreaTarget) {
-    scrollAreaTarget->RemoveEventListener(NS_LITERAL_STRING("mousemove"), this, true);
-  }
+  scrollArea->GetContent()->RemoveEventListener(NS_LITERAL_STRING("mousemove"), this, true);
   mListeningForScrollAreaEvents = false;
 }
 
 void
-ScrollbarActivity::AddScrollbarEventListeners(nsIDOMEventTarget* aScrollbar)
+ScrollbarActivity::AddScrollbarEventListeners(dom::EventTarget* aScrollbar)
 {
   if (aScrollbar) {
     aScrollbar->AddEventListener(NS_LITERAL_STRING("mousedown"), this, true);
     aScrollbar->AddEventListener(NS_LITERAL_STRING("mouseup"), this, true);
     aScrollbar->AddEventListener(NS_LITERAL_STRING("mouseover"), this, true);
     aScrollbar->AddEventListener(NS_LITERAL_STRING("mouseout"), this, true);
   }
 }
 
 void
-ScrollbarActivity::RemoveScrollbarEventListeners(nsIDOMEventTarget* aScrollbar)
+ScrollbarActivity::RemoveScrollbarEventListeners(dom::EventTarget* aScrollbar)
 {
   if (aScrollbar) {
     aScrollbar->RemoveEventListener(NS_LITERAL_STRING("mousedown"), this, true);
     aScrollbar->RemoveEventListener(NS_LITERAL_STRING("mouseup"), this, true);
     aScrollbar->RemoveEventListener(NS_LITERAL_STRING("mouseover"), this, true);
     aScrollbar->RemoveEventListener(NS_LITERAL_STRING("mouseout"), this, true);
   }
 }
--- a/layout/generic/ScrollbarActivity.h
+++ b/layout/generic/ScrollbarActivity.h
@@ -13,16 +13,21 @@
 #include "mozilla/TimeStamp.h"
 #include "nsRefreshDriver.h"
 
 class nsIContent;
 class nsIScrollbarMediator;
 class nsITimer;
 
 namespace mozilla {
+
+namespace dom {
+class EventTarget;
+} // namespace dom
+
 namespace layout {
 
 /**
  * ScrollbarActivity
  *
  * This class manages scrollbar behavior that imitates the native Mac OS X
  * Lion overlay scrollbar behavior: Scrollbars are only shown while "scrollbar
  * activity" occurs, and they're hidden with a fade animation after a short
@@ -113,18 +118,18 @@ protected:
 
   void StartFadeBeginTimer();
   void CancelFadeBeginTimer();
 
   void StartListeningForScrollbarEvents();
   void StartListeningForScrollAreaEvents();
   void StopListeningForScrollbarEvents();
   void StopListeningForScrollAreaEvents();
-  void AddScrollbarEventListeners(nsIDOMEventTarget* aScrollbar);
-  void RemoveScrollbarEventListeners(nsIDOMEventTarget* aScrollbar);
+  void AddScrollbarEventListeners(dom::EventTarget* aScrollbar);
+  void RemoveScrollbarEventListeners(dom::EventTarget* aScrollbar);
 
   void RegisterWithRefreshDriver();
   void UnregisterFromRefreshDriver();
 
   bool UpdateOpacity(TimeStamp aTime); // returns false if 'this' was destroyed
   void HoveredScrollbar(dom::Element* aScrollbar);
 
   nsRefreshDriver* GetRefreshDriver();
@@ -134,18 +139,18 @@ protected:
 
   const TimeDuration FadeDuration() {
     return TimeDuration::FromMilliseconds(mScrollbarFadeDuration);
   }
 
   nsIScrollbarMediator* mScrollableFrame;
   TimeStamp mFadeBeginTime;
   nsCOMPtr<nsITimer> mFadeBeginTimer;
-  nsCOMPtr<nsIDOMEventTarget> mHorizontalScrollbar; // null while inactive
-  nsCOMPtr<nsIDOMEventTarget> mVerticalScrollbar;   // null while inactive
+  nsCOMPtr<dom::EventTarget> mHorizontalScrollbar; // null while inactive
+  nsCOMPtr<dom::EventTarget> mVerticalScrollbar;   // null while inactive
   int mNestedActivityCounter;
   bool mIsActive;
   bool mIsFading;
   bool mListeningForScrollbarEvents;
   bool mListeningForScrollAreaEvents;
   bool mHScrollbarHovered;
   bool mVScrollbarHovered;