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

Unified Diff: third_party/WebKit/Source/core/dom/ModulePendingScript.h

Issue 2820703003: Reland of Introduce ModulePendingScript (Closed)
Patch Set: Rebase 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/ModulePendingScript.h
diff --git a/third_party/WebKit/Source/core/dom/ModulePendingScript.h b/third_party/WebKit/Source/core/dom/ModulePendingScript.h
new file mode 100644
index 0000000000000000000000000000000000000000..62ecccbbcfbac8682a2bb6da632754e4810ed829
--- /dev/null
+++ b/third_party/WebKit/Source/core/dom/ModulePendingScript.h
@@ -0,0 +1,98 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ModulePendingScript_h
+#define ModulePendingScript_h
+
+#include "core/dom/Modulator.h"
+#include "core/dom/ModuleScript.h"
+#include "core/dom/PendingScript.h"
+
+namespace blink {
+
+class ModulePendingScript;
+
+// ModulePendingScriptTreeClient is used to connect from Modulator::FetchTree()
+// to ModulePendingScript. Because ModulePendingScript is created after
+// Modulator::FetchTree() is called, ModulePendingScriptTreeClient is
+// registered as ModuleTreeClient to FetchTree() first, and later
+// ModulePendingScript is supplied to ModulePendingScriptTreeClient via
+// SetPendingScript() and is notified of module tree load finish.
+class ModulePendingScriptTreeClient final
+ : public GarbageCollectedFinalized<ModulePendingScriptTreeClient>,
+ public ModuleTreeClient {
+ USING_GARBAGE_COLLECTED_MIXIN(ModulePendingScriptTreeClient);
+
+ public:
+ static ModulePendingScriptTreeClient* Create() {
+ return new ModulePendingScriptTreeClient();
+ }
+ virtual ~ModulePendingScriptTreeClient() = default;
+
+ void SetPendingScript(ModulePendingScript* client);
+
+ ModuleScript* GetModuleScript() const { return module_script_; }
+
+ DECLARE_TRACE();
+
+ private:
+ ModulePendingScriptTreeClient();
+
+ // Implements ModuleTreeClient
+ void NotifyModuleTreeLoadFinished(ModuleScript*) override;
+
+ bool finished_ = false;
+ Member<ModuleScript> module_script_;
+ Member<ModulePendingScript> pending_script_;
+};
+
+// PendingScript for a module script
+// https://html.spec.whatwg.org/#module-script.
+class CORE_EXPORT ModulePendingScript : public PendingScript {
+ public:
+ static ModulePendingScript* Create(ScriptElementBase* element,
+ ModulePendingScriptTreeClient* client) {
+ return new ModulePendingScript(element, client);
+ }
+
+ ~ModulePendingScript() override;
+
+ void NotifyModuleTreeLoadFinished();
+
+ ModuleScript* GetModuleScript() const {
+ return module_tree_client_->GetModuleScript();
+ }
+
+ DECLARE_TRACE();
+
+ private:
+ ModulePendingScript(ScriptElementBase*, ModulePendingScriptTreeClient*);
+
+ // PendingScript
+ ScriptType GetScriptType() const override { return ScriptType::kModule; }
+ Script* GetSource(const KURL& document_url,
+ bool& error_occurred) const override;
+ bool IsReady() const override { return ready_; }
+ bool IsExternal() const override { return true; }
+ bool ErrorOccurred() const override;
+ bool WasCanceled() const override { return false; }
+
+ void StartStreamingIfPossible(Document*, ScriptStreamer::Type) override {}
+ KURL UrlForClassicScript() const override {
+ NOTREACHED();
+ return KURL();
+ }
+ void RemoveFromMemoryCache() override { NOTREACHED(); }
+
+ void DisposeInternal() override;
+
+ void CheckState() const override {}
+
+ Member<ModulePendingScriptTreeClient> module_tree_client_;
+ bool ready_ = false;
+};
+
+} // namespace blink
+
+#endif // ModulePendingScript_h
« no previous file with comments | « third_party/WebKit/Source/core/dom/BUILD.gn ('k') | third_party/WebKit/Source/core/dom/ModulePendingScript.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698