Skip to content

Commit

Permalink
Correctly "close" sections in headers field, if something went wrong
Browse files Browse the repository at this point in the history
(#8)
  • Loading branch information
Infocatcher committed Jan 21, 2014
1 parent 077682d commit 19116ec
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions chrome/content/linkPropsPlus.js
Expand Up @@ -813,6 +813,7 @@ var linkPropsPlusSvc = {
return false;
}
catch(e) {
this.headers.ensureSectionsEnded();
Components.utils.reportError(e);
}
this.onStopRequestCallback(false);
Expand Down Expand Up @@ -1163,6 +1164,8 @@ var linkPropsPlusSvc = {
return this.field = field;
},
clear: function() {
this._sections.length = 0;
this._activeSection = null;
this.field.textContent = "";
},
caption: function(s, nodeClass) {
Expand Down Expand Up @@ -1230,6 +1233,10 @@ var linkPropsPlusSvc = {
sections.pop();
this._activeSection = sections[sections.length - 1] || null;
},
ensureSectionsEnded: function() {
while(this._activeSection)
this.endSection();
},
_appendNode: function(nodeName, nodeClass, nodeText) {
return this._append(this._node.apply(this, arguments));
},
Expand Down Expand Up @@ -1558,9 +1565,10 @@ var linkPropsPlusSvc = {
return; // Window is closed
try {
if(request instanceof Components.interfaces.nsIHttpChannel) {
var status = request.responseStatus + " " + request.responseStatusText;
this.headers.caption(this.ut.getLocalized("response"));
this.headers.beginSection();
this.headers.entry("Status", request.responseStatus + " " + request.responseStatusText);
this.headers.entry("Status", status);
var headers = this._responseHeaders = { __proto__: null };
request.visitResponseHeaders(this);
this._responseHeaders = { __proto__: null };
Expand Down Expand Up @@ -1595,6 +1603,7 @@ var linkPropsPlusSvc = {
}
}
catch(err) {
this.headers.ensureSectionsEnded();
this.ut.error("Can't get information from request");
Components.utils.reportError(err);
}
Expand Down Expand Up @@ -1677,13 +1686,15 @@ var linkPropsPlusSvc = {
onStopRequest: function(request, ctxt, status) {
if(!this.canceled && request instanceof Components.interfaces.nsIHttpChannel) try {
var headers = this.parent.headers;
var status = request.responseStatus + " " + request.responseStatusText;
headers.caption(this.parent.ut.getLocalized("testResumabilityResponse"), "caption testResume");
headers.beginSection("block testResume");
headers.entry("Status", request.responseStatus + " " + request.responseStatusText);
headers.entry("Status", status);
request.visitResponseHeaders(this);
headers.endSection();
}
catch(e) {
this.headers.ensureSectionsEnded();
Components.utils.reportError(e);
}
this.setCanResumeDownload(false);
Expand All @@ -1702,6 +1713,7 @@ var linkPropsPlusSvc = {
this.headers.endSection();
}
catch(e) {
this.headers.ensureSectionsEnded();
Components.utils.reportError(e);
}
ch.asyncOpen(observer, null);
Expand Down

0 comments on commit 19116ec

Please sign in to comment.