Attachment #8832153: Part 4.1 (interdiff): Sync event for bug #1217544

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

(-)a/dom/webidl/BackgroundSyncEvent.webidl (-1 / +2 lines)
Line     Link Here 
 Lines 3-19    Link Here 
3
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
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/.
4
 * You can obtain one at http://mozilla.org/MPL/2.0/.
5
 *
5
 *
6
 * The origin of this IDL file is
6
 * The origin of this IDL file is
7
 * https://wicg.github.io/BackgroundSync/spec/
7
 * https://wicg.github.io/BackgroundSync/spec/
8
 */
8
 */
9
9
10
[Constructor(DOMString type, optional BackgroundSyncEventInit eventInitDict),
10
[Constructor(DOMString type, optional BackgroundSyncEventInit eventInitDict),
11
 Exposed=ServiceWorker]
11
 Exposed=ServiceWorker,
12
 Func="mozilla::dom::backgroundsync::BackgroundSync::PrefEnabled"]
12
interface BackgroundSyncEvent : ExtendableEvent {
13
interface BackgroundSyncEvent : ExtendableEvent {
13
  readonly attribute DOMString tag;
14
  readonly attribute DOMString tag;
14
  readonly attribute boolean lastChance;
15
  readonly attribute boolean lastChance;
15
};
16
};
16
17
17
dictionary BackgroundSyncEventInit : ExtendableEventInit {
18
dictionary BackgroundSyncEventInit : ExtendableEventInit {
18
  required DOMString tag;
19
  required DOMString tag;
19
  boolean lastChance = false;
20
  boolean lastChance = false;
(-)a/dom/workers/ServiceWorkerManager.cpp (-3 / +4 lines)
Line     Link Here 
 Lines 1103-1125   ServiceWorkerManager::SendNotificationCl Link Here 
1103
                                                 const nsAString& aBehavior)
1103
                                                 const nsAString& aBehavior)
1104
{
1104
{
1105
  return SendNotificationEvent(NS_LITERAL_STRING(NOTIFICATION_CLOSE_EVENT_NAME),
1105
  return SendNotificationEvent(NS_LITERAL_STRING(NOTIFICATION_CLOSE_EVENT_NAME),
1106
                               aOriginSuffix, aScope, aID, aTitle, aDir, aLang,
1106
                               aOriginSuffix, aScope, aID, aTitle, aDir, aLang,
1107
                               aBody, aTag, aIcon, aData, aBehavior);
1107
                               aBody, aTag, aIcon, aData, aBehavior);
1108
}
1108
}
1109
1109
1110
NS_IMETHODIMP
1110
NS_IMETHODIMP
1111
ServiceWorkerManager::SendBackgroundSyncEvent(const nsACString& aOriginAttributes,
1111
ServiceWorkerManager::SendBackgroundSyncEvent(const nsACString& aOrigin,
1112
                                              const nsACString& aScope,
1112
                                              const nsACString& aScope,
1113
                                              const nsAString& aTag,
1113
                                              const nsAString& aTag,
1114
                                              const bool aLastChance)
1114
                                              const bool aLastChance)
1115
{
1115
{
1116
  PrincipalOriginAttributes attrs;
1116
  nsAutoCString originNoSuffix;
1117
  if (!attrs.PopulateFromSuffix(aOriginAttributes)) {
1117
  OriginAttributes attrs;
1118
  if (!attrs.PopulateFromOrigin(aOrigin, originNoSuffix)) {
1118
    return NS_ERROR_INVALID_ARG;
1119
    return NS_ERROR_INVALID_ARG;
1119
  }
1120
  }
1120
1121
1121
  ServiceWorkerInfo* serviceWorker =
1122
  ServiceWorkerInfo* serviceWorker =
1122
    GetActiveWorkerInfoForScope(attrs, aScope);
1123
    GetActiveWorkerInfoForScope(attrs, aScope);
1123
  if (NS_WARN_IF(!serviceWorker)) {
1124
  if (NS_WARN_IF(!serviceWorker)) {
1124
    return NS_ERROR_FAILURE;
1125
    return NS_ERROR_FAILURE;
1125
  }
1126
  }
(-)a/dom/workers/ServiceWorkerManagerChild.cpp (-5 / +5 lines)
Line     Link Here 
 Lines 97-136   ServiceWorkerManagerChild::RecvNotifyRem Link Here 
97
  RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
97
  RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
98
  if (swm) {
98
  if (swm) {
99
    swm->RemoveAll();
99
    swm->RemoveAll();
100
  }
100
  }
101
101
102
  return IPC_OK();
102
  return IPC_OK();
103
}
103
}
104
104
105
bool
105
mozilla::ipc::IPCResult
106
ServiceWorkerManagerChild::RecvNotifyBackgroundSyncEvent(
106
ServiceWorkerManagerChild::RecvNotifyBackgroundSyncEvent(
107
    const PrincipalInfo& aPrincipalInfo, const nsString& aScope,
107
    const PrincipalInfo& aPrincipalInfo, const nsString& aScope,
108
    const nsString& aTag, const bool& aLastChance)
108
    const nsString& aTag, const bool& aLastChance)
109
{
109
{
110
  if (mShuttingDown) {
110
  if (mShuttingDown) {
111
    return true;
111
    return IPC_OK();
112
  }
112
  }
113
113
114
  nsCOMPtr<nsIPrincipal> principal = PrincipalInfoToPrincipal(aPrincipalInfo);
114
  nsCOMPtr<nsIPrincipal> principal = PrincipalInfoToPrincipal(aPrincipalInfo);
115
  if (NS_WARN_IF(!principal)) {
115
  if (NS_WARN_IF(!principal)) {
116
    return true;
116
    return IPC_OK();
117
  }
117
  }
118
118
119
  nsAutoCString originSuffix;
119
  nsAutoCString originSuffix;
120
  nsresult rv = principal->GetOriginSuffix(originSuffix);
120
  nsresult rv = principal->GetOriginSuffix(originSuffix);
121
  if (NS_WARN_IF(NS_FAILED(rv))) {
121
  if (NS_WARN_IF(NS_FAILED(rv))) {
122
    return true;
122
    return IPC_OK();
123
  }
123
  }
124
124
125
  RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
125
  RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
126
  MOZ_ASSERT(swm);
126
  MOZ_ASSERT(swm);
127
127
128
  swm->SendBackgroundSyncEvent(originSuffix,
128
  swm->SendBackgroundSyncEvent(originSuffix,
129
                               NS_ConvertUTF16toUTF8(aScope),
129
                               NS_ConvertUTF16toUTF8(aScope),
130
                               aTag, aLastChance);
130
                               aTag, aLastChance);
131
  return true;
131
  return IPC_OK();
132
}
132
}
133
133
134
} // namespace workers
134
} // namespace workers
135
} // namespace dom
135
} // namespace dom
136
} // namespace mozilla
136
} // namespace mozilla
(-)a/dom/workers/ServiceWorkerManagerChild.h (-4 / +4 lines)
Line     Link Here 
 Lines 41-60   public: Link Here 
41
41
42
  virtual mozilla::ipc::IPCResult RecvNotifyUnregister(const PrincipalInfo& aPrincipalInfo,
42
  virtual mozilla::ipc::IPCResult RecvNotifyUnregister(const PrincipalInfo& aPrincipalInfo,
43
                                                       const nsString& aScope) override;
43
                                                       const nsString& aScope) override;
44
44
45
  virtual mozilla::ipc::IPCResult RecvNotifyRemove(const nsCString& aHost) override;
45
  virtual mozilla::ipc::IPCResult RecvNotifyRemove(const nsCString& aHost) override;
46
46
47
  virtual mozilla::ipc::IPCResult RecvNotifyRemoveAll() override;
47
  virtual mozilla::ipc::IPCResult RecvNotifyRemoveAll() override;
48
48
49
  virtual bool RecvNotifyBackgroundSyncEvent(const PrincipalInfo& aPrincipalInfo,
49
  virtual mozilla::ipc::IPCResult RecvNotifyBackgroundSyncEvent(const PrincipalInfo& aPrincipalInfo,
50
                                             const nsString& aScope,
50
                                                                const nsString& aScope,
51
                                             const nsString& aTag,
51
                                                                const nsString& aTag,
52
                                             const bool& aLastChance) override;
52
                                                                const bool& aLastChance) override;
53
53
54
private:
54
private:
55
  ServiceWorkerManagerChild()
55
  ServiceWorkerManagerChild()
56
    : mShuttingDown(false)
56
    : mShuttingDown(false)
57
  {}
57
  {}
58
58
59
  ~ServiceWorkerManagerChild() {}
59
  ~ServiceWorkerManagerChild() {}
60
60

Return to bug 1217544