Bug 1230221 - Convert JS callsites to use asyncOpen2 within services/ (r=sicking)
--- a/services/common/rest.js
+++ b/services/common/rest.js
@@ -11,16 +11,17 @@ this.EXPORTED_SYMBOLS = [
"RESTResponse",
"TokenAuthenticatedRESTRequest",
];
#endif
Cu.import("resource://gre/modules/Preferences.jsm");
Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/NetUtil.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Log.jsm");
Cu.import("resource://services-common/utils.js");
XPCOMUtils.defineLazyModuleGetter(this, "CryptoUtils",
"resource://services-crypto/utils.js");
const Prefs = new Preferences("services.common.rest.");
@@ -300,24 +301,19 @@ RESTRequest.prototype = {
if (onComplete) {
this.onComplete = onComplete;
}
if (onProgress) {
this.onProgress = onProgress;
}
// Create and initialize HTTP channel.
- let channel = Services.io.newChannelFromURI2(this.uri,
- null, // aLoadingNode
- Services.scriptSecurityManager.getSystemPrincipal(),
- null, // aTriggeringPrincipal
- Ci.nsILoadInfo.SEC_NORMAL,
- Ci.nsIContentPolicy.TYPE_OTHER)
- .QueryInterface(Ci.nsIRequest)
- .QueryInterface(Ci.nsIHttpChannel);
+ let channel = NetUtil.newChannel({uri: this.uri, loadUsingSystemPrincipal: true})
+ .QueryInterface(Ci.nsIRequest)
+ .QueryInterface(Ci.nsIHttpChannel);
this.channel = channel;
channel.loadFlags |= this.loadFlags;
channel.notificationCallbacks = this;
// Set request headers.
let headers = this._headers;
for (let key in headers) {
if (key == 'authorization') {
@@ -353,17 +349,17 @@ RESTRequest.prototype = {
channel.requestMethod = method;
// Before opening the channel, set the charset that serves as a hint
// as to what the response might be encoded as.
channel.contentCharset = this.charset;
// Blast off!
try {
- channel.asyncOpen(this, null);
+ channel.asyncOpen2(this);
} catch (ex) {
// asyncOpen can throw in a bunch of cases -- e.g., a forbidden port.
this._log.warn("Caught an error in asyncOpen", ex);
CommonUtils.nextTick(onComplete.bind(this, ex));
}
this.status = this.SENT;
this.delayTimeout();
return this;
--- a/services/sync/modules/resource.js
+++ b/services/sync/modules/resource.js
@@ -8,16 +8,17 @@ this.EXPORTED_SYMBOLS = [
];
var Cc = Components.classes;
var Ci = Components.interfaces;
var Cr = Components.results;
var Cu = Components.utils;
Cu.import("resource://gre/modules/Preferences.jsm");
+Cu.import("resource://gre/modules/NetUtil.jsm");
Cu.import("resource://services-common/async.js");
Cu.import("resource://gre/modules/Log.jsm");
Cu.import("resource://services-common/observers.js");
Cu.import("resource://services-common/utils.js");
Cu.import("resource://services-sync/constants.js");
Cu.import("resource://services-sync/util.js");
const DEFAULT_LOAD_FLAGS =
@@ -143,26 +144,19 @@ AsyncResource.prototype = {
// ** {{{ AsyncResource._createRequest }}} **
//
// This method returns a new IO Channel for requests to be made
// through. It is never called directly, only {{{_doRequest}}} uses it
// to obtain a request channel.
//
_createRequest: function Res__createRequest(method) {
- let channel = Services.io.newChannel2(this.spec,
- null,
- null,
- null, // aLoadingNode
- Services.scriptSecurityManager.getSystemPrincipal(),
- null, // aTriggeringPrincipal
- Ci.nsILoadInfo.SEC_NORMAL,
- Ci.nsIContentPolicy.TYPE_OTHER)
- .QueryInterface(Ci.nsIRequest)
- .QueryInterface(Ci.nsIHttpChannel);
+ let channel = NetUtil.newChannel({uri: this.spec, loadUsingSystemPrincipal: true})
+ .QueryInterface(Ci.nsIRequest)
+ .QueryInterface(Ci.nsIHttpChannel);
channel.loadFlags |= DEFAULT_LOAD_FLAGS;
// Setup a callback to handle channel notifications.
let listener = new ChannelNotificationListener(this.headerNames);
channel.notificationCallbacks = listener;
// Compose a UA string fragment from the various available identifiers.
@@ -225,20 +219,20 @@ AsyncResource.prototype = {
}
// Setup a channel listener so that the actual network operation
// is performed asynchronously.
let listener = new ChannelListener(this._onComplete, this._onProgress,
this._log, this.ABORT_TIMEOUT);
channel.requestMethod = action;
try {
- channel.asyncOpen(listener, null);
+ channel.asyncOpen2(listener);
} catch (ex) {
- // asyncOpen can throw in a bunch of cases -- e.g., a forbidden port.
- this._log.warn("Caught an error in asyncOpen", ex);
+ // asyncOpen2 can throw in a bunch of cases -- e.g., a forbidden port.
+ this._log.warn("Caught an error in asyncOpen2", ex);
CommonUtils.nextTick(callback.bind(this, ex));
}
},
_onComplete: function _onComplete(error, data, channel) {
this._log.trace("In _onComplete. Error is " + error + ".");
if (error) {