зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1377580 - [2.1] Add support for external URI loading in GeckoView. r=snorp
This commit is contained in:
Родитель
d8fdd4ab7b
Коммит
87790afb62
|
@ -128,7 +128,10 @@ public class GeckoView extends LayerView {
|
||||||
private final GeckoViewHandler<NavigationListener> mNavigationHandler =
|
private final GeckoViewHandler<NavigationListener> mNavigationHandler =
|
||||||
new GeckoViewHandler<NavigationListener>(
|
new GeckoViewHandler<NavigationListener>(
|
||||||
"GeckoViewNavigation", this,
|
"GeckoViewNavigation", this,
|
||||||
new String[]{ "GeckoView:LocationChange" }
|
new String[]{
|
||||||
|
"GeckoView:LocationChange",
|
||||||
|
"GeckoView:OnLoadUri"
|
||||||
|
}
|
||||||
) {
|
) {
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(final NavigationListener listener,
|
public void handleMessage(final NavigationListener listener,
|
||||||
|
@ -142,8 +145,13 @@ public class GeckoView extends LayerView {
|
||||||
message.getBoolean("canGoBack"));
|
message.getBoolean("canGoBack"));
|
||||||
listener.onCanGoForward(GeckoView.this,
|
listener.onCanGoForward(GeckoView.this,
|
||||||
message.getBoolean("canGoForward"));
|
message.getBoolean("canGoForward"));
|
||||||
|
} else if ("GeckoView:OnLoadUri".equals(event)) {
|
||||||
|
final String uri = message.getString("uri");
|
||||||
|
final NavigationListener.TargetWindow where =
|
||||||
|
NavigationListener.TargetWindow.get(
|
||||||
|
message.getInt("where"));
|
||||||
|
listener.onLoadUri(GeckoView.this, uri, where);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1379,6 +1387,44 @@ public class GeckoView extends LayerView {
|
||||||
* @param canGoForward The new value for the ability.
|
* @param canGoForward The new value for the ability.
|
||||||
*/
|
*/
|
||||||
void onCanGoForward(GeckoView view, boolean canGoForward);
|
void onCanGoForward(GeckoView view, boolean canGoForward);
|
||||||
|
|
||||||
|
enum TargetWindow {
|
||||||
|
DEFAULT(0),
|
||||||
|
CURRENT(1),
|
||||||
|
NEW(2),
|
||||||
|
NEWTAB(3),
|
||||||
|
SWITCHTAB(4);
|
||||||
|
|
||||||
|
private static final TargetWindow[] sValues = TargetWindow.values();
|
||||||
|
private int mValue;
|
||||||
|
|
||||||
|
private TargetWindow(int value) {
|
||||||
|
mValue = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TargetWindow get(int value) {
|
||||||
|
return sValues[value];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum LoadUriResult {
|
||||||
|
HANDLED(0),
|
||||||
|
LOAD_IN_FRAME(1);
|
||||||
|
|
||||||
|
private int mValue;
|
||||||
|
|
||||||
|
private LoadUriResult(int value) {
|
||||||
|
mValue = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A request to open an URI.
|
||||||
|
* @param view The GeckoView that initiated the callback.
|
||||||
|
* @param uri The URI to be loaded.
|
||||||
|
* @param where The target window.
|
||||||
|
*/
|
||||||
|
void onLoadUri(GeckoView view, String uri, TargetWindow where);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -70,11 +70,61 @@ class GeckoViewNavigation extends GeckoViewModule {
|
||||||
debug("receiveMessage " + aMsg.name);
|
debug("receiveMessage " + aMsg.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// nsIBrowserDOMWindow::createContentWindow implementation.
|
||||||
|
createContentWindow(aUri, aOpener, aWhere, aFlags, aTriggeringPrincipal) {
|
||||||
|
debug("createContentWindow: aUri=" + (aUri && aUri.spec) +
|
||||||
|
" aWhere=" + aWhere +
|
||||||
|
" aFlags=" + aFlags);
|
||||||
|
|
||||||
|
if (!aUri) {
|
||||||
|
throw Cr.NS_ERROR_ABORT;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (aWhere === Ci.nsIBrowserDOMWindow.OPEN_DEFAULTWINDOW ||
|
||||||
|
aWhere === Ci.nsIBrowserDOMWindow.OPEN_CURRENTWINDOW) {
|
||||||
|
return this.browser.contentWindow;
|
||||||
|
}
|
||||||
|
|
||||||
|
let message = {
|
||||||
|
type: "GeckoView:OnLoadUri",
|
||||||
|
uri: aUri.spec,
|
||||||
|
where: aWhere,
|
||||||
|
flags: aFlags
|
||||||
|
};
|
||||||
|
|
||||||
|
debug("dispatch " + JSON.stringify(message));
|
||||||
|
|
||||||
|
this.eventDispatcher.sendRequest(message);
|
||||||
|
|
||||||
|
throw Cr.NS_ERROR_ABORT;
|
||||||
|
}
|
||||||
|
|
||||||
// nsIBrowserDOMWindow::openURI implementation.
|
// nsIBrowserDOMWindow::openURI implementation.
|
||||||
openURI(aUri, aOpener, aWhere, aFlags) {
|
openURI(aUri, aOpener, aWhere, aFlags, aTriggeringPrincipal) {
|
||||||
debug("openURI: aUri.spec=" + aUri.spec);
|
return this.createContentWindow(aUri, aOpener, aWhere, aFlags,
|
||||||
// nsIWebNavigation::loadURI(URI, loadFlags, referrer, postData, headers).
|
aTriggeringPrincipal);
|
||||||
this.browser.loadURI(aUri.spec, null, null, null);
|
}
|
||||||
|
|
||||||
|
// nsIBrowserDOMWindow::openURIInFrame implementation.
|
||||||
|
openURIInFrame(aUri, aParams, aWhere, aFlags, aNextTabParentId, aName) {
|
||||||
|
debug("openURIInFrame: aUri=" + (aUri && aUri.spec) +
|
||||||
|
" aParams=" + aParams +
|
||||||
|
" aWhere=" + aWhere +
|
||||||
|
" aFlags=" + aFlags +
|
||||||
|
" aNextTabParentId=" + aNextTabParentId +
|
||||||
|
" aName=" + aName);
|
||||||
|
|
||||||
|
if (aWhere === Ci.nsIBrowserDOMWindow.OPEN_DEFAULTWINDOW ||
|
||||||
|
aWhere === Ci.nsIBrowserDOMWindow.OPEN_CURRENTWINDOW) {
|
||||||
|
return this.browser.QueryInterface(Ci.nsIFrameLoaderOwner);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw Cr.NS_ERROR_ABORT;
|
||||||
|
}
|
||||||
|
|
||||||
|
isTabContentWindow(aWindow) {
|
||||||
|
debug("isTabContentWindow " + this.browser.contentWindow === aWindow);
|
||||||
|
return this.browser.contentWindow === aWindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
// nsIBrowserDOMWindow::canClose implementation.
|
// nsIBrowserDOMWindow::canClose implementation.
|
||||||
|
|
Загрузка…
Ссылка в новой задаче