Index: third_party/WebKit/Source/core/loader/modulescript/ModuleTreeLinker.h |
diff --git a/third_party/WebKit/Source/core/loader/modulescript/ModuleTreeLinker.h b/third_party/WebKit/Source/core/loader/modulescript/ModuleTreeLinker.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6fdd1a1614a69d2c473c1094dfb2f89728d3f98f |
--- /dev/null |
+++ b/third_party/WebKit/Source/core/loader/modulescript/ModuleTreeLinker.h |
@@ -0,0 +1,94 @@ |
+// 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 ModuleTreeLinker_h |
+#define ModuleTreeLinker_h |
+ |
+#include "core/CoreExport.h" |
+#include "core/dom/AncestorList.h" |
+#include "core/dom/Modulator.h" |
+ |
+namespace blink { |
+ |
+class ModuleScriptFetchRequest; |
+enum class ModuleGraphLevel; |
+class ModuleTreeLinkerRegistry; |
+ |
+// A ModuleTreeLinker is responsible for running and keeping intermediate states |
+// for "internal module script graph fetching procedure" for a module graph tree |
+// node. |
+// https://html.spec.whatwg.org/multipage/webappapis.html#internal-module-script-graph-fetching-procedure |
+class CORE_EXPORT ModuleTreeLinker final |
+ : public GarbageCollectedFinalized<ModuleTreeLinker>, |
+ public SingleModuleClient { |
+ USING_GARBAGE_COLLECTED_MIXIN(ModuleTreeLinker); |
+ |
+ public: |
+ static ModuleTreeLinker* Fetch(const ModuleScriptFetchRequest&, |
+ const AncestorList&, |
+ ModuleGraphLevel, |
+ Modulator*, |
+ ModuleTreeLinkerRegistry*, |
+ ModuleTreeClient*); |
+ virtual ~ModuleTreeLinker() = default; |
+ DECLARE_TRACE(); |
+ |
+ bool IsFetching() const { |
+ return State::kFetchingSelf <= state_ && state_ < State::kFinished; |
+ } |
+ bool HasFinished() const { return state_ == State::kFinished; } |
+ |
+ private: |
+ ModuleTreeLinker(const AncestorList& ancestor_list_with_url, |
+ Modulator*, |
+ ModuleTreeLinkerRegistry*, |
+ ModuleTreeClient*); |
+ |
+ enum class State { |
+ kInitial, |
+ // Running fetch of the module script corresponding to the target node. |
+ kFetchingSelf, |
+ // Running fetch of descendants of the target node. |
+ kFetchingDependencies, |
+ // Instantiating m_moduleScript and the node descendants. |
hiroshige
2017/04/19 22:24:08
nit: /m_moduleScript/module_script_/
kouhei (in TOK)
2017/04/24 01:06:22
Done.
|
+ kInstantiating, |
+ kFinished, |
+ }; |
+#if DCHECK_IS_ON() |
+ static const char* StateToString(State); |
+#endif |
+ void AdvanceState(State); |
+ |
+ void FetchSelf(const ModuleScriptFetchRequest&, ModuleGraphLevel); |
+ // Implements SingleModuleClient |
+ void NotifyModuleLoadFinished(ModuleScript*) override; |
+ |
+ void FetchDescendants(); |
+ enum class DescendantLoad { kFailed, kSuccess }; |
+ void NotifyOneDescendantFinished(DescendantLoad was_success); |
+ |
+ void Instantiate(); |
+ HeapHashSet<Member<ModuleScript>> UninstantiatedInclusiveDescendants(); |
+ |
+ class DependencyModuleClient; |
+ friend class DependencyModuleClient; |
+ |
+ Member<Modulator> modulator_; |
+ Member<ModuleTreeLinkerRegistry> registry_; |
+ Member<ModuleTreeClient> client_; |
+ HashSet<KURL> ancestor_list_with_url_; |
+ State state_ = State::kInitial; |
+ // Correspond to _result_ in |
+ // https://html.spec.whatwg.org/multipage/webappapis.html#internal-module-script-graph-fetching-procedure |
+ Member<ModuleScript> module_script_; |
+ // Correspond to _descendants result_ in |
+ // https://html.spec.whatwg.org/multipage/webappapis.html#internal-module-script-graph-fetching-procedure |
+ Member<ModuleScript> descendants_module_script_; |
+ size_t num_incomplete_descendants_ = 0; |
+ HeapHashSet<Member<DependencyModuleClient>> dependency_clients_; |
+}; |
+ |
+} // namespace blink |
+ |
+#endif |