Bug 792808 - Change pktApi.jsm to import and instantiate XHRs from global properties rather than using Cc.createInstance(Ci.nsIXMLHttpRequest); r?Gijs
MozReview-Commit-ID: 8jdzIb95MmB
--- a/browser/extensions/pocket/content/pktApi.jsm
+++ b/browser/extensions/pocket/content/pktApi.jsm
@@ -43,16 +43,17 @@
*/
const Cm = Components.manager;
this.EXPORTED_SYMBOLS = ["pktApi"];
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
ChromeUtils.import("resource://gre/modules/Services.jsm");
+Cu.importGlobalProperties(["XMLHttpRequest"]);
var pktApi = (function() {
/**
* Configuration
*/
// Base url for all api calls
@@ -246,17 +247,17 @@ var pktApi = (function() {
return false;
}
var url = baseAPIUrl + options.path;
var data = options.data || {};
data.locale_lang = Services.locale.getAppLocaleAsLangTag();
data.consumer_key = oAuthConsumerKey;
- var request = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Components.interfaces.nsIXMLHttpRequest);
+ var request = new XMLHttpRequest();
request.open("POST", url, true);
request.onreadystatechange = function(e) {
if (request.readyState == 4) {
if (request.status === 200) {
// There could still be an error if the response is no valid json
// or does not have status = 1
var response = parseJSON(request.response);
if (options.success && response && response.status == 1) {