From d2dad60d4cffa12c8821549c1ba869ec3620167b Mon Sep 17 00:00:00 2001 From: Ben Kelly Date: Mon, 4 Jul 2016 06:50:25 -0700 Subject: [PATCH] Bug 1283674 P1 Make ServiceWorkerContainer::GetController() work gracefully when its window is disconnected. r=baku --- dom/workers/ServiceWorkerContainer.cpp | 5 ++--- dom/workers/ServiceWorkerManager.cpp | 5 ++++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/dom/workers/ServiceWorkerContainer.cpp b/dom/workers/ServiceWorkerContainer.cpp index 2e7ae3f80ad8..2c7c9e553535 100644 --- a/dom/workers/ServiceWorkerContainer.cpp +++ b/dom/workers/ServiceWorkerContainer.cpp @@ -222,7 +222,6 @@ already_AddRefed ServiceWorkerContainer::GetController() { if (!mControllerWorker) { - nsresult rv; nsCOMPtr swm = mozilla::services::GetServiceWorkerManager(); if (!swm) { return nullptr; @@ -232,8 +231,8 @@ ServiceWorkerContainer::GetController() // In theory the DOM ServiceWorker object can exist without the worker // thread running, but it seems our design does not expect that. nsCOMPtr serviceWorker; - rv = swm->GetDocumentController(GetOwner(), - getter_AddRefs(serviceWorker)); + nsresult rv = swm->GetDocumentController(GetOwner(), + getter_AddRefs(serviceWorker)); if (NS_WARN_IF(NS_FAILED(rv))) { return nullptr; } diff --git a/dom/workers/ServiceWorkerManager.cpp b/dom/workers/ServiceWorkerManager.cpp index ded1ed374475..e193eb94eb31 100644 --- a/dom/workers/ServiceWorkerManager.cpp +++ b/dom/workers/ServiceWorkerManager.cpp @@ -2328,7 +2328,10 @@ NS_IMETHODIMP ServiceWorkerManager::GetDocumentController(nsPIDOMWindowInner* aWindow, nsISupports** aServiceWorker) { - MOZ_ASSERT(aWindow); + if (NS_WARN_IF(!aWindow)) { + return NS_ERROR_DOM_INVALID_STATE_ERR; + } + nsCOMPtr doc = aWindow->GetExtantDoc(); if (!doc) { return NS_ERROR_DOM_INVALID_STATE_ERR;