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

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: set m_fetcher in initialization list, s/override/final, copyright etc. Created 4 years, 5 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..207da36d94bc5d0f7f355e9d958fc5da21618529 100644
--- a/third_party/WebKit/Source/modules/worklet/Worklet.cpp
+++ b/third_party/WebKit/Source/modules/worklet/Worklet.cpp
@@ -6,87 +6,65 @@
#include "bindings/core/v8/ScriptPromiseResolver.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)
+Worklet::Worklet(ExecutionContext* executionContext, LocalFrame* frame)
: ActiveDOMObject(executionContext)
+ , m_fetcher(frame->loader().documentLoader()->fetcher())
{
}
ScriptPromise Worklet::import(ScriptState* scriptState, const String& url)
{
KURL scriptURL = getExecutionContext()->completeURL(url);
ikilpatrick 2016/07/28 22:42:10 should we still do the scriptURL isValid up front
Gleb Lanbin 2016/07/29 01:40:23 Done.
- if (!scriptURL.isValid()) {
- 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) {
+ m_resources.append(resource);
+ WorkletScriptLoader* workletLoader = WorkletScriptLoader::create(resolver, workletGlobalScopeProxy(), this);
+ resource->addClient(workletLoader);
+ } else {
+ resolver->reject(DOMException::create(NetworkError));
+ }
return promise;
}
-void Worklet::onResponse(WorkerScriptLoader* scriptLoader)
+void Worklet::notifyFinished(Resource* resource)
{
- 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);
+ size_t index = m_resources.find(resource);
+ DCHECK(index != kNotFound);
+ DCHECK(m_resources[index] == resource);
+ m_resources.remove(index);
}
void Worklet::stop()
{
workletGlobalScopeProxy()->terminateWorkletGlobalScope();
- for (auto scriptLoader : m_scriptLoaders) {
- scriptLoader->cancel();
+ for (auto resource : m_resources) {
ikilpatrick 2016/07/28 22:42:10 auto& ?
Gleb Lanbin 2016/07/29 01:40:23 Done.
+ resource->loader()->cancel();
}
}
DEFINE_TRACE(Worklet)
{
- visitor->trace(m_resolvers);
+ visitor->trace(m_resources);
+ visitor->trace(m_fetcher);
ActiveDOMObject::trace(visitor);
}

Powered by Google App Engine
This is Rietveld 408576698