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

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

Issue 2657823002: Worklet: Straighten layering of worklet script loading (Closed)
Patch Set: clean up Created 3 years, 11 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
« no previous file with comments | « third_party/WebKit/Source/core/workers/WorkletScriptLoader.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/workers/WorkletScriptLoader.cpp
diff --git a/third_party/WebKit/Source/core/workers/WorkletScriptLoader.cpp b/third_party/WebKit/Source/core/workers/WorkletScriptLoader.cpp
index f20af726f37f38277d8f2054ecc24624a016213e..b9ec6b5149c189d1fbfafe8c023966edd8ce9c83 100644
--- a/third_party/WebKit/Source/core/workers/WorkletScriptLoader.cpp
+++ b/third_party/WebKit/Source/core/workers/WorkletScriptLoader.cpp
@@ -4,39 +4,65 @@
#include "core/workers/WorkletScriptLoader.h"
-#include "core/dom/DOMException.h"
-#include "core/dom/ExceptionCode.h"
-#include "core/workers/Worklet.h"
+#include "bindings/core/v8/ScriptSourceCode.h"
+#include "core/loader/FrameFetchContext.h"
+#include "platform/loader/fetch/FetchInitiatorTypeNames.h"
+#include "wtf/WTF.h"
namespace blink {
-WorkletScriptLoader::WorkletScriptLoader(ScriptPromiseResolver* resolver,
- Worklet* worklet,
- ScriptResource* resource)
- : m_resolver(resolver), m_host(worklet) {
+WorkletScriptLoader::WorkletScriptLoader(ResourceFetcher* fetcher,
+ Client* client)
+ : m_fetcher(fetcher), m_client(client) {}
+
+void WorkletScriptLoader::fetchScript(const String& scriptURL) {
+ DCHECK(isMainThread());
+ DCHECK(!resource());
+ DCHECK(!m_wasScriptLoadComplete);
+
+ ResourceRequest resourceRequest(scriptURL);
+ resourceRequest.setRequestContext(WebURLRequest::RequestContextScript);
+ FetchRequest request(resourceRequest, FetchInitiatorTypeNames::internal);
+ ScriptResource* resource = ScriptResource::fetch(request, m_fetcher);
+ if (!resource) {
+ notifyFinished(nullptr);
+ return;
+ }
setResource(resource);
+ // notifyFinished() will be called later.
}
void WorkletScriptLoader::cancel() {
- clearResource();
+ DCHECK(isMainThread());
+ if (!resource() || m_wasScriptLoadComplete)
+ return;
+ notifyFinished(nullptr);
}
void WorkletScriptLoader::notifyFinished(Resource* resource) {
- DCHECK(this->resource() == resource);
-
- m_host->notifyFinished(this);
- if (resource->errorOccurred()) {
- m_resolver->reject(DOMException::create(NetworkError));
+ DCHECK(isMainThread());
+ DCHECK(!m_wasScriptLoadComplete);
+ clearResource();
+ m_wasScriptLoadComplete = true;
+ if (!resource || resource->errorOccurred()) {
+ m_client->notifyWorkletScriptLoadingFinished(this, ScriptSourceCode());
} else {
- DCHECK(resource->isLoaded());
- m_resolver->resolve();
+ m_wasScriptLoadSuccessful = true;
+ m_client->notifyWorkletScriptLoadingFinished(
+ this, ScriptSourceCode(static_cast<ScriptResource*>(resource)));
}
- clearResource();
+ m_fetcher = nullptr;
+ m_client = nullptr;
+}
+
+bool WorkletScriptLoader::wasScriptLoadSuccessful() const {
+ DCHECK(m_wasScriptLoadComplete);
+ return m_wasScriptLoadSuccessful;
}
DEFINE_TRACE(WorkletScriptLoader) {
- visitor->trace(m_resolver);
- visitor->trace(m_host);
+ visitor->trace(m_fetcher);
+ visitor->trace(m_client);
ResourceOwner<ScriptResource, ScriptResourceClient>::trace(visitor);
}
« no previous file with comments | « third_party/WebKit/Source/core/workers/WorkletScriptLoader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698