зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1325501 - move addons manager from XHR to ServiceRequest r=kmag
MozReview-Commit-ID: J0ytKWqDOr3 --HG-- extra : rebase_source : c87a158d5cd47598c8520ce96c796b1f4ca0ed17
This commit is contained in:
Родитель
505a86593c
Коммит
fb615ad9b0
|
@ -42,6 +42,9 @@ const PERSIST_FILES = {
|
|||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "LightweightThemeImageOptimizer",
|
||||
"resource://gre/modules/addons/LightweightThemeImageOptimizer.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "ServiceRequest",
|
||||
"resource://gre/modules/ServiceRequest.jsm");
|
||||
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "_prefs", () => {
|
||||
return Services.prefs.getBranch("lightweightThemes.");
|
||||
|
@ -254,8 +257,7 @@ this.LightweightThemeManager = {
|
|||
if (!theme || !theme.updateURL)
|
||||
return;
|
||||
|
||||
var req = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
|
||||
.createInstance(Ci.nsIXMLHttpRequest);
|
||||
var req = new ServiceRequest();
|
||||
|
||||
req.mozBackgroundRequest = true;
|
||||
req.overrideMimeType("text/plain");
|
||||
|
|
|
@ -26,6 +26,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "Preferences",
|
|||
"resource://gre/modules/Preferences.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "Promise",
|
||||
"resource://gre/modules/Promise.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "ServiceRequest",
|
||||
"resource://gre/modules/ServiceRequest.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "Task",
|
||||
"resource://gre/modules/Task.jsm");
|
||||
|
||||
|
@ -100,10 +102,6 @@ const INTEGER_KEY_MAP = {
|
|||
daily_users: "dailyUsers"
|
||||
};
|
||||
|
||||
// Wrap the XHR factory so that tests can override with a mock
|
||||
var XHRequest = Components.Constructor("@mozilla.org/xmlextras/xmlhttprequest;1",
|
||||
"nsIXMLHttpRequest");
|
||||
|
||||
function convertHTMLToPlainText(html) {
|
||||
if (!html)
|
||||
return html;
|
||||
|
@ -1433,7 +1431,7 @@ this.AddonRepository = {
|
|||
|
||||
logger.debug("Requesting " + aURI);
|
||||
|
||||
this._request = new XHRequest();
|
||||
this._request = new ServiceRequest();
|
||||
this._request.mozBackgroundRequest = true;
|
||||
this._request.open("GET", aURI, true);
|
||||
this._request.overrideMimeType("text/xml");
|
||||
|
|
|
@ -35,6 +35,9 @@ XPCOMUtils.defineLazyModuleGetter(this, "AddonManagerPrivate",
|
|||
"resource://gre/modules/AddonManager.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "AddonRepository",
|
||||
"resource://gre/modules/addons/AddonRepository.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "ServiceRequest",
|
||||
"resource://gre/modules/ServiceRequest.jsm");
|
||||
|
||||
|
||||
// Shared code for suppressing bad cert dialogs.
|
||||
XPCOMUtils.defineLazyGetter(this, "CertUtils", function() {
|
||||
|
@ -578,8 +581,7 @@ function UpdateParser(aId, aUpdateKey, aUrl, aObserver) {
|
|||
|
||||
logger.debug("Requesting " + aUrl);
|
||||
try {
|
||||
this.request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].
|
||||
createInstance(Ci.nsIXMLHttpRequest);
|
||||
this.request = new ServiceRequest();
|
||||
this.request.open("GET", this.url, true);
|
||||
this.request.channel.notificationCallbacks = new CertUtils.BadCertHandler(!requireBuiltIn);
|
||||
this.request.channel.loadFlags |= Ci.nsIRequest.LOAD_BYPASS_CACHE;
|
||||
|
|
|
@ -42,15 +42,18 @@ XPCOMUtils.defineLazyModuleGetter(this, "GMPPrefs",
|
|||
XPCOMUtils.defineLazyModuleGetter(this, "UpdateUtils",
|
||||
"resource://gre/modules/UpdateUtils.jsm");
|
||||
|
||||
var logger = Log.repository.getLogger("addons.productaddons");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "ServiceRequest",
|
||||
"resource://gre/modules/ServiceRequest.jsm");
|
||||
|
||||
// This exists so that tests can override the XHR behaviour for downloading
|
||||
// the addon update XML file.
|
||||
var CreateXHR = function() {
|
||||
return Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].
|
||||
createInstance(Ci.nsISupports);
|
||||
createInstance(Ci.nsISupports);
|
||||
}
|
||||
|
||||
var logger = Log.repository.getLogger("addons.productaddons");
|
||||
|
||||
/**
|
||||
* Number of milliseconds after which we need to cancel `downloadXML`.
|
||||
*
|
||||
|
@ -113,6 +116,11 @@ function downloadXML(url, allowNonBuiltIn = false, allowedCerts = null) {
|
|||
request.channel.loadFlags |= Ci.nsIRequest.LOAD_BYPASS_CACHE;
|
||||
// Prevent the request from writing to the cache.
|
||||
request.channel.loadFlags |= Ci.nsIRequest.INHIBIT_CACHING;
|
||||
// Use conservative TLS settings. See bug 1325501.
|
||||
// TODO move to ServiceRequest.
|
||||
if (request.channel instanceof Ci.nsIHttpChannelInternal) {
|
||||
request.channel.QueryInterface(Ci.nsIHttpChannelInternal).beConservative = true;
|
||||
}
|
||||
request.timeout = TIMEOUT_DELAY_MS;
|
||||
|
||||
request.overrideMimeType("text/xml");
|
||||
|
@ -163,7 +171,7 @@ function downloadXML(url, allowNonBuiltIn = false, allowedCerts = null) {
|
|||
function downloadJSON(uri) {
|
||||
logger.info("fetching config from: " + uri);
|
||||
return new Promise((resolve, reject) => {
|
||||
let xmlHttp = new XMLHttpRequest({mozAnon: true});
|
||||
let xmlHttp = new ServiceRequest({mozAnon: true});
|
||||
|
||||
xmlHttp.onload = function(aResponse) {
|
||||
resolve(JSON.parse(this.responseText));
|
||||
|
@ -290,8 +298,7 @@ function downloadLocalConfig() {
|
|||
*/
|
||||
function downloadFile(url) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].
|
||||
createInstance(Ci.nsISupports);
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.onload = function(response) {
|
||||
logger.info("downloadXHR File download. status=" + xhr.status);
|
||||
if (xhr.status != 200 && xhr.status != 206) {
|
||||
|
@ -323,6 +330,11 @@ function downloadFile(url) {
|
|||
xhr.responseType = "arraybuffer";
|
||||
try {
|
||||
xhr.open("GET", url);
|
||||
// Use conservative TLS settings. See bug 1325501.
|
||||
// TODO move to ServiceRequest.
|
||||
if (xhr.channel instanceof Ci.nsIHttpChannelInternal) {
|
||||
xhr.channel.QueryInterface(Ci.nsIHttpChannelInternal).beConservative = true;
|
||||
}
|
||||
xhr.send(null);
|
||||
} catch (ex) {
|
||||
reject(ex);
|
||||
|
|
|
@ -29,6 +29,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "UpdateUtils",
|
|||
"resource://gre/modules/UpdateUtils.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "OS",
|
||||
"resource://gre/modules/osfile.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "ServiceRequest",
|
||||
"resource://gre/modules/ServiceRequest.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "Task",
|
||||
"resource://gre/modules/Task.jsm");
|
||||
|
||||
|
@ -608,8 +610,7 @@ Blocklist.prototype = {
|
|||
}
|
||||
|
||||
LOG("Blocklist::notify: Requesting " + uri.spec);
|
||||
var request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].
|
||||
createInstance(Ci.nsIXMLHttpRequest);
|
||||
let request = new ServiceRequest();
|
||||
request.open("GET", uri.spec, true);
|
||||
request.channel.notificationCallbacks = new gCertUtils.BadCertHandler();
|
||||
request.overrideMimeType("text/xml");
|
||||
|
|
|
@ -17,8 +17,8 @@ var ARContext = Components.utils.import("resource://gre/modules/addons/AddonRepo
|
|||
// Mock out the XMLHttpRequest factory for AddonRepository so
|
||||
// we can reply with a timeout
|
||||
var pXHRStarted = Promise.defer();
|
||||
var oldXHRConstructor = ARContext.XHRequest;
|
||||
ARContext.XHRequest = function() {
|
||||
var oldXHRConstructor = ARContext.ServiceRequest;
|
||||
ARContext.ServiceRequest = function() {
|
||||
this._handlers = new Map();
|
||||
this.mozBackgroundRequest = false;
|
||||
this.timeout = undefined;
|
||||
|
@ -106,7 +106,7 @@ add_task(function* amo_ping_timeout() {
|
|||
xhr._handlers.get("timeout")();
|
||||
|
||||
// Put the old XHR constructor back
|
||||
ARContext.XHRequest = oldXHRConstructor;
|
||||
ARContext.ServiceRequest = oldXHRConstructor;
|
||||
// The window should close without further interaction
|
||||
yield promise_window_close(compatWindow);
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче