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

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

Issue 2912743002: [WIP] Worklet: Merge MainThreadWorklet and ThreadedWorklet into Worklet
Patch Set: WIP 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/workers/Worklet.cpp
diff --git a/third_party/WebKit/Source/core/workers/Worklet.cpp b/third_party/WebKit/Source/core/workers/Worklet.cpp
index 6620d822b7d92d4b754b6a80fd0832aaa5d7423f..fd85146ec383ab1de10938df39583ff0bb8202a2 100644
--- a/third_party/WebKit/Source/core/workers/Worklet.cpp
+++ b/third_party/WebKit/Source/core/workers/Worklet.cpp
@@ -10,9 +10,28 @@
#include "core/dom/TaskRunnerHelper.h"
#include "core/frame/LocalFrame.h"
#include "core/workers/WorkletGlobalScopeProxy.h"
+#include "core/workers/WorkletPendingTasks.h"
+#include "platform/wtf/WTF.h"
+#include "public/platform/WebURLRequest.h"
namespace blink {
+namespace {
+
+WebURLRequest::FetchCredentialsMode ParseCredentialsOption(
+ const String& credentials_option) {
+ if (credentials_option == "omit")
+ return WebURLRequest::kFetchCredentialsModeOmit;
+ if (credentials_option == "same-origin")
+ return WebURLRequest::kFetchCredentialsModeSameOrigin;
+ if (credentials_option == "include")
+ return WebURLRequest::kFetchCredentialsModeInclude;
+ NOTREACHED();
+ return WebURLRequest::kFetchCredentialsModeOmit;
+}
+
+} // namespace
+
Worklet::Worklet(LocalFrame* frame)
: ContextLifecycleObserver(frame->GetDocument()) {
DCHECK(IsMainThread());
@@ -62,6 +81,74 @@ ScriptPromise Worklet::addModule(ScriptState* script_state,
return promise;
}
+void Worklet::ContextDestroyed(ExecutionContext* execution_context) {
+ DCHECK(IsMainThread());
+ for (const auto& proxy : proxies_)
+ proxy->TerminateWorkletGlobalScope();
+}
+
+WorkletGlobalScopeProxy* Worklet::FindAvailableGlobalScope() const {
+ DCHECK(IsMainThread());
+ // TODO(nhiroki): Support the case where there are multiple global scopes.
+ DCHECK_EQ(1u, GetNumberOfGlobalScopes());
+ return proxies_.begin()->get();
+}
+
+// Implementation of the second half of the "addModule(moduleURL, options)"
+// algorithm:
+// https://drafts.css-houdini.org/worklets/#dom-worklet-addmodule
+void Worklet::FetchAndInvokeScript(const KURL& module_url_record,
+ const WorkletOptions& options,
+ ScriptPromiseResolver* resolver) {
+ DCHECK(IsMainThread());
+ if (!GetExecutionContext())
+ return;
+
+ // Step 6: "Let credentialOptions be the credentials member of options."
+ // TODO(nhiroki): Add tests for credentialOptions (https://crbug.com/710837).
+ WebURLRequest::FetchCredentialsMode credentials_mode =
+ ParseCredentialsOption(options.credentials());
+
+ // Step 7: "Let outsideSettings be the relevant settings object of this."
+ // TODO(nhiroki): outsideSettings will be used for posting a task to the
+ // document's responsible event loop. We could use a task runner for the
+ // purpose.
+
+ // Step 8: "Let moduleResponsesMap be worklet's module responses map."
+ // TODO(nhiroki): Implement moduleResponsesMap (https://crbug.com/627945).
+
+ // Step 9: "Let workletGlobalScopeType be worklet's worklet global scope
+ // type."
+ // workletGlobalScopeType is encoded into the class name (e.g., PaintWorklet).
+
+ // Step 10: "If the worklet's WorkletGlobalScopes is empty, run the following
+ // steps:"
+ // 10.1: "Create a WorkletGlobalScope given workletGlobalScopeType,
+ // moduleResponsesMap, and outsideSettings."
+ // 10.2: "Add the WorkletGlobalScope to worklet's WorkletGlobalScopes."
+ // "Depending on the type of worklet the user agent may create additional
+ // WorkletGlobalScopes at this time."
+ while (NeedsToCreateGlobalScope())
+ proxies_.insert(CreateGlobalScope());
+ DCHECK_LT(1u, GetNumberOfGlobalScopes());
+
+ // Step 11: "Let pendingTaskStruct be a new pending tasks struct with counter
+ // initialized to the length of worklet's WorkletGlobalScopes."
+ WorkletPendingTasks* pending_tasks =
+ new WorkletPendingTasks(GetNumberOfGlobalScopes(), resolver);
+
+ // Step 12: "For each workletGlobalScope in the worklet's
+ // WorkletGlobalScopes, queue a task on the workletGlobalScope to fetch and
+ // invoke a worklet script given workletGlobalScope, moduleURLRecord,
+ // moduleResponsesMap, credentialOptions, outsideSettings, pendingTaskStruct,
+ // and promise."
+ // TODO(nhiroki): Queue a task instead of executing this here.
+ for (const auto& proxy : proxies_) {
+ proxy->FetchAndInvokeScript(module_url_record, credentials_mode,
+ pending_tasks);
+ }
+}
+
DEFINE_TRACE(Worklet) {
ContextLifecycleObserver::Trace(visitor);
}
« no previous file with comments | « third_party/WebKit/Source/core/workers/Worklet.h ('k') | third_party/WebKit/Source/core/workers/WorkletGlobalScopeProxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698