Bug 707870 - Disconnect mListenerManager in nsDOMEventTargetHelper instead of expecting inheriting classes to do it. r=smaug
authorMounir Lamouri <mounir.lamouri@gmail.com>
Thu, 08 Dec 2011 16:31:14 +0800
changeset 82241 647b56f040f1ead84500f9bbdef54551e6be5a42
parent 82240 8cccdec3532b3c4f95bdd317fc6f8b362702d5cb
child 82242 ccc5f03e6dd2c1f70fa8f643dc8af53bc8692253
push id21587
push userbmo@edmorley.co.uk
push dateThu, 08 Dec 2011 15:13:43 +0000
treeherdermozilla-central@98db2311a44c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs707870
milestone11.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 707870 - Disconnect mListenerManager in nsDOMEventTargetHelper instead of expecting inheriting classes to do it. r=smaug
content/base/src/FileIOObject.cpp
content/base/src/FileIOObject.h
content/base/src/nsEventSource.cpp
content/base/src/nsInProcessTabChildGlobal.cpp
content/base/src/nsWebSocket.cpp
content/base/src/nsXMLHttpRequest.cpp
content/base/src/nsXMLHttpRequest.h
content/events/src/nsDOMEventTargetHelper.cpp
content/events/src/nsDOMEventTargetHelper.h
dom/battery/BatteryManager.cpp
dom/battery/BatteryManager.h
dom/indexedDB/IDBDatabase.cpp
dom/indexedDB/IDBRequest.cpp
dom/indexedDB/IDBTransaction.cpp
dom/ipc/TabChild.cpp
dom/ipc/TabChild.h
--- a/content/base/src/FileIOObject.cpp
+++ b/content/base/src/FileIOObject.cpp
@@ -83,22 +83,16 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 FileIOObject::FileIOObject()
   : mProgressEventWasDelayed(false),
     mTimerIsActive(false),
     mReadyState(0),
     mTotal(0), mTransferred(0)
 {}
 
-FileIOObject::~FileIOObject()
-{
-  if (mListenerManager)
-    mListenerManager->Disconnect();
-}
-
 void
 FileIOObject::StartProgressEventTimer()
 {
   if (!mProgressNotifier) {
     mProgressNotifier = do_CreateInstance(NS_TIMER_CONTRACTID);
   }
   if (mProgressNotifier) {
     mProgressEventWasDelayed = false;
--- a/content/base/src/FileIOObject.h
+++ b/content/base/src/FileIOObject.h
@@ -58,17 +58,16 @@ extern const PRUint64 kUnknownSize;
 // A common base class for FileReader and FileSaver
 
 class FileIOObject : public nsDOMEventTargetWrapperCache,
                      public nsIStreamListener,
                      public nsITimerCallback
 {
 public:
   FileIOObject();
-  ~FileIOObject();
 
   NS_DECL_ISUPPORTS_INHERITED
 
   // Common methods
   NS_METHOD Abort();
   NS_METHOD GetReadyState(PRUint16* aReadyState);
   NS_METHOD GetError(nsIDOMFileError** aError);
 
--- a/content/base/src/nsEventSource.cpp
+++ b/content/base/src/nsEventSource.cpp
@@ -92,21 +92,16 @@ nsEventSource::nsEventSource() :
   mScriptLine(0),
   mInnerWindowID(0)
 {
 }
 
 nsEventSource::~nsEventSource()
 {
   Close();
-
-  if (mListenerManager) {
-    mListenerManager->Disconnect();
-    mListenerManager = nsnull;
-  }
 }
 
 //-----------------------------------------------------------------------------
 // nsEventSource::nsISupports
 //-----------------------------------------------------------------------------
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(nsEventSource)
 
--- a/content/base/src/nsInProcessTabChildGlobal.cpp
+++ b/content/base/src/nsInProcessTabChildGlobal.cpp
@@ -115,20 +115,16 @@ nsInProcessTabChildGlobal::nsInProcessTa
 : mDocShell(aShell), mInitialized(false), mLoadingScript(false),
   mDelayedDisconnect(false), mOwner(aOwner), mChromeMessageManager(aChrome)
 {
 }
 
 nsInProcessTabChildGlobal::~nsInProcessTabChildGlobal()
 {
   NS_ASSERTION(!mCx, "Couldn't release JSContext?!?");
-
-  if (mListenerManager) {
-    mListenerManager->Disconnect();
-  }
 }
 
 nsresult
 nsInProcessTabChildGlobal::Init()
 {
 #ifdef DEBUG
   nsresult rv =
 #endif
--- a/content/base/src/nsWebSocket.cpp
+++ b/content/base/src/nsWebSocket.cpp
@@ -395,20 +395,17 @@ nsWebSocket::nsWebSocket() : mKeepingAli
 {
   NS_ABORT_IF_FALSE(NS_IsMainThread(), "Not running on main thread");
   nsLayoutStatics::AddRef();
 }
 
 nsWebSocket::~nsWebSocket()
 {
   NS_ABORT_IF_FALSE(NS_IsMainThread(), "Not running on main thread");
-  if (mListenerManager) {
-    mListenerManager->Disconnect();
-    mListenerManager = nsnull;
-  }
+
   Disconnect();
   nsLayoutStatics::Release();
 }
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(nsWebSocket)
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsWebSocket,
                                                   nsDOMEventTargetWrapperCache)
--- a/content/base/src/nsXMLHttpRequest.cpp
+++ b/content/base/src/nsXMLHttpRequest.cpp
@@ -396,23 +396,16 @@ NS_IMETHODIMP
 nsXHREventTarget::SetOnloadend(nsIDOMEventListener* aOnLoadend)
 {
   return RemoveAddEventListener(NS_LITERAL_STRING(LOADEND_STR),
                                 mOnLoadendListener, aOnLoadend);
 }
 
 /////////////////////////////////////////////
 
-nsXMLHttpRequestUpload::~nsXMLHttpRequestUpload()
-{
-  if (mListenerManager) {
-    mListenerManager->Disconnect();
-  }
-}
-
 DOMCI_DATA(XMLHttpRequestUpload, nsXMLHttpRequestUpload)
 
 NS_INTERFACE_MAP_BEGIN(nsXMLHttpRequestUpload)
   NS_INTERFACE_MAP_ENTRY(nsIXMLHttpRequestUpload)
   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(XMLHttpRequestUpload)
 NS_INTERFACE_MAP_END_INHERITING(nsXHREventTarget)
 
 NS_IMPL_ADDREF_INHERITED(nsXMLHttpRequestUpload, nsXHREventTarget)
@@ -442,20 +435,16 @@ nsXMLHttpRequest::nsXMLHttpRequest()
     mResultJSON(JSVAL_VOID),
     mResultArrayBuffer(nsnull)
 {
   nsLayoutStatics::AddRef();
 }
 
 nsXMLHttpRequest::~nsXMLHttpRequest()
 {
-  if (mListenerManager) {
-    mListenerManager->Disconnect();
-  }
-
   if (mState & (XML_HTTP_REQUEST_STOPPED |
                 XML_HTTP_REQUEST_SENT |
                 XML_HTTP_REQUEST_LOADING)) {
     Abort();
   }
 
   NS_ABORT_IF_FALSE(!(mState & XML_HTTP_REQUEST_SYNCLOOPING), "we rather crash than hang");
   mState &= ~XML_HTTP_REQUEST_SYNCLOOPING;
--- a/content/base/src/nsXMLHttpRequest.h
+++ b/content/base/src/nsXMLHttpRequest.h
@@ -95,17 +95,16 @@ class nsXMLHttpRequestUpload : public ns
 {
 public:
   nsXMLHttpRequestUpload(nsPIDOMWindow* aOwner,
                          nsIScriptContext* aScriptContext)
   {
     mOwner = aOwner;
     mScriptContext = aScriptContext;
   }
-  virtual ~nsXMLHttpRequestUpload();
   NS_DECL_ISUPPORTS_INHERITED
   NS_FORWARD_NSIXMLHTTPREQUESTEVENTTARGET(nsXHREventTarget::)
   NS_FORWARD_NSIDOMEVENTTARGET(nsXHREventTarget::)
   NS_DECL_NSIXMLHTTPREQUESTUPLOAD
 
   bool HasListeners()
   {
     return mListenerManager && mListenerManager->HasListeners();
--- a/content/events/src/nsDOMEventTargetHelper.cpp
+++ b/content/events/src/nsDOMEventTargetHelper.cpp
@@ -85,16 +85,23 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(
   NS_INTERFACE_MAP_ENTRY(nsIDOMEventTarget)
 NS_INTERFACE_MAP_END
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMEventTargetHelper)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMEventTargetHelper)
 
 NS_IMPL_DOMTARGET_DEFAULTS(nsDOMEventTargetHelper);
 
+nsDOMEventTargetHelper::~nsDOMEventTargetHelper()
+{
+  if (mListenerManager) {
+    mListenerManager->Disconnect();
+  }
+}
+
 NS_IMETHODIMP
 nsDOMEventTargetHelper::RemoveEventListener(const nsAString& aType,
                                             nsIDOMEventListener* aListener,
                                             bool aUseCapture)
 {
   nsEventListenerManager* elm = GetListenerManager(false);
   if (elm) {
     elm->RemoveEventListener(aType, aListener, aUseCapture);
--- a/content/events/src/nsDOMEventTargetHelper.h
+++ b/content/events/src/nsDOMEventTargetHelper.h
@@ -64,17 +64,17 @@ public:
 protected:
   nsCOMPtr<nsIDOMEventListener> mListener;
 };
 
 class nsDOMEventTargetHelper : public nsIDOMEventTarget
 {
 public:
   nsDOMEventTargetHelper() {}
-  virtual ~nsDOMEventTargetHelper() {}
+  virtual ~nsDOMEventTargetHelper();
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_CLASS(nsDOMEventTargetHelper)
 
   NS_DECL_NSIDOMEVENTTARGET
 
   bool HasListenersFor(const nsAString& aType)
   {
     return mListenerManager && mListenerManager->HasListenersFor(aType);
--- a/dom/battery/BatteryManager.cpp
+++ b/dom/battery/BatteryManager.cpp
@@ -86,23 +86,16 @@ NS_IMPL_RELEASE_INHERITED(BatteryManager
 
 BatteryManager::BatteryManager()
   : mLevel(kDefaultLevel)
   , mCharging(kDefaultCharging)
   , mRemainingTime(kDefaultRemainingTime)
 {
 }
 
-BatteryManager::~BatteryManager()
-{
-  if (mListenerManager) {
-    mListenerManager->Disconnect();
-  }
-}
-
 void
 BatteryManager::Init(nsPIDOMWindow *aWindow, nsIScriptContext* aScriptContext)
 {
   // Those vars come from nsDOMEventTargetHelper.
   mOwner = aWindow;
   mScriptContext = aScriptContext;
 
   hal::RegisterBatteryObserver(this);
--- a/dom/battery/BatteryManager.h
+++ b/dom/battery/BatteryManager.h
@@ -61,17 +61,16 @@ class BatteryManager : public nsDOMEvent
                      , public BatteryObserver
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIDOMMOZBATTERYMANAGER
   NS_FORWARD_NSIDOMEVENTTARGET(nsDOMEventTargetWrapperCache::)
 
   BatteryManager();
-  virtual ~BatteryManager();
 
   void Init(nsPIDOMWindow *aWindow, nsIScriptContext* aScriptContext);
   void Shutdown();
 
   // For IObserver.
   void Notify(const hal::BatteryInformation& aBatteryInfo);
 
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(BatteryManager,
--- a/dom/indexedDB/IDBDatabase.cpp
+++ b/dom/indexedDB/IDBDatabase.cpp
@@ -198,20 +198,16 @@ IDBDatabase::~IDBDatabase()
   if (mRegistered) {
     CloseInternal(true);
 
     IndexedDatabaseManager* mgr = IndexedDatabaseManager::Get();
     if (mgr) {
       mgr->UnregisterDatabase(this);
     }
   }
-
-  if (mListenerManager) {
-    mListenerManager->Disconnect();
-  }
 }
 
 void
 IDBDatabase::Invalidate()
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 
   // Make sure we're closed too.
--- a/dom/indexedDB/IDBRequest.cpp
+++ b/dom/indexedDB/IDBRequest.cpp
@@ -72,20 +72,16 @@ IDBRequest::~IDBRequest()
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 
   if (mResultValRooted) {
     // Calling a virtual from the destructor is bad... But we know that we won't
     // call a subclass' implementation because mResultValRooted will be set to
     // false.
     UnrootResultVal();
   }
-
-  if (mListenerManager) {
-    mListenerManager->Disconnect();
-  }
 }
 
 // static
 already_AddRefed<IDBRequest>
 IDBRequest::Create(nsISupports* aSource,
                    nsIScriptContext* aScriptContext,
                    nsPIDOMWindow* aOwner,
                    IDBTransaction* aTransaction)
--- a/dom/indexedDB/IDBTransaction.cpp
+++ b/dom/indexedDB/IDBTransaction.cpp
@@ -176,20 +176,16 @@ IDBTransaction::IDBTransaction()
 IDBTransaction::~IDBTransaction()
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
   NS_ASSERTION(!mPendingRequests, "Should have no pending requests here!");
   NS_ASSERTION(!mSavepointCount, "Should have released them all!");
   NS_ASSERTION(!mConnection, "Should have called CommitOrRollback!");
   NS_ASSERTION(!mCreating, "Should have been cleared already!");
   NS_ASSERTION(mFiredCompleteOrAbort, "Should have fired event!");
-
-  if (mListenerManager) {
-    mListenerManager->Disconnect();
-  }
 }
 
 void
 IDBTransaction::OnNewRequest()
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
   if (!mPendingRequests) {
     NS_ASSERTION(mReadyState == nsIIDBTransaction::INITIAL,
--- a/dom/ipc/TabChild.cpp
+++ b/dom/ipc/TabChild.cpp
@@ -994,23 +994,16 @@ TabChildGlobal::TabChildGlobal(TabChild*
                                               SendSyncMessageToParent,
                                               SendAsyncMessageToParent,
                                               nsnull,
                                               mTabChild,
                                               nsnull,
                                               aTabChild->GetJSContext());
 }
 
-TabChildGlobal::~TabChildGlobal()
-{
-  if (mListenerManager) {
-    mListenerManager->Disconnect();
-  }
-}
-
 NS_IMPL_CYCLE_COLLECTION_CLASS(TabChildGlobal)
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(TabChildGlobal,
                                                 nsDOMEventTargetWrapperCache)
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mMessageManager)
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(TabChildGlobal,
--- a/dom/ipc/TabChild.h
+++ b/dom/ipc/TabChild.h
@@ -89,17 +89,16 @@ class PContentDialogChild;
 
 class TabChildGlobal : public nsDOMEventTargetWrapperCache,
                        public nsIContentFrameMessageManager,
                        public nsIScriptObjectPrincipal,
                        public nsIScriptContextPrincipal
 {
 public:
   TabChildGlobal(TabChild* aTabChild);
-  ~TabChildGlobal();
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TabChildGlobal, nsDOMEventTargetWrapperCache)
   NS_FORWARD_SAFE_NSIFRAMEMESSAGEMANAGER(mMessageManager)
   NS_IMETHOD SendSyncMessage(const nsAString& aMessageName,
                              const jsval& aObject,
                              JSContext* aCx,
                              PRUint8 aArgc,
                              jsval* aRetval)