Index: third_party/WebKit/Source/modules/worklet/WorkletScriptLoader.cpp |
diff --git a/third_party/WebKit/Source/modules/worklet/WorkletScriptLoader.cpp b/third_party/WebKit/Source/modules/worklet/WorkletScriptLoader.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7db4b8fbefd3dfd6db0b6c6584e6cc0d51363f2e |
--- /dev/null |
+++ b/third_party/WebKit/Source/modules/worklet/WorkletScriptLoader.cpp |
@@ -0,0 +1,50 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "modules/worklet/WorkletScriptLoader.h" |
+ |
+#include "core/dom/DOMException.h" |
+#include "core/dom/ExceptionCode.h" |
+#include "core/fetch/ResourceLoader.h" |
+#include "modules/worklet/Worklet.h" |
+ |
+namespace blink { |
+ |
+WorkletScriptLoader::WorkletScriptLoader(ScriptPromiseResolver* resolver, Worklet* worklet, ScriptResource* resource) |
+ : m_resolver(resolver) |
+ , m_host(worklet) |
+{ |
+ setResource(resource); |
+} |
+ |
+void WorkletScriptLoader::cancel() |
+{ |
+ if (resource()) { |
+ resource()->loader()->cancel(); |
+ clearResource(); |
+ } |
+} |
+ |
+void WorkletScriptLoader::notifyFinished(Resource* resource) |
+{ |
+ DCHECK(this->resource() == resource); |
+ |
+ m_host->notifyFinished(this); |
+ if (resource->errorOccurred()) { |
+ m_resolver->reject(DOMException::create(NetworkError)); |
+ } else { |
+ DCHECK(resource->isLoaded()); |
+ m_resolver->resolve(); |
+ } |
+ clearResource(); |
+} |
+ |
+DEFINE_TRACE(WorkletScriptLoader) |
+{ |
+ visitor->trace(m_resolver); |
+ visitor->trace(m_host); |
+ ResourceOwner<ScriptResource, ScriptResourceClient>::trace(visitor); |
+} |
+ |
+} // namespace blink |