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 "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
| 9 #include "core/dom/AncestorList.h" |
9 #include "platform/heap/Handle.h" | 10 #include "platform/heap/Handle.h" |
10 #include "platform/weborigin/KURL.h" | 11 #include "platform/weborigin/KURL.h" |
| 12 #include "platform/weborigin/ReferrerPolicy.h" |
| 13 #include "wtf/text/WTFString.h" |
11 | 14 |
12 namespace blink { | 15 namespace blink { |
13 | 16 |
| 17 class ExecutionContext; |
14 class LocalFrame; | 18 class LocalFrame; |
| 19 class ModuleScript; |
| 20 class ModuleScriptLoaderClient; |
| 21 class ScriptModule; |
| 22 class ScriptModuleResolver; |
| 23 class ScriptValue; |
| 24 class WebTaskRunner; |
| 25 class ModuleScriptFetchRequest; |
| 26 |
| 27 // 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 |
| 29 // module map. |
| 30 class SingleModuleClient : public GarbageCollectedMixin { |
| 31 public: |
| 32 virtual void notifyModuleLoadFinished(ModuleScript*) = 0; |
| 33 }; |
| 34 |
| 35 // A ModuleTreeClient is notified when a module script and its whole descendent |
| 36 // tree load is complete. |
| 37 class ModuleTreeClient : public GarbageCollectedMixin { |
| 38 public: |
| 39 virtual void notifyModuleTreeLoadFinished(ModuleScript*) = 0; |
| 40 }; |
| 41 |
| 42 // spec: "top-level module fetch flag" |
| 43 enum class ModuleGraphLevel { TopLevelModuleFetch, DependentModuleFetch }; |
15 | 44 |
16 // A Modulator is an interface for "environment settings object" concept for | 45 // A Modulator is an interface for "environment settings object" concept for |
17 // module scripts. | 46 // module scripts. |
18 // https://html.spec.whatwg.org/#environment-settings-object | 47 // https://html.spec.whatwg.org/#environment-settings-object |
19 // | 48 // |
20 // A Modulator also serves as an entry point for various module spec algorithms. | 49 // A Modulator also serves as an entry point for various module spec algorithms. |
21 class CORE_EXPORT Modulator : public GarbageCollectedMixin { | 50 class CORE_EXPORT Modulator : public GarbageCollectedMixin { |
22 public: | 51 public: |
23 static Modulator* from(LocalFrame*); | 52 static Modulator* from(LocalFrame*); |
24 | 53 |
| 54 virtual ScriptModuleResolver* scriptModuleResolver() = 0; |
| 55 virtual WebTaskRunner* taskRunner() = 0; |
| 56 virtual ExecutionContext* executionContext() = 0; |
| 57 virtual ReferrerPolicy referrerPolicy() = 0; |
| 58 |
| 59 // https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-module-scrip
t-tree |
| 60 virtual void fetchTree(const ModuleScriptFetchRequest&, |
| 61 ModuleTreeClient*) = 0; |
| 62 |
| 63 // https://html.spec.whatwg.org/#internal-module-script-graph-fetching-procedu
re |
| 64 virtual void fetchTreeInternal(const ModuleScriptFetchRequest&, |
| 65 const AncestorList&, |
| 66 ModuleGraphLevel, |
| 67 ModuleTreeClient*) = 0; |
| 68 |
| 69 // Asynchronously retrieve a module script from the module map, or fetch it |
| 70 // and put it in the map if it's not there already. |
| 71 // https://html.spec.whatwg.org/#fetch-a-single-module-script |
| 72 virtual void fetchSingle(const ModuleScriptFetchRequest&, |
| 73 ModuleGraphLevel, |
| 74 SingleModuleClient*) = 0; |
| 75 |
| 76 // Synchronously retrieves a single module script from existing module map |
| 77 // entry. |
| 78 virtual ModuleScript* retrieveFetchedModuleScript(const KURL&) = 0; |
| 79 |
25 // https://html.spec.whatwg.org/#resolve-a-module-specifier | 80 // https://html.spec.whatwg.org/#resolve-a-module-specifier |
26 static KURL resolveModuleSpecifier(const String& moduleRequest, | 81 static KURL resolveModuleSpecifier(const String& moduleRequest, |
27 const KURL& baseURL); | 82 const KURL& baseURL); |
| 83 |
| 84 // TODO(kouhei): script should be a ScriptSourceCode. |
| 85 virtual ScriptModule compileModule(const String& script, |
| 86 const String& urlStr) = 0; |
| 87 |
| 88 virtual ScriptValue instantiateModule(ScriptModule) = 0; |
| 89 |
| 90 virtual Vector<String> moduleRequestsFromScriptModule(ScriptModule) = 0; |
| 91 |
| 92 virtual void executeModule(ScriptModule) = 0; |
| 93 |
| 94 private: |
| 95 friend class ModuleMap; |
| 96 |
| 97 // Asynchronously fetches a single module script. |
| 98 // This is triggered from fetchSingle() implementation (which is ModuleMap) if |
| 99 // the cached entry doesn't exist. |
| 100 virtual void fetchNewSingleModule(const ModuleScriptFetchRequest&, |
| 101 ModuleGraphLevel, |
| 102 ModuleScriptLoaderClient*) = 0; |
28 }; | 103 }; |
29 | 104 |
30 } // namespace blink | 105 } // namespace blink |
31 | 106 |
32 #endif | 107 #endif |
OLD | NEW |