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

Unified Diff: third_party/WebKit/Source/modules/worklet/Worklet.cpp

Issue 2178223002: Refactor Worklet class to use ScriptResource (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: synced to the head Created 4 years, 4 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/modules/worklet/Worklet.cpp
diff --git a/third_party/WebKit/Source/modules/worklet/Worklet.cpp b/third_party/WebKit/Source/modules/worklet/Worklet.cpp
index 54993701b26d3318a46beafde5caadf43c95419a..17b71c15c62a25199f2de4c87d646a868324d16d 100644
--- a/third_party/WebKit/Source/modules/worklet/Worklet.cpp
+++ b/third_party/WebKit/Source/modules/worklet/Worklet.cpp
@@ -5,17 +5,22 @@
#include "modules/worklet/Worklet.h"
#include "bindings/core/v8/ScriptPromiseResolver.h"
+#include "bindings/core/v8/ScriptSourceCode.h"
#include "bindings/core/v8/V8Binding.h"
-#include "bindings/core/v8/WorkerOrWorkletScriptController.h"
#include "core/dom/DOMException.h"
#include "core/dom/ExceptionCode.h"
-#include "core/inspector/InspectorInstrumentation.h"
+#include "core/fetch/FetchInitiatorTypeNames.h"
+#include "core/frame/LocalFrame.h"
+#include "core/loader/DocumentLoader.h"
+#include "core/loader/FrameFetchContext.h"
#include "core/workers/WorkletGlobalScopeProxy.h"
+#include "modules/worklet/WorkletScriptLoader.h"
namespace blink {
-Worklet::Worklet(ExecutionContext* executionContext)
- : ActiveDOMObject(executionContext)
+Worklet::Worklet(LocalFrame* frame)
+ : ActiveDOMObject(frame->document())
+ , m_fetcher(frame->loader().documentLoader()->fetcher())
{
}
@@ -26,67 +31,40 @@ ScriptPromise Worklet::import(ScriptState* scriptState, const String& url)
return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(SyntaxError, "'" + url + "' is not a valid URL."));
}
- // TODO(ikilpatrick): Perform upfront CSP checks once we decide on a
- // CSP-policy for worklets.
+ ResourceRequest resourceRequest(scriptURL);
+ resourceRequest.setRequestContext(WebURLRequest::RequestContextScript);
+ FetchRequest request(resourceRequest, FetchInitiatorTypeNames::internal);
+ ScriptResource* resource = ScriptResource::fetch(request, fetcher());
ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
- m_resolvers.append(resolver);
-
ScriptPromise promise = resolver->promise();
-
- // TODO(ikilpatrick): WorkerScriptLoader will need to be extended to allow
- // module loading support. For now just fetch a 'classic' script.
-
- // NOTE: WorkerScriptLoader may synchronously invoke its callbacks
- // (resolving the promise) before we return it.
- m_scriptLoaders.append(WorkerScriptLoader::create());
- m_scriptLoaders.last()->loadAsynchronously(*getExecutionContext(), scriptURL, DenyCrossOriginRequests,
- getExecutionContext()->securityContext().addressSpace(),
- bind(&Worklet::onResponse, wrapPersistent(this), WTF::unretained(m_scriptLoaders.last().get())),
- bind(&Worklet::onFinished, wrapPersistent(this), WTF::unretained(m_scriptLoaders.last().get()), wrapPersistent(resolver)));
-
+ if (resource) {
+ WorkletScriptLoader* workletLoader = WorkletScriptLoader::create(resolver, this, resource);
+ m_scriptLoaders.add(workletLoader);
+ } else {
+ resolver->reject(DOMException::create(NetworkError));
+ }
return promise;
}
-void Worklet::onResponse(WorkerScriptLoader* scriptLoader)
+void Worklet::notifyFinished(WorkletScriptLoader* scriptLoader)
{
- InspectorInstrumentation::didReceiveScriptResponse(getExecutionContext(), scriptLoader->identifier());
-}
-
-void Worklet::onFinished(WorkerScriptLoader* scriptLoader, ScriptPromiseResolver* resolver)
-{
- if (scriptLoader->failed()) {
- resolver->reject(DOMException::create(NetworkError));
- } else {
- // TODO(ikilpatrick): Worklets don't have the same error behaviour
- // as workers, etc. For a SyntaxError we should reject, however if
- // the script throws a normal error, resolve. For now just resolve.
- workletGlobalScopeProxy()->evaluateScript(scriptLoader->script(), scriptLoader->url());
- InspectorInstrumentation::scriptImported(getExecutionContext(), scriptLoader->identifier(), scriptLoader->script());
- resolver->resolve();
- }
-
- size_t index = m_scriptLoaders.find(scriptLoader);
-
- ASSERT(index != kNotFound);
- ASSERT(m_resolvers[index] == resolver);
-
- m_scriptLoaders.remove(index);
- m_resolvers.remove(index);
+ workletGlobalScopeProxy()->evaluateScript(ScriptSourceCode(scriptLoader->resource()));
+ m_scriptLoaders.remove(scriptLoader);
}
void Worklet::stop()
{
workletGlobalScopeProxy()->terminateWorkletGlobalScope();
-
- for (auto scriptLoader : m_scriptLoaders) {
+ for (const auto& scriptLoader : m_scriptLoaders) {
scriptLoader->cancel();
}
}
DEFINE_TRACE(Worklet)
{
- visitor->trace(m_resolvers);
+ visitor->trace(m_fetcher);
+ visitor->trace(m_scriptLoaders);
ActiveDOMObject::trace(visitor);
}
« no previous file with comments | « third_party/WebKit/Source/modules/worklet/Worklet.h ('k') | third_party/WebKit/Source/modules/worklet/WorkletScriptLoader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698