Skip to content

Commit

Permalink
fix bug 715721: Switch to using nsIChannel to do the synchronous I/O …
Browse files Browse the repository at this point in the history
…load from a URI. r=@mykmelez

(cherry picked from commit 543cf35)
  • Loading branch information
Mossop authored and mykmelez committed Jan 6, 2012
1 parent 5f28e7f commit fedf331
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions python-lib/cuddlefish/app-extension/bootstrap.js
Expand Up @@ -130,11 +130,24 @@ function getAppStartupTopic() {
// Utility function that synchronously reads local resource from the given
// `uri` and returns content string.
function readURI(uri) {
let request = XMLHttpRequest();
request.open('GET', uri, false);
request.overrideMimeType('text/plain');
request.send();
return request.responseText;
let ioservice = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
let channel = ioservice.newChannel(uri, "UTF-8", null);
let stream = channel.open();

let cstream = Cc["@mozilla.org/intl/converter-input-stream;1"].createInstance(Ci.nsIConverterInputStream);
cstream.init(stream, "UTF-8", 0, 0);

let str = {};
let data = "";
let read = 0;
do {
read = cstream.readString(0xffffffff, str);
data += str.value;
} while (read != 0);

cstream.close();

return data;
}

// Function takes `topic` to be observer via `nsIObserverService` and returns
Expand Down

0 comments on commit fedf331

Please sign in to comment.