Bumping manifests a=b2g-bump
[gecko.git] / dom / fetch / InternalRequest.h
blob93c20b6cf91922761f1b72d285335fabca6b3a46
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_dom_InternalRequest_h
7 #define mozilla_dom_InternalRequest_h
9 #include "mozilla/dom/HeadersBinding.h"
10 #include "mozilla/dom/InternalHeaders.h"
11 #include "mozilla/dom/RequestBinding.h"
13 #include "nsIContentPolicy.h"
14 #include "nsIInputStream.h"
15 #include "nsISupportsImpl.h"
17 class nsIDocument;
18 class nsPIDOMWindow;
20 namespace mozilla {
21 namespace dom {
23 class FetchBodyStream;
24 class Request;
26 class InternalRequest MOZ_FINAL
28 friend class Request;
30 public:
31 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(InternalRequest)
33 enum ContextFrameType
35 FRAMETYPE_AUXILIARY = 0,
36 FRAMETYPE_TOP_LEVEL,
37 FRAMETYPE_NESTED,
38 FRAMETYPE_NONE,
41 // Since referrer type can be none, client or a URL.
42 enum ReferrerType
44 REFERRER_NONE = 0,
45 REFERRER_CLIENT,
46 REFERRER_URL,
49 enum ResponseTainting
51 RESPONSETAINT_BASIC,
52 RESPONSETAINT_CORS,
53 RESPONSETAINT_OPAQUE,
56 explicit InternalRequest()
57 : mMethod("GET")
58 , mHeaders(new InternalHeaders(HeadersGuardEnum::None))
59 , mContextFrameType(FRAMETYPE_NONE)
60 , mReferrerType(REFERRER_CLIENT)
61 , mMode(RequestMode::No_cors)
62 , mCredentialsMode(RequestCredentials::Omit)
63 , mResponseTainting(RESPONSETAINT_BASIC)
64 , mRedirectCount(0)
65 , mAuthenticationFlag(false)
66 , mForceOriginHeader(false)
67 , mManualRedirect(false)
68 , mPreserveContentCodings(false)
69 // FIXME(nsm): This should be false by default, but will lead to the
70 // algorithm never loading data: URLs right now. See Bug 1018872 about
71 // how certain contexts will override it to set it to true. Fetch
72 // specification does not handle this yet.
73 , mSameOriginDataURL(true)
74 , mSkipServiceWorker(false)
75 , mSynchronous(false)
76 , mUnsafeRequest(false)
77 , mUseURLCredentials(false)
81 explicit InternalRequest(const InternalRequest& aOther)
82 : mMethod(aOther.mMethod)
83 , mURL(aOther.mURL)
84 , mHeaders(aOther.mHeaders)
85 , mBodyStream(aOther.mBodyStream)
86 , mContext(aOther.mContext)
87 , mOrigin(aOther.mOrigin)
88 , mContextFrameType(aOther.mContextFrameType)
89 , mReferrerType(aOther.mReferrerType)
90 , mReferrerURL(aOther.mReferrerURL)
91 , mMode(aOther.mMode)
92 , mCredentialsMode(aOther.mCredentialsMode)
93 , mResponseTainting(aOther.mResponseTainting)
94 , mRedirectCount(aOther.mRedirectCount)
95 , mAuthenticationFlag(aOther.mAuthenticationFlag)
96 , mForceOriginHeader(aOther.mForceOriginHeader)
97 , mManualRedirect(aOther.mManualRedirect)
98 , mPreserveContentCodings(aOther.mPreserveContentCodings)
99 , mSameOriginDataURL(aOther.mSameOriginDataURL)
100 , mSandboxedStorageAreaURLs(aOther.mSandboxedStorageAreaURLs)
101 , mSkipServiceWorker(aOther.mSkipServiceWorker)
102 , mSynchronous(aOther.mSynchronous)
103 , mUnsafeRequest(aOther.mUnsafeRequest)
104 , mUseURLCredentials(aOther.mUseURLCredentials)
108 void
109 GetMethod(nsCString& aMethod) const
111 aMethod.Assign(mMethod);
114 void
115 SetMethod(const nsACString& aMethod)
117 mMethod.Assign(aMethod);
120 bool
121 HasSimpleMethod() const
123 return mMethod.LowerCaseEqualsASCII("get") ||
124 mMethod.LowerCaseEqualsASCII("post") ||
125 mMethod.LowerCaseEqualsASCII("head");
128 void
129 GetURL(nsCString& aURL) const
131 aURL.Assign(mURL);
134 bool
135 ReferrerIsNone() const
137 return mReferrerType == REFERRER_NONE;
140 bool
141 ReferrerIsURL() const
143 return mReferrerType == REFERRER_URL;
146 bool
147 ReferrerIsClient() const
149 return mReferrerType == REFERRER_CLIENT;
152 nsCString
153 ReferrerAsURL() const
155 MOZ_ASSERT(ReferrerIsURL());
156 return mReferrerURL;
159 void
160 SetReferrer(const nsACString& aReferrer)
162 // May be removed later.
163 MOZ_ASSERT(!ReferrerIsNone());
164 mReferrerType = REFERRER_URL;
165 mReferrerURL.Assign(aReferrer);
168 bool
169 IsSynchronous() const
171 return mSynchronous;
174 RequestMode
175 Mode() const
177 return mMode;
180 void
181 SetMode(RequestMode aMode)
183 mMode = aMode;
186 void
187 SetCredentialsMode(RequestCredentials aCredentialsMode)
189 mCredentialsMode = aCredentialsMode;
192 ResponseTainting
193 GetResponseTainting() const
195 return mResponseTainting;
198 void
199 SetResponseTainting(ResponseTainting aTainting)
201 mResponseTainting = aTainting;
204 nsContentPolicyType
205 GetContext() const
207 return mContext;
210 bool
211 UnsafeRequest() const
213 return mUnsafeRequest;
216 InternalHeaders*
217 Headers()
219 return mHeaders;
222 bool
223 ForceOriginHeader()
225 return mForceOriginHeader;
228 void
229 GetOrigin(nsCString& aOrigin) const
231 aOrigin.Assign(mOrigin);
234 bool
235 SameOriginDataURL() const
237 return mSameOriginDataURL;
240 void
241 SetBody(nsIInputStream* aStream)
243 mBodyStream = aStream;
246 // Will return the original stream!
247 // Use a tee or copy if you don't want to erase the original.
248 void
249 GetBody(nsIInputStream** aStream)
251 nsCOMPtr<nsIInputStream> s = mBodyStream;
252 s.forget(aStream);
255 // The global is used as the client for the new object.
256 already_AddRefed<InternalRequest>
257 GetRequestConstructorCopy(nsIGlobalObject* aGlobal, ErrorResult& aRv) const;
259 private:
260 ~InternalRequest();
262 void
263 SetURL(const nsACString& aURL)
265 mURL.Assign(aURL);
268 nsCString mMethod;
269 nsCString mURL;
270 nsRefPtr<InternalHeaders> mHeaders;
271 nsCOMPtr<nsIInputStream> mBodyStream;
273 // nsContentPolicyType does not cover the complete set defined in the spec,
274 // but it is a good start.
275 nsContentPolicyType mContext;
277 nsCString mOrigin;
279 ContextFrameType mContextFrameType;
280 ReferrerType mReferrerType;
282 // When mReferrerType is REFERRER_URL.
283 nsCString mReferrerURL;
285 RequestMode mMode;
286 RequestCredentials mCredentialsMode;
287 ResponseTainting mResponseTainting;
289 uint32_t mRedirectCount;
291 bool mAuthenticationFlag;
292 bool mForceOriginHeader;
293 bool mManualRedirect;
294 bool mPreserveContentCodings;
295 bool mSameOriginDataURL;
296 bool mSandboxedStorageAreaURLs;
297 bool mSkipServiceWorker;
298 bool mSynchronous;
299 bool mUnsafeRequest;
300 bool mUseURLCredentials;
303 } // namespace dom
304 } // namespace mozilla
306 #endif // mozilla_dom_InternalRequest_h