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

Unified Diff: third_party/WebKit/Source/core/workers/MainThreadWorkletGlobalScope.cpp

Issue 2830603003: Worklet: Move WorkletScriptLoader from MainThreadWorklet to MainThreadWorkletGlobalScope (Closed)
Patch Set: const auto& Created 3 years, 8 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/workers/MainThreadWorkletGlobalScope.cpp
diff --git a/third_party/WebKit/Source/core/workers/MainThreadWorkletGlobalScope.cpp b/third_party/WebKit/Source/core/workers/MainThreadWorkletGlobalScope.cpp
index 2929a2a42c9abacaf757159882e2643ef22849e1..3b11b5281e04b9b97bc76c6e122bb67ee3624147 100644
--- a/third_party/WebKit/Source/core/workers/MainThreadWorkletGlobalScope.cpp
+++ b/third_party/WebKit/Source/core/workers/MainThreadWorkletGlobalScope.cpp
@@ -6,6 +6,7 @@
#include "bindings/core/v8/ScriptSourceCode.h"
#include "bindings/core/v8/WorkerOrWorkletScriptController.h"
+#include "core/dom/Document.h"
#include "core/frame/Deprecation.h"
#include "core/frame/FrameConsole.h"
#include "core/frame/LocalFrame.h"
@@ -18,9 +19,11 @@ MainThreadWorkletGlobalScope::MainThreadWorkletGlobalScope(
const KURL& url,
const String& user_agent,
PassRefPtr<SecurityOrigin> security_origin,
- v8::Isolate* isolate)
+ v8::Isolate* isolate,
+ WorkletObjectProxy* object_proxy)
: WorkletGlobalScope(url, user_agent, std::move(security_origin), isolate),
- ContextClient(frame) {}
+ ContextClient(frame),
+ object_proxy_(object_proxy) {}
MainThreadWorkletGlobalScope::~MainThreadWorkletGlobalScope() {}
@@ -45,15 +48,43 @@ WorkerThread* MainThreadWorkletGlobalScope::GetThread() const {
return nullptr;
}
+void MainThreadWorkletGlobalScope::FetchAndInvokeScript(
+ int32_t request_id,
+ const KURL& script_url) {
+ DCHECK(IsMainThread());
+ // TODO(nhiroki): Replace this with module script loading.
+ WorkletScriptLoader* script_loader =
+ WorkletScriptLoader::Create(GetFrame()->GetDocument()->Fetcher(), this);
+ script_loader->set_request_id(request_id);
+ loader_set_.insert(script_loader);
+ script_loader->FetchScript(script_url);
+}
+
void MainThreadWorkletGlobalScope::EvaluateScript(
const ScriptSourceCode& script_source_code) {
- ScriptController()->Evaluate(script_source_code);
+ // This should be called only for threaded worklets that still use classic
+ // script loading.
+ NOTREACHED();
}
void MainThreadWorkletGlobalScope::TerminateWorkletGlobalScope() {
+ for (const auto& script_loader : loader_set_)
+ script_loader->Cancel();
Dispose();
}
+void MainThreadWorkletGlobalScope::NotifyWorkletScriptLoadingFinished(
+ WorkletScriptLoader* script_loader,
+ const ScriptSourceCode& source_code) {
+ DCHECK(IsMainThread());
+ int32_t request_id = script_loader->request_id();
+ loader_set_.erase(script_loader);
+ bool success = script_loader->WasScriptLoadSuccessful();
+ if (success)
+ ScriptController()->Evaluate(source_code);
+ object_proxy_->DidFetchAndInvokeScript(request_id, success);
+}
+
void MainThreadWorkletGlobalScope::AddConsoleMessage(
ConsoleMessage* console_message) {
GetFrame()->Console().AddMessage(console_message);
@@ -63,4 +94,11 @@ void MainThreadWorkletGlobalScope::ExceptionThrown(ErrorEvent* event) {
MainThreadDebugger::Instance()->ExceptionThrown(this, event);
}
+DEFINE_TRACE(MainThreadWorkletGlobalScope) {
+ visitor->Trace(loader_set_);
+ visitor->Trace(object_proxy_);
+ WorkletGlobalScope::Trace(visitor);
+ ContextClient::Trace(visitor);
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698