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 ModuleScriptLoader_h | |
| 6 #define ModuleScriptLoader_h | |
| 7 | |
| 8 #include "core/CoreExport.h" | |
| 9 #include "core/loader/modulescript/ModuleScriptFetchRequest.h" | |
| 10 #include "core/loader/resource/ScriptResource.h" | |
| 11 #include "platform/heap/Handle.h" | |
| 12 #include "platform/loader/fetch/ResourceLoaderOptions.h" | |
| 13 #include "platform/loader/fetch/ResourceOwner.h" | |
| 14 #include "platform/weborigin/KURL.h" | |
| 15 #include "public/platform/WebURLRequest.h" | |
| 16 | |
| 17 namespace blink { | |
| 18 | |
| 19 class Modulator; | |
| 20 class ModuleScript; | |
| 21 class ModuleScriptLoaderClient; | |
| 22 class ModuleScriptLoaderRegistry; | |
| 23 enum class ModuleGraphLevel; | |
| 24 | |
| 25 // A ModuleScriptLoader is responsible for loading a new single ModuleScript. | |
| 26 // | |
| 27 // A ModuleScriptLoader constructs and emits FetchRequest to ResourceFetcher | |
| 28 // (via ScriptResource::fetch). Then, it keeps track of the fetch progress by | |
| 29 // being a ScriptResourceClient. Finally, it returns its client a compiled | |
| 30 // ModuleScript. | |
| 31 // | |
| 32 // ModuleLoaders should only be used via Modulator and its ModuleMap. | |
|
hiroshige
2017/03/06 22:20:21
nit: s/ModuleLoaders/ModuleScriptLoader(s)/?
kouhei (in TOK)
2017/03/23 00:34:01
Done.
| |
| 33 class CORE_EXPORT ModuleScriptLoader final | |
| 34 : public GarbageCollectedFinalized<ModuleScriptLoader>, | |
| 35 public ResourceOwner<ScriptResource> { | |
| 36 WTF_MAKE_NONCOPYABLE(ModuleScriptLoader); | |
| 37 USING_GARBAGE_COLLECTED_MIXIN(ModuleScriptLoader); | |
| 38 | |
| 39 enum class State { | |
| 40 Initial, | |
| 41 // FetchRequest is being processed, and ModuleScriptLoader hasn't | |
| 42 // notifyFinished(). | |
| 43 Fetching, | |
| 44 // Finished successfully or w/ error. | |
| 45 Finished, | |
| 46 }; | |
| 47 | |
| 48 public: | |
| 49 static ModuleScriptLoader* create(Modulator* modulator, | |
| 50 ModuleScriptLoaderRegistry* registry, | |
| 51 ModuleScriptLoaderClient* client) { | |
| 52 return new ModuleScriptLoader(modulator, registry, client); | |
| 53 } | |
| 54 | |
| 55 ~ModuleScriptLoader() override; | |
| 56 | |
| 57 void fetch(const ModuleScriptFetchRequest&, | |
|
yhirano
2017/02/28 11:30:11
Please note that the client can be notified synchr
kouhei (in TOK)
2017/03/06 02:10:09
Done.
| |
| 58 ResourceFetcher*, | |
| 59 ModuleGraphLevel); | |
| 60 | |
| 61 bool isInitialState() const { return m_state == State::Initial; } | |
| 62 bool hasFinished() const { return m_state == State::Finished; } | |
| 63 | |
| 64 DECLARE_TRACE(); | |
| 65 | |
| 66 private: | |
| 67 ModuleScriptLoader(Modulator*, | |
| 68 ModuleScriptLoaderRegistry*, | |
| 69 ModuleScriptLoaderClient*); | |
| 70 | |
| 71 static ModuleScript* createModuleScript(const String& sourceText, | |
| 72 const KURL&, | |
| 73 Modulator*, | |
| 74 const String& nonce, | |
| 75 ParserDisposition, | |
| 76 WebURLRequest::FetchCredentialsMode); | |
| 77 | |
| 78 void advanceState(State newState); | |
| 79 #if DCHECK_IS_ON() | |
| 80 static const char* stateToString(State); | |
| 81 #endif | |
| 82 | |
| 83 // Implements ScriptResourceClient | |
| 84 void notifyFinished(Resource*) override; | |
| 85 String debugName() const override { return "ModuleScriptLoader"; } | |
| 86 | |
| 87 static bool wasModuleLoadSuccessful(Resource*); | |
| 88 | |
| 89 Member<Modulator> m_modulator; | |
| 90 State m_state = State::Initial; | |
| 91 String m_nonce; | |
| 92 ParserDisposition m_parserState; | |
| 93 Member<ModuleScript> m_moduleScript; | |
| 94 Member<ModuleScriptLoaderRegistry> m_registry; | |
| 95 Member<ModuleScriptLoaderClient> m_client; | |
| 96 #if DCHECK_IS_ON() | |
| 97 KURL m_url; | |
| 98 #endif | |
| 99 }; | |
| 100 | |
| 101 } // namespace blink | |
| 102 | |
| 103 #endif | |
| OLD | NEW |