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