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

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

Issue 2842923002: Support Inline module script (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 ec7c860544ae8c0e3604351a42930aa4cdadd58b..633b689545b11727474f9c09ec38d66685332167 100644
--- a/third_party/WebKit/Source/core/dom/ScriptLoader.cpp
+++ b/third_party/WebKit/Source/core/dom/ScriptLoader.cpp
@@ -481,16 +481,75 @@ bool ScriptLoader::PrepareScript(const TextPosition& script_start_position,
break;
// - "module":
- case ScriptType::kModule:
- // TODO(hiroshige): Implement inline module scripts.
- element_document.AddConsoleMessage(ConsoleMessage::Create(
- kJSMessageSource, kErrorMessageLevel,
- "Inline module script is not yet supported",
- SourceLocation::Create(element_document.Url().GetString(),
- script_start_position.line_.OneBasedInt(),
- script_start_position.column_.OneBasedInt(),
- nullptr)));
- return false;
+ case ScriptType::kModule: {
+ // Dup of FetchScript() logic.
+
+ // 15. "Let CORS setting be the current state of the element's
+ // crossorigin content attribute."
+ CrossOriginAttributeValue cross_origin =
+ GetCrossOriginAttributeValue(element_->CrossOriginAttributeValue());
+
+ // 16. "Let module script credentials mode be determined by switching
+ // on CORS setting:"
+ WebURLRequest::FetchCredentialsMode credentials_mode =
+ WebURLRequest::kFetchCredentialsModeOmit;
+ switch (cross_origin) {
+ case kCrossOriginAttributeNotSet:
+ credentials_mode = WebURLRequest::kFetchCredentialsModeOmit;
+ break;
+ case kCrossOriginAttributeAnonymous:
+ credentials_mode = WebURLRequest::kFetchCredentialsModeSameOrigin;
+ break;
+ case kCrossOriginAttributeUseCredentials:
+ credentials_mode = WebURLRequest::kFetchCredentialsModeInclude;
+ break;
+ }
+ // 17. "If the script element has a nonce attribute,
+ // then let cryptographic nonce be that attribute's value.
+ // Otherwise, let cryptographic nonce be the empty string."
+ String nonce;
+ if (element_->IsNonceableElement())
+ nonce = element_->nonce();
+
+ // 19. "Let parser state be "parser-inserted"
+ // if the script element has been flagged as "parser-inserted",
+ // and "not parser-inserted" otherwise."
+ ParserDisposition parser_state =
+ IsParserInserted() ? kParserInserted : kNotParserInserted;
+
+ // End of dup.
+ KURL script_url =
+ (!element_document.IsInDocumentWrite() && parser_inserted_)
+ ? element_document.Url()
+ : KURL();
+
+ // 1. Let base URL be the script element's node document's document
+ // base URL.
+ KURL base_url = element_document.BaseURL();
+
+ // 2. Let script be the result of creating a module script using
+ // source text, settings, base URL, cryptographic nonce, parser state,
+ // and module script credentials mode.
+ Modulator* modulator = Modulator::From(
+ ToScriptStateForMainWorld(element_document.GetFrame()));
+ ScriptModule record = modulator->CompileModule(
+ ScriptContent(), base_url, kSharableCrossOrigin);
+ // 3. If this returns null, set the script's script to null and abort
+ // these substeps; the script is ready.
+ if (record.IsNull()) {
+ return false;
+ }
+
+ ModuleScript* script = ModuleScript::Create(
+ modulator, record, base_url, nonce, parser_state, credentials_mode);
+
+ // 4. Fetch the descendants of script (using an empty ancestor list).
+ // When this asynchronously completes, set the script's script to
+ // the result. At that time, the script is ready.
+ DCHECK(!module_tree_client_);
+ module_tree_client_ = ModulePendingScriptTreeClient::Create();
+ modulator->FetchDescendantsForInlineScript(script, module_tree_client_);
hiroshige 2017/04/26 04:54:59 [not specced] This CL jumps to Step 5. of https://
+ }
}
}

Powered by Google App Engine
This is Rietveld 408576698