mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-14 10:43:24 +00:00
Bug 605309 - DesktopNotificationCenter gets itself in leak cycles. r=jst a=blocking-betaN
This commit is contained in:
parent
62b832f1c5
commit
50c51b53cc
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
};
|
||||
|
||||
|
@ -90,6 +90,11 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
void Shutdown() {
|
||||
mOwner = nsnull;
|
||||
mScriptContext = nsnull;
|
||||
}
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsPIDOMWindow> mOwner;
|
||||
nsCOMPtr<nsIScriptContext> mScriptContext;
|
||||
|
@ -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)
|
||||
|
||||
|
28
dom/tests/mochitest/notification/test_leak_windowClose.html
Normal file
28
dom/tests/mochitest/notification/test_leak_windowClose.html
Normal 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>
|
Loading…
Reference in New Issue
Block a user