mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 22:01:30 +00:00
Bug 1163898 part 2. Allow creation of an anonymous XHR in non-window scopes if the right mozAnon bits are passed in. r=smaug
This commit is contained in:
parent
068f758b05
commit
ca4d389a7a
@ -391,29 +391,33 @@ nsXMLHttpRequest::InitParameters(bool aAnon, bool aSystem)
|
||||
}
|
||||
|
||||
// Check for permissions.
|
||||
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(GetOwner());
|
||||
if (!window || !window->GetDocShell()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Chrome is always allowed access, so do the permission check only
|
||||
// for non-chrome pages.
|
||||
if (!IsSystemXHR() && aSystem) {
|
||||
nsCOMPtr<nsIDocument> doc = window->GetExtantDoc();
|
||||
if (!doc) {
|
||||
nsIGlobalObject* global = GetOwnerGlobal();
|
||||
if (NS_WARN_IF(!global)) {
|
||||
SetParameters(aAnon, false);
|
||||
return;
|
||||
}
|
||||
|
||||
nsIPrincipal* principal = global->PrincipalOrNull();
|
||||
if (NS_WARN_IF(!principal)) {
|
||||
SetParameters(aAnon, false);
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIPrincipal> principal = doc->NodePrincipal();
|
||||
nsCOMPtr<nsIPermissionManager> permMgr =
|
||||
services::GetPermissionManager();
|
||||
if (!permMgr)
|
||||
if (NS_WARN_IF(!permMgr)) {
|
||||
SetParameters(aAnon, false);
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t permission;
|
||||
nsresult rv =
|
||||
permMgr->TestPermissionFromPrincipal(principal, "systemXHR", &permission);
|
||||
if (NS_FAILED(rv) || permission != nsIPermissionManager::ALLOW_ACTION) {
|
||||
SetParameters(aAnon, false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
16
dom/tests/unit/test_xhr_init.js
Normal file
16
dom/tests/unit/test_xhr_init.js
Normal file
@ -0,0 +1,16 @@
|
||||
function run_test()
|
||||
{
|
||||
Components.utils.importGlobalProperties(["XMLHttpRequest"]);
|
||||
|
||||
var x = new XMLHttpRequest({mozAnon: true, mozSystem: false});
|
||||
do_check_true(x.mozAnon);
|
||||
do_check_true(x.mozSystem); // Because we're system principal
|
||||
|
||||
x = new XMLHttpRequest({mozAnon: true});
|
||||
do_check_true(x.mozAnon);
|
||||
do_check_true(x.mozSystem);
|
||||
|
||||
x = new XMLHttpRequest();
|
||||
do_check_false(x.mozAnon);
|
||||
do_check_true(x.mozSystem);
|
||||
}
|
@ -23,3 +23,4 @@ skip-if = os == "android"
|
||||
[test_geolocation_position_unavailable_wrap.js]
|
||||
skip-if = os == "mac" || os == "android"
|
||||
[test_PromiseDebugging.js]
|
||||
[test_xhr_init.js]
|
||||
|
Loading…
Reference in New Issue
Block a user