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 "modules/worklet/Worklet.h" | 5 #include "modules/worklet/Worklet.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/V8Binding.h" | 9 #include "bindings/core/v8/V8Binding.h" |
10 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" | 10 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" |
11 #include "core/dom/DOMException.h" | 11 #include "core/dom/DOMException.h" |
12 #include "core/dom/ExceptionCode.h" | 12 #include "core/dom/ExceptionCode.h" |
| 13 #include "core/inspector/InspectorInstrumentation.h" |
13 #include "modules/worklet/WorkletGlobalScope.h" | 14 #include "modules/worklet/WorkletGlobalScope.h" |
14 | 15 |
15 namespace blink { | 16 namespace blink { |
16 | 17 |
17 // static | 18 // static |
18 Worklet* Worklet::create(LocalFrame* frame, ExecutionContext* executionContext) | 19 Worklet* Worklet::create(LocalFrame* frame, ExecutionContext* executionContext) |
19 { | 20 { |
20 Worklet* worklet = new Worklet(frame, executionContext); | 21 Worklet* worklet = new Worklet(frame, executionContext); |
21 worklet->suspendIfNeeded(); | 22 worklet->suspendIfNeeded(); |
22 return worklet; | 23 return worklet; |
23 } | 24 } |
24 | 25 |
25 Worklet::Worklet(LocalFrame* frame, ExecutionContext* executionContext) | 26 Worklet::Worklet(LocalFrame* frame, ExecutionContext* executionContext) |
26 : ActiveDOMObject(executionContext) | 27 : ActiveDOMObject(executionContext) |
27 , m_workletGlobalScope(WorkletGlobalScope::create(frame, executionContext->u
rl(), executionContext->userAgent(), executionContext->securityOrigin(), toIsola
te(executionContext))) | 28 , m_workletGlobalScope(WorkletGlobalScope::create(frame, executionContext->u
rl(), executionContext->userAgent(), executionContext->securityOrigin(), toIsola
te(executionContext))) |
28 { | 29 { |
| 30 InspectorInstrumentation::didCreateScriptContext(frame, m_workletGlobalScope
->scriptController()->scriptState(), m_workletGlobalScope->securityOrigin(), Wor
kerWorldId); |
29 } | 31 } |
30 | 32 |
31 ScriptPromise Worklet::import(ScriptState* scriptState, const String& url) | 33 ScriptPromise Worklet::import(ScriptState* scriptState, const String& url) |
32 { | 34 { |
33 KURL scriptURL = executionContext()->completeURL(url); | 35 KURL scriptURL = executionContext()->completeURL(url); |
34 if (!scriptURL.isValid()) { | 36 if (!scriptURL.isValid()) { |
35 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(SyntaxError, "'" + url + "' is not a valid URL.")); | 37 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(SyntaxError, "'" + url + "' is not a valid URL.")); |
36 } | 38 } |
37 | 39 |
38 // TODO(ikilpatrick): Perform upfront CSP checks once we decide on a | 40 // TODO(ikilpatrick): Perform upfront CSP checks once we decide on a |
(...skipping 26 matching lines...) Expand all Loading... |
65 | 67 |
66 void Worklet::onFinished(WorkerScriptLoader* scriptLoader, ScriptPromiseResolver
* resolver) | 68 void Worklet::onFinished(WorkerScriptLoader* scriptLoader, ScriptPromiseResolver
* resolver) |
67 { | 69 { |
68 if (scriptLoader->failed()) { | 70 if (scriptLoader->failed()) { |
69 resolver->reject(DOMException::create(NetworkError)); | 71 resolver->reject(DOMException::create(NetworkError)); |
70 } else { | 72 } else { |
71 // TODO(ikilpatrick): Worklets don't have the same error behaviour | 73 // TODO(ikilpatrick): Worklets don't have the same error behaviour |
72 // as workers, etc. For a SyntaxError we should reject, however if | 74 // as workers, etc. For a SyntaxError we should reject, however if |
73 // the script throws a normal error, resolve. For now just resolve. | 75 // the script throws a normal error, resolve. For now just resolve. |
74 m_workletGlobalScope->scriptController()->evaluate(ScriptSourceCode(scri
ptLoader->script(), scriptLoader->url())); | 76 m_workletGlobalScope->scriptController()->evaluate(ScriptSourceCode(scri
ptLoader->script(), scriptLoader->url())); |
| 77 InspectorInstrumentation::scriptImported(m_workletGlobalScope, scriptLoa
der->identifier(), scriptLoader->script()); |
75 resolver->resolve(); | 78 resolver->resolve(); |
76 } | 79 } |
77 | 80 |
78 size_t index = m_scriptLoaders.find(scriptLoader); | 81 size_t index = m_scriptLoaders.find(scriptLoader); |
79 | 82 |
80 ASSERT(index != kNotFound); | 83 ASSERT(index != kNotFound); |
81 ASSERT(m_resolvers[index] == resolver); | 84 ASSERT(m_resolvers[index] == resolver); |
82 | 85 |
83 m_scriptLoaders.remove(index); | 86 m_scriptLoaders.remove(index); |
84 m_resolvers.remove(index); | 87 m_resolvers.remove(index); |
85 } | 88 } |
86 | 89 |
87 void Worklet::stop() | 90 void Worklet::stop() |
88 { | 91 { |
89 m_workletGlobalScope->scriptController()->willScheduleExecutionTermination()
; | 92 m_workletGlobalScope->scriptController()->willScheduleExecutionTermination()
; |
90 | 93 |
91 for (auto scriptLoader : m_scriptLoaders) { | 94 for (auto scriptLoader : m_scriptLoaders) { |
92 scriptLoader->cancel(); | 95 scriptLoader->cancel(); |
93 } | 96 } |
94 } | 97 } |
95 | 98 |
96 DEFINE_TRACE(Worklet) | 99 DEFINE_TRACE(Worklet) |
97 { | 100 { |
98 visitor->trace(m_resolvers); | 101 visitor->trace(m_resolvers); |
99 visitor->trace(m_workletGlobalScope); | 102 visitor->trace(m_workletGlobalScope); |
100 ActiveDOMObject::trace(visitor); | 103 ActiveDOMObject::trace(visitor); |
101 } | 104 } |
102 | 105 |
103 } // namespace blink | 106 } // namespace blink |
OLD | NEW |