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

Side by Side Diff: third_party/WebKit/Source/core/dom/ModulatorImpl.cpp

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

Powered by Google App Engine
This is Rietveld 408576698