/src/mozilla-central/dom/fetch/Response.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_Response_h |
8 | | #define mozilla_dom_Response_h |
9 | | |
10 | | #include "nsWrapperCache.h" |
11 | | #include "nsISupportsImpl.h" |
12 | | |
13 | | #include "mozilla/dom/Fetch.h" |
14 | | #include "mozilla/dom/ResponseBinding.h" |
15 | | |
16 | | #include "InternalHeaders.h" |
17 | | #include "InternalResponse.h" |
18 | | |
19 | | namespace mozilla { |
20 | | namespace ipc { |
21 | | class PrincipalInfo; |
22 | | } // namespace ipc |
23 | | |
24 | | namespace dom { |
25 | | |
26 | | class Headers; |
27 | | |
28 | | class Response final : public nsISupports |
29 | | , public FetchBody<Response> |
30 | | , public nsWrapperCache |
31 | | { |
32 | | NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
33 | | NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Response) |
34 | | |
35 | | public: |
36 | | Response(nsIGlobalObject* aGlobal, InternalResponse* aInternalResponse, |
37 | | AbortSignalImpl* aSignalImpl); |
38 | | |
39 | | Response(const Response& aOther) = delete; |
40 | | |
41 | | JSObject* |
42 | | WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override |
43 | | { |
44 | | return Response_Binding::Wrap(aCx, this, aGivenProto); |
45 | | } |
46 | | |
47 | | ResponseType |
48 | | Type() const |
49 | | { |
50 | | return mInternalResponse->Type(); |
51 | | } |
52 | | void |
53 | | GetUrl(nsAString& aUrl) const |
54 | | { |
55 | | CopyUTF8toUTF16(mInternalResponse->GetURL(), aUrl); |
56 | | } |
57 | | bool |
58 | | Redirected() const |
59 | | { |
60 | | return mInternalResponse->IsRedirected(); |
61 | | } |
62 | | uint16_t |
63 | | Status() const |
64 | | { |
65 | | return mInternalResponse->GetStatus(); |
66 | | } |
67 | | |
68 | | bool |
69 | | Ok() const |
70 | | { |
71 | | return mInternalResponse->GetStatus() >= 200 && |
72 | | mInternalResponse->GetStatus() <= 299; |
73 | | } |
74 | | |
75 | | void |
76 | | GetStatusText(nsCString& aStatusText) const |
77 | | { |
78 | | aStatusText = mInternalResponse->GetStatusText(); |
79 | | } |
80 | | |
81 | | InternalHeaders* |
82 | | GetInternalHeaders() const |
83 | 0 | { |
84 | 0 | return mInternalResponse->Headers(); |
85 | 0 | } |
86 | | |
87 | | void |
88 | | InitChannelInfo(nsIChannel* aChannel) |
89 | | { |
90 | | mInternalResponse->InitChannelInfo(aChannel); |
91 | | } |
92 | | |
93 | | const ChannelInfo& |
94 | | GetChannelInfo() const |
95 | | { |
96 | | return mInternalResponse->GetChannelInfo(); |
97 | | } |
98 | | |
99 | | const UniquePtr<mozilla::ipc::PrincipalInfo>& |
100 | | GetPrincipalInfo() const |
101 | 0 | { |
102 | 0 | return mInternalResponse->GetPrincipalInfo(); |
103 | 0 | } |
104 | | |
105 | | Headers* Headers_(); |
106 | | |
107 | | void |
108 | | GetBody(nsIInputStream** aStream, int64_t* aBodyLength = nullptr) |
109 | 0 | { |
110 | 0 | mInternalResponse->GetBody(aStream, aBodyLength); |
111 | 0 | } |
112 | | |
113 | | using FetchBody::GetBody; |
114 | | |
115 | | using FetchBody::BodyLocalPath; |
116 | | |
117 | | const nsAString& |
118 | | BodyLocalPath() const |
119 | 0 | { |
120 | 0 | return mInternalResponse->BodyLocalPath(); |
121 | 0 | } |
122 | | |
123 | | static already_AddRefed<Response> |
124 | | Error(const GlobalObject& aGlobal); |
125 | | |
126 | | static already_AddRefed<Response> |
127 | | Redirect(const GlobalObject& aGlobal, const nsAString& aUrl, uint16_t aStatus, ErrorResult& aRv); |
128 | | |
129 | | static already_AddRefed<Response> |
130 | | Constructor(const GlobalObject& aGlobal, |
131 | | const Optional<Nullable<fetch::ResponseBodyInit>>& aBody, |
132 | | const ResponseInit& aInit, ErrorResult& rv); |
133 | | |
134 | | nsIGlobalObject* GetParentObject() const |
135 | | { |
136 | | return mOwner; |
137 | | } |
138 | | |
139 | | already_AddRefed<Response> |
140 | | Clone(JSContext* aCx, ErrorResult& aRv); |
141 | | |
142 | | already_AddRefed<Response> |
143 | | CloneUnfiltered(JSContext* aCx, ErrorResult& aRv); |
144 | | |
145 | | void |
146 | | SetBody(nsIInputStream* aBody, int64_t aBodySize); |
147 | | |
148 | | already_AddRefed<InternalResponse> |
149 | | GetInternalResponse() const; |
150 | | |
151 | | AbortSignalImpl* |
152 | | GetSignalImpl() const override |
153 | 0 | { |
154 | 0 | return mSignalImpl; |
155 | 0 | } |
156 | | |
157 | | private: |
158 | | ~Response(); |
159 | | |
160 | | RefPtr<InternalResponse> mInternalResponse; |
161 | | // Lazily created |
162 | | RefPtr<Headers> mHeaders; |
163 | | RefPtr<AbortSignalImpl> mSignalImpl; |
164 | | }; |
165 | | |
166 | | } // namespace dom |
167 | | } // namespace mozilla |
168 | | |
169 | | #endif // mozilla_dom_Response_h |