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

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

Issue 2821803002: Introduce ScriptLoader::script_type_ (Closed)
Patch Set: 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 77cc040f3400f0f5af8bc9f49e42ae0b41fe73e9..3f0bcab07e3ad1abf674bc1b0e45ea8ce391c00b 100644
--- a/third_party/WebKit/Source/core/dom/ScriptLoader.cpp
+++ b/third_party/WebKit/Source/core/dom/ScriptLoader.cpp
@@ -156,10 +156,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:
@@ -172,12 +174,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;
}
@@ -185,11 +185,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(
kouhei (in TOK) 2017/04/15 01:18:23 rename this to DetermineScriptType and have this r
+ 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,
kouhei (in TOK) 2017/04/15 01:18:23 DetermineScriptTypeForElement -> return ScriptTYpe
+ 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
@@ -230,9 +259,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,
@@ -263,6 +292,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;

Powered by Google App Engine
This is Rietveld 408576698