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
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6#include "domstubs.idl"
7#include "nsIRequest.idl"
8
9interface mozIDOMWindow;
10interface nsPIDOMWindowInner;
11interface mozIDOMWindowProxy;
12interface nsIArray;
13interface nsIInterceptedChannel;
14interface nsIPrincipal;
15interface nsIRunnable;
16interface nsIURI;
17%{C++
18namespace mozilla {
19namespace dom {
20class ClientInfo;
21class ServiceWorkerDescriptor;
22} // namespace dom
23} // namespace mozilla
24%}
25
26[ref] native const_ClientInfoRef(const mozilla::dom::ClientInfo);
27[ref] native const_ServiceWorkerDescriptorRef(const mozilla::dom::ServiceWorkerDescriptor);
28
29[scriptable, uuid(52ee2c9d-ee87-4caf-9588-23ae77ff8798)]
30interface nsIServiceWorkerUnregisterCallback : nsISupports
31{
32  // aState is true if the unregistration succeded.
33  // It's false if this ServiceWorkerRegistration doesn't exist.
34  void unregisterSucceeded(in bool aState);
35  void unregisterFailed();
36};
37
38interface nsIWorkerDebugger;
39
40[scriptable, builtinclass, uuid(76e357ed-208d-4e4c-9165-1c4059707879)]
41interface nsIServiceWorkerInfo : nsISupports
42{
43  // State values below should match the ServiceWorkerState enumeration.
44  const unsigned short STATE_PARSED = 0;
45  const unsigned short STATE_INSTALLING = 1;
46  const unsigned short STATE_INSTALLED = 2;
47  const unsigned short STATE_ACTIVATING = 3;
48  const unsigned short STATE_ACTIVATED = 4;
49  const unsigned short STATE_REDUNDANT = 5;
50  const unsigned short STATE_UNKNOWN = 6;
51
52  readonly attribute AString id;
53
54  readonly attribute AString scriptSpec;
55  readonly attribute AString cacheName;
56
57  readonly attribute unsigned short state;
58
59  readonly attribute nsIWorkerDebugger debugger;
60
61  // Return whether the ServiceWorker has a "fetch" event listener. Throws if
62  // this is unknown because the worker's main script hasn't finished executing
63  // (when exposed as evaluatingWorker).
64  readonly attribute bool handlesFetchEvents;
65
66  readonly attribute PRTime installedTime;
67  readonly attribute PRTime activatedTime;
68  readonly attribute PRTime redundantTime;
69
70  void attachDebugger();
71
72  void detachDebugger();
73};
74
75[scriptable, uuid(87e63548-d440-4b8a-b158-65ad1de0211E)]
76interface nsIServiceWorkerRegistrationInfoListener : nsISupports
77{
78  void onChange();
79};
80
81[scriptable, builtinclass, uuid(ddbc1fd4-2f2e-4fca-a395-6e010bbedfe3)]
82interface nsIServiceWorkerRegistrationInfo : nsISupports
83{
84  // State values below should match the ServiceWorkerUpdateViaCache enumeration.
85  const unsigned short UPDATE_VIA_CACHE_IMPORTS = 0;
86  const unsigned short UPDATE_VIA_CACHE_ALL = 1;
87  const unsigned short UPDATE_VIA_CACHE_NONE = 2;
88
89  readonly attribute nsIPrincipal principal;
90
91  readonly attribute AString scope;
92  readonly attribute AString scriptSpec;
93  readonly attribute unsigned short updateViaCache;
94
95  readonly attribute PRTime lastUpdateTime;
96
97  readonly attribute nsIServiceWorkerInfo evaluatingWorker;
98  readonly attribute nsIServiceWorkerInfo installingWorker;
99  readonly attribute nsIServiceWorkerInfo waitingWorker;
100  readonly attribute nsIServiceWorkerInfo activeWorker;
101
102  // Allows to get the related nsIServiceWorkerInfo for a given
103  // nsIWorkerDebugger. Over time we shouldn't need this anymore,
104  // and instead always control then nsIWorkerDebugger from
105  // nsIServiceWorkerInfo and not the other way around.  Returns
106  // null if the service worker is no longer registered.
107  nsIServiceWorkerInfo getWorkerByID(in unsigned long long aID);
108
109  void addListener(in nsIServiceWorkerRegistrationInfoListener listener);
110
111  void removeListener(in nsIServiceWorkerRegistrationInfoListener listener);
112};
113
114[scriptable, uuid(9e523e7c-ad6f-4df0-8077-c74aebbc679d)]
115interface nsIServiceWorkerManagerListener : nsISupports
116{
117  void onRegister(in nsIServiceWorkerRegistrationInfo aInfo);
118
119  void onUnregister(in nsIServiceWorkerRegistrationInfo aInfo);
120};
121
122[scriptable, builtinclass, uuid(7404c8e8-4d47-4449-8ed1-47d1261d4e33)]
123interface nsIServiceWorkerManager : nsISupports
124{
125  /**
126   * Unregister an existing ServiceWorker registration for `aScope`.
127   * It keeps aCallback alive until the operation is concluded.
128   */
129  void unregister(in nsIPrincipal aPrincipal,
130                  in nsIServiceWorkerUnregisterCallback aCallback,
131                  in AString aScope);
132
133  nsIServiceWorkerRegistrationInfo getRegistrationByPrincipal(in nsIPrincipal aPrincipal,
134                                                              in AString aScope);
135
136  [notxpcom, nostdcall] bool StartControlling(in const_ClientInfoRef aClientInfo,
137                                              in const_ServiceWorkerDescriptorRef aServiceWorker);
138
139  // Testing
140  AString getScopeForUrl(in nsIPrincipal aPrincipal, in AString aPath);
141
142  // It returns an array of nsIServiceWorkerRegistrationInfos.
143  nsIArray getAllRegistrations();
144
145  // For clear-origin-attributes-data
146  void removeRegistrationsByOriginAttributes(in AString aOriginAttributes);
147
148  // It calls softUpdate() for each child process.
149  [implicit_jscontext] void propagateSoftUpdate(in jsval aOriginAttributes,
150                                                in AString aScope);
151
152  // It calls unregister() in each child process. The callback is used to
153  // inform when unregister() is completed on the current process.
154  void propagateUnregister(in nsIPrincipal aPrincipal,
155                           in nsIServiceWorkerUnregisterCallback aCallback,
156                           in AString aScope);
157
158  void sendNotificationClickEvent(in ACString aOriginSuffix,
159                                  in ACString scope,
160                                  in AString aID,
161                                  in AString aTitle,
162                                  in AString aDir,
163                                  in AString aLang,
164                                  in AString aBody,
165                                  in AString aTag,
166                                  in AString aIcon,
167                                  in AString aData,
168                                  in AString aBehavior);
169
170  void sendNotificationCloseEvent(in ACString aOriginSuffix,
171                                  in ACString scope,
172                                  in AString aID,
173                                  in AString aTitle,
174                                  in AString aDir,
175                                  in AString aLang,
176                                  in AString aBody,
177                                  in AString aTag,
178                                  in AString aIcon,
179                                  in AString aData,
180                                  in AString aBehavior);
181
182  [optional_argc] void sendPushEvent(in ACString aOriginAttributes,
183                                     in ACString aScope,
184                                     [optional] in Array<uint8_t> aDataBytes);
185  void sendPushSubscriptionChangeEvent(in ACString aOriginAttributes,
186                                       in ACString scope);
187
188  void addListener(in nsIServiceWorkerManagerListener aListener);
189
190  void removeListener(in nsIServiceWorkerManagerListener aListener);
191
192  bool isParentInterceptEnabled();
193};
194
195%{ C++
196#define SERVICEWORKERMANAGER_CONTRACTID "@mozilla.org/serviceworkers/manager;1"
197%}
198