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 emit FetchRequest to RequestFetcher (via | |
|
yhirano
2017/02/17 04:59:15
ResourceFetcher?
yhirano
2017/02/17 04:59:15
emit"s"
kouhei (in TOK)
2017/02/21 01:26:51
Done.
kouhei (in TOK)
2017/02/21 01:26:51
Done.
| |
| 28 // ScriptResource::fetch). Then, it keeps track of the fetch progress by being a | |
| 29 // ScriptResourceClient. Finally, it return its client a compiled ModuleScript. | |
|
yhirano
2017/02/17 04:59:15
return"s"
kouhei (in TOK)
2017/02/21 01:26:51
Done.
| |
| 30 // | |
| 31 // ModuleLoaders should only be used via Modulator and its ModuleMap. | |
| 32 class CORE_EXPORT ModuleScriptLoader final | |
| 33 : public GarbageCollectedFinalized<ModuleScriptLoader>, | |
| 34 public ResourceOwner<ScriptResource> { | |
| 35 WTF_MAKE_NONCOPYABLE(ModuleScriptLoader); | |
| 36 USING_GARBAGE_COLLECTED_MIXIN(ModuleScriptLoader); | |
| 37 | |
| 38 enum class State { | |
|
hiroshige
2017/02/20 23:15:32
nit: having a declaration here (other than WTF_MAK
| |
| 39 Initial, | |
| 40 // FetchRequest is being processed, and ModuleScriptLoader hasn't | |
| 41 // notifyFinished(). | |
| 42 Fetching, | |
| 43 // Finished successfully or w/ error. | |
| 44 Finished, | |
| 45 }; | |
| 46 | |
| 47 public: | |
| 48 static ModuleScriptLoader* create(Modulator* modulator, | |
| 49 ModuleScriptLoaderRegistry* registry, | |
| 50 ModuleScriptLoaderClient* client) { | |
| 51 return new ModuleScriptLoader(modulator, registry, client); | |
| 52 } | |
| 53 | |
| 54 virtual ~ModuleScriptLoader(); | |
|
yhirano
2017/02/17 04:59:15
-virtual
+override
kouhei (in TOK)
2017/02/21 01:26:51
Done.
| |
| 55 | |
| 56 void fetch(const ModuleScriptFetchRequest&, | |
| 57 ResourceFetcher*, | |
| 58 ModuleGraphLevel); | |
| 59 | |
| 60 bool isInitialState() const { return m_state == State::Initial; } | |
| 61 bool hasFinished() const { return m_state == State::Finished; } | |
| 62 | |
| 63 DECLARE_TRACE(); | |
| 64 | |
| 65 private: | |
| 66 ModuleScriptLoader(Modulator*, | |
| 67 ModuleScriptLoaderRegistry*, | |
| 68 ModuleScriptLoaderClient*); | |
| 69 | |
| 70 static ModuleScript* createModuleScript(const String& sourceText, | |
| 71 const KURL&, | |
| 72 Modulator*, | |
| 73 const String& nonce, | |
| 74 ParserDisposition, | |
| 75 WebURLRequest::FetchCredentialsMode); | |
| 76 | |
| 77 void advanceState(State newState); | |
| 78 #ifndef NDEBUG | |
| 79 static const char* stateToString(State); | |
| 80 #endif | |
| 81 | |
| 82 // Implements ScriptResourceClient | |
| 83 void notifyFinished(Resource*) override; | |
| 84 String debugName() const override { return "ModuleScriptLoader"; } | |
| 85 | |
| 86 static bool wasModuleLoadSuccessful(Resource*); | |
| 87 | |
| 88 Member<Modulator> m_modulator; | |
| 89 State m_state = State::Initial; | |
| 90 String m_nonce; | |
| 91 ParserDisposition m_parserState; | |
| 92 WebURLRequest::FetchCredentialsMode m_credentialsMode; | |
| 93 Member<ModuleScript> m_moduleScript; | |
| 94 Member<ModuleScriptLoaderRegistry> m_registry; | |
| 95 Member<ModuleScriptLoaderClient> m_client; | |
| 96 #ifndef NDEBUG | |
| 97 KURL m_url; | |
| 98 #endif | |
| 99 }; | |
| 100 | |
| 101 } // namespace blink | |
| 102 | |
| 103 #endif | |
| OLD | NEW |