Bug 1619778 - Wait for Gecko to be ready when delivering Web Push events r=geckoview-reviewers,aklotz a=jcristau
authorJames Willcox <snorp@snorp.net>
Fri, 13 Mar 2020 20:08:26 +0000
changeset 580709 45be288db1b73a73779b952fe197dedb7c9c492d
parent 580708 b8069adfb9ac2270a4765f1b4428df374e4c5e48
child 580710 c6d1ad75d7ca1ab66cf4b269ef73e3020a4abc90
push id12927
push userapavel@mozilla.com
push dateThu, 26 Mar 2020 17:37:55 +0000
treeherdermozilla-beta@45be288db1b7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgeckoview-reviewers, aklotz, jcristau
bugs1619778
milestone75.0
Bug 1619778 - Wait for Gecko to be ready when delivering Web Push events r=geckoview-reviewers,aklotz a=jcristau Differential Revision: https://phabricator.services.mozilla.com/D66586
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/WebPushController.java
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/WebPushController.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/WebPushController.java
@@ -2,24 +2,26 @@
  * 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 org.mozilla.gecko.EventDispatcher;
+import org.mozilla.gecko.GeckoThread;
 import org.mozilla.gecko.util.BundleEventListener;
 import org.mozilla.gecko.util.EventCallback;
 import org.mozilla.gecko.util.GeckoBundle;
 import org.mozilla.gecko.util.ThreadUtils;
 
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.support.annotation.UiThread;
+import android.util.Log;
 
 public class WebPushController {
     private static final String LOGTAG = "WebPushController";
 
     private WebPushDelegate mDelegate;
     private BundleEventListener mEventListener;
 
     /* package */ WebPushController() {
@@ -56,20 +58,22 @@ public class WebPushController {
      * Send a push event with a payload for a given subscription.
      * @param scope The Service Worker scope associated with this subscription.
      * @param data The unencrypted payload.
      */
     @UiThread
     public void onPushEvent(final @NonNull String scope, final @Nullable byte[] data) {
         ThreadUtils.assertOnUiThread();
 
-        final GeckoBundle msg = new GeckoBundle(2);
-        msg.putString("scope", scope);
-        msg.putString("data", Base64Utils.encode(data));
-        EventDispatcher.getInstance().dispatch("GeckoView:PushEvent", msg);
+        GeckoThread.waitForState(GeckoThread.State.JNI_READY).accept(val -> {
+            final GeckoBundle msg = new GeckoBundle(2);
+            msg.putString("scope", scope);
+            msg.putString("data", Base64Utils.encode(data));
+            EventDispatcher.getInstance().dispatch("GeckoView:PushEvent", msg);
+        }, e -> Log.e(LOGTAG, "Unable to deliver Web Push message", e));
     }
 
     /**
      * Notify that a given subscription has changed. This is normally a signal to the content
      * that it needs to re-subscribe.
      *
      * @param scope The Service Worker scope associated with this subscription.
      */