mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 765468 - Use a dictionary for the argument to the XMLHttpRequest constructor; r=bz
This commit is contained in:
parent
7199ac064a
commit
56a3842ca1
@ -553,28 +553,36 @@ nsXMLHttpRequest::InitParameters(JSContext* aCx, const jsval* aParams)
|
||||
nsresult rv = params.Init(aCx, aParams);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
InitParameters(params.mozAnon, params.mozSystem);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsXMLHttpRequest::InitParameters(bool aAnon, bool aSystem)
|
||||
{
|
||||
// Check for permissions.
|
||||
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(GetOwner());
|
||||
NS_ENSURE_TRUE(window && window->GetDocShell(), NS_OK);
|
||||
if (!window || !window->GetDocShell()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Chrome is always allowed access, so do the permission check only
|
||||
// for non-chrome pages.
|
||||
if (!nsContentUtils::IsCallerChrome()) {
|
||||
nsCOMPtr<nsIDocument> doc = do_QueryInterface(window->GetExtantDocument());
|
||||
NS_ENSURE_TRUE(doc, NS_OK);
|
||||
if (!doc) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
doc->NodePrincipal()->GetURI(getter_AddRefs(uri));
|
||||
|
||||
if (!nsContentUtils::URIIsChromeOrInPref(uri, "dom.systemXHR.whitelist")) {
|
||||
return NS_OK;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
mIsAnon = params.mozAnon;
|
||||
mIsSystem = params.mozSystem;
|
||||
|
||||
return NS_OK;
|
||||
mIsAnon = aAnon;
|
||||
mIsSystem = aSystem;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -182,7 +182,7 @@ public:
|
||||
static already_AddRefed<nsXMLHttpRequest>
|
||||
Constructor(JSContext* aCx,
|
||||
nsISupports* aGlobal,
|
||||
const mozilla::dom::Optional<jsval>& aParams,
|
||||
const mozilla::dom::Nullable<mozilla::dom::MozXMLHttpRequestParameters>& aParams,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal);
|
||||
@ -194,12 +194,9 @@ public:
|
||||
|
||||
nsRefPtr<nsXMLHttpRequest> req = new nsXMLHttpRequest();
|
||||
req->Construct(principal->GetPrincipal(), window);
|
||||
if (aParams.WasPassed()) {
|
||||
nsresult rv = req->InitParameters(aCx, &aParams.Value());
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
return req.forget();
|
||||
}
|
||||
if (!aParams.IsNull()) {
|
||||
const mozilla::dom::MozXMLHttpRequestParameters& params = aParams.Value();
|
||||
req->InitParameters(params.mozAnon, params.mozSystem);
|
||||
}
|
||||
return req.forget();
|
||||
}
|
||||
@ -217,6 +214,7 @@ public:
|
||||
|
||||
// Initialize XMLHttpRequestParameter object.
|
||||
nsresult InitParameters(JSContext* aCx, const jsval* aParams);
|
||||
void InitParameters(bool aAnon, bool aSystem);
|
||||
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
|
@ -21,6 +21,8 @@ function runTests() {
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
let validParameters = [
|
||||
undefined,
|
||||
null,
|
||||
{},
|
||||
{mozSystem: ""},
|
||||
{mozSystem: 0},
|
||||
@ -30,8 +32,12 @@ function runTests() {
|
||||
];
|
||||
|
||||
let invalidParameters = [
|
||||
undefined,
|
||||
null,
|
||||
0,
|
||||
7,
|
||||
Math.PI,
|
||||
"string",
|
||||
true,
|
||||
false,
|
||||
{get mozSystem() { throw "Bla"; } },
|
||||
];
|
||||
|
||||
|
@ -31,7 +31,27 @@ enum XMLHttpRequestResponseType {
|
||||
"moz-blob"
|
||||
};
|
||||
|
||||
[Constructor(optional any params)]
|
||||
/**
|
||||
* Parameters for instantiating an XMLHttpRequest. They are passed as an
|
||||
* optional argument to the constructor:
|
||||
*
|
||||
* new XMLHttpRequest({anon: true, system: true});
|
||||
*/
|
||||
dictionary MozXMLHttpRequestParameters
|
||||
{
|
||||
/**
|
||||
* If true, the request will be sent without cookie and authentication
|
||||
* headers.
|
||||
*/
|
||||
boolean mozAnon = false;
|
||||
|
||||
/**
|
||||
* If true, the same origin policy will not be enforced on the request.
|
||||
*/
|
||||
boolean mozSystem = false;
|
||||
};
|
||||
|
||||
[Constructor(optional MozXMLHttpRequestParameters? params = null)]
|
||||
interface XMLHttpRequest : XMLHttpRequestEventTarget {
|
||||
// event handler
|
||||
[TreatNonCallableAsNull] attribute Function? onreadystatechange;
|
||||
|
@ -1466,7 +1466,7 @@ XMLHttpRequest::_finalize(JSFreeOp* aFop)
|
||||
XMLHttpRequest*
|
||||
XMLHttpRequest::Constructor(JSContext* aCx,
|
||||
JSObject* aGlobal,
|
||||
const Optional<jsval>& aParams,
|
||||
const Nullable<MozXMLHttpRequestParametersWorkers>& aParams,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx);
|
||||
|
@ -72,7 +72,8 @@ public:
|
||||
|
||||
static XMLHttpRequest*
|
||||
Constructor(JSContext* aCx, JSObject* aGlobal,
|
||||
const Optional<jsval>& aParams, ErrorResult& aRv);
|
||||
const Nullable<MozXMLHttpRequestParametersWorkers>& aParams,
|
||||
ErrorResult& aRv);
|
||||
void
|
||||
Unpin();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user