summaryrefslogtreecommitdiffstats
path: root/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/WebPushDelegate.java
blob: d9e9c3927435f923a9f0f3584d11aef54806074a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
 * vim: ts=4 sw=4 expandtab:
 * 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/. */

package org.mozilla.geckoview;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;

public interface WebPushDelegate {
  /**
   * Creates a push subscription for the given service worker scope. A scope uniquely identifies a
   * service worker. `appServerKey` optionally creates a restricted subscription.
   *
   * <p>Applications will likely want to persist the returned {@link WebPushSubscription} in order
   * to support {@link #onGetSubscription(String)}.
   *
   * @param scope The Service Worker scope.
   * @param appServerKey An optional application server key.
   * @return A {@link GeckoResult} which resolves to a {@link WebPushSubscription}
   * @see <a href="http://w3c.github.io/push-api/#dom-pushmanager-subscribe">subscribe()</a>
   * @see <a
   *     href="http://w3c.github.io/push-api/#dom-pushsubscriptionoptionsinit-applicationserverkey">Application
   *     server key</a>
   */
  @UiThread
  default @Nullable GeckoResult<WebPushSubscription> onSubscribe(
      @NonNull final String scope, @Nullable final byte[] appServerKey) {
    return null;
  }

  /**
   * Retrieves a subscription for the given service worker scope.
   *
   * @param scope The scope for the requested {@link WebPushSubscription}.
   * @return A {@link GeckoResult} which resolves to a {@link WebPushSubscription}
   * @see <a
   *     href="http://w3c.github.io/push-api/#dom-pushmanager-getsubscription">getSubscription()</a>
   */
  @UiThread
  default @Nullable GeckoResult<WebPushSubscription> onGetSubscription(
      @NonNull final String scope) {
    return null;
  }

  /**
   * Removes a push subscription. If this fails, apps should resolve the returned {@link
   * GeckoResult} with an exception.
   *
   * @param scope The Service Worker scope for the subscription.
   * @return A {@link GeckoResult}, which if non-exceptional indicates successfully unsubscribing.
   * @see <a
   *     href="http://w3c.github.io/push-api/#dom-pushsubscription-unsubscribe">unsubscribe()</a>
   */
  @UiThread
  default @Nullable GeckoResult<Void> onUnsubscribe(@NonNull final String scope) {
    return null;
  }
}