Chromium Code Reviews| Index: third_party/WebKit/Source/core/dom/ScriptLoader.cpp |
| diff --git a/third_party/WebKit/Source/core/dom/ScriptLoader.cpp b/third_party/WebKit/Source/core/dom/ScriptLoader.cpp |
| index ffebfa4db4587c37ef4d17ee35fcf30536cdca9c..7641d70e4884883eb08f0810c6e2c0485fe02f8e 100644 |
| --- a/third_party/WebKit/Source/core/dom/ScriptLoader.cpp |
| +++ b/third_party/WebKit/Source/core/dom/ScriptLoader.cpp |
| @@ -121,7 +121,7 @@ void ScriptLoader::detach() |
| m_pendingScript = nullptr; |
| } |
| -// Helper function |
| +// Helper function. Must take a lowercase language as input. |
| static bool isLegacySupportedJavaScriptLanguage(const String& language) |
| { |
| // Mozilla 1.8 accepts javascript1.0 - javascript1.7, but WinIE 7 accepts only javascript1.1 - javascript1.3. |
| @@ -131,23 +131,19 @@ static bool isLegacySupportedJavaScriptLanguage(const String& language) |
| // We want to accept all the values that either of these browsers accept, but not other values. |
| // FIXME: This function is not HTML5 compliant. These belong in the MIME registry as "text/javascript<version>" entries. |
| - typedef HashSet<String, CaseFoldingHash> LanguageSet; |
| - DEFINE_STATIC_LOCAL(LanguageSet, languages, ({ |
| - "javascript", |
| - "javascript1.0", |
| - "javascript1.1", |
| - "javascript1.2", |
| - "javascript1.3", |
| - "javascript1.4", |
| - "javascript1.5", |
| - "javascript1.6", |
| - "javascript1.7", |
| - "livescript", |
| - "ecmascript", |
| - "jscript", |
| - })); |
| - |
| - return languages.contains(language); |
| + DCHECK_EQ(language, language.lower()); |
|
Yoav Weiss
2016/09/05 15:06:25
Why the change here? I don't expect this function
Charlie Harrison
2016/09/05 17:15:06
I changed this so that the function could be calle
|
| + return language == "javascript" |
| + || language == "javascript1.0" |
| + || language == "javascript1.1" |
| + || language == "javascript1.2" |
| + || language == "javascript1.3" |
| + || language == "javascript1.4" |
| + || language == "javascript1.5" |
| + || language == "javascript1.6" |
| + || language == "javascript1.7" |
| + || language == "livescript" |
| + || language == "ecmascript" |
| + || language == "jscript"; |
| } |
| void ScriptLoader::dispatchErrorEvent() |
| @@ -162,29 +158,30 @@ void ScriptLoader::dispatchLoadEvent() |
| setHaveFiredLoadEvent(true); |
| } |
| -bool ScriptLoader::isScriptTypeSupported(LegacyTypeSupport supportLegacyTypes) const |
| +bool ScriptLoader::isValidScriptTypeAndLanguage(const String& type, const String& language, LegacyTypeSupport supportLegacyTypes) |
| { |
| // FIXME: isLegacySupportedJavaScriptLanguage() is not valid HTML5. It is used here to maintain backwards compatibility with existing layout tests. The specific violations are: |
| // - Allowing type=javascript. type= should only support MIME types, such as text/javascript. |
| // - Allowing a different set of languages for language= and type=. language= supports Javascript 1.1 and 1.4-1.6, but type= does not. |
| - |
| - String type = client()->typeAttributeValue(); |
| - String language = client()->languageAttributeValue(); |
| - if (type.isEmpty() && language.isEmpty()) |
| - return true; // Assume text/javascript. |
| if (type.isEmpty()) { |
| - type = "text/" + language.lower(); |
| - if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(type) || isLegacySupportedJavaScriptLanguage(language)) |
| - return true; |
| + String lowerLanguage = language.lower(); |
| + return language.isEmpty() // assume text/javascript. |
| + || MIMETypeRegistry::isSupportedJavaScriptMIMEType("text/" + lowerLanguage) |
| + || isLegacySupportedJavaScriptLanguage(lowerLanguage); |
| } else if (RuntimeEnabledFeatures::moduleScriptsEnabled() && type == "module") { |
| return true; |
| - } else if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(type.stripWhiteSpace()) || (supportLegacyTypes == AllowLegacyTypeInTypeAttribute && isLegacySupportedJavaScriptLanguage(type))) { |
| + } else if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(type.stripWhiteSpace()) || (supportLegacyTypes == AllowLegacyTypeInTypeAttribute && isLegacySupportedJavaScriptLanguage(type.lower()))) { |
| return true; |
| } |
| return false; |
| } |
| +bool ScriptLoader::isScriptTypeSupported(LegacyTypeSupport supportLegacyTypes) const |
| +{ |
| + return isValidScriptTypeAndLanguage(client()->typeAttributeValue(), client()->languageAttributeValue(), supportLegacyTypes); |
| +} |
| + |
| // http://dev.w3.org/html5/spec/Overview.html#prepare-a-script |
| bool ScriptLoader::prepareScript(const TextPosition& scriptStartPosition, LegacyTypeSupport supportLegacyTypes) |
| { |
| @@ -344,9 +341,10 @@ bool isSVGScriptLoader(Element* element) |
| void ScriptLoader::logScriptMimetype(ScriptResource* resource, LocalFrame* frame, String mimetype) |
| { |
| - bool text = mimetype.lower().startsWith("text/"); |
| - bool application = mimetype.lower().startsWith("application/"); |
| - bool expectedJs = MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimetype) || (text && isLegacySupportedJavaScriptLanguage(mimetype.substring(5))); |
| + String lowerMimetype = mimetype.lower(); |
| + bool text = lowerMimetype.startsWith("text/"); |
| + bool application = lowerMimetype.startsWith("application/"); |
| + bool expectedJs = MIMETypeRegistry::isSupportedJavaScriptMIMEType(lowerMimetype) || (text && isLegacySupportedJavaScriptLanguage(lowerMimetype.substring(5))); |
| bool sameOrigin = m_element->document().getSecurityOrigin()->canRequest(m_resource->url()); |
| if (expectedJs) { |
| return; |