1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "InternalRequest.h"
8 #include "nsIContentPolicy.h"
9 #include "nsIDocument.h"
11 #include "mozilla/ErrorResult.h"
12 #include "mozilla/dom/ScriptSettings.h"
13 #include "mozilla/dom/workers/Workers.h"
15 #include "WorkerPrivate.h"
20 // The global is used to extract the principal.
21 already_AddRefed
<InternalRequest
>
22 InternalRequest::GetRequestConstructorCopy(nsIGlobalObject
* aGlobal
, ErrorResult
& aRv
) const
24 nsRefPtr
<InternalRequest
> copy
= new InternalRequest();
25 copy
->mURL
.Assign(mURL
);
26 copy
->SetMethod(mMethod
);
27 copy
->mHeaders
= new InternalHeaders(*mHeaders
);
29 copy
->mBodyStream
= mBodyStream
;
30 copy
->mPreserveContentCodings
= true;
32 if (NS_IsMainThread()) {
33 nsIPrincipal
* principal
= aGlobal
->PrincipalOrNull();
34 MOZ_ASSERT(principal
);
35 aRv
= nsContentUtils::GetASCIIOrigin(principal
, copy
->mOrigin
);
36 if (NS_WARN_IF(aRv
.Failed())) {
40 workers::WorkerPrivate
* worker
= workers::GetCurrentThreadWorkerPrivate();
42 worker
->AssertIsOnWorkerThread();
44 workers::WorkerPrivate::LocationInfo
& location
= worker
->GetLocationInfo();
45 copy
->mOrigin
= NS_ConvertUTF16toUTF8(location
.mOrigin
);
48 copy
->mContext
= nsIContentPolicy::TYPE_FETCH
;
50 copy
->mCredentialsMode
= mCredentialsMode
;
54 InternalRequest::~InternalRequest()
59 } // namespace mozilla