OLD | NEW |
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/dom/Modulator.h" |
| 11 #include "core/dom/TaskRunnerHelper.h" |
11 #include "core/frame/Deprecation.h" | 12 #include "core/frame/Deprecation.h" |
12 #include "core/frame/FrameConsole.h" | 13 #include "core/frame/FrameConsole.h" |
13 #include "core/frame/LocalFrame.h" | 14 #include "core/frame/LocalFrame.h" |
14 #include "core/inspector/MainThreadDebugger.h" | 15 #include "core/inspector/MainThreadDebugger.h" |
15 #include "core/loader/modulescript/ModuleScriptFetchRequest.h" | 16 #include "core/loader/modulescript/ModuleScriptFetchRequest.h" |
16 #include "core/probe/CoreProbes.h" | 17 #include "core/probe/CoreProbes.h" |
| 18 #include "core/workers/WorkletModuleResponsesMap.h" |
17 #include "core/workers/WorkletModuleTreeClient.h" | 19 #include "core/workers/WorkletModuleTreeClient.h" |
18 #include "public/platform/WebURLRequest.h" | 20 #include "public/platform/WebURLRequest.h" |
19 | 21 |
20 namespace blink { | 22 namespace blink { |
21 | 23 |
22 MainThreadWorkletGlobalScope::MainThreadWorkletGlobalScope( | 24 MainThreadWorkletGlobalScope::MainThreadWorkletGlobalScope( |
23 LocalFrame* frame, | 25 LocalFrame* frame, |
24 const KURL& url, | 26 const KURL& url, |
25 const String& user_agent, | 27 const String& user_agent, |
26 PassRefPtr<SecurityOrigin> security_origin, | 28 PassRefPtr<SecurityOrigin> security_origin, |
(...skipping 24 matching lines...) Expand all Loading... |
51 WorkerThread* MainThreadWorkletGlobalScope::GetThread() const { | 53 WorkerThread* MainThreadWorkletGlobalScope::GetThread() const { |
52 NOTREACHED(); | 54 NOTREACHED(); |
53 return nullptr; | 55 return nullptr; |
54 } | 56 } |
55 | 57 |
56 // Implementation of the first half of the "fetch and invoke a worklet script" | 58 // Implementation of the first half of the "fetch and invoke a worklet script" |
57 // algorithm: | 59 // algorithm: |
58 // https://drafts.css-houdini.org/worklets/#fetch-and-invoke-a-worklet-script | 60 // https://drafts.css-houdini.org/worklets/#fetch-and-invoke-a-worklet-script |
59 void MainThreadWorkletGlobalScope::FetchAndInvokeScript( | 61 void MainThreadWorkletGlobalScope::FetchAndInvokeScript( |
60 const KURL& module_url_record, | 62 const KURL& module_url_record, |
| 63 WorkletModuleResponsesMap* module_responses_map, |
61 WebURLRequest::FetchCredentialsMode credentials_mode, | 64 WebURLRequest::FetchCredentialsMode credentials_mode, |
62 RefPtr<WebTaskRunner> outside_settings_task_runner, | 65 RefPtr<WebTaskRunner> outside_settings_task_runner, |
63 WorkletPendingTasks* pending_tasks) { | 66 WorkletPendingTasks* pending_tasks) { |
64 DCHECK(IsMainThread()); | 67 DCHECK(IsMainThread()); |
| 68 if (!module_responses_map_proxy_) { |
| 69 module_responses_map_proxy_ = new WorkletModuleResponsesMapProxy( |
| 70 module_responses_map, outside_settings_task_runner, |
| 71 TaskRunnerHelper::Get(TaskType::kUnspecedLoading, this)); |
| 72 } |
| 73 |
65 // Step 1: "Let insideSettings be the workletGlobalScope's associated | 74 // Step 1: "Let insideSettings be the workletGlobalScope's associated |
66 // environment settings object." | 75 // environment settings object." |
67 // Step 2: "Let script by the result of fetch a worklet script given | 76 // Step 2: "Let script by the result of fetch a worklet script given |
68 // moduleURLRecord, moduleResponsesMap, credentialOptions, outsideSettings, | 77 // moduleURLRecord, moduleResponsesMap, credentialOptions, outsideSettings, |
69 // and insideSettings when it asynchronously completes." | 78 // and insideSettings when it asynchronously completes." |
70 String nonce = ""; | 79 String nonce = ""; |
71 ParserDisposition parser_state = kNotParserInserted; | 80 ParserDisposition parser_state = kNotParserInserted; |
72 Modulator* modulator = Modulator::From(ScriptController()->GetScriptState()); | 81 Modulator* modulator = Modulator::From(ScriptController()->GetScriptState()); |
73 ModuleScriptFetchRequest module_request(module_url_record, nonce, | 82 ModuleScriptFetchRequest module_request(module_url_record, nonce, |
74 parser_state, credentials_mode); | 83 parser_state, credentials_mode); |
75 | 84 |
76 // Step 3 to 5 are implemented in | 85 // Step 3 to 5 are implemented in |
77 // WorkletModuleTreeClient::NotifyModuleTreeLoadFinished. | 86 // WorkletModuleTreeClient::NotifyModuleTreeLoadFinished. |
78 WorkletModuleTreeClient* client = new WorkletModuleTreeClient( | 87 WorkletModuleTreeClient* client = new WorkletModuleTreeClient( |
79 modulator, std::move(outside_settings_task_runner), pending_tasks); | 88 modulator, std::move(outside_settings_task_runner), pending_tasks); |
80 modulator->FetchTree(module_request, client); | 89 modulator->FetchTree(module_request, client); |
81 } | 90 } |
82 | 91 |
83 // TODO(nhiroki): Add tests for termination. | 92 // TODO(nhiroki): Add tests for termination. |
84 void MainThreadWorkletGlobalScope::Terminate() { | 93 void MainThreadWorkletGlobalScope::Terminate() { |
85 Dispose(); | 94 Dispose(); |
86 } | 95 } |
87 | 96 |
| 97 WorkletModuleResponsesMapProxy* |
| 98 MainThreadWorkletGlobalScope::GetModuleResponsesMapProxy() const { |
| 99 DCHECK(module_responses_map_proxy_); |
| 100 return module_responses_map_proxy_; |
| 101 } |
| 102 |
88 void MainThreadWorkletGlobalScope::AddConsoleMessage( | 103 void MainThreadWorkletGlobalScope::AddConsoleMessage( |
89 ConsoleMessage* console_message) { | 104 ConsoleMessage* console_message) { |
90 GetFrame()->Console().AddMessage(console_message); | 105 GetFrame()->Console().AddMessage(console_message); |
91 } | 106 } |
92 | 107 |
93 void MainThreadWorkletGlobalScope::ExceptionThrown(ErrorEvent* event) { | 108 void MainThreadWorkletGlobalScope::ExceptionThrown(ErrorEvent* event) { |
94 MainThreadDebugger::Instance()->ExceptionThrown(this, event); | 109 MainThreadDebugger::Instance()->ExceptionThrown(this, event); |
95 } | 110 } |
96 | 111 |
97 CoreProbeSink* MainThreadWorkletGlobalScope::GetProbeSink() { | 112 CoreProbeSink* MainThreadWorkletGlobalScope::GetProbeSink() { |
98 return probe::ToCoreProbeSink(GetFrame()); | 113 return probe::ToCoreProbeSink(GetFrame()); |
99 } | 114 } |
100 | 115 |
101 DEFINE_TRACE(MainThreadWorkletGlobalScope) { | 116 DEFINE_TRACE(MainThreadWorkletGlobalScope) { |
| 117 visitor->Trace(module_responses_map_proxy_); |
102 WorkletGlobalScope::Trace(visitor); | 118 WorkletGlobalScope::Trace(visitor); |
103 ContextClient::Trace(visitor); | 119 ContextClient::Trace(visitor); |
104 } | 120 } |
105 | 121 |
106 } // namespace blink | 122 } // namespace blink |
OLD | NEW |