Bug 1124951: Make JS callers of ios.newChannel call ios.newChannel2 in toolkit/devtools (r=jryans)

This commit is contained in:
Christoph Kerschbaumer 2015-01-26 19:54:52 -08:00
parent 5b8fcccd7c
commit ac155f2556
7 changed files with 156 additions and 76 deletions

View File

@ -463,20 +463,27 @@ exports.fetch = function fetch(aURL, aOptions={ loadFromCache: true }) {
case "chrome":
case "resource":
try {
NetUtil.asyncFetch(url, function onFetch(aStream, aStatus, aRequest) {
if (!components.isSuccessCode(aStatus)) {
deferred.reject(new Error("Request failed with status code = "
+ aStatus
+ " after NetUtil.asyncFetch for url = "
+ url));
return;
}
NetUtil.asyncFetch2(
url,
function onFetch(aStream, aStatus, aRequest) {
if (!components.isSuccessCode(aStatus)) {
deferred.reject(new Error("Request failed with status code = "
+ aStatus
+ " after NetUtil.asyncFetch2 for url = "
+ url));
return;
}
let source = NetUtil.readInputStreamToString(aStream, aStream.available());
contentType = aRequest.contentType;
deferred.resolve(source);
aStream.close();
});
let source = NetUtil.readInputStreamToString(aStream, aStream.available());
contentType = aRequest.contentType;
deferred.resolve(source);
aStream.close();
},
null, // aLoadingNode
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
} catch (ex) {
deferred.reject(ex);
}

View File

@ -199,14 +199,22 @@ SrcdirProvider.prototype = {
_readFile: function(filename) {
let deferred = promise.defer();
let file = new FileUtils.File(filename);
NetUtil.asyncFetch(file, (inputStream, status) => {
if (!Components.isSuccessCode(status)) {
deferred.reject(new Error("Couldn't load manifest: " + filename + "\n"));
return;
}
var data = NetUtil.readInputStreamToString(inputStream, inputStream.available());
deferred.resolve(data);
});
NetUtil.asyncFetch2(
file,
(inputStream, status) => {
if (!Components.isSuccessCode(status)) {
deferred.reject(new Error("Couldn't load manifest: " + filename + "\n"));
return;
}
var data = NetUtil.readInputStreamToString(inputStream, inputStream.available());
deferred.resolve(data);
},
null, // aLoadingNode
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
return deferred.promise;
},

View File

@ -187,17 +187,24 @@ function uploadPackageBulk(client, webappsActor, packageFile, progressCallback)
});
request.on("bulk-send-ready", ({copyFrom}) => {
NetUtil.asyncFetch(packageFile, function(inputStream) {
let copying = copyFrom(inputStream);
copying.on("progress", (e, progress) => {
progressCallback(progress);
});
copying.then(() => {
console.log("Bulk upload done");
inputStream.close();
deferred.resolve(actor);
});
});
NetUtil.asyncFetch2(
packageFile,
function(inputStream) {
let copying = copyFrom(inputStream);
copying.on("progress", (e, progress) => {
progressCallback(progress);
});
copying.then(() => {
console.log("Bulk upload done");
inputStream.close();
deferred.resolve(actor);
});
},
null, // aLoadingNode
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
});
}

View File

@ -156,7 +156,14 @@ exports.items = [
try {
let io = Cc["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService);
let channel = io.newChannel(data, null, null);
let channel = io.newChannel2(data,
null,
null,
null, // aLoadingNode
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_IMAGE);
let input = channel.open();
let imgTools = Cc["@mozilla.org/image/tools;1"]
.getService(Ci.imgITools);

View File

@ -667,20 +667,27 @@ function fetch(aURL, aOptions={ loadFromCache: true, window: null,
case "chrome":
case "resource":
try {
NetUtil.asyncFetch(url, function onFetch(aStream, aStatus, aRequest) {
if (!components.isSuccessCode(aStatus)) {
deferred.reject(new Error("Request failed with status code = "
+ aStatus
+ " after NetUtil.asyncFetch for url = "
+ url));
return;
}
NetUtil.asyncFetch2(
url,
function onFetch(aStream, aStatus, aRequest) {
if (!components.isSuccessCode(aStatus)) {
deferred.reject(new Error("Request failed with status code = "
+ aStatus
+ " after NetUtil.asyncFetch2 for url = "
+ url));
return;
}
let source = NetUtil.readInputStreamToString(aStream, aStream.available());
contentType = aRequest.contentType;
deferred.resolve(source);
aStream.close();
});
let source = NetUtil.readInputStreamToString(aStream, aStream.available());
contentType = aRequest.contentType;
deferred.resolve(source);
aStream.close();
},
null, // aLoadingNode
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_STYLESHEET);
} catch (ex) {
deferred.reject(ex);
}
@ -689,12 +696,26 @@ function fetch(aURL, aOptions={ loadFromCache: true, window: null,
default:
let channel;
try {
channel = Services.io.newChannel(url, null, null);
channel = Services.io.newChannel2(url,
null,
null,
null, // aLoadingNode
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_STYLESHEET);
} catch (e if e.name == "NS_ERROR_UNKNOWN_PROTOCOL") {
// On Windows xpcshell tests, c:/foo/bar can pass as a valid URL, but
// newChannel won't be able to handle it.
url = "file:///" + url;
channel = Services.io.newChannel(url, null, null);
channel = Services.io.newChannel2(url,
null,
null,
null, // aLoadingNode
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_STYLESHEET);
}
let chunks = [];
let streamListener = {

View File

@ -1086,20 +1086,27 @@ function fetch(aURL, aOptions={ loadFromCache: true, window: null,
case "chrome":
case "resource":
try {
NetUtil.asyncFetch(url, function onFetch(aStream, aStatus, aRequest) {
if (!components.isSuccessCode(aStatus)) {
deferred.reject(new Error("Request failed with status code = "
+ aStatus
+ " after NetUtil.asyncFetch for url = "
+ url));
return;
}
NetUtil.asyncFetch2(
url,
function onFetch(aStream, aStatus, aRequest) {
if (!components.isSuccessCode(aStatus)) {
deferred.reject(new Error("Request failed with status code = "
+ aStatus
+ " after NetUtil.asyncFetch2 for url = "
+ url));
return;
}
let source = NetUtil.readInputStreamToString(aStream, aStream.available());
contentType = aRequest.contentType;
deferred.resolve(source);
aStream.close();
});
let source = NetUtil.readInputStreamToString(aStream, aStream.available());
contentType = aRequest.contentType;
deferred.resolve(source);
aStream.close();
},
null, // aLoadingNode
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_STYLESHEET);
} catch (ex) {
deferred.reject(ex);
}
@ -1108,12 +1115,26 @@ function fetch(aURL, aOptions={ loadFromCache: true, window: null,
default:
let channel;
try {
channel = Services.io.newChannel(url, null, null);
channel = Services.io.newChannel2(url,
null,
null,
null, // aLoadingNode
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_STYLESHEET);
} catch (e if e.name == "NS_ERROR_UNKNOWN_PROTOCOL") {
// On Windows xpcshell tests, c:/foo/bar can pass as a valid URL, but
// newChannel won't be able to handle it.
url = "file:///" + url;
channel = Services.io.newChannel(url, null, null);
channel = Services.io.newChannel2(url,
null,
null,
null, // aLoadingNode
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_STYLESHEET);
}
let chunks = [];
let streamListener = {

View File

@ -275,27 +275,36 @@ let NetworkHelper = {
*/
loadFromCache: function NH_loadFromCache(aUrl, aCharset, aCallback)
{
let channel = NetUtil.newChannel(aUrl);
let channel = NetUtil.newChannel2(aUrl,
null,
null,
null, // aLoadingNode
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
// Ensure that we only read from the cache and not the server.
channel.loadFlags = Ci.nsIRequest.LOAD_FROM_CACHE |
Ci.nsICachingChannel.LOAD_ONLY_FROM_CACHE |
Ci.nsICachingChannel.LOAD_BYPASS_LOCAL_CACHE_IF_BUSY;
NetUtil.asyncFetch(channel, (aInputStream, aStatusCode, aRequest) => {
if (!components.isSuccessCode(aStatusCode)) {
aCallback(null);
return;
}
NetUtil.asyncFetch2(
channel,
(aInputStream, aStatusCode, aRequest) => {
if (!components.isSuccessCode(aStatusCode)) {
aCallback(null);
return;
}
// Try to get the encoding from the channel. If there is none, then use
// the passed assumed aCharset.
let aChannel = aRequest.QueryInterface(Ci.nsIChannel);
let contentCharset = aChannel.contentCharset || aCharset;
// Try to get the encoding from the channel. If there is none, then use
// the passed assumed aCharset.
let aChannel = aRequest.QueryInterface(Ci.nsIChannel);
let contentCharset = aChannel.contentCharset || aCharset;
// Read the content of the stream using contentCharset as encoding.
aCallback(this.readAndConvertFromStream(aInputStream, contentCharset));
});
// Read the content of the stream using contentCharset as encoding.
aCallback(this.readAndConvertFromStream(aInputStream, contentCharset));
});
},
/**