Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 Components.utils.import("resource://testing-common/httpd.js");
8 const nsIDocumentEncoder = Components.interfaces.nsIDocumentEncoder;
9 const replacementChar = Components.interfaces.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER;
11 function loadContentFile(aFile, aCharset) {
12 //if(aAsIso == undefined) aAsIso = false;
13 if(aCharset == undefined)
14 aCharset = 'UTF-8';
16 var file = do_get_file(aFile);
17 var ios = Components.classes['@mozilla.org/network/io-service;1']
18 .getService(Components.interfaces.nsIIOService);
19 var chann = ios.newChannelFromURI ( ios.newFileURI (file) );
20 chann.contentCharset = aCharset;
22 /*var inputStream = Components.classes["@mozilla.org/scriptableinputstream;1"]
23 .createInstance(Components.interfaces.nsIScriptableInputStream);
24 inputStream.init(chann.open());
25 return inputStream.read(file.fileSize);
26 */
28 var inputStream = Components.classes["@mozilla.org/intl/converter-input-stream;1"]
29 .createInstance(Components.interfaces.nsIConverterInputStream);
30 inputStream.init(chann.open(), aCharset, 1024, replacementChar);
31 var str = {}, content = '';
32 while (inputStream.readString(4096, str) != 0) {
33 content += str.value;
34 }
35 return content;
36 }