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 b3ffe3bec9481ff04fadb12b4fb0ac8651013d69..86f8f890e7b98021bf10901dc88a54b2069499f4 100644 |
| --- a/third_party/WebKit/Source/core/workers/MainThreadWorklet.cpp |
| +++ b/third_party/WebKit/Source/core/workers/MainThreadWorklet.cpp |
| @@ -11,27 +11,15 @@ |
| #include "core/dom/ExceptionCode.h" |
| #include "core/frame/LocalFrame.h" |
| #include "core/workers/WorkletGlobalScopeProxy.h" |
| +#include "core/workers/WorkletPendingTasks.h" |
| #include "platform/wtf/WTF.h" |
| namespace blink { |
| -namespace { |
| - |
| -int32_t GetNextRequestId() { |
| - DCHECK(IsMainThread()); |
| - static int32_t next_request_id = 1; |
| - CHECK_LT(next_request_id, std::numeric_limits<int32_t>::max()); |
| - return next_request_id++; |
| -} |
| - |
| -} // namespace |
| - |
| -MainThreadWorklet::MainThreadWorklet(LocalFrame* frame) : Worklet(frame) { |
| - DCHECK(resolver_map_.IsEmpty()); |
| -} |
| +MainThreadWorklet::MainThreadWorklet(LocalFrame* frame) : Worklet(frame) {} |
| ScriptPromise MainThreadWorklet::addModule(ScriptState* script_state, |
| - const String& url) { |
| + const String& module_url) { |
| DCHECK(IsMainThread()); |
| if (!GetExecutionContext()) { |
| return ScriptPromise::RejectWithDOMException( |
| @@ -39,44 +27,43 @@ ScriptPromise MainThreadWorklet::addModule(ScriptState* script_state, |
| "This frame is already detached")); |
| } |
| - KURL script_url = GetExecutionContext()->CompleteURL(url); |
| - if (!script_url.IsValid()) { |
| + KURL module_url_record = GetExecutionContext()->CompleteURL(module_url); |
| + if (!module_url_record.IsValid()) { |
| return ScriptPromise::RejectWithDOMException( |
| - script_state, DOMException::Create( |
| - kSyntaxError, "'" + url + "' is not a valid URL.")); |
| + script_state, |
| + DOMException::Create(kSyntaxError, |
| + "'" + module_url + "' is not a valid URL.")); |
| } |
| - int32_t request_id = GetNextRequestId(); |
| ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); |
| ScriptPromise promise = resolver->Promise(); |
| - resolver_map_.Set(request_id, resolver); |
| - GetWorkletGlobalScopeProxy()->FetchAndInvokeScript(request_id, script_url); |
| - return promise; |
| -} |
| -void MainThreadWorklet::DidFetchAndInvokeScript(int32_t request_id, |
| - bool success) { |
| - DCHECK(IsMainThread()); |
| - ScriptPromiseResolver* resolver = resolver_map_.at(request_id); |
| - if (!resolver) |
| - return; |
| - resolver_map_.erase(request_id); |
| - if (!success) { |
| - resolver->Reject(DOMException::Create(kNetworkError)); |
| - return; |
| - } |
| - resolver->Resolve(); |
| + // Step 11: "Let pendingTaskStruct be a new pending tasks struct with counter |
|
kouhei (in TOK)
2017/04/27 10:05:33
Add context link https://drafts.css-houdini.org/wo
nhiroki
2017/04/28 04:41:14
Done.
|
| + // initialized to the length of worklet's WorkletGlobalScopes." |
| + // TODO(nhiroki): Introduce the concept of "worklet's WorkletGlobalScopes" and |
| + // use the length of it here. |
| + const int number_of_global_scopes = 1; |
|
kouhei (in TOK)
2017/04/27 10:05:33
constexpr?
nhiroki
2017/04/28 04:41:14
Done.
|
| + WorkletPendingTasks* pending_tasks = |
| + new WorkletPendingTasks(number_of_global_scopes, resolver); |
| + |
| + // Step 12: "For each workletGlobalScope in the worklet's |
| + // WorkletGlobalScopes, queue a task on the workletGlobalScope to fetch and |
| + // invoke a worklet script given workletGlobalScope, moduleURLRecord, |
| + // moduleResponsesMap, credentialOptions, outsideSettings, pendingTaskStruct, |
| + // and promise." |
| + // TODO(nhiroki): Pass the remaining parameters (e.g., credentialOptions). |
|
kouhei (in TOK)
2017/04/27 10:05:33
Add a note about skipping "queue a task". TODO or
nhiroki
2017/04/28 04:41:14
Done.
|
| + GetWorkletGlobalScopeProxy()->FetchAndInvokeScript(module_url_record, |
| + pending_tasks); |
| + return promise; |
| } |
| void MainThreadWorklet::ContextDestroyed(ExecutionContext* execution_context) { |
| DCHECK(IsMainThread()); |
| - resolver_map_.clear(); |
| GetWorkletGlobalScopeProxy()->TerminateWorkletGlobalScope(); |
| Worklet::ContextDestroyed(execution_context); |
| } |
| DEFINE_TRACE(MainThreadWorklet) { |
| - visitor->Trace(resolver_map_); |
| Worklet::Trace(visitor); |
| } |