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

Side by Side Diff: third_party/WebKit/Source/modules/worklet/Worklet.cpp

Issue 2262483003: Worklet: Move common worklet code from modules/worklet to core/workers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove modules/worklet directory 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "modules/worklet/Worklet.h"
6
7 #include "bindings/core/v8/ScriptPromiseResolver.h"
8 #include "bindings/core/v8/ScriptSourceCode.h"
9 #include "bindings/core/v8/V8Binding.h"
10 #include "core/dom/DOMException.h"
11 #include "core/dom/ExceptionCode.h"
12 #include "core/fetch/FetchInitiatorTypeNames.h"
13 #include "core/frame/LocalFrame.h"
14 #include "core/loader/DocumentLoader.h"
15 #include "core/loader/FrameFetchContext.h"
16 #include "core/workers/WorkletGlobalScopeProxy.h"
17 #include "modules/worklet/WorkletScriptLoader.h"
18
19 namespace blink {
20
21 Worklet::Worklet(LocalFrame* frame)
22 : ActiveDOMObject(frame->document())
23 , m_fetcher(frame->loader().documentLoader()->fetcher())
24 {
25 }
26
27 ScriptPromise Worklet::import(ScriptState* scriptState, const String& url)
28 {
29 KURL scriptURL = getExecutionContext()->completeURL(url);
30 if (!scriptURL.isValid()) {
31 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(SyntaxError, "'" + url + "' is not a valid URL."));
32 }
33
34 ResourceRequest resourceRequest(scriptURL);
35 resourceRequest.setRequestContext(WebURLRequest::RequestContextScript);
36 FetchRequest request(resourceRequest, FetchInitiatorTypeNames::internal);
37 ScriptResource* resource = ScriptResource::fetch(request, fetcher());
38
39 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
40 ScriptPromise promise = resolver->promise();
41 if (resource) {
42 WorkletScriptLoader* workletLoader = WorkletScriptLoader::create(resolve r, this, resource);
43 m_scriptLoaders.add(workletLoader);
44 } else {
45 resolver->reject(DOMException::create(NetworkError));
46 }
47 return promise;
48 }
49
50 void Worklet::notifyFinished(WorkletScriptLoader* scriptLoader)
51 {
52 workletGlobalScopeProxy()->evaluateScript(ScriptSourceCode(scriptLoader->res ource()));
53 m_scriptLoaders.remove(scriptLoader);
54 }
55
56 void Worklet::stop()
57 {
58 workletGlobalScopeProxy()->terminateWorkletGlobalScope();
59 for (const auto& scriptLoader : m_scriptLoaders) {
60 scriptLoader->cancel();
61 }
62 }
63
64 DEFINE_TRACE(Worklet)
65 {
66 visitor->trace(m_fetcher);
67 visitor->trace(m_scriptLoaders);
68 ActiveDOMObject::trace(visitor);
69 }
70
71 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/worklet/Worklet.h ('k') | third_party/WebKit/Source/modules/worklet/Worklet.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698