From 100aa0a44845a6d62eff0874b8d229478bc8f33e Mon Sep 17 00:00:00 2001 From: Olli Pettay Date: Thu, 26 Jan 2012 15:45:12 +0100 Subject: [PATCH] Bug 720536 - unmark ELM listeners, r=mccr8 --HG-- extra : rebase_source : 9c4bdf80b23e4c95c114de83977f813f6c977516 --- content/events/src/nsDOMEventTargetHelper.h | 7 ++++++ content/events/src/nsEventListenerManager.cpp | 23 +++++++++++++++++++ content/events/src/nsEventListenerManager.h | 4 ++++ 3 files changed, 34 insertions(+) diff --git a/content/events/src/nsDOMEventTargetHelper.h b/content/events/src/nsDOMEventTargetHelper.h index f789e0569257..12b0fcf958ac 100644 --- a/content/events/src/nsDOMEventTargetHelper.h +++ b/content/events/src/nsDOMEventTargetHelper.h @@ -104,4 +104,11 @@ protected: nsCOMPtr mOwner; // Inner window. }; +#define NS_UNMARK_LISTENER_WRAPPER(_event) \ + if (tmp->mOn##_event##Listener) { \ + nsCOMPtr wjs = \ + do_QueryInterface(tmp->mOn##_event##Listener->GetInner()); \ + xpc_UnmarkGrayObject(wjs); \ + } + #endif // nsDOMEventTargetHelper_h_ diff --git a/content/events/src/nsEventListenerManager.cpp b/content/events/src/nsEventListenerManager.cpp index 20ce29aae8ce..609db3ee8c30 100644 --- a/content/events/src/nsEventListenerManager.cpp +++ b/content/events/src/nsEventListenerManager.cpp @@ -82,6 +82,7 @@ #include "nsDOMEvent.h" #include "nsIContentSecurityPolicy.h" #include "nsJSEnvironment.h" +#include "xpcpublic.h" #include "sampler.h" using namespace mozilla::dom; @@ -240,9 +241,14 @@ nsEventListenerManager::AddEventListener(nsIDOMEventListener *aListener, ls->mListener = aListener; ls->mEventType = aType; ls->mTypeAtom = aTypeAtom; + ls->mWrappedJS = false; ls->mFlags = aFlags; ls->mHandlerIsString = false; + nsCOMPtr wjs = do_QueryInterface(aListener); + if (wjs) { + ls->mWrappedJS = true; + } if (aFlags & NS_EVENT_FLAG_SYSTEM_EVENT) { mMayHaveSystemGroupListeners = true; } @@ -1013,3 +1019,20 @@ nsEventListenerManager::SizeOf() const } return size; } + +void +nsEventListenerManager::UnmarkGrayJSListeners() +{ + PRUint32 count = mListeners.Length(); + for (PRUint32 i = 0; i < count; ++i) { + const nsListenerStruct& ls = mListeners.ElementAt(i); + nsIJSEventListener* jsl = ls.GetJSListener(); + if (jsl) { + xpc_UnmarkGrayObject(jsl->GetHandler()); + xpc_UnmarkGrayObject(jsl->GetEventScope()); + } else if (ls.mWrappedJS) { + nsCOMPtr wjs = do_QueryInterface(ls.mListener); + xpc_UnmarkGrayObject(wjs); + } + } +} diff --git a/content/events/src/nsEventListenerManager.h b/content/events/src/nsEventListenerManager.h index f54c1bfffd40..f070f0a48197 100644 --- a/content/events/src/nsEventListenerManager.h +++ b/content/events/src/nsEventListenerManager.h @@ -70,6 +70,7 @@ struct nsListenerStruct nsCOMPtr mTypeAtom; PRUint16 mFlags; bool mHandlerIsString; + bool mWrappedJS; nsIJSEventListener* GetJSListener() const { return (mFlags & NS_PRIV_EVENT_FLAG_SCRIPT) ? @@ -243,6 +244,9 @@ public: bool MayHaveMouseEnterLeaveEventListener() { return mMayHaveMouseEnterLeaveEventListener; } PRInt64 SizeOf() const; + + void UnmarkGrayJSListeners(); + protected: nsresult HandleEventSubType(nsListenerStruct* aListenerStruct, nsIDOMEventListener* aListener,