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

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

Issue 2146633002: Enable checking for Content Security Policies before loading an external worklet script. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "modules/worklet/Worklet.h" 5 #include "modules/worklet/Worklet.h"
6 6
7 #include "bindings/core/v8/ScriptPromiseResolver.h" 7 #include "bindings/core/v8/ScriptPromiseResolver.h"
8 #include "bindings/core/v8/V8Binding.h" 8 #include "bindings/core/v8/V8Binding.h"
9 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" 9 #include "bindings/core/v8/WorkerOrWorkletScriptController.h"
10 #include "core/dom/DOMException.h" 10 #include "core/dom/DOMException.h"
11 #include "core/dom/ExceptionCode.h" 11 #include "core/dom/ExceptionCode.h"
12 #include "core/inspector/InspectorInstrumentation.h" 12 #include "core/inspector/InspectorInstrumentation.h"
13 #include "core/workers/WorkletGlobalScopeProxy.h" 13 #include "core/workers/WorkletGlobalScopeProxy.h"
14 14
15 namespace blink { 15 namespace blink {
16 16
17 Worklet::Worklet(ExecutionContext* executionContext) 17 Worklet::Worklet(ExecutionContext* executionContext)
18 : ActiveDOMObject(executionContext) 18 : ActiveDOMObject(executionContext)
19 { 19 {
20 } 20 }
21 21
22 ScriptPromise Worklet::import(ScriptState* scriptState, const String& url) 22 ScriptPromise Worklet::import(ScriptState* scriptState, const String& url)
23 { 23 {
24 KURL scriptURL = getExecutionContext()->completeURL(url); 24 KURL scriptURL = getExecutionContext()->completeURL(url);
25 if (!scriptURL.isValid()) { 25 if (!scriptURL.isValid()) {
26 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(SyntaxError, "'" + url + "' is not a valid URL.")); 26 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(SyntaxError, "'" + url + "' is not a valid URL."));
27 } 27 }
28 28
29 // TODO(ikilpatrick): Perform upfront CSP checks once we decide on a 29 if (!getExecutionContext()->securityContext().contentSecurityPolicy()->allow ScriptFromSource(scriptURL, AtomicString())) {
30 // CSP-policy for worklets. 30 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NetworkError, "The script at '" + scriptURL.elidedString() + "' failed to load."));
ikilpatrick 2016/07/20 17:56:17 A better message is probably something like "Acces
31 }
31 32
32 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 33 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
33 m_resolvers.append(resolver); 34 m_resolvers.append(resolver);
34 35
35 ScriptPromise promise = resolver->promise(); 36 ScriptPromise promise = resolver->promise();
36 37
37 // TODO(ikilpatrick): WorkerScriptLoader will need to be extended to allow 38 // TODO(ikilpatrick): WorkerScriptLoader will need to be extended to allow
38 // module loading support. For now just fetch a 'classic' script. 39 // module loading support. For now just fetch a 'classic' script.
39 40
40 // NOTE: WorkerScriptLoader may synchronously invoke its callbacks 41 // NOTE: WorkerScriptLoader may synchronously invoke its callbacks
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 } 85 }
85 } 86 }
86 87
87 DEFINE_TRACE(Worklet) 88 DEFINE_TRACE(Worklet)
88 { 89 {
89 visitor->trace(m_resolvers); 90 visitor->trace(m_resolvers);
90 ActiveDOMObject::trace(visitor); 91 ActiveDOMObject::trace(visitor);
91 } 92 }
92 93
93 } // namespace blink 94 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/worklet-import-blocked-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698