diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index a446862b70ef..f7c471126068 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -10201,6 +10201,12 @@ nsNavigator::SetDocShell(nsIDocShell *aDocShell) mGeolocation->Shutdown(); mGeolocation = nsnull; } + + if (mNotification) + { + mNotification->Shutdown(); + mNotification = nsnull; + } } //***************************************************************************** @@ -10588,6 +10594,13 @@ nsNavigator::LoadingNewDocument() mGeolocation->Shutdown(); mGeolocation = nsnull; } + + if (mNotification) + { + mNotification->Shutdown(); + mNotification = nsnull; + } + } nsresult @@ -10751,6 +10764,11 @@ NS_IMETHODIMP nsNavigator::GetMozNotification(nsIDOMDesktopNotificationCenter ** NS_ENSURE_ARG_POINTER(aRetVal); *aRetVal = nsnull; + if (mNotification) { + NS_ADDREF(*aRetVal = mNotification); + return NS_OK; + } + nsCOMPtr window(do_GetInterface(mDocShell)); NS_ENSURE_TRUE(window, NS_ERROR_FAILURE); @@ -10763,14 +10781,12 @@ NS_IMETHODIMP nsNavigator::GetMozNotification(nsIDOMDesktopNotificationCenter ** nsIScriptContext *scx = sgo->GetContext(); NS_ENSURE_TRUE(scx, NS_ERROR_FAILURE); - nsRefPtr notification = - new nsDesktopNotificationCenter(window->GetCurrentInnerWindow(), - scx); - - if (!notification) { + mNotification = new nsDesktopNotificationCenter(window->GetCurrentInnerWindow(), + scx); + if (!mNotification) { return NS_ERROR_FAILURE; } - *aRetVal = notification.forget().get(); + NS_ADDREF(*aRetVal = mNotification); return NS_OK; } diff --git a/dom/base/nsGlobalWindow.h b/dom/base/nsGlobalWindow.h index 7e818d0adb45..f993bac8d51c 100644 --- a/dom/base/nsGlobalWindow.h +++ b/dom/base/nsGlobalWindow.h @@ -147,6 +147,7 @@ class nsRunnable; class nsDOMOfflineResourceList; class nsGeolocation; +class nsDesktopNotificationCenter; #ifdef MOZ_DISABLE_DOMCRYPTO class nsIDOMCrypto; @@ -1043,6 +1044,7 @@ protected: nsRefPtr mMimeTypes; nsRefPtr mPlugins; nsRefPtr mGeolocation; + nsRefPtr mNotification; nsIDocShell* mDocShell; // weak reference }; diff --git a/dom/src/notification/nsDesktopNotification.h b/dom/src/notification/nsDesktopNotification.h index a8fd4810f24c..95a0beea979d 100644 --- a/dom/src/notification/nsDesktopNotification.h +++ b/dom/src/notification/nsDesktopNotification.h @@ -90,6 +90,11 @@ public: { } + void Shutdown() { + mOwner = nsnull; + mScriptContext = nsnull; + } + private: nsCOMPtr mOwner; nsCOMPtr mScriptContext; diff --git a/dom/tests/mochitest/notification/Makefile.in b/dom/tests/mochitest/notification/Makefile.in index f9ba21862fdd..631f8f6b5f54 100644 --- a/dom/tests/mochitest/notification/Makefile.in +++ b/dom/tests/mochitest/notification/Makefile.in @@ -47,6 +47,7 @@ include $(topsrcdir)/config/rules.mk _TEST_FILES = \ test_basic_notification.html \ test_basic_notification_click.html \ + test_leak_windowClose.html \ notification_common.js \ $(NULL) diff --git a/dom/tests/mochitest/notification/test_leak_windowClose.html b/dom/tests/mochitest/notification/test_leak_windowClose.html new file mode 100644 index 000000000000..81eda4ad1f46 --- /dev/null +++ b/dom/tests/mochitest/notification/test_leak_windowClose.html @@ -0,0 +1,28 @@ + + + + + Test for leak when window closes + + + + + + + +

I like to write tests

+ +