| 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/IntegrityMetadata.h" | 10 #include "core/fetch/IntegrityMetadata.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 class PreloadRequest { | 23 class PreloadRequest { |
| 24 USING_FAST_MALLOC(PreloadRequest); | 24 USING_FAST_MALLOC(PreloadRequest); |
| 25 | 25 |
| 26 public: | 26 public: |
| 27 enum RequestType { | 27 enum RequestType { |
| 28 RequestTypePreload, | 28 RequestTypePreload, |
| 29 RequestTypePreconnect, | 29 RequestTypePreconnect, |
| 30 RequestTypeLinkRelPreload | 30 RequestTypeLinkRelPreload |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 static std::unique_ptr<PreloadRequest> create( | 33 // TODO(csharrison): Move the implementation to the cpp file when core/html |
| 34 // gets its own testing source set in html/BUILD.gn. |
| 35 static std::unique_ptr<PreloadRequest> createIfNeeded( |
| 34 const String& initiatorName, | 36 const String& initiatorName, |
| 35 const TextPosition& initiatorPosition, | 37 const TextPosition& initiatorPosition, |
| 36 const String& resourceURL, | 38 const String& resourceURL, |
| 37 const KURL& baseURL, | 39 const KURL& baseURL, |
| 38 Resource::Type resourceType, | 40 Resource::Type resourceType, |
| 39 const ReferrerPolicy referrerPolicy, | 41 const ReferrerPolicy referrerPolicy, |
| 40 const FetchRequest::ResourceWidth& resourceWidth = | 42 const FetchRequest::ResourceWidth& resourceWidth = |
| 41 FetchRequest::ResourceWidth(), | 43 FetchRequest::ResourceWidth(), |
| 42 const ClientHintsPreferences& clientHintsPreferences = | 44 const ClientHintsPreferences& clientHintsPreferences = |
| 43 ClientHintsPreferences(), | 45 ClientHintsPreferences(), |
| 44 RequestType requestType = RequestTypePreload) { | 46 RequestType requestType = RequestTypePreload) { |
| 47 // Never preload data URLs. We also disallow relative ref URLs which become |
| 48 // data URLs if the document's URL is a data URL. We don't want to create |
| 49 // extra resource requests with data URLs to avoid copy / initialization |
| 50 // overhead, which can be significant for large URLs. |
| 51 if (resourceURL.isEmpty() || resourceURL.startsWith("#") || |
| 52 protocolIs(resourceURL, "data")) { |
| 53 return nullptr; |
| 54 } |
| 45 return wrapUnique(new PreloadRequest( | 55 return wrapUnique(new PreloadRequest( |
| 46 initiatorName, initiatorPosition, resourceURL, baseURL, resourceType, | 56 initiatorName, initiatorPosition, resourceURL, baseURL, resourceType, |
| 47 resourceWidth, clientHintsPreferences, requestType, referrerPolicy)); | 57 resourceWidth, clientHintsPreferences, requestType, referrerPolicy)); |
| 48 } | 58 } |
| 49 | 59 |
| 50 bool isSafeToSendToAnotherThread() const; | 60 bool isSafeToSendToAnotherThread() const; |
| 51 | 61 |
| 52 FetchRequest resourceRequest(Document*); | 62 FetchRequest resourceRequest(Document*); |
| 53 | 63 |
| 54 const String& charset() const { return m_charset; } | 64 const String& charset() const { return m_charset; } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 | 143 |
| 134 // Used for deprecation warnings. | 144 // Used for deprecation warnings. |
| 135 bool m_hasInvalidTypeOrLanguage = false; | 145 bool m_hasInvalidTypeOrLanguage = false; |
| 136 }; | 146 }; |
| 137 | 147 |
| 138 typedef Vector<std::unique_ptr<PreloadRequest>> PreloadRequestStream; | 148 typedef Vector<std::unique_ptr<PreloadRequest>> PreloadRequestStream; |
| 139 | 149 |
| 140 } // namespace blink | 150 } // namespace blink |
| 141 | 151 |
| 142 #endif | 152 #endif |
| OLD | NEW |