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/dom/Modulator.h" | 5 #include "core/dom/Modulator.h" |
6 | 6 |
7 #include "bindings/core/v8/V8BindingForCore.h" | 7 #include "bindings/core/v8/V8BindingForCore.h" |
8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
9 #include "core/dom/ModulatorImpl.h" | 9 #include "core/dom/ModulatorImpl.h" |
10 #include "core/frame/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
| 11 #include "core/workers/MainThreadWorkletGlobalScope.h" |
11 #include "platform/bindings/ScriptState.h" | 12 #include "platform/bindings/ScriptState.h" |
12 #include "platform/bindings/V8PerContextData.h" | 13 #include "platform/bindings/V8PerContextData.h" |
13 | 14 |
14 namespace blink { | 15 namespace blink { |
15 | 16 |
16 namespace { | 17 namespace { |
17 const char kPerContextDataKey[] = "Modulator"; | 18 const char kPerContextDataKey[] = "Modulator"; |
18 } // namespace | 19 } // namespace |
19 | 20 |
20 Modulator* Modulator::From(ScriptState* script_state) { | 21 Modulator* Modulator::From(ScriptState* script_state) { |
21 if (!script_state) | 22 if (!script_state) |
22 return nullptr; | 23 return nullptr; |
23 | 24 |
24 V8PerContextData* per_context_data = script_state->PerContextData(); | 25 V8PerContextData* per_context_data = script_state->PerContextData(); |
25 if (!per_context_data) | 26 if (!per_context_data) |
26 return nullptr; | 27 return nullptr; |
27 | 28 |
28 Modulator* modulator = | 29 Modulator* modulator = |
29 static_cast<Modulator*>(per_context_data->GetData(kPerContextDataKey)); | 30 static_cast<Modulator*>(per_context_data->GetData(kPerContextDataKey)); |
30 if (!modulator) { | 31 if (modulator) |
31 if (Document* document = ToDocument(ExecutionContext::From(script_state))) { | 32 return modulator; |
32 modulator = ModulatorImpl::Create(script_state, document->Fetcher()); | 33 ExecutionContext* execution_context = ExecutionContext::From(script_state); |
33 Modulator::SetModulator(script_state, modulator); | 34 if (execution_context->IsDocument()) { |
34 } | 35 Document* document = ToDocument(execution_context); |
| 36 modulator = ModulatorImpl::Create(script_state, document->Fetcher()); |
| 37 Modulator::SetModulator(script_state, modulator); |
| 38 } else if (execution_context->IsMainThreadWorkletGlobalScope()) { |
| 39 MainThreadWorkletGlobalScope* global_scope = |
| 40 ToMainThreadWorkletGlobalScope(execution_context); |
| 41 modulator = ModulatorImpl::Create( |
| 42 script_state, global_scope->GetFrame()->GetDocument()->Fetcher()); |
| 43 Modulator::SetModulator(script_state, modulator); |
| 44 } else { |
| 45 NOTREACHED(); |
35 } | 46 } |
36 return modulator; | 47 return modulator; |
37 } | 48 } |
38 | 49 |
39 Modulator::~Modulator() {} | 50 Modulator::~Modulator() {} |
40 | 51 |
41 void Modulator::SetModulator(ScriptState* script_state, Modulator* modulator) { | 52 void Modulator::SetModulator(ScriptState* script_state, Modulator* modulator) { |
42 DCHECK(script_state); | 53 DCHECK(script_state); |
43 V8PerContextData* per_context_data = script_state->PerContextData(); | 54 V8PerContextData* per_context_data = script_state->PerContextData(); |
44 DCHECK(per_context_data); | 55 DCHECK(per_context_data); |
(...skipping 27 matching lines...) Expand all Loading... |
72 // script's base URL as the base URL. | 83 // script's base URL as the base URL. |
73 DCHECK(base_url.IsValid()); | 84 DCHECK(base_url.IsValid()); |
74 KURL absolute_url(base_url, module_request); | 85 KURL absolute_url(base_url, module_request); |
75 if (absolute_url.IsValid()) | 86 if (absolute_url.IsValid()) |
76 return absolute_url; | 87 return absolute_url; |
77 | 88 |
78 return KURL(); | 89 return KURL(); |
79 } | 90 } |
80 | 91 |
81 } // namespace blink | 92 } // namespace blink |
OLD | NEW |