Chromium Code Reviews| 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(); } |
|
kouhei (in TOK)
2017/04/14 00:20:45
Comment explaining "why" would help
|
| + |
| + void DisposeInternal() override; |
| + |
| + void CheckState() const override {} |
| + |
| + Member<ModulePendingScriptTreeClient> module_tree_client_; |
| + bool ready_ = false; |
| +}; |
| + |
| +} // namespace blink |
| + |
| +#endif // ModulePendingScript_h |