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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 if (match(m_tagImpl, sourceTag) && m_matchedMediaAttribute && pictureDat
a.sourceURL.isEmpty()) { | 166 if (match(m_tagImpl, sourceTag) && m_matchedMediaAttribute && pictureDat
a.sourceURL.isEmpty()) { |
167 pictureData.sourceURL = m_srcsetImageCandidate.toString(); | 167 pictureData.sourceURL = m_srcsetImageCandidate.toString(); |
168 pictureData.sourceSizeSet = m_sourceSizeSet; | 168 pictureData.sourceSizeSet = m_sourceSizeSet; |
169 pictureData.sourceSize = m_sourceSize; | 169 pictureData.sourceSize = m_sourceSize; |
170 pictureData.picked = true; | 170 pictureData.picked = true; |
171 } else if (match(m_tagImpl, imgTag) && !pictureData.sourceURL.isEmpty())
{ | 171 } else if (match(m_tagImpl, imgTag) && !pictureData.sourceURL.isEmpty())
{ |
172 setUrlToLoad(pictureData.sourceURL, AllowURLReplacement); | 172 setUrlToLoad(pictureData.sourceURL, AllowURLReplacement); |
173 } | 173 } |
174 } | 174 } |
175 | 175 |
176 PassOwnPtr<PreloadRequest> createPreloadRequest(const KURL& predictedBaseURL
, const SegmentedString& source, const ClientHintsPreferences& clientHintsPrefer
ences, const PictureData& pictureData) | 176 PassOwnPtr<PreloadRequest> createPreloadRequest(const KURL& predictedBaseURL
, const SegmentedString& source, const ClientHintsPreferences& clientHintsPrefer
ences, const PictureData& pictureData, const ReferrerPolicy referrerPolicy) |
177 { | 177 { |
178 PreloadRequest::RequestType requestType = PreloadRequest::RequestTypePre
load; | 178 PreloadRequest::RequestType requestType = PreloadRequest::RequestTypePre
load; |
179 if (shouldPreconnect()) | 179 if (shouldPreconnect()) |
180 requestType = PreloadRequest::RequestTypePreconnect; | 180 requestType = PreloadRequest::RequestTypePreconnect; |
181 else if (!shouldPreload() || !m_matchedMediaAttribute) | 181 else if (!shouldPreload() || !m_matchedMediaAttribute) |
182 return nullptr; | 182 return nullptr; |
183 | 183 |
184 TextPosition position = TextPosition(source.currentLine(), source.curren
tColumn()); | 184 TextPosition position = TextPosition(source.currentLine(), source.curren
tColumn()); |
185 FetchRequest::ResourceWidth resourceWidth; | 185 FetchRequest::ResourceWidth resourceWidth; |
186 float sourceSize = m_sourceSize; | 186 float sourceSize = m_sourceSize; |
187 bool sourceSizeSet = m_sourceSizeSet; | 187 bool sourceSizeSet = m_sourceSizeSet; |
188 if (pictureData.picked) { | 188 if (pictureData.picked) { |
189 sourceSizeSet = pictureData.sourceSizeSet; | 189 sourceSizeSet = pictureData.sourceSizeSet; |
190 sourceSize = pictureData.sourceSize; | 190 sourceSize = pictureData.sourceSize; |
191 } | 191 } |
192 if (sourceSizeSet) { | 192 if (sourceSizeSet) { |
193 resourceWidth.width = sourceSize; | 193 resourceWidth.width = sourceSize; |
194 resourceWidth.isSet = true; | 194 resourceWidth.isSet = true; |
195 } | 195 } |
196 | 196 |
197 OwnPtr<PreloadRequest> request = PreloadRequest::create(initiatorFor(m_t
agImpl), position, m_urlToLoad, predictedBaseURL, resourceType(), resourceWidth,
clientHintsPreferences, requestType); | 197 OwnPtr<PreloadRequest> request = PreloadRequest::create(initiatorFor(m_t
agImpl), position, m_urlToLoad, predictedBaseURL, resourceType(), referrerPolicy
, resourceWidth, clientHintsPreferences, requestType); |
198 if (isCORSEnabled()) | 198 if (isCORSEnabled()) |
199 request->setCrossOriginEnabled(allowStoredCredentials()); | 199 request->setCrossOriginEnabled(allowStoredCredentials()); |
200 request->setCharset(charset()); | 200 request->setCharset(charset()); |
201 request->setDefer(m_defer); | 201 request->setDefer(m_defer); |
202 return request.release(); | 202 return request.release(); |
203 } | 203 } |
204 | 204 |
205 private: | 205 private: |
206 template<typename NameType> | 206 template<typename NameType> |
207 void processScriptAttribute(const NameType& attributeName, const String& att
ributeValue) | 207 void processScriptAttribute(const NameType& attributeName, const String& att
ributeValue) |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 return; | 466 return; |
467 ViewportDescription description(ViewportDescription::ViewportMeta); | 467 ViewportDescription description(ViewportDescription::ViewportMeta); |
468 HTMLMetaElement::getViewportDescriptionFromContentAttribute(attributeValue,
description, nullptr, documentParameters->viewportMetaZeroValuesQuirk); | 468 HTMLMetaElement::getViewportDescriptionFromContentAttribute(attributeValue,
description, nullptr, documentParameters->viewportMetaZeroValuesQuirk); |
469 FloatSize initialViewport(documentParameters->mediaValues->viewportHeight(),
documentParameters->mediaValues->viewportWidth()); | 469 FloatSize initialViewport(documentParameters->mediaValues->viewportHeight(),
documentParameters->mediaValues->viewportWidth()); |
470 PageScaleConstraints constraints = description.resolve(initialViewport, docu
mentParameters->defaultViewportMinWidth); | 470 PageScaleConstraints constraints = description.resolve(initialViewport, docu
mentParameters->defaultViewportMinWidth); |
471 MediaValuesCached* cachedMediaValues = static_cast<MediaValuesCached*>(docum
entParameters->mediaValues.get()); | 471 MediaValuesCached* cachedMediaValues = static_cast<MediaValuesCached*>(docum
entParameters->mediaValues.get()); |
472 cachedMediaValues->setViewportHeight(constraints.layoutSize.height()); | 472 cachedMediaValues->setViewportHeight(constraints.layoutSize.height()); |
473 cachedMediaValues->setViewportWidth(constraints.layoutSize.width()); | 473 cachedMediaValues->setViewportWidth(constraints.layoutSize.width()); |
474 } | 474 } |
475 | 475 |
476 template<typename Token> | 476 static void handleMetaReferrer(const String& attributeValue, CachedDocumentParam
eters* documentParameters, CSSPreloadScanner* cssScanner) |
| 477 { |
| 478 if (attributeValue.isEmpty() || attributeValue.isNull() || !SecurityPolicy::
referrerPolicyFromString(attributeValue, &documentParameters->referrerPolicy)) { |
| 479 documentParameters->referrerPolicy = ReferrerPolicyDefault; |
| 480 } |
| 481 cssScanner->setReferrerPolicy(documentParameters->referrerPolicy); |
| 482 } |
| 483 |
| 484 template <typename Token> |
| 485 static void handleMetaNameAttribute(const Token& token, CachedDocumentParameters
* documentParameters, CSSPreloadScanner* cssScanner) |
| 486 { |
| 487 const typename Token::Attribute* nameAttribute = token.getAttributeItem(name
Attr); |
| 488 if (!nameAttribute) |
| 489 return; |
| 490 |
| 491 String nameAttributeValue(nameAttribute->value); |
| 492 const typename Token::Attribute* contentAttribute = token.getAttributeItem(c
ontentAttr); |
| 493 if (!contentAttribute) |
| 494 return; |
| 495 |
| 496 String contentAttributeValue(contentAttribute->value); |
| 497 if (equalIgnoringCase(nameAttributeValue, "viewport")) { |
| 498 handleMetaViewport(contentAttributeValue, documentParameters); |
| 499 return; |
| 500 } |
| 501 |
| 502 if (equalIgnoringCase(nameAttributeValue, "referrer")) { |
| 503 handleMetaReferrer(contentAttributeValue, documentParameters, cssScanner
); |
| 504 } |
| 505 } |
| 506 |
| 507 template <typename Token> |
477 void TokenPreloadScanner::scanCommon(const Token& token, const SegmentedString&
source, PreloadRequestStream& requests) | 508 void TokenPreloadScanner::scanCommon(const Token& token, const SegmentedString&
source, PreloadRequestStream& requests) |
478 { | 509 { |
479 if (!m_documentParameters->doHtmlPreloadScanning) | 510 if (!m_documentParameters->doHtmlPreloadScanning) |
480 return; | 511 return; |
481 | 512 |
482 // Disable preload for documents with AppCache. | 513 // Disable preload for documents with AppCache. |
483 if (m_isAppCacheEnabled) | 514 if (m_isAppCacheEnabled) |
484 return; | 515 return; |
485 | 516 |
486 // http://crbug.com/434230 Disable preload for documents with CSP <meta> tag
s | 517 // http://crbug.com/434230 Disable preload for documents with CSP <meta> tag
s |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 String equivAttributeValue(equivAttribute->value); | 571 String equivAttributeValue(equivAttribute->value); |
541 if (equalIgnoringCase(equivAttributeValue, "content-security-pol
icy")) { | 572 if (equalIgnoringCase(equivAttributeValue, "content-security-pol
icy")) { |
542 m_isCSPEnabled = true; | 573 m_isCSPEnabled = true; |
543 } else if (equalIgnoringCase(equivAttributeValue, "accept-ch"))
{ | 574 } else if (equalIgnoringCase(equivAttributeValue, "accept-ch"))
{ |
544 const typename Token::Attribute* contentAttribute = token.ge
tAttributeItem(contentAttr); | 575 const typename Token::Attribute* contentAttribute = token.ge
tAttributeItem(contentAttr); |
545 if (contentAttribute) | 576 if (contentAttribute) |
546 handleAcceptClientHintsHeader(String(contentAttribute->v
alue), m_clientHintsPreferences, nullptr); | 577 handleAcceptClientHintsHeader(String(contentAttribute->v
alue), m_clientHintsPreferences, nullptr); |
547 } | 578 } |
548 return; | 579 return; |
549 } | 580 } |
550 const typename Token::Attribute* nameAttribute = token.getAttributeI
tem(nameAttr); | 581 |
551 if (nameAttribute && equalIgnoringCase(String(nameAttribute->value),
"viewport")) { | 582 handleMetaNameAttribute(token, m_documentParameters.get(), &m_cssSca
nner); |
552 const typename Token::Attribute* contentAttribute = token.getAtt
ributeItem(contentAttr); | |
553 if (contentAttribute) | |
554 handleMetaViewport(String(contentAttribute->value), m_docume
ntParameters.get()); | |
555 return; | |
556 } | |
557 } | 583 } |
558 | 584 |
559 if (match(tagImpl, pictureTag)) { | 585 if (match(tagImpl, pictureTag)) { |
560 m_inPicture = true; | 586 m_inPicture = true; |
561 m_pictureData = PictureData(); | 587 m_pictureData = PictureData(); |
562 return; | 588 return; |
563 } | 589 } |
564 | 590 |
565 StartTagScanner scanner(tagImpl, m_documentParameters->mediaValues); | 591 StartTagScanner scanner(tagImpl, m_documentParameters->mediaValues); |
566 scanner.processAttributes(token.attributes()); | 592 scanner.processAttributes(token.attributes()); |
567 if (m_inPicture) | 593 if (m_inPicture) |
568 scanner.handlePictureSourceURL(m_pictureData); | 594 scanner.handlePictureSourceURL(m_pictureData); |
569 OwnPtr<PreloadRequest> request = scanner.createPreloadRequest(m_predicte
dBaseElementURL, source, m_clientHintsPreferences, m_pictureData); | 595 OwnPtr<PreloadRequest> request = scanner.createPreloadRequest(m_predicte
dBaseElementURL, source, m_clientHintsPreferences, m_pictureData, m_documentPara
meters->referrerPolicy); |
570 if (request) | 596 if (request) |
571 requests.append(request.release()); | 597 requests.append(request.release()); |
572 return; | 598 return; |
573 } | 599 } |
574 default: { | 600 default: { |
575 return; | 601 return; |
576 } | 602 } |
577 } | 603 } |
578 } | 604 } |
579 | 605 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 ASSERT(document); | 656 ASSERT(document); |
631 doHtmlPreloadScanning = !document->settings() || document->settings()->doHtm
lPreloadScanning(); | 657 doHtmlPreloadScanning = !document->settings() || document->settings()->doHtm
lPreloadScanning(); |
632 if (givenMediaValues) | 658 if (givenMediaValues) |
633 mediaValues = givenMediaValues; | 659 mediaValues = givenMediaValues; |
634 else | 660 else |
635 mediaValues = MediaValuesCached::create(*document); | 661 mediaValues = MediaValuesCached::create(*document); |
636 ASSERT(mediaValues->isSafeToSendToAnotherThread()); | 662 ASSERT(mediaValues->isSafeToSendToAnotherThread()); |
637 defaultViewportMinWidth = document->viewportDefaultMinWidth(); | 663 defaultViewportMinWidth = document->viewportDefaultMinWidth(); |
638 viewportMetaZeroValuesQuirk = document->settings() && document->settings()->
viewportMetaZeroValuesQuirk(); | 664 viewportMetaZeroValuesQuirk = document->settings() && document->settings()->
viewportMetaZeroValuesQuirk(); |
639 viewportMetaEnabled = document->settings() && document->settings()->viewport
MetaEnabled(); | 665 viewportMetaEnabled = document->settings() && document->settings()->viewport
MetaEnabled(); |
| 666 referrerPolicy = ReferrerPolicyDefault; |
640 } | 667 } |
641 | 668 |
642 } | 669 } |
OLD | NEW |