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/loader/modulescript/ModuleTreeLinker.h" | 5 #include "core/loader/modulescript/ModuleTreeLinker.h" |
6 | 6 |
7 #include "bindings/core/v8/ScriptModule.h" | 7 #include "bindings/core/v8/ScriptModule.h" |
8 #include "core/dom/AncestorList.h" | 8 #include "core/dom/AncestorList.h" |
9 #include "core/dom/ModuleScript.h" | 9 #include "core/dom/ModuleScript.h" |
10 #include "core/loader/modulescript/ModuleScriptFetchRequest.h" | 10 #include "core/loader/modulescript/ModuleScriptFetchRequest.h" |
11 #include "core/loader/modulescript/ModuleTreeLinkerRegistry.h" | 11 #include "core/loader/modulescript/ModuleTreeLinkerRegistry.h" |
| 12 #include "platform/WebTaskRunner.h" |
12 #include "platform/loader/fetch/ResourceLoadingLog.h" | 13 #include "platform/loader/fetch/ResourceLoadingLog.h" |
13 #include "platform/wtf/Vector.h" | 14 #include "platform/wtf/Vector.h" |
14 | 15 |
15 namespace blink { | 16 namespace blink { |
16 | 17 |
17 ModuleTreeLinker* ModuleTreeLinker::Fetch( | 18 ModuleTreeLinker* ModuleTreeLinker::Fetch( |
18 const ModuleScriptFetchRequest& request, | 19 const ModuleScriptFetchRequest& request, |
19 const AncestorList& ancestor_list, | 20 const AncestorList& ancestor_list, |
20 ModuleGraphLevel level, | 21 ModuleGraphLevel level, |
21 Modulator* modulator, | 22 Modulator* modulator, |
22 ModuleTreeLinkerRegistry* registry, | 23 ModuleTreeLinkerRegistry* registry, |
23 ModuleTreeClient* client) { | 24 ModuleTreeClient* client) { |
24 AncestorList ancestor_list_with_url = ancestor_list; | 25 AncestorList ancestor_list_with_url = ancestor_list; |
25 ancestor_list_with_url.insert(request.Url()); | 26 ancestor_list_with_url.insert(request.Url()); |
26 | 27 |
27 ModuleTreeLinker* fetcher = | 28 ModuleTreeLinker* fetcher = |
28 new ModuleTreeLinker(ancestor_list_with_url, modulator, registry, client); | 29 new ModuleTreeLinker(ancestor_list_with_url, modulator, registry, client); |
29 fetcher->FetchSelf(request, level); | 30 fetcher->FetchSelf(request, level); |
30 return fetcher; | 31 return fetcher; |
31 } | 32 } |
32 | 33 |
| 34 ModuleTreeLinker* ModuleTreeLinker::FetchDescendantsForInlineScript( |
| 35 ModuleScript* module_script, |
| 36 Modulator* modulator, |
| 37 ModuleTreeLinkerRegistry* registry, |
| 38 ModuleTreeClient* client) { |
| 39 AncestorList empty_ancestor_list; |
| 40 |
| 41 // Substep 4 in "module" case in Step 22 of "prepare a script":" |
| 42 // https://html.spec.whatwg.org/#prepare-a-script |
| 43 |
| 44 // 4. "Fetch the descendants of script (using an empty ancestor list)." |
| 45 ModuleTreeLinker* fetcher = |
| 46 new ModuleTreeLinker(empty_ancestor_list, modulator, registry, client); |
| 47 fetcher->module_script_ = module_script; |
| 48 fetcher->AdvanceState(State::kFetchingSelf); |
| 49 |
| 50 // "When this asynchronously completes, set the script's script to |
| 51 // the result. At that time, the script is ready." |
| 52 // |
| 53 // Currently we execute "internal module script graph |
| 54 // fetching procedure" Step 5- in addition to "fetch the descendants", |
| 55 // which is not specced yet. https://github.com/whatwg/html/issues/2544 |
| 56 // TODO(hiroshige): Fix the implementation and/or comments once the spec |
| 57 // is updated. |
| 58 modulator->TaskRunner()->PostTask( |
| 59 BLINK_FROM_HERE, |
| 60 WTF::Bind(&ModuleTreeLinker::FetchDescendants, WrapPersistent(fetcher))); |
| 61 return fetcher; |
| 62 } |
| 63 |
33 ModuleTreeLinker::ModuleTreeLinker(const AncestorList& ancestor_list_with_url, | 64 ModuleTreeLinker::ModuleTreeLinker(const AncestorList& ancestor_list_with_url, |
34 Modulator* modulator, | 65 Modulator* modulator, |
35 ModuleTreeLinkerRegistry* registry, | 66 ModuleTreeLinkerRegistry* registry, |
36 ModuleTreeClient* client) | 67 ModuleTreeClient* client) |
37 : modulator_(modulator), | 68 : modulator_(modulator), |
38 registry_(registry), | 69 registry_(registry), |
39 client_(client), | 70 client_(client), |
40 ancestor_list_with_url_(ancestor_list_with_url) { | 71 ancestor_list_with_url_(ancestor_list_with_url) { |
41 CHECK(modulator); | 72 CHECK(modulator); |
42 CHECK(registry); | 73 CHECK(registry); |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 HeapHashSet<Member<ModuleScript>> uninstantiated_set; | 503 HeapHashSet<Member<ModuleScript>> uninstantiated_set; |
473 for (const auto& script : inclusive_descendants) { | 504 for (const auto& script : inclusive_descendants) { |
474 if (script->InstantiationState() == | 505 if (script->InstantiationState() == |
475 ModuleInstantiationState::kUninstantiated) | 506 ModuleInstantiationState::kUninstantiated) |
476 uninstantiated_set.insert(script); | 507 uninstantiated_set.insert(script); |
477 } | 508 } |
478 return uninstantiated_set; | 509 return uninstantiated_set; |
479 } | 510 } |
480 | 511 |
481 } // namespace blink | 512 } // namespace blink |
OLD | NEW |