2013-04-24 22:29:31 -07: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/. */
|
|
|
|
|
|
|
|
let Cc = Components.classes;
|
|
|
|
let Ci = Components.interfaces;
|
|
|
|
let Cu = Components.utils;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
|
|
|
|
|
|
|
|
let WebProgressListener = {
|
|
|
|
init: function() {
|
|
|
|
let webProgress = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebProgress);
|
|
|
|
webProgress.addProgressListener(this, Ci.nsIWebProgress.NOTIFY_ALL);
|
|
|
|
},
|
|
|
|
|
|
|
|
_requestSpec: function (aRequest) {
|
|
|
|
if (!aRequest || !(aRequest instanceof Ci.nsIChannel))
|
|
|
|
return null;
|
|
|
|
return aRequest.QueryInterface(Ci.nsIChannel).URI.spec;
|
|
|
|
},
|
|
|
|
|
|
|
|
_setupJSON: function setupJSON(aWebProgress, aRequest) {
|
|
|
|
return {
|
|
|
|
isTopLevel: aWebProgress.isTopLevel,
|
|
|
|
requestURI: this._requestSpec(aRequest)
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2013-07-17 06:27:49 -07:00
|
|
|
_setupObjects: function setupObjects(aWebProgress) {
|
|
|
|
let win = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindow);
|
|
|
|
return {
|
|
|
|
contentWindow: win,
|
|
|
|
// DOMWindow is not necessarily the content-window with subframes.
|
|
|
|
DOMWindow: aWebProgress.DOMWindow
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2013-04-24 22:29:31 -07:00
|
|
|
onStateChange: function onStateChange(aWebProgress, aRequest, aStateFlags, aStatus) {
|
|
|
|
let json = this._setupJSON(aWebProgress, aRequest);
|
2013-07-17 06:27:49 -07:00
|
|
|
let objects = this._setupObjects(aWebProgress);
|
|
|
|
|
2013-04-24 22:29:31 -07:00
|
|
|
json.stateFlags = aStateFlags;
|
|
|
|
json.status = aStatus;
|
|
|
|
|
2013-07-17 06:27:49 -07:00
|
|
|
sendAsyncMessage("Content:StateChange", json, objects);
|
2013-04-24 22:29:31 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
onProgressChange: function onProgressChange(aWebProgress, aRequest, aCurSelf, aMaxSelf, aCurTotal, aMaxTotal) {
|
|
|
|
},
|
|
|
|
|
|
|
|
onLocationChange: function onLocationChange(aWebProgress, aRequest, aLocationURI, aFlags) {
|
|
|
|
let spec = aLocationURI ? aLocationURI.spec : "";
|
|
|
|
let charset = content.document.characterSet;
|
|
|
|
|
|
|
|
let json = this._setupJSON(aWebProgress, aRequest);
|
2013-07-17 06:27:49 -07:00
|
|
|
let objects = this._setupObjects(aWebProgress);
|
|
|
|
|
2013-04-24 22:29:31 -07:00
|
|
|
json.documentURI = aWebProgress.DOMWindow.document.documentURIObject.spec;
|
|
|
|
json.location = spec;
|
|
|
|
json.canGoBack = docShell.canGoBack;
|
|
|
|
json.canGoForward = docShell.canGoForward;
|
|
|
|
json.charset = charset.toString();
|
|
|
|
|
2013-07-17 06:27:49 -07:00
|
|
|
sendAsyncMessage("Content:LocationChange", json, objects);
|
2013-04-24 22:29:31 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
onStatusChange: function onStatusChange(aWebProgress, aRequest, aStatus, aMessage) {
|
|
|
|
let json = this._setupJSON(aWebProgress, aRequest);
|
2013-07-17 06:27:49 -07:00
|
|
|
let objects = this._setupObjects(aWebProgress);
|
|
|
|
|
2013-04-24 22:29:31 -07:00
|
|
|
json.status = aStatus;
|
|
|
|
json.message = aMessage;
|
|
|
|
|
2013-07-17 06:27:49 -07:00
|
|
|
sendAsyncMessage("Content:StatusChange", json, objects);
|
2013-04-24 22:29:31 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
onSecurityChange: function onSecurityChange(aWebProgress, aRequest, aState) {
|
|
|
|
let json = this._setupJSON(aWebProgress, aRequest);
|
2013-07-17 06:27:49 -07:00
|
|
|
let objects = this._setupObjects(aWebProgress);
|
|
|
|
|
2013-04-24 22:29:31 -07:00
|
|
|
json.state = aState;
|
2013-07-09 19:45:07 -07:00
|
|
|
json.status = SecurityUI.getSSLStatusAsString();
|
2013-04-24 22:29:31 -07:00
|
|
|
|
2013-07-17 06:27:49 -07:00
|
|
|
sendAsyncMessage("Content:SecurityChange", json, objects);
|
2013-04-24 22:29:31 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
QueryInterface: function QueryInterface(aIID) {
|
|
|
|
if (aIID.equals(Ci.nsIWebProgressListener) ||
|
|
|
|
aIID.equals(Ci.nsISupportsWeakReference) ||
|
|
|
|
aIID.equals(Ci.nsISupports)) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
WebProgressListener.init();
|
|
|
|
|
|
|
|
let WebNavigation = {
|
|
|
|
_webNavigation: docShell.QueryInterface(Ci.nsIWebNavigation),
|
|
|
|
|
|
|
|
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);
|
|
|
|
},
|
|
|
|
|
|
|
|
receiveMessage: function(message) {
|
|
|
|
switch (message.name) {
|
|
|
|
case "WebNavigation:GoBack":
|
|
|
|
this.goBack();
|
|
|
|
break;
|
|
|
|
case "WebNavigation:GoForward":
|
|
|
|
this.goForward();
|
|
|
|
break;
|
|
|
|
case "WebNavigation:GotoIndex":
|
|
|
|
this.gotoIndex(message);
|
|
|
|
break;
|
|
|
|
case "WebNavigation:LoadURI":
|
|
|
|
this.loadURI(message);
|
|
|
|
break;
|
|
|
|
case "WebNavigation:Reload":
|
|
|
|
this.reload(message);
|
|
|
|
break;
|
|
|
|
case "WebNavigation:Stop":
|
|
|
|
this.stop(message);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
goBack: function() {
|
|
|
|
if (this._webNavigation.canGoBack)
|
|
|
|
this._webNavigation.goBack();
|
|
|
|
},
|
|
|
|
|
|
|
|
goForward: function() {
|
|
|
|
if (this._webNavigation.canGoForward)
|
|
|
|
this._webNavigation.goForward();
|
|
|
|
},
|
|
|
|
|
|
|
|
gotoIndex: function(message) {
|
|
|
|
this._webNavigation.gotoIndex(message.index);
|
|
|
|
},
|
|
|
|
|
|
|
|
loadURI: function(message) {
|
|
|
|
let flags = message.json.flags || this._webNavigation.LOAD_FLAGS_NONE;
|
|
|
|
this._webNavigation.loadURI(message.json.uri, flags, null, null, null);
|
|
|
|
},
|
|
|
|
|
|
|
|
reload: function(message) {
|
|
|
|
let flags = message.json.flags || this._webNavigation.LOAD_FLAGS_NONE;
|
|
|
|
this._webNavigation.reload(flags);
|
|
|
|
},
|
|
|
|
|
|
|
|
stop: function(message) {
|
|
|
|
let flags = message.json.flags || this._webNavigation.STOP_ALL;
|
|
|
|
this._webNavigation.stop(flags);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
WebNavigation.init();
|
2013-04-24 22:29:39 -07:00
|
|
|
|
2013-07-09 19:45:07 -07:00
|
|
|
let SecurityUI = {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-04-24 22:29:39 -07: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);
|