зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1443658 - Use an integer for target in NavigationDelegate.onLoadUri() target r=esawin
MozReview-Commit-ID: AXv8eHQ9sgG
This commit is contained in:
Родитель
ca39c61532
Коммит
51b9d6b539
|
@ -611,9 +611,9 @@ public class CustomTabsActivity extends AppCompatActivity
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean onLoadUri(final GeckoSession session, final String urlStr,
|
||||
final TargetWindow where) {
|
||||
if (where != TargetWindow.NEW) {
|
||||
public boolean onLoadRequest(final GeckoSession session, final String urlStr,
|
||||
final int target) {
|
||||
if (target != GeckoSession.NavigationDelegate.TARGET_WINDOW_NEW) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -380,7 +380,7 @@ public class WebAppActivity extends AppCompatActivity
|
|||
|
||||
@Override
|
||||
public boolean onLoadUri(final GeckoSession session, final String urlStr,
|
||||
final TargetWindow where) {
|
||||
final int target) {
|
||||
final Uri uri = Uri.parse(urlStr);
|
||||
if (uri == null) {
|
||||
// We can't really handle this, so deny it?
|
||||
|
@ -388,7 +388,7 @@ public class WebAppActivity extends AppCompatActivity
|
|||
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
|
||||
// let Gecko handle it.
|
||||
return false;
|
||||
|
|
|
@ -44,13 +44,13 @@ class NavigationDelegateTest {
|
|||
sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate {
|
||||
@AssertCalled(count = 1, order = intArrayOf(1))
|
||||
override fun onLoadUri(session: GeckoSession, uri: String,
|
||||
where: GeckoSession.NavigationDelegate.TargetWindow): Boolean {
|
||||
where: Int): Boolean {
|
||||
assertThat("Session should not be null", session, notNullValue())
|
||||
assertThat("URI should not be null", uri, notNullValue())
|
||||
assertThat("URI should match", uri, endsWith(HELLO_HTML_PATH))
|
||||
assertThat("Where should not be null", where, notNullValue())
|
||||
assertThat("Where should match", where,
|
||||
equalTo(GeckoSession.NavigationDelegate.TargetWindow.CURRENT))
|
||||
equalTo(GeckoSession.NavigationDelegate.TARGET_WINDOW_CURRENT))
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -90,10 +90,10 @@ class NavigationDelegateTest {
|
|||
sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate {
|
||||
@AssertCalled(count = 1, order = intArrayOf(1))
|
||||
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("Where should match", where,
|
||||
equalTo(GeckoSession.NavigationDelegate.TargetWindow.CURRENT))
|
||||
equalTo(GeckoSession.NavigationDelegate.TARGET_WINDOW_CURRENT))
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -139,10 +139,10 @@ class NavigationDelegateTest {
|
|||
sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate {
|
||||
@AssertCalled(count = 1, order = intArrayOf(1))
|
||||
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("Where should match", where,
|
||||
equalTo(GeckoSession.NavigationDelegate.TargetWindow.CURRENT))
|
||||
equalTo(GeckoSession.NavigationDelegate.TARGET_WINDOW_CURRENT))
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -173,10 +173,10 @@ class NavigationDelegateTest {
|
|||
sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate {
|
||||
@AssertCalled(count = 1, order = intArrayOf(1))
|
||||
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("Where should match", where,
|
||||
equalTo(GeckoSession.NavigationDelegate.TargetWindow.CURRENT))
|
||||
equalTo(GeckoSession.NavigationDelegate.TARGET_WINDOW_CURRENT))
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -206,7 +206,7 @@ class NavigationDelegateTest {
|
|||
sessionRule.delegateDuringNextWait(object : Callbacks.NavigationDelegate {
|
||||
@AssertCalled(count = 2)
|
||||
override fun onLoadUri(session: GeckoSession, uri: String,
|
||||
where: GeckoSession.NavigationDelegate.TargetWindow): Boolean {
|
||||
where: Int): Boolean {
|
||||
return uri.endsWith(HELLO_HTML_PATH)
|
||||
}
|
||||
})
|
||||
|
|
|
@ -40,7 +40,7 @@ public class TestRunnerActivity extends Activity {
|
|||
}
|
||||
|
||||
@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
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ class Callbacks private constructor() {
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -127,6 +127,17 @@ public class GeckoSession extends LayerSession
|
|||
"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
|
||||
public void handleMessage(final NavigationDelegate delegate,
|
||||
final String event,
|
||||
|
@ -141,9 +152,7 @@ public class GeckoSession extends LayerSession
|
|||
message.getBoolean("canGoForward"));
|
||||
} else if ("GeckoView:OnLoadUri".equals(event)) {
|
||||
final String uri = message.getString("uri");
|
||||
final NavigationDelegate.TargetWindow where =
|
||||
NavigationDelegate.TargetWindow.forGeckoValue(
|
||||
message.getInt("where"));
|
||||
final int where = convertGeckoTarget(message.getInt("where"));
|
||||
final boolean result =
|
||||
delegate.onLoadUri(GeckoSession.this, uri, where);
|
||||
callback.sendSuccess(result);
|
||||
|
@ -1399,49 +1408,21 @@ public class GeckoSession extends LayerSession
|
|||
*/
|
||||
void onCanGoForward(GeckoSession session, boolean canGoForward);
|
||||
|
||||
enum TargetWindow {
|
||||
DEFAULT(0),
|
||||
CURRENT(1),
|
||||
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];
|
||||
}
|
||||
}
|
||||
public static final int TARGET_WINDOW_NONE = 0;
|
||||
public static final int TARGET_WINDOW_CURRENT = 1;
|
||||
public static final int TARGET_WINDOW_NEW = 2;
|
||||
|
||||
/**
|
||||
* A request to open an URI.
|
||||
* @param session The GeckoSession that initiated the callback.
|
||||
* @param uri The URI to be loaded.
|
||||
* @param where The target window.
|
||||
*
|
||||
* @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);
|
||||
* A request to open an URI.
|
||||
* @param session The GeckoSession that initiated the callback.
|
||||
* @param uri The URI to be loaded.
|
||||
* @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.
|
||||
*/
|
||||
boolean onLoadUri(GeckoSession session, String uri, int target);
|
||||
|
||||
/**
|
||||
* 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
|
||||
public boolean onLoadUri(final GeckoSession session, final String uri,
|
||||
final TargetWindow where) {
|
||||
Log.d(LOGTAG, "onLoadUri=" + uri + " where=" + where);
|
||||
final int target) {
|
||||
Log.d(LOGTAG, "onLoadUri=" + uri + " where=" + target);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче