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" |
(...skipping 25 matching lines...) Expand all Loading... |
36 ScriptPromise promise = resolver->promise(); | 36 ScriptPromise promise = resolver->promise(); |
37 | 37 |
38 // TODO(ikilpatrick): WorkerScriptLoader will need to be extended to allow | 38 // TODO(ikilpatrick): WorkerScriptLoader will need to be extended to allow |
39 // module loading support. For now just fetch a 'classic' script. | 39 // module loading support. For now just fetch a 'classic' script. |
40 | 40 |
41 // NOTE: WorkerScriptLoader may synchronously invoke its callbacks | 41 // NOTE: WorkerScriptLoader may synchronously invoke its callbacks |
42 // (resolving the promise) before we return it. | 42 // (resolving the promise) before we return it. |
43 m_scriptLoaders.append(WorkerScriptLoader::create()); | 43 m_scriptLoaders.append(WorkerScriptLoader::create()); |
44 m_scriptLoaders.last()->loadAsynchronously(*getExecutionContext(), scriptURL
, DenyCrossOriginRequests, | 44 m_scriptLoaders.last()->loadAsynchronously(*getExecutionContext(), scriptURL
, DenyCrossOriginRequests, |
45 getExecutionContext()->securityContext().addressSpace(), | 45 getExecutionContext()->securityContext().addressSpace(), |
46 bind(&Worklet::onResponse, this), | 46 bind(&Worklet::onResponse, this, m_scriptLoaders.last().get()), |
47 bind(&Worklet::onFinished, this, m_scriptLoaders.last().get(), resolver)
); | 47 bind(&Worklet::onFinished, this, m_scriptLoaders.last().get(), resolver)
); |
48 | 48 |
49 return promise; | 49 return promise; |
50 } | 50 } |
51 | 51 |
52 void Worklet::onResponse() | 52 void Worklet::onResponse(WorkerScriptLoader* scriptLoader) |
53 { | 53 { |
54 // TODO(ikilpatrick): Add devtools instrumentation on worklet script | 54 InspectorInstrumentation::didReceiveScriptResponse(getExecutionContext(), sc
riptLoader->identifier()); |
55 // resource loading. | |
56 } | 55 } |
57 | 56 |
58 void Worklet::onFinished(WorkerScriptLoader* scriptLoader, ScriptPromiseResolver
* resolver) | 57 void Worklet::onFinished(WorkerScriptLoader* scriptLoader, ScriptPromiseResolver
* resolver) |
59 { | 58 { |
60 if (scriptLoader->failed()) { | 59 if (scriptLoader->failed()) { |
61 resolver->reject(DOMException::create(NetworkError)); | 60 resolver->reject(DOMException::create(NetworkError)); |
62 } else { | 61 } else { |
63 // TODO(ikilpatrick): Worklets don't have the same error behaviour | 62 // TODO(ikilpatrick): Worklets don't have the same error behaviour |
64 // as workers, etc. For a SyntaxError we should reject, however if | 63 // as workers, etc. For a SyntaxError we should reject, however if |
65 // the script throws a normal error, resolve. For now just resolve. | 64 // the script throws a normal error, resolve. For now just resolve. |
(...skipping 20 matching lines...) Expand all Loading... |
86 } | 85 } |
87 } | 86 } |
88 | 87 |
89 DEFINE_TRACE(Worklet) | 88 DEFINE_TRACE(Worklet) |
90 { | 89 { |
91 visitor->trace(m_resolvers); | 90 visitor->trace(m_resolvers); |
92 ActiveDOMObject::trace(visitor); | 91 ActiveDOMObject::trace(visitor); |
93 } | 92 } |
94 | 93 |
95 } // namespace blink | 94 } // namespace blink |
OLD | NEW |