Fixed handling of Dart MIME type
TBR=jacobr@google.com,alanknight@google.com
Review URL: https://codereview.chromium.org/1659793004 .
git-svn-id: https://src.chromium.org/blink/branches/dart/2454_1@202764 bbb929c8-8fbe-4397-9dbb-9b2b20218538
diff --git a/Source/core/dom/ScriptLoader.cpp b/Source/core/dom/ScriptLoader.cpp
index c29e0a2..1023f40 100644
--- a/Source/core/dom/ScriptLoader.cpp
+++ b/Source/core/dom/ScriptLoader.cpp
@@ -162,7 +162,34 @@
setHaveFiredLoadEvent(true);
}
-ScriptLoader::ScriptType ScriptLoader::isScriptTypeSupported(LegacyTypeSupport supportLegacyTypes) const
+bool ScriptLoader::isScriptTypeSupported(LegacyTypeSupport supportLegacyTypes) const
+{
+ // 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 ScriptJavaScript; // Assume text/javascript.
+ if (type.isEmpty()) {
+ type = "text/" + language.lower();
+ if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(type) || isLegacySupportedJavaScriptLanguage(language))
+ return true;
+ } else if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(type.stripWhiteSpace()) || (supportLegacyTypes == AllowLegacyTypeInTypeAttribute && isLegacySupportedJavaScriptLanguage(type))) {
+ return true;
+ } else if (MIMETypeRegistry::isSupportedDartMIMEType(type.stripWhiteSpace())) {
+ // FIXMEDART: Added check for Dart MIME type
+ return true;
+ }
+
+ return false;
+}
+
+
+// FIXMEDART: Added to return ScriptType and to support Dart MIME type similar to isScriptTypeSupported
+// but returns a enum for the script type.
+ScriptLoader::ScriptType ScriptLoader::getScriptTypeSupported(LegacyTypeSupport supportLegacyTypes) const
{
// 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.
@@ -179,6 +206,7 @@
} else if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(type.stripWhiteSpace()) || (supportLegacyTypes == AllowLegacyTypeInTypeAttribute && isLegacySupportedJavaScriptLanguage(type))) {
return ScriptJavaScript;
} else if (MIMETypeRegistry::isSupportedDartMIMEType(type.stripWhiteSpace())) {
+ // FIXMEDART: Added checked for Dart MIME type
return ScriptDart;
}
@@ -214,6 +242,10 @@
if (!isScriptTypeSupported(supportLegacyTypes))
return false;
+ // FIXMEDAT: Changed to compute the script type.
+ m_scriptType = getScriptTypeSupported(supportLegacyTypes);
+ RELEASE_ASSERT(m_scriptType != ScriptNone);
+
if (wasParserInserted) {
m_parserInserted = true;
m_forceAsync = false;
diff --git a/Source/core/dom/ScriptLoader.h b/Source/core/dom/ScriptLoader.h
index 3b1d379..6367afd 100644
--- a/Source/core/dom/ScriptLoader.h
+++ b/Source/core/dom/ScriptLoader.h
@@ -61,8 +61,8 @@
// XML parser calls these
void dispatchLoadEvent();
void dispatchErrorEvent();
- enum ScriptType { ScriptNone = 0, ScriptJavaScript, ScriptDart };
- ScriptType isScriptTypeSupported(LegacyTypeSupport) const;
+
+ bool isScriptTypeSupported(LegacyTypeSupport) const;
bool haveFiredLoadEvent() const { return m_haveFiredLoad; }
bool willBeParserExecuted() const { return m_willBeParserExecuted; }
@@ -118,6 +118,10 @@
bool m_willExecuteWhenDocumentFinishedParsing : 1;
bool m_forceAsync : 1;
bool m_willExecuteInOrder : 1;
+
+ // FIXMEDART: Type of script (JS, Dart, None).
+ enum ScriptType { ScriptNone = 0, ScriptJavaScript, ScriptDart };
+ ScriptType getScriptTypeSupported(LegacyTypeSupport) const;
ScriptType m_scriptType;
};