Commit 38295e6a authored by hiroshige's avatar hiroshige Committed by Commit bot

Move isLegacySupportedJavaScriptLanguage() to MIMETypeRegistry

This is preparation for https://codereview.chromium.org/2780463002/ that moves
callers of isLegacySupportedJavaScriptLanguage() to outside ScriptLoader.

BUG=594639, 686281

Review-Url: https://codereview.chromium.org/2806523002
Cr-Commit-Position: refs/heads/master@{#462792}
parent 32894e2b
...@@ -147,31 +147,6 @@ void ScriptLoader::detachPendingScript() { ...@@ -147,31 +147,6 @@ void ScriptLoader::detachPendingScript() {
m_pendingScript = nullptr; m_pendingScript = nullptr;
} }
static bool isLegacySupportedJavaScriptLanguage(const String& language) {
// Mozilla 1.8 accepts javascript1.0 - javascript1.7, but WinIE 7 accepts only
// javascript1.1 - javascript1.3.
// Mozilla 1.8 and WinIE 7 both accept javascript and livescript.
// WinIE 7 accepts ecmascript and jscript, but Mozilla 1.8 doesn't.
// Neither Mozilla 1.8 nor WinIE 7 accept leading or trailing whitespace.
// 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.
return equalIgnoringASCIICase(language, "javascript") ||
equalIgnoringASCIICase(language, "javascript1.0") ||
equalIgnoringASCIICase(language, "javascript1.1") ||
equalIgnoringASCIICase(language, "javascript1.2") ||
equalIgnoringASCIICase(language, "javascript1.3") ||
equalIgnoringASCIICase(language, "javascript1.4") ||
equalIgnoringASCIICase(language, "javascript1.5") ||
equalIgnoringASCIICase(language, "javascript1.6") ||
equalIgnoringASCIICase(language, "javascript1.7") ||
equalIgnoringASCIICase(language, "livescript") ||
equalIgnoringASCIICase(language, "ecmascript") ||
equalIgnoringASCIICase(language, "jscript");
}
void ScriptLoader::dispatchErrorEvent() { void ScriptLoader::dispatchErrorEvent() {
m_element->dispatchErrorEvent(); m_element->dispatchErrorEvent();
} }
...@@ -196,14 +171,14 @@ bool ScriptLoader::isValidScriptTypeAndLanguage( ...@@ -196,14 +171,14 @@ bool ScriptLoader::isValidScriptTypeAndLanguage(
return language.isEmpty() || // assume text/javascript. return language.isEmpty() || // assume text/javascript.
MIMETypeRegistry::isSupportedJavaScriptMIMEType("text/" + MIMETypeRegistry::isSupportedJavaScriptMIMEType("text/" +
language) || language) ||
isLegacySupportedJavaScriptLanguage(language); MIMETypeRegistry::isLegacySupportedJavaScriptLanguage(language);
} else if (RuntimeEnabledFeatures::moduleScriptsEnabled() && } else if (RuntimeEnabledFeatures::moduleScriptsEnabled() &&
type == "module") { type == "module") {
return true; return true;
} else if (MIMETypeRegistry::isSupportedJavaScriptMIMEType( } else if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(
type.stripWhiteSpace()) || type.stripWhiteSpace()) ||
(supportLegacyTypes == AllowLegacyTypeInTypeAttribute && (supportLegacyTypes == AllowLegacyTypeInTypeAttribute &&
isLegacySupportedJavaScriptLanguage(type))) { MIMETypeRegistry::isLegacySupportedJavaScriptLanguage(type))) {
return true; return true;
} }
...@@ -619,7 +594,8 @@ void ScriptLoader::logScriptMIMEType(LocalFrame* frame, ...@@ -619,7 +594,8 @@ void ScriptLoader::logScriptMIMEType(LocalFrame* frame,
if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType)) if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType))
return; return;
bool isText = mimeType.startsWith("text/", TextCaseASCIIInsensitive); bool isText = mimeType.startsWith("text/", TextCaseASCIIInsensitive);
if (isText && isLegacySupportedJavaScriptLanguage(mimeType.substring(5))) if (isText && MIMETypeRegistry::isLegacySupportedJavaScriptLanguage(
mimeType.substring(5)))
return; return;
bool isSameOrigin = bool isSameOrigin =
m_element->document().getSecurityOrigin()->canRequest(resource->url()); m_element->document().getSecurityOrigin()->canRequest(resource->url());
......
...@@ -126,6 +126,32 @@ bool MIMETypeRegistry::isSupportedJavaScriptMIMEType(const String& mimeType) { ...@@ -126,6 +126,32 @@ bool MIMETypeRegistry::isSupportedJavaScriptMIMEType(const String& mimeType) {
ToLowerASCIIOrEmpty(mimeType)); ToLowerASCIIOrEmpty(mimeType));
} }
bool MIMETypeRegistry::isLegacySupportedJavaScriptLanguage(
const String& language) {
// Mozilla 1.8 accepts javascript1.0 - javascript1.7, but WinIE 7 accepts only
// javascript1.1 - javascript1.3.
// Mozilla 1.8 and WinIE 7 both accept javascript and livescript.
// WinIE 7 accepts ecmascript and jscript, but Mozilla 1.8 doesn't.
// Neither Mozilla 1.8 nor WinIE 7 accept leading or trailing whitespace.
// 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.
return equalIgnoringASCIICase(language, "javascript") ||
equalIgnoringASCIICase(language, "javascript1.0") ||
equalIgnoringASCIICase(language, "javascript1.1") ||
equalIgnoringASCIICase(language, "javascript1.2") ||
equalIgnoringASCIICase(language, "javascript1.3") ||
equalIgnoringASCIICase(language, "javascript1.4") ||
equalIgnoringASCIICase(language, "javascript1.5") ||
equalIgnoringASCIICase(language, "javascript1.6") ||
equalIgnoringASCIICase(language, "javascript1.7") ||
equalIgnoringASCIICase(language, "livescript") ||
equalIgnoringASCIICase(language, "ecmascript") ||
equalIgnoringASCIICase(language, "jscript");
}
bool MIMETypeRegistry::isSupportedNonImageMIMEType(const String& mimeType) { bool MIMETypeRegistry::isSupportedNonImageMIMEType(const String& mimeType) {
return mime_util::IsSupportedNonImageMimeType(ToLowerASCIIOrEmpty(mimeType)); return mime_util::IsSupportedNonImageMimeType(ToLowerASCIIOrEmpty(mimeType));
} }
......
...@@ -69,6 +69,8 @@ class PLATFORM_EXPORT MIMETypeRegistry { ...@@ -69,6 +69,8 @@ class PLATFORM_EXPORT MIMETypeRegistry {
// resource. // resource.
static bool isSupportedJavaScriptMIMEType(const String& mimeType); static bool isSupportedJavaScriptMIMEType(const String& mimeType);
static bool isLegacySupportedJavaScriptLanguage(const String& language);
// Checks to see if a non-image mime type is suitable for being loaded as a // Checks to see if a non-image mime type is suitable for being loaded as a
// document in a frame. Includes supported JavaScript MIME types. // document in a frame. Includes supported JavaScript MIME types.
static bool isSupportedNonImageMIMEType(const String& mimeType); static bool isSupportedNonImageMIMEType(const String& mimeType);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment