Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef ModulePendingScript_h | |
| 6 #define ModulePendingScript_h | |
| 7 | |
| 8 #include "core/dom/Modulator.h" | |
| 9 #include "core/dom/ModuleScript.h" | |
| 10 #include "core/dom/PendingScript.h" | |
| 11 | |
| 12 namespace blink { | |
| 13 | |
| 14 class ModulePendingScript; | |
| 15 | |
| 16 // ModulePendingScriptTreeClient is used to connect from Modulator::FetchTree() | |
| 17 // to ModulePendingScript. Because ModulePendingScript is created after | |
| 18 // Modulator::FetchTree() is called, ModulePendingScriptTreeClient is | |
| 19 // registered as ModuleTreeClient to FetchTree() first, and later | |
| 20 // ModulePendingScript is supplied to ModulePendingScriptTreeClient via | |
| 21 // SetPendingScript() and is notified of module tree load finish. | |
| 22 class ModulePendingScriptTreeClient final | |
| 23 : public GarbageCollectedFinalized<ModulePendingScriptTreeClient>, | |
| 24 public ModuleTreeClient { | |
| 25 USING_GARBAGE_COLLECTED_MIXIN(ModulePendingScriptTreeClient); | |
| 26 | |
| 27 public: | |
| 28 static ModulePendingScriptTreeClient* Create() { | |
| 29 return new ModulePendingScriptTreeClient(); | |
| 30 } | |
| 31 virtual ~ModulePendingScriptTreeClient() = default; | |
| 32 | |
| 33 void SetPendingScript(ModulePendingScript* client); | |
| 34 | |
| 35 ModuleScript* GetModuleScript() const { return module_script_; } | |
| 36 | |
| 37 DECLARE_TRACE(); | |
| 38 | |
| 39 private: | |
| 40 ModulePendingScriptTreeClient(); | |
| 41 | |
| 42 // Implements ModuleTreeClient | |
| 43 void NotifyModuleTreeLoadFinished(ModuleScript*) override; | |
| 44 | |
| 45 bool finished_ = false; | |
| 46 Member<ModuleScript> module_script_; | |
| 47 Member<ModulePendingScript> pending_script_; | |
| 48 }; | |
| 49 | |
| 50 // PendingScript for a module script | |
| 51 // https://html.spec.whatwg.org/#module-script. | |
| 52 class CORE_EXPORT ModulePendingScript : public PendingScript { | |
| 53 public: | |
| 54 static ModulePendingScript* Create(ScriptElementBase* element, | |
| 55 ModulePendingScriptTreeClient* client) { | |
| 56 return new ModulePendingScript(element, client); | |
| 57 } | |
| 58 | |
| 59 ~ModulePendingScript() override; | |
| 60 | |
| 61 void NotifyModuleTreeLoadFinished(); | |
| 62 | |
| 63 ModuleScript* GetModuleScript() const { | |
| 64 return module_tree_client_->GetModuleScript(); | |
| 65 } | |
| 66 | |
| 67 DECLARE_TRACE(); | |
| 68 | |
| 69 private: | |
| 70 ModulePendingScript(ScriptElementBase*, ModulePendingScriptTreeClient*); | |
| 71 | |
| 72 // PendingScript | |
| 73 ScriptType GetScriptType() const override { return ScriptType::kModule; } | |
| 74 Script* GetSource(const KURL& document_url, | |
| 75 bool& error_occurred) const override; | |
| 76 bool IsReady() const override { return ready_; } | |
| 77 bool IsExternal() const override { return true; } | |
| 78 bool ErrorOccurred() const override; | |
| 79 bool WasCanceled() const override { return false; } | |
| 80 | |
| 81 void StartStreamingIfPossible(Document*, ScriptStreamer::Type) override {} | |
| 82 KURL UrlForClassicScript() const override { | |
| 83 NOTREACHED(); | |
| 84 return KURL(); | |
| 85 } | |
| 86 void RemoveFromMemoryCache() override { NOTREACHED(); } | |
|
kouhei (in TOK)
2017/04/14 00:20:45
Comment explaining "why" would help
| |
| 87 | |
| 88 void DisposeInternal() override; | |
| 89 | |
| 90 void CheckState() const override {} | |
| 91 | |
| 92 Member<ModulePendingScriptTreeClient> module_tree_client_; | |
| 93 bool ready_ = false; | |
| 94 }; | |
| 95 | |
| 96 } // namespace blink | |
| 97 | |
| 98 #endif // ModulePendingScript_h | |
| OLD | NEW |