Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/dom/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
0
  {
44
0
    return Response_Binding::Wrap(aCx, this, aGivenProto);
45
0
  }
46
47
  ResponseType
48
  Type() const
49
0
  {
50
0
    return mInternalResponse->Type();
51
0
  }
52
  void
53
  GetUrl(nsAString& aUrl) const
54
0
  {
55
0
    CopyUTF8toUTF16(mInternalResponse->GetURL(), aUrl);
56
0
  }
57
  bool
58
  Redirected() const
59
0
  {
60
0
    return mInternalResponse->IsRedirected();
61
0
  }
62
  uint16_t
63
  Status() const
64
0
  {
65
0
    return mInternalResponse->GetStatus();
66
0
  }
67
68
  bool
69
  Ok() const
70
0
  {
71
0
    return mInternalResponse->GetStatus() >= 200 &&
72
0
           mInternalResponse->GetStatus() <= 299;
73
0
  }
74
75
  void
76
  GetStatusText(nsCString& aStatusText) const
77
0
  {
78
0
    aStatusText = mInternalResponse->GetStatusText();
79
0
  }
80
81
  InternalHeaders*
82
  GetInternalHeaders() const
83
  {
84
    return mInternalResponse->Headers();
85
  }
86
87
  void
88
  InitChannelInfo(nsIChannel* aChannel)
89
0
  {
90
0
    mInternalResponse->InitChannelInfo(aChannel);
91
0
  }
92
93
  const ChannelInfo&
94
  GetChannelInfo() const
95
0
  {
96
0
    return mInternalResponse->GetChannelInfo();
97
0
  }
98
99
  const UniquePtr<mozilla::ipc::PrincipalInfo>&
100
  GetPrincipalInfo() const
101
  {
102
    return mInternalResponse->GetPrincipalInfo();
103
  }
104
105
  Headers* Headers_();
106
107
  void
108
  GetBody(nsIInputStream** aStream, int64_t* aBodyLength = nullptr)
109
  {
110
    mInternalResponse->GetBody(aStream, aBodyLength);
111
  }
112
113
  using FetchBody::GetBody;
114
115
  using FetchBody::BodyLocalPath;
116
117
  const nsAString&
118
  BodyLocalPath() const
119
  {
120
    return mInternalResponse->BodyLocalPath();
121
  }
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
0
  {
136
0
    return mOwner;
137
0
  }
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
  {
154
    return mSignalImpl;
155
  }
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