diff --git a/dom/serviceworkers/ServiceWorkerRegistrationImpl.cpp b/dom/serviceworkers/ServiceWorkerRegistrationImpl.cpp index 78ec762daf21..f03517d33ba5 100644 --- a/dom/serviceworkers/ServiceWorkerRegistrationImpl.cpp +++ b/dom/serviceworkers/ServiceWorkerRegistrationImpl.cpp @@ -26,6 +26,7 @@ #include "ServiceWorkerManager.h" #include "ServiceWorkerPrivate.h" #include "ServiceWorkerRegistration.h" +#include "ServiceWorkerUnregisterCallback.h" #include "nsIDocument.h" #include "nsIServiceWorkerManager.h" @@ -394,44 +395,6 @@ private: NS_IMPL_ISUPPORTS(SWRUpdateRunnable::TimerCallback, nsITimerCallback) -class UnregisterCallback final : public nsIServiceWorkerUnregisterCallback -{ - RefPtr mPromise; - -public: - NS_DECL_ISUPPORTS - - UnregisterCallback() - : mPromise(new GenericPromise::Private(__func__)) - { - } - - NS_IMETHOD - UnregisterSucceeded(bool aState) override - { - mPromise->Resolve(aState, __func__); - return NS_OK; - } - - NS_IMETHOD - UnregisterFailed() override - { - mPromise->Reject(NS_ERROR_DOM_SECURITY_ERR, __func__); - return NS_OK; - } - - RefPtr - Promise() const - { - return mPromise; - } - -private: - ~UnregisterCallback() = default; -}; - -NS_IMPL_ISUPPORTS(UnregisterCallback, nsIServiceWorkerUnregisterCallback) - class WorkerUnregisterCallback final : public nsIServiceWorkerUnregisterCallback { RefPtr mWorkerRef; diff --git a/dom/serviceworkers/ServiceWorkerRegistrationProxy.cpp b/dom/serviceworkers/ServiceWorkerRegistrationProxy.cpp index 50437db81c30..bdd8c4d21df7 100644 --- a/dom/serviceworkers/ServiceWorkerRegistrationProxy.cpp +++ b/dom/serviceworkers/ServiceWorkerRegistrationProxy.cpp @@ -9,6 +9,7 @@ #include "mozilla/ipc/BackgroundParent.h" #include "ServiceWorkerManager.h" #include "ServiceWorkerRegistrationParent.h" +#include "ServiceWorkerUnregisterCallback.h" namespace mozilla { namespace dom { @@ -170,42 +171,6 @@ ServiceWorkerRegistrationProxy::RevokeActor(ServiceWorkerRegistrationParent* aAc MOZ_ALWAYS_SUCCEEDS(SystemGroup::Dispatch(TaskCategory::Other, r.forget())); } -namespace { - -class UnregisterCallback final : public nsIServiceWorkerUnregisterCallback -{ - RefPtr mPromise; - - ~UnregisterCallback() = default; - -public: - explicit UnregisterCallback(GenericPromise::Private* aPromise) - : mPromise(aPromise) - { - MOZ_DIAGNOSTIC_ASSERT(mPromise); - } - - NS_IMETHOD - UnregisterSucceeded(bool aState) override - { - mPromise->Resolve(aState, __func__); - return NS_OK; - } - - NS_IMETHOD - UnregisterFailed() override - { - mPromise->Reject(NS_ERROR_DOM_SECURITY_ERR, __func__); - return NS_OK; - } - - NS_DECL_ISUPPORTS -}; - -NS_IMPL_ISUPPORTS(UnregisterCallback, nsIServiceWorkerUnregisterCallback) - -} // anonymous namespace - RefPtr ServiceWorkerRegistrationProxy::Unregister() { diff --git a/dom/serviceworkers/ServiceWorkerUnregisterCallback.cpp b/dom/serviceworkers/ServiceWorkerUnregisterCallback.cpp new file mode 100644 index 000000000000..ddc334dd51a0 --- /dev/null +++ b/dom/serviceworkers/ServiceWorkerUnregisterCallback.cpp @@ -0,0 +1,44 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "ServiceWorkerUnregisterCallback.h" + +namespace mozilla { +namespace dom { + +NS_IMPL_ISUPPORTS(UnregisterCallback, nsIServiceWorkerUnregisterCallback) + +UnregisterCallback::UnregisterCallback() + : mPromise(new GenericPromise::Private(__func__)) {} + +UnregisterCallback::UnregisterCallback(GenericPromise::Private* aPromise) + : mPromise(aPromise) +{ + MOZ_DIAGNOSTIC_ASSERT(mPromise); +} + +NS_IMETHODIMP +UnregisterCallback::UnregisterSucceeded(bool aState) +{ + mPromise->Resolve(aState, __func__); + return NS_OK; +} + +NS_IMETHODIMP +UnregisterCallback::UnregisterFailed() +{ + mPromise->Reject(NS_ERROR_DOM_SECURITY_ERR, __func__); + return NS_OK; +} + +RefPtr +UnregisterCallback::Promise() const +{ + return mPromise; +} + +} // namespace dom +} // namespace mozilla diff --git a/dom/serviceworkers/ServiceWorkerUnregisterCallback.h b/dom/serviceworkers/ServiceWorkerUnregisterCallback.h new file mode 100644 index 000000000000..1a7dacc79085 --- /dev/null +++ b/dom/serviceworkers/ServiceWorkerUnregisterCallback.h @@ -0,0 +1,45 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_dom_ServiceWorkerUnregisterCallback_h +#define mozilla_dom_ServiceWorkerUnregisterCallback_h + +#include "mozilla/MozPromise.h" +#include "mozilla/RefPtr.h" +#include "nsIServiceWorkerManager.h" + +namespace mozilla { +namespace dom { + +class UnregisterCallback final : public nsIServiceWorkerUnregisterCallback +{ + public: + NS_DECL_ISUPPORTS + + UnregisterCallback(); + + explicit UnregisterCallback(GenericPromise::Private* aPromise); + + // nsIServiceWorkerUnregisterCallback implementation + NS_IMETHOD + UnregisterSucceeded(bool aState) override; + + NS_IMETHOD + UnregisterFailed() override; + + RefPtr + Promise() const; + + private: + ~UnregisterCallback() = default; + + RefPtr mPromise; +}; + +} // namespace dom +} // namespace mozilla + +#endif // mozilla_dom_ServiceWorkerUnregisterCallback_h diff --git a/dom/serviceworkers/moz.build b/dom/serviceworkers/moz.build index f62a80866e33..8a0780f65e99 100644 --- a/dom/serviceworkers/moz.build +++ b/dom/serviceworkers/moz.build @@ -64,6 +64,7 @@ UNIFIED_SOURCES += [ 'ServiceWorkerRegistrationParent.cpp', 'ServiceWorkerRegistrationProxy.cpp', 'ServiceWorkerScriptCache.cpp', + 'ServiceWorkerUnregisterCallback.cpp', 'ServiceWorkerUnregisterJob.cpp', 'ServiceWorkerUpdateJob.cpp', 'ServiceWorkerUpdaterChild.cpp',