2013-04-25 05:29:31 +00:00
|
|
|
/* 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/. */
|
|
|
|
|
2015-09-15 18:19:45 +00:00
|
|
|
var Cc = Components.classes;
|
|
|
|
var Ci = Components.interfaces;
|
|
|
|
var Cu = Components.utils;
|
2013-04-25 05:29:31 +00:00
|
|
|
|
2015-04-03 14:51:00 +00:00
|
|
|
Cu.import("resource://gre/modules/AppConstants.jsm");
|
2013-04-25 05:29:31 +00:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
|
2014-07-15 05:10:06 +00:00
|
|
|
Cu.import("resource://gre/modules/RemoteAddonsChild.jsm");
|
2013-12-07 00:02:05 +00:00
|
|
|
Cu.import("resource://gre/modules/Timer.jsm");
|
2013-04-25 05:29:31 +00:00
|
|
|
|
2014-10-18 14:09:32 +00:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "PageThumbUtils",
|
|
|
|
"resource://gre/modules/PageThumbUtils.jsm");
|
2014-10-18 14:09:32 +00:00
|
|
|
|
2015-04-03 14:51:00 +00:00
|
|
|
if (AppConstants.MOZ_CRASHREPORTER) {
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "CrashReporter",
|
|
|
|
"@mozilla.org/xre/app-info;1",
|
|
|
|
"nsICrashReporter");
|
|
|
|
}
|
2014-05-17 16:39:14 +00:00
|
|
|
|
2015-07-09 17:18:11 +00:00
|
|
|
function makeInputStream(aString) {
|
|
|
|
let stream = Cc["@mozilla.org/io/string-input-stream;1"].
|
|
|
|
createInstance(Ci.nsISupportsCString);
|
|
|
|
stream.data = aString;
|
|
|
|
return stream; // XPConnect will QI this to nsIInputStream for us.
|
|
|
|
}
|
|
|
|
|
2015-09-15 18:19:45 +00:00
|
|
|
var WebProgressListener = {
|
2013-04-25 05:29:31 +00:00
|
|
|
init: function() {
|
2014-11-15 14:58:08 +00:00
|
|
|
this._filter = Cc["@mozilla.org/appshell/component/browser-status-filter;1"]
|
|
|
|
.createInstance(Ci.nsIWebProgress);
|
|
|
|
this._filter.addProgressListener(this, Ci.nsIWebProgress.NOTIFY_ALL);
|
|
|
|
|
2013-04-25 05:29:31 +00:00
|
|
|
let webProgress = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebProgress);
|
2014-11-15 14:58:08 +00:00
|
|
|
webProgress.addProgressListener(this._filter, Ci.nsIWebProgress.NOTIFY_ALL);
|
2013-04-25 05:29:31 +00:00
|
|
|
},
|
|
|
|
|
2014-11-23 09:28:20 +00:00
|
|
|
uninit() {
|
|
|
|
let webProgress = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebProgress);
|
|
|
|
webProgress.removeProgressListener(this._filter);
|
|
|
|
|
|
|
|
this._filter.removeProgressListener(this);
|
|
|
|
this._filter = null;
|
|
|
|
},
|
|
|
|
|
2014-09-25 03:34:47 +00:00
|
|
|
_requestSpec: function (aRequest, aPropertyName) {
|
2013-04-25 05:29:31 +00:00
|
|
|
if (!aRequest || !(aRequest instanceof Ci.nsIChannel))
|
|
|
|
return null;
|
2014-09-25 03:34:47 +00:00
|
|
|
return aRequest.QueryInterface(Ci.nsIChannel)[aPropertyName].spec;
|
2013-04-25 05:29:31 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_setupJSON: function setupJSON(aWebProgress, aRequest) {
|
2015-12-01 01:56:01 +00:00
|
|
|
let innerWindowID = null;
|
2014-11-15 14:58:08 +00:00
|
|
|
if (aWebProgress) {
|
2015-12-01 01:56:01 +00:00
|
|
|
let domWindowID = null;
|
2015-04-17 09:15:16 +00:00
|
|
|
try {
|
2015-12-01 01:56:01 +00:00
|
|
|
let utils = aWebProgress.DOMWindow.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindowUtils);
|
|
|
|
domWindowID = utils.outerWindowID;
|
|
|
|
innerWindowID = utils.currentInnerWindowID;
|
2015-04-17 09:15:16 +00:00
|
|
|
} catch (e) {
|
|
|
|
// If nsDocShell::Destroy has already been called, then we'll
|
2015-12-01 01:56:01 +00:00
|
|
|
// get NS_NOINTERFACE when trying to get the DOM window.
|
|
|
|
// If there is no current inner window, we'll get
|
|
|
|
// NS_ERROR_NOT_AVAILABLE.
|
2015-04-17 09:15:16 +00:00
|
|
|
}
|
|
|
|
|
2014-11-15 14:58:08 +00:00
|
|
|
aWebProgress = {
|
|
|
|
isTopLevel: aWebProgress.isTopLevel,
|
|
|
|
isLoadingDocument: aWebProgress.isLoadingDocument,
|
2015-02-10 17:28:31 +00:00
|
|
|
loadType: aWebProgress.loadType,
|
2015-04-17 09:15:16 +00:00
|
|
|
DOMWindowID: domWindowID
|
2014-11-15 14:58:08 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2013-04-25 05:29:31 +00:00
|
|
|
return {
|
2014-11-15 14:58:08 +00:00
|
|
|
webProgress: aWebProgress || null,
|
2014-09-25 03:34:47 +00:00
|
|
|
requestURI: this._requestSpec(aRequest, "URI"),
|
|
|
|
originalRequestURI: this._requestSpec(aRequest, "originalURI"),
|
2015-12-01 01:56:01 +00:00
|
|
|
documentContentType: content.document && content.document.contentType,
|
|
|
|
innerWindowID,
|
2013-04-25 05:29:31 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2015-04-03 14:46:53 +00:00
|
|
|
_setupObjects: function setupObjects(aWebProgress, aRequest) {
|
2014-11-19 00:20:59 +00:00
|
|
|
let domWindow;
|
|
|
|
try {
|
|
|
|
domWindow = aWebProgress && aWebProgress.DOMWindow;
|
|
|
|
} catch (e) {
|
|
|
|
// If nsDocShell::Destroy has already been called, then we'll
|
|
|
|
// get NS_NOINTERFACE when trying to get the DOM window. Ignore
|
|
|
|
// that here.
|
|
|
|
domWindow = null;
|
|
|
|
}
|
|
|
|
|
2013-07-17 13:27:49 +00:00
|
|
|
return {
|
2013-11-19 21:20:15 +00:00
|
|
|
contentWindow: content,
|
2013-07-17 13:27:49 +00:00
|
|
|
// DOMWindow is not necessarily the content-window with subframes.
|
2015-04-03 14:46:53 +00:00
|
|
|
DOMWindow: domWindow,
|
|
|
|
webProgress: aWebProgress,
|
|
|
|
request: aRequest,
|
2013-07-17 13:27:49 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2015-04-03 14:46:53 +00:00
|
|
|
_send(name, data, objects) {
|
|
|
|
if (RemoteAddonsChild.useSyncWebProgress) {
|
|
|
|
sendRpcMessage(name, data, objects);
|
|
|
|
} else {
|
|
|
|
sendAsyncMessage(name, data, objects);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-04-25 05:29:31 +00:00
|
|
|
onStateChange: function onStateChange(aWebProgress, aRequest, aStateFlags, aStatus) {
|
|
|
|
let json = this._setupJSON(aWebProgress, aRequest);
|
2015-04-03 14:46:53 +00:00
|
|
|
let objects = this._setupObjects(aWebProgress, aRequest);
|
2013-07-17 13:27:49 +00:00
|
|
|
|
2013-04-25 05:29:31 +00:00
|
|
|
json.stateFlags = aStateFlags;
|
|
|
|
json.status = aStatus;
|
|
|
|
|
2015-04-03 14:46:53 +00:00
|
|
|
this._send("Content:StateChange", json, objects);
|
2013-04-25 05:29:31 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onProgressChange: function onProgressChange(aWebProgress, aRequest, aCurSelf, aMaxSelf, aCurTotal, aMaxTotal) {
|
2014-12-03 22:14:23 +00:00
|
|
|
let json = this._setupJSON(aWebProgress, aRequest);
|
2015-04-03 14:46:53 +00:00
|
|
|
let objects = this._setupObjects(aWebProgress, aRequest);
|
2014-12-03 22:14:23 +00:00
|
|
|
|
|
|
|
json.curSelf = aCurSelf;
|
|
|
|
json.maxSelf = aMaxSelf;
|
|
|
|
json.curTotal = aCurTotal;
|
|
|
|
json.maxTotal = aMaxTotal;
|
|
|
|
|
2015-04-03 14:46:53 +00:00
|
|
|
this._send("Content:ProgressChange", json, objects);
|
2014-12-03 22:14:23 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onProgressChange64: function onProgressChange(aWebProgress, aRequest, aCurSelf, aMaxSelf, aCurTotal, aMaxTotal) {
|
|
|
|
this.onProgressChange(aWebProgress, aRequest, aCurSelf, aMaxSelf, aCurTotal, aMaxTotal);
|
2013-04-25 05:29:31 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onLocationChange: function onLocationChange(aWebProgress, aRequest, aLocationURI, aFlags) {
|
|
|
|
let json = this._setupJSON(aWebProgress, aRequest);
|
2015-04-03 14:46:53 +00:00
|
|
|
let objects = this._setupObjects(aWebProgress, aRequest);
|
2013-07-17 13:27:49 +00:00
|
|
|
|
2013-09-05 23:24:29 +00:00
|
|
|
json.location = aLocationURI ? aLocationURI.spec : "";
|
2013-11-22 06:39:05 +00:00
|
|
|
json.flags = aFlags;
|
2013-09-05 23:24:29 +00:00
|
|
|
|
2014-08-28 20:37:16 +00:00
|
|
|
// These properties can change even for a sub-frame navigation.
|
2015-04-01 21:20:09 +00:00
|
|
|
let webNav = docShell.QueryInterface(Ci.nsIWebNavigation);
|
|
|
|
json.canGoBack = webNav.canGoBack;
|
|
|
|
json.canGoForward = webNav.canGoForward;
|
2014-08-28 20:37:16 +00:00
|
|
|
|
2014-11-15 14:58:08 +00:00
|
|
|
if (aWebProgress && aWebProgress.isTopLevel) {
|
2013-09-05 23:24:29 +00:00
|
|
|
json.documentURI = content.document.documentURIObject.spec;
|
2015-04-08 23:44:17 +00:00
|
|
|
json.title = content.document.title;
|
2013-09-05 23:24:29 +00:00
|
|
|
json.charset = content.document.characterSet;
|
2014-08-13 17:29:00 +00:00
|
|
|
json.mayEnableCharacterEncodingMenu = docShell.mayEnableCharacterEncodingMenu;
|
2014-09-18 23:26:50 +00:00
|
|
|
json.principal = content.document.nodePrincipal;
|
2015-03-04 00:58:53 +00:00
|
|
|
json.synthetic = content.document.mozSyntheticDocument;
|
2015-05-15 17:00:11 +00:00
|
|
|
|
|
|
|
if (AppConstants.MOZ_CRASHREPORTER && CrashReporter.enabled) {
|
|
|
|
let uri = aLocationURI.clone();
|
|
|
|
try {
|
|
|
|
// If the current URI contains a username/password, remove it.
|
|
|
|
uri.userPass = "";
|
|
|
|
} catch (ex) { /* Ignore failures on about: URIs. */ }
|
|
|
|
CrashReporter.annotateCrashReport("URL", uri.spec);
|
|
|
|
}
|
2013-09-05 23:24:29 +00:00
|
|
|
}
|
2013-04-25 05:29:31 +00:00
|
|
|
|
2015-04-03 14:46:53 +00:00
|
|
|
this._send("Content:LocationChange", json, objects);
|
2013-04-25 05:29:31 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onStatusChange: function onStatusChange(aWebProgress, aRequest, aStatus, aMessage) {
|
|
|
|
let json = this._setupJSON(aWebProgress, aRequest);
|
2015-04-03 14:46:53 +00:00
|
|
|
let objects = this._setupObjects(aWebProgress, aRequest);
|
2013-07-17 13:27:49 +00:00
|
|
|
|
2013-04-25 05:29:31 +00:00
|
|
|
json.status = aStatus;
|
|
|
|
json.message = aMessage;
|
|
|
|
|
2015-04-03 14:46:53 +00:00
|
|
|
this._send("Content:StatusChange", json, objects);
|
2013-04-25 05:29:31 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onSecurityChange: function onSecurityChange(aWebProgress, aRequest, aState) {
|
|
|
|
let json = this._setupJSON(aWebProgress, aRequest);
|
2015-04-03 14:46:53 +00:00
|
|
|
let objects = this._setupObjects(aWebProgress, aRequest);
|
2013-07-17 13:27:49 +00:00
|
|
|
|
2013-04-25 05:29:31 +00:00
|
|
|
json.state = aState;
|
2013-07-10 02:45:07 +00:00
|
|
|
json.status = SecurityUI.getSSLStatusAsString();
|
2013-04-25 05:29:31 +00:00
|
|
|
|
2015-04-03 14:46:53 +00:00
|
|
|
this._send("Content:SecurityChange", json, objects);
|
2013-04-25 05:29:31 +00:00
|
|
|
},
|
|
|
|
|
2014-12-03 22:14:23 +00:00
|
|
|
onRefreshAttempted: function onRefreshAttempted(aWebProgress, aURI, aDelay, aSameURI) {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2013-04-25 05:29:31 +00:00
|
|
|
QueryInterface: function QueryInterface(aIID) {
|
|
|
|
if (aIID.equals(Ci.nsIWebProgressListener) ||
|
2014-12-03 22:14:23 +00:00
|
|
|
aIID.equals(Ci.nsIWebProgressListener2) ||
|
2013-04-25 05:29:31 +00:00
|
|
|
aIID.equals(Ci.nsISupportsWeakReference) ||
|
|
|
|
aIID.equals(Ci.nsISupports)) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
WebProgressListener.init();
|
2014-11-23 09:28:20 +00:00
|
|
|
addEventListener("unload", () => {
|
|
|
|
WebProgressListener.uninit();
|
|
|
|
});
|
2013-04-25 05:29:31 +00:00
|
|
|
|
2015-09-15 18:19:45 +00:00
|
|
|
var WebNavigation = {
|
2013-04-25 05:29:31 +00:00
|
|
|
init: function() {
|
|
|
|
addMessageListener("WebNavigation:GoBack", this);
|
|
|
|
addMessageListener("WebNavigation:GoForward", this);
|
|
|
|
addMessageListener("WebNavigation:GotoIndex", this);
|
|
|
|
addMessageListener("WebNavigation:LoadURI", this);
|
|
|
|
addMessageListener("WebNavigation:Reload", this);
|
|
|
|
addMessageListener("WebNavigation:Stop", this);
|
2015-03-28 22:48:16 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
get webNavigation() {
|
|
|
|
return docShell.QueryInterface(Ci.nsIWebNavigation);
|
2013-04-25 05:29:31 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
receiveMessage: function(message) {
|
|
|
|
switch (message.name) {
|
|
|
|
case "WebNavigation:GoBack":
|
|
|
|
this.goBack();
|
|
|
|
break;
|
|
|
|
case "WebNavigation:GoForward":
|
|
|
|
this.goForward();
|
|
|
|
break;
|
|
|
|
case "WebNavigation:GotoIndex":
|
2013-10-28 19:24:51 +00:00
|
|
|
this.gotoIndex(message.data.index);
|
2013-04-25 05:29:31 +00:00
|
|
|
break;
|
|
|
|
case "WebNavigation:LoadURI":
|
2015-01-05 17:42:31 +00:00
|
|
|
this.loadURI(message.data.uri, message.data.flags,
|
|
|
|
message.data.referrer, message.data.referrerPolicy,
|
2015-07-09 17:18:11 +00:00
|
|
|
message.data.postData, message.data.headers,
|
2015-01-05 17:42:31 +00:00
|
|
|
message.data.baseURI);
|
2013-04-25 05:29:31 +00:00
|
|
|
break;
|
|
|
|
case "WebNavigation:Reload":
|
2013-10-28 19:24:51 +00:00
|
|
|
this.reload(message.data.flags);
|
2013-04-25 05:29:31 +00:00
|
|
|
break;
|
|
|
|
case "WebNavigation:Stop":
|
2013-10-28 19:24:51 +00:00
|
|
|
this.stop(message.data.flags);
|
2013-04-25 05:29:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
goBack: function() {
|
2015-03-28 22:48:16 +00:00
|
|
|
if (this.webNavigation.canGoBack) {
|
|
|
|
this.webNavigation.goBack();
|
2014-08-28 20:37:16 +00:00
|
|
|
}
|
2013-04-25 05:29:31 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
goForward: function() {
|
2015-03-28 22:48:16 +00:00
|
|
|
if (this.webNavigation.canGoForward)
|
|
|
|
this.webNavigation.goForward();
|
2013-04-25 05:29:31 +00:00
|
|
|
},
|
|
|
|
|
2013-10-28 19:24:51 +00:00
|
|
|
gotoIndex: function(index) {
|
2015-03-28 22:48:16 +00:00
|
|
|
this.webNavigation.gotoIndex(index);
|
2013-04-25 05:29:31 +00:00
|
|
|
},
|
|
|
|
|
2015-07-09 17:18:11 +00:00
|
|
|
loadURI: function(uri, flags, referrer, referrerPolicy, postData, headers, baseURI) {
|
2015-05-15 17:00:11 +00:00
|
|
|
if (AppConstants.MOZ_CRASHREPORTER && CrashReporter.enabled) {
|
|
|
|
let annotation = uri;
|
|
|
|
try {
|
|
|
|
let url = Services.io.newURI(uri, null, null);
|
|
|
|
// If the current URI contains a username/password, remove it.
|
|
|
|
url.userPass = "";
|
|
|
|
annotation = url.spec;
|
|
|
|
} catch (ex) { /* Ignore failures to parse and failures
|
|
|
|
on about: URIs. */ }
|
|
|
|
CrashReporter.annotateCrashReport("URL", annotation);
|
|
|
|
}
|
2014-11-04 20:05:08 +00:00
|
|
|
if (referrer)
|
|
|
|
referrer = Services.io.newURI(referrer, null, null);
|
2015-07-09 17:18:11 +00:00
|
|
|
if (postData)
|
|
|
|
postData = makeInputStream(postData);
|
|
|
|
if (headers)
|
|
|
|
headers = makeInputStream(headers);
|
2015-01-05 17:42:31 +00:00
|
|
|
if (baseURI)
|
|
|
|
baseURI = Services.io.newURI(baseURI, null, null);
|
2015-03-28 22:48:16 +00:00
|
|
|
this.webNavigation.loadURIWithOptions(uri, flags, referrer, referrerPolicy,
|
2015-07-09 17:18:11 +00:00
|
|
|
postData, headers, baseURI);
|
2013-04-25 05:29:31 +00:00
|
|
|
},
|
|
|
|
|
2013-10-28 19:24:51 +00:00
|
|
|
reload: function(flags) {
|
2015-03-28 22:48:16 +00:00
|
|
|
this.webNavigation.reload(flags);
|
2013-04-25 05:29:31 +00:00
|
|
|
},
|
|
|
|
|
2013-10-28 19:24:51 +00:00
|
|
|
stop: function(flags) {
|
2015-03-28 22:48:16 +00:00
|
|
|
this.webNavigation.stop(flags);
|
2013-04-25 05:29:31 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
WebNavigation.init();
|
2013-04-25 05:29:39 +00:00
|
|
|
|
2015-09-15 18:19:45 +00:00
|
|
|
var SecurityUI = {
|
2013-07-10 02:45:07 +00:00
|
|
|
getSSLStatusAsString: function() {
|
|
|
|
let status = docShell.securityUI.QueryInterface(Ci.nsISSLStatusProvider).SSLStatus;
|
|
|
|
|
|
|
|
if (status) {
|
|
|
|
let helper = Cc["@mozilla.org/network/serialization-helper;1"]
|
|
|
|
.getService(Ci.nsISerializationHelper);
|
|
|
|
|
|
|
|
status.QueryInterface(Ci.nsISerializable);
|
|
|
|
return helper.serializeToString(status);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-09-15 18:19:45 +00:00
|
|
|
var ControllerCommands = {
|
2013-08-21 17:24:53 +00:00
|
|
|
init: function () {
|
|
|
|
addMessageListener("ControllerCommands:Do", this);
|
|
|
|
},
|
|
|
|
|
|
|
|
receiveMessage: function(message) {
|
|
|
|
switch(message.name) {
|
|
|
|
case "ControllerCommands:Do":
|
|
|
|
if (docShell.isCommandEnabled(message.data))
|
|
|
|
docShell.doCommand(message.data);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ControllerCommands.init()
|
|
|
|
|
2013-04-25 05:29:39 +00:00
|
|
|
addEventListener("DOMTitleChanged", function (aEvent) {
|
|
|
|
let document = content.document;
|
|
|
|
switch (aEvent.type) {
|
|
|
|
case "DOMTitleChanged":
|
|
|
|
if (!aEvent.isTrusted || aEvent.target.defaultView != content)
|
|
|
|
return;
|
|
|
|
|
|
|
|
sendAsyncMessage("DOMTitleChanged", { title: document.title });
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}, false);
|
2013-07-29 15:03:41 +00:00
|
|
|
|
2014-03-18 14:58:02 +00:00
|
|
|
addEventListener("DOMWindowClose", function (aEvent) {
|
|
|
|
if (!aEvent.isTrusted)
|
|
|
|
return;
|
|
|
|
sendAsyncMessage("DOMWindowClose");
|
|
|
|
}, false);
|
|
|
|
|
2013-07-29 15:03:41 +00:00
|
|
|
addEventListener("ImageContentLoaded", function (aEvent) {
|
|
|
|
if (content.document instanceof Ci.nsIImageDocument) {
|
|
|
|
let req = content.document.imageRequest;
|
|
|
|
if (!req.image)
|
|
|
|
return;
|
|
|
|
sendAsyncMessage("ImageDocumentLoaded", { width: req.image.width,
|
|
|
|
height: req.image.height });
|
|
|
|
}
|
2013-08-29 04:43:00 +00:00
|
|
|
}, false);
|
|
|
|
|
2014-03-19 09:25:13 +00:00
|
|
|
const ZoomManager = {
|
|
|
|
get fullZoom() {
|
|
|
|
return this._cache.fullZoom;
|
|
|
|
},
|
|
|
|
|
|
|
|
get textZoom() {
|
|
|
|
return this._cache.textZoom;
|
|
|
|
},
|
|
|
|
|
|
|
|
set fullZoom(value) {
|
|
|
|
this._cache.fullZoom = value;
|
|
|
|
this._markupViewer.fullZoom = value;
|
|
|
|
},
|
|
|
|
|
|
|
|
set textZoom(value) {
|
|
|
|
this._cache.textZoom = value;
|
|
|
|
this._markupViewer.textZoom = value;
|
|
|
|
},
|
|
|
|
|
|
|
|
refreshFullZoom: function() {
|
|
|
|
return this._refreshZoomValue('fullZoom');
|
|
|
|
},
|
|
|
|
|
|
|
|
refreshTextZoom: function() {
|
|
|
|
return this._refreshZoomValue('textZoom');
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves specified zoom property value from markupViewer and refreshes
|
|
|
|
* cache if needed.
|
|
|
|
* @param valueName Either 'fullZoom' or 'textZoom'.
|
|
|
|
* @returns Returns true if cached value was actually refreshed.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_refreshZoomValue: function(valueName) {
|
|
|
|
let actualZoomValue = this._markupViewer[valueName];
|
2015-04-29 12:39:30 +00:00
|
|
|
// Round to remove any floating-point error.
|
|
|
|
actualZoomValue = Number(actualZoomValue.toFixed(2));
|
2014-03-19 09:25:13 +00:00
|
|
|
if (actualZoomValue != this._cache[valueName]) {
|
|
|
|
this._cache[valueName] = actualZoomValue;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
get _markupViewer() {
|
2014-07-09 21:27:49 +00:00
|
|
|
return docShell.contentViewer;
|
2014-03-19 09:25:13 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_cache: {
|
|
|
|
fullZoom: NaN,
|
|
|
|
textZoom: NaN
|
|
|
|
}
|
|
|
|
};
|
2014-01-13 17:36:26 +00:00
|
|
|
|
|
|
|
addMessageListener("FullZoom", function (aMessage) {
|
2014-03-19 09:25:13 +00:00
|
|
|
ZoomManager.fullZoom = aMessage.data.value;
|
2014-01-13 17:36:26 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
addMessageListener("TextZoom", function (aMessage) {
|
2014-03-19 09:25:13 +00:00
|
|
|
ZoomManager.textZoom = aMessage.data.value;
|
2014-01-13 17:36:26 +00:00
|
|
|
});
|
|
|
|
|
2014-03-19 09:25:13 +00:00
|
|
|
addEventListener("FullZoomChange", function () {
|
|
|
|
if (ZoomManager.refreshFullZoom()) {
|
|
|
|
sendAsyncMessage("FullZoomChange", { value: ZoomManager.fullZoom});
|
|
|
|
}
|
2014-01-13 17:36:26 +00:00
|
|
|
}, false);
|
|
|
|
|
|
|
|
addEventListener("TextZoomChange", function (aEvent) {
|
2014-03-19 09:25:13 +00:00
|
|
|
if (ZoomManager.refreshTextZoom()) {
|
|
|
|
sendAsyncMessage("TextZoomChange", { value: ZoomManager.textZoom});
|
|
|
|
}
|
2014-01-13 17:36:26 +00:00
|
|
|
}, false);
|
|
|
|
|
2014-08-20 15:13:35 +00:00
|
|
|
addEventListener("ZoomChangeUsingMouseWheel", function () {
|
|
|
|
sendAsyncMessage("ZoomChangeUsingMouseWheel", {});
|
|
|
|
}, false);
|
|
|
|
|
2014-08-13 17:29:00 +00:00
|
|
|
addMessageListener("UpdateCharacterSet", function (aMessage) {
|
|
|
|
docShell.charset = aMessage.data.value;
|
|
|
|
docShell.gatherCharsetMenuTelemetry();
|
|
|
|
});
|
|
|
|
|
2014-10-18 14:09:32 +00:00
|
|
|
/**
|
|
|
|
* Remote thumbnail request handler for PageThumbs thumbnails.
|
|
|
|
*/
|
|
|
|
addMessageListener("Browser:Thumbnail:Request", function (aMessage) {
|
2016-01-12 17:08:33 +00:00
|
|
|
let snapshot;
|
|
|
|
let args = aMessage.data.additionalArgs;
|
|
|
|
let fullScale = args ? args.fullScale : false;
|
|
|
|
if (fullScale) {
|
|
|
|
snapshot = PageThumbUtils.createSnapshotThumbnail(content, null, args);
|
|
|
|
} else {
|
|
|
|
let snapshotWidth = aMessage.data.canvasWidth;
|
|
|
|
let snapshotHeight = aMessage.data.canvasHeight;
|
|
|
|
snapshot =
|
|
|
|
PageThumbUtils.createCanvas(content, snapshotWidth, snapshotHeight);
|
|
|
|
PageThumbUtils.createSnapshotThumbnail(content, snapshot, args);
|
|
|
|
}
|
2015-09-25 18:27:16 +00:00
|
|
|
|
|
|
|
snapshot.toBlob(function (aBlob) {
|
2014-10-18 14:09:32 +00:00
|
|
|
sendAsyncMessage("Browser:Thumbnail:Response", {
|
|
|
|
thumbnail: aBlob,
|
|
|
|
id: aMessage.data.id
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-01-22 13:07:56 +00:00
|
|
|
/**
|
|
|
|
* Remote isSafeForCapture request handler for PageThumbs.
|
|
|
|
*/
|
|
|
|
addMessageListener("Browser:Thumbnail:CheckState", function (aMessage) {
|
|
|
|
let result = PageThumbUtils.shouldStoreContentThumbnail(content, docShell);
|
|
|
|
sendAsyncMessage("Browser:Thumbnail:CheckState:Response", {
|
|
|
|
result: result
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-07-16 18:13:33 +00:00
|
|
|
// The AddonsChild needs to be rooted so that it stays alive as long as
|
|
|
|
// the tab.
|
2015-09-15 18:19:45 +00:00
|
|
|
var AddonsChild = RemoteAddonsChild.init(this);
|
2015-07-07 08:56:26 +00:00
|
|
|
if (AddonsChild) {
|
|
|
|
addEventListener("unload", () => {
|
|
|
|
RemoteAddonsChild.uninit(AddonsChild);
|
|
|
|
});
|
|
|
|
}
|
2014-07-15 05:10:06 +00:00
|
|
|
|
2014-03-12 03:13:48 +00:00
|
|
|
addMessageListener("NetworkPrioritizer:AdjustPriority", (msg) => {
|
|
|
|
let webNav = docShell.QueryInterface(Ci.nsIWebNavigation);
|
|
|
|
let loadGroup = webNav.QueryInterface(Ci.nsIDocumentLoader)
|
|
|
|
.loadGroup.QueryInterface(Ci.nsISupportsPriority);
|
|
|
|
loadGroup.adjustPriority(msg.data.adjustment);
|
|
|
|
});
|
|
|
|
|
2015-09-15 18:19:45 +00:00
|
|
|
var AutoCompletePopup = {
|
2013-12-07 00:02:05 +00:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIAutoCompletePopup]),
|
|
|
|
|
|
|
|
init: function() {
|
|
|
|
// Hook up the form fill autocomplete controller.
|
|
|
|
let controller = Cc["@mozilla.org/satchel/form-fill-controller;1"]
|
|
|
|
.getService(Ci.nsIFormFillController);
|
|
|
|
|
|
|
|
controller.attachToBrowser(docShell, this.QueryInterface(Ci.nsIAutoCompletePopup));
|
|
|
|
|
|
|
|
this._input = null;
|
|
|
|
this._popupOpen = false;
|
|
|
|
|
|
|
|
addMessageListener("FormAutoComplete:HandleEnter", message => {
|
|
|
|
this.selectedIndex = message.data.selectedIndex;
|
|
|
|
|
|
|
|
let controller = Components.classes["@mozilla.org/autocomplete/controller;1"].
|
|
|
|
getService(Components.interfaces.nsIAutoCompleteController);
|
|
|
|
controller.handleEnter(message.data.isPopupSelection);
|
|
|
|
});
|
2015-02-19 00:47:43 +00:00
|
|
|
|
|
|
|
addEventListener("unload", function() {
|
|
|
|
AutoCompletePopup.destroy();
|
|
|
|
});
|
2013-12-07 00:02:05 +00:00
|
|
|
},
|
|
|
|
|
2015-02-07 17:16:30 +00:00
|
|
|
destroy: function() {
|
|
|
|
let controller = Cc["@mozilla.org/satchel/form-fill-controller;1"]
|
|
|
|
.getService(Ci.nsIFormFillController);
|
|
|
|
|
|
|
|
controller.detachFromBrowser(docShell);
|
|
|
|
},
|
|
|
|
|
2013-12-07 00:02:05 +00:00
|
|
|
get input () { return this._input; },
|
|
|
|
get overrideValue () { return null; },
|
|
|
|
set selectedIndex (index) { },
|
|
|
|
get selectedIndex () {
|
|
|
|
// selectedIndex getter must be synchronous because we need the
|
|
|
|
// correct value when the controller is in controller::HandleEnter.
|
|
|
|
// We can't easily just let the parent inform us the new value every
|
|
|
|
// time it changes because not every action that can change the
|
|
|
|
// selectedIndex is trivial to catch (e.g. moving the mouse over the
|
|
|
|
// list).
|
|
|
|
return sendSyncMessage("FormAutoComplete:GetSelectedIndex", {});
|
|
|
|
},
|
|
|
|
get popupOpen () {
|
|
|
|
return this._popupOpen;
|
|
|
|
},
|
|
|
|
|
|
|
|
openAutocompletePopup: function (input, element) {
|
2015-05-28 16:55:46 +00:00
|
|
|
if (!this._popupOpen) {
|
|
|
|
// The search itself normally opens the popup itself, but in some cases,
|
|
|
|
// nsAutoCompleteController tries to use cached results so notify our
|
|
|
|
// popup to reuse the last results.
|
|
|
|
sendAsyncMessage("FormAutoComplete:MaybeOpenPopup", {});
|
|
|
|
}
|
2013-12-07 00:02:05 +00:00
|
|
|
this._input = input;
|
|
|
|
this._popupOpen = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
closePopup: function () {
|
|
|
|
this._popupOpen = false;
|
|
|
|
sendAsyncMessage("FormAutoComplete:ClosePopup", {});
|
|
|
|
},
|
|
|
|
|
|
|
|
invalidate: function () {
|
|
|
|
},
|
|
|
|
|
|
|
|
selectBy: function(reverse, page) {
|
|
|
|
this._index = sendSyncMessage("FormAutoComplete:SelectBy", {
|
|
|
|
reverse: reverse,
|
|
|
|
page: page
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-24 20:32:09 +00:00
|
|
|
addMessageListener("InPermitUnload", msg => {
|
|
|
|
let inPermitUnload = docShell.contentViewer && docShell.contentViewer.inPermitUnload;
|
|
|
|
sendAsyncMessage("InPermitUnload", {id: msg.data.id, inPermitUnload});
|
|
|
|
});
|
|
|
|
|
|
|
|
addMessageListener("PermitUnload", msg => {
|
|
|
|
sendAsyncMessage("PermitUnload", {id: msg.data.id, kind: "start"});
|
|
|
|
|
|
|
|
let permitUnload = true;
|
|
|
|
if (docShell && docShell.contentViewer) {
|
|
|
|
permitUnload = docShell.contentViewer.permitUnload();
|
|
|
|
}
|
|
|
|
|
|
|
|
sendAsyncMessage("PermitUnload", {id: msg.data.id, kind: "end", permitUnload});
|
|
|
|
});
|
|
|
|
|
2014-08-19 22:48:58 +00:00
|
|
|
// We may not get any responses to Browser:Init if the browser element
|
|
|
|
// is torn down too quickly.
|
2015-09-15 18:19:45 +00:00
|
|
|
var outerWindowID = content.QueryInterface(Ci.nsIInterfaceRequestor)
|
2015-01-27 23:32:40 +00:00
|
|
|
.getInterface(Ci.nsIDOMWindowUtils)
|
|
|
|
.outerWindowID;
|
2015-09-15 18:19:45 +00:00
|
|
|
var initData = sendSyncMessage("Browser:Init", {outerWindowID: outerWindowID});
|
2014-08-19 22:48:58 +00:00
|
|
|
if (initData.length) {
|
|
|
|
docShell.useGlobalHistory = initData[0].useGlobalHistory;
|
|
|
|
if (initData[0].initPopup) {
|
|
|
|
setTimeout(() => AutoCompletePopup.init(), 0);
|
|
|
|
}
|
2014-03-12 03:13:52 +00:00
|
|
|
}
|