Bug 1058043 - Patch 2 - StopListeningForEvents in ServiceWorkerRegistration destructor. r=baku

--HG--
extra : rebase_source : 224f28dcb1b9604916cbdd53bf4690ef32d71be9
This commit is contained in:
Nikhil Marathe 2014-08-27 13:33:20 -07:00
parent e4ade03675
commit 4cf96ddcba
3 changed files with 11 additions and 0 deletions

View File

@ -1851,6 +1851,7 @@ NS_IMETHODIMP
ServiceWorkerManager::AddRegistrationEventListener(nsIURI* aDocumentURI, nsIDOMEventTarget* aListener)
{
MOZ_ASSERT(aDocumentURI);
AssertIsOnMainThread();
nsRefPtr<ServiceWorkerDomainInfo> domainInfo = GetDomainInfo(aDocumentURI);
if (!domainInfo) {
nsCString domain;
@ -1875,6 +1876,7 @@ ServiceWorkerManager::AddRegistrationEventListener(nsIURI* aDocumentURI, nsIDOME
NS_IMETHODIMP
ServiceWorkerManager::RemoveRegistrationEventListener(nsIURI* aDocumentURI, nsIDOMEventTarget* aListener)
{
AssertIsOnMainThread();
MOZ_ASSERT(aDocumentURI);
nsRefPtr<ServiceWorkerDomainInfo> domainInfo = GetDomainInfo(aDocumentURI);
if (!domainInfo) {

View File

@ -38,6 +38,7 @@ ServiceWorkerRegistration::ServiceWorkerRegistration(nsPIDOMWindow* aWindow,
const nsAString& aScope)
: DOMEventTargetHelper(aWindow)
, mScope(aScope)
, mListeningForEvents(false)
{
MOZ_ASSERT(aWindow);
MOZ_ASSERT(aWindow->IsInnerWindow());
@ -47,6 +48,7 @@ ServiceWorkerRegistration::ServiceWorkerRegistration(nsPIDOMWindow* aWindow,
ServiceWorkerRegistration::~ServiceWorkerRegistration()
{
StopListeningForEvents();
}
void
@ -176,15 +178,21 @@ ServiceWorkerRegistration::StartListeningForEvents()
nsCOMPtr<nsIServiceWorkerManager> swm = do_GetService(SERVICEWORKERMANAGER_CONTRACTID);
if (swm) {
swm->AddRegistrationEventListener(GetDocumentURI(), this);
mListeningForEvents = true;
}
}
void
ServiceWorkerRegistration::StopListeningForEvents()
{
if (!mListeningForEvents) {
return;
}
nsCOMPtr<nsIServiceWorkerManager> swm = do_GetService(SERVICEWORKERMANAGER_CONTRACTID);
if (swm) {
swm->RemoveRegistrationEventListener(GetDocumentURI(), this);
mListeningForEvents = false;
}
}

View File

@ -86,6 +86,7 @@ private:
nsRefPtr<workers::ServiceWorker> mActiveWorker;
const nsString mScope;
bool mListeningForEvents;
};
} // namespace dom