/src/mozilla-central/dom/fetch/Request.h
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #ifndef mozilla_dom_Request_h |
8 | | #define mozilla_dom_Request_h |
9 | | |
10 | | #include "nsIContentPolicy.h" |
11 | | #include "nsISupportsImpl.h" |
12 | | #include "nsWrapperCache.h" |
13 | | |
14 | | #include "mozilla/dom/Fetch.h" |
15 | | #include "mozilla/dom/InternalRequest.h" |
16 | | // Required here due to certain WebIDL enums/classes being declared in both |
17 | | // files. |
18 | | #include "mozilla/dom/RequestBinding.h" |
19 | | |
20 | | namespace mozilla { |
21 | | namespace dom { |
22 | | |
23 | | class Headers; |
24 | | class InternalHeaders; |
25 | | class RequestOrUSVString; |
26 | | |
27 | | class Request final : public nsISupports |
28 | | , public FetchBody<Request> |
29 | | , public nsWrapperCache |
30 | | { |
31 | | NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
32 | | NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Request) |
33 | | |
34 | | public: |
35 | | Request(nsIGlobalObject* aOwner, InternalRequest* aRequest, |
36 | | AbortSignal* aSignal); |
37 | | |
38 | | JSObject* |
39 | | WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override |
40 | | { |
41 | | return Request_Binding::Wrap(aCx, this, aGivenProto); |
42 | | } |
43 | | |
44 | | void |
45 | | GetUrl(nsAString& aUrl) const |
46 | | { |
47 | | nsAutoCString url; |
48 | | mRequest->GetURL(url); |
49 | | CopyUTF8toUTF16(url, aUrl); |
50 | | } |
51 | | |
52 | | void |
53 | | GetMethod(nsCString& aMethod) const |
54 | | { |
55 | | aMethod = mRequest->mMethod; |
56 | | } |
57 | | |
58 | | RequestMode |
59 | | Mode() const |
60 | | { |
61 | | return mRequest->mMode; |
62 | | } |
63 | | |
64 | | RequestCredentials |
65 | | Credentials() const |
66 | | { |
67 | | return mRequest->mCredentialsMode; |
68 | | } |
69 | | |
70 | | RequestCache |
71 | | Cache() const |
72 | | { |
73 | | return mRequest->GetCacheMode(); |
74 | | } |
75 | | |
76 | | RequestRedirect |
77 | | Redirect() const |
78 | | { |
79 | | return mRequest->GetRedirectMode(); |
80 | | } |
81 | | |
82 | | void |
83 | | GetIntegrity(nsAString& aIntegrity) const |
84 | | { |
85 | | aIntegrity = mRequest->GetIntegrity(); |
86 | | } |
87 | | |
88 | | bool |
89 | | MozErrors() const |
90 | | { |
91 | | return mRequest->MozErrors(); |
92 | | } |
93 | | |
94 | | RequestDestination |
95 | | Destination() const |
96 | | { |
97 | | return mRequest->Destination(); |
98 | | } |
99 | | |
100 | | void |
101 | | OverrideContentPolicyType(nsContentPolicyType aContentPolicyType) |
102 | | { |
103 | | mRequest->OverrideContentPolicyType(aContentPolicyType); |
104 | | } |
105 | | |
106 | | bool |
107 | | IsContentPolicyTypeOverridden() const |
108 | | { |
109 | | return mRequest->IsContentPolicyTypeOverridden(); |
110 | | } |
111 | | |
112 | | void |
113 | | GetReferrer(nsAString& aReferrer) const |
114 | | { |
115 | | mRequest->GetReferrer(aReferrer); |
116 | | } |
117 | | |
118 | | ReferrerPolicy |
119 | | ReferrerPolicy_() const |
120 | | { |
121 | | return mRequest->ReferrerPolicy_(); |
122 | | } |
123 | | |
124 | | InternalHeaders* |
125 | | GetInternalHeaders() const |
126 | 0 | { |
127 | 0 | return mRequest->Headers(); |
128 | 0 | } |
129 | | |
130 | | Headers* Headers_(); |
131 | | |
132 | | using FetchBody::GetBody; |
133 | | |
134 | | void |
135 | | GetBody(nsIInputStream** aStream, int64_t* aBodyLength = nullptr) |
136 | | { |
137 | | mRequest->GetBody(aStream, aBodyLength); |
138 | | } |
139 | | |
140 | | void |
141 | | SetBody(nsIInputStream* aStream, int64_t aBodyLength) |
142 | 0 | { |
143 | 0 | mRequest->SetBody(aStream, aBodyLength); |
144 | 0 | } |
145 | | |
146 | | using FetchBody::BodyLocalPath; |
147 | | |
148 | | const nsAString& |
149 | | BodyLocalPath() const |
150 | 0 | { |
151 | 0 | return mRequest->BodyLocalPath(); |
152 | 0 | } |
153 | | |
154 | | static already_AddRefed<Request> |
155 | | Constructor(const GlobalObject& aGlobal, const RequestOrUSVString& aInput, |
156 | | const RequestInit& aInit, ErrorResult& rv); |
157 | | |
158 | | nsIGlobalObject* GetParentObject() const |
159 | | { |
160 | | return mOwner; |
161 | | } |
162 | | |
163 | | already_AddRefed<Request> |
164 | | Clone(ErrorResult& aRv); |
165 | | |
166 | | already_AddRefed<InternalRequest> |
167 | | GetInternalRequest(); |
168 | | |
169 | | const UniquePtr<mozilla::ipc::PrincipalInfo>& |
170 | | GetPrincipalInfo() const |
171 | 0 | { |
172 | 0 | return mRequest->GetPrincipalInfo(); |
173 | 0 | } |
174 | | |
175 | | AbortSignal* |
176 | | GetOrCreateSignal(); |
177 | | |
178 | | // This can return a null AbortSignalImpl. |
179 | | AbortSignalImpl* |
180 | | GetSignalImpl() const override; |
181 | | |
182 | | private: |
183 | | ~Request(); |
184 | | |
185 | | RefPtr<InternalRequest> mRequest; |
186 | | |
187 | | // Lazily created. |
188 | | RefPtr<Headers> mHeaders; |
189 | | RefPtr<AbortSignal> mSignal; |
190 | | }; |
191 | | |
192 | | } // namespace dom |
193 | | } // namespace mozilla |
194 | | |
195 | | #endif // mozilla_dom_Request_h |