| 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 <memory> | 8 #include <memory> |
| 9 #include "core/CoreExport.h" | 9 #include "core/CoreExport.h" |
| 10 #include "platform/CrossOriginAttributeValue.h" | 10 #include "platform/CrossOriginAttributeValue.h" |
| 11 #include "platform/loader/fetch/ClientHintsPreferences.h" | 11 #include "platform/loader/fetch/ClientHintsPreferences.h" |
| 12 #include "platform/loader/fetch/FetchParameters.h" | 12 #include "platform/loader/fetch/FetchParameters.h" |
| 13 #include "platform/loader/fetch/IntegrityMetadata.h" | 13 #include "platform/loader/fetch/IntegrityMetadata.h" |
| 14 #include "platform/loader/fetch/Resource.h" | 14 #include "platform/loader/fetch/Resource.h" |
| 15 #include "platform/loader/fetch/ResourceFetcher.h" |
| 15 #include "platform/weborigin/SecurityPolicy.h" | 16 #include "platform/weborigin/SecurityPolicy.h" |
| 16 #include "platform/wtf/Allocator.h" | 17 #include "platform/wtf/Allocator.h" |
| 17 #include "platform/wtf/PtrUtil.h" | 18 #include "platform/wtf/PtrUtil.h" |
| 18 #include "platform/wtf/text/TextPosition.h" | 19 #include "platform/wtf/text/TextPosition.h" |
| 19 | 20 |
| 20 namespace blink { | 21 namespace blink { |
| 21 | 22 |
| 22 class Document; | 23 class Document; |
| 23 | 24 |
| 24 class CORE_EXPORT PreloadRequest { | 25 class CORE_EXPORT PreloadRequest { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 36 // TODO(csharrison): Move the implementation to the cpp file when core/html | 37 // TODO(csharrison): Move the implementation to the cpp file when core/html |
| 37 // gets its own testing source set in html/BUILD.gn. | 38 // gets its own testing source set in html/BUILD.gn. |
| 38 static std::unique_ptr<PreloadRequest> CreateIfNeeded( | 39 static std::unique_ptr<PreloadRequest> CreateIfNeeded( |
| 39 const String& initiator_name, | 40 const String& initiator_name, |
| 40 const TextPosition& initiator_position, | 41 const TextPosition& initiator_position, |
| 41 const String& resource_url, | 42 const String& resource_url, |
| 42 const KURL& base_url, | 43 const KURL& base_url, |
| 43 Resource::Type resource_type, | 44 Resource::Type resource_type, |
| 44 const ReferrerPolicy referrer_policy, | 45 const ReferrerPolicy referrer_policy, |
| 45 ReferrerSource referrer_source, | 46 ReferrerSource referrer_source, |
| 47 ResourceFetcher::IsImageSet is_image_set, |
| 46 const FetchParameters::ResourceWidth& resource_width = | 48 const FetchParameters::ResourceWidth& resource_width = |
| 47 FetchParameters::ResourceWidth(), | 49 FetchParameters::ResourceWidth(), |
| 48 const ClientHintsPreferences& client_hints_preferences = | 50 const ClientHintsPreferences& client_hints_preferences = |
| 49 ClientHintsPreferences(), | 51 ClientHintsPreferences(), |
| 50 RequestType request_type = kRequestTypePreload) { | 52 RequestType request_type = kRequestTypePreload) { |
| 51 // Never preload data URLs. We also disallow relative ref URLs which become | 53 // Never preload data URLs. We also disallow relative ref URLs which become |
| 52 // data URLs if the document's URL is a data URL. We don't want to create | 54 // data URLs if the document's URL is a data URL. We don't want to create |
| 53 // extra resource requests with data URLs to avoid copy / initialization | 55 // extra resource requests with data URLs to avoid copy / initialization |
| 54 // overhead, which can be significant for large URLs. | 56 // overhead, which can be significant for large URLs. |
| 55 if (resource_url.IsEmpty() || resource_url.StartsWith("#") || | 57 if (resource_url.IsEmpty() || resource_url.StartsWith("#") || |
| 56 ProtocolIs(resource_url, "data")) { | 58 ProtocolIs(resource_url, "data")) { |
| 57 return nullptr; | 59 return nullptr; |
| 58 } | 60 } |
| 59 return WTF::WrapUnique(new PreloadRequest( | 61 return WTF::WrapUnique(new PreloadRequest( |
| 60 initiator_name, initiator_position, resource_url, base_url, | 62 initiator_name, initiator_position, resource_url, base_url, |
| 61 resource_type, resource_width, client_hints_preferences, request_type, | 63 resource_type, resource_width, client_hints_preferences, request_type, |
| 62 referrer_policy, referrer_source)); | 64 referrer_policy, referrer_source, is_image_set)); |
| 63 } | 65 } |
| 64 | 66 |
| 65 bool IsSafeToSendToAnotherThread() const; | 67 bool IsSafeToSendToAnotherThread() const; |
| 66 | 68 |
| 67 Resource* Start(Document*); | 69 Resource* Start(Document*); |
| 68 | 70 |
| 69 double DiscoveryTime() const { return discovery_time_; } | 71 double DiscoveryTime() const { return discovery_time_; } |
| 70 void SetDefer(FetchParameters::DeferOption defer) { defer_ = defer; } | 72 void SetDefer(FetchParameters::DeferOption defer) { defer_ = defer; } |
| 71 void SetCharset(const String& charset) { charset_ = charset.IsolatedCopy(); } | 73 void SetCharset(const String& charset) { charset_ = charset.IsolatedCopy(); } |
| 72 void SetCrossOrigin(CrossOriginAttributeValue cross_origin) { | 74 void SetCrossOrigin(CrossOriginAttributeValue cross_origin) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 95 void SetIntegrityMetadata(const IntegrityMetadataSet& metadata_set) { | 97 void SetIntegrityMetadata(const IntegrityMetadataSet& metadata_set) { |
| 96 integrity_metadata_ = metadata_set; | 98 integrity_metadata_ = metadata_set; |
| 97 } | 99 } |
| 98 const IntegrityMetadataSet& IntegrityMetadata() const { | 100 const IntegrityMetadataSet& IntegrityMetadata() const { |
| 99 return integrity_metadata_; | 101 return integrity_metadata_; |
| 100 } | 102 } |
| 101 void SetFromInsertionScanner(const bool from_insertion_scanner) { | 103 void SetFromInsertionScanner(const bool from_insertion_scanner) { |
| 102 from_insertion_scanner_ = from_insertion_scanner; | 104 from_insertion_scanner_ = from_insertion_scanner; |
| 103 } | 105 } |
| 104 | 106 |
| 107 bool IsImageSetForTestingOnly() const { |
| 108 return is_image_set_ == ResourceFetcher::kImageIsImageSet; |
| 109 } |
| 110 |
| 105 private: | 111 private: |
| 106 PreloadRequest(const String& initiator_name, | 112 PreloadRequest(const String& initiator_name, |
| 107 const TextPosition& initiator_position, | 113 const TextPosition& initiator_position, |
| 108 const String& resource_url, | 114 const String& resource_url, |
| 109 const KURL& base_url, | 115 const KURL& base_url, |
| 110 Resource::Type resource_type, | 116 Resource::Type resource_type, |
| 111 const FetchParameters::ResourceWidth& resource_width, | 117 const FetchParameters::ResourceWidth& resource_width, |
| 112 const ClientHintsPreferences& client_hints_preferences, | 118 const ClientHintsPreferences& client_hints_preferences, |
| 113 RequestType request_type, | 119 RequestType request_type, |
| 114 const ReferrerPolicy referrer_policy, | 120 const ReferrerPolicy referrer_policy, |
| 115 ReferrerSource referrer_source) | 121 ReferrerSource referrer_source, |
| 122 ResourceFetcher::IsImageSet is_image_set) |
| 116 : initiator_name_(initiator_name), | 123 : initiator_name_(initiator_name), |
| 117 initiator_position_(initiator_position), | 124 initiator_position_(initiator_position), |
| 118 resource_url_(resource_url.IsolatedCopy()), | 125 resource_url_(resource_url.IsolatedCopy()), |
| 119 base_url_(base_url.Copy()), | 126 base_url_(base_url.Copy()), |
| 120 resource_type_(resource_type), | 127 resource_type_(resource_type), |
| 121 cross_origin_(kCrossOriginAttributeNotSet), | 128 cross_origin_(kCrossOriginAttributeNotSet), |
| 122 discovery_time_(MonotonicallyIncreasingTime()), | 129 discovery_time_(MonotonicallyIncreasingTime()), |
| 123 defer_(FetchParameters::kNoDefer), | 130 defer_(FetchParameters::kNoDefer), |
| 124 resource_width_(resource_width), | 131 resource_width_(resource_width), |
| 125 client_hints_preferences_(client_hints_preferences), | 132 client_hints_preferences_(client_hints_preferences), |
| 126 request_type_(request_type), | 133 request_type_(request_type), |
| 127 referrer_policy_(referrer_policy), | 134 referrer_policy_(referrer_policy), |
| 128 referrer_source_(referrer_source), | 135 referrer_source_(referrer_source), |
| 129 from_insertion_scanner_(false) {} | 136 from_insertion_scanner_(false), |
| 137 is_image_set_(is_image_set) {} |
| 130 | 138 |
| 131 KURL CompleteURL(Document*); | 139 KURL CompleteURL(Document*); |
| 132 | 140 |
| 133 String initiator_name_; | 141 String initiator_name_; |
| 134 TextPosition initiator_position_; | 142 TextPosition initiator_position_; |
| 135 String resource_url_; | 143 String resource_url_; |
| 136 KURL base_url_; | 144 KURL base_url_; |
| 137 String charset_; | 145 String charset_; |
| 138 Resource::Type resource_type_; | 146 Resource::Type resource_type_; |
| 139 CrossOriginAttributeValue cross_origin_; | 147 CrossOriginAttributeValue cross_origin_; |
| 140 String nonce_; | 148 String nonce_; |
| 141 double discovery_time_; | 149 double discovery_time_; |
| 142 FetchParameters::DeferOption defer_; | 150 FetchParameters::DeferOption defer_; |
| 143 FetchParameters::ResourceWidth resource_width_; | 151 FetchParameters::ResourceWidth resource_width_; |
| 144 ClientHintsPreferences client_hints_preferences_; | 152 ClientHintsPreferences client_hints_preferences_; |
| 145 RequestType request_type_; | 153 RequestType request_type_; |
| 146 ReferrerPolicy referrer_policy_; | 154 ReferrerPolicy referrer_policy_; |
| 147 ReferrerSource referrer_source_; | 155 ReferrerSource referrer_source_; |
| 148 IntegrityMetadataSet integrity_metadata_; | 156 IntegrityMetadataSet integrity_metadata_; |
| 149 bool from_insertion_scanner_; | 157 bool from_insertion_scanner_; |
| 158 ResourceFetcher::IsImageSet is_image_set_; |
| 150 }; | 159 }; |
| 151 | 160 |
| 152 typedef Vector<std::unique_ptr<PreloadRequest>> PreloadRequestStream; | 161 typedef Vector<std::unique_ptr<PreloadRequest>> PreloadRequestStream; |
| 153 | 162 |
| 154 } // namespace blink | 163 } // namespace blink |
| 155 | 164 |
| 156 #endif | 165 #endif |
| OLD | NEW |