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/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/V8BindingForCore.h" | 9 #include "bindings/core/v8/V8BindingForCore.h" |
10 #include "core/frame/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
11 #include "core/workers/WorkletGlobalScopeProxy.h" | 11 #include "core/workers/WorkletGlobalScopeProxy.h" |
12 #include "core/workers/WorkletPendingTasks.h" | 12 #include "core/workers/WorkletPendingTasks.h" |
13 #include "platform/wtf/WTF.h" | 13 #include "platform/wtf/WTF.h" |
| 14 #include "public/platform/WebURLRequest.h" |
14 | 15 |
15 namespace blink { | 16 namespace blink { |
16 | 17 |
| 18 namespace { |
| 19 |
| 20 WebURLRequest::FetchCredentialsMode ParseCredentialsOption( |
| 21 const String& credentials_option) { |
| 22 if (credentials_option == "omit") |
| 23 return WebURLRequest::kFetchCredentialsModeOmit; |
| 24 if (credentials_option == "same-origin") |
| 25 return WebURLRequest::kFetchCredentialsModeSameOrigin; |
| 26 if (credentials_option == "include") |
| 27 return WebURLRequest::kFetchCredentialsModeInclude; |
| 28 NOTREACHED(); |
| 29 return WebURLRequest::kFetchCredentialsModeOmit; |
| 30 } |
| 31 |
| 32 } // namespace |
| 33 |
17 MainThreadWorklet::MainThreadWorklet(LocalFrame* frame) : Worklet(frame) {} | 34 MainThreadWorklet::MainThreadWorklet(LocalFrame* frame) : Worklet(frame) {} |
18 | 35 |
19 // Implementation of the second half of the "addModule(moduleURL, options)" | 36 // Implementation of the second half of the "addModule(moduleURL, options)" |
20 // algorithm: | 37 // algorithm: |
21 // https://drafts.css-houdini.org/worklets/#dom-worklet-addmodule | 38 // https://drafts.css-houdini.org/worklets/#dom-worklet-addmodule |
22 void MainThreadWorklet::FetchAndInvokeScript(const KURL& module_url_record, | 39 void MainThreadWorklet::FetchAndInvokeScript(const KURL& module_url_record, |
| 40 const WorkletOptions& options, |
23 ScriptPromiseResolver* resolver) { | 41 ScriptPromiseResolver* resolver) { |
24 DCHECK(IsMainThread()); | 42 DCHECK(IsMainThread()); |
25 if (!GetExecutionContext()) | 43 if (!GetExecutionContext()) |
26 return; | 44 return; |
27 | 45 |
28 // Step 6: "Let credentialOptions be the credentials member of options." | 46 // Step 6: "Let credentialOptions be the credentials member of options." |
29 // TODO(nhiroki): Implement credentialOptions (https://crbug.com/710837). | 47 // TODO(nhiroki): Add tests for credentialOptions (https://crbug.com/710837). |
| 48 WebURLRequest::FetchCredentialsMode credentials_mode = |
| 49 ParseCredentialsOption(options.credentials()); |
30 | 50 |
31 // Step 7: "Let outsideSettings be the relevant settings object of this." | 51 // Step 7: "Let outsideSettings be the relevant settings object of this." |
32 // TODO(nhiroki): outsideSettings will be used for posting a task to the | 52 // TODO(nhiroki): outsideSettings will be used for posting a task to the |
33 // document's responsible event loop. We could use a task runner for the | 53 // document's responsible event loop. We could use a task runner for the |
34 // purpose. | 54 // purpose. |
35 | 55 |
36 // Step 8: "Let moduleResponsesMap be worklet's module responses map." | 56 // Step 8: "Let moduleResponsesMap be worklet's module responses map." |
37 // TODO(nhiroki): Implement moduleResponsesMap (https://crbug.com/627945). | 57 // TODO(nhiroki): Implement moduleResponsesMap (https://crbug.com/627945). |
38 | 58 |
39 // Step 9: "Let workletGlobalScopeType be worklet's worklet global scope | 59 // Step 9: "Let workletGlobalScopeType be worklet's worklet global scope |
(...skipping 15 matching lines...) Expand all Loading... |
55 // use the length of it here. | 75 // use the length of it here. |
56 constexpr int number_of_global_scopes = 1; | 76 constexpr int number_of_global_scopes = 1; |
57 WorkletPendingTasks* pending_tasks = | 77 WorkletPendingTasks* pending_tasks = |
58 new WorkletPendingTasks(number_of_global_scopes, resolver); | 78 new WorkletPendingTasks(number_of_global_scopes, resolver); |
59 | 79 |
60 // Step 12: "For each workletGlobalScope in the worklet's | 80 // Step 12: "For each workletGlobalScope in the worklet's |
61 // WorkletGlobalScopes, queue a task on the workletGlobalScope to fetch and | 81 // WorkletGlobalScopes, queue a task on the workletGlobalScope to fetch and |
62 // invoke a worklet script given workletGlobalScope, moduleURLRecord, | 82 // invoke a worklet script given workletGlobalScope, moduleURLRecord, |
63 // moduleResponsesMap, credentialOptions, outsideSettings, pendingTaskStruct, | 83 // moduleResponsesMap, credentialOptions, outsideSettings, pendingTaskStruct, |
64 // and promise." | 84 // and promise." |
65 // TODO(nhiroki): Pass the remaining parameters (e.g., credentialOptions). | |
66 // TODO(nhiroki): Queue a task instead of executing this here. | 85 // TODO(nhiroki): Queue a task instead of executing this here. |
67 GetWorkletGlobalScopeProxy()->FetchAndInvokeScript(module_url_record, | 86 GetWorkletGlobalScopeProxy()->FetchAndInvokeScript( |
68 pending_tasks); | 87 module_url_record, credentials_mode, pending_tasks); |
69 } | 88 } |
70 | 89 |
71 void MainThreadWorklet::ContextDestroyed(ExecutionContext* execution_context) { | 90 void MainThreadWorklet::ContextDestroyed(ExecutionContext* execution_context) { |
72 DCHECK(IsMainThread()); | 91 DCHECK(IsMainThread()); |
73 GetWorkletGlobalScopeProxy()->TerminateWorkletGlobalScope(); | 92 GetWorkletGlobalScopeProxy()->TerminateWorkletGlobalScope(); |
74 } | 93 } |
75 | 94 |
76 DEFINE_TRACE(MainThreadWorklet) { | 95 DEFINE_TRACE(MainThreadWorklet) { |
77 Worklet::Trace(visitor); | 96 Worklet::Trace(visitor); |
78 } | 97 } |
79 | 98 |
80 } // namespace blink | 99 } // namespace blink |
OLD | NEW |