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"
24 class InternalHeaders
;
25 class RequestOrUSVString
;
27 class Request final
: public FetchBody
<Request
>, public nsWrapperCache
{
28 NS_DECL_ISUPPORTS_INHERITED
29 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(Request
,
33 Request(nsIGlobalObject
* aOwner
, SafeRefPtr
<InternalRequest
> aRequest
,
34 AbortSignal
* aSignal
);
36 JSObject
* WrapObject(JSContext
* aCx
,
37 JS::Handle
<JSObject
*> aGivenProto
) override
{
38 return Request_Binding::Wrap(aCx
, this, aGivenProto
);
41 void GetUrl(nsAString
& aUrl
) const {
43 mRequest
->GetURL(url
);
44 CopyUTF8toUTF16(url
, aUrl
);
47 void GetMethod(nsCString
& aMethod
) const { aMethod
= mRequest
->mMethod
; }
49 RequestMode
Mode() const { return mRequest
->mMode
; }
51 RequestCredentials
Credentials() const { return mRequest
->mCredentialsMode
; }
53 RequestCache
Cache() const { return mRequest
->GetCacheMode(); }
55 RequestRedirect
Redirect() const { return mRequest
->GetRedirectMode(); }
57 void GetIntegrity(nsAString
& aIntegrity
) const {
58 aIntegrity
= mRequest
->GetIntegrity();
61 bool MozErrors() const { return mRequest
->MozErrors(); }
63 RequestDestination
Destination() const { return mRequest
->Destination(); }
65 void OverrideContentPolicyType(uint32_t aContentPolicyType
) {
66 mRequest
->OverrideContentPolicyType(
67 static_cast<nsContentPolicyType
>(aContentPolicyType
));
70 bool IsContentPolicyTypeOverridden() const {
71 return mRequest
->IsContentPolicyTypeOverridden();
74 void GetReferrer(nsAString
& aReferrer
) const {
75 mRequest
->GetReferrer(aReferrer
);
78 ReferrerPolicy
ReferrerPolicy_() const { return mRequest
->ReferrerPolicy_(); }
80 InternalHeaders
* GetInternalHeaders() const { return mRequest
->Headers(); }
84 using FetchBody::GetBody
;
86 void GetBody(nsIInputStream
** aStream
, int64_t* aBodyLength
= nullptr) {
87 mRequest
->GetBody(aStream
, aBodyLength
);
90 void SetBody(nsIInputStream
* aStream
, int64_t aBodyLength
) {
91 mRequest
->SetBody(aStream
, aBodyLength
);
94 using FetchBody::BodyBlobURISpec
;
96 const nsACString
& BodyBlobURISpec() const {
97 return mRequest
->BodyBlobURISpec();
100 using FetchBody::BodyLocalPath
;
102 const nsAString
& BodyLocalPath() const { return mRequest
->BodyLocalPath(); }
104 static SafeRefPtr
<Request
> Constructor(const GlobalObject
& aGlobal
,
105 const RequestOrUSVString
& aInput
,
106 const RequestInit
& aInit
,
109 static SafeRefPtr
<Request
> Constructor(nsIGlobalObject
* aGlobal
,
111 const RequestOrUSVString
& aInput
,
112 const RequestInit
& aInit
,
115 nsIGlobalObject
* GetParentObject() const { return mOwner
; }
117 SafeRefPtr
<Request
> Clone(ErrorResult
& aRv
);
119 SafeRefPtr
<InternalRequest
> GetInternalRequest();
121 const UniquePtr
<mozilla::ipc::PrincipalInfo
>& GetPrincipalInfo() const {
122 return mRequest
->GetPrincipalInfo();
125 AbortSignal
* GetOrCreateSignal();
127 // This can return a null AbortSignalImpl.
128 AbortSignalImpl
* GetSignalImpl() const override
;
133 SafeRefPtr
<InternalRequest
> mRequest
;
136 RefPtr
<Headers
> mHeaders
;
137 RefPtr
<AbortSignal
> mSignal
;
141 } // namespace mozilla
143 #endif // mozilla_dom_Request_h