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

Side by Side Diff: third_party/WebKit/Source/core/workers/MainThreadWorklet.cpp

Issue 2871513002: Worklet: Lazily create PaintWorkletGlobalScopes (Closed)
Patch Set: clean up Created 3 years, 6 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
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 13 matching lines...) Expand all
24 if (credentials_option == "same-origin") 24 if (credentials_option == "same-origin")
25 return WebURLRequest::kFetchCredentialsModeSameOrigin; 25 return WebURLRequest::kFetchCredentialsModeSameOrigin;
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)
35 : Worklet(frame), global_scope_manager_(new WorkletGlobalScopeManager) {}
35 36
36 // Implementation of the second half of the "addModule(moduleURL, options)" 37 // Implementation of the second half of the "addModule(moduleURL, options)"
37 // algorithm: 38 // algorithm:
38 // https://drafts.css-houdini.org/worklets/#dom-worklet-addmodule 39 // https://drafts.css-houdini.org/worklets/#dom-worklet-addmodule
39 void MainThreadWorklet::FetchAndInvokeScript(const KURL& module_url_record, 40 void MainThreadWorklet::FetchAndInvokeScript(const KURL& module_url_record,
40 const WorkletOptions& options, 41 const WorkletOptions& options,
41 ScriptPromiseResolver* resolver) { 42 ScriptPromiseResolver* resolver) {
42 DCHECK(IsMainThread()); 43 DCHECK(IsMainThread());
43 if (!GetExecutionContext()) 44 if (!GetExecutionContext())
44 return; 45 return;
(...skipping 15 matching lines...) Expand all
60 // type." 61 // type."
61 // workletGlobalScopeType is encoded into the class name (e.g., PaintWorklet). 62 // workletGlobalScopeType is encoded into the class name (e.g., PaintWorklet).
62 63
63 // Step 10: "If the worklet's WorkletGlobalScopes is empty, run the following 64 // Step 10: "If the worklet's WorkletGlobalScopes is empty, run the following
64 // steps:" 65 // steps:"
65 // 10.1: "Create a WorkletGlobalScope given workletGlobalScopeType, 66 // 10.1: "Create a WorkletGlobalScope given workletGlobalScopeType,
66 // moduleResponsesMap, and outsideSettings." 67 // moduleResponsesMap, and outsideSettings."
67 // 10.2: "Add the WorkletGlobalScope to worklet's WorkletGlobalScopes." 68 // 10.2: "Add the WorkletGlobalScope to worklet's WorkletGlobalScopes."
68 // "Depending on the type of worklet the user agent may create additional 69 // "Depending on the type of worklet the user agent may create additional
69 // WorkletGlobalScopes at this time." 70 // WorkletGlobalScopes at this time."
70 // TODO(nhiroki): Create WorkletGlobalScopes at this point. 71 while (NeedsToCreateGlobalScope())
72 GetGlobalScopeManager().AddGlobalScope(CreateGlobalScope());
73 DCHECK_LT(0u, GetGlobalScopeManager().GetNumberOfGlobalScopes());
71 74
72 // Step 11: "Let pendingTaskStruct be a new pending tasks struct with counter 75 // Step 11: "Let pendingTaskStruct be a new pending tasks struct with counter
73 // initialized to the length of worklet's WorkletGlobalScopes." 76 // initialized to the length of worklet's WorkletGlobalScopes."
74 // TODO(nhiroki): Introduce the concept of "worklet's WorkletGlobalScopes" and 77 size_t length = GetGlobalScopeManager().GetNumberOfGlobalScopes();
75 // use the length of it here.
76 constexpr int number_of_global_scopes = 1;
77 WorkletPendingTasks* pending_tasks = 78 WorkletPendingTasks* pending_tasks =
78 new WorkletPendingTasks(number_of_global_scopes, resolver); 79 new WorkletPendingTasks(length, resolver);
79 80
80 // Step 12: "For each workletGlobalScope in the worklet's 81 // Step 12: "For each workletGlobalScope in the worklet's
81 // WorkletGlobalScopes, queue a task on the workletGlobalScope to fetch and 82 // WorkletGlobalScopes, queue a task on the workletGlobalScope to fetch and
82 // invoke a worklet script given workletGlobalScope, moduleURLRecord, 83 // invoke a worklet script given workletGlobalScope, moduleURLRecord,
83 // moduleResponsesMap, credentialOptions, outsideSettings, pendingTaskStruct, 84 // moduleResponsesMap, credentialOptions, outsideSettings, pendingTaskStruct,
84 // and promise." 85 // and promise."
85 // TODO(nhiroki): Queue a task instead of executing this here. 86 // TODO(nhiroki): Queue a task instead of executing this here.
86 GetWorkletGlobalScopeProxy()->FetchAndInvokeScript( 87 GetGlobalScopeManager().AddModuleToGlobalScopes(
87 module_url_record, credentials_mode, pending_tasks); 88 module_url_record, credentials_mode, pending_tasks);
88 } 89 }
89 90
90 void MainThreadWorklet::ContextDestroyed(ExecutionContext* execution_context) { 91 void MainThreadWorklet::ContextDestroyed(ExecutionContext* execution_context) {
91 DCHECK(IsMainThread()); 92 DCHECK(IsMainThread());
92 GetWorkletGlobalScopeProxy()->TerminateWorkletGlobalScope(); 93 GetGlobalScopeManager().TerminateGlobalScopes();
93 } 94 }
94 95
95 DEFINE_TRACE(MainThreadWorklet) { 96 DEFINE_TRACE(MainThreadWorklet) {
97 visitor->Trace(global_scope_manager_);
96 Worklet::Trace(visitor); 98 Worklet::Trace(visitor);
97 } 99 }
98 100
99 } // namespace blink 101 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698