diff options
Diffstat (limited to 'dom/xhr/XMLHttpRequest.cpp')
-rw-r--r-- | dom/xhr/XMLHttpRequest.cpp | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/dom/xhr/XMLHttpRequest.cpp b/dom/xhr/XMLHttpRequest.cpp index be94267d63..8807c5515a 100644 --- a/dom/xhr/XMLHttpRequest.cpp +++ b/dom/xhr/XMLHttpRequest.cpp @@ -7,7 +7,9 @@ #include "XMLHttpRequest.h" #include "XMLHttpRequestMainThread.h" #include "XMLHttpRequestWorker.h" +#include "mozilla/BasePrincipal.h" #include "mozilla/Logging.h" +#include "mozilla/StaticPrefs_network.h" #include "mozilla/net/CookieJarSettings.h" mozilla::LazyLogModule gXMLHttpRequestLog("XMLHttpRequest"); @@ -21,15 +23,16 @@ already_AddRefed<XMLHttpRequest> XMLHttpRequest::Constructor( if (NS_IsMainThread()) { nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports()); - nsCOMPtr<nsIScriptObjectPrincipal> principal = + nsCOMPtr<nsIScriptObjectPrincipal> scriptPrincipal = do_QueryInterface(aGlobal.GetAsSupports()); - if (!global || !principal) { + if (!global || !scriptPrincipal) { aRv.Throw(NS_ERROR_FAILURE); return nullptr; } nsCOMPtr<nsICookieJarSettings> cookieJarSettings; nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(global); + nsCOMPtr<nsIPrincipal> principal = scriptPrincipal->GetPrincipal(); if (window) { Document* document = window->GetExtantDoc(); if (NS_WARN_IF(!document)) { @@ -40,13 +43,21 @@ already_AddRefed<XMLHttpRequest> XMLHttpRequest::Constructor( cookieJarSettings = document->CookieJarSettings(); } else { // We are here because this is a sandbox. - cookieJarSettings = - net::CookieJarSettings::Create(principal->GetPrincipal()); + cookieJarSettings = net::CookieJarSettings::Create(principal); } RefPtr<XMLHttpRequestMainThread> req = new XMLHttpRequestMainThread(global); - req->Construct(principal->GetPrincipal(), cookieJarSettings, false); - req->InitParameters(aParams.mMozAnon, aParams.mMozSystem); + req->Construct(principal, cookieJarSettings, false); + + bool isAnon = false; + if (aParams.mMozAnon.WasPassed()) { + isAnon = aParams.mMozAnon.Value(); + } else { + isAnon = + StaticPrefs::network_fetch_systemDefaultsToOmittingCredentials() && + (aParams.mMozSystem || principal->IsSystemPrincipal()); + } + req->InitParameters(isAnon, aParams.mMozSystem); return req.forget(); } |