OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef PreloadRequest_h | 5 #ifndef PreloadRequest_h |
6 #define PreloadRequest_h | 6 #define PreloadRequest_h |
7 | 7 |
8 #include "core/fetch/ClientHintsPreferences.h" | 8 #include "core/fetch/ClientHintsPreferences.h" |
9 #include "core/fetch/FetchRequest.h" | 9 #include "core/fetch/FetchRequest.h" |
10 #include "core/fetch/Resource.h" | 10 #include "core/fetch/Resource.h" |
| 11 #include "platform/CrossOriginAttributeValue.h" |
11 #include "platform/weborigin/SecurityPolicy.h" | 12 #include "platform/weborigin/SecurityPolicy.h" |
12 #include "wtf/Allocator.h" | 13 #include "wtf/Allocator.h" |
13 #include "wtf/text/TextPosition.h" | 14 #include "wtf/text/TextPosition.h" |
14 | 15 |
15 namespace blink { | 16 namespace blink { |
16 | 17 |
17 class Document; | 18 class Document; |
18 | 19 |
19 class PreloadRequest { | 20 class PreloadRequest { |
20 USING_FAST_MALLOC(PreloadRequest); | 21 USING_FAST_MALLOC(PreloadRequest); |
21 public: | 22 public: |
22 enum RequestType { RequestTypePreload, RequestTypePreconnect }; | 23 enum RequestType { RequestTypePreload, RequestTypePreconnect }; |
23 | 24 |
24 static PassOwnPtr<PreloadRequest> create(const String& initiatorName, const
TextPosition& initiatorPosition, const String& resourceURL, const KURL& baseURL,
Resource::Type resourceType, const ReferrerPolicy referrerPolicy, const FetchRe
quest::ResourceWidth& resourceWidth = FetchRequest::ResourceWidth(), const Clien
tHintsPreferences& clientHintsPreferences = ClientHintsPreferences(), RequestTyp
e requestType = RequestTypePreload) | 25 static PassOwnPtr<PreloadRequest> create(const String& initiatorName, const
TextPosition& initiatorPosition, const String& resourceURL, const KURL& baseURL,
Resource::Type resourceType, const ReferrerPolicy referrerPolicy, const FetchRe
quest::ResourceWidth& resourceWidth = FetchRequest::ResourceWidth(), const Clien
tHintsPreferences& clientHintsPreferences = ClientHintsPreferences(), RequestTyp
e requestType = RequestTypePreload) |
25 { | 26 { |
26 return adoptPtr(new PreloadRequest(initiatorName, initiatorPosition, res
ourceURL, baseURL, resourceType, resourceWidth, clientHintsPreferences, requestT
ype, referrerPolicy)); | 27 return adoptPtr(new PreloadRequest(initiatorName, initiatorPosition, res
ourceURL, baseURL, resourceType, resourceWidth, clientHintsPreferences, requestT
ype, referrerPolicy)); |
27 } | 28 } |
28 | 29 |
29 bool isSafeToSendToAnotherThread() const; | 30 bool isSafeToSendToAnotherThread() const; |
30 | 31 |
31 FetchRequest resourceRequest(Document*); | 32 FetchRequest resourceRequest(Document*); |
32 | 33 |
33 const String& charset() const { return m_charset; } | 34 const String& charset() const { return m_charset; } |
34 double discoveryTime() const { return m_discoveryTime; } | 35 double discoveryTime() const { return m_discoveryTime; } |
35 void setDefer(FetchRequest::DeferOption defer) { m_defer = defer; } | 36 void setDefer(FetchRequest::DeferOption defer) { m_defer = defer; } |
36 void setCharset(const String& charset) { m_charset = charset.isolatedCopy();
} | 37 void setCharset(const String& charset) { m_charset = charset.isolatedCopy();
} |
37 void setCrossOriginEnabled(StoredCredentials allowCredentials) | 38 void setCrossOrigin(CrossOriginAttributeValue crossOrigin) |
38 { | 39 { |
39 m_isCORSEnabled = true; | 40 m_crossOrigin = crossOrigin; |
40 m_allowCredentials = allowCredentials; | |
41 } | 41 } |
42 | 42 CrossOriginAttributeValue crossOrigin() const |
| 43 { |
| 44 return m_crossOrigin; |
| 45 } |
43 Resource::Type resourceType() const { return m_resourceType; } | 46 Resource::Type resourceType() const { return m_resourceType; } |
44 | 47 |
45 const String& resourceURL() const { return m_resourceURL; } | 48 const String& resourceURL() const { return m_resourceURL; } |
46 float resourceWidth() const { return m_resourceWidth.isSet ? m_resourceWidth
.width : 0; } | 49 float resourceWidth() const { return m_resourceWidth.isSet ? m_resourceWidth
.width : 0; } |
47 const KURL& baseURL() const { return m_baseURL; } | 50 const KURL& baseURL() const { return m_baseURL; } |
48 bool isPreconnect() const { return m_requestType == RequestTypePreconnect; } | 51 bool isPreconnect() const { return m_requestType == RequestTypePreconnect; } |
49 bool isCORS() const { return m_isCORSEnabled; } | |
50 bool isAllowCredentials() const { return m_allowCredentials == AllowStoredCr
edentials; } | |
51 const ClientHintsPreferences& preferences() const { return m_clientHintsPref
erences; } | 52 const ClientHintsPreferences& preferences() const { return m_clientHintsPref
erences; } |
52 ReferrerPolicy referrerPolicy() const { return m_referrerPolicy; } | 53 ReferrerPolicy referrerPolicy() const { return m_referrerPolicy; } |
53 | 54 |
54 private: | 55 private: |
55 PreloadRequest(const String& initiatorName, | 56 PreloadRequest(const String& initiatorName, |
56 const TextPosition& initiatorPosition, | 57 const TextPosition& initiatorPosition, |
57 const String& resourceURL, | 58 const String& resourceURL, |
58 const KURL& baseURL, | 59 const KURL& baseURL, |
59 Resource::Type resourceType, | 60 Resource::Type resourceType, |
60 const FetchRequest::ResourceWidth& resourceWidth, | 61 const FetchRequest::ResourceWidth& resourceWidth, |
61 const ClientHintsPreferences& clientHintsPreferences, | 62 const ClientHintsPreferences& clientHintsPreferences, |
62 RequestType requestType, | 63 RequestType requestType, |
63 const ReferrerPolicy referrerPolicy) | 64 const ReferrerPolicy referrerPolicy) |
64 : m_initiatorName(initiatorName) | 65 : m_initiatorName(initiatorName) |
65 , m_initiatorPosition(initiatorPosition) | 66 , m_initiatorPosition(initiatorPosition) |
66 , m_resourceURL(resourceURL.isolatedCopy()) | 67 , m_resourceURL(resourceURL.isolatedCopy()) |
67 , m_baseURL(baseURL.copy()) | 68 , m_baseURL(baseURL.copy()) |
68 , m_resourceType(resourceType) | 69 , m_resourceType(resourceType) |
69 , m_isCORSEnabled(false) | 70 , m_crossOrigin(CrossOriginAttributeNotSet) |
70 , m_allowCredentials(DoNotAllowStoredCredentials) | |
71 , m_discoveryTime(monotonicallyIncreasingTime()) | 71 , m_discoveryTime(monotonicallyIncreasingTime()) |
72 , m_defer(FetchRequest::NoDefer) | 72 , m_defer(FetchRequest::NoDefer) |
73 , m_resourceWidth(resourceWidth) | 73 , m_resourceWidth(resourceWidth) |
74 , m_clientHintsPreferences(clientHintsPreferences) | 74 , m_clientHintsPreferences(clientHintsPreferences) |
75 , m_requestType(requestType) | 75 , m_requestType(requestType) |
76 , m_referrerPolicy(referrerPolicy) | 76 , m_referrerPolicy(referrerPolicy) |
77 { | 77 { |
78 } | 78 } |
79 | 79 |
80 KURL completeURL(Document*); | 80 KURL completeURL(Document*); |
81 | 81 |
82 String m_initiatorName; | 82 String m_initiatorName; |
83 TextPosition m_initiatorPosition; | 83 TextPosition m_initiatorPosition; |
84 String m_resourceURL; | 84 String m_resourceURL; |
85 KURL m_baseURL; | 85 KURL m_baseURL; |
86 String m_charset; | 86 String m_charset; |
87 Resource::Type m_resourceType; | 87 Resource::Type m_resourceType; |
88 bool m_isCORSEnabled; | 88 CrossOriginAttributeValue m_crossOrigin; |
89 StoredCredentials m_allowCredentials; | |
90 double m_discoveryTime; | 89 double m_discoveryTime; |
91 FetchRequest::DeferOption m_defer; | 90 FetchRequest::DeferOption m_defer; |
92 FetchRequest::ResourceWidth m_resourceWidth; | 91 FetchRequest::ResourceWidth m_resourceWidth; |
93 ClientHintsPreferences m_clientHintsPreferences; | 92 ClientHintsPreferences m_clientHintsPreferences; |
94 RequestType m_requestType; | 93 RequestType m_requestType; |
95 ReferrerPolicy m_referrerPolicy; | 94 ReferrerPolicy m_referrerPolicy; |
96 }; | 95 }; |
97 | 96 |
98 typedef Vector<OwnPtr<PreloadRequest>> PreloadRequestStream; | 97 typedef Vector<OwnPtr<PreloadRequest>> PreloadRequestStream; |
99 | 98 |
100 } | 99 } |
101 | 100 |
102 #endif | 101 #endif |
OLD | NEW |