tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nsIServiceWorkerManager.idl (13947B)


      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 
      9 interface mozIDOMWindow;
     10 interface nsPIDOMWindowInner;
     11 interface mozIDOMWindowProxy;
     12 interface nsIArray;
     13 interface nsIInterceptedChannel;
     14 interface nsIPrincipal;
     15 interface nsIPushSubscription;
     16 interface nsIRunnable;
     17 interface nsIURI;
     18 %{C++
     19 namespace mozilla {
     20 namespace dom {
     21 class ClientInfo;
     22 class ServiceWorkerDescriptor;
     23 class IPCNotification;
     24 } // namespace dom
     25 } // namespace mozilla
     26 %}
     27 
     28 [ref] native const_ClientInfoRef(const mozilla::dom::ClientInfo);
     29 [ref] native const_ServiceWorkerDescriptorRef(const mozilla::dom::ServiceWorkerDescriptor);
     30 [ref] native const_IPCNotificationRef(const mozilla::dom::IPCNotification);
     31 
     32 [scriptable, uuid(52ee2c9d-ee87-4caf-9588-23ae77ff8798)]
     33 interface nsIServiceWorkerUnregisterCallback : nsISupports
     34 {
     35  // aState is true if the unregistration succeded.
     36  // It's false if this ServiceWorkerRegistration doesn't exist.
     37  void unregisterSucceeded(in boolean aState);
     38  void unregisterFailed();
     39 };
     40 
     41 interface nsIWorkerDebugger;
     42 
     43 [scriptable, builtinclass, uuid(76e357ed-208d-4e4c-9165-1c4059707879)]
     44 interface nsIServiceWorkerInfo : nsISupports
     45 {
     46  // State values below should match the ServiceWorkerState enumeration.
     47  const unsigned short STATE_PARSED = 0;
     48  const unsigned short STATE_INSTALLING = 1;
     49  const unsigned short STATE_INSTALLED = 2;
     50  const unsigned short STATE_ACTIVATING = 3;
     51  const unsigned short STATE_ACTIVATED = 4;
     52  const unsigned short STATE_REDUNDANT = 5;
     53  const unsigned short STATE_UNKNOWN = 6;
     54 
     55  readonly attribute AString id;
     56 
     57  readonly attribute AString scriptSpec;
     58  readonly attribute AString cacheName;
     59 
     60  // How many times has this ServiceWorker been launched since the registration
     61  // was loaded?  This value is not persistent and starts at 0 every time the
     62  // browser restarts.  The value also inherently starts at 0 for a freshly
     63  // installed or updated ServiceWorker.
     64  readonly attribute unsigned long launchCount;
     65 
     66  readonly attribute unsigned short state;
     67 
     68  readonly attribute nsIWorkerDebugger debugger;
     69 
     70  // Return whether the ServiceWorker has a "fetch" event listener. Throws if
     71  // this is unknown because the worker's main script hasn't finished executing
     72  // (when exposed as evaluatingWorker).
     73  readonly attribute boolean handlesFetchEvents;
     74 
     75  readonly attribute PRTime installedTime;
     76  readonly attribute PRTime activatedTime;
     77  readonly attribute PRTime redundantTime;
     78 
     79  // Returns the lifetime deadline of the ServiceWorker as the number of
     80  // milliseconds since the (parent) process was created or 0 if there is no
     81  // current deadline.  This is primarily intended to allow tests to compare
     82  // consistent values, not be useful in general.  But note that
     83  // `ChromeUtils.now()` operates in the same units (milliseconds since
     84  // current process startup), and so can be used to hackily translate to wall
     85  // clock time.
     86  readonly attribute double lifetimeDeadline;
     87 
     88  // Total number of navigation faults experienced by this ServiceWorker since
     89  // it was loaded from disk at startup or was installed.
     90  readonly attribute unsigned long navigationFaultCount;
     91 
     92  // Testing mechanism to induce synthetic failure of fetch events.  If set to
     93  // something other than NS_OK, all fetch events dispatched will be propagated
     94  // to the content process, but when it comes time to dispatch the fetch event,
     95  // the cancellation control flow path will be triggered.
     96  attribute nsresult testingInjectCancellation;
     97 
     98  void attachDebugger();
     99 
    100  void detachDebugger();
    101 
    102  // Forcibly terminate the ServiceWorker if it is running, returning a promise
    103  // that will be resolved when the worker is fully terminated.  If the
    104  // ServiceWorker was not running, the promise will be resolved immediately.
    105  //
    106  // For the purposes of the ServiceWorkerManager, it's as if the ServiceWorker
    107  // is already dead when the call completes and returns the Promise.  Any new
    108  // functional events dispatched at the ServiceWorker will result in a new
    109  // instance/global being spun up.
    110  [implicit_jscontext]
    111  Promise terminateWorker();
    112 };
    113 
    114 [scriptable, uuid(87e63548-d440-4b8a-b158-65ad1de0211E)]
    115 interface nsIServiceWorkerRegistrationInfoListener : nsISupports
    116 {
    117  void onChange();
    118 };
    119 
    120 [scriptable, builtinclass, uuid(ddbc1fd4-2f2e-4fca-a395-6e010bbedfe3)]
    121 interface nsIServiceWorkerRegistrationInfo : nsISupports
    122 {
    123  // State values below should match the ServiceWorkerUpdateViaCache enumeration.
    124  const unsigned short UPDATE_VIA_CACHE_IMPORTS = 0;
    125  const unsigned short UPDATE_VIA_CACHE_ALL = 1;
    126  const unsigned short UPDATE_VIA_CACHE_NONE = 2;
    127 
    128  readonly attribute nsIPrincipal principal;
    129  readonly attribute boolean unregistered;
    130 
    131  readonly attribute AString scope;
    132  readonly attribute AString scriptSpec;
    133  readonly attribute unsigned short updateViaCache;
    134 
    135  readonly attribute PRTime lastUpdateTime;
    136 
    137  readonly attribute nsIServiceWorkerInfo evaluatingWorker;
    138  readonly attribute nsIServiceWorkerInfo installingWorker;
    139  readonly attribute nsIServiceWorkerInfo waitingWorker;
    140  readonly attribute nsIServiceWorkerInfo activeWorker;
    141 
    142  // Exposes the number of times we have ever checked the usage of this origin
    143  // for the purposes of mitigating ServiceWorker navigation faults that we
    144  // suspect to be due to quota limit problems.  This should start out 0 and
    145  // max out at 1 for the time being.
    146  //
    147  // Note that the underlying value is tracked on our per-Principal data, but
    148  // we don't currently expose that data directly via XPCOM so we're exposing
    149  // this here as the next best thing and because most non-test consumers would
    150  // work in terms of the registration anyways.
    151  //
    152  // This will return -1 if there is no longer any per-origin data because the
    153  // last registration for the origin (principal) has been unregistered.
    154  // (Retaining a reference to this interface does not impact anything the
    155  // underlying scope-to-registration map that is implemented per spec.)
    156  readonly attribute long quotaUsageCheckCount;
    157 
    158  // Allows to get the related nsIServiceWorkerInfo for a given
    159  // nsIWorkerDebugger. Over time we shouldn't need this anymore,
    160  // and instead always control then nsIWorkerDebugger from
    161  // nsIServiceWorkerInfo and not the other way around.  Returns
    162  // null if the service worker is no longer registered.
    163  nsIServiceWorkerInfo getWorkerByID(in unsigned long long aID);
    164 
    165  void addListener(in nsIServiceWorkerRegistrationInfoListener listener);
    166 
    167  void removeListener(in nsIServiceWorkerRegistrationInfoListener listener);
    168 
    169  // Terminate all the service worker relate to this registration.
    170  // This is used by the WebExtensions framework to shutdown the extension's
    171  // background service workers as part of shutdown, which happens when:
    172  // - the extension has been disabled.
    173  // - the extension is shutting down to be updated.
    174  // - the extension is shutting down as part of the uninstall flow.
    175  //
    176  // All the service workers instances related to this registration are expected
    177  // to be terminate immediately.
    178  //
    179  // TODO - Bug 1638099: This method should also allow the WebExtension framework
    180  // to mark the registration as disabled (e.g. through an additional parameter),
    181  // to avoid it to be started again until the WebExtensions framework does explicitly
    182  // mark it back to enabled.
    183  void forceShutdown();
    184 };
    185 
    186 [scriptable, uuid(9e523e7c-ad6f-4df0-8077-c74aebbc679d)]
    187 interface nsIServiceWorkerManagerListener : nsISupports
    188 {
    189  void onRegister(in nsIServiceWorkerRegistrationInfo aInfo);
    190 
    191  void onUnregister(in nsIServiceWorkerRegistrationInfo aInfo);
    192 
    193  /**
    194   * Called by ServiceWorker bypass mitigations when checking whether an
    195   * origin's quota usage is sufficiently full that we need to clear the origin
    196   * (and possibly group's) data as part of our mitigation.
    197   * This notification is provided primarily for testing code that needs to wait
    198   * for this check to happen but has no other mechanism for knowing it's
    199   * completed. Probably not relevant to devtools.
    200   */
    201  void onQuotaUsageCheckFinish(in nsIServiceWorkerRegistrationInfo aInfo);
    202 };
    203 
    204 [scriptable, builtinclass, uuid(7404c8e8-4d47-4449-8ed1-47d1261d4e33)]
    205 interface nsIServiceWorkerManager : nsISupports
    206 {
    207  /**
    208   * A testing helper that is meant to only be used in xpcshell-test to test behaviors
    209   * that would need a browser restart to re-initialize the ServiceWorkerManager from
    210   * the service worker registration dumped on disk (the one listed in the serviceworker.txt
    211   * file part of the Firefox profile directory).
    212   *
    213   * NOTE: this test helper does
    214   * - fail if "dom.serviceWorkers.testing.enabled" is not set to true
    215   * - fail if there are controlled clients (the test case is responsible of making sure that
    216   *   there is none when this method is being called)
    217   * - shutdown and clear all service worker registrations (but without removing them from
    218   *   the registration stored in serviceworker.txt)
    219   * - force reload the registration data stored in serviceworker.txt (but the test case using
    220   *   this helper is responsible to be sure that the registrations have been already written
    221   *   on disk)
    222   */
    223  void reloadRegistrationsForTest();
    224 
    225  /**
    226   * A testing helper that registers a service worker for testing purpose (e.g. used to test
    227   * a remote worker that has to spawn a new process to be launched).
    228   * This method can only be used when "dom.serviceWorkers.testing.enabled" is true and
    229   * it doesn't support all the registration options (e.g. updateViaCache is set automatically
    230   * to "imports").
    231   */
    232  [implicit_jscontext]
    233  Promise registerForTest(in nsIPrincipal aPrincipal,
    234                          in AString aScope,
    235                          in AString aScriptURL);
    236 
    237  /**
    238   * Register an extension background service worker for a given
    239   * extension principal and return a promise that resolves to the
    240   * nsIServiceWorkerRegistrationInfo (or rejects if there was one
    241   * already registered).
    242   */
    243  [implicit_jscontext]
    244  Promise registerForAddonPrincipal(in nsIPrincipal aPrincipal);
    245 
    246  /**
    247   * Get an extension background service worker registration for a
    248   * given extension principal, return an nsIServiceWorkerRegistrationInfo
    249   * if one exists (or null if no registration has been found).
    250   */
    251  void getRegistrationForAddonPrincipal(in nsIPrincipal aPrincipal,
    252                                        [optional, retval] out nsIServiceWorkerRegistrationInfo regInfo);
    253 
    254  /**
    255   * Wake up the extension background service worker given its extension base url,
    256   * for an API event identified by the namespace and event name strings.
    257   *
    258   * Returns a Promise which is resolved to true if a listener has been subscribed
    259   * during the synchronous worker script execution for the expected WebExtensions
    260   * API event.
    261   *
    262   * NOTE: ExtensionBrowser and ExtensionEventManager interfaces are keeping track
    263   * of these listeners. These are WebExtensions API event listeners and they do not
    264   * involve any functional events at all.
    265   */
    266  [implicit_jscontext]
    267  Promise wakeForExtensionAPIEvent(in AString aExtensionBaseURL,
    268                                   in AString aAPINamespace,
    269                                   in AString aAPIEventName);
    270 
    271  /**
    272   * Unregister an existing ServiceWorker registration for `aScope`.
    273   * It keeps aCallback alive until the operation is concluded.
    274   */
    275  void unregister(in nsIPrincipal aPrincipal,
    276                  in nsIServiceWorkerUnregisterCallback aCallback,
    277                  in AString aScope);
    278 
    279  nsIServiceWorkerRegistrationInfo getRegistrationByPrincipal(in nsIPrincipal aPrincipal,
    280                                                              in AString aScope);
    281 
    282  [notxpcom, nostdcall] boolean StartControlling(in const_ClientInfoRef aClientInfo,
    283                                                 in const_ServiceWorkerDescriptorRef aServiceWorker);
    284 
    285  // Testing
    286  AString getScopeForUrl(in nsIPrincipal aPrincipal, in AString aPath);
    287 
    288  // It returns an array of nsIServiceWorkerRegistrationInfos.
    289  nsIArray getAllRegistrations();
    290 
    291  // For clear-origin-attributes-data
    292  void removeRegistrationsByOriginAttributes(in AString aOriginAttributes);
    293 
    294  // It calls unregister() in each child process. The callback is used to
    295  // inform when unregister() is completed on the current process.
    296  void propagateUnregister(in nsIPrincipal aPrincipal,
    297                           in nsIServiceWorkerUnregisterCallback aCallback,
    298                           in AString aScope);
    299 
    300  [noscript]
    301  void sendNotificationClickEvent(in ACString aOriginSuffix,
    302                                  in AString scope,
    303                                  in const_IPCNotificationRef aNotification,
    304                                  in AString aAction);
    305 
    306  [noscript]
    307  void sendNotificationCloseEvent(in ACString aOriginSuffix,
    308                                  in AString scope,
    309                                  in const_IPCNotificationRef aNotification);
    310 
    311  [optional_argc] void sendPushEvent(in ACString aOriginAttributes,
    312                                     in ACString aScope,
    313                                     [optional] in Array<uint8_t> aDataBytes);
    314  void sendPushSubscriptionChangeEvent(in ACString aOriginAttributes,
    315                                       in ACString scope,
    316                                       [optional] in nsIPushSubscription aOldSubscription);
    317 
    318  void addListener(in nsIServiceWorkerManagerListener aListener);
    319 
    320  void removeListener(in nsIServiceWorkerManagerListener aListener);
    321 };
    322 
    323 %{ C++
    324 #define SERVICEWORKERMANAGER_CONTRACTID "@mozilla.org/serviceworkers/manager;1"
    325 %}