Chromium Code Reviews| 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 #include "core/dom/ModuleMap.h" | 5 #include "core/dom/ModuleMap.h" | 
| 6 | 6 | 
| 7 #include "core/dom/Modulator.h" | 7 #include "core/dom/Modulator.h" | 
| 8 #include "core/dom/ModuleScript.h" | 8 #include "core/dom/ModuleScript.h" | 
| 9 #include "core/dom/ScriptModuleResolver.h" | 9 #include "core/dom/ScriptModuleResolver.h" | 
| 10 #include "core/loader/modulescript/ModuleScriptFetchRequest.h" | 10 #include "core/loader/modulescript/ModuleScriptFetchRequest.h" | 
| 11 #include "core/loader/modulescript/ModuleScriptLoaderClient.h" | 11 #include "core/loader/modulescript/ModuleScriptLoaderClient.h" | 
| 12 #include "platform/WebTaskRunner.h" | 12 #include "platform/WebTaskRunner.h" | 
| 13 | 13 | 
| 14 namespace blink { | 14 namespace blink { | 
| 15 | 15 | 
| 16 // Entry struct represents a value in "module map" spec object. | 16 // Entry struct represents a value in "module map" spec object. | 
| 17 // https://html.spec.whatwg.org/multipage/webappapis.html#module-map | 17 // https://html.spec.whatwg.org/multipage/webappapis.html#module-map | 
| 18 class ModuleMap::Entry final : public GarbageCollectedFinalized<Entry>, | 18 class ModuleMap::Entry final : public GarbageCollectedFinalized<Entry>, | 
| 19 public TraceWrapperBase, | |
| 19 public ModuleScriptLoaderClient { | 20 public ModuleScriptLoaderClient { | 
| 20 USING_GARBAGE_COLLECTED_MIXIN(ModuleMap::Entry); | 21 USING_GARBAGE_COLLECTED_MIXIN(ModuleMap::Entry); | 
| 21 | 22 | 
| 22 public: | 23 public: | 
| 23 static Entry* create(ModuleMap* map) { return new Entry(map); } | 24 static Entry* create(ModuleMap* map) { return new Entry(map); } | 
| 24 ~Entry() override {} | 25 ~Entry() override {} | 
| 25 | 26 | 
| 26 DECLARE_TRACE(); | 27 DECLARE_TRACE(); | 
| 28 DECLARE_VIRTUAL_TRACE_WRAPPERS(); | |
| 
 
yhirano
2017/04/05 05:56:46
ditto
 
kouhei (in TOK)
2017/04/05 07:51:43
Done.
 
 | |
| 27 | 29 | 
| 28 // Notify fetched |m_moduleScript| to the client asynchronously. | 30 // Notify fetched |m_moduleScript| to the client asynchronously. | 
| 29 void addClient(SingleModuleClient*); | 31 void addClient(SingleModuleClient*); | 
| 30 | 32 | 
| 31 // This is only to be used from ScriptModuleResolver implementations. | 33 // This is only to be used from ScriptModuleResolver implementations. | 
| 32 ModuleScript* getModuleScript() const; | 34 ModuleScript* getModuleScript() const; | 
| 33 | 35 | 
| 34 private: | 36 private: | 
| 35 explicit Entry(ModuleMap*); | 37 explicit Entry(ModuleMap*); | 
| 36 | 38 | 
| 37 void dispatchFinishedNotificationAsync(SingleModuleClient*); | 39 void dispatchFinishedNotificationAsync(SingleModuleClient*); | 
| 38 | 40 | 
| 39 // Implements ModuleScriptLoaderClient | 41 // Implements ModuleScriptLoaderClient | 
| 40 void notifyNewSingleModuleFinished(ModuleScript*) override; | 42 void notifyNewSingleModuleFinished(ModuleScript*) override; | 
| 41 | 43 | 
| 42 Member<ModuleScript> m_moduleScript; | 44 TraceWrapperMember<ModuleScript> m_moduleScript; | 
| 43 Member<ModuleMap> m_map; | 45 Member<ModuleMap> m_map; | 
| 44 | 46 | 
| 45 // Correspond to the HTML spec: "fetching" state. | 47 // Correspond to the HTML spec: "fetching" state. | 
| 46 bool m_isFetching = true; | 48 bool m_isFetching = true; | 
| 47 | 49 | 
| 48 HeapHashSet<Member<SingleModuleClient>> m_clients; | 50 HeapHashSet<Member<SingleModuleClient>> m_clients; | 
| 49 }; | 51 }; | 
| 50 | 52 | 
| 51 ModuleMap::Entry::Entry(ModuleMap* map) : m_map(map) { | 53 ModuleMap::Entry::Entry(ModuleMap* map) | 
| 54 : m_moduleScript(this, nullptr), m_map(map) { | |
| 52 DCHECK(m_map); | 55 DCHECK(m_map); | 
| 53 } | 56 } | 
| 54 | 57 | 
| 55 DEFINE_TRACE(ModuleMap::Entry) { | 58 DEFINE_TRACE(ModuleMap::Entry) { | 
| 56 visitor->trace(m_moduleScript); | 59 visitor->trace(m_moduleScript); | 
| 57 visitor->trace(m_map); | 60 visitor->trace(m_map); | 
| 58 visitor->trace(m_clients); | 61 visitor->trace(m_clients); | 
| 59 } | 62 } | 
| 60 | 63 | 
| 64 DEFINE_TRACE_WRAPPERS(ModuleMap::Entry) { | |
| 65 visitor->traceWrappers(m_moduleScript); | |
| 66 } | |
| 67 | |
| 61 void ModuleMap::Entry::dispatchFinishedNotificationAsync( | 68 void ModuleMap::Entry::dispatchFinishedNotificationAsync( | 
| 62 SingleModuleClient* client) { | 69 SingleModuleClient* client) { | 
| 63 m_map->modulator()->taskRunner()->postTask( | 70 m_map->modulator()->taskRunner()->postTask( | 
| 64 BLINK_FROM_HERE, | 71 BLINK_FROM_HERE, | 
| 65 WTF::bind(&SingleModuleClient::notifyModuleLoadFinished, | 72 WTF::bind(&SingleModuleClient::notifyModuleLoadFinished, | 
| 66 wrapPersistent(client), wrapPersistent(m_moduleScript.get()))); | 73 wrapPersistent(client), wrapPersistent(m_moduleScript.get()))); | 
| 67 } | 74 } | 
| 68 | 75 | 
| 69 void ModuleMap::Entry::addClient(SingleModuleClient* newClient) { | 76 void ModuleMap::Entry::addClient(SingleModuleClient* newClient) { | 
| 70 DCHECK(!m_clients.contains(newClient)); | 77 DCHECK(!m_clients.contains(newClient)); | 
| (...skipping 30 matching lines...) Expand all Loading... | |
| 101 | 108 | 
| 102 ModuleMap::ModuleMap(Modulator* modulator) : m_modulator(modulator) { | 109 ModuleMap::ModuleMap(Modulator* modulator) : m_modulator(modulator) { | 
| 103 DCHECK(modulator); | 110 DCHECK(modulator); | 
| 104 } | 111 } | 
| 105 | 112 | 
| 106 DEFINE_TRACE(ModuleMap) { | 113 DEFINE_TRACE(ModuleMap) { | 
| 107 visitor->trace(m_map); | 114 visitor->trace(m_map); | 
| 108 visitor->trace(m_modulator); | 115 visitor->trace(m_modulator); | 
| 109 } | 116 } | 
| 110 | 117 | 
| 118 DEFINE_TRACE_WRAPPERS(ModuleMap) { | |
| 119 for (const auto& it : m_map) | |
| 120 visitor->traceWrappers(it.value); | |
| 121 } | |
| 122 | |
| 111 void ModuleMap::fetchSingleModuleScript(const ModuleScriptFetchRequest& request, | 123 void ModuleMap::fetchSingleModuleScript(const ModuleScriptFetchRequest& request, | 
| 112 ModuleGraphLevel level, | 124 ModuleGraphLevel level, | 
| 113 SingleModuleClient* client) { | 125 SingleModuleClient* client) { | 
| 114 // https://html.spec.whatwg.org/#fetch-a-single-module-script | 126 // https://html.spec.whatwg.org/#fetch-a-single-module-script | 
| 115 | 127 | 
| 116 // Step 1. Let moduleMap be module map settings object's module map. | 128 // Step 1. Let moduleMap be module map settings object's module map. | 
| 117 // Note: This is the ModuleMap. | 129 // Note: This is the ModuleMap. | 
| 118 | 130 | 
| 119 // Step 2. If moduleMap[url] is "fetching", wait in parallel until that | 131 // Step 2. If moduleMap[url] is "fetching", wait in parallel until that | 
| 120 // entry's value changes, then queue a task on the networking task source to | 132 // entry's value changes, then queue a task on the networking task source to | 
| 121 // proceed with running the following steps. | 133 // proceed with running the following steps. | 
| 122 MapImpl::AddResult result = m_map.insert(request.url(), nullptr); | 134 MapImpl::AddResult result = m_map.insert(request.url(), nullptr); | 
| 123 Member<Entry>& entry = result.storedValue->value; | 135 TraceWrapperMember<Entry>& entry = result.storedValue->value; | 
| 124 if (result.isNewEntry) { | 136 if (result.isNewEntry) { | 
| 125 entry = Entry::create(this); | 137 entry = TraceWrapperMember<Entry>(this, Entry::create(this)); | 
| 126 | 138 | 
| 127 // Steps 4-9 loads a new single module script. | 139 // Steps 4-9 loads a new single module script. | 
| 128 // Delegates to ModuleScriptLoader via Modulator. | 140 // Delegates to ModuleScriptLoader via Modulator. | 
| 129 m_modulator->fetchNewSingleModule(request, level, entry); | 141 m_modulator->fetchNewSingleModule(request, level, entry); | 
| 130 } | 142 } | 
| 131 DCHECK(entry); | 143 DCHECK(entry); | 
| 132 | 144 | 
| 133 // Step 3. If moduleMap[url] exists, asynchronously complete this algorithm | 145 // Step 3. If moduleMap[url] exists, asynchronously complete this algorithm | 
| 134 // with moduleMap[url], and abort these steps. | 146 // with moduleMap[url], and abort these steps. | 
| 135 // Step 10. Set moduleMap[url] to module script, and asynchronously complete | 147 // Step 10. Set moduleMap[url] to module script, and asynchronously complete | 
| 136 // this algorithm with module script. | 148 // this algorithm with module script. | 
| 137 entry->addClient(client); | 149 entry->addClient(client); | 
| 138 } | 150 } | 
| 139 | 151 | 
| 140 ModuleScript* ModuleMap::getFetchedModuleScript(const KURL& url) const { | 152 ModuleScript* ModuleMap::getFetchedModuleScript(const KURL& url) const { | 
| 141 MapImpl::const_iterator it = m_map.find(url); | 153 MapImpl::const_iterator it = m_map.find(url); | 
| 142 CHECK_NE(it, m_map.end()); | 154 CHECK_NE(it, m_map.end()); | 
| 143 return it->value->getModuleScript(); | 155 return it->value->getModuleScript(); | 
| 144 } | 156 } | 
| 145 | 157 | 
| 146 } // namespace blink | 158 } // namespace blink | 
| OLD | NEW |