Bug 792808 - Change devtools/ to import and instantiate XHRs from global properties rather than using Cc.createInstance(Ci.nsIXMLHttpRequest), and the same for FormData; r=Honza
authorThomas Wisniewski <wisniewskit@gmail.com>
Mon, 20 Nov 2017 00:27:39 -0500
changeset 404223 b2aa9ec1a16389df69befa4960d0f1d3aebd5619
parent 404222 2caa8dcfef0f6ac8c95c6ed0dd81fb3a5381213f
child 404224 4d3bc187d05c62dffe50132f328b71220db3f884
push id99968
push userrgurzau@mozilla.com
push dateFri, 16 Feb 2018 22:14:56 +0000
treeherdermozilla-inbound@2e16779c96cc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersHonza
bugs792808
milestone60.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 792808 - Change devtools/ to import and instantiate XHRs from global properties rather than using Cc.createInstance(Ci.nsIXMLHttpRequest), and the same for FormData; r=Honza MozReview-Commit-ID: HCziNedavb0
devtools/client/shared/getjson.js
devtools/client/webide/modules/app-validator.js
devtools/shared/builtin-modules.js
devtools/shared/fronts/device.js
devtools/shared/gcli/commands/jsb.js
devtools/shared/gcli/commands/screenshot.js
devtools/shared/gcli/source/lib/gcli/util/host.js
--- a/devtools/client/shared/getjson.js
+++ b/devtools/client/shared/getjson.js
@@ -1,21 +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/. */
 
 "use strict";
 
-const {CC} = require("chrome");
 const Services = require("Services");
 
 loader.lazyRequireGetter(this, "asyncStorage", "devtools/shared/async-storage");
 
-const XMLHttpRequest = CC("@mozilla.org/xmlextras/xmlhttprequest;1");
-
 /**
  * Downloads and caches a JSON file from an URL given by a pref.
  *
  * @param {String} prefName
  *        The preference for the target URL
  *
  * @return {Promise}
  *         - Resolved with the JSON object in case of successful request
--- a/devtools/client/webide/modules/app-validator.js
+++ b/devtools/client/webide/modules/app-validator.js
@@ -1,19 +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/. */
 "use strict";
 
-var {Ci, Cu, CC} = require("chrome");
+var {Ci, Cu} = require("chrome");
 
 const {FileUtils} = require("resource://gre/modules/FileUtils.jsm");
 const Services = require("Services");
 const {Task} = require("devtools/shared/task");
-var XMLHttpRequest = CC("@mozilla.org/xmlextras/xmlhttprequest;1");
 var strings = Services.strings.createBundle("chrome://devtools/locale/app-manager.properties");
 
 function AppValidator({ type, location }) {
   this.type = type;
   this.location = location;
   this.errors = [];
   this.warnings = [];
 }
--- a/devtools/shared/builtin-modules.js
+++ b/devtools/shared/builtin-modules.js
@@ -13,17 +13,17 @@
  * they would also miss them.
  */
 
 const { Cu, CC, Cc, Ci } = require("chrome");
 const promise = require("resource://gre/modules/Promise.jsm").Promise;
 const jsmScope = require("resource://gre/modules/Services.jsm");
 const { Services } = jsmScope;
 // Steal various globals only available in JSM scope (and not Sandbox one)
-const { ChromeUtils, HeapSnapshot,
+const { ChromeUtils, HeapSnapshot, XMLHttpRequest
         atob, btoa, TextEncoder, TextDecoder } = Cu.getGlobalForObject(jsmScope);
 
 // Create a single Sandbox to access global properties needed in this module.
 // Sandbox are memory expensive, so we should create as little as possible.
 const { CSS, CSSRule, FileReader, indexedDB, InspectorUtils, URL } =
     Cu.Sandbox(CC("@mozilla.org/systemprincipal;1", "nsIPrincipal")(), {
       wantGlobalProperties: [
         "CSS", "CSSRule", "FileReader", "indexedDB", "InspectorUtils", "URL",
@@ -226,21 +226,17 @@ exports.globals = {
     lazyGetter: defineLazyGetter,
     lazyImporter: defineLazyModuleGetter,
     lazyServiceGetter: defineLazyServiceGetter,
     lazyRequireGetter: lazyRequireGetter,
     // Defined by Loader.jsm
     id: null
   },
 
-  // Let new XMLHttpRequest do the right thing.
-  XMLHttpRequest: function () {
-    return Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
-           .createInstance(Ci.nsIXMLHttpRequest);
-  },
+  XMLHttpRequest: XMLHttpRequest,
 
   Node: Ci.nsIDOMNode,
   Element: Ci.nsIDOMElement,
   DocumentFragment: Ci.nsIDOMDocumentFragment,
 
   // Make sure `define` function exists.  This allows defining some modules
   // in AMD format while retaining CommonJS compatibility through this hook.
   // JSON Viewer needs modules in AMD format, as it currently uses RequireJS
--- a/devtools/shared/fronts/device.js
+++ b/devtools/shared/fronts/device.js
@@ -1,32 +1,31 @@
 /* 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/. */
 "use strict";
 
-const {Cc, Ci, Cu} = require("chrome");
+const {Cu} = require("chrome");
 const {deviceSpec} = require("devtools/shared/specs/device");
 const protocol = require("devtools/shared/protocol");
 const defer = require("devtools/shared/defer");
 
 const DeviceFront = protocol.FrontClassWithSpec(deviceSpec, {
   initialize: function (client, form) {
     protocol.Front.prototype.initialize.call(this, client);
     this.actorID = form.deviceActor;
     this.manage(this);
   },
 
   screenshotToBlob: function () {
     return this.screenshotToDataURL().then(longstr => {
       return longstr.string().then(dataURL => {
         let deferred = defer();
         longstr.release().catch(Cu.reportError);
-        let req = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
-            .createInstance(Ci.nsIXMLHttpRequest);
+        let req = new XMLHttpRequest();
         req.open("GET", dataURL, true);
         req.responseType = "blob";
         req.onload = () => {
           deferred.resolve(req.response);
         };
         req.onerror = () => {
           deferred.reject(req.status);
         };
--- a/devtools/shared/gcli/commands/jsb.js
+++ b/devtools/shared/gcli/commands/jsb.js
@@ -1,17 +1,15 @@
 /* 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/. */
 
 "use strict";
 
-const { Cc } = require("chrome");
 const l10n = require("gcli/l10n");
-const XMLHttpRequest = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"];
 
 loader.lazyImporter(this, "Preferences", "resource://gre/modules/Preferences.jsm");
 loader.lazyImporter(this, "ScratchpadManager", "resource://devtools/client/scratchpad/scratchpad-manager.jsm");
 
 loader.lazyRequireGetter(this, "beautify", "devtools/shared/jsbeautify/beautify");
 
 exports.items = [
   {
--- a/devtools/shared/gcli/commands/screenshot.js
+++ b/devtools/shared/gcli/commands/screenshot.js
@@ -423,20 +423,18 @@ function saveToClipboard(context, reply)
   });
 }
 
 /**
  * Upload screenshot data to Imgur, returning a promise of a URL (as a string)
  */
 function uploadToImgur(reply) {
   return new Promise((resolve, reject) => {
-    const xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
-                  .createInstance(Ci.nsIXMLHttpRequest);
-    const fd = Cc["@mozilla.org/files/formdata;1"]
-                  .createInstance(Ci.nsIDOMFormData);
+    const xhr = new XMLHttpRequest();
+    const fd = new FormData();
     fd.append("image", reply.data.split(",")[1]);
     fd.append("type", "base64");
     fd.append("title", reply.filename);
 
     const postURL = Services.prefs.getCharPref("devtools.gcli.imgurUploadURL");
     const clientID = "Client-ID " +
                      Services.prefs.getCharPref("devtools.gcli.imgurClientID");
 
--- a/devtools/shared/gcli/source/lib/gcli/util/host.js
+++ b/devtools/shared/gcli/source/lib/gcli/util/host.js
@@ -11,18 +11,19 @@
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 'use strict';
 
-var Cc = require('chrome').Cc;
-var Ci = require('chrome').Ci;
+const { Cc, Ci, Cu } = require("chrome");
+
+Cu.importGlobalProperties(["XMLHttpRequest"]);
 
 var { Task } = require("devtools/shared/task");
 
 var util = require('./util');
 
 function Highlighter(document) {
   this._document = document;
   this._nodes = util.createEmptyNodeList(this._document);
@@ -105,18 +106,17 @@ exports.staticRequire = function(requist
     return Promise.resolve('');
   }
   else {
     return new Promise((resolve, reject) => {
       var filename = resourceDirName(requistingModule.id) + '/' + name;
       filename = filename.replace(/\/\.\//g, '/');
       filename = 'resource://devtools/shared/gcli/source/lib/' + filename;
 
-      var xhr = Cc['@mozilla.org/xmlextras/xmlhttprequest;1']
-                  .createInstance(Ci.nsIXMLHttpRequest);
+      var xhr = new XMLHttpRequest();
 
       xhr.onload = () => {
         resolve(xhr.responseText);
       };
 
       xhr.onabort = xhr.onerror = xhr.ontimeout = err => {
         reject(err);
       };