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

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

Issue 2798383002: [local; kouhei 3] kouhei's ScriptLoader-part (for quick testing) (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
« no previous file with comments | « third_party/WebKit/Source/core/dom/ScriptLoader.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 c95bc45590983abac27325cd9bf1fc9c06c20b18..27b40cfa8884b5428c98b3c5c68a5ff25f0c79a2 100644
--- a/third_party/WebKit/Source/core/dom/ScriptLoader.cpp
+++ b/third_party/WebKit/Source/core/dom/ScriptLoader.cpp
@@ -34,6 +34,8 @@
#include "core/dom/DocumentParserTiming.h"
#include "core/dom/IgnoreDestructiveWriteCountIncrementer.h"
#include "core/dom/Script.h"
+#include "core/dom/Modulator.h"
+#include "core/dom/ModuleScript.h"
#include "core/dom/ScriptElementBase.h"
#include "core/dom/ScriptRunner.h"
#include "core/dom/ScriptableDocumentParser.h"
@@ -45,6 +47,7 @@
#include "core/html/CrossOriginAttribute.h"
#include "core/html/imports/HTMLImport.h"
#include "core/html/parser/HTMLParserIdioms.h"
+#include "core/loader/modulescript/ModuleScriptFetchRequest.h"
#include "platform/WebFrameScheduler.h"
#include "platform/loader/fetch/AccessControlStatus.h"
#include "platform/loader/fetch/FetchRequest.h"
@@ -59,6 +62,46 @@
namespace blink {
+class ScriptElementModuleClient
+ : public GarbageCollectedFinalized<ScriptElementModuleClient>,
+ public ModuleTreeClient {
+ USING_GARBAGE_COLLECTED_MIXIN(ScriptElementModuleClient);
+
+ public:
+ static ScriptElementModuleClient* create(LocalFrame* frame) {
+ return new ScriptElementModuleClient(frame);
+ }
+ virtual ~ScriptElementModuleClient() = default;
+
+ DECLARE_TRACE();
+
+ private:
+ ScriptElementModuleClient(LocalFrame* frame) : m_frame(frame) {}
+
+ // Implements ModuleTreeClient
+ void notifyModuleTreeLoadFinished(ModuleScript*) override;
+
+ Member<LocalFrame> m_frame;
+};
+
+void ScriptElementModuleClient::notifyModuleTreeLoadFinished(
+ ModuleScript* moduleScript) {
+ printf("notifyFinishedModuleTree!!! moduleScript: %p\n", moduleScript);
+ if (!moduleScript)
+ return;
+ DCHECK_EQ(moduleScript->instantiationState(),
+ ModuleInstantiationState::Instantiated);
+
+ // TODO(kouhei): Actually we should just return w/ the prepared script here.
+ // In this prototype, we will execute the module immediately just for fun. :)
+ Modulator::from(m_frame.get())->executeModule(moduleScript->record());
+}
+
+DEFINE_TRACE(ScriptElementModuleClient) {
+ visitor->trace(m_frame);
+ ModuleTreeClient::trace(visitor);
+}
+
ScriptLoader::ScriptLoader(ScriptElementBase* element,
bool parserInserted,
bool alreadyStarted,
@@ -105,6 +148,7 @@ ScriptLoader::~ScriptLoader() {}
DEFINE_TRACE(ScriptLoader) {
visitor->trace(m_element);
visitor->trace(m_resource);
+ visitor->trace(m_elementModuleClient);
visitor->trace(m_pendingScript);
PendingScriptClient::trace(visitor);
}
@@ -491,7 +535,8 @@ bool ScriptLoader::fetchScript(const String& sourceUrl,
// 21. "If the element has a src content attribute, run these substeps:"
if (!stripLeadingAndTrailingHTMLSpaces(sourceUrl).isEmpty()) {
// 21.4. "Parse src relative to the element's node document."
- ResourceRequest resourceRequest(elementDocument->completeURL(sourceUrl));
+ KURL url = elementDocument->completeURL(sourceUrl);
+ ResourceRequest resourceRequest(url);
// [Intervention]
if (m_documentWriteIntervention ==
@@ -511,6 +556,40 @@ bool ScriptLoader::fetchScript(const String& sourceUrl,
// 16. "Let module script credentials mode be determined by switching
// on CORS setting:"
// TODO(hiroshige): Implement this step for "module".
+ if (RuntimeEnabledFeatures::moduleScriptsEnabled() &&
+ m_element->typeAttributeValue() == "module") {
+ m_elementModuleClient = ScriptElementModuleClient::create(
+ elementDocument->contextDocument()->frame());
+
+ String nonce;
+ if (m_element->isNonceableElement())
+ nonce = m_element->nonce();
+ ParserDisposition parserState =
+ isParserInserted() ? ParserInserted : NotParserInserted;
+
+ // 16. "Let module script credentials mode be determined by switching
+ // on CORS setting:"
+ WebURLRequest::FetchCredentialsMode credentialsMode;
+ switch (crossOrigin) {
+ case CrossOriginAttributeNotSet:
+ credentialsMode = WebURLRequest::FetchCredentialsModeOmit;
+ break;
+ case CrossOriginAttributeAnonymous:
+ credentialsMode = WebURLRequest::FetchCredentialsModeSameOrigin;
+ break;
+ case CrossOriginAttributeUseCredentials:
+ credentialsMode = WebURLRequest::FetchCredentialsModeInclude;
+ break;
+ default:
+ NOTREACHED();
+ }
+
+ ModuleScriptFetchRequest moduleRequest(url, nonce, parserState,
+ credentialsMode);
+ Modulator::from(elementDocument->frame())
+ ->fetchTree(moduleRequest, m_elementModuleClient);
+ return true;
+ }
// 21.6, "classic": "Fetch a classic script given ... CORS setting
// ... and encoding."
« no previous file with comments | « third_party/WebKit/Source/core/dom/ScriptLoader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698