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

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

Issue 2099853002: 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, 6 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 m_element->dispatchEvent(Event::create(EventTypeNames::error)); 156 m_element->dispatchEvent(Event::create(EventTypeNames::error));
157 } 157 }
158 158
159 void ScriptLoader::dispatchLoadEvent() 159 void ScriptLoader::dispatchLoadEvent()
160 { 160 {
161 if (ScriptLoaderClient* client = this->client()) 161 if (ScriptLoaderClient* client = this->client())
162 client->dispatchLoadEvent(); 162 client->dispatchLoadEvent();
163 setHaveFiredLoadEvent(true); 163 setHaveFiredLoadEvent(true);
164 } 164 }
165 165
166 bool ScriptLoader::isScriptTypeSupported(LegacyTypeSupport supportLegacyTypes) c onst 166 // static
Yoav Weiss 2016/06/25 08:08:16 delete?
Charlie Harrison 2016/06/27 19:44:10 Done.
167 bool ScriptLoader::isValidScriptTypeAndLanguage(const String& type, const String & language, LegacyTypeSupport supportLegacyTypes)
167 { 168 {
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: 169 // FIXME: isLegacySupportedJavaScriptLanguage() is not valid HTML5. It is us ed here to maintain backwards compatibility with existing layout tests. The spec ific violations are:
169 // - Allowing type=javascript. type= should only support MIME types, such as text/javascript. 170 // - Allowing type=javascript. type= should only support MIME types, such as text/javascript.
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 // - 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
172 String type = client()->typeAttributeValue();
173 String language = client()->languageAttributeValue();
174 if (type.isEmpty() && language.isEmpty()) 173 if (type.isEmpty() && language.isEmpty())
Yoav Weiss 2016/06/25 08:08:16 nit: we can move the language.isEmpty() check to t
Charlie Harrison 2016/06/27 19:44:10 Done.
175 return true; // Assume text/javascript. 174 return true; // Assume text/javascript.
176 if (type.isEmpty()) { 175 if (type.isEmpty()) {
177 type = "text/" + language.lower(); 176 if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(type + language.lowe r()) || isLegacySupportedJavaScriptLanguage(language))
Yoav Weiss 2016/06/25 08:08:16 why "type + " here if type is empty? Did you mean
Charlie Harrison 2016/06/27 19:44:10 Oops. Fixed.
178 if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(type) || isLegacySup portedJavaScriptLanguage(language))
179 return true; 177 return true;
180 } else if (RuntimeEnabledFeatures::moduleScriptsEnabled() && type == "module ") { 178 } else if (RuntimeEnabledFeatures::moduleScriptsEnabled() && type == "module ") {
181 return true; 179 return true;
182 } else if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(type.stripWhiteSp ace()) || (supportLegacyTypes == AllowLegacyTypeInTypeAttribute && isLegacySuppo rtedJavaScriptLanguage(type))) { 180 } else if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(type.stripWhiteSp ace()) || (supportLegacyTypes == AllowLegacyTypeInTypeAttribute && isLegacySuppo rtedJavaScriptLanguage(type))) {
183 return true; 181 return true;
184 } 182 }
185 183
186 return false; 184 return false;
187 } 185 }
188 186
187 bool ScriptLoader::isScriptTypeSupported(LegacyTypeSupport supportLegacyTypes) c onst
188 {
189 return isValidScriptTypeAndLanguage(client()->typeAttributeValue(), client() ->languageAttributeValue(), supportLegacyTypes);
190 }
191
189 // http://dev.w3.org/html5/spec/Overview.html#prepare-a-script 192 // http://dev.w3.org/html5/spec/Overview.html#prepare-a-script
190 bool ScriptLoader::prepareScript(const TextPosition& scriptStartPosition, Legacy TypeSupport supportLegacyTypes) 193 bool ScriptLoader::prepareScript(const TextPosition& scriptStartPosition, Legacy TypeSupport supportLegacyTypes)
191 { 194 {
192 if (m_alreadyStarted) 195 if (m_alreadyStarted)
193 return false; 196 return false;
194 197
195 ScriptLoaderClient* client = this->client(); 198 ScriptLoaderClient* client = this->client();
196 199
197 bool wasParserInserted; 200 bool wasParserInserted;
198 if (m_parserInserted) { 201 if (m_parserInserted) {
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 if (isHTMLScriptLoader(element)) 523 if (isHTMLScriptLoader(element))
521 return toHTMLScriptElement(element)->loader(); 524 return toHTMLScriptElement(element)->loader();
522 525
523 if (isSVGScriptLoader(element)) 526 if (isSVGScriptLoader(element))
524 return toSVGScriptElement(element)->loader(); 527 return toSVGScriptElement(element)->loader();
525 528
526 return 0; 529 return 0;
527 } 530 }
528 531
529 } // namespace blink 532 } // 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