Bug 1243924 - Convert remaining callsites within dom/ to use channel.open2() (r=sicking)

This commit is contained in:
Christoph Kerschbaumer 2016-01-29 09:24:25 -08:00
parent 1f2034ed37
commit 81bc64d6ec
5 changed files with 23 additions and 34 deletions

View File

@ -4,7 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Components.utils.import("resource://testing-common/httpd.js");
Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.import("resource://gre/modules/NetUtil.jsm");
const nsIDocumentEncoder = Components.interfaces.nsIDocumentEncoder;
const replacementChar = Components.interfaces.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER;
@ -17,23 +17,21 @@ function loadContentFile(aFile, aCharset) {
var file = do_get_file(aFile);
var ios = Components.classes['@mozilla.org/network/io-service;1']
.getService(Components.interfaces.nsIIOService);
var chann = ios.newChannelFromURI2(ios.newFileURI(file),
null, // aLoadingNode
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Components.interfaces.nsILoadInfo.SEC_NORMAL,
Components.interfaces.nsIContentPolicy.TYPE_OTHER);
var chann = NetUtil.newChannel({
uri: ios.newFileURI(file),
loadUsingSystemPrincipal: true
});
chann.contentCharset = aCharset;
/*var inputStream = Components.classes["@mozilla.org/scriptableinputstream;1"]
.createInstance(Components.interfaces.nsIScriptableInputStream);
inputStream.init(chann.open());
inputStream.init(chann.open2());
return inputStream.read(file.fileSize);
*/
var inputStream = Components.classes["@mozilla.org/intl/converter-input-stream;1"]
.createInstance(Components.interfaces.nsIConverterInputStream);
inputStream.init(chann.open(), aCharset, 1024, replacementChar);
inputStream.init(chann.open2(), aCharset, 1024, replacementChar);
var str = {}, content = '';
while (inputStream.readString(4096, str) != 0) {
content += str.value;

View File

@ -128,7 +128,7 @@ ContactDB.prototype = {
uri: NetUtil.newURI(contactsFile),
loadUsingSystemPrincipal: true});
let stream = chan.open();
let stream = chan.open2();
// Obtain a converter to read from a UTF-8 encoded input stream.
let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]
.createInstance(Ci.nsIScriptableUnicodeConverter);

View File

@ -83,7 +83,7 @@ SettingsDB.prototype = {
let chan = NetUtil.newChannel({
uri: NetUtil.newURI(settingsFile),
loadUsingSystemPrincipal: true});
let stream = chan.open();
let stream = chan.open2();
// Obtain a converter to read from a UTF-8 encoded input stream.
let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]
.createInstance(Ci.nsIScriptableUnicodeConverter);

View File

@ -12,6 +12,8 @@ const nsIFilePicker = Components.interfaces.nsIFilePicker;
const STDURL_CTRID = "@mozilla.org/network/standard-url;1";
const nsIURI = Components.interfaces.nsIURI;
Components.utils.import("resource://gre/modules/NetUtil.jsm");
var gStop = false;
function loadFile(aUriSpec)
@ -22,17 +24,13 @@ function loadFile(aUriSpec)
if (!serv) {
throw Components.results.ERR_FAILURE;
}
var chan = serv.newChannel2(aUriSpec,
null,
null,
null, // aLoadingNode
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
var chan = NetUtil.newChannel({
uri: aUriSpec,
loadUsingSystemPrincipal: true
});
var instream =
Components.classes[SIS_CTRID].createInstance(nsISIS);
instream.init(chan.open());
instream.init(chan.open2());
return instream.read(instream.available());
}

View File

@ -3,6 +3,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Components.utils.import("resource://gre/modules/NetUtil.jsm");
var parser = new DOMParser();
var methodExpr = (new XPathEvaluator).createExpression("xsl:output/@method",
{
@ -307,21 +309,12 @@ runItem.prototype =
loadTextFile : function(url)
{
var serv = Components.classes[IOSERVICE_CTRID].
getService(nsIIOService);
if (!serv) {
throw Components.results.ERR_FAILURE;
}
var chan = serv.newChannel2(url,
null,
null,
null, // aLoadingNode
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
var chan = NetUtil.newChannel({
uri: url,
loadUsingSystemPrincipal: true
});
var instream = doCreate(SIS_CTRID, nsISIS);
instream.init(chan.open());
instream.init(chan.open2());
return instream.read(instream.available());
}