1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_serviceworker_h__
8 #define mozilla_dom_serviceworker_h__
10 #include "mozilla/DOMEventTargetHelper.h"
11 #include "mozilla/dom/BindingDeclarations.h"
12 #include "mozilla/dom/ServiceWorkerDescriptor.h"
13 #include "mozilla/dom/ServiceWorkerUtils.h"
19 class nsIGlobalObject
;
21 namespace mozilla::dom
{
23 class ServiceWorkerChild
;
24 class ServiceWorkerCloneData
;
25 struct StructuredSerializeOptions
;
27 #define NS_DOM_SERVICEWORKER_IID \
29 0xd42e0611, 0x3647, 0x4319, { \
30 0xae, 0x05, 0x19, 0x89, 0x59, 0xba, 0x99, 0x5e \
34 class ServiceWorker final
: public DOMEventTargetHelper
{
36 NS_DECLARE_STATIC_IID_ACCESSOR(NS_DOM_SERVICEWORKER_IID
)
37 NS_DECL_ISUPPORTS_INHERITED
38 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ServiceWorker
, DOMEventTargetHelper
)
40 IMPL_EVENT_HANDLER(statechange
)
41 IMPL_EVENT_HANDLER(error
)
43 static already_AddRefed
<ServiceWorker
> Create(
44 nsIGlobalObject
* aOwner
, const ServiceWorkerDescriptor
& aDescriptor
);
46 virtual JSObject
* WrapObject(JSContext
* aCx
,
47 JS::Handle
<JSObject
*> aGivenProto
) override
;
49 ServiceWorkerState
State() const;
51 void SetState(ServiceWorkerState aState
);
53 void MaybeDispatchStateChangeEvent();
55 void GetScriptURL(nsString
& aURL
) const;
57 void PostMessage(JSContext
* aCx
, JS::Handle
<JS::Value
> aMessage
,
58 const Sequence
<JSObject
*>& aTransferable
, ErrorResult
& aRv
);
60 void PostMessage(JSContext
* aCx
, JS::Handle
<JS::Value
> aMessage
,
61 const StructuredSerializeOptions
& aOptions
,
64 const ServiceWorkerDescriptor
& Descriptor() const;
66 void DisconnectFromOwner() override
;
68 void RevokeActor(ServiceWorkerChild
* aActor
);
71 ServiceWorker(nsIGlobalObject
* aWindow
,
72 const ServiceWorkerDescriptor
& aDescriptor
);
74 // This class is reference-counted and will be destroyed from Release().
77 void MaybeAttachToRegistration(ServiceWorkerRegistration
* aRegistration
);
81 ServiceWorkerDescriptor mDescriptor
;
83 RefPtr
<ServiceWorkerChild
> mActor
;
86 RefPtr
<ServiceWorkerRegistration
> mRegistration
;
87 ServiceWorkerState mLastNotifiedState
;
90 NS_DEFINE_STATIC_IID_ACCESSOR(ServiceWorker
, NS_DOM_SERVICEWORKER_IID
)
92 } // namespace mozilla::dom
94 #endif // mozilla_dom_serviceworker_h__