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
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_Request_h
8 #define mozilla_dom_Request_h
10 #include "nsISupportsImpl.h"
11 #include "nsWrapperCache.h"
13 #include "mozilla/dom/Fetch.h"
14 #include "mozilla/dom/InternalRequest.h"
15 // Required here due to certain WebIDL enums/classes being declared in both
17 #include "mozilla/dom/RequestBinding.h"
18 #include "mozilla/dom/SafeRefPtr.h"
20 namespace mozilla::dom
{
23 class InternalHeaders
;
24 class RequestOrUSVString
;
26 class Request final
: public FetchBody
<Request
>, public nsWrapperCache
{
27 NS_DECL_ISUPPORTS_INHERITED
28 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS_INHERITED(Request
,
32 Request(nsIGlobalObject
* aOwner
, SafeRefPtr
<InternalRequest
> aRequest
,
33 AbortSignal
* aSignal
);
35 JSObject
* WrapObject(JSContext
* aCx
,
36 JS::Handle
<JSObject
*> aGivenProto
) override
{
37 return Request_Binding::Wrap(aCx
, this, aGivenProto
);
40 void GetUrl(nsAString
& aUrl
) const {
42 mRequest
->GetURL(url
);
43 CopyUTF8toUTF16(url
, aUrl
);
46 void GetMethod(nsCString
& aMethod
) const { aMethod
= mRequest
->mMethod
; }
48 RequestMode
Mode() const { return mRequest
->mMode
; }
50 RequestCredentials
Credentials() const { return mRequest
->mCredentialsMode
; }
52 RequestCache
Cache() const { return mRequest
->GetCacheMode(); }
54 RequestRedirect
Redirect() const { return mRequest
->GetRedirectMode(); }
56 void GetIntegrity(nsAString
& aIntegrity
) const {
57 aIntegrity
= mRequest
->GetIntegrity();
60 bool MozErrors() const { return mRequest
->MozErrors(); }
62 RequestDestination
Destination() const { return mRequest
->Destination(); }
64 void OverrideContentPolicyType(uint32_t aContentPolicyType
) {
65 mRequest
->OverrideContentPolicyType(
66 static_cast<nsContentPolicyType
>(aContentPolicyType
));
69 bool IsContentPolicyTypeOverridden() const {
70 return mRequest
->IsContentPolicyTypeOverridden();
73 void GetReferrer(nsAString
& aReferrer
) const {
74 mRequest
->GetReferrer(aReferrer
);
77 ReferrerPolicy
ReferrerPolicy_() const { return mRequest
->ReferrerPolicy_(); }
79 InternalHeaders
* GetInternalHeaders() const { return mRequest
->Headers(); }
83 using FetchBody::GetBody
;
85 void GetBody(nsIInputStream
** aStream
, int64_t* aBodyLength
= nullptr) {
86 mRequest
->GetBody(aStream
, aBodyLength
);
89 void SetBody(nsIInputStream
* aStream
, int64_t aBodyLength
) {
90 mRequest
->SetBody(aStream
, aBodyLength
);
93 using FetchBody::BodyBlobURISpec
;
95 const nsACString
& BodyBlobURISpec() const {
96 return mRequest
->BodyBlobURISpec();
99 using FetchBody::BodyLocalPath
;
101 const nsAString
& BodyLocalPath() const { return mRequest
->BodyLocalPath(); }
103 static SafeRefPtr
<Request
> Constructor(const GlobalObject
& aGlobal
,
104 const RequestOrUSVString
& aInput
,
105 const RequestInit
& aInit
,
108 static SafeRefPtr
<Request
> Constructor(nsIGlobalObject
* aGlobal
,
110 const RequestOrUSVString
& aInput
,
111 const RequestInit
& aInit
,
114 nsIGlobalObject
* GetParentObject() const { return mOwner
; }
116 SafeRefPtr
<Request
> Clone(ErrorResult
& aRv
);
118 SafeRefPtr
<InternalRequest
> GetInternalRequest();
120 const UniquePtr
<mozilla::ipc::PrincipalInfo
>& GetPrincipalInfo() const {
121 return mRequest
->GetPrincipalInfo();
124 AbortSignal
* GetOrCreateSignal();
126 // This can return a null AbortSignalImpl.
127 AbortSignalImpl
* GetSignalImpl() const override
;
128 AbortSignalImpl
* GetSignalImplToConsumeBody() const final
;
133 SafeRefPtr
<InternalRequest
> mRequest
;
136 RefPtr
<Headers
> mHeaders
;
137 RefPtr
<AbortSignal
> mSignal
;
140 } // namespace mozilla::dom
142 #endif // mozilla_dom_Request_h