Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/serviceworkers/ServiceWorkerRegistrationImpl.h
Line
Count
Source (jump to first uncovered line)
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 "nsIDocument.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 : public ServiceWorkerRegistration::Inner
31
                                                , public ServiceWorkerRegistrationListener
32
{
33
public:
34
  NS_INLINE_DECL_REFCOUNTING(ServiceWorkerRegistrationMainThread, override)
35
36
  explicit ServiceWorkerRegistrationMainThread(const ServiceWorkerRegistrationDescriptor& aDescriptor);
37
38
  // ServiceWorkerRegistration::Inner
39
  void
40
  SetServiceWorkerRegistration(ServiceWorkerRegistration* aReg) override;
41
42
  void
43
  ClearServiceWorkerRegistration(ServiceWorkerRegistration* aReg) override;
44
45
  void
46
  Update(ServiceWorkerRegistrationCallback&& aSuccessCB,
47
         ServiceWorkerFailureCallback&& aFailureCB) override;
48
49
  void
50
  Unregister(ServiceWorkerBoolCallback&& aSuccessCB,
51
             ServiceWorkerFailureCallback&& aFailureCB) override;
52
53
  // ServiceWorkerRegistrationListener
54
  void
55
  UpdateState(const ServiceWorkerRegistrationDescriptor& aDescriptor) override;
56
57
  void
58
  RegistrationRemoved() override;
59
60
  void
61
  GetScope(nsAString& aScope) const override
62
0
  {
63
0
    aScope = mScope;
64
0
  }
65
66
  bool
67
  MatchesDescriptor(const ServiceWorkerRegistrationDescriptor& aDescriptor) override;
68
69
private:
70
  ~ServiceWorkerRegistrationMainThread();
71
72
  void
73
  StartListeningForEvents();
74
75
  void
76
  StopListeningForEvents();
77
78
  void
79
  RegistrationRemovedInternal();
80
81
  ServiceWorkerRegistration* mOuter;
82
  ServiceWorkerRegistrationDescriptor mDescriptor;
83
  RefPtr<ServiceWorkerRegistrationInfo> mInfo;
84
  const nsString mScope;
85
  bool mListeningForEvents;
86
};
87
88
////////////////////////////////////////////////////
89
// Worker Thread implementation
90
91
class WorkerListener;
92
93
class ServiceWorkerRegistrationWorkerThread final : public ServiceWorkerRegistration::Inner
94
{
95
  friend class WorkerListener;
96
97
public:
98
  NS_INLINE_DECL_REFCOUNTING(ServiceWorkerRegistrationWorkerThread, override)
99
100
  explicit ServiceWorkerRegistrationWorkerThread(const ServiceWorkerRegistrationDescriptor& aDescriptor);
101
102
  void
103
  RegistrationRemoved();
104
105
  // ServiceWorkerRegistration::Inner
106
  void
107
  SetServiceWorkerRegistration(ServiceWorkerRegistration* aReg) override;
108
109
  void
110
  ClearServiceWorkerRegistration(ServiceWorkerRegistration* aReg) override;
111
112
  void
113
  Update(ServiceWorkerRegistrationCallback&& aSuccessCB,
114
         ServiceWorkerFailureCallback&& aFailureCB) override;
115
116
  void
117
  Unregister(ServiceWorkerBoolCallback&& aSuccessCB,
118
             ServiceWorkerFailureCallback&& aFailureCB) override;
119
120
private:
121
  ~ServiceWorkerRegistrationWorkerThread();
122
123
  void
124
  InitListener();
125
126
  void
127
  ReleaseListener();
128
129
  void
130
  UpdateState(const ServiceWorkerRegistrationDescriptor& aDescriptor);
131
132
  // This can be called only by WorkerListener.
133
  WorkerPrivate*
134
  GetWorkerPrivate(const MutexAutoLock& aProofOfLock);
135
136
  ServiceWorkerRegistration* mOuter;
137
  const ServiceWorkerRegistrationDescriptor mDescriptor;
138
  const nsString mScope;
139
  RefPtr<WorkerListener> mListener;
140
  RefPtr<WeakWorkerRef> mWorkerRef;
141
};
142
143
} // dom namespace
144
} // mozilla namespace
145
146
#endif // mozilla_dom_serviceworkerregistrationimpl_h