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

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

Issue 2555653002: [WIP Prototype] ES6 https://html.spec.whatwg.org/#fetch-a-single-module-script implementation (Closed)
Patch Set: ModuleScriptLoaderTest Created 3 years, 11 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/fetch/ResourceOwner.h"
10 #include "core/loader/resource/ScriptResource.h"
11 #include "platform/heap/Handle.h"
12 #include "platform/weborigin/KURL.h"
13
14 namespace blink {
15
16 class ModuleController;
17 class ModuleScript;
18 class ModuleScriptLoaderRegistry;
19 class ModuleScriptLoaderClient;
20
21 // A ModuleScriptLoader is responsible for loading a new single ModuleScript.
22 //
23 // A ModuleScriptLoader constructs and emit FetchRequest to RequestFetcher (via
24 // ScriptResource::fetch).
25 // Then, it keeps track of the fetch progress by being a ScriptResourceClient.
26 // Finally, it return its client a compiled ModuleScript.
27 //
28 // ModuleLoaders should only be used via Modulator and its ModuleMap.
29 class CORE_EXPORT ModuleScriptLoader final
30 : public GarbageCollectedFinalized<ModuleScriptLoader>,
31 public ResourceOwner<ScriptResource> {
32 WTF_MAKE_NONCOPYABLE(ModuleScriptLoader);
33 USING_GARBAGE_COLLECTED_MIXIN(ModuleScriptLoader);
34
35 enum class State {
36 Initial,
37 // FetchRequest is being processed, and ModuleScriptLoader hasn't
38 // notifyFinished().
39 Fetching,
40 // Finished successfully or w/ error.
41 Finished,
42 };
43
44 public:
45 static ModuleScriptLoader* create(const KURL& url,
46 const KURL& baseURL,
47 ModuleController* moduleController,
48 ModuleScriptLoaderRegistry* registry,
49 ModuleScriptLoaderClient* client) {
50 return new ModuleScriptLoader(url, baseURL, moduleController, registry,
51 client);
52 }
53
54 virtual ~ModuleScriptLoader();
55
56 void fetch(ResourceFetcher*);
57
58 bool isInitialState() const { return m_state == State::Initial; }
59 bool hasFinished() const { return m_state == State::Finished; }
60
61 DECLARE_TRACE();
62
63 private:
64 explicit ModuleScriptLoader(const KURL&,
65 const KURL& baseURL,
66 ModuleController*,
67 ModuleScriptLoaderRegistry*,
68 ModuleScriptLoaderClient*);
69
70 void advanceState(State newState);
71
72 // Implements ScriptResourceClient
73 void notifyFinished(Resource*) override;
74 String debugName() const override { return "ModuleScriptLoader"; }
75
76 // TODO(kouhei): May be this method should live in ModuleResource? or should
77 // it be here to consolidate the spec impl code in ModuleMap.cpp?
78 static bool wasModuleLoadSuccessful(Resource*);
79
80 KURL m_url;
81 KURL m_baseURL;
82 Member<ModuleController> m_moduleController;
83 State m_state = State::Initial;
84 Member<ModuleScript> m_moduleScript;
85 Member<ModuleScriptLoaderRegistry> m_registry;
86 Member<ModuleScriptLoaderClient> m_client;
87 };
88
89 } // namespace blink
90
91 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698