mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:18:48 +00:00
24dc63cddd
- Bug 1205941 - Make TimerFirings logging output post-processible with fix_linux_stack.py. r=glandium. (042e3968a2) - Bug 1203427 (part 6) - Add link to MDN docs about TimerFirings logging. r=me. (19967a22e7) - missing bit of Bug 1178890 (b421ab56a1) - Bug 1207497 - Part 1: Remove use of expression closure from toolkit/, exept tests. r=Gijs (4cf4abbf3d) - Bug 1207497 - Part 2: Remove use of expression closure from tests in toolkit/. r=Gijs (6c4517c20e) - Bug 1207497 - Part 3: Fix wrong replacement in debug print in toolkit/mozapps/downloads/tests/unit/test_lowMinutes.js. r=me DONTBUILD (5311950d45) - bug 1171649 - Implement arm/iOS support in JS JITs. r=jandem (0eb06f1d3d) - Bug 1205708: Check if validation failed before reporting helper thread failure in Odin; r=luke (0bd8b70919) - missing bit of Bug 1112627: Remove redundant inline specifier in SIMD (76cea80b8c) - Bug 1189059: Replace setObjectMetadataCallback with enableObjectMetadataCallback, fix callers. r=fitzgen (053ae86af2) - Bug 1125412 - Draw a graph of memory usage, r=terrence (4ac21380a4) - Bug 1147985 - Avoid blank space when heap size graph is unavailable, r=terrence (9b48d4d435) - Bug 1170372 - Skip js1_5/Regress/regress-312588.js on SM(cgc) builds due to timeouts. (5298485837) - Bug 1160149 - Skip basic/testManyVars.js on SM(cgc) builds for frequent timeouts. (562cfc2713) - Bug 1198549 - Switch from | to $ as the preferred separator token (due to operator|), r=me\ (cc6fdb0697) - Bug 963738 - Handle Arrays in the analysis, r=terrence (589b285306) - Bug 1209696 - Check the return value of fopen, r=terrence (8c2378f3f9) - Bug 1197941 - Allow getline() to malloc its own buffer to avoid intermittent crashes, r=shu (e37b934fcc) - Bug 1180985 - Implement a JS GDB pretty-printer for JS::GCCellPtr. r=sfink (8848723b3a) - Bug 1180984 - JS GDB pretty-printers: Support Python 3. r=sfink (ae4c76014d) - Bug 1198628 - IonMonkey: ARM: Redefine FloatRegisters::Code and use it in the right way. r=nbp (d0d608b1cc) - Bug 1198145 - guard calls to getInst(). r=me (bb8c4e2e4b)
101 lines
3.8 KiB
JavaScript
101 lines
3.8 KiB
JavaScript
/* 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/. */
|
|
|
|
const EXPORTED_SYMBOLS = ["httpRequest", "percentEncode"];
|
|
|
|
const {classes: Cc, interfaces: Ci} = Components;
|
|
|
|
// Strictly follow RFC 3986 when encoding URI components.
|
|
// Accepts a unescaped string and returns the URI encoded string for use in
|
|
// an HTTP request.
|
|
function percentEncode(aString) {
|
|
return encodeURIComponent(aString).replace(/[!'()]/g, escape).replace(/\*/g, "%2A");
|
|
}
|
|
|
|
/*
|
|
* aOptions can have a variety of fields:
|
|
* headers, an array of headers
|
|
* postData, this can be:
|
|
* a string: send it as is
|
|
* an array of parameters: encode as form values
|
|
* null/undefined: no POST data.
|
|
* method, GET, POST or PUT (this is set automatically if postData exists).
|
|
* onLoad, a function handle to call when the load is complete, it takes two
|
|
* parameters: the responseText and the XHR object.
|
|
* onError, a function handle to call when an error occcurs, it takes three
|
|
* parameters: the error, the responseText and the XHR object.
|
|
* logger, an object that implements the debug and log methods (e.g. log.jsm).
|
|
*
|
|
* Headers or post data are given as an array of arrays, for each each inner
|
|
* array the first value is the key and the second is the value, e.g.
|
|
* [["key1", "value1"], ["key2", "value2"]].
|
|
*/
|
|
function httpRequest(aUrl, aOptions) {
|
|
let xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
|
|
.createInstance(Ci.nsIXMLHttpRequest);
|
|
xhr.mozBackgroundRequest = true; // no error dialogs
|
|
xhr.open(aOptions.method || (aOptions.postData ? "POST" : "GET"), aUrl);
|
|
xhr.channel.loadFlags = Ci.nsIChannel.LOAD_ANONYMOUS | // don't send cookies
|
|
Ci.nsIChannel.LOAD_BYPASS_CACHE |
|
|
Ci.nsIChannel.INHIBIT_CACHING;
|
|
xhr.onerror = function(aProgressEvent) {
|
|
if (aOptions.onError) {
|
|
// adapted from toolkit/mozapps/extensions/nsBlocklistService.js
|
|
let request = aProgressEvent.target;
|
|
let status;
|
|
try {
|
|
// may throw (local file or timeout)
|
|
status = request.status;
|
|
}
|
|
catch (e) {
|
|
request = request.channel.QueryInterface(Ci.nsIRequest);
|
|
status = request.status;
|
|
}
|
|
// When status is 0 we don't have a valid channel.
|
|
let statusText = status ? request.statusText : "offline";
|
|
aOptions.onError(statusText, null, this);
|
|
}
|
|
};
|
|
xhr.onload = function(aRequest) {
|
|
try {
|
|
let target = aRequest.target;
|
|
if (aOptions.logger)
|
|
aOptions.logger.debug("Received response: " + target.responseText);
|
|
if (target.status < 200 || target.status >= 300) {
|
|
let errorText = target.responseText;
|
|
if (!errorText || /<(ht|\?x)ml\b/i.test(errorText))
|
|
errorText = target.statusText;
|
|
throw target.status + " - " + errorText;
|
|
}
|
|
if (aOptions.onLoad)
|
|
aOptions.onLoad(target.responseText, this);
|
|
} catch (e) {
|
|
if (aOptions.onError)
|
|
aOptions.onError(e, aRequest.target.responseText, this);
|
|
}
|
|
};
|
|
|
|
if (aOptions.headers) {
|
|
aOptions.headers.forEach(function(header) {
|
|
xhr.setRequestHeader(header[0], header[1]);
|
|
});
|
|
}
|
|
|
|
// Handle adding postData as defined above.
|
|
let POSTData = aOptions.postData || null;
|
|
if (POSTData && Array.isArray(POSTData)) {
|
|
xhr.setRequestHeader("Content-Type",
|
|
"application/x-www-form-urlencoded; charset=utf-8");
|
|
POSTData = POSTData.map(p => p[0] + "=" + percentEncode(p[1]))
|
|
.join("&");
|
|
}
|
|
|
|
if (aOptions.logger) {
|
|
aOptions.logger.log("sending request to " + aUrl + " (POSTData = " +
|
|
POSTData + ")");
|
|
}
|
|
xhr.send(POSTData);
|
|
return xhr;
|
|
}
|