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

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

Issue 2826313003: Worklet: Enable module script loading for main thread worklets (Closed)
Patch Set: rebase (ready for review) 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 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/MainThreadWorkletGlobalScope.h" 5 #include "core/workers/MainThreadWorkletGlobalScope.h"
6 6
7 #include "bindings/core/v8/ScriptSourceCode.h" 7 #include "bindings/core/v8/ScriptSourceCode.h"
8 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" 8 #include "bindings/core/v8/WorkerOrWorkletScriptController.h"
9 #include "core/dom/Document.h" 9 #include "core/dom/Document.h"
10 #include "core/dom/Modulator.h"
10 #include "core/frame/Deprecation.h" 11 #include "core/frame/Deprecation.h"
11 #include "core/frame/FrameConsole.h" 12 #include "core/frame/FrameConsole.h"
12 #include "core/frame/LocalFrame.h" 13 #include "core/frame/LocalFrame.h"
13 #include "core/inspector/MainThreadDebugger.h" 14 #include "core/inspector/MainThreadDebugger.h"
15 #include "core/loader/modulescript/ModuleScriptFetchRequest.h"
14 #include "core/probe/CoreProbes.h" 16 #include "core/probe/CoreProbes.h"
17 #include "core/workers/WorkletModuleTreeClient.h"
18 #include "public/platform/WebURLRequest.h"
15 19
16 namespace blink { 20 namespace blink {
17 21
18 MainThreadWorkletGlobalScope::MainThreadWorkletGlobalScope( 22 MainThreadWorkletGlobalScope::MainThreadWorkletGlobalScope(
19 LocalFrame* frame, 23 LocalFrame* frame,
20 const KURL& url, 24 const KURL& url,
21 const String& user_agent, 25 const String& user_agent,
22 PassRefPtr<SecurityOrigin> security_origin, 26 PassRefPtr<SecurityOrigin> security_origin,
23 v8::Isolate* isolate) 27 v8::Isolate* isolate)
24 : WorkletGlobalScope(url, user_agent, std::move(security_origin), isolate), 28 : WorkletGlobalScope(url, user_agent, std::move(security_origin), isolate),
(...skipping 27 matching lines...) Expand all
52 void MainThreadWorkletGlobalScope::FetchAndInvokeScript( 56 void MainThreadWorkletGlobalScope::FetchAndInvokeScript(
53 const KURL& module_url_record, 57 const KURL& module_url_record,
54 WebURLRequest::FetchCredentialsMode credentials_mode, 58 WebURLRequest::FetchCredentialsMode credentials_mode,
55 WorkletPendingTasks* pending_tasks) { 59 WorkletPendingTasks* pending_tasks) {
56 DCHECK(IsMainThread()); 60 DCHECK(IsMainThread());
57 // Step 1: "Let insideSettings be the workletGlobalScope's associated 61 // Step 1: "Let insideSettings be the workletGlobalScope's associated
58 // environment settings object." 62 // environment settings object."
59 // Step 2: "Let script by the result of fetch a worklet script given 63 // Step 2: "Let script by the result of fetch a worklet script given
60 // moduleURLRecord, moduleResponsesMap, credentialOptions, outsideSettings, 64 // moduleURLRecord, moduleResponsesMap, credentialOptions, outsideSettings,
61 // and insideSettings when it asynchronously completes." 65 // and insideSettings when it asynchronously completes."
62 // TODO(nhiroki): Replace this with module script loading. Set fetch request's 66 String nonce = "";
63 // credentials mode to |credentials_mode|. 67 ParserDisposition parser_state = kNotParserInserted;
64 WorkletScriptLoader* script_loader = 68 Modulator* modulator = Modulator::From(ScriptController()->GetScriptState());
65 WorkletScriptLoader::Create(GetFrame()->GetDocument()->Fetcher(), this); 69 ModuleScriptFetchRequest module_request(module_url_record, nonce,
66 loader_map_.Set(script_loader, pending_tasks); 70 parser_state, credentials_mode);
67 script_loader->FetchScript(module_url_record); 71
72 // Step 3-5 are implemented in
kinuko 2017/05/24 13:57:10 nit: 3-5 -> 3 to 5, just to make it clearer
nhiroki 2017/05/24 14:53:11 Done.
73 // WorkletModuleTreeClient::NotifyModuleTreeLoadFinished.
74 WorkletModuleTreeClient* client =
75 new WorkletModuleTreeClient(modulator, pending_tasks);
76 modulator->FetchTree(module_request, client);
68 } 77 }
69 78
70 // TODO(nhiroki): Add tests for termination. 79 // TODO(nhiroki): Add tests for termination.
71 void MainThreadWorkletGlobalScope::Terminate() { 80 void MainThreadWorkletGlobalScope::Terminate() {
72 for (auto it = loader_map_.begin(); it != loader_map_.end();) {
73 WorkletScriptLoader* script_loader = it->key;
74 // Cancel() eventually calls NotifyWorkletScriptLoadingFinished() and
75 // removes |it| from |loader_map_|, so increment it in advance.
76 ++it;
77 script_loader->Cancel();
78 }
79 Dispose(); 81 Dispose();
80 } 82 }
81 83
82 // Implementation of the second half of the "fetch and invoke a worklet script"
83 // algorithm:
84 // https://drafts.css-houdini.org/worklets/#fetch-and-invoke-a-worklet-script
85 void MainThreadWorkletGlobalScope::NotifyWorkletScriptLoadingFinished(
86 WorkletScriptLoader* script_loader,
87 const ScriptSourceCode& source_code) {
88 DCHECK(IsMainThread());
89 auto it = loader_map_.find(script_loader);
90 DCHECK(it != loader_map_.end());
91 WorkletPendingTasks* pending_tasks = it->value;
92 loader_map_.erase(it);
93
94 if (!script_loader->WasScriptLoadSuccessful()) {
95 // Step 3: "If script is null, then queue a task on outsideSettings's
96 // responsible event loop to run these steps:"
97 // The steps are implemented in WorkletPendingTasks::Abort().
98 // TODO(nhiroki): Queue a task instead of executing this here.
99 pending_tasks->Abort();
100 return;
101 }
102
103 // Step 4: "Run a module script given script."
104 ScriptController()->Evaluate(source_code);
105
106 // Step 5: "Queue a task on outsideSettings's responsible event loop to run
107 // these steps:"
108 // The steps are implemented in WorkletPendingTasks::DecrementCounter().
109 // TODO(nhiroki): Queue a task instead of executing this here.
110 pending_tasks->DecrementCounter();
111 }
112
113 void MainThreadWorkletGlobalScope::AddConsoleMessage( 84 void MainThreadWorkletGlobalScope::AddConsoleMessage(
114 ConsoleMessage* console_message) { 85 ConsoleMessage* console_message) {
115 GetFrame()->Console().AddMessage(console_message); 86 GetFrame()->Console().AddMessage(console_message);
116 } 87 }
117 88
118 void MainThreadWorkletGlobalScope::ExceptionThrown(ErrorEvent* event) { 89 void MainThreadWorkletGlobalScope::ExceptionThrown(ErrorEvent* event) {
119 MainThreadDebugger::Instance()->ExceptionThrown(this, event); 90 MainThreadDebugger::Instance()->ExceptionThrown(this, event);
120 } 91 }
121 92
122 CoreProbeSink* MainThreadWorkletGlobalScope::GetProbeSink() { 93 CoreProbeSink* MainThreadWorkletGlobalScope::GetProbeSink() {
123 return probe::ToCoreProbeSink(GetFrame()); 94 return probe::ToCoreProbeSink(GetFrame());
124 } 95 }
125 96
126 DEFINE_TRACE(MainThreadWorkletGlobalScope) { 97 DEFINE_TRACE(MainThreadWorkletGlobalScope) {
127 visitor->Trace(loader_map_);
128 WorkletGlobalScope::Trace(visitor); 98 WorkletGlobalScope::Trace(visitor);
129 ContextClient::Trace(visitor); 99 ContextClient::Trace(visitor);
130 } 100 }
131 101
132 } // namespace blink 102 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698