| 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..98abde33f327dd1b4db91129ec7aec87a29aa26c
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/core/loader/modulescript/ModuleScriptLoader.h
|
| @@ -0,0 +1,91 @@
|
| +// 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/fetch/ResourceOwner.h"
|
| +#include "core/loader/resource/ScriptResource.h"
|
| +#include "platform/heap/Handle.h"
|
| +#include "platform/weborigin/KURL.h"
|
| +
|
| +namespace blink {
|
| +
|
| +class ModuleController;
|
| +class ModuleScript;
|
| +class ModuleScriptLoaderRegistry;
|
| +class ModuleScriptLoaderClient;
|
| +
|
| +// A ModuleScriptLoader is responsible for loading a new single ModuleScript.
|
| +//
|
| +// A ModuleScriptLoader constructs and emit FetchRequest to RequestFetcher (via
|
| +// ScriptResource::fetch).
|
| +// Then, it keeps track of the fetch progress by being a ScriptResourceClient.
|
| +// Finally, it return 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(const KURL& url,
|
| + const KURL& baseURL,
|
| + ModuleController* moduleController,
|
| + ModuleScriptLoaderRegistry* registry,
|
| + ModuleScriptLoaderClient* client) {
|
| + return new ModuleScriptLoader(url, baseURL, moduleController, registry,
|
| + client);
|
| + }
|
| +
|
| + virtual ~ModuleScriptLoader();
|
| +
|
| + void fetch(ResourceFetcher*);
|
| +
|
| + bool isInitialState() const { return m_state == State::Initial; }
|
| + bool hasFinished() const { return m_state == State::Finished; }
|
| +
|
| + DECLARE_TRACE();
|
| +
|
| + private:
|
| + explicit ModuleScriptLoader(const KURL&,
|
| + const KURL& baseURL,
|
| + ModuleController*,
|
| + ModuleScriptLoaderRegistry*,
|
| + ModuleScriptLoaderClient*);
|
| +
|
| + void advanceState(State newState);
|
| +
|
| + // Implements ScriptResourceClient
|
| + void notifyFinished(Resource*) override;
|
| + String debugName() const override { return "ModuleScriptLoader"; }
|
| +
|
| + // TODO(kouhei): May be this method should live in ModuleResource? or should
|
| + // it be here to consolidate the spec impl code in ModuleMap.cpp?
|
| + static bool wasModuleLoadSuccessful(Resource*);
|
| +
|
| + KURL m_url;
|
| + KURL m_baseURL;
|
| + Member<ModuleController> m_moduleController;
|
| + State m_state = State::Initial;
|
| + Member<ModuleScript> m_moduleScript;
|
| + Member<ModuleScriptLoaderRegistry> m_registry;
|
| + Member<ModuleScriptLoaderClient> m_client;
|
| +};
|
| +
|
| +} // namespace blink
|
| +
|
| +#endif
|
|
|