/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "nsISupports.idl"

interface nsIPrincipal;

/**
 * Fires service worker events for push messages sent to content subscriptions,
 * and XPCOM observer notifications for system subscriptions. This service
 * can only be used from the parent process.
 */
[scriptable, builtinclass, uuid(b00dfdeb-14e5-425b-adc7-b531442e3216)]
interface nsIPushNotifier : nsISupports
{
  void notifyPush(in ACString scope, in nsIPrincipal principal,
                  in DOMString messageId);

  void notifyPushWithData(in ACString scope, in nsIPrincipal principal,
                          in DOMString messageId,
                          [optional] in uint32_t dataLen,
                          [array, size_is(dataLen)] in uint8_t data);

  void notifySubscriptionChange(in ACString scope, in nsIPrincipal principal);

  void notifyError(in ACString scope, in nsIPrincipal principal,
                   in DOMString message, in uint32_t flags);
};

/**
 * A push message sent to a system subscription, used as the subject of a
 * `push-message` observer notification. System subscriptions are created by
 * the system principal, and do not use worker events.
 *
 * This interface resembles the `PushMessageData` WebIDL interface.
 */
[scriptable, builtinclass, uuid(136dc8fd-8c56-4176-9170-eaa86b6ba99e)]
interface nsIPushMessage : nsISupports
{
  /** Extracts the data as a UTF-8 text string. */
  DOMString text();

  /** Extracts the data as a JSON value. */
  [implicit_jscontext] jsval json();

  /** Extracts the raw binary data. */
  void binary([optional] out uint32_t dataLen,
              [array, retval, size_is(dataLen)] out uint8_t data);
};
