Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: third_party/WebKit/Source/core/loader/modulescript/ModuleScriptLoader.h

Issue 2697073002: [ES6 modules] Introduce ModuleScriptLoader (Closed)
Patch Set: rebased Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef ModuleScriptLoader_h
6 #define ModuleScriptLoader_h
7
8 #include "core/CoreExport.h"
9 #include "core/loader/modulescript/ModuleScriptFetchRequest.h"
10 #include "core/loader/resource/ScriptResource.h"
11 #include "platform/heap/Handle.h"
12 #include "platform/loader/fetch/ResourceLoaderOptions.h"
13 #include "platform/loader/fetch/ResourceOwner.h"
14 #include "platform/weborigin/KURL.h"
15 #include "public/platform/WebURLRequest.h"
16
17 namespace blink {
18
19 class Modulator;
20 class ModuleScript;
21 class ModuleScriptLoaderClient;
22 class ModuleScriptLoaderRegistry;
23 enum class ModuleGraphLevel;
24
25 // A ModuleScriptLoader is responsible for loading a new single ModuleScript.
26 //
27 // A ModuleScriptLoader constructs and emits FetchRequest to ResourceFetcher
28 // (via ScriptResource::fetch). Then, it keeps track of the fetch progress by
29 // being a ScriptResourceClient. Finally, it returns its client a compiled
30 // ModuleScript.
31 //
32 // ModuleScriptLoader(s) should only be used via Modulator and its ModuleMap.
33 class CORE_EXPORT ModuleScriptLoader final
34 : public GarbageCollectedFinalized<ModuleScriptLoader>,
35 public ResourceOwner<ScriptResource> {
36 WTF_MAKE_NONCOPYABLE(ModuleScriptLoader);
37 USING_GARBAGE_COLLECTED_MIXIN(ModuleScriptLoader);
38
39 enum class State {
40 Initial,
41 // FetchRequest is being processed, and ModuleScriptLoader hasn't
42 // notifyFinished().
43 Fetching,
44 // Finished successfully or w/ error.
45 Finished,
46 };
47
48 public:
49 static ModuleScriptLoader* create(Modulator* modulator,
50 ModuleScriptLoaderRegistry* registry,
51 ModuleScriptLoaderClient* client) {
52 return new ModuleScriptLoader(modulator, registry, client);
53 }
54
55 ~ModuleScriptLoader() override;
56
57 // Note: fetch may notify |m_client| synchronously or asynchronously.
58 void fetch(const ModuleScriptFetchRequest&,
59 ResourceFetcher*,
60 ModuleGraphLevel);
61
62 bool isInitialState() const { return m_state == State::Initial; }
63 bool hasFinished() const { return m_state == State::Finished; }
64
65 DECLARE_TRACE();
66
67 private:
68 ModuleScriptLoader(Modulator*,
69 ModuleScriptLoaderRegistry*,
70 ModuleScriptLoaderClient*);
71
72 static ModuleScript* createModuleScript(const String& sourceText,
73 const KURL&,
74 Modulator*,
75 const String& nonce,
76 ParserDisposition,
77 WebURLRequest::FetchCredentialsMode);
78
79 void advanceState(State newState);
80 #if DCHECK_IS_ON()
81 static const char* stateToString(State);
82 #endif
83
84 // Implements ScriptResourceClient
85 void notifyFinished(Resource*) override;
86 String debugName() const override { return "ModuleScriptLoader"; }
87
88 static bool wasModuleLoadSuccessful(Resource*);
89
90 Member<Modulator> m_modulator;
91 State m_state = State::Initial;
92 String m_nonce;
93 ParserDisposition m_parserState;
94 Member<ModuleScript> m_moduleScript;
95 Member<ModuleScriptLoaderRegistry> m_registry;
96 Member<ModuleScriptLoaderClient> m_client;
97 #if DCHECK_IS_ON()
98 KURL m_url;
99 #endif
100 };
101
102 } // namespace blink
103
104 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698