2014-08-19 17:56:00 +04:00
|
|
|
/* -*- 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_ServiceWorkerRegistration_h
|
|
|
|
#define mozilla_dom_ServiceWorkerRegistration_h
|
|
|
|
|
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2018-01-08 16:05:05 +03:00
|
|
|
#include "mozilla/dom/DOMPrefs.h"
|
2015-01-26 21:31:38 +03:00
|
|
|
#include "mozilla/dom/ServiceWorkerBinding.h"
|
2017-08-16 09:21:29 +03:00
|
|
|
#include "mozilla/dom/ServiceWorkerRegistrationBinding.h"
|
2018-02-14 22:23:16 +03:00
|
|
|
#include "mozilla/dom/ServiceWorkerRegistrationDescriptor.h"
|
2018-04-26 23:52:28 +03:00
|
|
|
#include "mozilla/dom/ServiceWorkerUtils.h"
|
2014-08-19 17:56:00 +04:00
|
|
|
|
2015-06-26 04:50:24 +03:00
|
|
|
// Support for Notification API extension.
|
|
|
|
#include "mozilla/dom/NotificationBinding.h"
|
|
|
|
|
2018-02-14 22:23:17 +03:00
|
|
|
class nsIGlobalObject;
|
2014-08-19 17:56:00 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class Promise;
|
2015-04-11 06:19:28 +03:00
|
|
|
class PushManager;
|
2018-02-14 22:23:15 +03:00
|
|
|
class WorkerPrivate;
|
2018-02-14 22:23:17 +03:00
|
|
|
class ServiceWorker;
|
2015-04-08 23:13:32 +03:00
|
|
|
|
2018-03-03 00:02:49 +03:00
|
|
|
#define NS_DOM_SERVICEWORKERREGISTRATION_IID \
|
|
|
|
{0x4578a90e, 0xa427, 0x4237, {0x98, 0x4a, 0xbd, 0x98, 0xe4, 0xcd, 0x5f, 0x3a}}
|
|
|
|
|
2018-02-14 22:23:17 +03:00
|
|
|
class ServiceWorkerRegistration final : public DOMEventTargetHelper
|
2014-08-19 17:56:00 +04:00
|
|
|
{
|
|
|
|
public:
|
2018-02-14 22:23:17 +03:00
|
|
|
class Inner
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
SetServiceWorkerRegistration(ServiceWorkerRegistration* aReg) = 0;
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
ClearServiceWorkerRegistration(ServiceWorkerRegistration* aReg) = 0;
|
|
|
|
|
2018-06-15 22:21:33 +03:00
|
|
|
virtual void
|
|
|
|
Update(ServiceWorkerRegistrationCallback&& aSuccessCB,
|
|
|
|
ServiceWorkerFailureCallback&& aFailureCB) = 0;
|
2018-02-14 22:23:17 +03:00
|
|
|
|
2018-06-15 22:21:33 +03:00
|
|
|
virtual void
|
|
|
|
Unregister(ServiceWorkerBoolCallback&& aSuccessCB,
|
|
|
|
ServiceWorkerFailureCallback&& aFailureCB) = 0;
|
2018-02-14 22:23:17 +03:00
|
|
|
};
|
|
|
|
|
2018-03-03 00:02:49 +03:00
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(NS_DOM_SERVICEWORKERREGISTRATION_IID)
|
2014-08-19 17:56:00 +04:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2018-02-14 22:23:17 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ServiceWorkerRegistration, DOMEventTargetHelper)
|
2014-08-19 17:56:00 +04:00
|
|
|
|
|
|
|
IMPL_EVENT_HANDLER(updatefound)
|
|
|
|
|
2016-06-12 17:26:51 +03:00
|
|
|
static already_AddRefed<ServiceWorkerRegistration>
|
|
|
|
CreateForMainThread(nsPIDOMWindowInner* aWindow,
|
2018-02-14 22:23:15 +03:00
|
|
|
const ServiceWorkerRegistrationDescriptor& aDescriptor);
|
2016-06-12 17:26:51 +03:00
|
|
|
|
|
|
|
static already_AddRefed<ServiceWorkerRegistration>
|
2018-01-31 10:24:08 +03:00
|
|
|
CreateForWorker(WorkerPrivate* aWorkerPrivate,
|
2018-03-03 00:02:50 +03:00
|
|
|
nsIGlobalObject* aGlobal,
|
2018-02-14 22:23:15 +03:00
|
|
|
const ServiceWorkerRegistrationDescriptor& aDescriptor);
|
2014-08-19 17:56:00 +04:00
|
|
|
|
|
|
|
JSObject*
|
2016-06-12 17:26:51 +03:00
|
|
|
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2014-08-19 17:56:00 +04:00
|
|
|
|
2018-02-14 22:23:17 +03:00
|
|
|
void DisconnectFromOwner() override;
|
|
|
|
|
2018-04-10 21:00:56 +03:00
|
|
|
void
|
|
|
|
RegistrationRemoved();
|
|
|
|
|
2018-02-14 22:23:16 +03:00
|
|
|
already_AddRefed<ServiceWorker>
|
|
|
|
GetInstalling() const;
|
2014-08-19 17:56:00 +04:00
|
|
|
|
2018-02-14 22:23:16 +03:00
|
|
|
already_AddRefed<ServiceWorker>
|
|
|
|
GetWaiting() const;
|
2014-08-19 17:56:00 +04:00
|
|
|
|
2018-02-14 22:23:16 +03:00
|
|
|
already_AddRefed<ServiceWorker>
|
|
|
|
GetActive() const;
|
|
|
|
|
|
|
|
void
|
|
|
|
UpdateState(const ServiceWorkerRegistrationDescriptor& aDescriptor);
|
|
|
|
|
|
|
|
bool
|
|
|
|
MatchesDescriptor(const ServiceWorkerRegistrationDescriptor& aDescriptor) const;
|
2014-08-19 17:56:00 +04:00
|
|
|
|
2018-02-14 22:23:16 +03:00
|
|
|
void
|
|
|
|
GetScope(nsAString& aScope) const;
|
2015-04-04 01:18:55 +03:00
|
|
|
|
2018-02-14 22:23:16 +03:00
|
|
|
ServiceWorkerUpdateViaCache
|
|
|
|
GetUpdateViaCache(ErrorResult& aRv) const;
|
2017-08-16 09:21:29 +03:00
|
|
|
|
2018-02-14 22:23:17 +03:00
|
|
|
already_AddRefed<Promise>
|
|
|
|
Update(ErrorResult& aRv);
|
2015-03-20 04:09:10 +03:00
|
|
|
|
2018-02-14 22:23:17 +03:00
|
|
|
already_AddRefed<Promise>
|
|
|
|
Unregister(ErrorResult& aRv);
|
2014-08-19 17:56:00 +04:00
|
|
|
|
2018-02-14 22:23:17 +03:00
|
|
|
already_AddRefed<PushManager>
|
|
|
|
GetPushManager(JSContext* aCx, ErrorResult& aRv);
|
2014-08-19 17:56:00 +04:00
|
|
|
|
2018-02-14 22:23:17 +03:00
|
|
|
already_AddRefed<Promise>
|
2015-06-26 04:50:24 +03:00
|
|
|
ShowNotification(JSContext* aCx,
|
|
|
|
const nsAString& aTitle,
|
2015-06-26 04:50:24 +03:00
|
|
|
const NotificationOptions& aOptions,
|
2018-02-14 22:23:17 +03:00
|
|
|
ErrorResult& aRv);
|
2014-08-19 17:56:00 +04:00
|
|
|
|
2018-02-14 22:23:17 +03:00
|
|
|
already_AddRefed<Promise>
|
2016-06-12 17:26:51 +03:00
|
|
|
GetNotifications(const GetNotificationOptions& aOptions,
|
2018-02-14 22:23:17 +03:00
|
|
|
ErrorResult& aRv);
|
2015-04-07 23:09:07 +03:00
|
|
|
|
2018-07-02 17:44:18 +03:00
|
|
|
const ServiceWorkerRegistrationDescriptor&
|
|
|
|
Descriptor() const;
|
|
|
|
|
2018-07-05 20:13:48 +03:00
|
|
|
void
|
|
|
|
WhenVersionReached(uint64_t aVersion, ServiceWorkerBoolCallback&& aCallback);
|
|
|
|
|
2018-02-14 22:23:17 +03:00
|
|
|
private:
|
|
|
|
ServiceWorkerRegistration(nsIGlobalObject* aGlobal,
|
|
|
|
const ServiceWorkerRegistrationDescriptor& aDescriptor,
|
|
|
|
Inner* aInner);
|
2015-04-07 23:09:07 +03:00
|
|
|
|
2018-02-14 22:23:17 +03:00
|
|
|
~ServiceWorkerRegistration();
|
2014-08-19 17:56:00 +04:00
|
|
|
|
2018-07-05 20:13:47 +03:00
|
|
|
void
|
|
|
|
UpdateStateInternal(const Maybe<ServiceWorkerDescriptor>& aInstalling,
|
|
|
|
const Maybe<ServiceWorkerDescriptor>& aWaiting,
|
|
|
|
const Maybe<ServiceWorkerDescriptor>& aActive);
|
|
|
|
|
2018-07-05 20:13:47 +03:00
|
|
|
void
|
|
|
|
MaybeScheduleUpdateFound(const Maybe<ServiceWorkerDescriptor>& aInstallingDescriptor);
|
|
|
|
|
|
|
|
void
|
|
|
|
MaybeDispatchUpdateFound();
|
|
|
|
|
2018-07-05 20:13:47 +03:00
|
|
|
void
|
|
|
|
UpdatePromiseSettled();
|
|
|
|
|
2018-02-14 22:23:16 +03:00
|
|
|
ServiceWorkerRegistrationDescriptor mDescriptor;
|
2018-02-14 22:23:17 +03:00
|
|
|
RefPtr<Inner> mInner;
|
2018-03-08 21:43:33 +03:00
|
|
|
|
2018-02-14 22:23:16 +03:00
|
|
|
RefPtr<ServiceWorker> mInstallingWorker;
|
|
|
|
RefPtr<ServiceWorker> mWaitingWorker;
|
|
|
|
RefPtr<ServiceWorker> mActiveWorker;
|
2018-02-14 22:23:17 +03:00
|
|
|
RefPtr<PushManager> mPushManager;
|
2018-07-05 20:13:47 +03:00
|
|
|
|
2018-07-05 20:13:48 +03:00
|
|
|
struct VersionCallback
|
|
|
|
{
|
|
|
|
uint64_t mVersion;
|
|
|
|
ServiceWorkerBoolCallback mFunc;
|
|
|
|
|
|
|
|
VersionCallback(uint64_t aVersion, ServiceWorkerBoolCallback&& aFunc)
|
|
|
|
: mVersion(aVersion)
|
|
|
|
, mFunc(std::move(aFunc))
|
|
|
|
{
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mFunc);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
nsTArray<UniquePtr<VersionCallback>> mVersionCallbackList;
|
|
|
|
|
2018-07-05 20:13:47 +03:00
|
|
|
uint64_t mScheduledUpdateFoundId;
|
|
|
|
uint64_t mDispatchedUpdateFoundId;
|
2018-07-05 20:13:47 +03:00
|
|
|
uint32_t mPendingUpdatePromises;
|
2015-04-04 01:18:55 +03:00
|
|
|
};
|
2015-04-11 06:19:28 +03:00
|
|
|
|
2018-03-03 00:02:49 +03:00
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(ServiceWorkerRegistration, NS_DOM_SERVICEWORKERREGISTRATION_IID)
|
2014-08-19 17:56:00 +04:00
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2015-04-04 01:18:55 +03:00
|
|
|
#endif /* mozilla_dom_ServiceWorkerRegistration_h */
|