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

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

Issue 104943004: Have preloader handle crossorigin resources better. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Initialize m_allowCredentials in the constructor Created 7 years 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 } 91 }
92 92
93 class TokenPreloadScanner::StartTagScanner { 93 class TokenPreloadScanner::StartTagScanner {
94 public: 94 public:
95 StartTagScanner(const StringImpl* tagImpl, float deviceScaleFactor) 95 StartTagScanner(const StringImpl* tagImpl, float deviceScaleFactor)
96 : m_tagImpl(tagImpl) 96 : m_tagImpl(tagImpl)
97 , m_linkIsStyleSheet(false) 97 , m_linkIsStyleSheet(false)
98 , m_inputIsImage(false) 98 , m_inputIsImage(false)
99 , m_deviceScaleFactor(deviceScaleFactor) 99 , m_deviceScaleFactor(deviceScaleFactor)
100 , m_encounteredImgSrc(false) 100 , m_encounteredImgSrc(false)
101 , m_isCORSEnabled(false)
102 , m_allowCredentials(DoNotAllowStoredCredentials)
101 { 103 {
102 if (!match(m_tagImpl, imgTag) 104 if (!match(m_tagImpl, imgTag)
103 && !match(m_tagImpl, inputTag) 105 && !match(m_tagImpl, inputTag)
104 && !match(m_tagImpl, linkTag) 106 && !match(m_tagImpl, linkTag)
105 && !match(m_tagImpl, scriptTag)) 107 && !match(m_tagImpl, scriptTag))
106 m_tagImpl = 0; 108 m_tagImpl = 0;
107 } 109 }
108 110
109 enum URLReplacement { 111 enum URLReplacement {
110 AllowURLReplacement, 112 AllowURLReplacement,
(...skipping 21 matching lines...) Expand all
132 } 134 }
133 135
134 PassOwnPtr<PreloadRequest> createPreloadRequest(const KURL& predictedBaseURL , const SegmentedString& source) 136 PassOwnPtr<PreloadRequest> createPreloadRequest(const KURL& predictedBaseURL , const SegmentedString& source)
135 { 137 {
136 if (!shouldPreload()) 138 if (!shouldPreload())
137 return nullptr; 139 return nullptr;
138 140
139 TRACE_EVENT_INSTANT1("net", "PreloadRequest", "url", m_urlToLoad.ascii() ); 141 TRACE_EVENT_INSTANT1("net", "PreloadRequest", "url", m_urlToLoad.ascii() );
140 TextPosition position = TextPosition(source.currentLine(), source.curren tColumn()); 142 TextPosition position = TextPosition(source.currentLine(), source.curren tColumn());
141 OwnPtr<PreloadRequest> request = PreloadRequest::create(initiatorFor(m_t agImpl), position, m_urlToLoad, predictedBaseURL, resourceType(), m_mediaAttribu te); 143 OwnPtr<PreloadRequest> request = PreloadRequest::create(initiatorFor(m_t agImpl), position, m_urlToLoad, predictedBaseURL, resourceType(), m_mediaAttribu te);
142 request->setCrossOriginModeAllowsCookies(crossOriginModeAllowsCookies()) ; 144 if (isCORSEnabled())
145 request->setCrossOriginEnabled(allowCredentials());
143 request->setCharset(charset()); 146 request->setCharset(charset());
144 return request.release(); 147 return request.release();
145 } 148 }
146 149
147 private: 150 private:
148 template<typename NameType> 151 template<typename NameType>
149 void processAttribute(const NameType& attributeName, const String& attribute Value) 152 void processAttribute(const NameType& attributeName, const String& attribute Value)
150 { 153 {
151 if (match(attributeName, charsetAttr)) 154 if (match(attributeName, charsetAttr))
152 m_charset = attributeValue; 155 m_charset = attributeValue;
153 156
154 if (match(m_tagImpl, scriptTag)) { 157 if (match(m_tagImpl, scriptTag)) {
155 if (match(attributeName, srcAttr)) 158 if (match(attributeName, srcAttr))
156 setUrlToLoad(attributeValue, DisallowURLReplacement); 159 setUrlToLoad(attributeValue, DisallowURLReplacement);
157 else if (match(attributeName, crossoriginAttr) && !attributeValue.is Null()) 160 else if (match(attributeName, crossoriginAttr))
158 m_crossOriginMode = stripLeadingAndTrailingHTMLSpaces(attributeV alue); 161 setCrossOriginAllowed(attributeValue);
159 } else if (match(m_tagImpl, imgTag)) { 162 } else if (match(m_tagImpl, imgTag)) {
160 if (match(attributeName, srcAttr) && !m_encounteredImgSrc) { 163 if (match(attributeName, srcAttr) && !m_encounteredImgSrc) {
161 m_encounteredImgSrc = true; 164 m_encounteredImgSrc = true;
162 setUrlToLoad(bestFitSourceForImageAttributes(m_deviceScaleFactor , attributeValue, m_srcsetImageCandidate), AllowURLReplacement); 165 setUrlToLoad(bestFitSourceForImageAttributes(m_deviceScaleFactor , attributeValue, m_srcsetImageCandidate), AllowURLReplacement);
163 } else if (match(attributeName, crossoriginAttr) && !attributeValue. isNull()) { 166 } else if (match(attributeName, crossoriginAttr)) {
164 m_crossOriginMode = stripLeadingAndTrailingHTMLSpaces(attributeV alue); 167 setCrossOriginAllowed(attributeValue);
165 } else if (RuntimeEnabledFeatures::srcsetEnabled() 168 } else if (RuntimeEnabledFeatures::srcsetEnabled()
166 && match(attributeName, srcsetAttr) 169 && match(attributeName, srcsetAttr)
167 && m_srcsetImageCandidate.isEmpty()) { 170 && m_srcsetImageCandidate.isEmpty()) {
168 m_srcsetImageCandidate = bestFitSourceForSrcsetAttribute(m_devic eScaleFactor, attributeValue); 171 m_srcsetImageCandidate = bestFitSourceForSrcsetAttribute(m_devic eScaleFactor, attributeValue);
169 setUrlToLoad(bestFitSourceForImageAttributes(m_deviceScaleFactor , m_urlToLoad, m_srcsetImageCandidate), AllowURLReplacement); 172 setUrlToLoad(bestFitSourceForImageAttributes(m_deviceScaleFactor , m_urlToLoad, m_srcsetImageCandidate), AllowURLReplacement);
170 } 173 }
171 } else if (match(m_tagImpl, linkTag)) { 174 } else if (match(m_tagImpl, linkTag)) {
172 if (match(attributeName, hrefAttr)) 175 if (match(attributeName, hrefAttr))
173 setUrlToLoad(attributeValue, DisallowURLReplacement); 176 setUrlToLoad(attributeValue, DisallowURLReplacement);
174 else if (match(attributeName, relAttr)) 177 else if (match(attributeName, relAttr))
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 if (match(m_tagImpl, scriptTag)) 217 if (match(m_tagImpl, scriptTag))
215 return Resource::Script; 218 return Resource::Script;
216 if (match(m_tagImpl, imgTag) || (match(m_tagImpl, inputTag) && m_inputIs Image)) 219 if (match(m_tagImpl, imgTag) || (match(m_tagImpl, inputTag) && m_inputIs Image))
217 return Resource::Image; 220 return Resource::Image;
218 if (match(m_tagImpl, linkTag) && m_linkIsStyleSheet) 221 if (match(m_tagImpl, linkTag) && m_linkIsStyleSheet)
219 return Resource::CSSStyleSheet; 222 return Resource::CSSStyleSheet;
220 ASSERT_NOT_REACHED(); 223 ASSERT_NOT_REACHED();
221 return Resource::Raw; 224 return Resource::Raw;
222 } 225 }
223 226
224 bool shouldPreload() 227 bool shouldPreload() const
225 { 228 {
226 if (m_urlToLoad.isEmpty()) 229 if (m_urlToLoad.isEmpty())
227 return false; 230 return false;
228 if (match(m_tagImpl, linkTag) && !m_linkIsStyleSheet) 231 if (match(m_tagImpl, linkTag) && !m_linkIsStyleSheet)
229 return false; 232 return false;
230 if (match(m_tagImpl, inputTag) && !m_inputIsImage) 233 if (match(m_tagImpl, inputTag) && !m_inputIsImage)
231 return false; 234 return false;
232 return true; 235 return true;
233 } 236 }
234 237
235 bool crossOriginModeAllowsCookies() 238 bool isCORSEnabled() const
236 { 239 {
237 return m_crossOriginMode.isNull() || equalIgnoringCase(m_crossOriginMode , "use-credentials"); 240 return m_isCORSEnabled;
241 }
242
243 StoredCredentials allowCredentials() const
244 {
245 return m_allowCredentials;
246 }
247
248 void setCrossOriginAllowed(const String& corsSetting)
249 {
250 m_isCORSEnabled = true;
251 if (!corsSetting.isNull() && equalIgnoringCase(stripLeadingAndTrailingHT MLSpaces(corsSetting), "use-credentials"))
252 m_allowCredentials = AllowStoredCredentials;
253 else
254 m_allowCredentials = DoNotAllowStoredCredentials;
238 } 255 }
239 256
240 const StringImpl* m_tagImpl; 257 const StringImpl* m_tagImpl;
241 String m_urlToLoad; 258 String m_urlToLoad;
242 ImageCandidate m_srcsetImageCandidate; 259 ImageCandidate m_srcsetImageCandidate;
243 String m_charset; 260 String m_charset;
244 String m_crossOriginMode;
245 bool m_linkIsStyleSheet; 261 bool m_linkIsStyleSheet;
246 String m_mediaAttribute; 262 String m_mediaAttribute;
247 bool m_inputIsImage; 263 bool m_inputIsImage;
248 float m_deviceScaleFactor; 264 float m_deviceScaleFactor;
249 bool m_encounteredImgSrc; 265 bool m_encounteredImgSrc;
266 bool m_isCORSEnabled;
267 StoredCredentials m_allowCredentials;
250 }; 268 };
251 269
252 TokenPreloadScanner::TokenPreloadScanner(const KURL& documentURL, float deviceSc aleFactor) 270 TokenPreloadScanner::TokenPreloadScanner(const KURL& documentURL, float deviceSc aleFactor)
253 : m_documentURL(documentURL) 271 : m_documentURL(documentURL)
254 , m_inStyle(false) 272 , m_inStyle(false)
255 , m_deviceScaleFactor(deviceScaleFactor) 273 , m_deviceScaleFactor(deviceScaleFactor)
256 , m_templateCount(0) 274 , m_templateCount(0)
257 { 275 {
258 } 276 }
259 277
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 if (m_token.type() == HTMLToken::StartTag) 401 if (m_token.type() == HTMLToken::StartTag)
384 m_tokenizer->updateStateFor(AtomicString(m_token.name())); 402 m_tokenizer->updateStateFor(AtomicString(m_token.name()));
385 m_scanner.scan(m_token, m_source, requests); 403 m_scanner.scan(m_token, m_source, requests);
386 m_token.clear(); 404 m_token.clear();
387 } 405 }
388 406
389 preloader->takeAndPreload(requests); 407 preloader->takeAndPreload(requests);
390 } 408 }
391 409
392 } 410 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698