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

This commit is contained in:
Eugen Sawin 2018-04-23 23:10:50 +02:00
Родитель 3aa42d1204
Коммит aeda0a9513
8 изменённых файлов: 40 добавлений и 28 удалений

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -5,6 +5,7 @@
package org.mozilla.geckoview.test;
import org.mozilla.geckoview.GeckoResponse;
import org.mozilla.geckoview.GeckoSession;
import org.mozilla.geckoview.GeckoSessionSettings;
import org.mozilla.geckoview.GeckoView;
@ -43,13 +44,13 @@ public class TestRunnerActivity extends Activity {
@Override
public void onLoadRequest(GeckoSession session, String uri, int target,
GeckoSession.Response<Boolean> response) {
GeckoResponse<Boolean> response) {
// Allow Gecko to load all URIs
response.respond(false);
}
@Override
public void onNewSession(GeckoSession session, String uri, GeckoSession.Response<GeckoSession> response) {
public void onNewSession(GeckoSession session, String uri, GeckoResponse<GeckoSession> response) {
response.respond(createSession(session.getSettings()));
}
};

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -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.
*/

Просмотреть файл

@ -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);
@ -2005,7 +2005,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,
@ -2048,16 +2048,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.
@ -2103,7 +2093,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
@ -2115,7 +2105,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);
}
/**

Просмотреть файл

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