Bug 1402755 - Stop using nsIXMLHttpRequest constructor; use the regular XMLHttpRequest one instead. r=aceman,philipp
authorThomas Wisniewski <wisniewskit@gmail.com>
Mon, 25 Sep 2017 17:08:28 -0400
changeset 29090 86741416b36b16bb5aa2c68acef61430f45b7425
parent 29089 4395039ec2eeb6b2baaaf226abff7ff1ff15baf5
child 29091 ac845a2682a78db055a3cf0323284a0f2e9e4b6f
push id2068
push userclokep@gmail.com
push dateMon, 13 Nov 2017 19:02:14 +0000
treeherdercomm-beta@9c7e7ce8672b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaceman, philipp
bugs1402755
Bug 1402755 - Stop using nsIXMLHttpRequest constructor; use the regular XMLHttpRequest one instead. r=aceman,philipp
calendar/base/content/dialogs/calendar-migration-dialog.js
calendar/base/modules/calXMLUtils.jsm
mail/base/content/specialTabs.js
mail/base/modules/mailInstrumentation.js
mail/components/cloudfile/nsBox.js
mail/components/cloudfile/nsHightail.js
mailnews/extensions/newsblog/content/Feed.js
mailnews/extensions/newsblog/content/FeedUtils.jsm
--- a/calendar/base/content/dialogs/calendar-migration-dialog.js
+++ b/calendar/base/content/dialogs/calendar-migration-dialog.js
@@ -5,16 +5,18 @@
 var SUNBIRD_UID = "{718e30fb-e89b-41dd-9da7-e25a45638b28}";
 var FIREFOX_UID = "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}";
 
 Components.utils.import("resource://calendar/modules/calUtils.jsm");
 Components.utils.import("resource://gre/modules/Services.jsm");
 Components.utils.import("resource://gre/modules/Preferences.jsm");
 Components.utils.import("resource://gre/modules/AppConstants.jsm");
 
+Components.utils.importGlobalProperties(["XMLHttpRequest"]);
+
 //
 // The front-end wizard bits.
 //
 var gMigrateWizard = {
     /**
      * Called from onload of the migrator window.  Takes all of the migrators
      * that were passed in via window.arguments and adds them to checklist. The
      * user can then check these off to migrate the data from those sources.
@@ -227,18 +229,17 @@ var gDataMigrator = {
             dataSource.append("CalendarManager.rdf");
             if (!dataSource.exists()) {
                 return;
             }
 
             // Let this be a lesson to anyone designing APIs. The RDF API is so
             // impossibly confusing that it's actually simpler/cleaner/shorter
             // to simply parse as XML and use the better DOM APIs.
-            var req = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
-                      .createInstance(Components.interfaces.nsIXMLHttpRequest);
+            var req = new XMLHttpRequest();
             req.open('GET', "file://" + dataSource.path, true);
             req.onreadystatechange = function calext_onreadychange() {
                 if (req.readyState == 4) {
                     migLOG(req.responseText);
                     parseAndMigrate(req.responseXML, aCallback)
                 }
             };
             req.send(null);
--- a/calendar/base/modules/calXMLUtils.jsm
+++ b/calendar/base/modules/calXMLUtils.jsm
@@ -1,16 +1,18 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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/. */
 
 /** Helper functions for parsing and serializing XML */
 
 Components.utils.import("resource://calendar/modules/calUtils.jsm");
 
+Components.utils.importGlobalProperties(["XMLHttpRequest"]);
+
 this.EXPORTED_SYMBOLS = ["cal"];
 cal.xml = {} || cal.xml;
 
 /**
  * Evaluate an XPath query for the given node. Be careful with the return value
  * here, as it may be:
  *
  * - null, if there are no results
@@ -127,19 +129,17 @@ cal.xml.parseString = function(str, docU
 /**
  * Read an XML file synchronously. This method should be avoided, consider
  * rewriting the caller to be asynchronous.
  *
  * @param uri       The URI to read.
  * @return          The DOM Document resulting from the file.
  */
 cal.xml.parseFile = function(uri) {
-    let req = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
-                        .createInstance(Components.interfaces.nsIXMLHttpRequest);
-
+    let req = new XMLHttpRequest();
     req.open("GET", uri, false);
     req.overrideMimeType("text/xml");
     req.send(null);
     return req.responseXML;
 };
 
 /**
  * Serialize the DOM tree into a string.
--- a/mail/base/content/specialTabs.js
+++ b/mail/base/content/specialTabs.js
@@ -544,18 +544,17 @@ var specialTabs = {
         onDownloadError(aEvent);
         return;
       }
 
       specialTabs.loadFaviconImageNode(onLoadSuccess, onDownloadError,
                                        iconUri.spec);
     });
 
-    let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
-                    .createInstance(Ci.nsIXMLHttpRequest);
+    let request = new XMLHttpRequest();
     request.open("GET", url, true);
     request.responseType = "document";
     request.onload = onDownload;
     request.onerror = onDownloadError;
     request.timeout = this.REQUEST_TIMEOUT;
     request.ontimeout = onDownloadError;
     request.send(null);
   },
--- a/mail/base/modules/mailInstrumentation.js
+++ b/mail/base/modules/mailInstrumentation.js
@@ -15,16 +15,18 @@ var Ci = Components.interfaces;
 var Cu = Components.utils;
 
 var nsIMFNService = Ci.nsIMsgFolderNotificationService;
 
 Cu.import("resource:///modules/errUtils.js");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource:///modules/mailServices.js");
 
+Cu.importGlobalProperties(["XMLHttpRequest"]);
+
 /* :::::::: The Module ::::::::::::::: */
 
 var mailInstrumentationManager =
 {
   // JS object containing the current state object
   _currentState: null,
 
   /**
@@ -154,18 +156,17 @@ var mailInstrumentationManager =
 
     let byteArray = converter.convertToByteArray(address, {});
     ch.update(byteArray, byteArray.length);
     let hashedData = ch.finish(false);
     return this._bytesAsHex(hashedData);
   },
 
   _postData: function minst_postData() {
-    let req = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
-                .createInstance(Ci.nsIXMLHttpRequest);
+    let req = new XMLHttpRequest();
     let url = Services.prefs.getCharPref("mail.instrumentation.postUrl");
     if (!url.length)
       return;
     let dataToPost = this._lastStateString;
     req.open("POST", url, true);
     req.onerror = this._onError;
     req.onload = this._onLoad;
     req.send(dataToPost);
--- a/mail/components/cloudfile/nsBox.js
+++ b/mail/components/cloudfile/nsBox.js
@@ -12,17 +12,17 @@ var {classes: Cc, interfaces: Ci, utils:
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource:///modules/gloda/log4moz.js");
 Cu.import("resource:///modules/cloudFileAccounts.js");
 Cu.import("resource:///modules/OAuth2.jsm");
 Cu.import("resource://gre/modules/Http.jsm");
 
-Cu.importGlobalProperties(["File"]);
+Cu.importGlobalProperties(["File", "XMLHttpRequest"]);
 
 var gServerUrl = "https://api.box.com/2.0/";
 var gUploadUrl = "https://upload.box.com/api/2.0/";
 
 var kAuthBaseUrl = "https://www.box.com/api/";
 var kAuthUrl = "oauth2/authorize";
 
 XPCOMUtils.defineLazyServiceGetter(this, "gProtocolService",
@@ -693,18 +693,17 @@ nsBoxFileUploader.prototype = {
    * Do the upload of the file to Box.
    */
   uploadFile: function nsBox_uploadFile() {
     this.requestObserver.onStartRequest(null, null);
     let requestUrl = gUploadUrl + "files/content";
     this.box._uploadInfo[this.file.path] = {};
     this.box._uploadInfo[this.file.path].uploadUrl = requestUrl;
 
-    let req = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
-                .createInstance(Ci.nsIXMLHttpRequest);
+    let req = new XMLHttpRequest();
 
     let curDate = Date.now().toString();
     this.log.info("upload url = " + requestUrl);
     this.request = req;
     req.open("POST", requestUrl, true);
     req.onload = function() {
       if (req.status >= 200 && req.status < 400) {
         try {
--- a/mail/components/cloudfile/nsHightail.js
+++ b/mail/components/cloudfile/nsHightail.js
@@ -10,16 +10,18 @@
 
 var {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource:///modules/gloda/log4moz.js");
 Cu.import("resource:///modules/cloudFileAccounts.js");
 
+Cu.importGlobalProperties(["XMLHttpRequest"]);
+
 var gServerUrl = "https://dpi.yousendit.com"; // Production url
 // test url var gServerUrl = "https://test2-api.yousendit.com";
 
 var kApiKey = "7spvjdt7m4kycr7jyhywrdn2";
 var kAuthPath = "/dpi/v1/auth";
 var kUserInfoPath = "/dpi/v2/user";
 var kFolderPath = "/dpi/v1/folder/";
 var kFolderFilePath = "/dpi/v1/folder/file/";
@@ -319,18 +321,17 @@ nsHightail.prototype = {
    *                        is successful.
    * @param failureCallback a callback fired if retrieving profile information
    *                        fails.
    */
   _getUserInfo: function(successCallback, failureCallback) {
     this.log.info("getting user info");
     let args = "?email=" + this._userName + "&";
 
-    let req = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
-                .createInstance(Ci.nsIXMLHttpRequest);
+    let req = new XMLHttpRequest();
     req.open("GET", gServerUrl + kUserInfoPath + args + kUrlTail, true);
 
     req.onload = function() {
       if (req.status >= 200 && req.status < 400) {
         this.log.info("request status = " + req.status +
                       " response = " + req.responseText);
         let docResponse = JSON.parse(req.responseText);
         this.log.info("user info response parsed = " + docResponse);
@@ -443,18 +444,17 @@ nsHightail.prototype = {
   createNewAccount: function(aEmailAddress, aPassword,aFirstName, aLastName,
                              aRequestObserver) {
     if (Services.io.offline)
       throw Ci.nsIMsgCloudFileProvider.offlineErr;
 
     let args = "?email=" + aEmailAddress + "&password=" + aPassword + "&firstname="
                + aFirstName + "&lastname=" + aLastName + "&";
 
-    let req = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
-                .createInstance(Ci.nsIXMLHttpRequest);
+    let req = new XMLHttpRequest();
 
     req.open("POST", gServerUrl + kUserInfoPath + args + kUrlTail, true);
 
     req.onload = function() {
       if (req.status >= 200 &&
           req.status < 400) {
         this.log.info("request status = " + req + " response = " +
                       req.responseText);
@@ -524,18 +524,17 @@ nsHightail.prototype = {
    */
   _checkFolderExist: function(aFolderId, aFoundCallback, aNotFoundCallback) {
     this.log.info('checkFolderExist');
     if (Services.io.offline)
       throw Ci.nsIMsgCloudFileProvider.offlineErr;
 
     let args = "?includeFiles=false&includeFolders=true&";
 
-    let req = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
-                .createInstance(Ci.nsIXMLHttpRequest);
+    let req = new XMLHttpRequest();
 
     req.open("GET",
              gServerUrl + kFolderPath + aFolderId + args + kUrlTail,
              true);
 
     req.onload = function() {
       let docResponse = JSON.parse(req.responseText);
       if (req.status >= 200 && req.status < 400) {
@@ -574,18 +573,17 @@ nsHightail.prototype = {
    */
   _createFolder: function(aName, aParent, aSuccessCallback) {
     this.log.info("Create folder: " + aName);
     if (Services.io.offline)
       throw Ci.nsIMsgCloudFileProvider.offlineErr;
 
     let args = "?name=" + aName + "&parentId=" + aParent + "&";
 
-    let req = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
-                .createInstance(Ci.nsIXMLHttpRequest);
+    let req = new XMLHttpRequest();
 
     req.open("POST", gServerUrl + kFolderPath.replace(/\/$/, '') + args + kUrlTail, true);
 
     req.onload = function() {
       let docResponse = JSON.parse(req.responseText);
       if (req.status >= 200 && req.status < 400) {
         this.log.info("request status = " + req + " response = " +
                       req.responseText);
@@ -676,18 +674,17 @@ nsHightail.prototype = {
     }
 
     let uploadInfo = this._uploadInfo[aFile.path];
     if (!uploadInfo) {
       this.log.error("Could not find a record for the file to be deleted.");
       throw Cr.NS_ERROR_FAILURE;
     }
 
-    let req = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
-                .createInstance(Ci.nsIXMLHttpRequest);
+    let req = new XMLHttpRequest();
 
     let args = kFolderFilePath + uploadInfo.fileId + "?";
 
     req.open("DELETE", gServerUrl + args + kUrlTail, true);
     this.log.info("Sending request to: " + gServerUrl + args);
 
     req.onerror = function() {
       let response = JSON.parse(req.responseText);
@@ -809,18 +806,17 @@ nsHightail.prototype = {
    *                 if no auth token is currently stored.
    */
   logon: function(successCallback, failureCallback, aWithUI) {
     this.log.info("Logging in, aWithUI = " + aWithUI);
     if (this._password == undefined || !this._password)
       this._password = this.getPassword(this._userName, !aWithUI);
     let args = "?email=" + this._userName + "&password=" + this._password + "&";
     this.log.info("Sending login information...");
-    let req = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
-                .createInstance(Ci.nsIXMLHttpRequest);
+    let req = new XMLHttpRequest();
     let curDate = Date.now().toString();
 
     req.open("POST", gServerUrl + kAuthPath + args + kUrlTail, true);
     req.onerror = function() {
       this.log.info("logon failure");
       failureCallback();
     }.bind(this);
 
@@ -912,18 +908,17 @@ nsHightailFileUploader.prototype = {
   /**
    * Communicates with Hightail to get the URL that we will send the upload
    * request to.
    *
    * @param successCallback the callback fired if getting the URL is successful
    * @param failureCallback the callback fired if getting the URL fails
    */
   _prepareToSend: function(successCallback, failureCallback) {
-    let req = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
-                .createInstance(Ci.nsIXMLHttpRequest);
+    let req = new XMLHttpRequest();
 
     req.open("POST", gServerUrl + kFolderInitUploadPath + "?" + kUrlTail, true);
 
     req.onerror = failureCallback;
 
     req.onload = function() {
       let response = req.responseText;
       if (req.status >= 200 && req.status < 400) {
@@ -953,18 +948,17 @@ nsHightailFileUploader.prototype = {
     req.send();
   },
 
   /**
    * Once we've got the URL to upload the file to, this function actually does
    * the upload of the file to Hightail.
    */
   _uploadFile: function() {
-    let req = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
-                .createInstance(Ci.nsIXMLHttpRequest);
+    let req = new XMLHttpRequest();
 
     let curDate = Date.now().toString();
     this.log.info("upload url = " + this._urlInfo.uploadUrl[0]);
     this.request = req;
     req.open("POST", this._urlInfo.uploadUrl[0] + "?" + kUrlTail, true);
     req.onload = function() {
       this.cleanupTempFile();
       if (req.status >= 200 && req.status < 400) {
@@ -1003,17 +997,17 @@ nsHightailFileUploader.prototype = {
     fileContents += "\r\n--" + boundary +
       "\r\nContent-Disposition: form-data; name=\"fname\"; filename=\"" +
       fileName + "\"\r\nContent-Type: application/octet-stream" +
       "\r\n\r\n";
 
     // Since js doesn't like binary data in strings, we're going to create
     // a temp file consisting of the message preamble, the file contents, and
     // the post script, and pass a stream based on that file to
-    // nsIXMLHttpRequest.send().
+    // XMLHttpRequest.send().
 
     try {
       this._tempFile = this.getTempFile(this.file.leafName);
       let ostream = Cc["@mozilla.org/network/file-output-stream;1"]
                      .createInstance(Ci.nsIFileOutputStream);
       ostream.init(this._tempFile, -1, -1, 0);
       ostream.write(fileContents, fileContents.length);
 
@@ -1044,17 +1038,17 @@ nsHightailFileUploader.prototype = {
       this._fstream.close();
       // I don't trust re-using the old fstream.
       this._fstream = Cc["@mozilla.org/network/file-input-stream;1"]
                      .createInstance(Ci.nsIFileInputStream);
       this._fstream.init(this._tempFile, -1, 0, 0);
       this._bufStream = Cc["@mozilla.org/network/buffered-input-stream;1"]
                         .createInstance(Ci.nsIBufferedInputStream);
       this._bufStream.init(this._fstream, 4096);
-      // nsIXMLHttpRequest's nsIVariant handling requires that we QI
+      // XMLHttpRequest's nsIVariant handling requires that we QI
       // to nsIInputStream.
       req.sendInputStream(this._bufStream.QueryInterface(Ci.nsIInputStream));
     } catch (ex) {
       this.cleanupTempFile();
       this.log.error(ex);
       throw ex;
     }
   },
@@ -1077,18 +1071,17 @@ nsHightailFileUploader.prototype = {
     }
   },
   /**
    * Once the file is uploaded, if we want to get a sharing URL back, we have
    * to send a "commit" request - which this function does.
    */
   _commitSend: function() {
     this.log.info("commit sending file " + this._urlInfo.fileId);
-    let req = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
-                .createInstance(Ci.nsIXMLHttpRequest);
+    let req = new XMLHttpRequest();
     let args = "?name=" + this.file.leafName +
                "&fileId=" + this._urlInfo.fileId +
                "&parentId=" + this.hightail._folderId + "&";
 
     req.open("POST", gServerUrl + kFolderCommitUploadPath + args + kUrlTail, true);
 
     req.onerror = function() {
       this.log.info("error in commit send");
@@ -1155,18 +1148,17 @@ nsHightailFileUploader.prototype = {
   /**
    * Attempt to find download url for file.
    *
    * @param aFileId id of file
    * @param aSuccessCallback called if url is found
    * @param aFailureCallback called if url is not found
    */
   _findDownloadUrl: function(aFileId, aSuccessCallback, aFailureCallback) {
-    let req = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
-                .createInstance(Ci.nsIXMLHttpRequest);
+    let req = new XMLHttpRequest();
 
     req.open("GET", gServerUrl + kFolderFilePath + aFileId, true);
 
     req.onerror = function() {
       this.log.info("error in findDownloadUrl");
       aFailureCallback();
     }.bind(this);
 
--- a/mailnews/extensions/newsblog/content/Feed.js
+++ b/mailnews/extensions/newsblog/content/Feed.js
@@ -150,18 +150,17 @@ Feed.prototype =
       // active get new messages are handled prior to getting here.
       let win = Services.wm.getMostRecentWindow("mail:3pane");
       if (!win.MailOfflineMgr.getNewMail()) {
         this.storeNextItem();
         return;
       }
     }
 
-    this.request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].
-                   createInstance(Ci.nsIXMLHttpRequest);
+    this.request = new XMLHttpRequest();
     // Must set onProgress before calling open.
     this.request.onprogress = this.onProgress;
     this.request.open("GET", this.url, true);
     this.request.channel.loadFlags |= Ci.nsIRequest.LOAD_BYPASS_CACHE |
                                       Ci.nsIRequest.INHIBIT_CACHING;
 
     // Some servers, if sent If-Modified-Since, will send 304 if subsequently
     // not sent If-Modified-Since, as in the case of an unsubscribe and new
--- a/mailnews/extensions/newsblog/content/FeedUtils.jsm
+++ b/mailnews/extensions/newsblog/content/FeedUtils.jsm
@@ -10,16 +10,18 @@ var {classes: Cc, interfaces: Ci, utils:
 Cu.import("resource:///modules/gloda/log4moz.js");
 Cu.import("resource:///modules/mailServices.js");
 Cu.import("resource:///modules/MailUtils.js");
 Cu.import("resource:///modules/jsmime.jsm");
 Cu.import("resource://gre/modules/FileUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
+Cu.importGlobalProperties(["XMLHttpRequest"]);
+
 Services.scriptloader.loadSubScript("chrome://messenger-newsblog/content/Feed.js");
 Services.scriptloader.loadSubScript("chrome://messenger-newsblog/content/FeedItem.js");
 Services.scriptloader.loadSubScript("chrome://messenger-newsblog/content/feed-parser.js");
 
 var FeedUtils = {
   MOZ_PARSERERROR_NS: "http://www.mozilla.org/newlayout/xml/parsererror.xml",
 
   RDF_SYNTAX_NS: "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
@@ -1409,18 +1411,17 @@ var FeedUtils = {
     }
 
     // If feeditems.rdf is not sane, duplicate messages will occur repeatedly
     // until the file is corrected; check that the file is valid XML. This is
     // done lazily only once in a session.
     let fileUrl = Services.io.getProtocolHandler("file")
                              .QueryInterface(Ci.nsIFileProtocolHandler)
                              .getURLSpecFromFile(file);
-    let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
-                    .createInstance(Ci.nsIXMLHttpRequest);
+    let request = new XMLHttpRequest();
     request.open("GET", fileUrl, false);
     request.responseType = "document";
     request.send();
     let dom = request.responseXML;
     if (dom instanceof Ci.nsIDOMXMLDocument &&
         dom.documentElement.namespaceURI != this.MOZ_PARSERERROR_NS)
       return file;