Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Unified Diff: third_party/WebKit/Source/core/dom/Modulator.cpp

Issue 2826313003: Worklet: Enable module script loading for main thread worklets (Closed)
Patch Set: rebase (ready for review) Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/dom/Modulator.cpp
diff --git a/third_party/WebKit/Source/core/dom/Modulator.cpp b/third_party/WebKit/Source/core/dom/Modulator.cpp
index 83a11579aaab62e0374015842120886967506e55..d240b8e06967e43ea9661a70ae2b4ad9b8666191 100644
--- a/third_party/WebKit/Source/core/dom/Modulator.cpp
+++ b/third_party/WebKit/Source/core/dom/Modulator.cpp
@@ -8,6 +8,7 @@
#include "core/dom/Document.h"
#include "core/dom/ModulatorImpl.h"
#include "core/frame/LocalFrame.h"
+#include "core/workers/MainThreadWorkletGlobalScope.h"
#include "platform/bindings/ScriptState.h"
#include "platform/bindings/V8PerContextData.h"
@@ -27,11 +28,21 @@ Modulator* Modulator::From(ScriptState* script_state) {
Modulator* modulator =
static_cast<Modulator*>(per_context_data->GetData(kPerContextDataKey));
- if (!modulator) {
- if (Document* document = ToDocument(ExecutionContext::From(script_state))) {
- modulator = ModulatorImpl::Create(script_state, document->Fetcher());
- Modulator::SetModulator(script_state, modulator);
- }
+ if (modulator)
+ return modulator;
+ ExecutionContext* execution_context = ExecutionContext::From(script_state);
+ if (execution_context->IsDocument()) {
+ Document* document = ToDocument(execution_context);
+ modulator = ModulatorImpl::Create(script_state, document->Fetcher());
+ Modulator::SetModulator(script_state, modulator);
+ } else if (execution_context->IsMainThreadWorkletGlobalScope()) {
+ MainThreadWorkletGlobalScope* global_scope =
+ ToMainThreadWorkletGlobalScope(execution_context);
+ modulator = ModulatorImpl::Create(
+ script_state, global_scope->GetFrame()->GetDocument()->Fetcher());
+ Modulator::SetModulator(script_state, modulator);
+ } else {
+ NOTREACHED();
}
return modulator;
}

Powered by Google App Engine
This is Rietveld 408576698