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 71 // Total number of navigation faults experienced by this ServiceWorker since 72 // it was loaded from disk at startup or was installed. 73 readonly attribute unsigned long navigationFaultCount; 74 75 // Testing mechanism to induce synthetic failure of fetch events. If set to 76 // something other than NS_OK, all fetch events dispatched will be propagated 77 // to the content process, but when it comes time to dispatch the fetch event, 78 // the cancellation control flow path will be triggered. 79 attribute nsresult testingInjectCancellation; 80 81 82 void attachDebugger(); 83 84 void detachDebugger(); 85}; 86 87[scriptable, uuid(87e63548-d440-4b8a-b158-65ad1de0211E)] 88interface nsIServiceWorkerRegistrationInfoListener : nsISupports 89{ 90 void onChange(); 91}; 92 93[scriptable, builtinclass, uuid(ddbc1fd4-2f2e-4fca-a395-6e010bbedfe3)] 94interface nsIServiceWorkerRegistrationInfo : nsISupports 95{ 96 // State values below should match the ServiceWorkerUpdateViaCache enumeration. 97 const unsigned short UPDATE_VIA_CACHE_IMPORTS = 0; 98 const unsigned short UPDATE_VIA_CACHE_ALL = 1; 99 const unsigned short UPDATE_VIA_CACHE_NONE = 2; 100 101 readonly attribute nsIPrincipal principal; 102 readonly attribute boolean unregistered; 103 104 readonly attribute AString scope; 105 readonly attribute AString scriptSpec; 106 readonly attribute unsigned short updateViaCache; 107 108 readonly attribute PRTime lastUpdateTime; 109 110 readonly attribute nsIServiceWorkerInfo evaluatingWorker; 111 readonly attribute nsIServiceWorkerInfo installingWorker; 112 readonly attribute nsIServiceWorkerInfo waitingWorker; 113 readonly attribute nsIServiceWorkerInfo activeWorker; 114 115 // Exposes the number of times we have ever checked the usage of this origin 116 // for the purposes of mitigating ServiceWorker navigation faults that we 117 // suspect to be due to quota limit problems. This should start out 0 and 118 // max out at 1 for the time being. 119 // 120 // Note that the underlying value is tracked on our per-Principal data, but 121 // we don't currently expose that data directly via XPCOM so we're exposing 122 // this here as the next best thing and because most non-test consumers would 123 // work in terms of the registration anyways. 124 // 125 // This will return -1 if there is no longer any per-origin data because the 126 // last registration for the origin (principal) has been unregistered. 127 // (Retaining a reference to this interface does not impact anything the 128 // underlying scope-to-registration map that is implemented per spec.) 129 readonly attribute long quotaUsageCheckCount; 130 131 // Allows to get the related nsIServiceWorkerInfo for a given 132 // nsIWorkerDebugger. Over time we shouldn't need this anymore, 133 // and instead always control then nsIWorkerDebugger from 134 // nsIServiceWorkerInfo and not the other way around. Returns 135 // null if the service worker is no longer registered. 136 nsIServiceWorkerInfo getWorkerByID(in unsigned long long aID); 137 138 void addListener(in nsIServiceWorkerRegistrationInfoListener listener); 139 140 void removeListener(in nsIServiceWorkerRegistrationInfoListener listener); 141 142 // Terminate all the service worker relate to this registration. 143 // This is used by the WebExtensions framework to shutdown the extension's 144 // background service workers as part of shutdown, which happens when: 145 // - the extension has been disabled. 146 // - the extension is shutting down to be updated. 147 // - the extension is shutting down as part of the uninstall flow. 148 // 149 // All the service workers instances related to this registration are expected 150 // to be terminate immediately. 151 // 152 // TODO - Bug 1638099: This method should also allow the WebExtension framework 153 // to mark the registration as disabled (e.g. through an additional parameter), 154 // to avoid it to be started again until the WebExtensions framework does explicitly 155 // mark it back to enabled. 156 void forceShutdown(); 157}; 158 159[scriptable, uuid(9e523e7c-ad6f-4df0-8077-c74aebbc679d)] 160interface nsIServiceWorkerManagerListener : nsISupports 161{ 162 void onRegister(in nsIServiceWorkerRegistrationInfo aInfo); 163 164 void onUnregister(in nsIServiceWorkerRegistrationInfo aInfo); 165}; 166 167[scriptable, builtinclass, uuid(7404c8e8-4d47-4449-8ed1-47d1261d4e33)] 168interface nsIServiceWorkerManager : nsISupports 169{ 170 /** 171 * A testing helper that registers a service worker for testing purpose (e.g. used to test 172 * a remote worker that has to spawn a new process to be launched). 173 * This method can only be used when "dom.serviceWorkers.testing.enabled" is true and 174 * it doesn't support all the registration options (e.g. updateViaCache is set automatically 175 * to "imports"). 176 */ 177 [implicit_jscontext] 178 Promise registerForTest(in nsIPrincipal aPrincipal, 179 in AString aScope, 180 in AString aScriptURL); 181 182 /** 183 * Register an extension background service worker for a given 184 * extension principal and return a promise that resolves to the 185 * nsIServiceWorkerRegistrationInfo (or rejects if there was one 186 * already registered). 187 */ 188 [implicit_jscontext] 189 Promise registerForAddonPrincipal(in nsIPrincipal aPrincipal); 190 191 /** 192 * Unregister an existing ServiceWorker registration for `aScope`. 193 * It keeps aCallback alive until the operation is concluded. 194 */ 195 void unregister(in nsIPrincipal aPrincipal, 196 in nsIServiceWorkerUnregisterCallback aCallback, 197 in AString aScope); 198 199 nsIServiceWorkerRegistrationInfo getRegistrationByPrincipal(in nsIPrincipal aPrincipal, 200 in AString aScope); 201 202 [notxpcom, nostdcall] bool StartControlling(in const_ClientInfoRef aClientInfo, 203 in const_ServiceWorkerDescriptorRef aServiceWorker); 204 205 // Testing 206 AString getScopeForUrl(in nsIPrincipal aPrincipal, in AString aPath); 207 208 // It returns an array of nsIServiceWorkerRegistrationInfos. 209 nsIArray getAllRegistrations(); 210 211 // For clear-origin-attributes-data 212 void removeRegistrationsByOriginAttributes(in AString aOriginAttributes); 213 214 // It calls unregister() in each child process. The callback is used to 215 // inform when unregister() is completed on the current process. 216 void propagateUnregister(in nsIPrincipal aPrincipal, 217 in nsIServiceWorkerUnregisterCallback aCallback, 218 in AString aScope); 219 220 void sendNotificationClickEvent(in ACString aOriginSuffix, 221 in ACString scope, 222 in AString aID, 223 in AString aTitle, 224 in AString aDir, 225 in AString aLang, 226 in AString aBody, 227 in AString aTag, 228 in AString aIcon, 229 in AString aData, 230 in AString aBehavior); 231 232 void sendNotificationCloseEvent(in ACString aOriginSuffix, 233 in ACString scope, 234 in AString aID, 235 in AString aTitle, 236 in AString aDir, 237 in AString aLang, 238 in AString aBody, 239 in AString aTag, 240 in AString aIcon, 241 in AString aData, 242 in AString aBehavior); 243 244 [optional_argc] void sendPushEvent(in ACString aOriginAttributes, 245 in ACString aScope, 246 [optional] in Array<uint8_t> aDataBytes); 247 void sendPushSubscriptionChangeEvent(in ACString aOriginAttributes, 248 in ACString scope); 249 250 void addListener(in nsIServiceWorkerManagerListener aListener); 251 252 void removeListener(in nsIServiceWorkerManagerListener aListener); 253}; 254 255%{ C++ 256#define SERVICEWORKERMANAGER_CONTRACTID "@mozilla.org/serviceworkers/manager;1" 257%} 258