Pass response data to Zotero.WebProgressFinishListener callback

Pass an object with 'status' and 'contentType' if available
This commit is contained in:
Dan Stillman 2018-08-16 00:50:36 -04:00
parent bcf94942f9
commit 7a646a292b

View file

@ -2815,17 +2815,36 @@ Zotero.Browser = new function() {
*/
Zotero.WebProgressFinishListener = function(onFinish) {
var _request;
var _finished = false;
this.getRequest = function () {
return _request;
};
this.onStateChange = function(wp, req, stateFlags, status) {
//Zotero.debug('onStageChange: ' + stateFlags);
//Zotero.debug('onStateChange: ' + stateFlags);
if (stateFlags & Components.interfaces.nsIWebProgressListener.STATE_STOP
&& stateFlags & Components.interfaces.nsIWebProgressListener.STATE_IS_NETWORK) {
if (_finished) {
return;
}
// Get status code and content ype
let status = null;
let contentType = null;
try {
let r = _request || req;
_request.QueryInterface(Components.interfaces.nsIHttpChannel);
status = r.responseStatus;
contentType = r.contentType;
}
catch (e) {
Zotero.debug(e, 2);
}
_request = null;
onFinish();
onFinish({ status, contentType });
_finished = true;
}
else {
_request = req;