Bug 1458327 - 3. Make GeckoSessionHandler and GeckoSessionSettings work with init-data; r=esawin
authorJim Chen <nchen@mozilla.com>
Fri, 04 May 2018 21:08:10 -0400
changeset 473114 5ab8f1a1eb577852a578f643958b8008921da806
parent 473113 f37d7d18d8e740bbb6d556385e94fa884719c217
child 473115 3647f62ed6b6f4a45120208a4a1423791ce672e6
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersesawin
bugs1458327
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1458327 - 3. Make GeckoSessionHandler and GeckoSessionSettings work with init-data; r=esawin Make GeckoSessionHandler and GeckoSessionSettings use the updated "GeckoView:EnableModule" and "GeckoView:UpdateSettings" events. Also, send events for updating settings only while the session is open. Don't send events while the session is closed, because when opening the session, we will send settings in one batch in the init-data. MozReview-Commit-ID: Kytx8Ak4A5p
mobile/android/chrome/geckoview/geckoview.js
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSessionHandler.java
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSessionSettings.java
--- a/mobile/android/chrome/geckoview/geckoview.js
+++ b/mobile/android/chrome/geckoview/geckoview.js
@@ -43,17 +43,17 @@ var ModuleManager = {
             manager: self,
             ...module,
           }),
         ];
       }
     })());
 
     WindowEventDispatcher.registerListener(this, [
-      "GeckoView:EnableModule",
+      "GeckoView:UpdateModuleState",
       "GeckoView:UpdateInitData",
       "GeckoView:UpdateSettings",
     ]);
   },
 
   get window() {
     return window;
   },
@@ -89,17 +89,17 @@ var ModuleManager = {
       module.impl.onSettingsUpdate();
       this._browser.messageManager.sendAsyncMessage("GeckoView:UpdateSettings",
                                                     this._settings);
     });
   },
 
   onEvent(aEvent, aData, aCallback) {
     switch (aEvent) {
-      case "GeckoView:EnableModule": {
+      case "GeckoView:UpdateModuleState": {
         const module = this._modules.get(aData.module);
         if (module) {
           module.enabled = aData.enabled;
         }
         break;
       }
 
       case "GeckoView:UpdateInitData": {
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java
@@ -820,17 +820,17 @@ public class GeckoSession extends LayerS
             mTextInput.onWindowChanged(mWindow);
         }
 
         if (change == WINDOW_CLOSE) {
             // Detach when window is closing, and reattach immediately after window is closed.
             // We reattach immediate after closing because we want any actions performed while the
             // session is closed to be properly queued, until the session is open again.
             for (final GeckoSessionHandler<?> handler : mSessionHandlers) {
-                handler.setSessionIsReady(getEventDispatcher(), !inProgress);
+                handler.setSessionIsReady(this, !inProgress);
             }
         }
     }
 
     /**
      * Get the SessionTextInput instance for this session. May be called on any thread.
      *
      * @return SessionTextInput instance.
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSessionHandler.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSessionHandler.java
@@ -37,66 +37,65 @@ import android.util.Log;
                                       final boolean alwaysListen) {
         session.handlersCount++;
 
         mAlwaysListen = alwaysListen;
         mModuleName = module;
         mEvents = events;
 
         if (alwaysListen) {
-            register(session.getEventDispatcher());
-            setSessionIsReady(session.getEventDispatcher(), /* ready */ true);
+            register(session);
         }
     }
 
     public Delegate getDelegate() {
         return mDelegate;
     }
 
     public void setDelegate(final Delegate delegate, final GeckoSession session) {
-        final EventDispatcher eventDispatcher = session.getEventDispatcher();
         if (mDelegate == delegate) {
             return;
         }
 
         final boolean unsettingOldDelegate = mDelegate != null &&
                                              delegate == null;
         final boolean settingNewDelegate = mDelegate == null &&
                                            delegate != null;
 
         if (!mAlwaysListen && unsettingOldDelegate) {
-            unregister(eventDispatcher);
+            unregister(session);
         }
 
         mDelegate = delegate;
 
         if (!mAlwaysListen && settingNewDelegate) {
-            register(eventDispatcher);
+            register(session);
         }
     }
 
-    private void unregister(final EventDispatcher eventDispatcher) {
-        setSessionIsReady(eventDispatcher, /* ready */ false);
-        eventDispatcher.unregisterUiThreadListener(this, mEvents);
+    private void unregister(final GeckoSession session) {
+        setSessionIsReady(session, /* ready */ false);
+        session.getEventDispatcher().unregisterUiThreadListener(this, mEvents);
     }
 
-    private void register(final EventDispatcher eventDispatcher) {
-        eventDispatcher.registerUiThreadListener(this, mEvents);
-        setSessionIsReady(eventDispatcher, /* ready */ true);
+    private void register(final GeckoSession session) {
+        session.getEventDispatcher().registerUiThreadListener(this, mEvents);
+        setSessionIsReady(session, /* ready */ true);
     }
 
-    public void setSessionIsReady(final EventDispatcher eventDispatcher, final boolean ready) {
+    public void setSessionIsReady(final GeckoSession session, final boolean ready) {
+        // If not enabled, we don't need Gecko to register/unregister.
         if (!mAlwaysListen && mDelegate == null) {
             return;
         }
 
-        final GeckoBundle msg = new GeckoBundle(1);
+        final GeckoBundle msg = new GeckoBundle(2);
         msg.putString("module", mModuleName);
-        eventDispatcher.dispatch(ready ? "GeckoView:Register"
-                                       : "GeckoView:Unregister", msg);
+        msg.putBoolean("enabled", ready);
+        session.getEventDispatcher().dispatch("GeckoView:UpdateModuleState", msg);
     }
 
     @Override
     public void handleMessage(final String event, final GeckoBundle message,
                               final EventCallback callback) {
         if (DEBUG) {
             Log.d(LOGTAG, mModuleName + " handleMessage: event = " + event);
         }
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSessionSettings.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSessionSettings.java
@@ -192,18 +192,18 @@ public final class GeckoSessionSettings 
             throw new IllegalArgumentException("Invalid value");
         }
 
         final Object old = mBundle.get(key.name);
         return (old != value) && (old == null || !old.equals(value));
     }
 
     private void dispatchUpdate() {
-        if (mSession != null) {
-            mSession.getEventDispatcher().dispatch("GeckoView:UpdateSettings", null);
+        if (mSession != null && mSession.isOpen()) {
+            mSession.getEventDispatcher().dispatch("GeckoView:UpdateSettings", toBundle());
         }
     }
 
     @Override // Parcelable
     public int describeContents() {
         return 0;
     }