Bug 605309 - DesktopNotificationCenter gets itself in leak cycles. r=jst a=blocking-betaN

This commit is contained in:
Doug Turner 2010-10-18 18:54:00 -07:00
parent 62b832f1c5
commit 50c51b53cc
5 changed files with 58 additions and 6 deletions

View File

@ -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<nsPIDOMWindow> 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<nsDesktopNotificationCenter> 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;
}

View File

@ -147,6 +147,7 @@ class nsRunnable;
class nsDOMOfflineResourceList;
class nsGeolocation;
class nsDesktopNotificationCenter;
#ifdef MOZ_DISABLE_DOMCRYPTO
class nsIDOMCrypto;
@ -1043,6 +1044,7 @@ protected:
nsRefPtr<nsMimeTypeArray> mMimeTypes;
nsRefPtr<nsPluginArray> mPlugins;
nsRefPtr<nsGeolocation> mGeolocation;
nsRefPtr<nsDesktopNotificationCenter> mNotification;
nsIDocShell* mDocShell; // weak reference
};

View File

@ -90,6 +90,11 @@ public:
{
}
void Shutdown() {
mOwner = nsnull;
mScriptContext = nsnull;
}
private:
nsCOMPtr<nsPIDOMWindow> mOwner;
nsCOMPtr<nsIScriptContext> mScriptContext;

View File

@ -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)

View File

@ -0,0 +1,28 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=605309
-->
<head>
<title>Test for leak when window closes</title>
<script type="text/javascript" src="/MochiKit/packed.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<script>
function boom()
{
document.documentElement.focus();
var x = navigator.mozNotification;
document.documentElement.addEventListener('', function(){x}, false);
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
window.addEventListener("load", boom, false);
</script>
</head>
<body>
<p> I like to write tests </p>
</body>
</html>