tor-browser

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

nsIPushNotifier.idl (3398B)


      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 "nsISupports.idl"
      7 
      8 %{C++
      9 // These constants are duplicated in `PushComponents.js`.
     10 #define OBSERVER_TOPIC_PUSH "push-message"
     11 #define OBSERVER_TOPIC_SUBSCRIPTION_CHANGE "push-subscription-change"
     12 #define OBSERVER_TOPIC_SUBSCRIPTION_MODIFIED "push-subscription-modified"
     13 %}
     14 
     15 interface nsIPrincipal;
     16 interface nsIPushSubscription;
     17 
     18 /**
     19 * Fires XPCOM observer notifications and service worker events for
     20 * messages sent to push subscriptions.
     21 */
     22 [scriptable, builtinclass, uuid(b00dfdeb-14e5-425b-adc7-b531442e3216)]
     23 interface nsIPushNotifier : nsISupports
     24 {
     25  /**
     26   * Fires a `push-message` observer notification, and sends a `push` event to
     27   * the service worker registered for the |scope|. |messageId| is an opaque ID
     28   * used to report errors if the worker fails to handle the message.
     29   */
     30  void notifyPush(in ACString scope, in nsIPrincipal principal,
     31                  in AString messageId);
     32 
     33  /**
     34   * Same as `notifyPush`, except the subject of the observer notification
     35   * receives an `nsIPushMessage` instance containing the |data|. Service
     36   * workers can access the |data| via the `PushMessageData` WebIDL interface.
     37   */
     38  void notifyPushWithData(in ACString scope, in nsIPrincipal principal,
     39                          in AString messageId,
     40                          in Array<uint8_t> data);
     41 
     42  /**
     43   * Fires a `push-subscription-change` observer notification, and sends a
     44   * `pushsubscriptionchange` event to the service worker registered for the
     45   * |scope|.
     46   */
     47  void notifySubscriptionChange(in ACString scope, in nsIPrincipal principal,
     48                                [optional] in nsIPushSubscription oldSubscription);
     49 
     50  /**
     51   * Fires a `push-subscription-modified` observer notification. Chrome code
     52   * can listen for this notification to see when a subscription is added,
     53   * updated, removed, or expired for any |scope|.
     54   *
     55   * This is useful for Dev Tools and debugging add-ons that passively observe
     56   * when subscriptions are created or dropped. Other callers should listen for
     57   * `push-subscription-change` and resubscribe instead.
     58   */
     59  void notifySubscriptionModified(in ACString scope, in nsIPrincipal principal);
     60 
     61  void notifyError(in ACString scope, in nsIPrincipal principal,
     62                   in AString message, in uint32_t flags);
     63 };
     64 
     65 /**
     66 * Provides methods for retrieving push message data in different formats.
     67 * This interface resembles the `PushMessageData` WebIDL interface.
     68 */
     69 [scriptable, builtinclass, uuid(dfc4f151-cead-40df-8eb7-7a7a67c54b16)]
     70 interface nsIPushData : nsISupports
     71 {
     72  /** Extracts the data as a UTF-8 text string. */
     73  AString text();
     74 
     75  /** Extracts the data as a JSON value. */
     76  [implicit_jscontext] jsval json();
     77 
     78  /** Extracts the raw binary data. */
     79  Array<uint8_t> binary();
     80 };
     81 
     82 /**
     83 * The subject of a `push-message` observer notification. |data| may be |null|
     84 * for messages without data.
     85 */
     86 [scriptable, builtinclass, uuid(b9d063ca-0e3f-4fee-be4b-ea9103263433)]
     87 interface nsIPushMessage : nsISupports
     88 {
     89  readonly attribute nsIPrincipal principal;
     90  readonly attribute nsIPushData data;
     91 };