OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/MainThreadWorklet.h" | 5 #include "core/workers/MainThreadWorklet.h" |
6 | 6 |
7 #include "bindings/core/v8/ScriptSourceCode.h" | 7 #include "bindings/core/v8/ScriptSourceCode.h" |
8 #include "bindings/core/v8/V8BindingForCore.h" | 8 #include "bindings/core/v8/V8BindingForCore.h" |
9 #include "core/dom/DOMException.h" | 9 #include "core/dom/DOMException.h" |
10 #include "core/dom/Document.h" | 10 #include "core/dom/Document.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 // https://drafts.css-houdini.org/worklets/#dom-worklet-addmodule | 22 // https://drafts.css-houdini.org/worklets/#dom-worklet-addmodule |
23 ScriptPromise MainThreadWorklet::addModule(ScriptState* script_state, | 23 ScriptPromise MainThreadWorklet::addModule(ScriptState* script_state, |
24 const String& module_url) { | 24 const String& module_url) { |
25 DCHECK(IsMainThread()); | 25 DCHECK(IsMainThread()); |
26 if (!GetExecutionContext()) { | 26 if (!GetExecutionContext()) { |
27 return ScriptPromise::RejectWithDOMException( | 27 return ScriptPromise::RejectWithDOMException( |
28 script_state, DOMException::Create(kInvalidStateError, | 28 script_state, DOMException::Create(kInvalidStateError, |
29 "This frame is already detached")); | 29 "This frame is already detached")); |
30 } | 30 } |
31 | 31 |
32 KURL module_url_record = GetExecutionContext()->CompleteURL(module_url); | 32 // Step 1: "Let promise be a new promise." |
33 if (!module_url_record.IsValid()) { | |
34 return ScriptPromise::RejectWithDOMException( | |
35 script_state, | |
36 DOMException::Create(kSyntaxError, | |
37 "'" + module_url + "' is not a valid URL.")); | |
38 } | |
39 | |
40 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); | 33 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); |
41 ScriptPromise promise = resolver->Promise(); | 34 ScriptPromise promise = resolver->Promise(); |
42 | 35 |
| 36 // Step 2: "Let worklet be the current Worklet." |
| 37 // |this| is the current Worklet. |
| 38 |
| 39 // Step 3: "Let moduleURLRecord be the result of parsing the moduleURL |
| 40 // argument relative to the relevant settings object of this." |
| 41 KURL module_url_record = GetExecutionContext()->CompleteURL(module_url); |
| 42 |
| 43 // Step 4: "If moduleURLRecord is failure, then reject promise with a |
| 44 // "SyntaxError" DOMException and return promise." |
| 45 if (!module_url_record.IsValid()) { |
| 46 resolver->Reject(DOMException::Create( |
| 47 kSyntaxError, "'" + module_url + "' is not a valid URL.")); |
| 48 return promise; |
| 49 } |
| 50 |
| 51 // Step 5: "Return promise, and then continue running this algorithm in |
| 52 // parallel." |
| 53 // TODO(nhiroki): Make the following sequence async. |
| 54 |
| 55 // Step 6: "Let credentialOptions be the credentials member of options." |
| 56 // TODO(nhiroki): Implement credentialOptions (https://crbug.com/710837). |
| 57 |
| 58 // Step 7: "Let outsideSettings be the relevant settings object of this." |
| 59 // TODO(nhiroki): outsideSettings will be used for posting a task to the |
| 60 // document's responsible event loop. We could use a task runner for the |
| 61 // purpose. |
| 62 |
| 63 // Step 8: "Let moduleResponsesMap be worklet's module responses map." |
| 64 // TODO(nhiroki): Implement moduleResponsesMap (https://crbug.com/627945). |
| 65 |
| 66 // Step 9: "Let workletGlobalScopeType be worklet's worklet global scope |
| 67 // type." |
| 68 // workletGlobalScopeType is encoded into the class name (e.g., PaintWorklet). |
| 69 |
| 70 // Step 10: "If the worklet's WorkletGlobalScopes is empty, run the following |
| 71 // steps:" |
| 72 // 10.1: "Create a WorkletGlobalScope given workletGlobalScopeType, |
| 73 // moduleResponsesMap, and outsideSettings." |
| 74 // 10.2: "Add the WorkletGlobalScope to worklet's WorkletGlobalScopes." |
| 75 // "Depending on the type of worklet the user agent may create additional |
| 76 // WorkletGlobalScopes at this time." |
| 77 // TODO(nhiroki): Create WorkletGlobalScopes at this point. |
| 78 |
43 // Step 11: "Let pendingTaskStruct be a new pending tasks struct with counter | 79 // Step 11: "Let pendingTaskStruct be a new pending tasks struct with counter |
44 // initialized to the length of worklet's WorkletGlobalScopes." | 80 // initialized to the length of worklet's WorkletGlobalScopes." |
45 // TODO(nhiroki): Introduce the concept of "worklet's WorkletGlobalScopes" and | 81 // TODO(nhiroki): Introduce the concept of "worklet's WorkletGlobalScopes" and |
46 // use the length of it here. | 82 // use the length of it here. |
47 constexpr int number_of_global_scopes = 1; | 83 constexpr int number_of_global_scopes = 1; |
48 WorkletPendingTasks* pending_tasks = | 84 WorkletPendingTasks* pending_tasks = |
49 new WorkletPendingTasks(number_of_global_scopes, resolver); | 85 new WorkletPendingTasks(number_of_global_scopes, resolver); |
50 | 86 |
51 // Step 12: "For each workletGlobalScope in the worklet's | 87 // Step 12: "For each workletGlobalScope in the worklet's |
52 // WorkletGlobalScopes, queue a task on the workletGlobalScope to fetch and | 88 // WorkletGlobalScopes, queue a task on the workletGlobalScope to fetch and |
(...skipping 11 matching lines...) Expand all Loading... |
64 DCHECK(IsMainThread()); | 100 DCHECK(IsMainThread()); |
65 GetWorkletGlobalScopeProxy()->TerminateWorkletGlobalScope(); | 101 GetWorkletGlobalScopeProxy()->TerminateWorkletGlobalScope(); |
66 Worklet::ContextDestroyed(execution_context); | 102 Worklet::ContextDestroyed(execution_context); |
67 } | 103 } |
68 | 104 |
69 DEFINE_TRACE(MainThreadWorklet) { | 105 DEFINE_TRACE(MainThreadWorklet) { |
70 Worklet::Trace(visitor); | 106 Worklet::Trace(visitor); |
71 } | 107 } |
72 | 108 |
73 } // namespace blink | 109 } // namespace blink |
OLD | NEW |