2014-06-25 09:12:07 +04:00
|
|
|
// -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
|
2013-04-25 09:29:31 +04: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/.
|
|
|
|
|
2018-02-23 22:50:01 +03:00
|
|
|
var EXPORTED_SYMBOLS = ["RemoteWebProgressManager"];
|
2013-04-25 09:29:31 +04:00
|
|
|
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
2013-07-29 19:03:41 +04:00
|
|
|
|
2018-02-05 16:53:21 +03:00
|
|
|
function RemoteWebProgressRequest(spec, originalSpec, matchedList, requestCPOW) {
|
2015-04-03 17:46:53 +03:00
|
|
|
this.wrappedJSObject = this;
|
|
|
|
|
2017-11-09 19:36:57 +03:00
|
|
|
this._uri = Services.io.newURI(spec);
|
|
|
|
this._originalURI = Services.io.newURI(originalSpec);
|
2015-04-03 17:46:53 +03:00
|
|
|
this._requestCPOW = requestCPOW;
|
2018-02-05 16:53:21 +03:00
|
|
|
this._matchedList = matchedList;
|
2013-04-25 09:29:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
RemoteWebProgressRequest.prototype = {
|
2018-04-23 06:55:06 +03:00
|
|
|
QueryInterface: ChromeUtils.generateQI([Ci.nsIChannel, Ci.nsIClassifiedChannel]),
|
2013-04-25 09:29:31 +04:00
|
|
|
|
2018-06-14 14:05:43 +03:00
|
|
|
get URI() { return this._uri; },
|
|
|
|
get originalURI() { return this._originalURI; },
|
2018-08-31 08:59:17 +03:00
|
|
|
get matchedList() { return this._matchedList; },
|
2013-04-25 09:29:31 +04:00
|
|
|
};
|
|
|
|
|
2013-09-06 21:10:11 +04:00
|
|
|
function RemoteWebProgress(aManager, aIsTopLevel) {
|
2015-04-03 17:46:53 +03:00
|
|
|
this.wrappedJSObject = this;
|
|
|
|
|
2013-09-06 21:10:11 +04:00
|
|
|
this._manager = aManager;
|
|
|
|
|
2013-07-29 19:03:41 +04:00
|
|
|
this._isLoadingDocument = false;
|
2013-07-17 17:27:49 +04:00
|
|
|
this._DOMWindow = null;
|
2015-02-10 20:28:31 +03:00
|
|
|
this._DOMWindowID = 0;
|
2013-09-06 21:10:11 +04:00
|
|
|
this._isTopLevel = aIsTopLevel;
|
2013-07-29 19:03:41 +04:00
|
|
|
this._loadType = 0;
|
2013-04-25 09:29:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
RemoteWebProgress.prototype = {
|
|
|
|
NOTIFY_STATE_REQUEST: 0x00000001,
|
|
|
|
NOTIFY_STATE_DOCUMENT: 0x00000002,
|
|
|
|
NOTIFY_STATE_NETWORK: 0x00000004,
|
|
|
|
NOTIFY_STATE_WINDOW: 0x00000008,
|
|
|
|
NOTIFY_STATE_ALL: 0x0000000f,
|
|
|
|
NOTIFY_PROGRESS: 0x00000010,
|
|
|
|
NOTIFY_STATUS: 0x00000020,
|
|
|
|
NOTIFY_SECURITY: 0x00000040,
|
|
|
|
NOTIFY_LOCATION: 0x00000080,
|
|
|
|
NOTIFY_REFRESH: 0x00000100,
|
|
|
|
NOTIFY_ALL: 0x000001ff,
|
|
|
|
|
2017-10-15 21:50:30 +03:00
|
|
|
get isLoadingDocument() { return this._isLoadingDocument; },
|
2013-07-17 17:27:49 +04:00
|
|
|
get DOMWindow() { return this._DOMWindow; },
|
2015-02-10 20:28:31 +03:00
|
|
|
get DOMWindowID() { return this._DOMWindowID; },
|
2017-10-15 21:50:30 +03:00
|
|
|
get isTopLevel() { return this._isTopLevel; },
|
2013-07-29 19:03:41 +04:00
|
|
|
get loadType() { return this._loadType; },
|
2013-04-25 09:29:31 +04:00
|
|
|
|
2017-04-12 00:17:31 +03:00
|
|
|
addProgressListener(aListener, aNotifyMask) {
|
|
|
|
this._manager.addProgressListener(aListener, aNotifyMask);
|
2013-09-06 21:10:11 +04:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
removeProgressListener(aListener) {
|
2013-09-06 21:10:11 +04:00
|
|
|
this._manager.removeProgressListener(aListener);
|
2018-08-31 08:59:17 +03:00
|
|
|
},
|
2013-09-06 21:10:11 +04:00
|
|
|
};
|
|
|
|
|
2016-11-12 02:22:34 +03:00
|
|
|
function RemoteWebProgressManager(aBrowser) {
|
2013-09-06 21:10:11 +04:00
|
|
|
this._topLevelWebProgress = new RemoteWebProgress(this, true);
|
|
|
|
this._progressListeners = [];
|
|
|
|
|
2015-02-19 03:47:43 +03:00
|
|
|
this.swapBrowser(aBrowser);
|
2013-09-06 21:10:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
RemoteWebProgressManager.prototype = {
|
2016-12-30 02:34:54 +03:00
|
|
|
swapBrowser(aBrowser) {
|
2015-02-19 03:47:43 +03:00
|
|
|
if (this._messageManager) {
|
|
|
|
this._messageManager.removeMessageListener("Content:StateChange", this);
|
|
|
|
this._messageManager.removeMessageListener("Content:LocationChange", this);
|
|
|
|
this._messageManager.removeMessageListener("Content:SecurityChange", this);
|
|
|
|
this._messageManager.removeMessageListener("Content:StatusChange", this);
|
|
|
|
this._messageManager.removeMessageListener("Content:ProgressChange", this);
|
2016-02-16 17:08:14 +03:00
|
|
|
this._messageManager.removeMessageListener("Content:LoadURIResult", this);
|
2015-02-19 03:47:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
this._browser = aBrowser;
|
|
|
|
this._messageManager = aBrowser.messageManager;
|
|
|
|
this._messageManager.addMessageListener("Content:StateChange", this);
|
|
|
|
this._messageManager.addMessageListener("Content:LocationChange", this);
|
|
|
|
this._messageManager.addMessageListener("Content:SecurityChange", this);
|
|
|
|
this._messageManager.addMessageListener("Content:StatusChange", this);
|
|
|
|
this._messageManager.addMessageListener("Content:ProgressChange", this);
|
2016-02-16 17:08:14 +03:00
|
|
|
this._messageManager.addMessageListener("Content:LoadURIResult", this);
|
2015-02-19 03:47:43 +03:00
|
|
|
},
|
|
|
|
|
2013-09-06 21:10:11 +04:00
|
|
|
get topLevelWebProgress() {
|
|
|
|
return this._topLevelWebProgress;
|
|
|
|
},
|
|
|
|
|
2017-04-12 00:17:31 +03:00
|
|
|
addProgressListener(aListener, aNotifyMask) {
|
2013-04-25 09:29:31 +04:00
|
|
|
let listener = aListener.QueryInterface(Ci.nsIWebProgressListener);
|
2017-04-12 00:17:31 +03:00
|
|
|
this._progressListeners.push({
|
|
|
|
listener,
|
2018-08-31 08:59:17 +03:00
|
|
|
mask: aNotifyMask || Ci.nsIWebProgress.NOTIFY_ALL,
|
2017-04-12 00:17:31 +03:00
|
|
|
});
|
2013-04-25 09:29:31 +04:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
removeProgressListener(aListener) {
|
2013-04-25 09:29:31 +04:00
|
|
|
this._progressListeners =
|
2017-04-12 00:17:31 +03:00
|
|
|
this._progressListeners.filter(l => l.listener != aListener);
|
2013-04-25 09:29:31 +04:00
|
|
|
},
|
|
|
|
|
2018-07-13 21:48:55 +03:00
|
|
|
_fixSecInfoAndState(aSecInfo, aState) {
|
2013-09-06 21:10:11 +04:00
|
|
|
let deserialized = null;
|
2018-07-13 21:48:55 +03:00
|
|
|
if (aSecInfo) {
|
2013-09-06 21:10:11 +04:00
|
|
|
let helper = Cc["@mozilla.org/network/serialization-helper;1"]
|
2018-02-28 20:51:33 +03:00
|
|
|
.getService(Ci.nsISerializationHelper);
|
2013-09-06 21:10:11 +04:00
|
|
|
|
2018-07-13 21:48:55 +03:00
|
|
|
deserialized = helper.deserializeObject(aSecInfo);
|
|
|
|
deserialized.QueryInterface(Ci.nsITransportSecurityInfo);
|
2013-09-06 21:10:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return [deserialized, aState];
|
2013-04-25 09:29:31 +04:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
setCurrentURI(aURI) {
|
2013-11-13 03:02:14 +04:00
|
|
|
// This function is simpler than nsDocShell::SetCurrentURI since
|
|
|
|
// it doesn't have to deal with child docshells.
|
2016-01-13 00:44:08 +03:00
|
|
|
let remoteWebNav = this._browser._remoteWebNavigationImpl;
|
|
|
|
remoteWebNav._currentURI = aURI;
|
2013-11-13 03:02:14 +04:00
|
|
|
|
|
|
|
let webProgress = this.topLevelWebProgress;
|
2017-04-12 00:17:31 +03:00
|
|
|
for (let { listener, mask } of this._progressListeners) {
|
|
|
|
if (mask & Ci.nsIWebProgress.NOTIFY_LOCATION) {
|
|
|
|
listener.onLocationChange(webProgress, null, aURI);
|
|
|
|
}
|
2013-11-13 03:02:14 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-04-12 00:17:31 +03:00
|
|
|
_callProgressListeners(type, methodName, ...args) {
|
|
|
|
for (let { listener, mask } of this._progressListeners) {
|
|
|
|
if ((mask & type) && listener[methodName]) {
|
2013-11-07 03:43:59 +04:00
|
|
|
try {
|
2017-04-12 00:17:31 +03:00
|
|
|
listener[methodName].apply(listener, args);
|
2013-11-07 03:43:59 +04:00
|
|
|
} catch (ex) {
|
|
|
|
Cu.reportError("RemoteWebProgress failed to call " + methodName + ": " + ex + "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
receiveMessage(aMessage) {
|
2013-09-06 21:10:11 +04:00
|
|
|
let json = aMessage.json;
|
|
|
|
let objects = aMessage.objects;
|
2016-03-08 23:04:10 +03:00
|
|
|
// This message is a custom one we send as a result of a loadURI call.
|
|
|
|
// It shouldn't go through the same processing as all the forwarded
|
|
|
|
// webprogresslistener messages.
|
|
|
|
if (aMessage.name == "Content:LoadURIResult") {
|
|
|
|
this._browser.inLoadURI = false;
|
|
|
|
return;
|
|
|
|
}
|
2013-09-06 21:10:11 +04:00
|
|
|
|
2014-11-15 17:58:08 +03:00
|
|
|
let webProgress = null;
|
|
|
|
let isTopLevel = json.webProgress && json.webProgress.isTopLevel;
|
2013-09-06 21:10:11 +04:00
|
|
|
// The top-level WebProgress is always the same, but because we don't
|
2014-11-15 17:58:08 +03:00
|
|
|
// really have a concept of subframes/content we always create a new object
|
2013-09-06 21:10:11 +04:00
|
|
|
// for those.
|
2014-11-15 17:58:08 +03:00
|
|
|
if (json.webProgress) {
|
|
|
|
webProgress = isTopLevel ? this._topLevelWebProgress
|
|
|
|
: new RemoteWebProgress(this, false);
|
|
|
|
|
|
|
|
// Update the actual WebProgress fields.
|
|
|
|
webProgress._isLoadingDocument = json.webProgress.isLoadingDocument;
|
|
|
|
webProgress._DOMWindow = objects.DOMWindow;
|
2015-02-10 20:28:31 +03:00
|
|
|
webProgress._DOMWindowID = json.webProgress.DOMWindowID;
|
2014-11-15 17:58:08 +03:00
|
|
|
webProgress._loadType = json.webProgress.loadType;
|
2015-04-03 17:46:53 +03:00
|
|
|
webProgress._webProgressCPOW = objects.webProgress;
|
2014-11-15 17:58:08 +03:00
|
|
|
}
|
2013-09-06 21:10:11 +04:00
|
|
|
|
|
|
|
// The WebProgressRequest object however is always dynamic.
|
2014-09-25 07:34:47 +04:00
|
|
|
let request = null;
|
|
|
|
if (json.requestURI) {
|
|
|
|
request = new RemoteWebProgressRequest(json.requestURI,
|
2015-04-03 17:46:53 +03:00
|
|
|
json.originalRequestURI,
|
2018-02-05 16:53:21 +03:00
|
|
|
json.matchedList,
|
2015-04-03 17:46:53 +03:00
|
|
|
objects.request);
|
2014-09-25 07:34:47 +04:00
|
|
|
}
|
2013-09-06 21:10:11 +04:00
|
|
|
|
2014-11-15 17:58:08 +03:00
|
|
|
if (isTopLevel) {
|
2013-09-06 21:10:11 +04:00
|
|
|
this._browser._contentWindow = objects.contentWindow;
|
2017-12-05 03:19:43 +03:00
|
|
|
this._browser._contentDocument = objects.contentDocument;
|
2017-10-10 20:14:01 +03:00
|
|
|
// Setting a content-type back to `null` is quite nonsensical for the
|
|
|
|
// frontend, especially since we're not expecting it.
|
|
|
|
if (json.documentContentType !== null) {
|
|
|
|
this._browser._documentContentType = json.documentContentType;
|
|
|
|
}
|
2016-04-13 21:32:45 +03:00
|
|
|
if (typeof json.inLoadURI != "undefined") {
|
|
|
|
this._browser.inLoadURI = json.inLoadURI;
|
|
|
|
}
|
2016-02-24 18:24:20 +03:00
|
|
|
if (json.charset) {
|
|
|
|
this._browser._characterSet = json.charset;
|
|
|
|
this._browser._mayEnableCharacterEncodingMenu = json.mayEnableCharacterEncodingMenu;
|
|
|
|
}
|
2014-03-12 07:13:41 +04:00
|
|
|
}
|
2013-04-25 09:29:31 +04:00
|
|
|
|
|
|
|
switch (aMessage.name) {
|
|
|
|
case "Content:StateChange":
|
2016-02-10 23:49:50 +03:00
|
|
|
if (isTopLevel) {
|
2017-11-09 19:36:57 +03:00
|
|
|
this._browser._documentURI = Services.io.newURI(json.documentURI);
|
2016-02-10 23:49:50 +03:00
|
|
|
}
|
2017-04-12 00:17:31 +03:00
|
|
|
this._callProgressListeners(
|
|
|
|
Ci.nsIWebProgress.NOTIFY_STATE_ALL, "onStateChange", webProgress,
|
|
|
|
request, json.stateFlags, json.status
|
|
|
|
);
|
2013-04-25 09:29:31 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "Content:LocationChange":
|
2017-11-09 19:36:57 +03:00
|
|
|
let location = Services.io.newURI(json.location);
|
2013-11-22 10:39:05 +04:00
|
|
|
let flags = json.flags;
|
2016-01-13 00:44:08 +03:00
|
|
|
let remoteWebNav = this._browser._remoteWebNavigationImpl;
|
2013-09-06 03:24:29 +04:00
|
|
|
|
2014-08-29 00:37:16 +04:00
|
|
|
// These properties can change even for a sub-frame navigation.
|
2016-01-13 00:44:08 +03:00
|
|
|
remoteWebNav.canGoBack = json.canGoBack;
|
|
|
|
remoteWebNav.canGoForward = json.canGoForward;
|
2014-08-29 00:37:16 +04:00
|
|
|
|
2014-11-15 17:58:08 +03:00
|
|
|
if (isTopLevel) {
|
2016-01-13 00:44:08 +03:00
|
|
|
remoteWebNav._currentURI = location;
|
2017-11-09 19:36:57 +03:00
|
|
|
this._browser._documentURI = Services.io.newURI(json.documentURI);
|
2015-04-09 02:44:17 +03:00
|
|
|
this._browser._contentTitle = json.title;
|
2013-09-06 03:24:29 +04:00
|
|
|
this._browser._imageDocument = null;
|
2014-09-19 03:26:50 +04:00
|
|
|
this._browser._contentPrincipal = json.principal;
|
2015-03-04 03:58:53 +03:00
|
|
|
this._browser._isSyntheticDocument = json.synthetic;
|
2015-12-01 04:56:01 +03:00
|
|
|
this._browser._innerWindowID = json.innerWindowID;
|
2017-09-21 03:08:00 +03:00
|
|
|
this._browser._contentRequestContextID = json.requestContextID;
|
2013-09-06 03:24:29 +04:00
|
|
|
}
|
2013-04-27 19:37:04 +04:00
|
|
|
|
2017-04-12 00:17:31 +03:00
|
|
|
this._callProgressListeners(
|
|
|
|
Ci.nsIWebProgress.NOTIFY_LOCATION, "onLocationChange", webProgress,
|
|
|
|
request, location, flags
|
|
|
|
);
|
2013-04-25 09:29:31 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "Content:SecurityChange":
|
2018-07-13 21:48:55 +03:00
|
|
|
let [secInfo, state] = this._fixSecInfoAndState(json.secInfo, json.state);
|
2013-09-06 21:10:11 +04:00
|
|
|
|
2014-11-15 17:58:08 +03:00
|
|
|
if (isTopLevel) {
|
2013-09-06 21:10:11 +04:00
|
|
|
// Invoking this getter triggers the generation of the underlying object,
|
|
|
|
// which we need to access with ._securityUI, because .securityUI returns
|
|
|
|
// a wrapper that makes _update inaccessible.
|
|
|
|
void this._browser.securityUI;
|
2018-07-13 21:48:55 +03:00
|
|
|
this._browser._securityUI._update(secInfo, state);
|
2013-09-06 21:10:11 +04:00
|
|
|
}
|
|
|
|
|
2017-04-12 00:17:31 +03:00
|
|
|
this._callProgressListeners(
|
|
|
|
Ci.nsIWebProgress.NOTIFY_SECURITY, "onSecurityChange", webProgress,
|
|
|
|
request, state
|
|
|
|
);
|
2013-04-25 09:29:31 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "Content:StatusChange":
|
2017-04-12 00:17:31 +03:00
|
|
|
this._callProgressListeners(
|
|
|
|
Ci.nsIWebProgress.NOTIFY_STATUS, "onStatusChange", webProgress, request,
|
|
|
|
json.status, json.message
|
|
|
|
);
|
2013-04-25 09:29:31 +04:00
|
|
|
break;
|
2014-12-04 01:14:23 +03:00
|
|
|
|
|
|
|
case "Content:ProgressChange":
|
2017-04-12 00:17:31 +03:00
|
|
|
this._callProgressListeners(
|
|
|
|
Ci.nsIWebProgress.NOTIFY_PROGRESS, "onProgressChange", webProgress,
|
|
|
|
request, json.curSelf, json.maxSelf, json.curTotal, json.maxTotal
|
|
|
|
);
|
2014-12-04 01:14:23 +03:00
|
|
|
break;
|
2013-04-25 09:29:31 +04:00
|
|
|
}
|
2015-04-03 17:46:53 +03:00
|
|
|
},
|
2013-04-25 09:29:31 +04:00
|
|
|
};
|