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"
23 class FetchBodyStream
;
26 class InternalRequest MOZ_FINAL
31 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(InternalRequest
)
35 FRAMETYPE_AUXILIARY
= 0,
41 // Since referrer type can be none, client or a URL.
56 explicit InternalRequest()
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
)
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)
76 , mUnsafeRequest(false)
77 , mUseURLCredentials(false)
81 explicit InternalRequest(const InternalRequest
& aOther
)
82 : mMethod(aOther
.mMethod
)
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
)
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
)
109 GetMethod(nsCString
& aMethod
) const
111 aMethod
.Assign(mMethod
);
115 SetMethod(const nsACString
& aMethod
)
117 mMethod
.Assign(aMethod
);
121 HasSimpleMethod() const
123 return mMethod
.LowerCaseEqualsASCII("get") ||
124 mMethod
.LowerCaseEqualsASCII("post") ||
125 mMethod
.LowerCaseEqualsASCII("head");
129 GetURL(nsCString
& aURL
) const
135 ReferrerIsNone() const
137 return mReferrerType
== REFERRER_NONE
;
141 ReferrerIsURL() const
143 return mReferrerType
== REFERRER_URL
;
147 ReferrerIsClient() const
149 return mReferrerType
== REFERRER_CLIENT
;
153 ReferrerAsURL() const
155 MOZ_ASSERT(ReferrerIsURL());
160 SetReferrer(const nsACString
& aReferrer
)
162 // May be removed later.
163 MOZ_ASSERT(!ReferrerIsNone());
164 mReferrerType
= REFERRER_URL
;
165 mReferrerURL
.Assign(aReferrer
);
169 IsSynchronous() const
181 SetMode(RequestMode aMode
)
187 SetCredentialsMode(RequestCredentials aCredentialsMode
)
189 mCredentialsMode
= aCredentialsMode
;
193 GetResponseTainting() const
195 return mResponseTainting
;
199 SetResponseTainting(ResponseTainting aTainting
)
201 mResponseTainting
= aTainting
;
211 UnsafeRequest() const
213 return mUnsafeRequest
;
225 return mForceOriginHeader
;
229 GetOrigin(nsCString
& aOrigin
) const
231 aOrigin
.Assign(mOrigin
);
235 SameOriginDataURL() const
237 return mSameOriginDataURL
;
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.
249 GetBody(nsIInputStream
** aStream
)
251 nsCOMPtr
<nsIInputStream
> s
= mBodyStream
;
255 // The global is used as the client for the new object.
256 already_AddRefed
<InternalRequest
>
257 GetRequestConstructorCopy(nsIGlobalObject
* aGlobal
, ErrorResult
& aRv
) const;
263 SetURL(const nsACString
& aURL
)
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
;
279 ContextFrameType mContextFrameType
;
280 ReferrerType mReferrerType
;
282 // When mReferrerType is REFERRER_URL.
283 nsCString mReferrerURL
;
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
;
300 bool mUseURLCredentials
;
304 } // namespace mozilla
306 #endif // mozilla_dom_InternalRequest_h