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

Side by Side Diff: Source/web/WebEmbeddedWorkerImpl.cpp

Issue 714833002: [ServiceWorker] CSP support for ServiceWorker environment. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: else if Created 6 years, 1 month 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 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 15 matching lines...) Expand all
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "web/WebEmbeddedWorkerImpl.h" 32 #include "web/WebEmbeddedWorkerImpl.h"
33 33
34 #include "core/dom/CrossThreadTask.h" 34 #include "core/dom/CrossThreadTask.h"
35 #include "core/dom/Document.h" 35 #include "core/dom/Document.h"
36 #include "core/frame/csp/ContentSecurityPolicy.h"
36 #include "core/inspector/InspectorInstrumentation.h" 37 #include "core/inspector/InspectorInstrumentation.h"
37 #include "core/inspector/WorkerDebuggerAgent.h" 38 #include "core/inspector/WorkerDebuggerAgent.h"
38 #include "core/inspector/WorkerInspectorController.h" 39 #include "core/inspector/WorkerInspectorController.h"
39 #include "core/loader/FrameLoadRequest.h" 40 #include "core/loader/FrameLoadRequest.h"
40 #include "core/loader/SubstituteData.h" 41 #include "core/loader/SubstituteData.h"
41 #include "core/workers/WorkerClients.h" 42 #include "core/workers/WorkerClients.h"
42 #include "core/workers/WorkerGlobalScope.h" 43 #include "core/workers/WorkerGlobalScope.h"
43 #include "core/workers/WorkerInspectorProxy.h" 44 #include "core/workers/WorkerInspectorProxy.h"
44 #include "core/workers/WorkerLoaderProxy.h" 45 #include "core/workers/WorkerLoaderProxy.h"
45 #include "core/workers/WorkerScriptLoader.h" 46 #include "core/workers/WorkerScriptLoader.h"
46 #include "core/workers/WorkerScriptLoaderClient.h" 47 #include "core/workers/WorkerScriptLoaderClient.h"
47 #include "core/workers/WorkerThreadStartupData.h" 48 #include "core/workers/WorkerThreadStartupData.h"
48 #include "modules/serviceworkers/ServiceWorkerThread.h" 49 #include "modules/serviceworkers/ServiceWorkerThread.h"
49 #include "platform/SharedBuffer.h" 50 #include "platform/SharedBuffer.h"
50 #include "platform/heap/Handle.h" 51 #include "platform/heap/Handle.h"
51 #include "platform/network/ContentSecurityPolicyParsers.h" 52 #include "platform/network/ContentSecurityPolicyParsers.h"
53 #include "platform/network/ContentSecurityPolicyResponseHeaders.h"
52 #include "public/platform/Platform.h" 54 #include "public/platform/Platform.h"
53 #include "public/platform/WebURLRequest.h" 55 #include "public/platform/WebURLRequest.h"
54 #include "public/web/WebDevToolsAgent.h" 56 #include "public/web/WebDevToolsAgent.h"
55 #include "public/web/WebServiceWorkerContextClient.h" 57 #include "public/web/WebServiceWorkerContextClient.h"
56 #include "public/web/WebServiceWorkerNetworkProvider.h" 58 #include "public/web/WebServiceWorkerNetworkProvider.h"
57 #include "public/web/WebSettings.h" 59 #include "public/web/WebSettings.h"
58 #include "public/web/WebView.h" 60 #include "public/web/WebView.h"
59 #include "public/web/WebWorkerPermissionClientProxy.h" 61 #include "public/web/WebWorkerPermissionClientProxy.h"
60 #include "web/ServiceWorkerGlobalScopeClientImpl.h" 62 #include "web/ServiceWorkerGlobalScopeClientImpl.h"
61 #include "web/ServiceWorkerGlobalScopeProxy.h" 63 #include "web/ServiceWorkerGlobalScopeProxy.h"
(...skipping 19 matching lines...) Expand all
81 83
82 void load(ExecutionContext* loadingContext, const KURL& scriptURL, const Clo sure& callback) 84 void load(ExecutionContext* loadingContext, const KURL& scriptURL, const Clo sure& callback)
83 { 85 {
84 ASSERT(loadingContext); 86 ASSERT(loadingContext);
85 m_callback = callback; 87 m_callback = callback;
86 m_scriptLoader->setRequestContext(WebURLRequest::RequestContextServiceWo rker); 88 m_scriptLoader->setRequestContext(WebURLRequest::RequestContextServiceWo rker);
87 m_scriptLoader->loadAsynchronously( 89 m_scriptLoader->loadAsynchronously(
88 *loadingContext, scriptURL, DenyCrossOriginRequests, this); 90 *loadingContext, scriptURL, DenyCrossOriginRequests, this);
89 } 91 }
90 92
93 void didReceiveResponse(unsigned long identifier, const ResourceResponse& re sponse) override
94 {
95 m_contentSecurityPolicy = ContentSecurityPolicy::create();
96 m_contentSecurityPolicy->setOverrideURLForSelf(response.url());
97 m_contentSecurityPolicy->didReceiveHeaders(ContentSecurityPolicyResponse Headers(response));
98 }
99
91 virtual void notifyFinished() override 100 virtual void notifyFinished() override
92 { 101 {
93 m_callback(); 102 m_callback();
94 } 103 }
95 104
96 void cancel() 105 void cancel()
97 { 106 {
98 m_scriptLoader->cancel(); 107 m_scriptLoader->cancel();
99 } 108 }
100 109
101 bool failed() const { return m_scriptLoader->failed(); } 110 bool failed() const { return m_scriptLoader->failed(); }
102 const KURL& url() const { return m_scriptLoader->responseURL(); } 111 const KURL& url() const { return m_scriptLoader->responseURL(); }
103 String script() const { return m_scriptLoader->script(); } 112 String script() const { return m_scriptLoader->script(); }
113 PassRefPtr<ContentSecurityPolicy> releaseContentSecurityPolicy() { return m_ contentSecurityPolicy.release(); }
104 114
105 private: 115 private:
106 Loader() : m_scriptLoader(WorkerScriptLoader::create()) 116 Loader() : m_scriptLoader(WorkerScriptLoader::create())
107 { 117 {
108 } 118 }
109 119
110 RefPtr<WorkerScriptLoader> m_scriptLoader; 120 RefPtr<WorkerScriptLoader> m_scriptLoader;
121 RefPtr<ContentSecurityPolicy> m_contentSecurityPolicy;
111 Closure m_callback; 122 Closure m_callback;
112 }; 123 };
113 124
114 class WebEmbeddedWorkerImpl::LoaderProxy : public WorkerLoaderProxy { 125 class WebEmbeddedWorkerImpl::LoaderProxy : public WorkerLoaderProxy {
115 public: 126 public:
116 static PassOwnPtr<LoaderProxy> create(WebEmbeddedWorkerImpl& embeddedWorker) 127 static PassOwnPtr<LoaderProxy> create(WebEmbeddedWorkerImpl& embeddedWorker)
117 { 128 {
118 return adoptPtr(new LoaderProxy(embeddedWorker)); 129 return adoptPtr(new LoaderProxy(embeddedWorker));
119 } 130 }
120 131
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 if (InspectorInstrumentation::shouldPauseDedicatedWorkerOnStart(document)) 411 if (InspectorInstrumentation::shouldPauseDedicatedWorkerOnStart(document))
401 startMode = PauseWorkerGlobalScopeOnStart; 412 startMode = PauseWorkerGlobalScopeOnStart;
402 413
403 // FIXME: this document's origin is pristine and without any extra privilege s. (crbug.com/254993) 414 // FIXME: this document's origin is pristine and without any extra privilege s. (crbug.com/254993)
404 SecurityOrigin* starterOrigin = document->securityOrigin(); 415 SecurityOrigin* starterOrigin = document->securityOrigin();
405 416
406 OwnPtrWillBeRawPtr<WorkerClients> workerClients = WorkerClients::create(); 417 OwnPtrWillBeRawPtr<WorkerClients> workerClients = WorkerClients::create();
407 providePermissionClientToWorker(workerClients.get(), m_permissionClient.rele ase()); 418 providePermissionClientToWorker(workerClients.get(), m_permissionClient.rele ase());
408 provideServiceWorkerGlobalScopeClientToWorker(workerClients.get(), ServiceWo rkerGlobalScopeClientImpl::create(*m_workerContextClient)); 419 provideServiceWorkerGlobalScopeClientToWorker(workerClients.get(), ServiceWo rkerGlobalScopeClientImpl::create(*m_workerContextClient));
409 420
421 // We need to set the CSP to both the shadow page's document and the Service WorkerGlobalScope.
422 document->initContentSecurityPolicy(m_mainScriptLoader->releaseContentSecuri tyPolicy());
423
410 KURL scriptURL = m_mainScriptLoader->url(); 424 KURL scriptURL = m_mainScriptLoader->url();
411 OwnPtrWillBeRawPtr<WorkerThreadStartupData> startupData = 425 OwnPtrWillBeRawPtr<WorkerThreadStartupData> startupData =
412 WorkerThreadStartupData::create( 426 WorkerThreadStartupData::create(
413 scriptURL, 427 scriptURL,
414 m_workerStartData.userAgent, 428 m_workerStartData.userAgent,
415 m_mainScriptLoader->script(), 429 m_mainScriptLoader->script(),
416 startMode, 430 startMode,
417 // FIXME: fill appropriate CSP info and policy type. 431 document->contentSecurityPolicy()->deprecatedHeader(),
Mike West 2014/11/12 12:28:36 I don't think this is correct; it differs from the
horo 2014/11/13 01:09:02 This document is not the document who created (reg
Mike West 2014/11/19 10:31:49 Hrm. Ok, then I misunderstood the implementation h
horo 2014/11/19 12:35:41 Yes. We create the dummy document which lives in t
418 String(), 432 document->contentSecurityPolicy()->deprecatedHeaderType(),
419 ContentSecurityPolicyHeaderTypeEnforce,
420 starterOrigin, 433 starterOrigin,
421 workerClients.release()); 434 workerClients.release());
422 435
423 m_mainScriptLoader.clear(); 436 m_mainScriptLoader.clear();
424 437
425 m_workerGlobalScopeProxy = ServiceWorkerGlobalScopeProxy::create(*this, *doc ument, *m_workerContextClient); 438 m_workerGlobalScopeProxy = ServiceWorkerGlobalScopeProxy::create(*this, *doc ument, *m_workerContextClient);
426 m_loaderProxy = LoaderProxy::create(*this); 439 m_loaderProxy = LoaderProxy::create(*this);
427 m_workerThread = ServiceWorkerThread::create(*m_loaderProxy, *m_workerGlobal ScopeProxy, startupData.release()); 440 m_workerThread = ServiceWorkerThread::create(*m_loaderProxy, *m_workerGlobal ScopeProxy, startupData.release());
428 m_workerThread->start(); 441 m_workerThread->start();
429 m_workerInspectorProxy->workerThreadCreated(document, m_workerThread.get(), scriptURL); 442 m_workerInspectorProxy->workerThreadCreated(document, m_workerThread.get(), scriptURL);
430 } 443 }
431 444
432 } // namespace blink 445 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698