| // 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 Modulator_h |
| #define Modulator_h |
| |
| #include "bindings/core/v8/ScriptWrappable.h" |
| #include "bindings/core/v8/V8PerContextData.h" |
| #include "core/CoreExport.h" |
| #include "platform/heap/Handle.h" |
| #include "platform/loader/fetch/AccessControlStatus.h" |
| #include "platform/weborigin/KURL.h" |
| #include "platform/weborigin/ReferrerPolicy.h" |
| #include "platform/wtf/text/WTFString.h" |
| |
| namespace blink { |
| |
| class ModuleScript; |
| class ModuleScriptFetchRequest; |
| class ModuleScriptLoaderClient; |
| class ScriptModule; |
| class ScriptModuleResolver; |
| class ScriptState; |
| class ScriptValue; |
| class SecurityOrigin; |
| class WebTaskRunner; |
| |
| // A SingleModuleClient is notified when single module script node (node as in a |
| // module tree graph) load is complete and its corresponding entry is created in |
| // module map. |
| class SingleModuleClient : public GarbageCollectedMixin { |
| public: |
| virtual void NotifyModuleLoadFinished(ModuleScript*) = 0; |
| }; |
| |
| // spec: "top-level module fetch flag" |
| // https://html.spec.whatwg.org/multipage/webappapis.html#fetching-scripts-is-top-level |
| enum class ModuleGraphLevel { kTopLevelModuleFetch, kDependentModuleFetch }; |
| |
| // A Modulator is an interface for "environment settings object" concept for |
| // module scripts. |
| // https://html.spec.whatwg.org/#environment-settings-object |
| // |
| // A Modulator also serves as an entry point for various module spec algorithms. |
| class CORE_EXPORT Modulator : public GarbageCollectedFinalized<Modulator>, |
| public V8PerContextData::Data, |
| public TraceWrapperBase { |
| USING_GARBAGE_COLLECTED_MIXIN(Modulator); |
| |
| public: |
| static Modulator* From(ScriptState*); |
| virtual ~Modulator(); |
| |
| static void SetModulator(ScriptState*, Modulator*); |
| static void ClearModulator(ScriptState*); |
| |
| DEFINE_INLINE_VIRTUAL_TRACE() {} |
| |
| virtual ScriptModuleResolver* GetScriptModuleResolver() = 0; |
| virtual WebTaskRunner* TaskRunner() = 0; |
| virtual ReferrerPolicy GetReferrerPolicy() = 0; |
| virtual SecurityOrigin* GetSecurityOrigin() = 0; |
| |
| // Synchronously retrieves a single module script from existing module map |
| // entry. |
| virtual ModuleScript* GetFetchedModuleScript(const KURL&) = 0; |
| |
| // https://html.spec.whatwg.org/#resolve-a-module-specifier |
| static KURL ResolveModuleSpecifier(const String& module_request, |
| const KURL& base_url); |
| |
| virtual ScriptModule CompileModule(const String& script, |
| const String& url_str, |
| AccessControlStatus) = 0; |
| |
| virtual ScriptValue InstantiateModule(ScriptModule) = 0; |
| |
| virtual Vector<String> ModuleRequestsFromScriptModule(ScriptModule) = 0; |
| |
| virtual void ExecuteModule(ScriptModule) = 0; |
| |
| private: |
| friend class ModuleMap; |
| |
| // Fetches a single module script. |
| // This is triggered from fetchSingle() implementation (which is in ModuleMap) |
| // if the cached entry doesn't exist. |
| // The client can be notified either synchronously or asynchronously. |
| virtual void FetchNewSingleModule(const ModuleScriptFetchRequest&, |
| ModuleGraphLevel, |
| ModuleScriptLoaderClient*) = 0; |
| }; |
| |
| } // namespace blink |
| |
| #endif |