no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / dom / xhr / XMLHttpRequest.cpp
blobbe94267d63ec6f321175058f4d01b327a1db3f16
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "XMLHttpRequest.h"
8 #include "XMLHttpRequestMainThread.h"
9 #include "XMLHttpRequestWorker.h"
10 #include "mozilla/Logging.h"
11 #include "mozilla/net/CookieJarSettings.h"
13 mozilla::LazyLogModule gXMLHttpRequestLog("XMLHttpRequest");
15 namespace mozilla::dom {
17 /* static */
18 already_AddRefed<XMLHttpRequest> XMLHttpRequest::Constructor(
19 const GlobalObject& aGlobal, const MozXMLHttpRequestParameters& aParams,
20 ErrorResult& aRv) {
21 if (NS_IsMainThread()) {
22 nsCOMPtr<nsIGlobalObject> global =
23 do_QueryInterface(aGlobal.GetAsSupports());
24 nsCOMPtr<nsIScriptObjectPrincipal> principal =
25 do_QueryInterface(aGlobal.GetAsSupports());
26 if (!global || !principal) {
27 aRv.Throw(NS_ERROR_FAILURE);
28 return nullptr;
31 nsCOMPtr<nsICookieJarSettings> cookieJarSettings;
32 nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(global);
33 if (window) {
34 Document* document = window->GetExtantDoc();
35 if (NS_WARN_IF(!document)) {
36 aRv.Throw(NS_ERROR_FAILURE);
37 return nullptr;
40 cookieJarSettings = document->CookieJarSettings();
41 } else {
42 // We are here because this is a sandbox.
43 cookieJarSettings =
44 net::CookieJarSettings::Create(principal->GetPrincipal());
47 RefPtr<XMLHttpRequestMainThread> req = new XMLHttpRequestMainThread(global);
48 req->Construct(principal->GetPrincipal(), cookieJarSettings, false);
49 req->InitParameters(aParams.mMozAnon, aParams.mMozSystem);
50 return req.forget();
53 return XMLHttpRequestWorker::Construct(aGlobal, aParams, aRv);
56 } // namespace mozilla::dom