OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
3 * Copyright (C) 2009 Torch Mobile, Inc. http://www.torchmobile.com/ | 3 * Copyright (C) 2009 Torch Mobile, Inc. http://www.torchmobile.com/ |
4 * Copyright (C) 2010 Google Inc. All Rights Reserved. | 4 * Copyright (C) 2010 Google Inc. All Rights Reserved. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
8 * are met: | 8 * are met: |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 #include "core/html/HTMLMetaElement.h" | 43 #include "core/html/HTMLMetaElement.h" |
44 #include "core/html/LinkRelAttribute.h" | 44 #include "core/html/LinkRelAttribute.h" |
45 #include "core/html/parser/HTMLParserIdioms.h" | 45 #include "core/html/parser/HTMLParserIdioms.h" |
46 #include "core/html/parser/HTMLSrcsetParser.h" | 46 #include "core/html/parser/HTMLSrcsetParser.h" |
47 #include "core/html/parser/HTMLTokenizer.h" | 47 #include "core/html/parser/HTMLTokenizer.h" |
48 #include "core/loader/LinkLoader.h" | 48 #include "core/loader/LinkLoader.h" |
49 #include "platform/ContentType.h" | 49 #include "platform/ContentType.h" |
50 #include "platform/Histogram.h" | 50 #include "platform/Histogram.h" |
51 #include "platform/MIMETypeRegistry.h" | 51 #include "platform/MIMETypeRegistry.h" |
52 #include "platform/TraceEvent.h" | 52 #include "platform/TraceEvent.h" |
53 #include <memory> | |
54 | 53 |
55 namespace blink { | 54 namespace blink { |
56 | 55 |
57 namespace { | 56 namespace { |
58 | 57 |
59 // When adding values to this enum, update histograms.xml as well. | 58 // When adding values to this enum, update histograms.xml as well. |
60 enum DocumentWriteGatedEvaluation { | 59 enum DocumentWriteGatedEvaluation { |
61 GatedEvaluationScriptTooLong, | 60 GatedEvaluationScriptTooLong, |
62 GatedEvaluationNoLikelyScript, | 61 GatedEvaluationNoLikelyScript, |
63 GatedEvaluationLooping, | 62 GatedEvaluationLooping, |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 // ref to a string we're going to send will fail isSafeToSendToAnoth
erThread(). | 199 // ref to a string we're going to send will fail isSafeToSendToAnoth
erThread(). |
201 pictureData.sourceURL = m_srcsetImageCandidate.toString().isolatedCo
py(); | 200 pictureData.sourceURL = m_srcsetImageCandidate.toString().isolatedCo
py(); |
202 pictureData.sourceSizeSet = m_sourceSizeSet; | 201 pictureData.sourceSizeSet = m_sourceSizeSet; |
203 pictureData.sourceSize = m_sourceSize; | 202 pictureData.sourceSize = m_sourceSize; |
204 pictureData.picked = true; | 203 pictureData.picked = true; |
205 } else if (match(m_tagImpl, imgTag) && !pictureData.sourceURL.isEmpty())
{ | 204 } else if (match(m_tagImpl, imgTag) && !pictureData.sourceURL.isEmpty())
{ |
206 setUrlToLoad(pictureData.sourceURL, AllowURLReplacement); | 205 setUrlToLoad(pictureData.sourceURL, AllowURLReplacement); |
207 } | 206 } |
208 } | 207 } |
209 | 208 |
210 std::unique_ptr<PreloadRequest> createPreloadRequest(const KURL& predictedBa
seURL, const SegmentedString& source, const ClientHintsPreferences& clientHintsP
references, const PictureData& pictureData, const ReferrerPolicy documentReferre
rPolicy) | 209 PassOwnPtr<PreloadRequest> createPreloadRequest(const KURL& predictedBaseURL
, const SegmentedString& source, const ClientHintsPreferences& clientHintsPrefer
ences, const PictureData& pictureData, const ReferrerPolicy documentReferrerPoli
cy) |
211 { | 210 { |
212 PreloadRequest::RequestType requestType = PreloadRequest::RequestTypePre
load; | 211 PreloadRequest::RequestType requestType = PreloadRequest::RequestTypePre
load; |
213 if (shouldPreconnect()) { | 212 if (shouldPreconnect()) { |
214 requestType = PreloadRequest::RequestTypePreconnect; | 213 requestType = PreloadRequest::RequestTypePreconnect; |
215 } else { | 214 } else { |
216 if (isLinkRelPreload()) { | 215 if (isLinkRelPreload()) { |
217 requestType = PreloadRequest::RequestTypeLinkRelPreload; | 216 requestType = PreloadRequest::RequestTypeLinkRelPreload; |
218 } | 217 } |
219 if (!shouldPreload()) { | 218 if (!shouldPreload()) { |
220 return nullptr; | 219 return nullptr; |
(...skipping 13 matching lines...) Expand all Loading... |
234 resourceWidth.width = sourceSize; | 233 resourceWidth.width = sourceSize; |
235 resourceWidth.isSet = true; | 234 resourceWidth.isSet = true; |
236 } | 235 } |
237 | 236 |
238 Resource::Type type; | 237 Resource::Type type; |
239 if (!resourceType(type)) | 238 if (!resourceType(type)) |
240 return nullptr; | 239 return nullptr; |
241 | 240 |
242 // The element's 'referrerpolicy' attribute (if present) takes precedenc
e over the document's referrer policy. | 241 // The element's 'referrerpolicy' attribute (if present) takes precedenc
e over the document's referrer policy. |
243 ReferrerPolicy referrerPolicy = (m_referrerPolicy != ReferrerPolicyDefau
lt) ? m_referrerPolicy : documentReferrerPolicy; | 242 ReferrerPolicy referrerPolicy = (m_referrerPolicy != ReferrerPolicyDefau
lt) ? m_referrerPolicy : documentReferrerPolicy; |
244 std::unique_ptr<PreloadRequest> request = PreloadRequest::create(initiat
orFor(m_tagImpl), position, m_urlToLoad, predictedBaseURL, type, referrerPolicy,
resourceWidth, clientHintsPreferences, requestType); | 243 OwnPtr<PreloadRequest> request = PreloadRequest::create(initiatorFor(m_t
agImpl), position, m_urlToLoad, predictedBaseURL, type, referrerPolicy, resource
Width, clientHintsPreferences, requestType); |
245 request->setCrossOrigin(m_crossOrigin); | 244 request->setCrossOrigin(m_crossOrigin); |
246 request->setCharset(charset()); | 245 request->setCharset(charset()); |
247 request->setDefer(m_defer); | 246 request->setDefer(m_defer); |
248 request->setIntegrityMetadata(m_integrityMetadata); | 247 request->setIntegrityMetadata(m_integrityMetadata); |
249 return request; | 248 return request; |
250 } | 249 } |
251 | 250 |
252 private: | 251 private: |
253 template<typename NameType> | 252 template<typename NameType> |
254 void processScriptAttribute(const NameType& attributeName, const String& att
ributeValue) | 253 void processScriptAttribute(const NameType& attributeName, const String& att
ributeValue) |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 float m_sourceSize; | 473 float m_sourceSize; |
475 bool m_sourceSizeSet; | 474 bool m_sourceSizeSet; |
476 FetchRequest::DeferOption m_defer; | 475 FetchRequest::DeferOption m_defer; |
477 CrossOriginAttributeValue m_crossOrigin; | 476 CrossOriginAttributeValue m_crossOrigin; |
478 Member<MediaValuesCached> m_mediaValues; | 477 Member<MediaValuesCached> m_mediaValues; |
479 bool m_referrerPolicySet; | 478 bool m_referrerPolicySet; |
480 ReferrerPolicy m_referrerPolicy; | 479 ReferrerPolicy m_referrerPolicy; |
481 IntegrityMetadataSet m_integrityMetadata; | 480 IntegrityMetadataSet m_integrityMetadata; |
482 }; | 481 }; |
483 | 482 |
484 TokenPreloadScanner::TokenPreloadScanner(const KURL& documentURL, std::unique_pt
r<CachedDocumentParameters> documentParameters, const MediaValuesCached::MediaVa
luesCachedData& mediaValuesCachedData) | 483 TokenPreloadScanner::TokenPreloadScanner(const KURL& documentURL, PassOwnPtr<Cac
hedDocumentParameters> documentParameters, const MediaValuesCached::MediaValuesC
achedData& mediaValuesCachedData) |
485 : m_documentURL(documentURL) | 484 : m_documentURL(documentURL) |
486 , m_inStyle(false) | 485 , m_inStyle(false) |
487 , m_inPicture(false) | 486 , m_inPicture(false) |
488 , m_inScript(false) | 487 , m_inScript(false) |
489 , m_isAppCacheEnabled(false) | 488 , m_isAppCacheEnabled(false) |
490 , m_isCSPEnabled(false) | 489 , m_isCSPEnabled(false) |
491 , m_templateCount(0) | 490 , m_templateCount(0) |
492 , m_documentParameters(std::move(documentParameters)) | 491 , m_documentParameters(std::move(documentParameters)) |
493 , m_mediaValues(MediaValuesCached::create(mediaValuesCachedData)) | 492 , m_mediaValues(MediaValuesCached::create(mediaValuesCachedData)) |
494 , m_didRewind(false) | 493 , m_didRewind(false) |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 if (match(tagImpl, pictureTag)) { | 737 if (match(tagImpl, pictureTag)) { |
739 m_inPicture = true; | 738 m_inPicture = true; |
740 m_pictureData = PictureData(); | 739 m_pictureData = PictureData(); |
741 return; | 740 return; |
742 } | 741 } |
743 | 742 |
744 StartTagScanner scanner(tagImpl, m_mediaValues); | 743 StartTagScanner scanner(tagImpl, m_mediaValues); |
745 scanner.processAttributes(token.attributes()); | 744 scanner.processAttributes(token.attributes()); |
746 if (m_inPicture) | 745 if (m_inPicture) |
747 scanner.handlePictureSourceURL(m_pictureData); | 746 scanner.handlePictureSourceURL(m_pictureData); |
748 std::unique_ptr<PreloadRequest> request = scanner.createPreloadRequest(m
_predictedBaseElementURL, source, m_clientHintsPreferences, m_pictureData, m_doc
umentParameters->referrerPolicy); | 747 OwnPtr<PreloadRequest> request = scanner.createPreloadRequest(m_predicte
dBaseElementURL, source, m_clientHintsPreferences, m_pictureData, m_documentPara
meters->referrerPolicy); |
749 if (request) | 748 if (request) |
750 requests.append(std::move(request)); | 749 requests.append(std::move(request)); |
751 return; | 750 return; |
752 } | 751 } |
753 default: { | 752 default: { |
754 return; | 753 return; |
755 } | 754 } |
756 } | 755 } |
757 } | 756 } |
758 | 757 |
759 template<typename Token> | 758 template<typename Token> |
760 void TokenPreloadScanner::updatePredictedBaseURL(const Token& token) | 759 void TokenPreloadScanner::updatePredictedBaseURL(const Token& token) |
761 { | 760 { |
762 ASSERT(m_predictedBaseElementURL.isEmpty()); | 761 ASSERT(m_predictedBaseElementURL.isEmpty()); |
763 if (const typename Token::Attribute* hrefAttribute = token.getAttributeItem(
hrefAttr)) { | 762 if (const typename Token::Attribute* hrefAttribute = token.getAttributeItem(
hrefAttr)) { |
764 KURL url(m_documentURL, stripLeadingAndTrailingHTMLSpaces(hrefAttribute-
>value8BitIfNecessary())); | 763 KURL url(m_documentURL, stripLeadingAndTrailingHTMLSpaces(hrefAttribute-
>value8BitIfNecessary())); |
765 m_predictedBaseElementURL = url.isValid() ? url.copy() : KURL(); | 764 m_predictedBaseElementURL = url.isValid() ? url.copy() : KURL(); |
766 } | 765 } |
767 } | 766 } |
768 | 767 |
769 HTMLPreloadScanner::HTMLPreloadScanner(const HTMLParserOptions& options, const K
URL& documentURL, std::unique_ptr<CachedDocumentParameters> documentParameters,
const MediaValuesCached::MediaValuesCachedData& mediaValuesCachedData) | 768 HTMLPreloadScanner::HTMLPreloadScanner(const HTMLParserOptions& options, const K
URL& documentURL, PassOwnPtr<CachedDocumentParameters> documentParameters, const
MediaValuesCached::MediaValuesCachedData& mediaValuesCachedData) |
770 : m_scanner(documentURL, std::move(documentParameters), mediaValuesCachedDat
a) | 769 : m_scanner(documentURL, std::move(documentParameters), mediaValuesCachedDat
a) |
771 , m_tokenizer(HTMLTokenizer::create(options)) | 770 , m_tokenizer(HTMLTokenizer::create(options)) |
772 { | 771 { |
773 } | 772 } |
774 | 773 |
775 HTMLPreloadScanner::~HTMLPreloadScanner() | 774 HTMLPreloadScanner::~HTMLPreloadScanner() |
776 { | 775 { |
777 } | 776 } |
778 | 777 |
779 void HTMLPreloadScanner::appendToEnd(const SegmentedString& source) | 778 void HTMLPreloadScanner::appendToEnd(const SegmentedString& source) |
(...skipping 29 matching lines...) Expand all Loading... |
809 ASSERT(document); | 808 ASSERT(document); |
810 doHtmlPreloadScanning = !document->settings() || document->settings()->doHtm
lPreloadScanning(); | 809 doHtmlPreloadScanning = !document->settings() || document->settings()->doHtm
lPreloadScanning(); |
811 doDocumentWritePreloadScanning = doHtmlPreloadScanning && document->frame()
&& document->frame()->isMainFrame(); | 810 doDocumentWritePreloadScanning = doHtmlPreloadScanning && document->frame()
&& document->frame()->isMainFrame(); |
812 defaultViewportMinWidth = document->viewportDefaultMinWidth(); | 811 defaultViewportMinWidth = document->viewportDefaultMinWidth(); |
813 viewportMetaZeroValuesQuirk = document->settings() && document->settings()->
viewportMetaZeroValuesQuirk(); | 812 viewportMetaZeroValuesQuirk = document->settings() && document->settings()->
viewportMetaZeroValuesQuirk(); |
814 viewportMetaEnabled = document->settings() && document->settings()->viewport
MetaEnabled(); | 813 viewportMetaEnabled = document->settings() && document->settings()->viewport
MetaEnabled(); |
815 referrerPolicy = document->getReferrerPolicy(); | 814 referrerPolicy = document->getReferrerPolicy(); |
816 } | 815 } |
817 | 816 |
818 } // namespace blink | 817 } // namespace blink |
OLD | NEW |