Bug 1317604 - 2. Rip out GeckoView event listeners; r=snorp
authorJim Chen <nchen@mozilla.com>
Mon, 21 Nov 2016 10:01:30 -0500
changeset 323679 c672332a484db01b65449af076039221c777c409
parent 323678 946e15013499fe1bae4c1d8e910bacaf26638ade
child 323680 ace6ae91b3760d36e66e9d831f30b4fba73c0c7a
push id30981
push usercbook@mozilla.com
push dateTue, 22 Nov 2016 14:53:38 +0000
treeherdermozilla-central@1a3194836cb4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1317604
milestone53.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 1317604 - 2. Rip out GeckoView event listeners; r=snorp GeckoView's GeckoEventListener and NativeEventListener are not actually hooked up to events right now, so it's better to just rip them out until we figure out a better implementation in the future.
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoView.java
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoView.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoView.java
@@ -10,20 +10,16 @@ import java.util.Set;
 
 import org.json.JSONException;
 import org.json.JSONObject;
 import org.mozilla.gecko.annotation.ReflectionTarget;
 import org.mozilla.gecko.annotation.WrapForJNI;
 import org.mozilla.gecko.gfx.LayerView;
 import org.mozilla.gecko.mozglue.JNIObject;
 import org.mozilla.gecko.util.EventCallback;
-import org.mozilla.gecko.util.GeckoEventListener;
-import org.mozilla.gecko.util.NativeEventListener;
-import org.mozilla.gecko.util.NativeJSObject;
-import org.mozilla.gecko.util.ThreadUtils;
 
 import android.app.Activity;
 import android.content.Context;
 import android.content.SharedPreferences;
 import android.os.Binder;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.IBinder;
@@ -33,91 +29,32 @@ import android.util.AttributeSet;
 import android.util.DisplayMetrics;
 import android.util.Log;
 import android.view.KeyEvent;
 import android.view.View;
 import android.view.inputmethod.EditorInfo;
 import android.view.inputmethod.InputConnection;
 
 public class GeckoView extends LayerView
-    implements ContextGetter, GeckoEventListener, NativeEventListener {
+    implements ContextGetter {
 
     private static final String DEFAULT_SHARED_PREFERENCES_FILE = "GeckoView";
     private static final String LOGTAG = "GeckoView";
 
     private final EventDispatcher eventDispatcher = new EventDispatcher();
 
     private ChromeDelegate mChromeDelegate;
     private ContentDelegate mContentDelegate;
 
     private InputConnectionListener mInputConnectionListener;
 
     protected boolean onAttachedToWindowCalled;
     protected String chromeURI;
     protected int screenId = 0; // default to the primary screen
 
-    @Override
-    public void handleMessage(final String event, final JSONObject message) {
-        ThreadUtils.postToUiThread(new Runnable() {
-            @Override
-            public void run() {
-                try {
-                    if (event.equals("Gecko:Ready")) {
-                        handleReady(message);
-                    } else if (event.equals("Content:StateChange")) {
-                        handleStateChange(message);
-                    } else if (event.equals("Content:LoadError")) {
-                        handleLoadError(message);
-                    } else if (event.equals("Content:PageShow")) {
-                        handlePageShow(message);
-                    } else if (event.equals("DOMTitleChanged")) {
-                        handleTitleChanged(message);
-                    } else if (event.equals("Link:Favicon")) {
-                        handleLinkFavicon(message);
-                    } else if (event.equals("Prompt:Show") || event.equals("Prompt:ShowTop")) {
-                        handlePrompt(message);
-                    } else if (event.equals("Accessibility:Event")) {
-                        int mode = getImportantForAccessibility();
-                        if (mode == View.IMPORTANT_FOR_ACCESSIBILITY_YES ||
-                                mode == View.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
-                            GeckoAccessibility.sendAccessibilityEvent(message);
-                        }
-                    }
-                } catch (Exception e) {
-                    Log.e(LOGTAG, "handleMessage threw for " + event, e);
-                }
-            }
-        });
-    }
-
-    @Override
-    public void handleMessage(final String event, final NativeJSObject message, final EventCallback callback) {
-        try {
-            if ("Accessibility:Ready".equals(event)) {
-                GeckoAccessibility.updateAccessibilitySettings(getContext());
-            } else if ("GeckoView:Message".equals(event)) {
-                // We need to pull out the bundle while on the Gecko thread.
-                NativeJSObject json = message.optObject("data", null);
-                if (json == null) {
-                    // Must have payload to call the message handler.
-                    return;
-                }
-                final Bundle data = json.toBundle();
-                ThreadUtils.postToUiThread(new Runnable() {
-                    @Override
-                    public void run() {
-                        handleScriptMessage(data, callback);
-                    }
-                });
-            }
-        } catch (Exception e) {
-            Log.w(LOGTAG, "handleMessage threw for " + event, e);
-        }
-    }
-
     @WrapForJNI(dispatchTo = "proxy")
     protected static final class Window extends JNIObject {
         @WrapForJNI(skip = true)
         /* package */ Window() {}
 
         static native void open(Window instance, GeckoView view, Object compositor,
                                 EventDispatcher dispatcher, String chromeURI, int screenId);
 
@@ -388,96 +325,16 @@ public class GeckoView extends LayerView
         if (url.startsWith("resource://android/assets/")) {
             GeckoAppShell.notifyObservers("GeckoView:ImportScript", url);
             return;
         }
 
         throw new IllegalArgumentException("Must import script from 'resources://android/assets/' location.");
     }
 
-    private void handleReady(final JSONObject message) {
-        if (mChromeDelegate != null) {
-            mChromeDelegate.onReady(this);
-        }
-    }
-
-    private void handleStateChange(final JSONObject message) throws JSONException {
-        int state = message.getInt("state");
-        if ((state & GeckoAppShell.WPL_STATE_IS_NETWORK) != 0) {
-            if ((state & GeckoAppShell.WPL_STATE_START) != 0) {
-                if (mContentDelegate != null) {
-                    int id = message.getInt("tabID");
-                    mContentDelegate.onPageStart(this, new Browser(id), message.getString("uri"));
-                }
-            } else if ((state & GeckoAppShell.WPL_STATE_STOP) != 0) {
-                if (mContentDelegate != null) {
-                    int id = message.getInt("tabID");
-                    mContentDelegate.onPageStop(this, new Browser(id), message.getBoolean("success"));
-                }
-            }
-        }
-    }
-
-    private void handleLoadError(final JSONObject message) throws JSONException {
-        if (mContentDelegate != null) {
-            int id = message.getInt("tabID");
-            mContentDelegate.onPageStop(GeckoView.this, new Browser(id), false);
-        }
-    }
-
-    private void handlePageShow(final JSONObject message) throws JSONException {
-        if (mContentDelegate != null) {
-            int id = message.getInt("tabID");
-            mContentDelegate.onPageShow(GeckoView.this, new Browser(id));
-        }
-    }
-
-    private void handleTitleChanged(final JSONObject message) throws JSONException {
-        if (mContentDelegate != null) {
-            int id = message.getInt("tabID");
-            mContentDelegate.onReceivedTitle(GeckoView.this, new Browser(id), message.getString("title"));
-        }
-    }
-
-    private void handleLinkFavicon(final JSONObject message) throws JSONException {
-        if (mContentDelegate != null) {
-            int id = message.getInt("tabID");
-            mContentDelegate.onReceivedFavicon(GeckoView.this, new Browser(id), message.getString("href"), message.getInt("size"));
-        }
-    }
-
-    private void handlePrompt(final JSONObject message) throws JSONException {
-        if (mChromeDelegate != null) {
-            String hint = message.optString("hint");
-            if ("alert".equals(hint)) {
-                String text = message.optString("text");
-                mChromeDelegate.onAlert(GeckoView.this, null, text, new PromptResult(message));
-            } else if ("confirm".equals(hint)) {
-                String text = message.optString("text");
-                mChromeDelegate.onConfirm(GeckoView.this, null, text, new PromptResult(message));
-            } else if ("prompt".equals(hint)) {
-                String text = message.optString("text");
-                String defaultValue = message.optString("textbox0");
-                mChromeDelegate.onPrompt(GeckoView.this, null, text, defaultValue, new PromptResult(message));
-            } else if ("remotedebug".equals(hint)) {
-                mChromeDelegate.onDebugRequest(GeckoView.this, new PromptResult(message));
-            }
-        }
-    }
-
-    private void handleScriptMessage(final Bundle data, final EventCallback callback) {
-        if (mChromeDelegate != null) {
-            MessageResult result = null;
-            if (callback != null) {
-                result = new MessageResult(callback);
-            }
-            mChromeDelegate.onScriptMessage(GeckoView.this, data, result);
-        }
-    }
-
     /**
     * Set the chrome callback handler.
     * This will replace the current handler.
     * @param chrome An implementation of GeckoViewChrome.
     */
     public void setChromeDelegate(ChromeDelegate chrome) {
         mChromeDelegate = chrome;
     }