| 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 "modules/worklet/WorkletGlobalScope.h" | 13 #include "modules/worklet/WorkletGlobalScope.h" |
| 14 | 14 |
| 15 namespace blink { | 15 namespace blink { |
| 16 | 16 |
| 17 // static | 17 // static |
| 18 Worklet* Worklet::create(LocalFrame* frame, ExecutionContext* executionContext) | 18 Worklet* Worklet::create(LocalFrame* frame, ExecutionContext* executionContext) |
| 19 { | 19 { |
| 20 Worklet* worklet = new Worklet(frame, executionContext); | 20 Worklet* worklet = new Worklet(frame, executionContext); |
| 21 worklet->suspendIfNeeded(); | 21 worklet->suspendIfNeeded(); |
| 22 return worklet; | 22 return worklet; |
| 23 } | 23 } |
| 24 | 24 |
| 25 Worklet::Worklet(LocalFrame* frame, ExecutionContext* executionContext) | 25 Worklet::Worklet(LocalFrame* frame, ExecutionContext* executionContext) |
| 26 : ActiveDOMObject(executionContext) | 26 : ActiveDOMObject(executionContext) |
| 27 , m_workletGlobalScope(WorkletGlobalScope::create(frame, executionContext->u
rl(), executionContext->userAgent(), executionContext->securityOrigin(), toIsola
te(executionContext))) | 27 , m_workletGlobalScope(WorkletGlobalScope::create(frame, executionContext->u
rl(), executionContext->userAgent(), executionContext->getSecurityOrigin(), toIs
olate(executionContext))) |
| 28 { | 28 { |
| 29 } | 29 } |
| 30 | 30 |
| 31 ScriptPromise Worklet::import(ScriptState* scriptState, const String& url) | 31 ScriptPromise Worklet::import(ScriptState* scriptState, const String& url) |
| 32 { | 32 { |
| 33 KURL scriptURL = executionContext()->completeURL(url); | 33 KURL scriptURL = getExecutionContext()->completeURL(url); |
| 34 if (!scriptURL.isValid()) { | 34 if (!scriptURL.isValid()) { |
| 35 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(SyntaxError, "'" + url + "' is not a valid URL.")); | 35 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(SyntaxError, "'" + url + "' is not a valid URL.")); |
| 36 } | 36 } |
| 37 | 37 |
| 38 // TODO(ikilpatrick): Perform upfront CSP checks once we decide on a | 38 // TODO(ikilpatrick): Perform upfront CSP checks once we decide on a |
| 39 // CSP-policy for worklets. | 39 // CSP-policy for worklets. |
| 40 | 40 |
| 41 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 41 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 42 m_resolvers.append(resolver); | 42 m_resolvers.append(resolver); |
| 43 | 43 |
| 44 ScriptPromise promise = resolver->promise(); | 44 ScriptPromise promise = resolver->promise(); |
| 45 | 45 |
| 46 // TODO(ikilpatrick): WorkerScriptLoader will need to be extended to allow | 46 // TODO(ikilpatrick): WorkerScriptLoader will need to be extended to allow |
| 47 // module loading support. For now just fetch a 'classic' script. | 47 // module loading support. For now just fetch a 'classic' script. |
| 48 | 48 |
| 49 // NOTE: WorkerScriptLoader may synchronously invoke its callbacks | 49 // NOTE: WorkerScriptLoader may synchronously invoke its callbacks |
| 50 // (resolving the promise) before we return it. | 50 // (resolving the promise) before we return it. |
| 51 m_scriptLoaders.append(WorkerScriptLoader::create()); | 51 m_scriptLoaders.append(WorkerScriptLoader::create()); |
| 52 m_scriptLoaders.last()->loadAsynchronously(*executionContext(), scriptURL, D
enyCrossOriginRequests, | 52 m_scriptLoaders.last()->loadAsynchronously(*getExecutionContext(), scriptURL
, DenyCrossOriginRequests, |
| 53 executionContext()->securityContext().addressSpace(), | 53 getExecutionContext()->securityContext().addressSpace(), |
| 54 bind(&Worklet::onResponse, this), | 54 bind(&Worklet::onResponse, this), |
| 55 bind(&Worklet::onFinished, this, m_scriptLoaders.last().get(), resolver)
); | 55 bind(&Worklet::onFinished, this, m_scriptLoaders.last().get(), resolver)
); |
| 56 | 56 |
| 57 return promise; | 57 return promise; |
| 58 } | 58 } |
| 59 | 59 |
| 60 void Worklet::onResponse() | 60 void Worklet::onResponse() |
| 61 { | 61 { |
| 62 // TODO(ikilpatrick): Add devtools instrumentation on worklet script | 62 // TODO(ikilpatrick): Add devtools instrumentation on worklet script |
| 63 // resource loading. | 63 // resource loading. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 94 } | 94 } |
| 95 | 95 |
| 96 DEFINE_TRACE(Worklet) | 96 DEFINE_TRACE(Worklet) |
| 97 { | 97 { |
| 98 visitor->trace(m_resolvers); | 98 visitor->trace(m_resolvers); |
| 99 visitor->trace(m_workletGlobalScope); | 99 visitor->trace(m_workletGlobalScope); |
| 100 ActiveDOMObject::trace(visitor); | 100 ActiveDOMObject::trace(visitor); |
| 101 } | 101 } |
| 102 | 102 |
| 103 } // namespace blink | 103 } // namespace blink |
| OLD | NEW |