Bug 1443658 - Use an integer for target in NavigationDelegate.onLoadUri() target r=esawin

MozReview-Commit-ID: AXv8eHQ9sgG
This commit is contained in:
James Willcox 2018-02-28 16:14:30 -05:00
Родитель ca39c61532
Коммит 51b9d6b539
7 изменённых файлов: 43 добавлений и 62 удалений

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

@ -611,9 +611,9 @@ public class CustomTabsActivity extends AppCompatActivity
} }
@Override @Override
public boolean onLoadUri(final GeckoSession session, final String urlStr, public boolean onLoadRequest(final GeckoSession session, final String urlStr,
final TargetWindow where) { final int target) {
if (where != TargetWindow.NEW) { if (target != GeckoSession.NavigationDelegate.TARGET_WINDOW_NEW) {
return false; return false;
} }

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

@ -380,7 +380,7 @@ public class WebAppActivity extends AppCompatActivity
@Override @Override
public boolean onLoadUri(final GeckoSession session, final String urlStr, public boolean onLoadUri(final GeckoSession session, final String urlStr,
final TargetWindow where) { final int target) {
final Uri uri = Uri.parse(urlStr); final Uri uri = Uri.parse(urlStr);
if (uri == null) { if (uri == null) {
// We can't really handle this, so deny it? // We can't really handle this, so deny it?
@ -388,7 +388,7 @@ public class WebAppActivity extends AppCompatActivity
return true; return true;
} }
if (mManifest.isInScope(uri) && where != TargetWindow.NEW) { if (mManifest.isInScope(uri) && target != TARGET_WINDOW_NEW) {
// This is in scope and wants to load in the same frame, so // This is in scope and wants to load in the same frame, so
// let Gecko handle it. // let Gecko handle it.
return false; return false;

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

@ -44,13 +44,13 @@ class NavigationDelegateTest {
sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate { sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate {
@AssertCalled(count = 1, order = intArrayOf(1)) @AssertCalled(count = 1, order = intArrayOf(1))
override fun onLoadUri(session: GeckoSession, uri: String, override fun onLoadUri(session: GeckoSession, uri: String,
where: GeckoSession.NavigationDelegate.TargetWindow): Boolean { where: Int): Boolean {
assertThat("Session should not be null", session, notNullValue()) assertThat("Session should not be null", session, notNullValue())
assertThat("URI should not be null", uri, notNullValue()) assertThat("URI should not be null", uri, notNullValue())
assertThat("URI should match", uri, endsWith(HELLO_HTML_PATH)) assertThat("URI should match", uri, endsWith(HELLO_HTML_PATH))
assertThat("Where should not be null", where, notNullValue()) assertThat("Where should not be null", where, notNullValue())
assertThat("Where should match", where, assertThat("Where should match", where,
equalTo(GeckoSession.NavigationDelegate.TargetWindow.CURRENT)) equalTo(GeckoSession.NavigationDelegate.TARGET_WINDOW_CURRENT))
return false return false
} }
@ -90,10 +90,10 @@ class NavigationDelegateTest {
sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate { sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate {
@AssertCalled(count = 1, order = intArrayOf(1)) @AssertCalled(count = 1, order = intArrayOf(1))
override fun onLoadUri(session: GeckoSession, uri: String, override fun onLoadUri(session: GeckoSession, uri: String,
where: GeckoSession.NavigationDelegate.TargetWindow): Boolean { where: Int): Boolean {
assertThat("URI should match", uri, endsWith(HELLO_HTML_PATH)) assertThat("URI should match", uri, endsWith(HELLO_HTML_PATH))
assertThat("Where should match", where, assertThat("Where should match", where,
equalTo(GeckoSession.NavigationDelegate.TargetWindow.CURRENT)) equalTo(GeckoSession.NavigationDelegate.TARGET_WINDOW_CURRENT))
return false return false
} }
@ -139,10 +139,10 @@ class NavigationDelegateTest {
sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate { sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate {
@AssertCalled(count = 1, order = intArrayOf(1)) @AssertCalled(count = 1, order = intArrayOf(1))
override fun onLoadUri(session: GeckoSession, uri: String, override fun onLoadUri(session: GeckoSession, uri: String,
where: GeckoSession.NavigationDelegate.TargetWindow): Boolean { where: Int): Boolean {
assertThat("URI should match", uri, endsWith(HELLO_HTML_PATH)) assertThat("URI should match", uri, endsWith(HELLO_HTML_PATH))
assertThat("Where should match", where, assertThat("Where should match", where,
equalTo(GeckoSession.NavigationDelegate.TargetWindow.CURRENT)) equalTo(GeckoSession.NavigationDelegate.TARGET_WINDOW_CURRENT))
return false return false
} }
@ -173,10 +173,10 @@ class NavigationDelegateTest {
sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate { sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate {
@AssertCalled(count = 1, order = intArrayOf(1)) @AssertCalled(count = 1, order = intArrayOf(1))
override fun onLoadUri(session: GeckoSession, uri: String, override fun onLoadUri(session: GeckoSession, uri: String,
where: GeckoSession.NavigationDelegate.TargetWindow): Boolean { where: Int): Boolean {
assertThat("URI should match", uri, endsWith(HELLO2_HTML_PATH)) assertThat("URI should match", uri, endsWith(HELLO2_HTML_PATH))
assertThat("Where should match", where, assertThat("Where should match", where,
equalTo(GeckoSession.NavigationDelegate.TargetWindow.CURRENT)) equalTo(GeckoSession.NavigationDelegate.TARGET_WINDOW_CURRENT))
return false return false
} }
@ -206,7 +206,7 @@ class NavigationDelegateTest {
sessionRule.delegateDuringNextWait(object : Callbacks.NavigationDelegate { sessionRule.delegateDuringNextWait(object : Callbacks.NavigationDelegate {
@AssertCalled(count = 2) @AssertCalled(count = 2)
override fun onLoadUri(session: GeckoSession, uri: String, override fun onLoadUri(session: GeckoSession, uri: String,
where: GeckoSession.NavigationDelegate.TargetWindow): Boolean { where: Int): Boolean {
return uri.endsWith(HELLO_HTML_PATH) return uri.endsWith(HELLO_HTML_PATH)
} }
}) })

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

@ -40,7 +40,7 @@ public class TestRunnerActivity extends Activity {
} }
@Override @Override
public boolean onLoadUri(GeckoSession session, String uri, TargetWindow where) { public boolean onLoadUri(GeckoSession session, String uri, int target) {
// Allow Gecko to load all URIs // Allow Gecko to load all URIs
return false; return false;
} }

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

@ -40,7 +40,7 @@ class Callbacks private constructor() {
override fun onCanGoForward(session: GeckoSession, canGoForward: Boolean) { override fun onCanGoForward(session: GeckoSession, canGoForward: Boolean) {
} }
override fun onLoadUri(session: GeckoSession, uri: String, where: GeckoSession.NavigationDelegate.TargetWindow): Boolean { override fun onLoadUri(session: GeckoSession, uri: String, where: Int): Boolean {
return false; return false;
} }

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

@ -127,6 +127,17 @@ public class GeckoSession extends LayerSession
"GeckoView:OnNewSession" "GeckoView:OnNewSession"
} }
) { ) {
// This needs to match nsIBrowserDOMWindow.idl
private int convertGeckoTarget(int geckoTarget) {
switch (geckoTarget) {
case 0: // OPEN_DEFAULTWINDOW
case 1: // OPEN_CURRENTWINDOW
return NavigationDelegate.TARGET_WINDOW_CURRENT;
default: // OPEN_NEWWINDOW, OPEN_NEWTAB, OPEN_SWITCHTAB
return NavigationDelegate.TARGET_WINDOW_NEW;
}
}
@Override @Override
public void handleMessage(final NavigationDelegate delegate, public void handleMessage(final NavigationDelegate delegate,
final String event, final String event,
@ -141,9 +152,7 @@ public class GeckoSession extends LayerSession
message.getBoolean("canGoForward")); message.getBoolean("canGoForward"));
} else if ("GeckoView:OnLoadUri".equals(event)) { } else if ("GeckoView:OnLoadUri".equals(event)) {
final String uri = message.getString("uri"); final String uri = message.getString("uri");
final NavigationDelegate.TargetWindow where = final int where = convertGeckoTarget(message.getInt("where"));
NavigationDelegate.TargetWindow.forGeckoValue(
message.getInt("where"));
final boolean result = final boolean result =
delegate.onLoadUri(GeckoSession.this, uri, where); delegate.onLoadUri(GeckoSession.this, uri, where);
callback.sendSuccess(result); callback.sendSuccess(result);
@ -1399,49 +1408,21 @@ public class GeckoSession extends LayerSession
*/ */
void onCanGoForward(GeckoSession session, boolean canGoForward); void onCanGoForward(GeckoSession session, boolean canGoForward);
enum TargetWindow { public static final int TARGET_WINDOW_NONE = 0;
DEFAULT(0), public static final int TARGET_WINDOW_CURRENT = 1;
CURRENT(1), public static final int TARGET_WINDOW_NEW = 2;
NEW(2);
private static final TargetWindow[] sValues = TargetWindow.values();
private int mValue;
private TargetWindow(int value) {
mValue = value;
}
public static TargetWindow forValue(int value) {
return sValues[value];
}
public static TargetWindow forGeckoValue(int value) {
// DEFAULT(0),
// CURRENT(1),
// NEW(2),
// NEWTAB(3),
// SWITCHTAB(4);
final TargetWindow[] sMap = {
DEFAULT,
CURRENT,
NEW,
NEW,
NEW
};
return sMap[value];
}
}
/** /**
* A request to open an URI. * A request to open an URI.
* @param session The GeckoSession that initiated the callback. * @param session The GeckoSession that initiated the callback.
* @param uri The URI to be loaded. * @param uri The URI to be loaded.
* @param where The target window. * @param target The target where the window has requested to open. One of
* * TARGET_WINDOW_*.
* @return Whether or not the load was handled. Returning false will allow Gecko *
* to continue the load as normal. * @return Whether or not the load was handled. Returning false will allow Gecko
*/ * to continue the load as normal.
boolean onLoadUri(GeckoSession session, String uri, TargetWindow where); */
boolean onLoadUri(GeckoSession session, String uri, int target);
/** /**
* A request has been made to open a new session. The URI is provided only for * A request has been made to open a new session. The URI is provided only for

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

@ -349,8 +349,8 @@ public class GeckoViewActivity extends Activity {
@Override @Override
public boolean onLoadUri(final GeckoSession session, final String uri, public boolean onLoadUri(final GeckoSession session, final String uri,
final TargetWindow where) { final int target) {
Log.d(LOGTAG, "onLoadUri=" + uri + " where=" + where); Log.d(LOGTAG, "onLoadUri=" + uri + " where=" + target);
return false; return false;
} }