| 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..f9f6125496b46591ed5ed89c87c26f0f0ecf182b
|
| --- /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 emits FetchRequest to ResourceFetcher
|
| +// (via ScriptResource::fetch). Then, it keeps track of the fetch progress by
|
| +// being a ScriptResourceClient. Finally, it returns its client a compiled
|
| +// ModuleScript.
|
| +//
|
| +// 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 {
|
| + 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);
|
| + }
|
| +
|
| + ~ModuleScriptLoader() override;
|
| +
|
| + 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;
|
| + Member<ModuleScript> m_moduleScript;
|
| + Member<ModuleScriptLoaderRegistry> m_registry;
|
| + Member<ModuleScriptLoaderClient> m_client;
|
| +#ifndef NDEBUG
|
| + KURL m_url;
|
| +#endif
|
| +};
|
| +
|
| +} // namespace blink
|
| +
|
| +#endif
|
|
|