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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 , m_linkIsPreconnect(false) | 116 , m_linkIsPreconnect(false) |
117 , m_linkIsImport(false) | 117 , m_linkIsImport(false) |
118 , m_matchedMediaAttribute(true) | 118 , m_matchedMediaAttribute(true) |
119 , m_inputIsImage(false) | 119 , m_inputIsImage(false) |
120 , m_sourceSize(0) | 120 , m_sourceSize(0) |
121 , m_sourceSizeSet(false) | 121 , m_sourceSizeSet(false) |
122 , m_isCORSEnabled(false) | 122 , m_isCORSEnabled(false) |
123 , m_defer(FetchRequest::NoDefer) | 123 , m_defer(FetchRequest::NoDefer) |
124 , m_allowCredentials(DoNotAllowStoredCredentials) | 124 , m_allowCredentials(DoNotAllowStoredCredentials) |
125 , m_mediaValues(mediaValues) | 125 , m_mediaValues(mediaValues) |
| 126 , m_referrerPolicySet(false) |
| 127 , m_referrerPolicy(ReferrerPolicyDefault) |
126 { | 128 { |
127 ASSERT(m_mediaValues->isCached()); | 129 ASSERT(m_mediaValues->isCached()); |
128 if (match(m_tagImpl, imgTag) | 130 if (match(m_tagImpl, imgTag) |
129 || match(m_tagImpl, sourceTag)) { | 131 || match(m_tagImpl, sourceTag)) { |
130 m_sourceSize = SizesAttributeParser(m_mediaValues, String()).length(
); | 132 m_sourceSize = SizesAttributeParser(m_mediaValues, String()).length(
); |
131 return; | 133 return; |
132 } | 134 } |
133 if ( !match(m_tagImpl, inputTag) | 135 if ( !match(m_tagImpl, inputTag) |
134 && !match(m_tagImpl, linkTag) | 136 && !match(m_tagImpl, linkTag) |
135 && !match(m_tagImpl, scriptTag) | 137 && !match(m_tagImpl, scriptTag) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 if (match(m_tagImpl, sourceTag) && m_matchedMediaAttribute && pictureDat
a.sourceURL.isEmpty()) { | 169 if (match(m_tagImpl, sourceTag) && m_matchedMediaAttribute && pictureDat
a.sourceURL.isEmpty()) { |
168 pictureData.sourceURL = m_srcsetImageCandidate.toString(); | 170 pictureData.sourceURL = m_srcsetImageCandidate.toString(); |
169 pictureData.sourceSizeSet = m_sourceSizeSet; | 171 pictureData.sourceSizeSet = m_sourceSizeSet; |
170 pictureData.sourceSize = m_sourceSize; | 172 pictureData.sourceSize = m_sourceSize; |
171 pictureData.picked = true; | 173 pictureData.picked = true; |
172 } else if (match(m_tagImpl, imgTag) && !pictureData.sourceURL.isEmpty())
{ | 174 } else if (match(m_tagImpl, imgTag) && !pictureData.sourceURL.isEmpty())
{ |
173 setUrlToLoad(pictureData.sourceURL, AllowURLReplacement); | 175 setUrlToLoad(pictureData.sourceURL, AllowURLReplacement); |
174 } | 176 } |
175 } | 177 } |
176 | 178 |
177 PassOwnPtr<PreloadRequest> createPreloadRequest(const KURL& predictedBaseURL
, const SegmentedString& source, const ClientHintsPreferences& clientHintsPrefer
ences, const PictureData& pictureData, const ReferrerPolicy referrerPolicy) | 179 PassOwnPtr<PreloadRequest> createPreloadRequest(const KURL& predictedBaseURL
, const SegmentedString& source, const ClientHintsPreferences& clientHintsPrefer
ences, const PictureData& pictureData, const ReferrerPolicy documentReferrerPoli
cy) |
178 { | 180 { |
179 PreloadRequest::RequestType requestType = PreloadRequest::RequestTypePre
load; | 181 PreloadRequest::RequestType requestType = PreloadRequest::RequestTypePre
load; |
180 if (shouldPreconnect()) | 182 if (shouldPreconnect()) |
181 requestType = PreloadRequest::RequestTypePreconnect; | 183 requestType = PreloadRequest::RequestTypePreconnect; |
182 else if (!shouldPreload() || !m_matchedMediaAttribute) | 184 else if (!shouldPreload() || !m_matchedMediaAttribute) |
183 return nullptr; | 185 return nullptr; |
184 | 186 |
185 TextPosition position = TextPosition(source.currentLine(), source.curren
tColumn()); | 187 TextPosition position = TextPosition(source.currentLine(), source.curren
tColumn()); |
186 FetchRequest::ResourceWidth resourceWidth; | 188 FetchRequest::ResourceWidth resourceWidth; |
187 float sourceSize = m_sourceSize; | 189 float sourceSize = m_sourceSize; |
188 bool sourceSizeSet = m_sourceSizeSet; | 190 bool sourceSizeSet = m_sourceSizeSet; |
189 if (pictureData.picked) { | 191 if (pictureData.picked) { |
190 sourceSizeSet = pictureData.sourceSizeSet; | 192 sourceSizeSet = pictureData.sourceSizeSet; |
191 sourceSize = pictureData.sourceSize; | 193 sourceSize = pictureData.sourceSize; |
192 } | 194 } |
193 if (sourceSizeSet) { | 195 if (sourceSizeSet) { |
194 resourceWidth.width = sourceSize; | 196 resourceWidth.width = sourceSize; |
195 resourceWidth.isSet = true; | 197 resourceWidth.isSet = true; |
196 } | 198 } |
197 | 199 |
| 200 // The element's 'referrerpolicy' attribute (if present) takes precedenc
e over the document's referrer policy. |
| 201 ReferrerPolicy referrerPolicy = m_referrerPolicy != ReferrerPolicyDefaul
t ? m_referrerPolicy : documentReferrerPolicy; |
198 OwnPtr<PreloadRequest> request = PreloadRequest::create(initiatorFor(m_t
agImpl), position, m_urlToLoad, predictedBaseURL, resourceType(), referrerPolicy
, resourceWidth, clientHintsPreferences, requestType); | 202 OwnPtr<PreloadRequest> request = PreloadRequest::create(initiatorFor(m_t
agImpl), position, m_urlToLoad, predictedBaseURL, resourceType(), referrerPolicy
, resourceWidth, clientHintsPreferences, requestType); |
199 if (isCORSEnabled()) | 203 if (isCORSEnabled()) |
200 request->setCrossOriginEnabled(allowStoredCredentials()); | 204 request->setCrossOriginEnabled(allowStoredCredentials()); |
201 request->setCharset(charset()); | 205 request->setCharset(charset()); |
202 request->setDefer(m_defer); | 206 request->setDefer(m_defer); |
203 return request.release(); | 207 return request.release(); |
204 } | 208 } |
205 | 209 |
206 private: | 210 private: |
207 template<typename NameType> | 211 template<typename NameType> |
(...skipping 22 matching lines...) Expand all Loading... |
230 m_srcsetAttributeValue = attributeValue; | 234 m_srcsetAttributeValue = attributeValue; |
231 m_srcsetImageCandidate = bestFitSourceForSrcsetAttribute(m_mediaValu
es->devicePixelRatio(), m_sourceSize, attributeValue); | 235 m_srcsetImageCandidate = bestFitSourceForSrcsetAttribute(m_mediaValu
es->devicePixelRatio(), m_sourceSize, attributeValue); |
232 setUrlToLoad(bestFitSourceForImageAttributes(m_mediaValues->devicePi
xelRatio(), m_sourceSize, m_imgSrcUrl, m_srcsetImageCandidate), AllowURLReplacem
ent); | 236 setUrlToLoad(bestFitSourceForImageAttributes(m_mediaValues->devicePi
xelRatio(), m_sourceSize, m_imgSrcUrl, m_srcsetImageCandidate), AllowURLReplacem
ent); |
233 } else if (match(attributeName, sizesAttr) && !m_sourceSizeSet) { | 237 } else if (match(attributeName, sizesAttr) && !m_sourceSizeSet) { |
234 m_sourceSize = SizesAttributeParser(m_mediaValues, attributeValue).l
ength(); | 238 m_sourceSize = SizesAttributeParser(m_mediaValues, attributeValue).l
ength(); |
235 m_sourceSizeSet = true; | 239 m_sourceSizeSet = true; |
236 if (!m_srcsetImageCandidate.isEmpty()) { | 240 if (!m_srcsetImageCandidate.isEmpty()) { |
237 m_srcsetImageCandidate = bestFitSourceForSrcsetAttribute(m_media
Values->devicePixelRatio(), m_sourceSize, m_srcsetAttributeValue); | 241 m_srcsetImageCandidate = bestFitSourceForSrcsetAttribute(m_media
Values->devicePixelRatio(), m_sourceSize, m_srcsetAttributeValue); |
238 setUrlToLoad(bestFitSourceForImageAttributes(m_mediaValues->devi
cePixelRatio(), m_sourceSize, m_imgSrcUrl, m_srcsetImageCandidate), AllowURLRepl
acement); | 242 setUrlToLoad(bestFitSourceForImageAttributes(m_mediaValues->devi
cePixelRatio(), m_sourceSize, m_imgSrcUrl, m_srcsetImageCandidate), AllowURLRepl
acement); |
239 } | 243 } |
| 244 } else if (!m_referrerPolicySet && match(attributeName, referrerpolicyAt
tr) && !attributeValue.isNull()) { |
| 245 m_referrerPolicySet = true; |
| 246 SecurityPolicy::referrerPolicyFromString(attributeValue, &m_referrer
Policy); |
240 } | 247 } |
241 } | 248 } |
242 | 249 |
243 template<typename NameType> | 250 template<typename NameType> |
244 void processLinkAttribute(const NameType& attributeName, const String& attri
buteValue) | 251 void processLinkAttribute(const NameType& attributeName, const String& attri
buteValue) |
245 { | 252 { |
246 // FIXME - Don't set rel/media/crossorigin multiple times. | 253 // FIXME - Don't set rel/media/crossorigin multiple times. |
247 if (match(attributeName, hrefAttr)) { | 254 if (match(attributeName, hrefAttr)) { |
248 setUrlToLoad(attributeValue, DisallowURLReplacement); | 255 setUrlToLoad(attributeValue, DisallowURLReplacement); |
249 } else if (match(attributeName, relAttr)) { | 256 } else if (match(attributeName, relAttr)) { |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 bool m_matchedMediaAttribute; | 411 bool m_matchedMediaAttribute; |
405 bool m_inputIsImage; | 412 bool m_inputIsImage; |
406 String m_imgSrcUrl; | 413 String m_imgSrcUrl; |
407 String m_srcsetAttributeValue; | 414 String m_srcsetAttributeValue; |
408 float m_sourceSize; | 415 float m_sourceSize; |
409 bool m_sourceSizeSet; | 416 bool m_sourceSizeSet; |
410 bool m_isCORSEnabled; | 417 bool m_isCORSEnabled; |
411 FetchRequest::DeferOption m_defer; | 418 FetchRequest::DeferOption m_defer; |
412 StoredCredentials m_allowCredentials; | 419 StoredCredentials m_allowCredentials; |
413 RefPtrWillBeMember<MediaValues> m_mediaValues; | 420 RefPtrWillBeMember<MediaValues> m_mediaValues; |
| 421 bool m_referrerPolicySet; |
| 422 ReferrerPolicy m_referrerPolicy; |
414 }; | 423 }; |
415 | 424 |
416 TokenPreloadScanner::TokenPreloadScanner(const KURL& documentURL, PassOwnPtr<Cac
hedDocumentParameters> documentParameters) | 425 TokenPreloadScanner::TokenPreloadScanner(const KURL& documentURL, PassOwnPtr<Cac
hedDocumentParameters> documentParameters) |
417 : m_documentURL(documentURL) | 426 : m_documentURL(documentURL) |
418 , m_inStyle(false) | 427 , m_inStyle(false) |
419 , m_inPicture(false) | 428 , m_inPicture(false) |
420 , m_isAppCacheEnabled(false) | 429 , m_isAppCacheEnabled(false) |
421 , m_isCSPEnabled(false) | 430 , m_isCSPEnabled(false) |
422 , m_templateCount(0) | 431 , m_templateCount(0) |
423 , m_documentParameters(documentParameters) | 432 , m_documentParameters(documentParameters) |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 else | 670 else |
662 mediaValues = MediaValuesCached::create(*document); | 671 mediaValues = MediaValuesCached::create(*document); |
663 ASSERT(mediaValues->isSafeToSendToAnotherThread()); | 672 ASSERT(mediaValues->isSafeToSendToAnotherThread()); |
664 defaultViewportMinWidth = document->viewportDefaultMinWidth(); | 673 defaultViewportMinWidth = document->viewportDefaultMinWidth(); |
665 viewportMetaZeroValuesQuirk = document->settings() && document->settings()->
viewportMetaZeroValuesQuirk(); | 674 viewportMetaZeroValuesQuirk = document->settings() && document->settings()->
viewportMetaZeroValuesQuirk(); |
666 viewportMetaEnabled = document->settings() && document->settings()->viewport
MetaEnabled(); | 675 viewportMetaEnabled = document->settings() && document->settings()->viewport
MetaEnabled(); |
667 referrerPolicy = ReferrerPolicyDefault; | 676 referrerPolicy = ReferrerPolicyDefault; |
668 } | 677 } |
669 | 678 |
670 } | 679 } |
OLD | NEW |