Bug 1437551 - [3.1] Move generic callback out of GeckoSession. r=snorp,jchen
☠☠ backed out by c1752eb8f975 ☠ ☠
authorEugen Sawin <esawin@mozilla.com>
Tue, 17 Apr 2018 00:13:54 +0200
changeset 468676 45ba3fb2d9ccf3cadf6f5b77808bdf9e25a7e415
parent 468675 4b780b06d2ebf392432bcf9a326aeba9a17cef61
child 468677 e893040e197fc005256d3f07ac3ba53ad5da3d28
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp, jchen
bugs1437551
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 1437551 - [3.1] Move generic callback out of GeckoSession. r=snorp,jchen
mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsActivity.java
mobile/android/base/java/org/mozilla/gecko/webapps/WebAppActivity.java
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/BasicSelectionActionDelegate.java
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoResponse.java
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntime.java
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java
mobile/android/geckoview_example/src/main/java/org/mozilla/geckoview_example/GeckoViewActivity.java
--- a/mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsActivity.java
+++ b/mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsActivity.java
@@ -52,16 +52,17 @@ import org.mozilla.gecko.text.TextSelect
 import org.mozilla.gecko.util.ActivityUtils;
 import org.mozilla.gecko.util.ColorUtil;
 import org.mozilla.gecko.util.GeckoBundle;
 import org.mozilla.gecko.util.IntentUtils;
 import org.mozilla.gecko.util.PackageUtil;
 import org.mozilla.gecko.webapps.WebApps;
 import org.mozilla.gecko.widget.ActionModePresenter;
 import org.mozilla.gecko.widget.GeckoPopupMenu;
+import org.mozilla.geckoview.GeckoResponse;
 import org.mozilla.geckoview.GeckoRuntime;
 import org.mozilla.geckoview.GeckoSession;
 import org.mozilla.geckoview.GeckoSessionSettings;
 import org.mozilla.geckoview.GeckoView;
 
 import java.util.List;
 
 public class CustomTabsActivity extends AppCompatActivity
@@ -599,17 +600,17 @@ public class CustomTabsActivity extends 
     public void onCanGoForward(GeckoSession session, boolean canGoForward) {
         mCanGoForward = canGoForward;
         updateMenuItemForward();
     }
 
     @Override
     public void onLoadRequest(final GeckoSession session, final String urlStr,
                                  final int target,
-                                 final GeckoSession.Response<Boolean> response) {
+                                 final GeckoResponse<Boolean> response) {
         if (target != GeckoSession.NavigationDelegate.TARGET_WINDOW_NEW) {
             response.respond(false);
             return;
         }
 
         final Uri uri = Uri.parse(urlStr);
         if (uri == null) {
             // We can't handle this, so deny it.
@@ -640,17 +641,17 @@ public class CustomTabsActivity extends 
             }
         }
 
         response.respond(true);
     }
 
     @Override
     public void onNewSession(final GeckoSession session, final String uri,
-                             final GeckoSession.Response<GeckoSession> response) {
+                             final GeckoResponse<GeckoSession> response) {
         // We should never get here because we abort loads that need a new session in onLoadRequest()
         throw new IllegalStateException("Unexpected new session");
     }
 
     /* GeckoSession.ProgressDelegate */
     @Override
     public void onPageStart(GeckoSession session, String url) {
         mCurrentUrl = url;
--- a/mobile/android/base/java/org/mozilla/gecko/webapps/WebAppActivity.java
+++ b/mobile/android/base/java/org/mozilla/gecko/webapps/WebAppActivity.java
@@ -32,16 +32,17 @@ import org.mozilla.gecko.preferences.Gec
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.customtabs.CustomTabsActivity;
 import org.mozilla.gecko.permissions.Permissions;
 import org.mozilla.gecko.prompts.PromptService;
 import org.mozilla.gecko.text.TextSelection;
 import org.mozilla.gecko.util.ActivityUtils;
 import org.mozilla.gecko.util.ColorUtil;
 import org.mozilla.gecko.widget.ActionModePresenter;
+import org.mozilla.geckoview.GeckoResponse;
 import org.mozilla.geckoview.GeckoRuntime;
 import org.mozilla.geckoview.GeckoSession;
 import org.mozilla.geckoview.GeckoSessionSettings;
 import org.mozilla.geckoview.GeckoView;
 
 public class WebAppActivity extends AppCompatActivity
                             implements ActionModePresenter,
                                        GeckoSession.ContentDelegate,
@@ -368,17 +369,17 @@ public class WebAppActivity extends AppC
     @Override // GeckoSession.ContentDelegate
     public void onFullScreen(GeckoSession session, boolean fullScreen) {
         updateFullScreenContent(fullScreen);
     }
 
     @Override
     public void onLoadRequest(final GeckoSession session, final String urlStr,
                               final int target,
-                              final GeckoSession.Response<Boolean> response) {
+                              final GeckoResponse<Boolean> response) {
         final Uri uri = Uri.parse(urlStr);
         if (uri == null) {
             // We can't really handle this, so deny it?
             Log.w(LOGTAG, "Failed to parse URL for navigation: " + urlStr);
             response.respond(true);
             return;
         }
 
@@ -420,17 +421,17 @@ public class WebAppActivity extends AppC
                 Log.w(LOGTAG, "No activity handler found for: " + urlStr);
             }
         }
         response.respond(true);
     }
 
     @Override
     public void onNewSession(final GeckoSession session, final String uri,
-                             final GeckoSession.Response<GeckoSession> response) {
+                             final GeckoResponse<GeckoSession> response) {
         // We should never get here because we abort loads that need a new session in onLoadRequest()
         throw new IllegalStateException("Unexpected new session");
     }
 
     private void updateFullScreen() {
         boolean fullScreen = mIsFullScreenContent || mIsFullScreenMode;
         if (ActivityUtils.isFullScreen(this) == fullScreen) {
             return;
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/BasicSelectionActionDelegate.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/BasicSelectionActionDelegate.java
@@ -59,17 +59,17 @@ public class BasicSelectionActionDelegat
     protected final RectF mTempRect = new RectF();
 
     private boolean mExternalActionsEnabled;
 
     protected ActionMode mActionMode;
     protected GeckoSession mSession;
     protected Selection mSelection;
     protected List<String> mActions;
-    protected GeckoSession.Response<String> mResponse;
+    protected GeckoResponse<String> mResponse;
     protected boolean mRepopulatedMenu;
 
     @TargetApi(Build.VERSION_CODES.M)
     private class Callback2Wrapper extends ActionMode.Callback2 {
         @Override
         public boolean onCreateActionMode(final ActionMode actionMode, final Menu menu) {
             return BasicSelectionActionDelegate.this.onCreateActionMode(actionMode, menu);
         }
@@ -345,17 +345,17 @@ public class BasicSelectionActionDelegat
         mTempMatrix.mapRect(mTempRect, mSelection.clientRect);
         mTempRect.roundOut(outRect);
     }
 
     @TargetApi(Build.VERSION_CODES.M)
     @Override
     public void onShowActionRequest(final GeckoSession session, final Selection selection,
                                     final String[] actions,
-                                    final GeckoSession.Response<String> response) {
+                                    final GeckoResponse<String> response) {
         mSession = session;
         mSelection = selection;
         mActions = Arrays.asList(actions);
         mResponse = response;
 
         if (mActionMode != null) {
             if (actions.length > 0) {
                 mActionMode.invalidate();
new file mode 100644
--- /dev/null
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoResponse.java
@@ -0,0 +1,19 @@
+/* -*- 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;
+
+/**
+ * This is used to receive async responses from delegate methods.
+ */
+public interface GeckoResponse<T> {
+    /**
+     * Called when async processing has finished.
+     *
+     * @param value The value contained in the response.
+     */
+    void respond(T value);
+}
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntime.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntime.java
@@ -28,17 +28,17 @@ public final class GeckoRuntime implemen
 
     private static GeckoRuntime sDefaultRuntime;
 
     /**
      * Get the default runtime for the given context.
      * This will create and initialize the runtime with the default settings.
      *
      * Note: Only use this for session-less apps.
-     *       For regular apps, use create() and createSession() instead.
+     *       For regular apps, use create() instead.
      *
      * @return The (static) default runtime for the context.
      */
     public static synchronized @NonNull GeckoRuntime getDefault(
             final @NonNull Context context) {
         Log.d(LOGTAG, "getDefault");
         if (sDefaultRuntime == null) {
             sDefaultRuntime = new GeckoRuntime();
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java
@@ -176,26 +176,26 @@ public class GeckoSession extends LayerS
                     delegate.onCanGoBack(GeckoSession.this,
                                          message.getBoolean("canGoBack"));
                     delegate.onCanGoForward(GeckoSession.this,
                                             message.getBoolean("canGoForward"));
                 } else if ("GeckoView:OnLoadRequest".equals(event)) {
                     final String uri = message.getString("uri");
                     final int where = convertGeckoTarget(message.getInt("where"));
                     delegate.onLoadRequest(GeckoSession.this, uri, where,
-                        new Response<Boolean>() {
+                        new GeckoResponse<Boolean>() {
                             @Override
                             public void respond(Boolean handled) {
                                 callback.sendSuccess(handled);
                             }
                         });
                 } else if ("GeckoView:OnNewSession".equals(event)) {
                     final String uri = message.getString("uri");
                     delegate.onNewSession(GeckoSession.this, uri,
-                        new Response<GeckoSession>() {
+                        new GeckoResponse<GeckoSession>() {
                             @Override
                             public void respond(GeckoSession session) {
                                 if (session == null) {
                                     callback.sendSuccess(null);
                                     return;
                                 }
 
                                 if (session.isOpen()) {
@@ -358,17 +358,17 @@ public class GeckoSession extends LayerS
                                       final GeckoBundle message,
                                       final EventCallback callback) {
                 if ("GeckoView:ShowSelectionAction".equals(event)) {
                     final SelectionActionDelegate.Selection selection =
                             new SelectionActionDelegate.Selection(message);
 
                     final String[] actions = message.getStringArray("actions");
                     final int seqNo = message.getInt("seqNo");
-                    final Response<String> response = new Response<String>() {
+                    final GeckoResponse<String> response = new GeckoResponse<String>() {
                         @Override
                         public void respond(final String action) {
                             final GeckoBundle response = new GeckoBundle(2);
                             response.putString("id", action);
                             response.putInt("seqNo", seqNo);
                             callback.sendSuccess(response);
                         }
                     };
@@ -1913,17 +1913,17 @@ public class GeckoSession extends LayerS
          * @param selection Current selection attributes.
          * @param actions Array of built-in actions available; possible values
          * come from the {@link #ACTION_CUT ACTION_*} constants.
          * @param response Callback object for performing built-in actions. For example,
          * {@code response.respond(actions[0])} performs the first action. May be used
          * multiple times to perform multiple actions at once.
          */
         void onShowActionRequest(GeckoSession session, Selection selection,
-                                 @Action String[] actions, Response<String> response);
+                                 @Action String[] actions, GeckoResponse<String> response);
 
         @IntDef({HIDE_REASON_NO_SELECTION,
                  HIDE_REASON_INVISIBLE_SELECTION,
                  HIDE_REASON_ACTIVE_SELECTION,
                  HIDE_REASON_ACTIVE_SCROLL})
         @interface HideReason {}
 
         /**
@@ -1956,26 +1956,16 @@ public class GeckoSession extends LayerS
          *
          * @param session The GeckoSession that initiated the callback.
          * @param reason The reason that actions are no longer available, as one of the
          * {@link #HIDE_REASON_NO_SELECTION HIDE_REASON_*} constants.
          */
         void onHideAction(GeckoSession session, @HideReason int reason);
     }
 
-    /**
-     * This is used to send responses in delegate methods that have asynchronous responses.
-     */
-    public interface Response<T> {
-        /**
-         * @param val The value contained in the response
-         */
-        void respond(T val);
-    }
-
     public interface NavigationDelegate {
         /**
         * A view has started loading content from the network.
         * @param session The GeckoSession that initiated the callback.
         * @param url The resource being loaded.
         */
         void onLocationChange(GeckoSession session, String url);
 
@@ -2011,29 +2001,29 @@ public class GeckoSession extends LayerS
          * @param target The target where the window has requested to open. One of
          *               TARGET_WINDOW_*.
          * @param response A response which will state whether or not the load
          *                 was handled. If unhandled, Gecko will continue the
          *                 load as normal.
          */
         void onLoadRequest(GeckoSession session, String uri,
                            @TargetWindow int target,
-                           Response<Boolean> response);
+                           GeckoResponse<Boolean> response);
 
         /**
         * A request has been made to open a new session. The URI is provided only for
         * informational purposes. Do not call GeckoSession.loadUri() here. Additionally, the
         * returned GeckoSession must be a newly-created one.
         *
         * @param session The GeckoSession that initiated the callback.
         * @param uri The URI to be loaded.
         *
         * @param response A Response which will hold the returned GeckoSession
         */
-        void onNewSession(GeckoSession session, String uri, Response<GeckoSession> response);
+        void onNewSession(GeckoSession session, String uri, GeckoResponse<GeckoSession> response);
     }
 
     /**
      * GeckoSession applications implement this interface to handle prompts triggered by
      * content in the GeckoSession, such as alerts, authentication dialogs, and select list
      * pickers.
      **/
     public interface PromptDelegate {
--- a/mobile/android/geckoview_example/src/main/java/org/mozilla/geckoview_example/GeckoViewActivity.java
+++ b/mobile/android/geckoview_example/src/main/java/org/mozilla/geckoview_example/GeckoViewActivity.java
@@ -12,19 +12,19 @@ import android.net.Uri;
 import android.os.Build;
 import android.os.Bundle;
 import android.os.SystemClock;
 import android.util.Log;
 import android.view.WindowManager;
 
 import java.util.Locale;
 
+import org.mozilla.geckoview.GeckoResponse;
 import org.mozilla.geckoview.GeckoSession;
 import org.mozilla.geckoview.GeckoSessionSettings;
-import org.mozilla.geckoview.GeckoSession.Response;
 import org.mozilla.geckoview.GeckoSession.TrackingProtectionDelegate;
 import org.mozilla.geckoview.GeckoView;
 import org.mozilla.geckoview.GeckoRuntime;
 import org.mozilla.geckoview.GeckoRuntimeSettings;
 
 public class GeckoViewActivity extends Activity {
     private static final String LOGTAG = "GeckoViewActivity";
     private static final String DEFAULT_URL = "https://mozilla.org";
@@ -359,23 +359,23 @@ public class GeckoViewActivity extends A
         }
 
         @Override
         public void onCanGoForward(GeckoSession session, boolean value) {
         }
 
         @Override
         public void onLoadRequest(final GeckoSession session, final String uri,
-                                  final int target, Response<Boolean> response) {
+                                  final int target, GeckoResponse<Boolean> response) {
             Log.d(LOGTAG, "onLoadRequest=" + uri + " where=" + target);
             response.respond(false);
         }
 
         @Override
-        public void onNewSession(final GeckoSession session, final String uri, Response<GeckoSession> response) {
+        public void onNewSession(final GeckoSession session, final String uri, GeckoResponse<GeckoSession> response) {
             response.respond(null);
         }
     }
 
     private class MyTrackingProtection implements GeckoSession.TrackingProtectionDelegate {
         private int mBlockedAds = 0;
         private int mBlockedAnalytics = 0;
         private int mBlockedSocial = 0;