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/workers/MainThreadWorklet.h" | 5 #include "core/workers/MainThreadWorklet.h" |
6 | 6 |
7 #include "bindings/core/v8/ScriptPromiseResolver.h" | 7 #include "bindings/core/v8/ScriptPromiseResolver.h" |
8 #include "bindings/core/v8/ScriptSourceCode.h" | 8 #include "bindings/core/v8/ScriptSourceCode.h" |
9 #include "bindings/core/v8/V8BindingForCore.h" | 9 #include "bindings/core/v8/V8BindingForCore.h" |
10 #include "core/frame/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 if (credentials_option == "include") | 26 if (credentials_option == "include") |
27 return WebURLRequest::kFetchCredentialsModeInclude; | 27 return WebURLRequest::kFetchCredentialsModeInclude; |
28 NOTREACHED(); | 28 NOTREACHED(); |
29 return WebURLRequest::kFetchCredentialsModeOmit; | 29 return WebURLRequest::kFetchCredentialsModeOmit; |
30 } | 30 } |
31 | 31 |
32 } // namespace | 32 } // namespace |
33 | 33 |
34 MainThreadWorklet::MainThreadWorklet(LocalFrame* frame) : Worklet(frame) {} | 34 MainThreadWorklet::MainThreadWorklet(LocalFrame* frame) : Worklet(frame) {} |
35 | 35 |
| 36 WorkletGlobalScopeProxy* MainThreadWorklet::FindAvailableGlobalScope() const { |
| 37 DCHECK(IsMainThread()); |
| 38 // TODO(nhiroki): Support the case where there are multiple global scopes. |
| 39 DCHECK_EQ(1u, GetNumberOfGlobalScopes()); |
| 40 return proxies_.begin()->get(); |
| 41 } |
| 42 |
36 // Implementation of the second half of the "addModule(moduleURL, options)" | 43 // Implementation of the second half of the "addModule(moduleURL, options)" |
37 // algorithm: | 44 // algorithm: |
38 // https://drafts.css-houdini.org/worklets/#dom-worklet-addmodule | 45 // https://drafts.css-houdini.org/worklets/#dom-worklet-addmodule |
39 void MainThreadWorklet::FetchAndInvokeScript(const KURL& module_url_record, | 46 void MainThreadWorklet::FetchAndInvokeScript(const KURL& module_url_record, |
40 const WorkletOptions& options, | 47 const WorkletOptions& options, |
41 ScriptPromiseResolver* resolver) { | 48 ScriptPromiseResolver* resolver) { |
42 DCHECK(IsMainThread()); | 49 DCHECK(IsMainThread()); |
43 if (!GetExecutionContext()) | 50 if (!GetExecutionContext()) |
44 return; | 51 return; |
45 | 52 |
(...skipping 14 matching lines...) Expand all Loading... |
60 // type." | 67 // type." |
61 // workletGlobalScopeType is encoded into the class name (e.g., PaintWorklet). | 68 // workletGlobalScopeType is encoded into the class name (e.g., PaintWorklet). |
62 | 69 |
63 // Step 10: "If the worklet's WorkletGlobalScopes is empty, run the following | 70 // Step 10: "If the worklet's WorkletGlobalScopes is empty, run the following |
64 // steps:" | 71 // steps:" |
65 // 10.1: "Create a WorkletGlobalScope given workletGlobalScopeType, | 72 // 10.1: "Create a WorkletGlobalScope given workletGlobalScopeType, |
66 // moduleResponsesMap, and outsideSettings." | 73 // moduleResponsesMap, and outsideSettings." |
67 // 10.2: "Add the WorkletGlobalScope to worklet's WorkletGlobalScopes." | 74 // 10.2: "Add the WorkletGlobalScope to worklet's WorkletGlobalScopes." |
68 // "Depending on the type of worklet the user agent may create additional | 75 // "Depending on the type of worklet the user agent may create additional |
69 // WorkletGlobalScopes at this time." | 76 // WorkletGlobalScopes at this time." |
70 // TODO(nhiroki): Create WorkletGlobalScopes at this point. | 77 while (NeedsToCreateGlobalScope()) |
| 78 proxies_.insert(CreateGlobalScope()); |
| 79 DCHECK_LT(0u, GetNumberOfGlobalScopes()); |
71 | 80 |
72 // Step 11: "Let pendingTaskStruct be a new pending tasks struct with counter | 81 // Step 11: "Let pendingTaskStruct be a new pending tasks struct with counter |
73 // initialized to the length of worklet's WorkletGlobalScopes." | 82 // initialized to the length of worklet's WorkletGlobalScopes." |
74 // TODO(nhiroki): Introduce the concept of "worklet's WorkletGlobalScopes" and | |
75 // use the length of it here. | |
76 constexpr int number_of_global_scopes = 1; | |
77 WorkletPendingTasks* pending_tasks = | 83 WorkletPendingTasks* pending_tasks = |
78 new WorkletPendingTasks(number_of_global_scopes, resolver); | 84 new WorkletPendingTasks(GetNumberOfGlobalScopes(), resolver); |
79 | 85 |
80 // Step 12: "For each workletGlobalScope in the worklet's | 86 // Step 12: "For each workletGlobalScope in the worklet's |
81 // WorkletGlobalScopes, queue a task on the workletGlobalScope to fetch and | 87 // WorkletGlobalScopes, queue a task on the workletGlobalScope to fetch and |
82 // invoke a worklet script given workletGlobalScope, moduleURLRecord, | 88 // invoke a worklet script given workletGlobalScope, moduleURLRecord, |
83 // moduleResponsesMap, credentialOptions, outsideSettings, pendingTaskStruct, | 89 // moduleResponsesMap, credentialOptions, outsideSettings, pendingTaskStruct, |
84 // and promise." | 90 // and promise." |
85 // TODO(nhiroki): Queue a task instead of executing this here. | 91 // TODO(nhiroki): Queue a task instead of executing this here. |
86 GetWorkletGlobalScopeProxy()->FetchAndInvokeScript( | 92 for (const auto& proxy : proxies_) { |
87 module_url_record, credentials_mode, pending_tasks); | 93 proxy->FetchAndInvokeScript(module_url_record, credentials_mode, |
| 94 pending_tasks); |
| 95 } |
88 } | 96 } |
89 | 97 |
90 void MainThreadWorklet::ContextDestroyed(ExecutionContext* execution_context) { | 98 void MainThreadWorklet::ContextDestroyed(ExecutionContext* execution_context) { |
91 DCHECK(IsMainThread()); | 99 DCHECK(IsMainThread()); |
92 GetWorkletGlobalScopeProxy()->TerminateWorkletGlobalScope(); | 100 for (const auto& proxy : proxies_) |
| 101 proxy->TerminateWorkletGlobalScope(); |
93 } | 102 } |
94 | 103 |
95 DEFINE_TRACE(MainThreadWorklet) { | 104 DEFINE_TRACE(MainThreadWorklet) { |
96 Worklet::Trace(visitor); | 105 Worklet::Trace(visitor); |
97 } | 106 } |
98 | 107 |
99 } // namespace blink | 108 } // namespace blink |
OLD | NEW |