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/Worklet.h" | 5 #include "core/workers/Worklet.h" |
6 | 6 |
7 #include "bindings/core/v8/ScriptPromiseResolver.h" | 7 #include "bindings/core/v8/ScriptPromiseResolver.h" |
8 #include "core/dom/DOMException.h" | 8 #include "core/dom/DOMException.h" |
9 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
10 #include "core/dom/TaskRunnerHelper.h" | 10 #include "core/dom/TaskRunnerHelper.h" |
11 #include "core/frame/LocalFrame.h" | 11 #include "core/frame/LocalFrame.h" |
12 #include "core/workers/WorkletGlobalScopeProxy.h" | 12 #include "core/workers/WorkletGlobalScopeProxy.h" |
13 | 13 |
14 namespace blink { | 14 namespace blink { |
15 | 15 |
16 Worklet::Worklet(LocalFrame* frame) | 16 Worklet::Worklet(LocalFrame* frame) |
17 : ContextLifecycleObserver(frame->GetDocument()) { | 17 : ContextLifecycleObserver(frame->GetDocument()) { |
18 DCHECK(IsMainThread()); | 18 DCHECK(IsMainThread()); |
19 } | 19 } |
20 | 20 |
21 // Implementation of the first half of the "addModule(moduleURL, options)" | 21 // Implementation of the first half of the "addModule(moduleURL, options)" |
22 // algorithm: | 22 // algorithm: |
23 // https://drafts.css-houdini.org/worklets/#dom-worklet-addmodule | 23 // https://drafts.css-houdini.org/worklets/#dom-worklet-addmodule |
24 ScriptPromise Worklet::addModule(ScriptState* script_state, | 24 ScriptPromise Worklet::addModule(ScriptState* script_state, |
25 const String& module_url) { | 25 const String& module_url, |
| 26 const WorkletOptions& options) { |
26 DCHECK(IsMainThread()); | 27 DCHECK(IsMainThread()); |
27 if (!GetExecutionContext()) { | 28 if (!GetExecutionContext()) { |
28 return ScriptPromise::RejectWithDOMException( | 29 return ScriptPromise::RejectWithDOMException( |
29 script_state, DOMException::Create(kInvalidStateError, | 30 script_state, DOMException::Create(kInvalidStateError, |
30 "This frame is already detached")); | 31 "This frame is already detached")); |
31 } | 32 } |
32 | 33 |
33 // Step 1: "Let promise be a new promise." | 34 // Step 1: "Let promise be a new promise." |
34 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); | 35 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); |
35 ScriptPromise promise = resolver->Promise(); | 36 ScriptPromise promise = resolver->Promise(); |
(...skipping 11 matching lines...) Expand all Loading... |
47 resolver->Reject(DOMException::Create( | 48 resolver->Reject(DOMException::Create( |
48 kSyntaxError, "'" + module_url + "' is not a valid URL.")); | 49 kSyntaxError, "'" + module_url + "' is not a valid URL.")); |
49 return promise; | 50 return promise; |
50 } | 51 } |
51 | 52 |
52 // Step 5: "Return promise, and then continue running this algorithm in | 53 // Step 5: "Return promise, and then continue running this algorithm in |
53 // parallel." | 54 // parallel." |
54 // |kUnspecedLoading| is used here because this is a part of script module | 55 // |kUnspecedLoading| is used here because this is a part of script module |
55 // loading. | 56 // loading. |
56 TaskRunnerHelper::Get(TaskType::kUnspecedLoading, script_state) | 57 TaskRunnerHelper::Get(TaskType::kUnspecedLoading, script_state) |
57 ->PostTask(BLINK_FROM_HERE, | 58 ->PostTask( |
58 WTF::Bind(&Worklet::FetchAndInvokeScript, WrapPersistent(this), | 59 BLINK_FROM_HERE, |
59 module_url_record, WrapPersistent(resolver))); | 60 WTF::Bind(&Worklet::FetchAndInvokeScript, WrapPersistent(this), |
| 61 module_url_record, options, WrapPersistent(resolver))); |
60 return promise; | 62 return promise; |
61 } | 63 } |
62 | 64 |
63 DEFINE_TRACE(Worklet) { | 65 DEFINE_TRACE(Worklet) { |
64 ContextLifecycleObserver::Trace(visitor); | 66 ContextLifecycleObserver::Trace(visitor); |
65 } | 67 } |
66 | 68 |
67 } // namespace blink | 69 } // namespace blink |
OLD | NEW |