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
{
18 already_AddRefed
<XMLHttpRequest
> XMLHttpRequest::Constructor(
19 const GlobalObject
& aGlobal
, const MozXMLHttpRequestParameters
& aParams
,
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
);
31 nsCOMPtr
<nsICookieJarSettings
> cookieJarSettings
;
32 nsCOMPtr
<nsPIDOMWindowInner
> window
= do_QueryInterface(global
);
34 Document
* document
= window
->GetExtantDoc();
35 if (NS_WARN_IF(!document
)) {
36 aRv
.Throw(NS_ERROR_FAILURE
);
40 cookieJarSettings
= document
->CookieJarSettings();
42 // We are here because this is a sandbox.
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
);
53 return XMLHttpRequestWorker::Construct(aGlobal
, aParams
, aRv
);
56 } // namespace mozilla::dom