Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: third_party/WebKit/Source/platform/network/ResourceResponse.h

Issue 2746113002: platform/loader: move network/Resource* to loader/fetch (Closed)
Patch Set: git rebase master Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Google Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27 #ifndef ResourceResponse_h
28 #define ResourceResponse_h
29
30 #include "platform/PlatformExport.h"
31 #include "platform/blob/BlobData.h"
32 #include "platform/network/HTTPHeaderMap.h"
33 #include "platform/network/HTTPParsers.h"
34 #include "platform/network/ResourceLoadInfo.h"
35 #include "platform/network/ResourceLoadTiming.h"
36 #include "platform/weborigin/KURL.h"
37 #include "public/platform/WebURLResponse.h"
38 #include "public/platform/modules/serviceworker/WebServiceWorkerResponseType.h"
39 #include "wtf/RefCounted.h"
40 #include "wtf/RefPtr.h"
41 #include "wtf/Vector.h"
42 #include "wtf/text/CString.h"
43
44 namespace blink {
45
46 struct CrossThreadResourceResponseData;
47
48 class PLATFORM_EXPORT ResourceResponse final {
49 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
50
51 public:
52 enum HTTPVersion {
53 HTTPVersionUnknown,
54 HTTPVersion_0_9,
55 HTTPVersion_1_0,
56 HTTPVersion_1_1,
57 HTTPVersion_2_0
58 };
59 enum SecurityStyle {
60 SecurityStyleUnknown,
61 SecurityStyleUnauthenticated,
62 SecurityStyleAuthenticationBroken,
63 SecurityStyleWarning,
64 SecurityStyleAuthenticated
65 };
66
67 class PLATFORM_EXPORT SignedCertificateTimestamp final {
68 public:
69 SignedCertificateTimestamp(String status,
70 String origin,
71 String logDescription,
72 String logId,
73 int64_t timestamp,
74 String hashAlgorithm,
75 String signatureAlgorithm,
76 String signatureData)
77 : m_status(status),
78 m_origin(origin),
79 m_logDescription(logDescription),
80 m_logId(logId),
81 m_timestamp(timestamp),
82 m_hashAlgorithm(hashAlgorithm),
83 m_signatureAlgorithm(signatureAlgorithm),
84 m_signatureData(signatureData) {}
85 explicit SignedCertificateTimestamp(
86 const struct blink::WebURLResponse::SignedCertificateTimestamp&);
87 SignedCertificateTimestamp isolatedCopy() const;
88
89 String m_status;
90 String m_origin;
91 String m_logDescription;
92 String m_logId;
93 int64_t m_timestamp;
94 String m_hashAlgorithm;
95 String m_signatureAlgorithm;
96 String m_signatureData;
97 };
98
99 using SignedCertificateTimestampList =
100 WTF::Vector<SignedCertificateTimestamp>;
101
102 struct SecurityDetails {
103 DISALLOW_NEW();
104 SecurityDetails() : validFrom(0), validTo(0) {}
105 // All strings are human-readable values.
106 String protocol;
107 // keyExchange is the empty string if not applicable for the connection's
108 // protocol.
109 String keyExchange;
110 // keyExchangeGroup is the empty string if not applicable for the
111 // connection's key exchange.
112 String keyExchangeGroup;
113 String cipher;
114 // mac is the empty string when the connection cipher suite does not
115 // have a separate MAC value (i.e. if the cipher suite is AEAD).
116 String mac;
117 String subjectName;
118 Vector<String> sanList;
119 String issuer;
120 time_t validFrom;
121 time_t validTo;
122 // DER-encoded X509Certificate certificate chain.
123 Vector<AtomicString> certificate;
124 SignedCertificateTimestampList sctList;
125 };
126
127 class ExtraData : public RefCounted<ExtraData> {
128 public:
129 virtual ~ExtraData() {}
130 };
131
132 explicit ResourceResponse(CrossThreadResourceResponseData*);
133
134 // Gets a copy of the data suitable for passing to another thread.
135 std::unique_ptr<CrossThreadResourceResponseData> copyData() const;
136
137 ResourceResponse();
138 ResourceResponse(const KURL&,
139 const AtomicString& mimeType,
140 long long expectedLength,
141 const AtomicString& textEncodingName);
142 ResourceResponse(const ResourceResponse&);
143 ResourceResponse& operator=(const ResourceResponse&);
144
145 bool isNull() const { return m_isNull; }
146 bool isHTTP() const;
147
148 // The URL of the resource. Note that if a service worker responded to the
149 // request for this resource, it may have fetched an entirely different URL
150 // and responded with that resource. wasFetchedViaServiceWorker() and
151 // originalURLViaServiceWorker() can be used to determine whether and how a
152 // service worker responded to the request. Example service worker code:
153 //
154 // onfetch = (event => {
155 // if (event.request.url == 'https://abc.com')
156 // event.respondWith(fetch('https://def.com'));
157 // });
158 //
159 // If this service worker responds to an "https://abc.com" request, then for
160 // the resulting ResourceResponse, url() is "https://abc.com",
161 // wasFetchedViaServiceWorker() is true, and originalURLViaServiceWorker() is
162 // "https://def.com".
163 const KURL& url() const;
164 void setURL(const KURL&);
165
166 const AtomicString& mimeType() const;
167 void setMimeType(const AtomicString&);
168
169 long long expectedContentLength() const;
170 void setExpectedContentLength(long long);
171
172 const AtomicString& textEncodingName() const;
173 void setTextEncodingName(const AtomicString&);
174
175 int httpStatusCode() const;
176 void setHTTPStatusCode(int);
177
178 const AtomicString& httpStatusText() const;
179 void setHTTPStatusText(const AtomicString&);
180
181 const AtomicString& httpHeaderField(const AtomicString& name) const;
182 void setHTTPHeaderField(const AtomicString& name, const AtomicString& value);
183 void addHTTPHeaderField(const AtomicString& name, const AtomicString& value);
184 void clearHTTPHeaderField(const AtomicString& name);
185 const HTTPHeaderMap& httpHeaderFields() const;
186
187 bool isMultipart() const { return mimeType() == "multipart/x-mixed-replace"; }
188
189 bool isAttachment() const;
190
191 AtomicString httpContentType() const;
192
193 // These functions return parsed values of the corresponding response headers.
194 // NaN means that the header was not present or had invalid value.
195 bool cacheControlContainsNoCache() const;
196 bool cacheControlContainsNoStore() const;
197 bool cacheControlContainsMustRevalidate() const;
198 bool hasCacheValidatorFields() const;
199 double cacheControlMaxAge() const;
200 double cacheControlStaleWhileRevalidate() const;
201 double date() const;
202 double age() const;
203 double expires() const;
204 double lastModified() const;
205
206 unsigned connectionID() const;
207 void setConnectionID(unsigned);
208
209 bool connectionReused() const;
210 void setConnectionReused(bool);
211
212 bool wasCached() const;
213 void setWasCached(bool);
214
215 ResourceLoadTiming* resourceLoadTiming() const;
216 void setResourceLoadTiming(PassRefPtr<ResourceLoadTiming>);
217
218 PassRefPtr<ResourceLoadInfo> resourceLoadInfo() const;
219 void setResourceLoadInfo(PassRefPtr<ResourceLoadInfo>);
220
221 HTTPVersion httpVersion() const { return m_httpVersion; }
222 void setHTTPVersion(HTTPVersion version) { m_httpVersion = version; }
223
224 bool hasMajorCertificateErrors() const { return m_hasMajorCertificateErrors; }
225 void setHasMajorCertificateErrors(bool hasMajorCertificateErrors) {
226 m_hasMajorCertificateErrors = hasMajorCertificateErrors;
227 }
228
229 SecurityStyle getSecurityStyle() const { return m_securityStyle; }
230 void setSecurityStyle(SecurityStyle securityStyle) {
231 m_securityStyle = securityStyle;
232 }
233
234 const SecurityDetails* getSecurityDetails() const {
235 return &m_securityDetails;
236 }
237 void setSecurityDetails(const String& protocol,
238 const String& keyExchange,
239 const String& keyExchangeGroup,
240 const String& cipher,
241 const String& mac,
242 const String& subjectName,
243 const Vector<String>& sanList,
244 const String& issuer,
245 time_t validFrom,
246 time_t validTo,
247 const Vector<AtomicString>& certificate,
248 const SignedCertificateTimestampList& sctList);
249
250 long long appCacheID() const { return m_appCacheID; }
251 void setAppCacheID(long long id) { m_appCacheID = id; }
252
253 const KURL& appCacheManifestURL() const { return m_appCacheManifestURL; }
254 void setAppCacheManifestURL(const KURL& url) { m_appCacheManifestURL = url; }
255
256 bool wasFetchedViaSPDY() const { return m_wasFetchedViaSPDY; }
257 void setWasFetchedViaSPDY(bool value) { m_wasFetchedViaSPDY = value; }
258
259 // See ServiceWorkerResponseInfo::was_fetched_via_service_worker.
260 bool wasFetchedViaServiceWorker() const {
261 return m_wasFetchedViaServiceWorker;
262 }
263 void setWasFetchedViaServiceWorker(bool value) {
264 m_wasFetchedViaServiceWorker = value;
265 }
266
267 bool wasFetchedViaForeignFetch() const { return m_wasFetchedViaForeignFetch; }
268 void setWasFetchedViaForeignFetch(bool value) {
269 m_wasFetchedViaForeignFetch = value;
270 }
271
272 // See ServiceWorkerResponseInfo::was_fallback_required.
273 bool wasFallbackRequiredByServiceWorker() const {
274 return m_wasFallbackRequiredByServiceWorker;
275 }
276 void setWasFallbackRequiredByServiceWorker(bool value) {
277 m_wasFallbackRequiredByServiceWorker = value;
278 }
279
280 WebServiceWorkerResponseType serviceWorkerResponseType() const {
281 return m_serviceWorkerResponseType;
282 }
283 void setServiceWorkerResponseType(WebServiceWorkerResponseType value) {
284 m_serviceWorkerResponseType = value;
285 }
286
287 // See ServiceWorkerResponseInfo::url_list_via_service_worker.
288 const Vector<KURL>& urlListViaServiceWorker() const {
289 return m_urlListViaServiceWorker;
290 }
291 void setURLListViaServiceWorker(const Vector<KURL>& urlList) {
292 m_urlListViaServiceWorker = urlList;
293 }
294
295 // Returns the last URL of urlListViaServiceWorker if exists. Otherwise
296 // returns an empty URL.
297 KURL originalURLViaServiceWorker() const;
298
299 const Vector<char>& multipartBoundary() const { return m_multipartBoundary; }
300 void setMultipartBoundary(const char* bytes, size_t size) {
301 m_multipartBoundary.clear();
302 m_multipartBoundary.append(bytes, size);
303 }
304
305 const String& cacheStorageCacheName() const {
306 return m_cacheStorageCacheName;
307 }
308 void setCacheStorageCacheName(const String& cacheStorageCacheName) {
309 m_cacheStorageCacheName = cacheStorageCacheName;
310 }
311
312 const Vector<String>& corsExposedHeaderNames() const {
313 return m_corsExposedHeaderNames;
314 }
315 void setCorsExposedHeaderNames(const Vector<String>& headerNames) {
316 m_corsExposedHeaderNames = headerNames;
317 }
318
319 bool didServiceWorkerNavigationPreload() const {
320 return m_didServiceWorkerNavigationPreload;
321 }
322 void setDidServiceWorkerNavigationPreload(bool value) {
323 m_didServiceWorkerNavigationPreload = value;
324 }
325
326 int64_t responseTime() const { return m_responseTime; }
327 void setResponseTime(int64_t responseTime) { m_responseTime = responseTime; }
328
329 const AtomicString& remoteIPAddress() const { return m_remoteIPAddress; }
330 void setRemoteIPAddress(const AtomicString& value) {
331 m_remoteIPAddress = value;
332 }
333
334 unsigned short remotePort() const { return m_remotePort; }
335 void setRemotePort(unsigned short value) { m_remotePort = value; }
336
337 long long encodedDataLength() const { return m_encodedDataLength; }
338 void setEncodedDataLength(long long value);
339
340 long long encodedBodyLength() const { return m_encodedBodyLength; }
341 void addToEncodedBodyLength(long long value);
342
343 long long decodedBodyLength() const { return m_decodedBodyLength; }
344 void addToDecodedBodyLength(long long value);
345
346 const String& downloadedFilePath() const { return m_downloadedFilePath; }
347 void setDownloadedFilePath(const String&);
348
349 // Extra data associated with this response.
350 ExtraData* getExtraData() const { return m_extraData.get(); }
351 void setExtraData(PassRefPtr<ExtraData> extraData) {
352 m_extraData = extraData;
353 }
354
355 unsigned memoryUsage() const {
356 // average size, mostly due to URL and Header Map strings
357 return 1280;
358 }
359
360 // PlzNavigate: Even if there is redirections, only one
361 // ResourceResponse is built: the final response.
362 // The redirect response chain can be accessed by this function.
363 const Vector<ResourceResponse>& redirectResponses() const {
364 return m_redirectResponses;
365 }
366 void appendRedirectResponse(const ResourceResponse&);
367
368 // This method doesn't compare the all members.
369 static bool compare(const ResourceResponse&, const ResourceResponse&);
370
371 private:
372 void updateHeaderParsedState(const AtomicString& name);
373
374 KURL m_url;
375 AtomicString m_mimeType;
376 long long m_expectedContentLength;
377 AtomicString m_textEncodingName;
378 int m_httpStatusCode;
379 AtomicString m_httpStatusText;
380 HTTPHeaderMap m_httpHeaderFields;
381 bool m_wasCached : 1;
382 unsigned m_connectionID;
383 bool m_connectionReused : 1;
384 RefPtr<ResourceLoadTiming> m_resourceLoadTiming;
385 RefPtr<ResourceLoadInfo> m_resourceLoadInfo;
386
387 bool m_isNull : 1;
388
389 mutable CacheControlHeader m_cacheControlHeader;
390
391 mutable bool m_haveParsedAgeHeader : 1;
392 mutable bool m_haveParsedDateHeader : 1;
393 mutable bool m_haveParsedExpiresHeader : 1;
394 mutable bool m_haveParsedLastModifiedHeader : 1;
395
396 mutable double m_age;
397 mutable double m_date;
398 mutable double m_expires;
399 mutable double m_lastModified;
400
401 // True if the resource was retrieved by the embedder in spite of
402 // certificate errors.
403 bool m_hasMajorCertificateErrors;
404
405 // The security style of the resource.
406 // This only contains a valid value when the DevTools Network domain is
407 // enabled. (Otherwise, it contains a default value of Unknown.)
408 SecurityStyle m_securityStyle;
409
410 // Security details of this request's connection.
411 // If m_securityStyle is Unknown or Unauthenticated, this does not contain
412 // valid data.
413 SecurityDetails m_securityDetails;
414
415 // HTTP version used in the response, if known.
416 HTTPVersion m_httpVersion;
417
418 // The id of the appcache this response was retrieved from, or zero if
419 // the response was not retrieved from an appcache.
420 long long m_appCacheID;
421
422 // The manifest url of the appcache this response was retrieved from, if any.
423 // Note: only valid for main resource responses.
424 KURL m_appCacheManifestURL;
425
426 // The multipart boundary of this response.
427 Vector<char> m_multipartBoundary;
428
429 // Was the resource fetched over SPDY. See http://dev.chromium.org/spdy
430 bool m_wasFetchedViaSPDY;
431
432 // Was the resource fetched over an explicit proxy (HTTP, SOCKS, etc).
433 bool m_wasFetchedViaProxy;
434
435 // Was the resource fetched over a ServiceWorker.
436 bool m_wasFetchedViaServiceWorker;
437
438 // Was the resource fetched using a foreign fetch service worker.
439 bool m_wasFetchedViaForeignFetch;
440
441 // Was the fallback request with skip service worker flag required.
442 bool m_wasFallbackRequiredByServiceWorker;
443
444 // The type of the response which was fetched by the ServiceWorker.
445 WebServiceWorkerResponseType m_serviceWorkerResponseType;
446
447 // The URL list of the response which was fetched by the ServiceWorker.
448 // This is empty if the response was created inside the ServiceWorker.
449 Vector<KURL> m_urlListViaServiceWorker;
450
451 // The cache name of the CacheStorage from where the response is served via
452 // the ServiceWorker. Null if the response isn't from the CacheStorage.
453 String m_cacheStorageCacheName;
454
455 // The headers that should be exposed according to CORS. Only guaranteed
456 // to be set if the response was fetched by a ServiceWorker.
457 Vector<String> m_corsExposedHeaderNames;
458
459 // True if service worker navigation preload was performed due to
460 // the request for this resource.
461 bool m_didServiceWorkerNavigationPreload;
462
463 // The time at which the response headers were received. For cached
464 // responses, this time could be "far" in the past.
465 int64_t m_responseTime;
466
467 // Remote IP address of the socket which fetched this resource.
468 AtomicString m_remoteIPAddress;
469
470 // Remote port number of the socket which fetched this resource.
471 unsigned short m_remotePort;
472
473 // Size of the response in bytes prior to decompression.
474 long long m_encodedDataLength;
475
476 // Size of the response body in bytes prior to decompression.
477 long long m_encodedBodyLength;
478
479 // Sizes of the response body in bytes after any content-encoding is
480 // removed.
481 long long m_decodedBodyLength;
482
483 // The downloaded file path if the load streamed to a file.
484 String m_downloadedFilePath;
485
486 // The handle to the downloaded file to ensure the underlying file will not
487 // be deleted.
488 RefPtr<BlobDataHandle> m_downloadedFileHandle;
489
490 // ExtraData associated with the response.
491 RefPtr<ExtraData> m_extraData;
492
493 // PlzNavigate: the redirect responses are transmitted
494 // inside the final response.
495 Vector<ResourceResponse> m_redirectResponses;
496 };
497
498 inline bool operator==(const ResourceResponse& a, const ResourceResponse& b) {
499 return ResourceResponse::compare(a, b);
500 }
501 inline bool operator!=(const ResourceResponse& a, const ResourceResponse& b) {
502 return !(a == b);
503 }
504
505 struct CrossThreadResourceResponseData {
506 WTF_MAKE_NONCOPYABLE(CrossThreadResourceResponseData);
507 USING_FAST_MALLOC(CrossThreadResourceResponseData);
508
509 public:
510 CrossThreadResourceResponseData() {}
511 KURL m_url;
512 String m_mimeType;
513 long long m_expectedContentLength;
514 String m_textEncodingName;
515 int m_httpStatusCode;
516 String m_httpStatusText;
517 std::unique_ptr<CrossThreadHTTPHeaderMapData> m_httpHeaders;
518 RefPtr<ResourceLoadTiming> m_resourceLoadTiming;
519 bool m_hasMajorCertificateErrors;
520 ResourceResponse::SecurityStyle m_securityStyle;
521 ResourceResponse::SecurityDetails m_securityDetails;
522 // This is |certificate| from SecurityDetails since that structure should
523 // use an AtomicString but this temporary structure is sent across threads.
524 Vector<String> m_certificate;
525 ResourceResponse::HTTPVersion m_httpVersion;
526 long long m_appCacheID;
527 KURL m_appCacheManifestURL;
528 Vector<char> m_multipartBoundary;
529 bool m_wasFetchedViaSPDY;
530 bool m_wasFetchedViaProxy;
531 bool m_wasFetchedViaServiceWorker;
532 bool m_wasFetchedViaForeignFetch;
533 bool m_wasFallbackRequiredByServiceWorker;
534 WebServiceWorkerResponseType m_serviceWorkerResponseType;
535 Vector<KURL> m_urlListViaServiceWorker;
536 String m_cacheStorageCacheName;
537 bool m_didServiceWorkerNavigationPreload;
538 int64_t m_responseTime;
539 String m_remoteIPAddress;
540 unsigned short m_remotePort;
541 long long m_encodedDataLength;
542 long long m_encodedBodyLength;
543 long long m_decodedBodyLength;
544 String m_downloadedFilePath;
545 RefPtr<BlobDataHandle> m_downloadedFileHandle;
546 };
547
548 } // namespace blink
549
550 #endif // ResourceResponse_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698