| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2003, 2006 Apple Computer, Inc. All rights reserved. | |
| 3 * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> | |
| 4 * Copyright (C) 2009, 2012 Google Inc. All rights reserved. | |
| 5 * | |
| 6 * Redistribution and use in source and binary forms, with or without | |
| 7 * modification, are permitted provided that the following conditions | |
| 8 * are met: | |
| 9 * 1. Redistributions of source code must retain the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer. | |
| 11 * 2. Redistributions in binary form must reproduce the above copyright | |
| 12 * notice, this list of conditions and the following disclaimer in the | |
| 13 * documentation and/or other materials provided with the distribution. | |
| 14 * | |
| 15 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | |
| 16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| 18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
| 19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
| 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
| 22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
| 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 26 */ | |
| 27 | |
| 28 #ifndef ResourceRequest_h | |
| 29 #define ResourceRequest_h | |
| 30 | |
| 31 #include "platform/HTTPNames.h" | |
| 32 #include "platform/network/EncodedFormData.h" | |
| 33 #include "platform/network/HTTPHeaderMap.h" | |
| 34 #include "platform/network/HTTPParsers.h" | |
| 35 #include "platform/network/ResourceLoadPriority.h" | |
| 36 #include "platform/weborigin/KURL.h" | |
| 37 #include "platform/weborigin/Referrer.h" | |
| 38 #include "platform/weborigin/SecurityOrigin.h" | |
| 39 #include "public/platform/WebAddressSpace.h" | |
| 40 #include "public/platform/WebURLRequest.h" | |
| 41 #include "wtf/RefCounted.h" | |
| 42 #include <memory> | |
| 43 | |
| 44 namespace blink { | |
| 45 | |
| 46 enum class WebCachePolicy; | |
| 47 | |
| 48 enum class ResourceRequestBlockedReason { | |
| 49 CSP, | |
| 50 MixedContent, | |
| 51 Origin, | |
| 52 Inspector, | |
| 53 SubresourceFilter, | |
| 54 Other, | |
| 55 None | |
| 56 }; | |
| 57 | |
| 58 enum InputToLoadPerfMetricReportPolicy { | |
| 59 NoReport, // Don't report metrics for this ResourceRequest. | |
| 60 ReportLink, // Report metrics for this request as initiated by a link click. | |
| 61 ReportIntent, // Report metrics for this request as initiated by an intent. | |
| 62 }; | |
| 63 | |
| 64 struct CrossThreadResourceRequestData; | |
| 65 | |
| 66 class PLATFORM_EXPORT ResourceRequest final { | |
| 67 DISALLOW_NEW(); | |
| 68 | |
| 69 public: | |
| 70 enum class RedirectStatus { FollowedRedirect, NoRedirect }; | |
| 71 | |
| 72 class ExtraData : public RefCounted<ExtraData> { | |
| 73 public: | |
| 74 virtual ~ExtraData() {} | |
| 75 }; | |
| 76 | |
| 77 ResourceRequest(); | |
| 78 ResourceRequest(const String& urlString); | |
| 79 ResourceRequest(const KURL&); | |
| 80 explicit ResourceRequest(CrossThreadResourceRequestData*); | |
| 81 ResourceRequest(const ResourceRequest&); | |
| 82 ResourceRequest& operator=(const ResourceRequest&); | |
| 83 | |
| 84 // Gets a copy of the data suitable for passing to another thread. | |
| 85 std::unique_ptr<CrossThreadResourceRequestData> copyData() const; | |
| 86 | |
| 87 bool isNull() const; | |
| 88 bool isEmpty() const; | |
| 89 | |
| 90 const KURL& url() const; | |
| 91 void setURL(const KURL& url); | |
| 92 | |
| 93 void removeUserAndPassFromURL(); | |
| 94 | |
| 95 WebCachePolicy getCachePolicy() const; | |
| 96 void setCachePolicy(WebCachePolicy); | |
| 97 | |
| 98 double timeoutInterval() const; // May return 0 when using platform default. | |
| 99 void setTimeoutInterval(double); | |
| 100 | |
| 101 const KURL& firstPartyForCookies() const; | |
| 102 void setFirstPartyForCookies(const KURL& firstPartyForCookies); | |
| 103 | |
| 104 PassRefPtr<SecurityOrigin> requestorOrigin() const; | |
| 105 void setRequestorOrigin(PassRefPtr<SecurityOrigin>); | |
| 106 | |
| 107 const AtomicString& httpMethod() const; | |
| 108 void setHTTPMethod(const AtomicString&); | |
| 109 | |
| 110 const HTTPHeaderMap& httpHeaderFields() const; | |
| 111 const AtomicString& httpHeaderField(const AtomicString& name) const; | |
| 112 void setHTTPHeaderField(const AtomicString& name, const AtomicString& value); | |
| 113 void addHTTPHeaderField(const AtomicString& name, const AtomicString& value); | |
| 114 void addHTTPHeaderFields(const HTTPHeaderMap& headerFields); | |
| 115 void clearHTTPHeaderField(const AtomicString& name); | |
| 116 | |
| 117 const AtomicString& httpContentType() const { | |
| 118 return httpHeaderField(HTTPNames::Content_Type); | |
| 119 } | |
| 120 void setHTTPContentType(const AtomicString& httpContentType) { | |
| 121 setHTTPHeaderField(HTTPNames::Content_Type, httpContentType); | |
| 122 } | |
| 123 | |
| 124 bool didSetHTTPReferrer() const { return m_didSetHTTPReferrer; } | |
| 125 const AtomicString& httpReferrer() const { | |
| 126 return httpHeaderField(HTTPNames::Referer); | |
| 127 } | |
| 128 ReferrerPolicy getReferrerPolicy() const { return m_referrerPolicy; } | |
| 129 void setHTTPReferrer(const Referrer&); | |
| 130 void clearHTTPReferrer(); | |
| 131 | |
| 132 const AtomicString& httpOrigin() const { | |
| 133 return httpHeaderField(HTTPNames::Origin); | |
| 134 } | |
| 135 const AtomicString& httpSuborigin() const { | |
| 136 return httpHeaderField(HTTPNames::Suborigin); | |
| 137 } | |
| 138 // Note that these will also set and clear, respectively, the | |
| 139 // Suborigin header, if appropriate. | |
| 140 void setHTTPOrigin(const SecurityOrigin*); | |
| 141 void clearHTTPOrigin(); | |
| 142 | |
| 143 void addHTTPOriginIfNeeded(const SecurityOrigin*); | |
| 144 void addHTTPOriginIfNeeded(const String&); | |
| 145 | |
| 146 const AtomicString& httpUserAgent() const { | |
| 147 return httpHeaderField(HTTPNames::User_Agent); | |
| 148 } | |
| 149 void setHTTPUserAgent(const AtomicString& httpUserAgent) { | |
| 150 setHTTPHeaderField(HTTPNames::User_Agent, httpUserAgent); | |
| 151 } | |
| 152 void clearHTTPUserAgent(); | |
| 153 | |
| 154 void setHTTPAccept(const AtomicString& httpAccept) { | |
| 155 setHTTPHeaderField(HTTPNames::Accept, httpAccept); | |
| 156 } | |
| 157 | |
| 158 EncodedFormData* httpBody() const; | |
| 159 void setHTTPBody(PassRefPtr<EncodedFormData>); | |
| 160 | |
| 161 EncodedFormData* attachedCredential() const; | |
| 162 void setAttachedCredential(PassRefPtr<EncodedFormData>); | |
| 163 | |
| 164 bool allowStoredCredentials() const; | |
| 165 void setAllowStoredCredentials(bool allowCredentials); | |
| 166 | |
| 167 ResourceLoadPriority priority() const; | |
| 168 void setPriority(ResourceLoadPriority, int intraPriorityValue = 0); | |
| 169 | |
| 170 bool isConditional() const; | |
| 171 | |
| 172 // Whether the associated ResourceHandleClient needs to be notified of | |
| 173 // upload progress made for that resource. | |
| 174 bool reportUploadProgress() const { return m_reportUploadProgress; } | |
| 175 void setReportUploadProgress(bool reportUploadProgress) { | |
| 176 m_reportUploadProgress = reportUploadProgress; | |
| 177 } | |
| 178 | |
| 179 // Whether actual headers being sent/received should be collected and reported | |
| 180 // for the request. | |
| 181 bool reportRawHeaders() const { return m_reportRawHeaders; } | |
| 182 void setReportRawHeaders(bool reportRawHeaders) { | |
| 183 m_reportRawHeaders = reportRawHeaders; | |
| 184 } | |
| 185 | |
| 186 // Allows the request to be matched up with its requestor. | |
| 187 int requestorID() const { return m_requestorID; } | |
| 188 void setRequestorID(int requestorID) { m_requestorID = requestorID; } | |
| 189 | |
| 190 // The process id of the process from which this request originated. In | |
| 191 // the case of out-of-process plugins, this allows to link back the | |
| 192 // request to the plugin process (as it is processed through a render | |
| 193 // view process). | |
| 194 int requestorProcessID() const { return m_requestorProcessID; } | |
| 195 void setRequestorProcessID(int requestorProcessID) { | |
| 196 m_requestorProcessID = requestorProcessID; | |
| 197 } | |
| 198 | |
| 199 // Allows the request to be matched up with its app cache host. | |
| 200 int appCacheHostID() const { return m_appCacheHostID; } | |
| 201 void setAppCacheHostID(int id) { m_appCacheHostID = id; } | |
| 202 | |
| 203 // True if request was user initiated. | |
| 204 bool hasUserGesture() const { return m_hasUserGesture; } | |
| 205 void setHasUserGesture(bool); | |
| 206 | |
| 207 // True if request should be downloaded to file. | |
| 208 bool downloadToFile() const { return m_downloadToFile; } | |
| 209 void setDownloadToFile(bool downloadToFile) { | |
| 210 m_downloadToFile = downloadToFile; | |
| 211 } | |
| 212 | |
| 213 // True if the requestor wants to receive a response body as | |
| 214 // WebDataConsumerHandle. | |
| 215 bool useStreamOnResponse() const { return m_useStreamOnResponse; } | |
| 216 void setUseStreamOnResponse(bool useStreamOnResponse) { | |
| 217 m_useStreamOnResponse = useStreamOnResponse; | |
| 218 } | |
| 219 | |
| 220 // The service worker mode indicating which service workers should get events | |
| 221 // for this request. | |
| 222 WebURLRequest::ServiceWorkerMode getServiceWorkerMode() const { | |
| 223 return m_serviceWorkerMode; | |
| 224 } | |
| 225 void setServiceWorkerMode( | |
| 226 WebURLRequest::ServiceWorkerMode serviceWorkerMode) { | |
| 227 m_serviceWorkerMode = serviceWorkerMode; | |
| 228 } | |
| 229 | |
| 230 // True if corresponding AppCache group should be resetted. | |
| 231 bool shouldResetAppCache() { return m_shouldResetAppCache; } | |
| 232 void setShouldResetAppCache(bool shouldResetAppCache) { | |
| 233 m_shouldResetAppCache = shouldResetAppCache; | |
| 234 } | |
| 235 | |
| 236 // Extra data associated with this request. | |
| 237 ExtraData* getExtraData() const { return m_extraData.get(); } | |
| 238 void setExtraData(PassRefPtr<ExtraData> extraData) { | |
| 239 m_extraData = extraData; | |
| 240 } | |
| 241 | |
| 242 WebURLRequest::RequestContext requestContext() const { | |
| 243 return m_requestContext; | |
| 244 } | |
| 245 void setRequestContext(WebURLRequest::RequestContext context) { | |
| 246 m_requestContext = context; | |
| 247 } | |
| 248 | |
| 249 WebURLRequest::FrameType frameType() const { return m_frameType; } | |
| 250 void setFrameType(WebURLRequest::FrameType frameType) { | |
| 251 m_frameType = frameType; | |
| 252 } | |
| 253 | |
| 254 WebURLRequest::FetchRequestMode fetchRequestMode() const { | |
| 255 return m_fetchRequestMode; | |
| 256 } | |
| 257 void setFetchRequestMode(WebURLRequest::FetchRequestMode mode) { | |
| 258 m_fetchRequestMode = mode; | |
| 259 } | |
| 260 | |
| 261 WebURLRequest::FetchCredentialsMode fetchCredentialsMode() const { | |
| 262 return m_fetchCredentialsMode; | |
| 263 } | |
| 264 void setFetchCredentialsMode(WebURLRequest::FetchCredentialsMode mode) { | |
| 265 m_fetchCredentialsMode = mode; | |
| 266 } | |
| 267 | |
| 268 WebURLRequest::FetchRedirectMode fetchRedirectMode() const { | |
| 269 return m_fetchRedirectMode; | |
| 270 } | |
| 271 void setFetchRedirectMode(WebURLRequest::FetchRedirectMode redirect) { | |
| 272 m_fetchRedirectMode = redirect; | |
| 273 } | |
| 274 | |
| 275 WebURLRequest::PreviewsState previewsState() const { return m_previewsState; } | |
| 276 void setPreviewsState(WebURLRequest::PreviewsState previewsState) { | |
| 277 m_previewsState = previewsState; | |
| 278 } | |
| 279 | |
| 280 bool cacheControlContainsNoCache() const; | |
| 281 bool cacheControlContainsNoStore() const; | |
| 282 bool hasCacheValidatorFields() const; | |
| 283 | |
| 284 bool checkForBrowserSideNavigation() const { | |
| 285 return m_checkForBrowserSideNavigation; | |
| 286 } | |
| 287 void setCheckForBrowserSideNavigation(bool check) { | |
| 288 m_checkForBrowserSideNavigation = check; | |
| 289 } | |
| 290 | |
| 291 double uiStartTime() const { return m_uiStartTime; } | |
| 292 void setUIStartTime(double uiStartTimeSeconds) { | |
| 293 m_uiStartTime = uiStartTimeSeconds; | |
| 294 } | |
| 295 | |
| 296 // https://mikewest.github.io/cors-rfc1918/#external-request | |
| 297 bool isExternalRequest() const { return m_isExternalRequest; } | |
| 298 void setExternalRequestStateFromRequestorAddressSpace(WebAddressSpace); | |
| 299 | |
| 300 InputToLoadPerfMetricReportPolicy inputPerfMetricReportPolicy() const { | |
| 301 return m_inputPerfMetricReportPolicy; | |
| 302 } | |
| 303 void setInputPerfMetricReportPolicy( | |
| 304 InputToLoadPerfMetricReportPolicy inputPerfMetricReportPolicy) { | |
| 305 m_inputPerfMetricReportPolicy = inputPerfMetricReportPolicy; | |
| 306 } | |
| 307 | |
| 308 void setRedirectStatus(RedirectStatus status) { m_redirectStatus = status; } | |
| 309 RedirectStatus redirectStatus() const { return m_redirectStatus; } | |
| 310 | |
| 311 void setNavigationStartTime(double); | |
| 312 double navigationStartTime() const { return m_navigationStart; } | |
| 313 | |
| 314 void setIsSameDocumentNavigation(bool isSameDocument) { | |
| 315 m_isSameDocumentNavigation = isSameDocument; | |
| 316 } | |
| 317 bool isSameDocumentNavigation() const { return m_isSameDocumentNavigation; } | |
| 318 | |
| 319 private: | |
| 320 const CacheControlHeader& cacheControlHeader() const; | |
| 321 | |
| 322 bool needsHTTPOrigin() const; | |
| 323 | |
| 324 KURL m_url; | |
| 325 WebCachePolicy m_cachePolicy; | |
| 326 double m_timeoutInterval; // 0 is a magic value for platform default on | |
| 327 // platforms that have one. | |
| 328 KURL m_firstPartyForCookies; | |
| 329 RefPtr<SecurityOrigin> m_requestorOrigin; | |
| 330 AtomicString m_httpMethod; | |
| 331 HTTPHeaderMap m_httpHeaderFields; | |
| 332 RefPtr<EncodedFormData> m_httpBody; | |
| 333 RefPtr<EncodedFormData> m_attachedCredential; | |
| 334 bool m_allowStoredCredentials : 1; | |
| 335 bool m_reportUploadProgress : 1; | |
| 336 bool m_reportRawHeaders : 1; | |
| 337 bool m_hasUserGesture : 1; | |
| 338 bool m_downloadToFile : 1; | |
| 339 bool m_useStreamOnResponse : 1; | |
| 340 bool m_shouldResetAppCache : 1; | |
| 341 WebURLRequest::ServiceWorkerMode m_serviceWorkerMode; | |
| 342 ResourceLoadPriority m_priority; | |
| 343 int m_intraPriorityValue; | |
| 344 int m_requestorID; | |
| 345 int m_requestorProcessID; | |
| 346 int m_appCacheHostID; | |
| 347 RefPtr<ExtraData> m_extraData; | |
| 348 WebURLRequest::RequestContext m_requestContext; | |
| 349 WebURLRequest::FrameType m_frameType; | |
| 350 WebURLRequest::FetchRequestMode m_fetchRequestMode; | |
| 351 WebURLRequest::FetchCredentialsMode m_fetchCredentialsMode; | |
| 352 WebURLRequest::FetchRedirectMode m_fetchRedirectMode; | |
| 353 WebURLRequest::PreviewsState m_previewsState; | |
| 354 ReferrerPolicy m_referrerPolicy; | |
| 355 bool m_didSetHTTPReferrer; | |
| 356 bool m_checkForBrowserSideNavigation; | |
| 357 double m_uiStartTime; | |
| 358 bool m_isExternalRequest; | |
| 359 bool m_isSameDocumentNavigation; | |
| 360 InputToLoadPerfMetricReportPolicy m_inputPerfMetricReportPolicy; | |
| 361 | |
| 362 mutable CacheControlHeader m_cacheControlHeaderCache; | |
| 363 | |
| 364 static double s_defaultTimeoutInterval; | |
| 365 | |
| 366 RedirectStatus m_redirectStatus; | |
| 367 | |
| 368 double m_navigationStart = 0; | |
| 369 }; | |
| 370 | |
| 371 struct CrossThreadResourceRequestData { | |
| 372 WTF_MAKE_NONCOPYABLE(CrossThreadResourceRequestData); | |
| 373 USING_FAST_MALLOC(CrossThreadResourceRequestData); | |
| 374 | |
| 375 public: | |
| 376 CrossThreadResourceRequestData() {} | |
| 377 KURL m_url; | |
| 378 | |
| 379 WebCachePolicy m_cachePolicy; | |
| 380 double m_timeoutInterval; | |
| 381 KURL m_firstPartyForCookies; | |
| 382 RefPtr<SecurityOrigin> m_requestorOrigin; | |
| 383 | |
| 384 String m_httpMethod; | |
| 385 std::unique_ptr<CrossThreadHTTPHeaderMapData> m_httpHeaders; | |
| 386 RefPtr<EncodedFormData> m_httpBody; | |
| 387 RefPtr<EncodedFormData> m_attachedCredential; | |
| 388 bool m_allowStoredCredentials; | |
| 389 bool m_reportUploadProgress; | |
| 390 bool m_hasUserGesture; | |
| 391 bool m_downloadToFile; | |
| 392 WebURLRequest::ServiceWorkerMode m_serviceWorkerMode; | |
| 393 bool m_useStreamOnResponse; | |
| 394 bool m_shouldResetAppCache; | |
| 395 ResourceLoadPriority m_priority; | |
| 396 int m_intraPriorityValue; | |
| 397 int m_requestorID; | |
| 398 int m_requestorProcessID; | |
| 399 int m_appCacheHostID; | |
| 400 WebURLRequest::RequestContext m_requestContext; | |
| 401 WebURLRequest::FrameType m_frameType; | |
| 402 WebURLRequest::FetchRequestMode m_fetchRequestMode; | |
| 403 WebURLRequest::FetchCredentialsMode m_fetchCredentialsMode; | |
| 404 WebURLRequest::FetchRedirectMode m_fetchRedirectMode; | |
| 405 WebURLRequest::PreviewsState m_previewsState; | |
| 406 ReferrerPolicy m_referrerPolicy; | |
| 407 bool m_didSetHTTPReferrer; | |
| 408 bool m_checkForBrowserSideNavigation; | |
| 409 double m_uiStartTime; | |
| 410 bool m_isExternalRequest; | |
| 411 InputToLoadPerfMetricReportPolicy m_inputPerfMetricReportPolicy; | |
| 412 ResourceRequest::RedirectStatus m_redirectStatus; | |
| 413 }; | |
| 414 | |
| 415 } // namespace blink | |
| 416 | |
| 417 #endif // ResourceRequest_h | |
| OLD | NEW |