Bumping manifests a=b2g-bump
[gecko.git] / dom / fetch / InternalRequest.cpp
blob46603f6d346f36259ae4212e7bf2e0ef744f28bc
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"
17 namespace mozilla {
18 namespace dom {
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())) {
37 return nullptr;
39 } else {
40 workers::WorkerPrivate* worker = workers::GetCurrentThreadWorkerPrivate();
41 MOZ_ASSERT(worker);
42 worker->AssertIsOnWorkerThread();
44 workers::WorkerPrivate::LocationInfo& location = worker->GetLocationInfo();
45 copy->mOrigin = NS_ConvertUTF16toUTF8(location.mOrigin);
48 copy->mContext = nsIContentPolicy::TYPE_FETCH;
49 copy->mMode = mMode;
50 copy->mCredentialsMode = mCredentialsMode;
51 return copy.forget();
54 InternalRequest::~InternalRequest()
58 } // namespace dom
59 } // namespace mozilla