Bug 1437551 - [3.1] Move generic callback out of GeckoSession. r=snorp,jchen

This commit is contained in:
Eugen Sawin 2018-04-17 00:13:54 +02:00
parent 6cec4c4563
commit a443c8b358
7 changed files with 37 additions and 26 deletions

View File

@ -57,6 +57,7 @@ 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;
@ -604,7 +605,7 @@ public class CustomTabsActivity extends AppCompatActivity
@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;
@ -645,7 +646,7 @@ public class CustomTabsActivity extends AppCompatActivity
@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");
}

View File

@ -37,6 +37,7 @@ 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;
@ -373,7 +374,7 @@ public class WebAppActivity extends AppCompatActivity
@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?
@ -425,7 +426,7 @@ public class WebAppActivity extends AppCompatActivity
@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");
}

View File

@ -64,7 +64,7 @@ public class BasicSelectionActionDelegate implements ActionMode.Callback,
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)
@ -350,7 +350,7 @@ public class BasicSelectionActionDelegate implements ActionMode.Callback,
@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);

View File

@ -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);
}

View File

@ -33,7 +33,7 @@ public final class GeckoRuntime implements Parcelable {
* 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.
*/

View File

@ -181,7 +181,7 @@ public class GeckoSession extends LayerSession
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);
@ -190,7 +190,7 @@ public class GeckoSession extends LayerSession
} 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) {
@ -363,7 +363,7 @@ public class GeckoSession extends LayerSession
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);
@ -1918,7 +1918,7 @@ public class GeckoSession extends LayerSession
* 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,
@ -1961,16 +1961,6 @@ public class GeckoSession extends LayerSession
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.
@ -2016,7 +2006,7 @@ public class GeckoSession extends LayerSession
*/
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
@ -2028,7 +2018,7 @@ public class GeckoSession extends LayerSession
*
* @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);
}
/**

View File

@ -17,9 +17,9 @@ 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;
@ -364,13 +364,13 @@ public class GeckoViewActivity extends Activity {
@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);
}
}