OLD | NEW |
---|---|
(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 #include "core/dom/ModulatorImpl.h" | |
6 | |
7 #include "core/dom/Document.h" | |
8 #include "core/dom/ExecutionContext.h" | |
9 #include "core/dom/ModuleMap.h" | |
10 #include "core/dom/ModuleScript.h" | |
11 #include "core/dom/ScriptModuleResolverImpl.h" | |
12 #include "core/dom/TaskRunnerHelper.h" | |
13 #include "core/frame/LocalFrame.h" | |
14 #include "core/loader/modulescript/ModuleScriptFetchRequest.h" | |
15 #include "core/loader/modulescript/ModuleScriptLoaderRegistry.h" | |
16 #include "platform/loader/fetch/ResourceFetcher.h" | |
17 | |
18 namespace blink { | |
19 | |
20 ModulatorImpl* ModulatorImpl::Create(RefPtr<ScriptState> script_state, | |
21 Document& document) { | |
22 return new ModulatorImpl( | |
23 std::move(script_state), | |
24 TaskRunnerHelper::Get(TaskType::kNetworking, &document), &document, | |
25 document.Fetcher()); | |
26 } | |
27 | |
28 ModulatorImpl::ModulatorImpl(RefPtr<ScriptState> script_state, | |
29 RefPtr<WebTaskRunner> task_runner, | |
30 ExecutionContext* execution_context, | |
nhiroki
2017/04/19 03:15:47
We might not have to pass |execution_context| here
kouhei (in TOK)
2017/04/19 03:38:53
Done.
| |
31 ResourceFetcher* fetcher) | |
32 : script_state_(std::move(script_state)), | |
33 task_runner_(std::move(task_runner)), | |
34 execution_context_(execution_context), | |
35 fetcher_(fetcher), | |
36 map_(this, ModuleMap::Create(this)), | |
37 loader_registry_(ModuleScriptLoaderRegistry::Create()), | |
38 script_module_resolver_(ScriptModuleResolverImpl::Create(this)) { | |
39 DCHECK(script_state_); | |
40 DCHECK(task_runner_); | |
41 DCHECK(execution_context_); | |
42 DCHECK(fetcher_); | |
43 } | |
44 | |
45 ModulatorImpl::~ModulatorImpl() {} | |
46 | |
47 ReferrerPolicy ModulatorImpl::GetReferrerPolicy() { | |
48 return execution_context_->GetReferrerPolicy(); | |
49 } | |
50 | |
51 SecurityOrigin* ModulatorImpl::GetSecurityOrigin() { | |
52 return execution_context_->GetSecurityOrigin(); | |
53 } | |
54 | |
55 void ModulatorImpl::FetchTree(const ModuleScriptFetchRequest& request, | |
56 ModuleTreeClient* client) { | |
57 // Step 1. Perform the internal module script graph fetching procedure given | |
58 // url, settings object, destination, cryptographic nonce, parser state, | |
59 // credentials mode, settings object, a new empty list, "client", and with the | |
60 // top-level module fetch flag set. If the caller of this algorithm specified | |
61 // custom perform the fetch steps, pass those along as well. | |
62 | |
63 // Note: "Fetch a module script graph" algorithm doesn't have "referrer" as | |
64 // its argument. | |
65 DCHECK(request.GetReferrer().IsNull()); | |
66 | |
67 AncestorList empty_ancestor_list; | |
68 FetchTreeInternal(request, empty_ancestor_list, | |
69 ModuleGraphLevel::kTopLevelModuleFetch, client); | |
70 | |
71 // Step 2. When the internal module script graph fetching procedure | |
72 // asynchronously completes with result, asynchronously complete this | |
73 // algorithm with result. | |
74 // Note: We delegate to ModuleTreeLinker to notify ModuleTreeClient. | |
75 } | |
76 | |
77 void ModulatorImpl::FetchTreeInternal(const ModuleScriptFetchRequest& request, | |
78 const AncestorList& ancestor_list, | |
79 ModuleGraphLevel level, | |
80 ModuleTreeClient* client) { | |
81 NOTIMPLEMENTED(); | |
82 } | |
83 | |
84 void ModulatorImpl::FetchSingle(const ModuleScriptFetchRequest& request, | |
85 ModuleGraphLevel level, | |
86 SingleModuleClient* client) { | |
87 map_->FetchSingleModuleScript(request, level, client); | |
88 } | |
89 | |
90 void ModulatorImpl::FetchNewSingleModule( | |
91 const ModuleScriptFetchRequest& request, | |
92 ModuleGraphLevel level, | |
93 ModuleScriptLoaderClient* client) { | |
94 loader_registry_->Fetch(request, level, this, fetcher_.Get(), client); | |
95 } | |
96 | |
97 ModuleScript* ModulatorImpl::GetFetchedModuleScript(const KURL& url) { | |
98 return map_->GetFetchedModuleScript(url); | |
99 } | |
100 | |
101 ScriptModule ModulatorImpl::CompileModule( | |
102 const String& provided_source, | |
103 const String& url_str, | |
104 AccessControlStatus access_control_status) { | |
105 // Implements Steps 3-6 of | |
106 // https://html.spec.whatwg.org/multipage/webappapis.html#creating-a-module-sc ript | |
107 | |
108 // Step 3. Let realm be the provided environment settings object's Realm. | |
109 // Note: Realm is v8::Context. | |
110 | |
111 // Step 4. If scripting is disabled for the given environment settings | |
112 // object's responsible browsing context, then let script source be the empty | |
113 // string. Otherwise, let script source be the provided script source. | |
114 String script_source; | |
115 if (execution_context_->CanExecuteScripts(kAboutToExecuteScript)) | |
116 script_source = provided_source; | |
117 | |
118 // Step 5. Let result be ParseModule(script source, realm, script). | |
119 // Step 6. If result is a List of errors, report the exception given by the | |
120 // first element of result for script, return null, and abort these steps. | |
121 // Note: reporting is routed via V8Initializer::messageHandlerInMainThread. | |
122 ScriptState::Scope scope(script_state_.Get()); | |
123 return ScriptModule::Compile(script_state_->GetIsolate(), script_source, | |
124 url_str, access_control_status); | |
125 } | |
126 | |
127 ScriptValue ModulatorImpl::InstantiateModule(ScriptModule script_module) { | |
128 ScriptState::Scope scope(script_state_.Get()); | |
129 return script_module.Instantiate(script_state_.Get()); | |
130 } | |
131 | |
132 Vector<String> ModulatorImpl::ModuleRequestsFromScriptModule( | |
133 ScriptModule script_module) { | |
134 ScriptState::Scope scope(script_state_.Get()); | |
135 return script_module.ModuleRequests(script_state_.Get()); | |
136 } | |
137 | |
138 DEFINE_TRACE(ModulatorImpl) { | |
139 Modulator::Trace(visitor); | |
140 visitor->Trace(execution_context_); | |
141 visitor->Trace(fetcher_); | |
142 visitor->Trace(map_); | |
143 visitor->Trace(loader_registry_); | |
144 visitor->Trace(script_module_resolver_); | |
145 } | |
146 | |
147 DEFINE_TRACE_WRAPPERS(ModulatorImpl) { | |
148 visitor->TraceWrappers(map_); | |
149 } | |
150 | |
151 } // namespace blink | |
OLD | NEW |