mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-27 04:05:32 +00:00
6962d3f0f6
Put GeckoView chrome content and JS module files into their own GeckoView-specific directories, to make it easier to build separate JARs for GeckoView and Fennec. --HG-- rename : mobile/android/chrome/content/GeckoViewContent.js => mobile/android/chrome/geckoview/GeckoViewContent.js rename : mobile/android/chrome/content/geckoview.js => mobile/android/chrome/geckoview/geckoview.js rename : mobile/android/chrome/content/geckoview.xul => mobile/android/chrome/geckoview/geckoview.xul rename : mobile/android/modules/AndroidLog.jsm => mobile/android/modules/geckoview/AndroidLog.jsm rename : mobile/android/modules/GeckoViewContent.jsm => mobile/android/modules/geckoview/GeckoViewContent.jsm rename : mobile/android/modules/GeckoViewModule.jsm => mobile/android/modules/geckoview/GeckoViewModule.jsm rename : mobile/android/modules/GeckoViewNavigation.jsm => mobile/android/modules/geckoview/GeckoViewNavigation.jsm rename : mobile/android/modules/GeckoViewProgress.jsm => mobile/android/modules/geckoview/GeckoViewProgress.jsm rename : mobile/android/modules/GeckoViewSettings.jsm => mobile/android/modules/geckoview/GeckoViewSettings.jsm rename : mobile/android/modules/Messaging.jsm => mobile/android/modules/geckoview/Messaging.jsm
135 lines
4.0 KiB
JavaScript
135 lines
4.0 KiB
JavaScript
/* 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/. */
|
|
|
|
"use strict";
|
|
|
|
this.EXPORTED_SYMBOLS = ["GeckoViewNavigation"];
|
|
|
|
const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
|
|
|
|
Cu.import("resource://gre/modules/GeckoViewModule.jsm");
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "EventDispatcher",
|
|
"resource://gre/modules/Messaging.jsm");
|
|
|
|
var dump = Cu.import("resource://gre/modules/AndroidLog.jsm", {})
|
|
.AndroidLog.d.bind(null, "ViewNavigation");
|
|
|
|
function debug(aMsg) {
|
|
// dump(aMsg);
|
|
}
|
|
|
|
// Handles navigation requests between Gecko and a GeckoView.
|
|
// Implements GeckoView.loadUri via openURI.
|
|
// Handles GeckoView:GoBack and :GoForward requests dispatched by
|
|
// GeckoView.goBack and .goForward.
|
|
// Dispatches GeckoView:LocationChange to the GeckoView on location change when
|
|
// active.
|
|
// Can be activated and deactivated by GeckoViewNavigation:Active and :Inactive
|
|
// events.
|
|
class GeckoViewNavigation extends GeckoViewModule {
|
|
init() {
|
|
this.window.QueryInterface(Ci.nsIDOMChromeWindow).browserDOMWindow = this;
|
|
|
|
// We need to listen initially because the "GeckoViewNavigation:Active"
|
|
// event may be dispatched before this object is constructed.
|
|
this.registerProgressListener();
|
|
|
|
this.eventDispatcher.registerListener(this, [
|
|
"GeckoViewNavigation:Active",
|
|
"GeckoViewNavigation:Inactive",
|
|
"GeckoView:GoBack",
|
|
"GeckoView:GoForward",
|
|
"GeckoView:LoadUri",
|
|
"GeckoView:Reload",
|
|
]);
|
|
}
|
|
|
|
// Bundle event handler.
|
|
onEvent(aEvent, aData, aCallback) {
|
|
debug("onEvent: aEvent=" + aEvent + ", aData=" + JSON.stringify(aData));
|
|
|
|
switch (aEvent) {
|
|
case "GeckoViewNavigation:Active":
|
|
this.registerProgressListener();
|
|
break;
|
|
case "GeckoViewNavigation:Inactive":
|
|
this.unregisterProgressListener();
|
|
break;
|
|
case "GeckoView:GoBack":
|
|
this.browser.goBack();
|
|
break;
|
|
case "GeckoView:GoForward":
|
|
this.browser.goForward();
|
|
break;
|
|
case "GeckoView:LoadUri":
|
|
this.browser.loadURI(aData.uri, null, null, null);
|
|
break;
|
|
case "GeckoView:Reload":
|
|
this.browser.reload();
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Message manager event handler.
|
|
receiveMessage(aMsg) {
|
|
debug("receiveMessage " + aMsg.name);
|
|
}
|
|
|
|
// nsIBrowserDOMWindow::openURI implementation.
|
|
openURI(aUri, aOpener, aWhere, aFlags) {
|
|
debug("openURI: aUri.spec=" + aUri.spec);
|
|
// nsIWebNavigation::loadURI(URI, loadFlags, referrer, postData, headers).
|
|
this.browser.loadURI(aUri.spec, null, null, null);
|
|
}
|
|
|
|
// nsIBrowserDOMWindow::canClose implementation.
|
|
canClose() {
|
|
debug("canClose");
|
|
return false;
|
|
}
|
|
|
|
registerProgressListener() {
|
|
debug("registerProgressListener");
|
|
let flags = Ci.nsIWebProgress.NOTIFY_LOCATION;
|
|
this.progressFilter =
|
|
Cc["@mozilla.org/appshell/component/browser-status-filter;1"]
|
|
.createInstance(Ci.nsIWebProgress);
|
|
this.progressFilter.addProgressListener(this, flags);
|
|
this.browser.addProgressListener(this.progressFilter, flags);
|
|
}
|
|
|
|
unregisterProgressListener() {
|
|
debug("unregisterProgressListener");
|
|
if (!this.progressFilter) {
|
|
return;
|
|
}
|
|
this.progressFilter.removeProgressListener(this);
|
|
this.browser.removeProgressListener(this.progressFilter);
|
|
}
|
|
|
|
// WebProgress event handler.
|
|
onLocationChange(aWebProgress, aRequest, aLocationURI, aFlags) {
|
|
debug("onLocationChange");
|
|
|
|
let fixedURI = aLocationURI;
|
|
|
|
try {
|
|
fixedURI = URIFixup.createExposableURI(aLocationURI);
|
|
} catch (ex) { }
|
|
|
|
let message = {
|
|
type: "GeckoView:LocationChange",
|
|
uri: fixedURI.spec,
|
|
canGoBack: this.browser.canGoBack,
|
|
canGoForward: this.browser.canGoForward,
|
|
};
|
|
|
|
debug("dispatch " + JSON.stringify(message));
|
|
|
|
this.eventDispatcher.sendRequest(message);
|
|
}
|
|
}
|