Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: third_party/WebKit/Source/core/html/parser/HTMLPreloadScanner.cpp

Issue 2301323003: Add deprecation warning for script fetches with invalid types (Closed)
Patch Set: Update deprecation message with chromestatus entry Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 16 matching lines...) Expand all
27 27
28 #include "core/html/parser/HTMLPreloadScanner.h" 28 #include "core/html/parser/HTMLPreloadScanner.h"
29 29
30 #include "core/HTMLNames.h" 30 #include "core/HTMLNames.h"
31 #include "core/InputTypeNames.h" 31 #include "core/InputTypeNames.h"
32 #include "core/css/MediaList.h" 32 #include "core/css/MediaList.h"
33 #include "core/css/MediaQueryEvaluator.h" 33 #include "core/css/MediaQueryEvaluator.h"
34 #include "core/css/MediaValuesCached.h" 34 #include "core/css/MediaValuesCached.h"
35 #include "core/css/parser/SizesAttributeParser.h" 35 #include "core/css/parser/SizesAttributeParser.h"
36 #include "core/dom/Document.h" 36 #include "core/dom/Document.h"
37 #include "core/dom/ScriptLoader.h"
37 #include "core/fetch/IntegrityMetadata.h" 38 #include "core/fetch/IntegrityMetadata.h"
38 #include "core/frame/LocalFrame.h" 39 #include "core/frame/LocalFrame.h"
39 #include "core/frame/Settings.h" 40 #include "core/frame/Settings.h"
40 #include "core/frame/SubresourceIntegrity.h" 41 #include "core/frame/SubresourceIntegrity.h"
41 #include "core/html/CrossOriginAttribute.h" 42 #include "core/html/CrossOriginAttribute.h"
42 #include "core/html/HTMLImageElement.h" 43 #include "core/html/HTMLImageElement.h"
43 #include "core/html/HTMLMetaElement.h" 44 #include "core/html/HTMLMetaElement.h"
44 #include "core/html/LinkRelAttribute.h" 45 #include "core/html/LinkRelAttribute.h"
45 #include "core/html/parser/HTMLParserIdioms.h" 46 #include "core/html/parser/HTMLParserIdioms.h"
46 #include "core/html/parser/HTMLSrcsetParser.h" 47 #include "core/html/parser/HTMLSrcsetParser.h"
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 requestType = PreloadRequest::RequestTypePreconnect; 216 requestType = PreloadRequest::RequestTypePreconnect;
216 } else { 217 } else {
217 if (isLinkRelPreload()) { 218 if (isLinkRelPreload()) {
218 requestType = PreloadRequest::RequestTypeLinkRelPreload; 219 requestType = PreloadRequest::RequestTypeLinkRelPreload;
219 } 220 }
220 if (!shouldPreload()) { 221 if (!shouldPreload()) {
221 return nullptr; 222 return nullptr;
222 } 223 }
223 } 224 }
224 225
225
226 TextPosition position = TextPosition(source.currentLine(), source.curren tColumn()); 226 TextPosition position = TextPosition(source.currentLine(), source.curren tColumn());
227 FetchRequest::ResourceWidth resourceWidth; 227 FetchRequest::ResourceWidth resourceWidth;
228 float sourceSize = m_sourceSize; 228 float sourceSize = m_sourceSize;
229 bool sourceSizeSet = m_sourceSizeSet; 229 bool sourceSizeSet = m_sourceSizeSet;
230 if (pictureData.picked) { 230 if (pictureData.picked) {
231 sourceSizeSet = pictureData.sourceSizeSet; 231 sourceSizeSet = pictureData.sourceSizeSet;
232 sourceSize = pictureData.sourceSize; 232 sourceSize = pictureData.sourceSize;
233 } 233 }
234 if (sourceSizeSet) { 234 if (sourceSizeSet) {
235 resourceWidth.width = sourceSize; 235 resourceWidth.width = sourceSize;
236 resourceWidth.isSet = true; 236 resourceWidth.isSet = true;
237 } 237 }
238 238
239 Resource::Type type; 239 Resource::Type type;
240 if (!resourceType(type)) 240 if (!resourceType(type))
241 return nullptr; 241 return nullptr;
242 242
243 // The element's 'referrerpolicy' attribute (if present) takes precedenc e over the document's referrer policy. 243 // The element's 'referrerpolicy' attribute (if present) takes precedenc e over the document's referrer policy.
244 ReferrerPolicy referrerPolicy = (m_referrerPolicy != ReferrerPolicyDefau lt) ? m_referrerPolicy : documentReferrerPolicy; 244 ReferrerPolicy referrerPolicy = (m_referrerPolicy != ReferrerPolicyDefau lt) ? m_referrerPolicy : documentReferrerPolicy;
245 std::unique_ptr<PreloadRequest> request = PreloadRequest::create(initiat orFor(m_tagImpl), position, m_urlToLoad, predictedBaseURL, type, referrerPolicy, resourceWidth, clientHintsPreferences, requestType); 245 std::unique_ptr<PreloadRequest> request = PreloadRequest::create(initiat orFor(m_tagImpl), position, m_urlToLoad, predictedBaseURL, type, referrerPolicy, resourceWidth, clientHintsPreferences, requestType);
246 request->setCrossOrigin(m_crossOrigin); 246 request->setCrossOrigin(m_crossOrigin);
247 request->setNonce(m_nonce); 247 request->setNonce(m_nonce);
248 request->setCharset(charset()); 248 request->setCharset(charset());
249 request->setDefer(m_defer); 249 request->setDefer(m_defer);
250 request->setIntegrityMetadata(m_integrityMetadata); 250 request->setIntegrityMetadata(m_integrityMetadata);
251
252 // TODO(csharrison): Once this is deprecated, just abort the request
253 // here.
254 if (match(m_tagImpl, scriptTag) && !ScriptLoader::isValidScriptTypeAndLa nguage(m_typeAttributeValue, m_languageAttributeValue, ScriptLoader::AllowLegacy TypeInTypeAttribute))
255 request->setScriptHasInvalidTypeOrLanguage();
251 return request; 256 return request;
252 } 257 }
253 258
254 private: 259 private:
255 template<typename NameType> 260 template<typename NameType>
256 void processScriptAttribute(const NameType& attributeName, const String& att ributeValue) 261 void processScriptAttribute(const NameType& attributeName, const String& att ributeValue)
257 { 262 {
258 // FIXME - Don't set crossorigin multiple times. 263 // FIXME - Don't set crossorigin multiple times.
259 if (match(attributeName, srcAttr)) 264 if (match(attributeName, srcAttr))
260 setUrlToLoad(attributeValue, DisallowURLReplacement); 265 setUrlToLoad(attributeValue, DisallowURLReplacement);
261 else if (match(attributeName, crossoriginAttr)) 266 else if (match(attributeName, crossoriginAttr))
262 setCrossOrigin(attributeValue); 267 setCrossOrigin(attributeValue);
263 else if (match(attributeName, nonceAttr)) 268 else if (match(attributeName, nonceAttr))
264 setNonce(attributeValue); 269 setNonce(attributeValue);
265 else if (match(attributeName, asyncAttr)) 270 else if (match(attributeName, asyncAttr))
266 setDefer(FetchRequest::LazyLoad); 271 setDefer(FetchRequest::LazyLoad);
267 else if (match(attributeName, deferAttr)) 272 else if (match(attributeName, deferAttr))
268 setDefer(FetchRequest::LazyLoad); 273 setDefer(FetchRequest::LazyLoad);
269 // Note that only scripts need to have the integrity metadata set on 274 // Note that only scripts need to have the integrity metadata set on
270 // preloads. This is because script resources fetches, and only script 275 // preloads. This is because script resources fetches, and only script
271 // resource fetches, need to re-request resources if a cached version 276 // resource fetches, need to re-request resources if a cached version
272 // has different metadata (including empty) from the metadata on the 277 // has different metadata (including empty) from the metadata on the
273 // request. See the comment before the call to 278 // request. See the comment before the call to
274 // mustRefetchDueToIntegrityMismatch() in 279 // mustRefetchDueToIntegrityMismatch() in
275 // Source/core/fetch/ResourceFetcher.cpp for a more complete 280 // Source/core/fetch/ResourceFetcher.cpp for a more complete
276 // explanation. 281 // explanation.
277 else if (match(attributeName, integrityAttr)) 282 else if (match(attributeName, integrityAttr))
278 SubresourceIntegrity::parseIntegrityAttribute(attributeValue, m_inte grityMetadata); 283 SubresourceIntegrity::parseIntegrityAttribute(attributeValue, m_inte grityMetadata);
284 else if (match(attributeName, typeAttr))
285 m_typeAttributeValue = attributeValue;
286 else if (match(attributeName, languageAttr))
287 m_languageAttributeValue = attributeValue;
279 } 288 }
280 289
281 template<typename NameType> 290 template<typename NameType>
282 void processImgAttribute(const NameType& attributeName, const String& attrib uteValue) 291 void processImgAttribute(const NameType& attributeName, const String& attrib uteValue)
283 { 292 {
284 if (match(attributeName, srcAttr) && m_imgSrcUrl.isNull()) { 293 if (match(attributeName, srcAttr) && m_imgSrcUrl.isNull()) {
285 m_imgSrcUrl = attributeValue; 294 m_imgSrcUrl = attributeValue;
286 setUrlToLoad(bestFitSourceForImageAttributes(m_mediaValues->devicePi xelRatio(), m_sourceSize, attributeValue, m_srcsetImageCandidate), AllowURLRepla cement); 295 setUrlToLoad(bestFitSourceForImageAttributes(m_mediaValues->devicePi xelRatio(), m_sourceSize, attributeValue, m_srcsetImageCandidate), AllowURLRepla cement);
287 } else if (match(attributeName, crossoriginAttr)) { 296 } else if (match(attributeName, crossoriginAttr)) {
288 setCrossOrigin(attributeValue); 297 setCrossOrigin(attributeValue);
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 String m_charset; 484 String m_charset;
476 bool m_linkIsStyleSheet; 485 bool m_linkIsStyleSheet;
477 bool m_linkIsPreconnect; 486 bool m_linkIsPreconnect;
478 bool m_linkIsPreload; 487 bool m_linkIsPreload;
479 bool m_linkIsImport; 488 bool m_linkIsImport;
480 bool m_matched; 489 bool m_matched;
481 bool m_inputIsImage; 490 bool m_inputIsImage;
482 String m_imgSrcUrl; 491 String m_imgSrcUrl;
483 String m_srcsetAttributeValue; 492 String m_srcsetAttributeValue;
484 String m_asAttributeValue; 493 String m_asAttributeValue;
494 String m_typeAttributeValue;
495 String m_languageAttributeValue;
485 float m_sourceSize; 496 float m_sourceSize;
486 bool m_sourceSizeSet; 497 bool m_sourceSizeSet;
487 FetchRequest::DeferOption m_defer; 498 FetchRequest::DeferOption m_defer;
488 CrossOriginAttributeValue m_crossOrigin; 499 CrossOriginAttributeValue m_crossOrigin;
489 String m_nonce; 500 String m_nonce;
490 Member<MediaValuesCached> m_mediaValues; 501 Member<MediaValuesCached> m_mediaValues;
491 bool m_referrerPolicySet; 502 bool m_referrerPolicySet;
492 ReferrerPolicy m_referrerPolicy; 503 ReferrerPolicy m_referrerPolicy;
493 IntegrityMetadataSet m_integrityMetadata; 504 IntegrityMetadataSet m_integrityMetadata;
494 }; 505 };
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 ASSERT(document); 823 ASSERT(document);
813 doHtmlPreloadScanning = !document->settings() || document->settings()->doHtm lPreloadScanning(); 824 doHtmlPreloadScanning = !document->settings() || document->settings()->doHtm lPreloadScanning();
814 doDocumentWritePreloadScanning = doHtmlPreloadScanning && document->frame() && document->frame()->isMainFrame(); 825 doDocumentWritePreloadScanning = doHtmlPreloadScanning && document->frame() && document->frame()->isMainFrame();
815 defaultViewportMinWidth = document->viewportDefaultMinWidth(); 826 defaultViewportMinWidth = document->viewportDefaultMinWidth();
816 viewportMetaZeroValuesQuirk = document->settings() && document->settings()-> viewportMetaZeroValuesQuirk(); 827 viewportMetaZeroValuesQuirk = document->settings() && document->settings()-> viewportMetaZeroValuesQuirk();
817 viewportMetaEnabled = document->settings() && document->settings()->viewport MetaEnabled(); 828 viewportMetaEnabled = document->settings() && document->settings()->viewport MetaEnabled();
818 referrerPolicy = document->getReferrerPolicy(); 829 referrerPolicy = document->getReferrerPolicy();
819 } 830 }
820 831
821 } // namespace blink 832 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698