OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/workers/Worklet.h" | 5 #include "core/workers/Worklet.h" |
6 | 6 |
7 #include "bindings/core/v8/ScriptPromiseResolver.h" | 7 #include "bindings/core/v8/ScriptPromiseResolver.h" |
8 #include "core/dom/DOMException.h" | 8 #include "core/dom/DOMException.h" |
9 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
10 #include "core/dom/TaskRunnerHelper.h" | 10 #include "core/dom/TaskRunnerHelper.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 return WebURLRequest::kFetchCredentialsModeSameOrigin; | 26 return WebURLRequest::kFetchCredentialsModeSameOrigin; |
27 if (credentials_option == "include") | 27 if (credentials_option == "include") |
28 return WebURLRequest::kFetchCredentialsModeInclude; | 28 return WebURLRequest::kFetchCredentialsModeInclude; |
29 NOTREACHED(); | 29 NOTREACHED(); |
30 return WebURLRequest::kFetchCredentialsModeOmit; | 30 return WebURLRequest::kFetchCredentialsModeOmit; |
31 } | 31 } |
32 | 32 |
33 } // namespace | 33 } // namespace |
34 | 34 |
35 Worklet::Worklet(LocalFrame* frame) | 35 Worklet::Worklet(LocalFrame* frame) |
36 : ContextLifecycleObserver(frame->GetDocument()) { | 36 : ContextLifecycleObserver(frame->GetDocument()), |
| 37 module_responses_map_(new WorkletModuleResponsesMap) { |
37 DCHECK(IsMainThread()); | 38 DCHECK(IsMainThread()); |
38 } | 39 } |
39 | 40 |
40 Worklet::~Worklet() { | 41 Worklet::~Worklet() { |
41 for (const auto& proxy : proxies_) | 42 for (const auto& proxy : proxies_) |
42 proxy->WorkletObjectDestroyed(); | 43 proxy->WorkletObjectDestroyed(); |
43 } | 44 } |
44 | 45 |
45 // Implementation of the first half of the "addModule(moduleURL, options)" | 46 // Implementation of the first half of the "addModule(moduleURL, options)" |
46 // algorithm: | 47 // algorithm: |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 | 117 |
117 // Step 7: "Let outsideSettings be the relevant settings object of this." | 118 // Step 7: "Let outsideSettings be the relevant settings object of this." |
118 // In the specification, outsideSettings is used for posting a task to the | 119 // In the specification, outsideSettings is used for posting a task to the |
119 // document's responsible event loop. In our implementation, we use the | 120 // document's responsible event loop. In our implementation, we use the |
120 // document's UnspecedLoading task runner as that is what we commonly use for | 121 // document's UnspecedLoading task runner as that is what we commonly use for |
121 // module loading. | 122 // module loading. |
122 RefPtr<WebTaskRunner> outside_settings_task_runner = | 123 RefPtr<WebTaskRunner> outside_settings_task_runner = |
123 TaskRunnerHelper::Get(TaskType::kUnspecedLoading, GetExecutionContext()); | 124 TaskRunnerHelper::Get(TaskType::kUnspecedLoading, GetExecutionContext()); |
124 | 125 |
125 // Step 8: "Let moduleResponsesMap be worklet's module responses map." | 126 // Step 8: "Let moduleResponsesMap be worklet's module responses map." |
126 // TODO(nhiroki): Implement moduleResponsesMap (https://crbug.com/627945). | 127 WorkletModuleResponsesMap* module_responses_map = module_responses_map_; |
127 | 128 |
128 // Step 9: "Let workletGlobalScopeType be worklet's worklet global scope | 129 // Step 9: "Let workletGlobalScopeType be worklet's worklet global scope |
129 // type." | 130 // type." |
130 // workletGlobalScopeType is encoded into the class name (e.g., PaintWorklet). | 131 // workletGlobalScopeType is encoded into the class name (e.g., PaintWorklet). |
131 | 132 |
132 // Step 10: "If the worklet's WorkletGlobalScopes is empty, run the following | 133 // Step 10: "If the worklet's WorkletGlobalScopes is empty, run the following |
133 // steps:" | 134 // steps:" |
134 // 10.1: "Create a WorkletGlobalScope given workletGlobalScopeType, | 135 // 10.1: "Create a WorkletGlobalScope given workletGlobalScopeType, |
135 // moduleResponsesMap, and outsideSettings." | 136 // moduleResponsesMap, and outsideSettings." |
136 // 10.2: "Add the WorkletGlobalScope to worklet's WorkletGlobalScopes." | 137 // 10.2: "Add the WorkletGlobalScope to worklet's WorkletGlobalScopes." |
137 // "Depending on the type of worklet the user agent may create additional | 138 // "Depending on the type of worklet the user agent may create additional |
138 // WorkletGlobalScopes at this time." | 139 // WorkletGlobalScopes at this time." |
139 while (NeedsToCreateGlobalScope()) | 140 while (NeedsToCreateGlobalScope()) |
140 proxies_.insert(CreateGlobalScope()); | 141 proxies_.insert(CreateGlobalScope()); |
141 DCHECK_EQ(1u, GetNumberOfGlobalScopes()); | 142 DCHECK_EQ(1u, GetNumberOfGlobalScopes()); |
142 | 143 |
143 // Step 11: "Let pendingTaskStruct be a new pending tasks struct with counter | 144 // Step 11: "Let pendingTaskStruct be a new pending tasks struct with counter |
144 // initialized to the length of worklet's WorkletGlobalScopes." | 145 // initialized to the length of worklet's WorkletGlobalScopes." |
145 WorkletPendingTasks* pending_tasks = | 146 WorkletPendingTasks* pending_tasks = |
146 new WorkletPendingTasks(GetNumberOfGlobalScopes(), resolver); | 147 new WorkletPendingTasks(GetNumberOfGlobalScopes(), resolver); |
147 | 148 |
148 // Step 12: "For each workletGlobalScope in the worklet's | 149 // Step 12: "For each workletGlobalScope in the worklet's |
149 // WorkletGlobalScopes, queue a task on the workletGlobalScope to fetch and | 150 // WorkletGlobalScopes, queue a task on the workletGlobalScope to fetch and |
150 // invoke a worklet script given workletGlobalScope, moduleURLRecord, | 151 // invoke a worklet script given workletGlobalScope, moduleURLRecord, |
151 // moduleResponsesMap, credentialOptions, outsideSettings, pendingTaskStruct, | 152 // moduleResponsesMap, credentialOptions, outsideSettings, pendingTaskStruct, |
152 // and promise." | 153 // and promise." |
153 // TODO(nhiroki): Queue a task instead of executing this here. | 154 // TODO(nhiroki): Queue a task instead of executing this here. |
154 for (const auto& proxy : proxies_) { | 155 for (const auto& proxy : proxies_) { |
155 proxy->FetchAndInvokeScript(module_url_record, credentials_mode, | 156 proxy->FetchAndInvokeScript(module_url_record, module_responses_map, |
156 outside_settings_task_runner, pending_tasks); | 157 credentials_mode, outside_settings_task_runner, |
| 158 pending_tasks); |
157 } | 159 } |
158 } | 160 } |
159 | 161 |
160 DEFINE_TRACE(Worklet) { | 162 DEFINE_TRACE(Worklet) { |
161 visitor->Trace(proxies_); | 163 visitor->Trace(proxies_); |
| 164 visitor->Trace(module_responses_map_); |
162 ContextLifecycleObserver::Trace(visitor); | 165 ContextLifecycleObserver::Trace(visitor); |
163 } | 166 } |
164 | 167 |
165 } // namespace blink | 168 } // namespace blink |
OLD | NEW |