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

Side by Side Diff: third_party/WebKit/Source/core/dom/ScriptLoader.cpp

Issue 2130773002: Revert of Don't preload scripts with invalid type/language attributes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserv ed. 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserv ed.
6 * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> 6 * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org>
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 } 114 }
115 115
116 void ScriptLoader::detach() 116 void ScriptLoader::detach()
117 { 117 {
118 if (!m_pendingScript) 118 if (!m_pendingScript)
119 return; 119 return;
120 m_pendingScript->dispose(); 120 m_pendingScript->dispose();
121 m_pendingScript = nullptr; 121 m_pendingScript = nullptr;
122 } 122 }
123 123
124 // Helper function. Must take a lowercase language as input. 124 // Helper function
125 static bool isLegacySupportedJavaScriptLanguage(const String& language) 125 static bool isLegacySupportedJavaScriptLanguage(const String& language)
126 { 126 {
127 // Mozilla 1.8 accepts javascript1.0 - javascript1.7, but WinIE 7 accepts on ly javascript1.1 - javascript1.3. 127 // Mozilla 1.8 accepts javascript1.0 - javascript1.7, but WinIE 7 accepts on ly javascript1.1 - javascript1.3.
128 // Mozilla 1.8 and WinIE 7 both accept javascript and livescript. 128 // Mozilla 1.8 and WinIE 7 both accept javascript and livescript.
129 // WinIE 7 accepts ecmascript and jscript, but Mozilla 1.8 doesn't. 129 // WinIE 7 accepts ecmascript and jscript, but Mozilla 1.8 doesn't.
130 // Neither Mozilla 1.8 nor WinIE 7 accept leading or trailing whitespace. 130 // Neither Mozilla 1.8 nor WinIE 7 accept leading or trailing whitespace.
131 // We want to accept all the values that either of these browsers accept, bu t not other values. 131 // We want to accept all the values that either of these browsers accept, bu t not other values.
132 132
133 // FIXME: This function is not HTML5 compliant. These belong in the MIME reg istry as "text/javascript<version>" entries. 133 // FIXME: This function is not HTML5 compliant. These belong in the MIME reg istry as "text/javascript<version>" entries.
134 DCHECK_EQ(language, language.lower()); 134 typedef HashSet<String, CaseFoldingHash> LanguageSet;
135 return language == "javascript" 135 DEFINE_STATIC_LOCAL(LanguageSet, languages, ());
136 || language == "javascript1.0" 136 if (languages.isEmpty()) {
137 || language == "javascript1.1" 137 languages.add("javascript");
138 || language == "javascript1.2" 138 languages.add("javascript1.0");
139 || language == "javascript1.3" 139 languages.add("javascript1.1");
140 || language == "javascript1.4" 140 languages.add("javascript1.2");
141 || language == "javascript1.5" 141 languages.add("javascript1.3");
142 || language == "javascript1.6" 142 languages.add("javascript1.4");
143 || language == "javascript1.7" 143 languages.add("javascript1.5");
144 || language == "livescript" 144 languages.add("javascript1.6");
145 || language == "ecmascript" 145 languages.add("javascript1.7");
146 || language == "jscript"; 146 languages.add("livescript");
147 languages.add("ecmascript");
148 languages.add("jscript");
149 }
150
151 return languages.contains(language);
147 } 152 }
148 153
149 void ScriptLoader::dispatchErrorEvent() 154 void ScriptLoader::dispatchErrorEvent()
150 { 155 {
151 m_element->dispatchEvent(Event::create(EventTypeNames::error)); 156 m_element->dispatchEvent(Event::create(EventTypeNames::error));
152 } 157 }
153 158
154 void ScriptLoader::dispatchLoadEvent() 159 void ScriptLoader::dispatchLoadEvent()
155 { 160 {
156 if (ScriptLoaderClient* client = this->client()) 161 if (ScriptLoaderClient* client = this->client())
157 client->dispatchLoadEvent(); 162 client->dispatchLoadEvent();
158 setHaveFiredLoadEvent(true); 163 setHaveFiredLoadEvent(true);
159 } 164 }
160 165
161 bool ScriptLoader::isValidScriptTypeAndLanguage(const String& type, const String & language, LegacyTypeSupport supportLegacyTypes) 166 bool ScriptLoader::isScriptTypeSupported(LegacyTypeSupport supportLegacyTypes) c onst
162 { 167 {
163 // FIXME: isLegacySupportedJavaScriptLanguage() is not valid HTML5. It is us ed here to maintain backwards compatibility with existing layout tests. The spec ific violations are: 168 // FIXME: isLegacySupportedJavaScriptLanguage() is not valid HTML5. It is us ed here to maintain backwards compatibility with existing layout tests. The spec ific violations are:
164 // - Allowing type=javascript. type= should only support MIME types, such as text/javascript. 169 // - Allowing type=javascript. type= should only support MIME types, such as text/javascript.
165 // - Allowing a different set of languages for language= and type=. language = supports Javascript 1.1 and 1.4-1.6, but type= does not. 170 // - Allowing a different set of languages for language= and type=. language = supports Javascript 1.1 and 1.4-1.6, but type= does not.
171
172 String type = client()->typeAttributeValue();
173 String language = client()->languageAttributeValue();
174 if (type.isEmpty() && language.isEmpty())
175 return true; // Assume text/javascript.
166 if (type.isEmpty()) { 176 if (type.isEmpty()) {
167 String lowerLanguage = language.lower(); 177 type = "text/" + language.lower();
168 return language.isEmpty() // assume text/javascript. 178 if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(type) || isLegacySup portedJavaScriptLanguage(language))
169 || MIMETypeRegistry::isSupportedJavaScriptMIMEType("text/" + lowerLa nguage) 179 return true;
170 || isLegacySupportedJavaScriptLanguage(lowerLanguage);
171 } else if (RuntimeEnabledFeatures::moduleScriptsEnabled() && type == "module ") { 180 } else if (RuntimeEnabledFeatures::moduleScriptsEnabled() && type == "module ") {
172 return true; 181 return true;
173 } else if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(type.stripWhiteSp ace()) || (supportLegacyTypes == AllowLegacyTypeInTypeAttribute && isLegacySuppo rtedJavaScriptLanguage(type.lower()))) { 182 } else if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(type.stripWhiteSp ace()) || (supportLegacyTypes == AllowLegacyTypeInTypeAttribute && isLegacySuppo rtedJavaScriptLanguage(type))) {
174 return true; 183 return true;
175 } 184 }
176 185
177 return false; 186 return false;
178 } 187 }
179 188
180 bool ScriptLoader::isScriptTypeSupported(LegacyTypeSupport supportLegacyTypes) c onst
181 {
182 return isValidScriptTypeAndLanguage(client()->typeAttributeValue(), client() ->languageAttributeValue(), supportLegacyTypes);
183 }
184
185 // http://dev.w3.org/html5/spec/Overview.html#prepare-a-script 189 // http://dev.w3.org/html5/spec/Overview.html#prepare-a-script
186 bool ScriptLoader::prepareScript(const TextPosition& scriptStartPosition, Legacy TypeSupport supportLegacyTypes) 190 bool ScriptLoader::prepareScript(const TextPosition& scriptStartPosition, Legacy TypeSupport supportLegacyTypes)
187 { 191 {
188 if (m_alreadyStarted) 192 if (m_alreadyStarted)
189 return false; 193 return false;
190 194
191 ScriptLoaderClient* client = this->client(); 195 ScriptLoaderClient* client = this->client();
192 196
193 bool wasParserInserted; 197 bool wasParserInserted;
194 if (m_parserInserted) { 198 if (m_parserInserted) {
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 } 337 }
334 338
335 bool isSVGScriptLoader(Element* element) 339 bool isSVGScriptLoader(Element* element)
336 { 340 {
337 DCHECK(element); 341 DCHECK(element);
338 return isSVGScriptElement(*element); 342 return isSVGScriptElement(*element);
339 } 343 }
340 344
341 void ScriptLoader::logScriptMimetype(ScriptResource* resource, LocalFrame* frame , String mimetype) 345 void ScriptLoader::logScriptMimetype(ScriptResource* resource, LocalFrame* frame , String mimetype)
342 { 346 {
343 String lowerMimetype = mimetype.lower(); 347 bool text = mimetype.lower().startsWith("text/");
344 bool text = lowerMimetype.startsWith("text/"); 348 bool application = mimetype.lower().startsWith("application/");
345 bool application = lowerMimetype.startsWith("application/"); 349 bool expectedJs = MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimetype) || (text && isLegacySupportedJavaScriptLanguage(mimetype.substring(5)));
346 bool expectedJs = MIMETypeRegistry::isSupportedJavaScriptMIMEType(lowerMimet ype) || (text && isLegacySupportedJavaScriptLanguage(lowerMimetype.substring(5)) );
347 bool sameOrigin = m_element->document().getSecurityOrigin()->canRequest(m_re source->url()); 350 bool sameOrigin = m_element->document().getSecurityOrigin()->canRequest(m_re source->url());
348 if (expectedJs) { 351 if (expectedJs) {
349 return; 352 return;
350 } 353 }
351 UseCounter::Feature feature = sameOrigin ? (text ? UseCounter::SameOriginTex tScript : application ? UseCounter::SameOriginApplicationScript : UseCounter::Sa meOriginOtherScript) : (text ? UseCounter::CrossOriginTextScript : application ? UseCounter::CrossOriginApplicationScript : UseCounter::CrossOriginOtherScript); 354 UseCounter::Feature feature = sameOrigin ? (text ? UseCounter::SameOriginTex tScript : application ? UseCounter::SameOriginApplicationScript : UseCounter::Sa meOriginOtherScript) : (text ? UseCounter::CrossOriginTextScript : application ? UseCounter::CrossOriginApplicationScript : UseCounter::CrossOriginOtherScript);
352 UseCounter::count(frame, feature); 355 UseCounter::count(frame, feature);
353 } 356 }
354 357
355 bool ScriptLoader::executeScript(const ScriptSourceCode& sourceCode, double* com pilationFinishTime) 358 bool ScriptLoader::executeScript(const ScriptSourceCode& sourceCode, double* com pilationFinishTime)
356 { 359 {
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 if (isHTMLScriptLoader(element)) 520 if (isHTMLScriptLoader(element))
518 return toHTMLScriptElement(element)->loader(); 521 return toHTMLScriptElement(element)->loader();
519 522
520 if (isSVGScriptLoader(element)) 523 if (isSVGScriptLoader(element))
521 return toSVGScriptElement(element)->loader(); 524 return toSVGScriptElement(element)->loader();
522 525
523 return 0; 526 return 0;
524 } 527 }
525 528
526 } // namespace blink 529 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/ScriptLoader.h ('k') | third_party/WebKit/Source/core/html/parser/HTMLPreloadScanner.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698