Attachment #8727182: Part 4: SyncEvent for bug #1217544

View | Details | Raw Unified | Return to bug 1217544
Collapse All | Expand All

(-)a/dom/bindings/Bindings.conf (+6 lines)
Line     Link Here 
 Lines 1264-1279   DOMInterfaces = { Link Here 
1264
'SVGUnitTypes' : {
1264
'SVGUnitTypes' : {
1265
    'concrete': False,
1265
    'concrete': False,
1266
},
1266
},
1267
1267
1268
'SVGZoomAndPan' : {
1268
'SVGZoomAndPan' : {
1269
    'concrete': False,
1269
    'concrete': False,
1270
},
1270
},
1271
1271
1272
'SyncEvent': {
1273
    'headerFile': 'mozilla/dom/ServiceWorkerEvents.h',
1274
    'nativeType': 'mozilla::dom::workers::SyncEvent',
1275
    'workers': True
1276
},
1277
1272
'Text': {
1278
'Text': {
1273
    # Total hack to allow binding code to realize that nsTextNode can
1279
    # Total hack to allow binding code to realize that nsTextNode can
1274
    # in fact be cast to Text.
1280
    # in fact be cast to Text.
1275
    'headerFile': 'nsTextNode.h',
1281
    'headerFile': 'nsTextNode.h',
1276
},
1282
},
1277
1283
1278
'TextDecoder': {
1284
'TextDecoder': {
1279
    'wrapperCache': False
1285
    'wrapperCache': False
(-)a/dom/interfaces/base/nsIServiceWorkerManager.idl (-2 / +6 lines)
Line     Link Here 
 Lines 72-88   interface nsIServiceWorkerRegistrationIn Link Here 
72
[scriptable, uuid(9e523e7c-ad6f-4df0-8077-c74aebbc679d)]
72
[scriptable, uuid(9e523e7c-ad6f-4df0-8077-c74aebbc679d)]
73
interface nsIServiceWorkerManagerListener : nsISupports
73
interface nsIServiceWorkerManagerListener : nsISupports
74
{
74
{
75
  void onRegister(in nsIServiceWorkerRegistrationInfo aInfo);
75
  void onRegister(in nsIServiceWorkerRegistrationInfo aInfo);
76
76
77
  void onUnregister(in nsIServiceWorkerRegistrationInfo aInfo);
77
  void onUnregister(in nsIServiceWorkerRegistrationInfo aInfo);
78
};
78
};
79
79
80
[scriptable, builtinclass, uuid(7404c8e8-4d47-4449-8ed1-47d1261d4e33)]
80
[scriptable, builtinclass, uuid(0577039d-c34e-4f01-afb4-a423ae650e54)]
81
interface nsIServiceWorkerManager : nsISupports
81
interface nsIServiceWorkerManager : nsISupports
82
{
82
{
83
  /**
83
  /**
84
   * Registers a ServiceWorker with script loaded from `aScriptURI` to act as
84
   * Registers a ServiceWorker with script loaded from `aScriptURI` to act as
85
   * the ServiceWorker for aScope.  Requires a valid entry settings object on
85
   * the ServiceWorker for aScope.  Requires a valid entry settings object on
86
   * the stack. This means you must call this from content code 'within'
86
   * the stack. This means you must call this from content code 'within'
87
   * a window.
87
   * a window.
88
   *
88
   *
 Lines 186-204   interface nsIServiceWorkerManager : nsIS Link Here 
186
                                  in AString aData,
186
                                  in AString aData,
187
                                  in AString aBehavior);
187
                                  in AString aBehavior);
188
  [optional_argc] void sendPushEvent(in ACString aOriginAttributes,
188
  [optional_argc] void sendPushEvent(in ACString aOriginAttributes,
189
                                     in ACString aScope,
189
                                     in ACString aScope,
190
                                     [optional] in uint32_t aDataLength,
190
                                     [optional] in uint32_t aDataLength,
191
                                     [optional, array, size_is(aDataLength)] in uint8_t aDataBytes);
191
                                     [optional, array, size_is(aDataLength)] in uint8_t aDataBytes);
192
  void sendPushSubscriptionChangeEvent(in ACString aOriginAttributes,
192
  void sendPushSubscriptionChangeEvent(in ACString aOriginAttributes,
193
                                       in ACString scope);
193
                                       in ACString scope);
194
195
  void addListener(in nsIServiceWorkerManagerListener aListener);
194
  void addListener(in nsIServiceWorkerManagerListener aListener);
196
195
197
  void removeListener(in nsIServiceWorkerManagerListener aListener);
196
  void removeListener(in nsIServiceWorkerManagerListener aListener);
198
197
199
  bool shouldReportToWindow(in mozIDOMWindowProxy aWindow, in ACString aScope);
198
  bool shouldReportToWindow(in mozIDOMWindowProxy aWindow, in ACString aScope);
199
200
  void sendSyncEvent(in ACString aOriginAttributes,
201
                     in ACString scope,
202
                     in AString aTag,
203
                     in boolean aLastChance);
200
};
204
};
201
205
202
%{ C++
206
%{ C++
203
#define SERVICEWORKERMANAGER_CONTRACTID "@mozilla.org/serviceworkers/manager;1"
207
#define SERVICEWORKERMANAGER_CONTRACTID "@mozilla.org/serviceworkers/manager;1"
204
%}
208
%}
(-)a/dom/sync/SyncIPCTypes.ipdlh (+1 lines)
Line     Link Here 
 Lines 4-19    Link Here 
4
4
5
include PBackgroundSharedTypes;
5
include PBackgroundSharedTypes;
6
6
7
namespace mozilla {
7
namespace mozilla {
8
namespace dom {
8
namespace dom {
9
9
10
struct SyncRegisterArgs
10
struct SyncRegisterArgs
11
{
11
{
12
  nsString mScope;
12
  nsString mTag;
13
  nsString mTag;
13
};
14
};
14
15
15
struct SyncGetTagsArgs
16
struct SyncGetTagsArgs
16
{
17
{
17
};
18
};
18
19
19
union SyncOpArgs
20
union SyncOpArgs
(-)a/dom/sync/SyncManager.cpp (-5 / +11 lines)
Line     Link Here 
 Lines 139-167   private: Link Here 
139
};
139
};
140
140
141
// SyncManager
141
// SyncManager
142
142
143
// static
143
// static
144
already_AddRefed<SyncManager>
144
already_AddRefed<SyncManager>
145
SyncManager::CreateOnMainThread(nsIGlobalObject* aGlobal,
145
SyncManager::CreateOnMainThread(nsIGlobalObject* aGlobal,
146
                                nsIPrincipal* aPrincipal,
146
                                nsIPrincipal* aPrincipal,
147
                                const nsAString& aScope,
147
                                ErrorResult& aRv)
148
                                ErrorResult& aRv)
148
{
149
{
149
  MOZ_ASSERT(aGlobal);
150
  MOZ_ASSERT(aGlobal);
150
  MOZ_ASSERT(aPrincipal);
151
  MOZ_ASSERT(aPrincipal);
152
  MOZ_ASSERT(!aScope.IsEmpty());
151
  MOZ_ASSERT(NS_IsMainThread());
153
  MOZ_ASSERT(NS_IsMainThread());
152
154
153
  PrincipalInfo principalInfo;
155
  PrincipalInfo principalInfo;
154
  aRv = PrincipalToPrincipalInfo(aPrincipal, &principalInfo);
156
  aRv = PrincipalToPrincipalInfo(aPrincipal, &principalInfo);
155
  if (NS_WARN_IF(aRv.Failed())) {
157
  if (NS_WARN_IF(aRv.Failed())) {
156
    return nullptr;
158
    return nullptr;
157
  }
159
  }
158
160
159
  RefPtr<SyncManager> ref = new SyncManager(aGlobal, principalInfo);
161
  RefPtr<SyncManager> ref = new SyncManager(aGlobal, principalInfo, aScope);
160
162
161
  // Register as observeer for inner-window-destroyed.
163
  // Register as observeer for inner-window-destroyed.
162
  nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
164
  nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
163
  if (obs) {
165
  if (obs) {
164
    aRv = obs->AddObserver(ref, "inner-window-destroyed",
166
    aRv = obs->AddObserver(ref, "inner-window-destroyed",
165
                           false /* ownsWeak */);
167
                           false /* ownsWeak */);
166
    if (NS_WARN_IF(aRv.Failed())) {
168
    if (NS_WARN_IF(aRv.Failed())) {
167
      return nullptr;
169
      return nullptr;
 Lines 174-216   SyncManager::CreateOnMainThread(nsIGloba Link Here 
174
  ref->mInnerID = window->WindowID();
176
  ref->mInnerID = window->WindowID();
175
177
176
  return ref.forget();
178
  return ref.forget();
177
}
179
}
178
180
179
// static
181
// static
180
already_AddRefed<SyncManager>
182
already_AddRefed<SyncManager>
181
SyncManager::CreateOnWorker(nsIGlobalObject* aGlobal,
183
SyncManager::CreateOnWorker(nsIGlobalObject* aGlobal,
182
                            WorkerPrivate* aWorkerPrivate)
184
                            WorkerPrivate* aWorkerPrivate,
185
                            const nsAString& aScope)
183
{
186
{
184
  MOZ_ASSERT(aWorkerPrivate);
187
  MOZ_ASSERT(aWorkerPrivate);
188
  MOZ_ASSERT(!aScope.IsEmpty());
185
  aWorkerPrivate->AssertIsOnWorkerThread();
189
  aWorkerPrivate->AssertIsOnWorkerThread();
186
190
187
  const PrincipalInfo& principalInfo = aWorkerPrivate->GetPrincipalInfo();
191
  const PrincipalInfo& principalInfo = aWorkerPrivate->GetPrincipalInfo();
188
192
189
  RefPtr<SyncManager> ref = new SyncManager(aGlobal, principalInfo);
193
  RefPtr<SyncManager> ref = new SyncManager(aGlobal, principalInfo, aScope);
190
194
191
  ref->mWorkerFeature = new SyncManagerFeature(ref);
195
  ref->mWorkerFeature = new SyncManagerFeature(ref);
192
  JSContext* cx = aWorkerPrivate->GetJSContext();
196
  JSContext* cx = aWorkerPrivate->GetJSContext();
193
  if (NS_WARN_IF(!aWorkerPrivate->AddFeature(cx, ref->mWorkerFeature))) {
197
  if (NS_WARN_IF(!aWorkerPrivate->AddFeature(cx, ref->mWorkerFeature))) {
194
    NS_WARNING("Failed to register SyncManager worker feature");
198
    NS_WARNING("Failed to register SyncManager worker feature");
195
    ref->mWorkerFeature = nullptr;
199
    ref->mWorkerFeature = nullptr;
196
    return nullptr;
200
    return nullptr;
197
  }
201
  }
198
202
199
  return ref.forget();
203
  return ref.forget();
200
}
204
}
201
205
202
SyncManager::SyncManager(nsIGlobalObject* aGlobal,
206
SyncManager::SyncManager(nsIGlobalObject* aGlobal,
203
                         const PrincipalInfo& aPrincipalInfo)
207
                         const PrincipalInfo& aPrincipalInfo,
208
                         const nsAString& aScope)
204
  : mInnerID(0)
209
  : mInnerID(0)
205
  , mGlobal(aGlobal)
210
  , mGlobal(aGlobal)
206
  , mWorkerFeature(nullptr)
211
  , mWorkerFeature(nullptr)
207
  , mShuttingDown(false)
212
  , mShuttingDown(false)
208
  , mPrincipalInfo(MakeUnique<PrincipalInfo>(aPrincipalInfo))
213
  , mPrincipalInfo(MakeUnique<PrincipalInfo>(aPrincipalInfo))
214
  , mScope(aScope)
209
{
215
{
210
  // Register this component to PBackground.
216
  // Register this component to PBackground.
211
  PBackgroundChild* actor = BackgroundChild::GetForCurrentThread();
217
  PBackgroundChild* actor = BackgroundChild::GetForCurrentThread();
212
  if (actor) {
218
  if (actor) {
213
    ActorCreated(actor);
219
    ActorCreated(actor);
214
  } else {
220
  } else {
215
    MOZ_ALWAYS_TRUE(BackgroundChild::GetOrCreateForCurrentThread(this));
221
    MOZ_ALWAYS_TRUE(BackgroundChild::GetOrCreateForCurrentThread(this));
216
  }
222
  }
 Lines 376-392   SyncManager::ExecuteOp(const SyncOpArgs& Link Here 
376
  return p.forget();
382
  return p.forget();
377
}
383
}
378
384
379
// WebIDL interface methods.
385
// WebIDL interface methods.
380
386
381
already_AddRefed<Promise>
387
already_AddRefed<Promise>
382
SyncManager::Register(const nsAString& aTag, ErrorResult& aRv)
388
SyncManager::Register(const nsAString& aTag, ErrorResult& aRv)
383
{
389
{
384
  const SyncRegisterArgs args((nsString(aTag)));
390
  const SyncRegisterArgs args(mScope, (nsString(aTag)));
385
  return ExecuteOp(SyncOpArgs(args), aRv);
391
  return ExecuteOp(SyncOpArgs(args), aRv);
386
}
392
}
387
393
388
already_AddRefed<Promise>
394
already_AddRefed<Promise>
389
SyncManager::GetTags(ErrorResult& aRv)
395
SyncManager::GetTags(ErrorResult& aRv)
390
{
396
{
391
  const SyncGetTagsArgs args;
397
  const SyncGetTagsArgs args;
392
  return ExecuteOp(SyncOpArgs(args), aRv);
398
  return ExecuteOp(SyncOpArgs(args), aRv);
(-)a/dom/sync/SyncManager.h (-2 / +7 lines)
Line     Link Here 
 Lines 50-70   class SyncManager final : public nsIIPCB Link Here 
50
public:
50
public:
51
  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
51
  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
52
  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(
52
  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(
53
      SyncManager, nsIIPCBackgroundChildCreateCallback)
53
      SyncManager, nsIIPCBackgroundChildCreateCallback)
54
54
55
  static already_AddRefed<SyncManager>
55
  static already_AddRefed<SyncManager>
56
  CreateOnMainThread(nsIGlobalObject* aGlobal,
56
  CreateOnMainThread(nsIGlobalObject* aGlobal,
57
                     nsIPrincipal* aPrincipal,
57
                     nsIPrincipal* aPrincipal,
58
                     const nsAString& aScope,
58
                     ErrorResult& aRv);
59
                     ErrorResult& aRv);
59
60
60
  static already_AddRefed<SyncManager>
61
  static already_AddRefed<SyncManager>
61
  CreateOnWorker(nsIGlobalObject* aGlobal,
62
  CreateOnWorker(nsIGlobalObject* aGlobal,
62
                 workers::WorkerPrivate* aWorkerPrivate);
63
                 workers::WorkerPrivate* aWorkerPrivate,
64
                 const nsAString& aScope);
63
65
64
  uint64_t mInnerID;
66
  uint64_t mInnerID;
65
67
66
  // Binding methods.
68
  // Binding methods.
67
69
68
  nsIGlobalObject*
70
  nsIGlobalObject*
69
  GetParentObject() const
71
  GetParentObject() const
70
  {
72
  {
 Lines 82-113   public: Link Here 
82
  Register(const nsAString& aTag, ErrorResult& aRv);
84
  Register(const nsAString& aTag, ErrorResult& aRv);
83
85
84
  already_AddRefed<Promise>
86
  already_AddRefed<Promise>
85
  GetTags(ErrorResult& aRv);
87
  GetTags(ErrorResult& aRv);
86
88
87
  void Shutdown();
89
  void Shutdown();
88
private:
90
private:
89
  SyncManager(nsIGlobalObject* aGlobal,
91
  SyncManager(nsIGlobalObject* aGlobal,
90
              const mozilla::ipc::PrincipalInfo& aPrincipalInfo);
92
              const mozilla::ipc::PrincipalInfo& aPrincipalInfo,
93
              const nsAString& aScope);
91
94
92
  ~SyncManager();
95
  ~SyncManager();
93
96
94
  already_AddRefed<Promise>
97
  already_AddRefed<Promise>
95
  ExecuteOp(const SyncOpArgs& aArgs, ErrorResult& aRv);
98
  ExecuteOp(const SyncOpArgs& aArgs, ErrorResult& aRv);
96
99
97
  nsCOMPtr<nsIGlobalObject> mGlobal;
100
  nsCOMPtr<nsIGlobalObject> mGlobal;
98
101
99
  nsAutoPtr<workers::WorkerFeature> mWorkerFeature;
102
  nsAutoPtr<workers::WorkerFeature> mWorkerFeature;
100
103
101
  RefPtr<SyncManagerChild> mActor;
104
  RefPtr<SyncManagerChild> mActor;
102
105
103
  bool mShuttingDown;
106
  bool mShuttingDown;
104
107
105
  UniquePtr<mozilla::ipc::PrincipalInfo> mPrincipalInfo;
108
  UniquePtr<mozilla::ipc::PrincipalInfo> mPrincipalInfo;
106
109
110
  nsString mScope;
111
107
  nsTArray<RefPtr<SyncOpRunnable>> mPendingOperations;
112
  nsTArray<RefPtr<SyncOpRunnable>> mPendingOperations;
108
};
113
};
109
114
110
} // namespace dom
115
} // namespace dom
111
} // namespace mozilla
116
} // namespace mozilla
112
117
113
#endif // mozilla_dom_SyncManager_h
118
#endif // mozilla_dom_SyncManager_h
(-)a/dom/webidl/SyncEvent.webidl (+20 lines)
Line     Link Here 
Line 0    Link Here 
1
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* This Source Code Form is subject to the terms of the Mozilla Public
3
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
4
 * You can obtain one at http://mozilla.org/MPL/2.0/.
5
 *
6
 * The origin of this IDL file is
7
 * https://wicg.github.io/BackgroundSync/spec/
8
 */
9
10
[Constructor(DOMString type, optional SyncEventInit eventInitDict),
11
 Exposed=ServiceWorker]
12
interface SyncEvent : ExtendableEvent {
13
  readonly attribute DOMString tag;
14
  readonly attribute boolean lastChance;
15
};
16
17
dictionary SyncEventInit : ExtendableEventInit {
18
  required DOMString tag;
19
  boolean lastChance = false;
20
};
(-)a/dom/webidl/moz.build (+1 lines)
Line     Link Here 
 Lines 534-549   WEBIDL_FILES = [ Link Here 
534
    'SVGTransformList.webidl',
534
    'SVGTransformList.webidl',
535
    'SVGTSpanElement.webidl',
535
    'SVGTSpanElement.webidl',
536
    'SVGUnitTypes.webidl',
536
    'SVGUnitTypes.webidl',
537
    'SVGURIReference.webidl',
537
    'SVGURIReference.webidl',
538
    'SVGUseElement.webidl',
538
    'SVGUseElement.webidl',
539
    'SVGViewElement.webidl',
539
    'SVGViewElement.webidl',
540
    'SVGZoomAndPan.webidl',
540
    'SVGZoomAndPan.webidl',
541
    'SVGZoomEvent.webidl',
541
    'SVGZoomEvent.webidl',
542
    'SyncEvent.webidl',
542
    'SyncManager.webidl',
543
    'SyncManager.webidl',
543
    'SystemUpdate.webidl',
544
    'SystemUpdate.webidl',
544
    'TCPServerSocket.webidl',
545
    'TCPServerSocket.webidl',
545
    'TCPServerSocketEvent.webidl',
546
    'TCPServerSocketEvent.webidl',
546
    'TCPSocket.webidl',
547
    'TCPSocket.webidl',
547
    'TCPSocketErrorEvent.webidl',
548
    'TCPSocketErrorEvent.webidl',
548
    'TCPSocketEvent.webidl',
549
    'TCPSocketEvent.webidl',
549
    'Telephony.webidl',
550
    'Telephony.webidl',
(-)a/dom/workers/PServiceWorkerManager.ipdl (-1 / +6 lines)
Line     Link Here 
 Lines 28-45   parent: Link Here 
28
  async PropagateRemove(nsCString host);
28
  async PropagateRemove(nsCString host);
29
29
30
  async PropagateRemoveAll();
30
  async PropagateRemoveAll();
31
31
32
  async Shutdown();
32
  async Shutdown();
33
33
34
child:
34
child:
35
  async NotifyRegister(ServiceWorkerRegistrationData data);
35
  async NotifyRegister(ServiceWorkerRegistrationData data);
36
  async NotifySoftUpdate(PrincipalOriginAttributes originAttributes, nsString scope);
36
  async NotifySoftUpdate(PrincipalOriginAttributes originAttributes,
37
                         nsString scope);
37
  async NotifyUnregister(PrincipalInfo principalInfo, nsString scope);
38
  async NotifyUnregister(PrincipalInfo principalInfo, nsString scope);
38
  async NotifyRemove(nsCString host);
39
  async NotifyRemove(nsCString host);
39
  async NotifyRemoveAll();
40
  async NotifyRemoveAll();
41
  async SendSyncEvent(nsString originAttributes,
42
                      nsString scope,
43
                      nsString tag,
44
                      bool lastChance);
40
45
41
  async __delete__();
46
  async __delete__();
42
};
47
};
43
48
44
} // namespace dom
49
} // namespace dom
45
} // namespace mozilla
50
} // namespace mozilla
(-)a/dom/workers/ServiceWorkerEvents.cpp (-1 / +35 lines)
Line     Link Here 
 Lines 979-995   ExtractBytesFromData(const OwningArrayBu Link Here 
979
    const ArrayBuffer& buffer = aDataInit.GetAsArrayBuffer();
979
    const ArrayBuffer& buffer = aDataInit.GetAsArrayBuffer();
980
    return ExtractBytesFromArrayBuffer(buffer, aBytes);
980
    return ExtractBytesFromArrayBuffer(buffer, aBytes);
981
  } else if (aDataInit.IsUSVString()) {
981
  } else if (aDataInit.IsUSVString()) {
982
    return ExtractBytesFromUSVString(aDataInit.GetAsUSVString(), aBytes);
982
    return ExtractBytesFromUSVString(aDataInit.GetAsUSVString(), aBytes);
983
  }
983
  }
984
  NS_NOTREACHED("Unexpected push message data");
984
  NS_NOTREACHED("Unexpected push message data");
985
  return NS_ERROR_FAILURE;
985
  return NS_ERROR_FAILURE;
986
}
986
}
987
}
987
} // namespace
988
988
989
PushMessageData::PushMessageData(nsISupports* aOwner,
989
PushMessageData::PushMessageData(nsISupports* aOwner,
990
                                 const nsTArray<uint8_t>& aBytes)
990
                                 const nsTArray<uint8_t>& aBytes)
991
  : mOwner(aOwner), mBytes(aBytes) {}
991
  : mOwner(aOwner), mBytes(aBytes) {}
992
992
993
PushMessageData::~PushMessageData()
993
PushMessageData::~PushMessageData()
994
{
994
{
995
}
995
}
 Lines 1110-1125   NS_IMPL_RELEASE_INHERITED(PushEvent, Ext Link Here 
1110
1110
1111
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(PushEvent)
1111
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(PushEvent)
1112
NS_INTERFACE_MAP_END_INHERITING(ExtendableEvent)
1112
NS_INTERFACE_MAP_END_INHERITING(ExtendableEvent)
1113
1113
1114
NS_IMPL_CYCLE_COLLECTION_INHERITED(PushEvent, ExtendableEvent, mData)
1114
NS_IMPL_CYCLE_COLLECTION_INHERITED(PushEvent, ExtendableEvent, mData)
1115
1115
1116
#endif /* ! MOZ_SIMPLEPUSH */
1116
#endif /* ! MOZ_SIMPLEPUSH */
1117
1117
1118
// Background Sync
1119
1120
SyncEvent::SyncEvent(EventTarget* aOwner)
1121
  : ExtendableEvent(aOwner)
1122
{
1123
}
1124
1125
already_AddRefed<SyncEvent>
1126
SyncEvent::Constructor(mozilla::dom::EventTarget* aOwner,
1127
                       const nsAString& aType,
1128
                       const SyncEventInit& aOptions,
1129
                       ErrorResult& aRv)
1130
{
1131
  RefPtr<SyncEvent> e = new SyncEvent(aOwner);
1132
  bool trusted = e->Init(aOwner);
1133
  e->InitEvent(aType, aOptions.mBubbles, aOptions.mCancelable);
1134
  e->SetTrusted(trusted);
1135
  e->mTag = aOptions.mTag;
1136
  e->mLastChance = aOptions.mLastChance;
1137
  return e.forget();
1138
}
1139
1140
NS_IMPL_ADDREF_INHERITED(SyncEvent, ExtendableEvent)
1141
NS_IMPL_RELEASE_INHERITED(SyncEvent, ExtendableEvent)
1142
1143
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(SyncEvent)
1144
NS_INTERFACE_MAP_END_INHERITING(ExtendableEvent)
1145
1146
NS_IMPL_CYCLE_COLLECTION_CLASS(SyncEvent)
1147
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(SyncEvent, ExtendableEvent)
1148
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
1149
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(SyncEvent, ExtendableEvent)
1150
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
1151
1118
ExtendableMessageEvent::ExtendableMessageEvent(EventTarget* aOwner)
1152
ExtendableMessageEvent::ExtendableMessageEvent(EventTarget* aOwner)
1119
  : ExtendableEvent(aOwner)
1153
  : ExtendableEvent(aOwner)
1120
  , mData(JS::UndefinedValue())
1154
  , mData(JS::UndefinedValue())
1121
{
1155
{
1122
  mozilla::HoldJSObjects(this);
1156
  mozilla::HoldJSObjects(this);
1123
}
1157
}
1124
1158
1125
ExtendableMessageEvent::~ExtendableMessageEvent()
1159
ExtendableMessageEvent::~ExtendableMessageEvent()
(-)a/dom/workers/ServiceWorkerEvents.h (+51 lines)
Line     Link Here 
 Lines 16-31    Link Here 
16
#include "mozilla/dom/workers/bindings/ServiceWorker.h"
16
#include "mozilla/dom/workers/bindings/ServiceWorker.h"
17
17
18
#ifndef MOZ_SIMPLEPUSH
18
#ifndef MOZ_SIMPLEPUSH
19
#include "mozilla/dom/PushEventBinding.h"
19
#include "mozilla/dom/PushEventBinding.h"
20
#include "mozilla/dom/PushMessageDataBinding.h"
20
#include "mozilla/dom/PushMessageDataBinding.h"
21
#include "mozilla/dom/File.h"
21
#include "mozilla/dom/File.h"
22
#endif
22
#endif
23
23
24
#include "mozilla/dom/SyncEventBinding.h"
25
24
#include "nsProxyRelease.h"
26
#include "nsProxyRelease.h"
25
#include "nsContentUtils.h"
27
#include "nsContentUtils.h"
26
28
27
class nsIInterceptedChannel;
29
class nsIInterceptedChannel;
28
30
29
namespace mozilla {
31
namespace mozilla {
30
namespace dom {
32
namespace dom {
31
class Blob;
33
class Blob;
 Lines 317-327   public: Link Here 
317
319
318
  void SetPorts(MessagePortList* aPorts);
320
  void SetPorts(MessagePortList* aPorts);
319
321
320
  void SetSource(ServiceWorkerClient* aClient);
322
  void SetSource(ServiceWorkerClient* aClient);
321
323
322
  void SetSource(ServiceWorker* aServiceWorker);
324
  void SetSource(ServiceWorker* aServiceWorker);
323
};
325
};
324
326
327
class SyncEvent final : public ExtendableEvent
328
{
329
  nsString mTag;
330
  bool mLastChance;
331
332
protected:
333
  explicit SyncEvent(mozilla::dom::EventTarget* aOwner);
334
  ~SyncEvent() {}
335
336
public:
337
  NS_DECL_ISUPPORTS_INHERITED
338
  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SyncEvent, ExtendableEvent)
339
  NS_FORWARD_TO_EVENT
340
341
  virtual JSObject* WrapObjectInternal(JSContext* aCx,
342
                                       JS::Handle<JSObject*> aGivenProto) override
343
  {
344
    return mozilla::dom::SyncEventBinding_workers::Wrap(aCx, this, aGivenProto);
345
  }
346
347
  static already_AddRefed<SyncEvent>
348
  Constructor(mozilla::dom::EventTarget* aOwner,
349
              const nsAString& aType,
350
              const SyncEventInit& aOptions,
351
              ErrorResult& aRv);
352
353
  static already_AddRefed<SyncEvent>
354
  Constructor(const GlobalObject& aGlobal,
355
              const nsAString& aType,
356
              const SyncEventInit& aOptions,
357
              ErrorResult& aRv)
358
  {
359
    nsCOMPtr<EventTarget> owner = do_QueryInterface(aGlobal.GetAsSupports());
360
    return Constructor(owner, aType, aOptions, aRv);
361
  }
362
363
  void
364
  GetTag(nsAString& aTag)
365
  {
366
    aTag = mTag;
367
  }
368
369
  bool
370
  LastChance()
371
  {
372
    return mLastChance;
373
  }
374
};
375
325
END_WORKERS_NAMESPACE
376
END_WORKERS_NAMESPACE
326
377
327
#endif /* mozilla_dom_workers_serviceworkerevents_h__ */
378
#endif /* mozilla_dom_workers_serviceworkerevents_h__ */
(-)a/dom/workers/ServiceWorkerManager.cpp (+26 lines)
Line     Link Here 
 Lines 5200-5208   ServiceWorkerInfo::~ServiceWorkerInfo() Link Here 
5200
static uint64_t gServiceWorkerInfoCurrentID = 0;
5200
static uint64_t gServiceWorkerInfoCurrentID = 0;
5201
5201
5202
uint64_t
5202
uint64_t
5203
ServiceWorkerInfo::GetNextID() const
5203
ServiceWorkerInfo::GetNextID() const
5204
{
5204
{
5205
  return ++gServiceWorkerInfoCurrentID;
5205
  return ++gServiceWorkerInfoCurrentID;
5206
}
5206
}
5207
5207
5208
// Background Sync
5209
5210
NS_IMETHODIMP
5211
ServiceWorkerManager::SendSyncEvent(const nsACString& aOriginAttributes,
5212
                                    const nsACString& aScope,
5213
                                    const nsAString& aTag,
5214
                                    const bool aLastChance)
5215
{
5216
  PrincipalOriginAttributes attrs;
5217
  if (!attrs.PopulateFromSuffix(aOriginAttributes)) {
5218
    return NS_ERROR_INVALID_ARG;
5219
  }
5220
5221
  ServiceWorkerInfo* serviceWorker =
5222
    GetActiveWorkerInfoForScope(attrs, aScope);
5223
  if (NS_WARN_IF(!serviceWorker)) {
5224
    return NS_ERROR_FAILURE;
5225
  }
5226
5227
  RefPtr<ServiceWorkerRegistrationInfo> registration =
5228
    GetRegistration(serviceWorker->GetPrincipal(), aScope);
5229
5230
  return serviceWorker->WorkerPrivate()->SendSyncEvent(aTag, aLastChance,
5231
                                                       registration);
5232
}
5233
5208
END_WORKERS_NAMESPACE
5234
END_WORKERS_NAMESPACE
(-)a/dom/workers/ServiceWorkerManagerChild.cpp (+20 lines)
Line     Link Here 
 Lines 90-100   ServiceWorkerManagerChild::RecvNotifyRem Link Here 
90
90
91
  RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
91
  RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
92
  MOZ_ASSERT(swm);
92
  MOZ_ASSERT(swm);
93
93
94
  swm->RemoveAll();
94
  swm->RemoveAll();
95
  return true;
95
  return true;
96
}
96
}
97
97
98
bool
99
ServiceWorkerManagerChild::RecvSendSyncEvent(
100
    const nsString& aOriginAttributes,
101
    const nsString& aScope,
102
    const nsString& aTag,
103
    const bool& aLastChance)
104
{
105
  if (mShuttingDown) {
106
    return true;
107
  }
108
109
  RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
110
  MOZ_ASSERT(swm);
111
112
  swm->SendSyncEvent(NS_ConvertUTF16toUTF8(aOriginAttributes),
113
                     NS_ConvertUTF16toUTF8(aScope),
114
                     aTag, aLastChance);
115
  return true;
116
}
117
98
} // namespace workers
118
} // namespace workers
99
} // namespace dom
119
} // namespace dom
100
} // namespace mozilla
120
} // namespace mozilla
(-)a/dom/workers/ServiceWorkerManagerChild.h (+5 lines)
Line     Link Here 
 Lines 41-56   public: Link Here 
41
41
42
  virtual bool RecvNotifyUnregister(const PrincipalInfo& aPrincipalInfo,
42
  virtual bool RecvNotifyUnregister(const PrincipalInfo& aPrincipalInfo,
43
                                    const nsString& aScope) override;
43
                                    const nsString& aScope) override;
44
44
45
  virtual bool RecvNotifyRemove(const nsCString& aHost) override;
45
  virtual bool RecvNotifyRemove(const nsCString& aHost) override;
46
46
47
  virtual bool RecvNotifyRemoveAll() override;
47
  virtual bool RecvNotifyRemoveAll() override;
48
48
49
  virtual bool RecvSendSyncEvent(const nsString& aOriginAttributes,
50
                                 const nsString& aScope,
51
                                 const nsString& aTag,
52
                                 const bool& aLastChance) override;
53
49
private:
54
private:
50
  ServiceWorkerManagerChild()
55
  ServiceWorkerManagerChild()
51
    : mShuttingDown(false)
56
    : mShuttingDown(false)
52
  {}
57
  {}
53
58
54
  ~ServiceWorkerManagerChild() {}
59
  ~ServiceWorkerManagerChild() {}
55
60
56
  bool mShuttingDown;
61
  bool mShuttingDown;
(-)a/dom/workers/ServiceWorkerPrivate.cpp (-7 / +95 lines)
Line     Link Here 
 Lines 56-72   private: Link Here 
56
56
57
  RefPtr<ServiceWorkerPrivate> mPrivate;
57
  RefPtr<ServiceWorkerPrivate> mPrivate;
58
};
58
};
59
59
60
NS_IMPL_ISUPPORTS0(KeepAliveToken)
60
NS_IMPL_ISUPPORTS0(KeepAliveToken)
61
61
62
ServiceWorkerPrivate::ServiceWorkerPrivate(ServiceWorkerInfo* aInfo)
62
ServiceWorkerPrivate::ServiceWorkerPrivate(ServiceWorkerInfo* aInfo)
63
  : mInfo(aInfo)
63
  : mInfo(aInfo)
64
  , mIsPushWorker(false)
64
  , mIsPushOrSyncWorker(false)
65
  , mDebuggerCount(0)
65
  , mDebuggerCount(0)
66
  , mTokenCount(0)
66
  , mTokenCount(0)
67
{
67
{
68
  AssertIsOnMainThread();
68
  AssertIsOnMainThread();
69
  MOZ_ASSERT(aInfo);
69
  MOZ_ASSERT(aInfo);
70
70
71
  mIdleWorkerTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
71
  mIdleWorkerTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
72
  MOZ_ASSERT(mIdleWorkerTimer);
72
  MOZ_ASSERT(mIdleWorkerTimer);
 Lines 478-495   public: Link Here 
478
  {
478
  {
479
    MOZ_ASSERT(GetCurrentThreadWorkerPrivate() == mWorkerPrivate);
479
    MOZ_ASSERT(GetCurrentThreadWorkerPrivate() == mWorkerPrivate);
480
    mWorkerPrivate->AssertIsOnWorkerThread();
480
    mWorkerPrivate->AssertIsOnWorkerThread();
481
481
482
    ReportResult(aCx, false);
482
    ReportResult(aCx, false);
483
483
484
    // Note, all WaitUntil() rejections are reported to client consoles
484
    // Note, all WaitUntil() rejections are reported to client consoles
485
    // by the WaitUntilHandler in ServiceWorkerEvents.  This ensures that
485
    // by the WaitUntilHandler in ServiceWorkerEvents.  This ensures that
486
    // errors in non-lifecycle events like FetchEvent and PushEvent are
486
    // errors in non-lifecycle events like FetchEvent, PushEvent or SyncEvent
487
    // reported properly.
487
    // are reported properly.
488
  }
488
  }
489
};
489
};
490
490
491
NS_IMPL_ISUPPORTS0(LifeCycleEventWatcher)
491
NS_IMPL_ISUPPORTS0(LifeCycleEventWatcher)
492
492
493
bool
493
bool
494
LifecycleEventWorkerRunnable::DispatchLifecycleEvent(JSContext* aCx,
494
LifecycleEventWorkerRunnable::DispatchLifecycleEvent(JSContext* aCx,
495
                                                     WorkerPrivate* aWorkerPrivate)
495
                                                     WorkerPrivate* aWorkerPrivate)
 Lines 1357-1372   ServiceWorkerPrivate::SendFetchEvent(nsI Link Here 
1357
  jsapi.Init();
1357
  jsapi.Init();
1358
  if (NS_WARN_IF(!r->Dispatch(jsapi.cx()))) {
1358
  if (NS_WARN_IF(!r->Dispatch(jsapi.cx()))) {
1359
    return NS_ERROR_FAILURE;
1359
    return NS_ERROR_FAILURE;
1360
  }
1360
  }
1361
1361
1362
  return NS_OK;
1362
  return NS_OK;
1363
}
1363
}
1364
1364
1365
namespace {
1366
class SendSyncEventRunnable final : public ExtendableFunctionalEventWorkerRunnable
1367
{
1368
  nsString mTag;
1369
  bool mLastChance;
1370
1371
public:
1372
  SendSyncEventRunnable(WorkerPrivate* aWorkerPrivate,
1373
                        KeepAliveToken* aKeepAliveToken,
1374
                        const nsAString& aTag,
1375
                        const bool aLastChance,
1376
                        nsMainThreadPtrHandle<ServiceWorkerRegistrationInfo> aRegistration)
1377
    : ExtendableFunctionalEventWorkerRunnable(
1378
        aWorkerPrivate, aKeepAliveToken, aRegistration)
1379
    , mTag(aTag)
1380
    , mLastChance(aLastChance)
1381
  {
1382
    AssertIsOnMainThread();
1383
    MOZ_ASSERT(aWorkerPrivate);
1384
    MOZ_ASSERT(aWorkerPrivate->IsServiceWorker());
1385
  }
1386
1387
  bool
1388
  WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override
1389
  {
1390
    MOZ_ASSERT(aWorkerPrivate);
1391
    GlobalObject globalObj(aCx, aWorkerPrivate->GlobalScope()->GetWrapper());
1392
1393
    SyncEventInit sei;
1394
    sei.mTag = mTag;
1395
    sei.mLastChance = mLastChance;
1396
    sei.mBubbles = false;
1397
    sei.mCancelable = false;
1398
1399
    ErrorResult result;
1400
    RefPtr<SyncEvent> event =
1401
      SyncEvent::Constructor(globalObj, NS_LITERAL_STRING("sync"), sei, result);
1402
    if (NS_WARN_IF(result.Failed())) {
1403
      result.SuppressException();
1404
      return false;
1405
    }
1406
    event->SetTrusted(true);
1407
1408
    DispatchExtendableEventOnWorkerScope(aCx, aWorkerPrivate->GlobalScope(),
1409
                                         event, nullptr);
1410
1411
    return true;
1412
  }
1413
};
1414
} // anonymous namespace
1415
1416
nsresult
1417
ServiceWorkerPrivate::SendSyncEvent(const nsAString& aTag,
1418
                                    const bool aLastChance,
1419
                                    ServiceWorkerRegistrationInfo* aRegistration)
1420
{
1421
  nsresult rv = SpawnWorkerIfNeeded(SyncEvent, nullptr);
1422
  NS_ENSURE_SUCCESS(rv, rv);
1423
1424
  MOZ_ASSERT(mKeepAliveToken);
1425
1426
  nsMainThreadPtrHandle<ServiceWorkerRegistrationInfo> regInfo(
1427
      new nsMainThreadPtrHolder<ServiceWorkerRegistrationInfo>(aRegistration, false));
1428
1429
1430
  RefPtr<WorkerRunnable> runnable = new SendSyncEventRunnable(mWorkerPrivate,
1431
                                                              mKeepAliveToken,
1432
                                                              aTag,
1433
                                                              aLastChance,
1434
                                                              regInfo);
1435
1436
  if (mInfo->State() == ServiceWorkerState::Activating) {
1437
    mPendingFunctionalEvents.AppendElement(runnable.forget());
1438
    return NS_OK;
1439
  }
1440
1441
  MOZ_ASSERT(mInfo->State() == ServiceWorkerState::Activated);
1442
1443
  AutoJSAPI jsapi;
1444
  jsapi.Init();
1445
  if (NS_WARN_IF(!runnable->Dispatch(jsapi.cx()))) {
1446
    return NS_ERROR_FAILURE;
1447
  }
1448
1449
  return NS_OK;
1450
}
1451
1365
nsresult
1452
nsresult
1366
ServiceWorkerPrivate::SpawnWorkerIfNeeded(WakeUpReason aWhy,
1453
ServiceWorkerPrivate::SpawnWorkerIfNeeded(WakeUpReason aWhy,
1367
                                          nsIRunnable* aLoadFailedRunnable,
1454
                                          nsIRunnable* aLoadFailedRunnable,
1368
                                          nsILoadGroup* aLoadGroup)
1455
                                          nsILoadGroup* aLoadGroup)
1369
{
1456
{
1370
  AssertIsOnMainThread();
1457
  AssertIsOnMainThread();
1371
1458
1372
  // XXXcatalinb: We need to have a separate load group that's linked to
1459
  // XXXcatalinb: We need to have a separate load group that's linked to
 Lines 1451-1467   ServiceWorkerPrivate::SpawnWorkerIfNeede Link Here 
1451
  mWorkerPrivate = WorkerPrivate::Constructor(jsapi.cx(),
1538
  mWorkerPrivate = WorkerPrivate::Constructor(jsapi.cx(),
1452
                                              scriptSpec,
1539
                                              scriptSpec,
1453
                                              false, WorkerTypeService,
1540
                                              false, WorkerTypeService,
1454
                                              mInfo->Scope(), &info, error);
1541
                                              mInfo->Scope(), &info, error);
1455
  if (NS_WARN_IF(error.Failed())) {
1542
  if (NS_WARN_IF(error.Failed())) {
1456
    return error.StealNSResult();
1543
    return error.StealNSResult();
1457
  }
1544
  }
1458
1545
1459
  mIsPushWorker = false;
1546
  mIsPushOrSyncWorker = false;
1460
  RenewKeepAliveToken(aWhy);
1547
  RenewKeepAliveToken(aWhy);
1461
1548
1462
  return NS_OK;
1549
  return NS_OK;
1463
}
1550
}
1464
1551
1465
void
1552
void
1466
ServiceWorkerPrivate::StoreISupports(nsISupports* aSupports)
1553
ServiceWorkerPrivate::StoreISupports(nsISupports* aSupports)
1467
{
1554
{
 Lines 1518-1534   ServiceWorkerPrivate::NoteDeadServiceWor Link Here 
1518
  mInfo = nullptr;
1605
  mInfo = nullptr;
1519
  TerminateWorker();
1606
  TerminateWorker();
1520
}
1607
}
1521
1608
1522
void
1609
void
1523
ServiceWorkerPrivate::NoteStoppedControllingDocuments()
1610
ServiceWorkerPrivate::NoteStoppedControllingDocuments()
1524
{
1611
{
1525
  AssertIsOnMainThread();
1612
  AssertIsOnMainThread();
1526
  if (mIsPushWorker || mDebuggerCount) {
1613
  if (mIsPushOrSyncWorker || mDebuggerCount) {
1527
    return;
1614
    return;
1528
  }
1615
  }
1529
1616
1530
  TerminateWorker();
1617
  TerminateWorker();
1531
}
1618
}
1532
1619
1533
void
1620
void
1534
ServiceWorkerPrivate::Activated()
1621
ServiceWorkerPrivate::Activated()
 Lines 1658-1675   ServiceWorkerPrivate::TerminateWorkerCal Link Here 
1658
}
1745
}
1659
1746
1660
void
1747
void
1661
ServiceWorkerPrivate::RenewKeepAliveToken(WakeUpReason aWhy)
1748
ServiceWorkerPrivate::RenewKeepAliveToken(WakeUpReason aWhy)
1662
{
1749
{
1663
  // We should have an active worker if we're renewing the keep alive token.
1750
  // We should have an active worker if we're renewing the keep alive token.
1664
  MOZ_ASSERT(mWorkerPrivate);
1751
  MOZ_ASSERT(mWorkerPrivate);
1665
1752
1666
  if (aWhy == PushEvent || aWhy == PushSubscriptionChangeEvent) {
1753
  if (aWhy == PushEvent || aWhy == PushSubscriptionChangeEvent ||
1667
    mIsPushWorker = true;
1754
      aWhy == SyncEvent) {
1755
    mIsPushOrSyncWorker = true;
1668
  }
1756
  }
1669
1757
1670
  // If there is at least one debugger attached to the worker, the idle worker
1758
  // If there is at least one debugger attached to the worker, the idle worker
1671
  // timeout was canceled when the first debugger attached to the worker. It
1759
  // timeout was canceled when the first debugger attached to the worker. It
1672
  // should not be reset until the last debugger detaches from the worker.
1760
  // should not be reset until the last debugger detaches from the worker.
1673
  if (!mDebuggerCount) {
1761
  if (!mDebuggerCount) {
1674
    ResetIdleTimeout();
1762
    ResetIdleTimeout();
1675
  }
1763
  }
(-)a/dom/workers/ServiceWorkerPrivate.h (-5 / +11 lines)
Line     Link Here 
 Lines 101-116   public: Link Here 
101
                             const nsAString& aScope);
101
                             const nsAString& aScope);
102
102
103
  nsresult
103
  nsresult
104
  SendFetchEvent(nsIInterceptedChannel* aChannel,
104
  SendFetchEvent(nsIInterceptedChannel* aChannel,
105
                 nsILoadGroup* aLoadGroup,
105
                 nsILoadGroup* aLoadGroup,
106
                 const nsAString& aDocumentId,
106
                 const nsAString& aDocumentId,
107
                 bool aIsReload);
107
                 bool aIsReload);
108
108
109
  nsresult
110
  SendSyncEvent(const nsAString& aTag,
111
                const bool aLastChance,
112
                ServiceWorkerRegistrationInfo* aRegistration);
113
109
  void
114
  void
110
  StoreISupports(nsISupports* aSupports);
115
  StoreISupports(nsISupports* aSupports);
111
116
112
  void
117
  void
113
  RemoveISupports(nsISupports* aSupports);
118
  RemoveISupports(nsISupports* aSupports);
114
119
115
  // This will terminate the current running worker thread and drop the
120
  // This will terminate the current running worker thread and drop the
116
  // workerPrivate reference.
121
  // workerPrivate reference.
 Lines 141-157   public: Link Here 
141
private:
146
private:
142
  enum WakeUpReason {
147
  enum WakeUpReason {
143
    FetchEvent = 0,
148
    FetchEvent = 0,
144
    PushEvent,
149
    PushEvent,
145
    PushSubscriptionChangeEvent,
150
    PushSubscriptionChangeEvent,
146
    MessageEvent,
151
    MessageEvent,
147
    NotificationClickEvent,
152
    NotificationClickEvent,
148
    LifeCycleEvent,
153
    LifeCycleEvent,
149
    AttachEvent
154
    AttachEvent,
155
    SyncEvent
150
  };
156
  };
151
157
152
  // Timer callbacks
158
  // Timer callbacks
153
  static void
159
  static void
154
  NoteIdleWorkerCallback(nsITimer* aTimer, void* aPrivate);
160
  NoteIdleWorkerCallback(nsITimer* aTimer, void* aPrivate);
155
161
156
  static void
162
  static void
157
  TerminateWorkerCallback(nsITimer* aTimer, void *aPrivate);
163
  TerminateWorkerCallback(nsITimer* aTimer, void *aPrivate);
 Lines 184-203   private: Link Here 
184
190
185
  // The WorkerPrivate object can only be closed by this class or by the
191
  // The WorkerPrivate object can only be closed by this class or by the
186
  // RuntimeService class if gecko is shutting down. Closing the worker
192
  // RuntimeService class if gecko is shutting down. Closing the worker
187
  // multiple times is OK, since the second attempt will be a no-op.
193
  // multiple times is OK, since the second attempt will be a no-op.
188
  RefPtr<WorkerPrivate> mWorkerPrivate;
194
  RefPtr<WorkerPrivate> mWorkerPrivate;
189
195
190
  nsCOMPtr<nsITimer> mIdleWorkerTimer;
196
  nsCOMPtr<nsITimer> mIdleWorkerTimer;
191
197
192
  // We keep track if this worker received any push events since it was last
198
  // We keep track if this worker received any push or sync events since it
193
  // woken up. The flag is reset to false every time a new WorkerPrivate
199
  // was last woken up. The flag is reset to false every time a new
194
  // is created.
200
  // WorkerPrivate is created.
195
  bool mIsPushWorker;
201
  bool mIsPushOrSyncWorker;
196
202
197
  // We keep a token for |dom.serviceWorkers.idle_timeout| seconds to give the
203
  // We keep a token for |dom.serviceWorkers.idle_timeout| seconds to give the
198
  // worker a grace period after each event.
204
  // worker a grace period after each event.
199
  RefPtr<KeepAliveToken> mKeepAliveToken;
205
  RefPtr<KeepAliveToken> mKeepAliveToken;
200
206
201
  uint64_t mDebuggerCount;
207
  uint64_t mDebuggerCount;
202
208
203
  uint64_t mTokenCount;
209
  uint64_t mTokenCount;
(-)a/dom/workers/ServiceWorkerRegistration.cpp (-2 / +3 lines)
Line     Link Here 
 Lines 837-853   ServiceWorkerRegistrationMainThread::Get Link Here 
837
837
838
    nsCOMPtr<nsIPrincipal> principal = document->NodePrincipal();
838
    nsCOMPtr<nsIPrincipal> principal = document->NodePrincipal();
839
    if (!principal) {
839
    if (!principal) {
840
      aRv.Throw(NS_ERROR_FAILURE);
840
      aRv.Throw(NS_ERROR_FAILURE);
841
      return nullptr;
841
      return nullptr;
842
    }
842
    }
843
843
844
    mSyncManager = SyncManager::CreateOnMainThread(globalObject, principal,
844
    mSyncManager = SyncManager::CreateOnMainThread(globalObject, principal,
845
                                                   aRv);
845
                                                   mScope, aRv);
846
  }
846
  }
847
847
848
  return mSyncManager;
848
  return mSyncManager;
849
}
849
}
850
850
851
////////////////////////////////////////////////////
851
////////////////////////////////////////////////////
852
// Worker Thread implementation
852
// Worker Thread implementation
853
class WorkerListener final : public ServiceWorkerRegistrationListener
853
class WorkerListener final : public ServiceWorkerRegistrationListener
 Lines 1291-1306   ServiceWorkerRegistrationWorkerThread::G Link Here 
1291
  #endif /* ! MOZ_SIMPLEPUSH */
1291
  #endif /* ! MOZ_SIMPLEPUSH */
1292
}
1292
}
1293
1293
1294
SyncManager*
1294
SyncManager*
1295
ServiceWorkerRegistrationWorkerThread::GetSync(ErrorResult& aRv)
1295
ServiceWorkerRegistrationWorkerThread::GetSync(ErrorResult& aRv)
1296
{
1296
{
1297
  if (!mSyncManager) {
1297
  if (!mSyncManager) {
1298
    mSyncManager = SyncManager::CreateOnWorker(mWorkerPrivate->GlobalScope(),
1298
    mSyncManager = SyncManager::CreateOnWorker(mWorkerPrivate->GlobalScope(),
1299
                                               mWorkerPrivate);
1299
                                               mWorkerPrivate,
1300
                                               mScope);
1300
  }
1301
  }
1301
1302
1302
  return mSyncManager;
1303
  return mSyncManager;
1303
}
1304
}
1304
1305
1305
} // dom namespace
1306
} // dom namespace
1306
} // mozilla namespace
1307
} // mozilla namespace

Return to bug 1217544