Closed Bug 1343678 Opened 3 years ago Closed 2 months ago

Enable Web Push support in GeckoView

Categories

(GeckoView :: General, enhancement, P1)

Unspecified
Android
enhancement

Tracking

(firefox-esr60 wontfix, firefox66 wontfix, firefox67 wontfix, firefox68 wontfix, firefox69 wontfix, firefox70 wontfix, firefox71 fixed)

RESOLVED FIXED
mozilla71
Tracking Status
firefox-esr60 --- wontfix
firefox66 --- wontfix
firefox67 --- wontfix
firefox68 --- wontfix
firefox69 --- wontfix
firefox70 --- wontfix
firefox71 --- fixed

People

(Reporter: snorp, Assigned: snorp)

References

(Blocks 2 open bugs)

Details

(Whiteboard: [geckoview:m1909])

Attachments

(4 files, 2 obsolete files)

Web Push could be a very powerful feature if exposed to GeckoView consumers. GCM is kind of a PITA in comparison (IMHO), and Android's WebView does not support it AFAIK.

I am not sure what it would really look like, but it would probably provide a way for the Service Worker to communicate with an Android service.
Summary: Figure out Web Push support with GeckoView → [geckoview] Figure out Web Push support
Component: Embedding: APIs → GeckoView
Product: Core → Firefox for Android
Priority: -- → P3
I'll note that using anything other than native message support could cause the OS to trigger battery use warnings. That's one of the bigger reasons that we picked using GCM / APNs as a "bridge" system. 

There are a few other options, of course, but they come with conditions.

1) Instead of keeping a constant connection open, poll the server to see if any messages are outstanding. 
Cons: potentially high delay for message delivery compared with "native" implementations.

2) Use the bridge as a "poke" service. Send a "data-free" poke over the bridge to wake the UA to fetch messages using websocket method.
Cons: Kinda wasteful, still requires costly decryption but also now separate connection costs.

3) Use only native push service. GCM/FCM provide webpush. We could skip our own system in favor of a "pure" native implementation.
Cons: Significantly complicates future mozilla services like pushbox and broadcast.
Fenix will need GV API support for push notifications.
Priority: P3 → P2
Summary: [geckoview] Figure out Web Push support → Figure out Web Push support for GeckoView
Product: Firefox for Android → GeckoView
Whiteboard: [geckoview:fenix:p2]

P3 because Barbara says Web Push is not needed for Fenix MVP.

OS: Unspecified → Android
Priority: P2 → P3
Whiteboard: [geckoview:fenix:p2] → [geckoview:fenix:p3]
Depends on: 1533057
Whiteboard: [geckoview:fenix:p3] → [geckoview:fenix:p2]

Adding [geckoview:fenix:m7] whiteboard tag because we should figure out our Web Push plans in Q2.

Whiteboard: [geckoview:fenix:p2] → [geckoview:fenix:m7]

(In reply to Chris Peterson [:cpeterson] from comment #4)

AC issue to add an Engine component API for Web Push:
https://github.com/mozilla-mobile/android-components/issues/1919

I've closed the A-C ticket above as it was more for investigation on how a-c could support WebPush subscriptions. Now that we have some initial support, there are still some a-s dependencies that we can use to make this work.

This is a more appropriate a-c ticket to reference: https://github.com/mozilla-mobile/android-components/issues/3418

Snorp, Jonathan, JR, and I chatted about this in Whistler. We decided on adding a delegate to handle creating, fetching, and removing push subscriptions. Consumers like Fenix could wire up this delegate to the a-s Rust Push component, or any other backend they like. We can also use the delegate to mock the push server.

Here's a sketch of the delegate, and the DOM APIs it would support:

interface PushDelegate {
  /** Creates a push subscription for the given service worker scope. A scope
    * uniquely identifies a service worker. `appServerKey` optionally
    * creates a restricted subscription
    * (http://w3c.github.io/push-api/#dom-pushmanager-subscribe,
    * http://w3c.github.io/push-api/#dom-pushsubscriptionoptionsinit-applicationserverkey) */
  GeckoResult<PushSubscription> onSubscribe(@NonNull String scope,
                                            @Nullable byte[] appServerKey);
  /** Retrieves a subscription for the given service worker scope.
    * (http://w3c.github.io/push-api/#dom-pushmanager-getsubscription) */
  GeckoResult<PushSubscription> onGetSubscription(@NonNull String scope);
  /** Removes a push subscription. Resolves with `true` if the subscription
    * was successfully removed, `false` otherwise. This is passed through to
    * the DOM API
    * (http://w3c.github.io/push-api/#dom-pushsubscription-unsubscribe). */
  GeckoResult<Boolean> onUnsubscribe(@NonNull String scope);
}

/** Push subscription info to forward to the DOM API. */
interface PushSubscription {
  // http://w3c.github.io/push-api/#dom-pushsubscription-endpoint
  @NonNull String getEndpoint();
  // http://w3c.github.io/push-api/#dom-pushsubscription-getkey, "p256dh"
  @NonNull byte[] getEncryptionKey();
  // http://w3c.github.io/push-api/#dom-pushsubscription-getkey, "auth"
  @NonNull byte[] getAuthKey();
  // http://w3c.github.io/push-api/#dom-pushsubscriptionoptions, returns the same
  // value as the optional `appServerKey` argument.
  @Nullable byte[] getAppServerKey();
}

// On ServiceWorkerManager...
class ServiceWorkerManager {
  // ...

  /** Delivers a decrypted push message to the service worker for the given scope. */
  void onPushMessageReceived(String scope, byte[] message);

  /** Fires a `pushsubscriptionchange` event for a service worker, indicating the
      worker's subscription has been lost and the worker must resubscribe. */
  void onPushSubscriptionChange(String scope);
}

It looks to me like we may want to register a new thing here[0], but it seems like those bits really want you to look like a WebSocket or H2 type of push impl. It may be easier and/or more appropriate to implement nsIPushService[1] directly, which pretty much matches the public API we'd like to expose. It may, however, be a baby/bathwater situation.

[0] https://searchfox.org/mozilla-central/rev/c0ca77697c6868482f30af873ec8069f2c080a34/dom/push/PushService.jsm#15
[1] https://searchfox.org/mozilla-central/source/dom/interfaces/push/nsIPushService.idl

(In reply to James Willcox (:snorp) (jwillcox@mozilla.com) (he/him) from comment #8)

It may be easier and/or more appropriate to implement nsIPushService[1] directly, which pretty much matches the public API we'd like to expose. It may, however, be a baby/bathwater situation.

That might be the best option. We can also add the GeckoView implementation as a different backend here—keeping PushComponents mostly as it is now, but avoiding all the funky PushService.jsm machinery.

Though nsIPushService is pretty small, and, if we can use Messaging.jsm directly from the content process—or if we need to use it from content, anyway, to get the right event dispatcher—we wouldn't need PushServiceContent at all.

Blocks: 1561593
Assignee: nobody → snorp
See Also: → 1569618

[geckoview:fenix:m7] bugs should be priority P1.

I'm editing a bunch of GeckoView bugs. If you'd like to filter all this bugmail, search and destroy emails containing this UUID:

e88a5094-0fc0-4b7c-b7c5-aef00a11dbc9

Priority: P3 → P1
Attachment #9083130 - Attachment is obsolete: true
Attachment #9084345 - Attachment is obsolete: true
Pushed by jwillcox@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/37c92bba3e1c
Enable web push pref for GeckoView r=geckoview-reviewers,droeh
https://hg.mozilla.org/integration/autoland/rev/0bef62794abb
Use window context for `GeckoSessionTestRule.evaluateJS()` r=geckoview-reviewers,droeh
https://hg.mozilla.org/integration/autoland/rev/c22a725950f0
Add WebPush support to GeckoView r=jcj,lina,agi,geckoview-reviewers,droeh,mt
Flags: needinfo?(snorp)
Pushed by jwillcox@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/b01343e4c2eb
Enable web push pref for GeckoView r=geckoview-reviewers,droeh,smaug
https://hg.mozilla.org/integration/autoland/rev/5010684cdca4
Use window context for `GeckoSessionTestRule.evaluateJS()` r=geckoview-reviewers,droeh
https://hg.mozilla.org/integration/autoland/rev/619e7838ebfd
Add WebPush support to GeckoView r=jcj,lina,agi,geckoview-reviewers,droeh,mt
Flags: needinfo?(snorp)
Summary: Figure out Web Push support for GeckoView → Enable Web Push support in GeckoView
Pushed by jwillcox@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/3551cc55620d
Enable web push pref for GeckoView r=geckoview-reviewers,droeh,smaug
https://hg.mozilla.org/integration/autoland/rev/07b757a21222
Use window context for `GeckoSessionTestRule.evaluateJS()` r=geckoview-reviewers,droeh
https://hg.mozilla.org/integration/autoland/rev/85526faefe6d
Add WebPush support to GeckoView r=jcj,lina,agi,geckoview-reviewers,droeh,mt
https://hg.mozilla.org/integration/autoland/rev/7396789341b1
Ensure events expecting a reply get one even if there is no listener r=geckoview-reviewers,droeh,agi
Pushed by csabou@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/4b77646bc788
Followup to fix rebase error. r=snorp

Adding this bug to GV's September sprint.

Whiteboard: [geckoview:fenix:m7] → [geckoview:m1909]
Regressions: 1578365
Pushed by jwillcox@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/b2ae7f641b2d
Enable web push pref for GeckoView r=geckoview-reviewers,droeh,smaug,jgraham
https://hg.mozilla.org/integration/autoland/rev/2c7b6826afe9
Use window context for `GeckoSessionTestRule.evaluateJS()` r=geckoview-reviewers,droeh
https://hg.mozilla.org/integration/autoland/rev/b70bcfe2473f
Add WebPush support to GeckoView r=jcj,lina,agi,geckoview-reviewers,droeh,mt
https://hg.mozilla.org/integration/autoland/rev/3dc75350ad97
Ensure events expecting a reply get one even if there is no listener r=geckoview-reviewers,droeh,agi
Pushed by malexandru@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/c0810f35c8d5
Mark a few more wpt tests as passing on Android r=me
Flags: needinfo?(snorp)

firefox70=wontfix because I assume Fenix doesn't need us to uplift Web Push to GV 70 Beta. GV 71 Nightly will ride to Beta on October 21.

You need to log in before you can comment on or make changes to this bug.