Source code

Revision control

Other Tools

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/. */
6
7
#ifndef mozilla_dom_serviceworkerregistrationimpl_h
8
#define mozilla_dom_serviceworkerregistrationimpl_h
9
10
#include "mozilla/dom/WorkerPrivate.h"
11
#include "mozilla/Unused.h"
12
#include "nsCycleCollectionParticipant.h"
13
#include "mozilla/dom/Document.h"
14
#include "nsPIDOMWindow.h"
15
#include "ServiceWorkerManager.h"
16
#include "ServiceWorkerRegistration.h"
17
#include "ServiceWorkerRegistrationListener.h"
18
19
namespace mozilla {
20
namespace dom {
21
22
class Promise;
23
class PushManager;
24
class ServiceWorker;
25
class WeakWorkerRef;
26
27
////////////////////////////////////////////////////
28
// Main Thread implementation
29
30
class ServiceWorkerRegistrationMainThread final
31
: public ServiceWorkerRegistration::Inner,
32
public ServiceWorkerRegistrationListener {
33
public:
34
NS_INLINE_DECL_REFCOUNTING(ServiceWorkerRegistrationMainThread, override)
35
36
explicit ServiceWorkerRegistrationMainThread(
37
const ServiceWorkerRegistrationDescriptor& aDescriptor);
38
39
// ServiceWorkerRegistration::Inner
40
void SetServiceWorkerRegistration(ServiceWorkerRegistration* aReg) override;
41
42
void ClearServiceWorkerRegistration(ServiceWorkerRegistration* aReg) override;
43
44
void Update(ServiceWorkerRegistrationCallback&& aSuccessCB,
45
ServiceWorkerFailureCallback&& aFailureCB) override;
46
47
void Unregister(ServiceWorkerBoolCallback&& aSuccessCB,
48
ServiceWorkerFailureCallback&& aFailureCB) override;
49
50
// ServiceWorkerRegistrationListener
51
void UpdateState(
52
const ServiceWorkerRegistrationDescriptor& aDescriptor) override;
53
54
void FireUpdateFound() override;
55
56
void RegistrationCleared() override;
57
58
void GetScope(nsAString& aScope) const override { aScope = mScope; }
59
60
bool MatchesDescriptor(
61
const ServiceWorkerRegistrationDescriptor& aDescriptor) override;
62
63
private:
64
~ServiceWorkerRegistrationMainThread();
65
66
void StartListeningForEvents();
67
68
void StopListeningForEvents();
69
70
void RegistrationClearedInternal();
71
72
ServiceWorkerRegistration* mOuter;
73
ServiceWorkerRegistrationDescriptor mDescriptor;
74
RefPtr<ServiceWorkerRegistrationInfo> mInfo;
75
const nsString mScope;
76
bool mListeningForEvents;
77
};
78
79
////////////////////////////////////////////////////
80
// Worker Thread implementation
81
82
class WorkerListener;
83
84
class ServiceWorkerRegistrationWorkerThread final
85
: public ServiceWorkerRegistration::Inner {
86
friend class WorkerListener;
87
88
public:
89
NS_INLINE_DECL_REFCOUNTING(ServiceWorkerRegistrationWorkerThread, override)
90
91
explicit ServiceWorkerRegistrationWorkerThread(
92
const ServiceWorkerRegistrationDescriptor& aDescriptor);
93
94
void RegistrationCleared();
95
96
// ServiceWorkerRegistration::Inner
97
void SetServiceWorkerRegistration(ServiceWorkerRegistration* aReg) override;
98
99
void ClearServiceWorkerRegistration(ServiceWorkerRegistration* aReg) override;
100
101
void Update(ServiceWorkerRegistrationCallback&& aSuccessCB,
102
ServiceWorkerFailureCallback&& aFailureCB) override;
103
104
void Unregister(ServiceWorkerBoolCallback&& aSuccessCB,
105
ServiceWorkerFailureCallback&& aFailureCB) override;
106
107
private:
108
~ServiceWorkerRegistrationWorkerThread();
109
110
void InitListener();
111
112
void ReleaseListener();
113
114
void UpdateState(const ServiceWorkerRegistrationDescriptor& aDescriptor);
115
116
void FireUpdateFound();
117
118
// This can be called only by WorkerListener.
119
WorkerPrivate* GetWorkerPrivate(const MutexAutoLock& aProofOfLock);
120
121
ServiceWorkerRegistration* mOuter;
122
const ServiceWorkerRegistrationDescriptor mDescriptor;
123
const nsString mScope;
124
RefPtr<WorkerListener> mListener;
125
RefPtr<WeakWorkerRef> mWorkerRef;
126
};
127
128
} // namespace dom
129
} // namespace mozilla
130
131
#endif // mozilla_dom_serviceworkerregistrationimpl_h