| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef Modulator_h | 5 #ifndef Modulator_h |
| 6 #define Modulator_h | 6 #define Modulator_h |
| 7 | 7 |
| 8 #include "bindings/core/v8/ScriptWrappable.h" |
| 8 #include "bindings/core/v8/V8PerContextData.h" | 9 #include "bindings/core/v8/V8PerContextData.h" |
| 9 #include "core/CoreExport.h" | 10 #include "core/CoreExport.h" |
| 10 #include "platform/heap/Handle.h" | 11 #include "platform/heap/Handle.h" |
| 11 #include "platform/loader/fetch/AccessControlStatus.h" | 12 #include "platform/loader/fetch/AccessControlStatus.h" |
| 12 #include "platform/weborigin/KURL.h" | 13 #include "platform/weborigin/KURL.h" |
| 13 #include "platform/weborigin/ReferrerPolicy.h" | 14 #include "platform/weborigin/ReferrerPolicy.h" |
| 14 #include "wtf/text/WTFString.h" | 15 #include "wtf/text/WTFString.h" |
| 15 | 16 |
| 16 namespace blink { | 17 namespace blink { |
| 17 | 18 |
| 18 class ModuleScript; | 19 class ModuleScript; |
| 19 class ModuleScriptFetchRequest; | 20 class ModuleScriptFetchRequest; |
| 20 class ModuleScriptLoaderClient; | 21 class ModuleScriptLoaderClient; |
| 21 class ScriptModule; | 22 class ScriptModule; |
| 22 class ScriptModuleResolver; | 23 class ScriptModuleResolver; |
| 23 class ScriptState; | 24 class ScriptState; |
| 25 class ScriptValue; |
| 24 class SecurityOrigin; | 26 class SecurityOrigin; |
| 25 class WebTaskRunner; | 27 class WebTaskRunner; |
| 26 | 28 |
| 27 // A SingleModuleClient is notified when single module script node (node as in a | 29 // A SingleModuleClient is notified when single module script node (node as in a |
| 28 // module tree graph) load is complete and its corresponding entry is created in | 30 // module tree graph) load is complete and its corresponding entry is created in |
| 29 // module map. | 31 // module map. |
| 30 class SingleModuleClient : public GarbageCollectedMixin { | 32 class SingleModuleClient : public GarbageCollectedMixin { |
| 31 public: | 33 public: |
| 32 virtual void NotifyModuleLoadFinished(ModuleScript*) = 0; | 34 virtual void NotifyModuleLoadFinished(ModuleScript*) = 0; |
| 33 }; | 35 }; |
| 34 | 36 |
| 35 // spec: "top-level module fetch flag" | 37 // spec: "top-level module fetch flag" |
| 36 // https://html.spec.whatwg.org/multipage/webappapis.html#fetching-scripts-is-to
p-level | 38 // https://html.spec.whatwg.org/multipage/webappapis.html#fetching-scripts-is-to
p-level |
| 37 enum class ModuleGraphLevel { kTopLevelModuleFetch, kDependentModuleFetch }; | 39 enum class ModuleGraphLevel { kTopLevelModuleFetch, kDependentModuleFetch }; |
| 38 | 40 |
| 39 // A Modulator is an interface for "environment settings object" concept for | 41 // A Modulator is an interface for "environment settings object" concept for |
| 40 // module scripts. | 42 // module scripts. |
| 41 // https://html.spec.whatwg.org/#environment-settings-object | 43 // https://html.spec.whatwg.org/#environment-settings-object |
| 42 // | 44 // |
| 43 // A Modulator also serves as an entry point for various module spec algorithms. | 45 // A Modulator also serves as an entry point for various module spec algorithms. |
| 44 class CORE_EXPORT Modulator : public GarbageCollectedFinalized<Modulator>, | 46 class CORE_EXPORT Modulator : public GarbageCollectedFinalized<Modulator>, |
| 45 public V8PerContextData::Data { | 47 public V8PerContextData::Data, |
| 48 public TraceWrapperBase { |
| 46 USING_GARBAGE_COLLECTED_MIXIN(Modulator); | 49 USING_GARBAGE_COLLECTED_MIXIN(Modulator); |
| 47 | 50 |
| 48 public: | 51 public: |
| 49 static Modulator* From(ScriptState*); | 52 static Modulator* From(ScriptState*); |
| 50 virtual ~Modulator(); | 53 virtual ~Modulator(); |
| 51 | 54 |
| 52 static void SetModulator(ScriptState*, Modulator*); | 55 static void SetModulator(ScriptState*, Modulator*); |
| 53 static void ClearModulator(ScriptState*); | 56 static void ClearModulator(ScriptState*); |
| 54 | 57 |
| 55 DEFINE_INLINE_VIRTUAL_TRACE() {} | 58 DEFINE_INLINE_VIRTUAL_TRACE() {} |
| 56 | 59 |
| 57 virtual ScriptModuleResolver* GetScriptModuleResolver() = 0; | 60 virtual ScriptModuleResolver* GetScriptModuleResolver() = 0; |
| 58 virtual WebTaskRunner* TaskRunner() = 0; | 61 virtual WebTaskRunner* TaskRunner() = 0; |
| 59 virtual ReferrerPolicy GetReferrerPolicy() = 0; | 62 virtual ReferrerPolicy GetReferrerPolicy() = 0; |
| 60 virtual SecurityOrigin* GetSecurityOrigin() = 0; | 63 virtual SecurityOrigin* GetSecurityOrigin() = 0; |
| 61 | 64 |
| 65 // Synchronously retrieves a single module script from existing module map |
| 66 // entry. |
| 67 virtual ModuleScript* GetFetchedModuleScript(const KURL&) = 0; |
| 68 |
| 62 // https://html.spec.whatwg.org/#resolve-a-module-specifier | 69 // https://html.spec.whatwg.org/#resolve-a-module-specifier |
| 63 static KURL ResolveModuleSpecifier(const String& module_request, | 70 static KURL ResolveModuleSpecifier(const String& module_request, |
| 64 const KURL& base_url); | 71 const KURL& base_url); |
| 65 | 72 |
| 66 virtual ScriptModule CompileModule(const String& script, | 73 virtual ScriptModule CompileModule(const String& script, |
| 67 const String& url_str, | 74 const String& url_str, |
| 68 AccessControlStatus) = 0; | 75 AccessControlStatus) = 0; |
| 69 | 76 |
| 77 virtual ScriptValue InstantiateModule(ScriptModule) = 0; |
| 78 |
| 79 virtual Vector<String> ModuleRequestsFromScriptModule(ScriptModule) = 0; |
| 80 |
| 81 virtual void ExecuteModule(ScriptModule) = 0; |
| 82 |
| 70 private: | 83 private: |
| 71 friend class ModuleMap; | 84 friend class ModuleMap; |
| 72 | 85 |
| 73 // Fetches a single module script. | 86 // Fetches a single module script. |
| 74 // This is triggered from fetchSingle() implementation (which is in ModuleMap) | 87 // This is triggered from fetchSingle() implementation (which is in ModuleMap) |
| 75 // if the cached entry doesn't exist. | 88 // if the cached entry doesn't exist. |
| 76 // The client can be notified either synchronously or asynchronously. | 89 // The client can be notified either synchronously or asynchronously. |
| 77 virtual void FetchNewSingleModule(const ModuleScriptFetchRequest&, | 90 virtual void FetchNewSingleModule(const ModuleScriptFetchRequest&, |
| 78 ModuleGraphLevel, | 91 ModuleGraphLevel, |
| 79 ModuleScriptLoaderClient*) = 0; | 92 ModuleScriptLoaderClient*) = 0; |
| 80 }; | 93 }; |
| 81 | 94 |
| 82 } // namespace blink | 95 } // namespace blink |
| 83 | 96 |
| 84 #endif | 97 #endif |
| OLD | NEW |