| 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 } | 159 } |
| 160 | 160 |
| 161 void handlePictureSourceURL(String& sourceURL) | 161 void handlePictureSourceURL(String& sourceURL) |
| 162 { | 162 { |
| 163 if (match(m_tagImpl, sourceTag) && m_matchedMediaAttribute && sourceURL.
isEmpty()) | 163 if (match(m_tagImpl, sourceTag) && m_matchedMediaAttribute && sourceURL.
isEmpty()) |
| 164 sourceURL = m_srcsetImageCandidate.toString(); | 164 sourceURL = m_srcsetImageCandidate.toString(); |
| 165 else if (match(m_tagImpl, imgTag) && !sourceURL.isEmpty()) | 165 else if (match(m_tagImpl, imgTag) && !sourceURL.isEmpty()) |
| 166 setUrlToLoad(sourceURL, AllowURLReplacement); | 166 setUrlToLoad(sourceURL, AllowURLReplacement); |
| 167 } | 167 } |
| 168 | 168 |
| 169 PassOwnPtr<PreloadRequest> createPreloadRequest(const KURL& predictedBaseURL
, const SegmentedString& source) | 169 PassOwnPtr<PreloadRequest> createPreloadRequest(const KURL& predictedBaseURL
, const SegmentedString& source, const ClientHintsPreferences& clientHintsPrefer
ences) |
| 170 { | 170 { |
| 171 if (!shouldPreload() || !m_matchedMediaAttribute) | 171 if (!shouldPreload() || !m_matchedMediaAttribute) |
| 172 return nullptr; | 172 return nullptr; |
| 173 | 173 |
| 174 TextPosition position = TextPosition(source.currentLine(), source.curren
tColumn()); | 174 TextPosition position = TextPosition(source.currentLine(), source.curren
tColumn()); |
| 175 FetchRequest::ResourceWidth resourceWidth; | 175 FetchRequest::ResourceWidth resourceWidth; |
| 176 if (m_sourceSizeSet && m_srcsetImageCandidate.resourceWidth() != Uniniti
alizedDescriptor) { | 176 if (m_sourceSizeSet && m_srcsetImageCandidate.resourceWidth() != Uniniti
alizedDescriptor) { |
| 177 resourceWidth.width = m_sourceSize; | 177 resourceWidth.width = m_sourceSize; |
| 178 resourceWidth.isSet = true; | 178 resourceWidth.isSet = true; |
| 179 } | 179 } |
| 180 OwnPtr<PreloadRequest> request = PreloadRequest::create(initiatorFor(m_t
agImpl), position, m_urlToLoad, predictedBaseURL, resourceType(), resourceWidth)
; | 180 OwnPtr<PreloadRequest> request = PreloadRequest::create(initiatorFor(m_t
agImpl), position, m_urlToLoad, predictedBaseURL, resourceType(), resourceWidth,
clientHintsPreferences); |
| 181 if (isCORSEnabled()) | 181 if (isCORSEnabled()) |
| 182 request->setCrossOriginEnabled(allowStoredCredentials()); | 182 request->setCrossOriginEnabled(allowStoredCredentials()); |
| 183 request->setCharset(charset()); | 183 request->setCharset(charset()); |
| 184 request->setDefer(m_defer); | 184 request->setDefer(m_defer); |
| 185 return request.release(); | 185 return request.release(); |
| 186 } | 186 } |
| 187 | 187 |
| 188 private: | 188 private: |
| 189 template<typename NameType> | 189 template<typename NameType> |
| 190 void processScriptAttribute(const NameType& attributeName, const String& att
ributeValue) | 190 void processScriptAttribute(const NameType& attributeName, const String& att
ributeValue) |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 void TokenPreloadScanner::scan(const HTMLToken& token, const SegmentedString& so
urce, PreloadRequestStream& requests) | 429 void TokenPreloadScanner::scan(const HTMLToken& token, const SegmentedString& so
urce, PreloadRequestStream& requests) |
| 430 { | 430 { |
| 431 scanCommon(token, source, requests); | 431 scanCommon(token, source, requests); |
| 432 } | 432 } |
| 433 | 433 |
| 434 void TokenPreloadScanner::scan(const CompactHTMLToken& token, const SegmentedStr
ing& source, PreloadRequestStream& requests) | 434 void TokenPreloadScanner::scan(const CompactHTMLToken& token, const SegmentedStr
ing& source, PreloadRequestStream& requests) |
| 435 { | 435 { |
| 436 scanCommon(token, source, requests); | 436 scanCommon(token, source, requests); |
| 437 } | 437 } |
| 438 | 438 |
| 439 static void handleMetaViewport(const String& attributeValue, CachedDocumentParam
eters* documentParameters) |
| 440 { |
| 441 ViewportDescription description(ViewportDescription::ViewportMeta); |
| 442 HTMLMetaElement::getViewportDescriptionFromContentAttribute(attributeValue,
description, nullptr, documentParameters->viewportMetaZeroValuesQuirk); |
| 443 FloatSize initialViewport(documentParameters->mediaValues->viewportHeight(),
documentParameters->mediaValues->viewportWidth()); |
| 444 PageScaleConstraints constraints = description.resolve(initialViewport, docu
mentParameters->defaultViewportMinWidth); |
| 445 MediaValuesCached* cachedMediaValues = static_cast<MediaValuesCached*>(docum
entParameters->mediaValues.get()); |
| 446 cachedMediaValues->setViewportHeight(constraints.layoutSize.height()); |
| 447 cachedMediaValues->setViewportWidth(constraints.layoutSize.width()); |
| 448 } |
| 449 |
| 439 template<typename Token> | 450 template<typename Token> |
| 440 void TokenPreloadScanner::scanCommon(const Token& token, const SegmentedString&
source, PreloadRequestStream& requests) | 451 void TokenPreloadScanner::scanCommon(const Token& token, const SegmentedString&
source, PreloadRequestStream& requests) |
| 441 { | 452 { |
| 442 // Disable preload for documents with AppCache. | 453 // Disable preload for documents with AppCache. |
| 443 if (m_isAppCacheEnabled) | 454 if (m_isAppCacheEnabled) |
| 444 return; | 455 return; |
| 445 | 456 |
| 446 // http://crbug.com/434230 Disable preload for documents with CSP <meta> tag
s | 457 // http://crbug.com/434230 Disable preload for documents with CSP <meta> tag
s |
| 447 if (m_isCSPEnabled) | 458 if (m_isCSPEnabled) |
| 448 return; | 459 return; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 return; | 500 return; |
| 490 updatePredictedBaseURL(token); | 501 updatePredictedBaseURL(token); |
| 491 return; | 502 return; |
| 492 } | 503 } |
| 493 if (match(tagImpl, htmlTag) && token.getAttributeItem(manifestAttr)) { | 504 if (match(tagImpl, htmlTag) && token.getAttributeItem(manifestAttr)) { |
| 494 m_isAppCacheEnabled = true; | 505 m_isAppCacheEnabled = true; |
| 495 return; | 506 return; |
| 496 } | 507 } |
| 497 if (match(tagImpl, metaTag)) { | 508 if (match(tagImpl, metaTag)) { |
| 498 const typename Token::Attribute* equivAttribute = token.getAttribute
Item(http_equivAttr); | 509 const typename Token::Attribute* equivAttribute = token.getAttribute
Item(http_equivAttr); |
| 499 if (equivAttribute && equalIgnoringCase(String(equivAttribute->value
), "content-security-policy")) { | 510 if (equivAttribute) { |
| 500 m_isCSPEnabled = true; | 511 String equivAttributeValue(equivAttribute->value); |
| 512 if (equalIgnoringCase(equivAttributeValue, "content-security-pol
icy")) |
| 513 m_isCSPEnabled = true; |
| 514 else if (equalIgnoringCase(equivAttributeValue, "accept-ch")) |
| 515 handleAcceptClientHintsHeader(equivAttributeValue, m_clientH
intsPreferences); |
| 501 return; | 516 return; |
| 502 } | 517 } |
| 503 const typename Token::Attribute* nameAttribute = token.getAttributeI
tem(nameAttr); | 518 const typename Token::Attribute* nameAttribute = token.getAttributeI
tem(nameAttr); |
| 504 if (nameAttribute && equalIgnoringCase(String(nameAttribute->value),
"viewport")) { | 519 if (nameAttribute && equalIgnoringCase(String(nameAttribute->value),
"viewport")) { |
| 505 const typename Token::Attribute* contentAttribute = token.getAtt
ributeItem(contentAttr); | 520 const typename Token::Attribute* contentAttribute = token.getAtt
ributeItem(contentAttr); |
| 506 | 521 if (contentAttribute) |
| 507 if (contentAttribute) { | 522 handleMetaViewport(String(contentAttribute->value), m_docume
ntParameters.get()); |
| 508 ViewportDescription description(ViewportDescription::Viewpor
tMeta); | 523 return; |
| 509 HTMLMetaElement::getViewportDescriptionFromContentAttribute(
String(contentAttribute->value), description, nullptr, m_documentParameters->vie
wportMetaZeroValuesQuirk); | |
| 510 FloatSize initialViewport(m_documentParameters->mediaValues-
>viewportHeight(), m_documentParameters->mediaValues->viewportWidth()); | |
| 511 PageScaleConstraints constraints = description.resolve(initi
alViewport, m_documentParameters->defaultViewportMinWidth); | |
| 512 MediaValuesCached* cachedMediaValues = static_cast<MediaValu
esCached*>(m_documentParameters->mediaValues.get()); | |
| 513 cachedMediaValues->setViewportHeight(constraints.layoutSize.
height()); | |
| 514 cachedMediaValues->setViewportWidth(constraints.layoutSize.w
idth()); | |
| 515 } | |
| 516 } | 524 } |
| 517 } | 525 } |
| 518 | 526 |
| 519 if (RuntimeEnabledFeatures::pictureEnabled() && (match(tagImpl, pictureT
ag))) { | 527 if (RuntimeEnabledFeatures::pictureEnabled() && (match(tagImpl, pictureT
ag))) { |
| 520 m_inPicture = true; | 528 m_inPicture = true; |
| 521 m_pictureSourceURL = String(); | 529 m_pictureSourceURL = String(); |
| 522 return; | 530 return; |
| 523 } | 531 } |
| 524 | 532 |
| 525 StartTagScanner scanner(tagImpl, m_documentParameters->mediaValues); | 533 StartTagScanner scanner(tagImpl, m_documentParameters->mediaValues); |
| 526 scanner.processAttributes(token.attributes()); | 534 scanner.processAttributes(token.attributes()); |
| 527 if (m_inPicture) | 535 if (m_inPicture) |
| 528 scanner.handlePictureSourceURL(m_pictureSourceURL); | 536 scanner.handlePictureSourceURL(m_pictureSourceURL); |
| 529 OwnPtr<PreloadRequest> request = scanner.createPreloadRequest(m_predicte
dBaseElementURL, source); | 537 OwnPtr<PreloadRequest> request = scanner.createPreloadRequest(m_predicte
dBaseElementURL, source, m_clientHintsPreferences); |
| 530 if (request) | 538 if (request) |
| 531 requests.append(request.release()); | 539 requests.append(request.release()); |
| 532 return; | 540 return; |
| 533 } | 541 } |
| 534 default: { | 542 default: { |
| 535 return; | 543 return; |
| 536 } | 544 } |
| 537 } | 545 } |
| 538 } | 546 } |
| 539 | 547 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 if (givenMediaValues) | 599 if (givenMediaValues) |
| 592 mediaValues = givenMediaValues; | 600 mediaValues = givenMediaValues; |
| 593 else | 601 else |
| 594 mediaValues = MediaValuesCached::create(*document); | 602 mediaValues = MediaValuesCached::create(*document); |
| 595 ASSERT(mediaValues->isSafeToSendToAnotherThread()); | 603 ASSERT(mediaValues->isSafeToSendToAnotherThread()); |
| 596 defaultViewportMinWidth = document->viewportDefaultMinWidth(); | 604 defaultViewportMinWidth = document->viewportDefaultMinWidth(); |
| 597 viewportMetaZeroValuesQuirk = document->settings() && document->settings()->
viewportMetaZeroValuesQuirk(); | 605 viewportMetaZeroValuesQuirk = document->settings() && document->settings()->
viewportMetaZeroValuesQuirk(); |
| 598 } | 606 } |
| 599 | 607 |
| 600 } | 608 } |
| OLD | NEW |