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

Unified Diff: third_party/WebKit/Source/core/dom/ScriptLoader.cpp

Issue 2821803002: Introduce ScriptLoader::script_type_ (Closed)
Patch Set: Add missing include Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
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 b7ffc14fe49f45a40f6278f6b44bea0e0dc5ddd4..2686d851c6782011685c97fc22e02b7dedb829d8 100644
--- a/third_party/WebKit/Source/core/dom/ScriptLoader.cpp
+++ b/third_party/WebKit/Source/core/dom/ScriptLoader.cpp
@@ -157,10 +157,12 @@ void ScriptLoader::DispatchLoadEvent() {
SetHaveFiredLoadEvent(true);
}
-bool ScriptLoader::IsValidScriptTypeAndLanguage(
+namespace {
+
+bool IsValidClassicScriptTypeAndLanguage(
const String& type,
const String& language,
- LegacyTypeSupport support_legacy_types) {
+ ScriptLoader::LegacyTypeSupport support_legacy_types) {
// FIXME: isLegacySupportedJavaScriptLanguage() is not valid HTML5. It is used
// here to maintain backwards compatibility with existing layout tests. The
// specific violations are:
@@ -173,12 +175,10 @@ bool ScriptLoader::IsValidScriptTypeAndLanguage(
MIMETypeRegistry::IsSupportedJavaScriptMIMEType("text/" +
language) ||
MIMETypeRegistry::IsLegacySupportedJavaScriptLanguage(language);
- } else if (RuntimeEnabledFeatures::moduleScriptsEnabled() &&
- type == "module") {
- return true;
} else if (MIMETypeRegistry::IsSupportedJavaScriptMIMEType(
type.StripWhiteSpace()) ||
- (support_legacy_types == kAllowLegacyTypeInTypeAttribute &&
+ (support_legacy_types ==
+ ScriptLoader::kAllowLegacyTypeInTypeAttribute &&
MIMETypeRegistry::IsLegacySupportedJavaScriptLanguage(type))) {
return true;
}
@@ -186,11 +186,40 @@ bool ScriptLoader::IsValidScriptTypeAndLanguage(
return false;
}
-bool ScriptLoader::IsScriptTypeSupported(
- LegacyTypeSupport support_legacy_types) const {
+} // namespace
+
+// Step 6 of https://html.spec.whatwg.org/#prepare-a-script
+bool ScriptLoader::IsValidScriptTypeAndLanguage(
+ const String& type,
+ const String& language,
+ LegacyTypeSupport support_legacy_types,
+ ScriptType& out_script_type) {
+ if (IsValidClassicScriptTypeAndLanguage(type, language,
+ support_legacy_types)) {
+ // - "If the script block's type string is an ASCII case-insensitive match
+ // for any JavaScript MIME type, the script's type is "classic"."
+ // TODO(hiroshige): Annotate and/or cleanup this step.
+ out_script_type = ScriptType::kClassic;
+ return true;
+ }
+
+ if (RuntimeEnabledFeatures::moduleScriptsEnabled() && type == "module") {
+ // - "If the script block's type string is an ASCII case-insensitive match
+ // for the string "module", the script's type is "module"."
+ out_script_type = ScriptType::kModule;
+ return true;
+ }
+
+ // - "If neither of the above conditions are true, then abort these steps
+ // at this point. No script is executed."
+ return false;
+}
+
+bool ScriptLoader::IsScriptTypeSupported(LegacyTypeSupport support_legacy_types,
+ ScriptType& out_script_type) const {
return IsValidScriptTypeAndLanguage(element_->TypeAttributeValue(),
element_->LanguageAttributeValue(),
- support_legacy_types);
+ support_legacy_types, out_script_type);
}
// https://html.spec.whatwg.org/#prepare-a-script
@@ -231,9 +260,9 @@ bool ScriptLoader::PrepareScript(const TextPosition& script_start_position,
if (!element_->IsConnected())
return false;
- // 6.
- // TODO(hiroshige): Annotate and/or cleanup this step.
- if (!IsScriptTypeSupported(support_legacy_types))
+ // 6. "Determine the script's type as follows:"
+ // |script_type_| is set here.
+ if (!IsScriptTypeSupported(support_legacy_types, script_type_))
return false;
// 7. "If was-parser-inserted is true,
@@ -264,6 +293,11 @@ bool ScriptLoader::PrepareScript(const TextPosition& script_start_position,
if (!context_document->CanExecuteScripts(kAboutToExecuteScript))
return false;
+ // 11. "If the script element has a nomodule content attribute
+ // and the script's type is "classic", then abort these steps.
+ // The script is not executed."
+ // TODO(japhet): Implement this step.
+
// 13.
if (!IsScriptForEventSupported())
return false;
« no previous file with comments | « third_party/WebKit/Source/core/dom/ScriptLoader.h ('k') | third_party/WebKit/Source/core/html/HTMLScriptElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698