Chromium Code Reviews| Index: third_party/WebKit/Source/core/loader/modulescript/ModuleScriptLoader.h |
| diff --git a/third_party/WebKit/Source/core/loader/modulescript/ModuleScriptLoader.h b/third_party/WebKit/Source/core/loader/modulescript/ModuleScriptLoader.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cad586c558a4482a29ce59e36e3fcd247f830179 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/loader/modulescript/ModuleScriptLoader.h |
| @@ -0,0 +1,103 @@ |
| +// 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 ModuleScriptLoader_h |
| +#define ModuleScriptLoader_h |
| + |
| +#include "core/CoreExport.h" |
| +#include "core/loader/modulescript/ModuleScriptFetchRequest.h" |
| +#include "core/loader/resource/ScriptResource.h" |
| +#include "platform/heap/Handle.h" |
| +#include "platform/loader/fetch/ResourceLoaderOptions.h" |
| +#include "platform/loader/fetch/ResourceOwner.h" |
| +#include "platform/weborigin/KURL.h" |
| +#include "public/platform/WebURLRequest.h" |
| + |
| +namespace blink { |
| + |
| +class Modulator; |
| +class ModuleScript; |
| +class ModuleScriptLoaderClient; |
| +class ModuleScriptLoaderRegistry; |
| +enum class ModuleGraphLevel; |
| + |
| +// A ModuleScriptLoader is responsible for loading a new single ModuleScript. |
| +// |
| +// 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.
|
| +// ScriptResource::fetch). Then, it keeps track of the fetch progress by being a |
| +// 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.
|
| +// |
| +// ModuleLoaders should only be used via Modulator and its ModuleMap. |
| +class CORE_EXPORT ModuleScriptLoader final |
| + : public GarbageCollectedFinalized<ModuleScriptLoader>, |
| + public ResourceOwner<ScriptResource> { |
| + WTF_MAKE_NONCOPYABLE(ModuleScriptLoader); |
| + USING_GARBAGE_COLLECTED_MIXIN(ModuleScriptLoader); |
| + |
| + enum class State { |
|
hiroshige
2017/02/20 23:15:32
nit: having a declaration here (other than WTF_MAK
|
| + Initial, |
| + // FetchRequest is being processed, and ModuleScriptLoader hasn't |
| + // notifyFinished(). |
| + Fetching, |
| + // Finished successfully or w/ error. |
| + Finished, |
| + }; |
| + |
| + public: |
| + static ModuleScriptLoader* create(Modulator* modulator, |
| + ModuleScriptLoaderRegistry* registry, |
| + ModuleScriptLoaderClient* client) { |
| + return new ModuleScriptLoader(modulator, registry, client); |
| + } |
| + |
| + virtual ~ModuleScriptLoader(); |
|
yhirano
2017/02/17 04:59:15
-virtual
+override
kouhei (in TOK)
2017/02/21 01:26:51
Done.
|
| + |
| + void fetch(const ModuleScriptFetchRequest&, |
| + ResourceFetcher*, |
| + ModuleGraphLevel); |
| + |
| + bool isInitialState() const { return m_state == State::Initial; } |
| + bool hasFinished() const { return m_state == State::Finished; } |
| + |
| + DECLARE_TRACE(); |
| + |
| + private: |
| + ModuleScriptLoader(Modulator*, |
| + ModuleScriptLoaderRegistry*, |
| + ModuleScriptLoaderClient*); |
| + |
| + static ModuleScript* createModuleScript(const String& sourceText, |
| + const KURL&, |
| + Modulator*, |
| + const String& nonce, |
| + ParserDisposition, |
| + WebURLRequest::FetchCredentialsMode); |
| + |
| + void advanceState(State newState); |
| +#ifndef NDEBUG |
| + static const char* stateToString(State); |
| +#endif |
| + |
| + // Implements ScriptResourceClient |
| + void notifyFinished(Resource*) override; |
| + String debugName() const override { return "ModuleScriptLoader"; } |
| + |
| + static bool wasModuleLoadSuccessful(Resource*); |
| + |
| + Member<Modulator> m_modulator; |
| + State m_state = State::Initial; |
| + String m_nonce; |
| + ParserDisposition m_parserState; |
| + WebURLRequest::FetchCredentialsMode m_credentialsMode; |
| + Member<ModuleScript> m_moduleScript; |
| + Member<ModuleScriptLoaderRegistry> m_registry; |
| + Member<ModuleScriptLoaderClient> m_client; |
| +#ifndef NDEBUG |
| + KURL m_url; |
| +#endif |
| +}; |
| + |
| +} // namespace blink |
| + |
| +#endif |