Chromium Code Reviews| Index: third_party/WebKit/Source/core/workers/MainThreadWorklet.cpp |
| diff --git a/third_party/WebKit/Source/core/workers/MainThreadWorklet.cpp b/third_party/WebKit/Source/core/workers/MainThreadWorklet.cpp |
| index 43ac12846daf9ddca9a6050301035f5223636844..96ada9b193864f1291e18fc1d1d683de656a1618 100644 |
| --- a/third_party/WebKit/Source/core/workers/MainThreadWorklet.cpp |
| +++ b/third_party/WebKit/Source/core/workers/MainThreadWorklet.cpp |
| @@ -33,6 +33,13 @@ WebURLRequest::FetchCredentialsMode ParseCredentialsOption( |
| MainThreadWorklet::MainThreadWorklet(LocalFrame* frame) : Worklet(frame) {} |
| +WorkletGlobalScopeProxy* MainThreadWorklet::FindAvailableGlobalScope() const { |
| + DCHECK(IsMainThread()); |
| + // TODO(nhiroki): Support the case where there are multiple global scopes. |
| + DCHECK_EQ(1u, GetNumberOfGlobalScopes()); |
| + return proxies_.begin()->get(); |
| +} |
| + |
| // Implementation of the second half of the "addModule(moduleURL, options)" |
| // algorithm: |
| // https://drafts.css-houdini.org/worklets/#dom-worklet-addmodule |
| @@ -67,15 +74,14 @@ void MainThreadWorklet::FetchAndInvokeScript(const KURL& module_url_record, |
| // 10.2: "Add the WorkletGlobalScope to worklet's WorkletGlobalScopes." |
| // "Depending on the type of worklet the user agent may create additional |
| // WorkletGlobalScopes at this time." |
| - // TODO(nhiroki): Create WorkletGlobalScopes at this point. |
| + while (NeedsToCreateGlobalScope()) |
| + proxies_.insert(CreateGlobalScope()); |
| + DCHECK_LT(0u, GetNumberOfGlobalScopes()); |
|
haraken
2017/05/29 07:38:48
DCHECK_EQ(1, GetNumberOfGlobalScopes()) at the mom
nhiroki
2017/05/29 08:52:00
Done.
|
| // Step 11: "Let pendingTaskStruct be a new pending tasks struct with counter |
| // initialized to the length of worklet's WorkletGlobalScopes." |
| - // TODO(nhiroki): Introduce the concept of "worklet's WorkletGlobalScopes" and |
| - // use the length of it here. |
| - constexpr int number_of_global_scopes = 1; |
| WorkletPendingTasks* pending_tasks = |
| - new WorkletPendingTasks(number_of_global_scopes, resolver); |
| + new WorkletPendingTasks(GetNumberOfGlobalScopes(), resolver); |
| // Step 12: "For each workletGlobalScope in the worklet's |
| // WorkletGlobalScopes, queue a task on the workletGlobalScope to fetch and |
| @@ -83,13 +89,16 @@ void MainThreadWorklet::FetchAndInvokeScript(const KURL& module_url_record, |
| // moduleResponsesMap, credentialOptions, outsideSettings, pendingTaskStruct, |
| // and promise." |
| // TODO(nhiroki): Queue a task instead of executing this here. |
| - GetWorkletGlobalScopeProxy()->FetchAndInvokeScript( |
| - module_url_record, credentials_mode, pending_tasks); |
| + for (const auto& proxy : proxies_) { |
| + proxy->FetchAndInvokeScript(module_url_record, credentials_mode, |
| + pending_tasks); |
| + } |
| } |
| void MainThreadWorklet::ContextDestroyed(ExecutionContext* execution_context) { |
| DCHECK(IsMainThread()); |
| - GetWorkletGlobalScopeProxy()->TerminateWorkletGlobalScope(); |
| + for (const auto& proxy : proxies_) |
| + proxy->TerminateWorkletGlobalScope(); |
| } |
| DEFINE_TRACE(MainThreadWorklet) { |