diff options
Diffstat (limited to 'lib/http_observer/process_response.js')
-rw-r--r-- | lib/http_observer/process_response.js | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/lib/http_observer/process_response.js b/lib/http_observer/process_response.js index c1f5e88..000daa2 100644 --- a/lib/http_observer/process_response.js +++ b/lib/http_observer/process_response.js @@ -81,17 +81,6 @@ var processResponseObject = { }, /** - * genBinaryOutput - * Set or reset binaryOutputStream and storageStream. - */ - genBinaryOutput: function () { - this.storageStream = Cc["@mozilla.org/storagestream;1"] - .createInstance(Ci.nsIStorageStream); - this.binaryOutputStream = Cc["@mozilla.org/binaryoutputstream;1"] - .createInstance(Ci.nsIBinaryOutputStream); - }, - - /** * Gather the data gathered from onDataAvailable. */ setData: function () { @@ -393,21 +382,26 @@ var processResponseObject = { jsListenerCallback: function () { - var len = this.data.length; + var converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"] + .createInstance(Ci.nsIScriptableUnicodeConverter); - this.genBinaryOutput(); + if (typeof this.req.contentCharset !== 'undefined' && + this.req.contentCharset !== '' && + this.req.contentCharset !== null + ) { + converter.charset = this.req.contentCharset; + } else { + converter.charset = "utf-8"; + } - this.storageStream.init(8192, len, null); - this.binaryOutputStream.setOutputStream( - this.storageStream.getOutputStream(0)); - this.binaryOutputStream.writeBytes(this.data, len); + var stream = converter.convertToInputStream(this.data); try { this.listener.onDataAvailable( this.req, this.resInfo.context, this.storageStream.newInputStream(0), - 0, len); + 0, stream.available()); } catch (e) { this.req.cancel(this.req.NS_BINDING_ABORTED); } |