Commit 34a3d9f3 authored by tsepez@chromium.org's avatar tsepez@chromium.org

Source/WebCore: Pass Content-Security-Policy directives to worker threads.

https://bugs.webkit.org/show_bug.cgi?id=73242

Reviewed by David Levin.

Tests: http/tests/security/contentSecurityPolicy/shared-worker-connect-src-allowed.html
       http/tests/security/contentSecurityPolicy/shared-worker-connect-src-blocked.html
       http/tests/security/contentSecurityPolicy/worker-connect-src-allowed.html
       http/tests/security/contentSecurityPolicy/worker-connect-src-blocked.html

* page/ContentSecurityPolicy.h:
(WebCore::ContentSecurityPolicy::policy):
(WebCore::ContentSecurityPolicy::headerType):
* workers/DedicatedWorkerContext.cpp:
(WebCore::DedicatedWorkerContext::DedicatedWorkerContext):
* workers/DedicatedWorkerContext.h:
(WebCore::DedicatedWorkerContext::create):
* workers/DedicatedWorkerThread.cpp:
(WebCore::DedicatedWorkerThread::create):
(WebCore::DedicatedWorkerThread::DedicatedWorkerThread):
(WebCore::DedicatedWorkerThread::createWorkerContext):
* workers/DedicatedWorkerThread.h:
* workers/DefaultSharedWorkerRepository.cpp:
(WebCore::SharedWorkerScriptLoader::notifyFinished):
(WebCore::DefaultSharedWorkerRepository::workerScriptLoaded):
* workers/DefaultSharedWorkerRepository.h:
* workers/SharedWorkerContext.cpp:
(WebCore::SharedWorkerContext::SharedWorkerContext):
* workers/SharedWorkerContext.h:
(WebCore::SharedWorkerContext::create):
* workers/SharedWorkerThread.cpp:
(WebCore::SharedWorkerThread::create):
(WebCore::SharedWorkerThread::SharedWorkerThread):
(WebCore::SharedWorkerThread::createWorkerContext):
* workers/SharedWorkerThread.h:
* workers/WorkerContext.cpp:
(WebCore::WorkerContext::WorkerContext):
* workers/WorkerContext.h:
* workers/WorkerMessagingProxy.cpp:
(WebCore::WorkerMessagingProxy::startWorkerContext):
* workers/WorkerThread.cpp:
(WebCore::WorkerThreadStartupData::create):
(WebCore::WorkerThreadStartupData::WorkerThreadStartupData):
(WebCore::WorkerThread::WorkerThread):
(WebCore::WorkerThread::workerThread):
* workers/WorkerThread.h:

Source/WebKit/chromium: Pass Content-security-policy directive to worker threads.
https://bugs.webkit.org/show_bug.cgi?id=73242

Reviewed by David Levin.

* src/WebSharedWorkerImpl.cpp:
(WebKit::WebSharedWorkerImpl::startWorkerContext):
* src/WebWorkerClientImpl.cpp:
(WebKit::WebWorkerClientImpl::startWorkerContext):

LayoutTests: Pass Content-Security-Policy directives to worker threads.
https://bugs.webkit.org/show_bug.cgi?id=73242

Reviewed by David Levin.

* http/tests/security/contentSecurityPolicy/resources/shared-worker-make-xhr.js: Added.
(onconnect):
* http/tests/security/contentSecurityPolicy/resources/worker-make-xhr.js: Added.
* http/tests/security/contentSecurityPolicy/shared-worker-connect-src-allowed-expected.txt: Added.
* http/tests/security/contentSecurityPolicy/shared-worker-connect-src-allowed.html: Added.
* http/tests/security/contentSecurityPolicy/shared-worker-connect-src-blocked-expected.txt: Added.
* http/tests/security/contentSecurityPolicy/shared-worker-connect-src-blocked.html: Added.
* http/tests/security/contentSecurityPolicy/worker-connect-src-allowed-expected.txt: Added.
* http/tests/security/contentSecurityPolicy/worker-connect-src-allowed.html: Added.
* http/tests/security/contentSecurityPolicy/worker-connect-src-blocked-expected.txt: Added.
* http/tests/security/contentSecurityPolicy/worker-connect-src-blocked.html: Added.
* platform/chromium/test_expectations.txt:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@104329 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 240c13fa
2012-01-06 Tom Sepez <tsepez@chromium.org>
Pass Content-Security-Policy directives to worker threads.
https://bugs.webkit.org/show_bug.cgi?id=73242
Reviewed by David Levin.
* http/tests/security/contentSecurityPolicy/resources/shared-worker-make-xhr.js: Added.
(onconnect):
* http/tests/security/contentSecurityPolicy/resources/worker-make-xhr.js: Added.
* http/tests/security/contentSecurityPolicy/shared-worker-connect-src-allowed-expected.txt: Added.
* http/tests/security/contentSecurityPolicy/shared-worker-connect-src-allowed.html: Added.
* http/tests/security/contentSecurityPolicy/shared-worker-connect-src-blocked-expected.txt: Added.
* http/tests/security/contentSecurityPolicy/shared-worker-connect-src-blocked.html: Added.
* http/tests/security/contentSecurityPolicy/worker-connect-src-allowed-expected.txt: Added.
* http/tests/security/contentSecurityPolicy/worker-connect-src-allowed.html: Added.
* http/tests/security/contentSecurityPolicy/worker-connect-src-blocked-expected.txt: Added.
* http/tests/security/contentSecurityPolicy/worker-connect-src-blocked.html: Added.
* platform/chromium/test_expectations.txt:
2012-01-06 Mihnea Ovidenie <mihnea@adobe.com>
[CSSRegions]Crash while collecting svg elements in render flow thread.
onconnect = function (event) {
var port = event.ports[0];
try {
var xhr = new XMLHttpRequest;
xhr.open("GET", "http://127.0.0.1:8000/xmlhttprequest/resources/get.txt", true);
port.postMessage("xhr allowed");
} catch(e) {
port.postMessage("xhr blocked");
}
};
try {
var xhr = new XMLHttpRequest;
xhr.open("GET", "http://127.0.0.1:8000/xmlhttprequest/resources/get.txt", true);
postMessage("xhr allowed");
} catch(e) {
postMessage("xhr blocked");
}
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-WebKit-CSP" content="connect-src http://127.0.0.1:8000"/>
<script>
if (window.layoutTestController) {
layoutTestController.waitUntilDone();
layoutTestController.dumpAsText();
}
</script>
</head>
<body>
<script>
try {
var worker = new SharedWorker('http://127.0.0.1:8000/security/contentSecurityPolicy/resources/shared-worker-make-xhr.js');
worker.port.onmessage = function (event) {
alert(event.data);
if (window.layoutTestController)
layoutTestController.notifyDone();
};
} catch (e) {
alert(e);
if (window.layoutTestController)
layoutTestController.notifyDone();
}
</script>
</body>
</html>
CONSOLE MESSAGE: line 1: Refused to load connect from 'http://127.0.0.1:8000/xmlhttprequest/resources/get.txt' because of Content-Security-Policy.
ALERT: xhr blocked
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-WebKit-CSP" content="connect-src 'none'"/>
<script>
if (window.layoutTestController) {
layoutTestController.waitUntilDone();
layoutTestController.dumpAsText();
}
</script>
</head>
<body>
<script>
try {
var worker = new SharedWorker('http://127.0.0.1:8000/security/contentSecurityPolicy/resources/shared-worker-make-xhr.js');
worker.port.onmessage = function (event) {
alert(event.data);
if (window.layoutTestController)
layoutTestController.notifyDone();
};
} catch (e) {
alert(e);
if (window.layoutTestController)
layoutTestController.notifyDone();
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-WebKit-CSP" content="connect-src http://127.0.0.1:8000"/>
<script>
if (window.layoutTestController) {
layoutTestController.waitUntilDone();
layoutTestController.dumpAsText();
}
</script>
</head>
<body>
<script>
try {
var worker = new Worker('http://127.0.0.1:8000/security/contentSecurityPolicy/resources/worker-make-xhr.js');
worker.onmessage = function (event) {
alert(event.data);
if (window.layoutTestController)
layoutTestController.notifyDone();
};
} catch (e) {
alert(e);
if (window.layoutTestController)
layoutTestController.notifyDone();
}
</script>
</body>
</html>
CONSOLE MESSAGE: line 1: Refused to load connect from 'http://127.0.0.1:8000/xmlhttprequest/resources/get.txt' because of Content-Security-Policy.
ALERT: xhr blocked
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-WebKit-CSP" content="connect-src 'none'"/>
<script>
if (window.layoutTestController) {
layoutTestController.waitUntilDone();
layoutTestController.dumpAsText();
}
</script>
</head>
<body>
<script>
try {
var worker = new Worker('http://127.0.0.1:8000/security/contentSecurityPolicy/resources/worker-make-xhr.js');
worker.onmessage = function (event) {
alert(event.data);
if (window.layoutTestController)
layoutTestController.notifyDone();
};
} catch (e) {
alert(e);
if (window.layoutTestController)
layoutTestController.notifyDone();
}
</script>
</body>
</html>
......@@ -172,6 +172,8 @@ WONTFIX SKIP : http/tests/websocket/tests/hixie76/workers/shared-worker-simple.h
WONTFIX SKIP : http/tests/websocket/tests/hybi/workers/close-in-shared-worker.html = TIMEOUT
WONTFIX SKIP : http/tests/websocket/tests/hybi/workers/shared-worker-simple.html = TIMEOUT
WONTFIX SKIP : http/tests/inspector/network/network-shared-worker.html = PASS TIMEOUT FAIL
WONTFIX SKIP : http/tests/security/contentSecurityPolicy/shared-worker-connect-src-allowed.html = TEXT
WONTFIX SKIP : http/tests/security/contentSecurityPolicy/shared-worker-connect-src-blocked.html = TEXT
// test_shell does not support message ports
BUGWK74459 SKIP : fast/workers/termination-with-port-messages.html = CRASH
......
2012-01-06 Tom Sepez <tsepez@chromium.org>
Pass Content-Security-Policy directives to worker threads.
https://bugs.webkit.org/show_bug.cgi?id=73242
Reviewed by David Levin.
Tests: http/tests/security/contentSecurityPolicy/shared-worker-connect-src-allowed.html
http/tests/security/contentSecurityPolicy/shared-worker-connect-src-blocked.html
http/tests/security/contentSecurityPolicy/worker-connect-src-allowed.html
http/tests/security/contentSecurityPolicy/worker-connect-src-blocked.html
* page/ContentSecurityPolicy.h:
(WebCore::ContentSecurityPolicy::policy):
(WebCore::ContentSecurityPolicy::headerType):
* workers/DedicatedWorkerContext.cpp:
(WebCore::DedicatedWorkerContext::DedicatedWorkerContext):
* workers/DedicatedWorkerContext.h:
(WebCore::DedicatedWorkerContext::create):
* workers/DedicatedWorkerThread.cpp:
(WebCore::DedicatedWorkerThread::create):
(WebCore::DedicatedWorkerThread::DedicatedWorkerThread):
(WebCore::DedicatedWorkerThread::createWorkerContext):
* workers/DedicatedWorkerThread.h:
* workers/DefaultSharedWorkerRepository.cpp:
(WebCore::SharedWorkerScriptLoader::notifyFinished):
(WebCore::DefaultSharedWorkerRepository::workerScriptLoaded):
* workers/DefaultSharedWorkerRepository.h:
* workers/SharedWorkerContext.cpp:
(WebCore::SharedWorkerContext::SharedWorkerContext):
* workers/SharedWorkerContext.h:
(WebCore::SharedWorkerContext::create):
* workers/SharedWorkerThread.cpp:
(WebCore::SharedWorkerThread::create):
(WebCore::SharedWorkerThread::SharedWorkerThread):
(WebCore::SharedWorkerThread::createWorkerContext):
* workers/SharedWorkerThread.h:
* workers/WorkerContext.cpp:
(WebCore::WorkerContext::WorkerContext):
* workers/WorkerContext.h:
* workers/WorkerMessagingProxy.cpp:
(WebCore::WorkerMessagingProxy::startWorkerContext):
* workers/WorkerThread.cpp:
(WebCore::WorkerThreadStartupData::create):
(WebCore::WorkerThreadStartupData::WorkerThreadStartupData):
(WebCore::WorkerThread::WorkerThread):
(WebCore::WorkerThread::workerThread):
* workers/WorkerThread.h:
2012-01-06 Mihnea Ovidenie <mihnea@adobe.com>
[CSSRegions]Crash while collecting svg elements in render flow thread.
......@@ -52,6 +52,8 @@ public:
};
void didReceiveHeader(const String&, HeaderType);
String policy() { return m_header; }
HeaderType headerType() { return m_reportOnly ? ReportOnly : EnforcePolicy; }
bool allowJavaScriptURLs() const;
bool allowInlineEventHandlers() const;
......
......@@ -41,8 +41,8 @@
namespace WebCore {
DedicatedWorkerContext::DedicatedWorkerContext(const KURL& url, const String& userAgent, DedicatedWorkerThread* thread)
: WorkerContext(url, userAgent, thread)
DedicatedWorkerContext::DedicatedWorkerContext(const KURL& url, const String& userAgent, DedicatedWorkerThread* thread, const String& contentSecurityPolicy, ContentSecurityPolicy::HeaderType contentSecurityPolicyType)
: WorkerContext(url, userAgent, thread, contentSecurityPolicy, contentSecurityPolicyType)
{
}
......
......@@ -33,6 +33,7 @@
#if ENABLE(WORKERS)
#include "ContentSecurityPolicy.h"
#include "MessagePort.h"
#include "WorkerContext.h"
......@@ -43,9 +44,9 @@ namespace WebCore {
class DedicatedWorkerContext : public WorkerContext {
public:
typedef WorkerContext Base;
static PassRefPtr<DedicatedWorkerContext> create(const KURL& url, const String& userAgent, DedicatedWorkerThread* thread)
static PassRefPtr<DedicatedWorkerContext> create(const KURL& url, const String& userAgent, DedicatedWorkerThread* thread, const String& contentSecurityPolicy, ContentSecurityPolicy::HeaderType contentSecurityPolicyType)
{
return adoptRef(new DedicatedWorkerContext(url, userAgent, thread));
return adoptRef(new DedicatedWorkerContext(url, userAgent, thread, contentSecurityPolicy, contentSecurityPolicyType));
}
virtual bool isDedicatedWorkerContext() const { return true; }
......@@ -65,7 +66,7 @@ namespace WebCore {
DedicatedWorkerThread* thread();
private:
DedicatedWorkerContext(const KURL&, const String&, DedicatedWorkerThread*);
DedicatedWorkerContext(const KURL&, const String& userAgent, DedicatedWorkerThread*, const String& contentSecurityPolicy, ContentSecurityPolicy::HeaderType);
};
} // namespace WebCore
......
......@@ -39,13 +39,13 @@
namespace WebCore {
PassRefPtr<DedicatedWorkerThread> DedicatedWorkerThread::create(const KURL& scriptURL, const String& userAgent, const String& sourceCode, WorkerLoaderProxy& workerLoaderProxy, WorkerObjectProxy& workerObjectProxy, WorkerThreadStartMode startMode)
PassRefPtr<DedicatedWorkerThread> DedicatedWorkerThread::create(const KURL& scriptURL, const String& userAgent, const String& sourceCode, WorkerLoaderProxy& workerLoaderProxy, WorkerObjectProxy& workerObjectProxy, WorkerThreadStartMode startMode, const String& contentSecurityPolicy, ContentSecurityPolicy::HeaderType contentSecurityPolicyType)
{
return adoptRef(new DedicatedWorkerThread(scriptURL, userAgent, sourceCode, workerLoaderProxy, workerObjectProxy, startMode));
return adoptRef(new DedicatedWorkerThread(scriptURL, userAgent, sourceCode, workerLoaderProxy, workerObjectProxy, startMode, contentSecurityPolicy, contentSecurityPolicyType));
}
DedicatedWorkerThread::DedicatedWorkerThread(const KURL& url, const String& userAgent, const String& sourceCode, WorkerLoaderProxy& workerLoaderProxy, WorkerObjectProxy& workerObjectProxy, WorkerThreadStartMode startMode)
: WorkerThread(url, userAgent, sourceCode, workerLoaderProxy, workerObjectProxy, startMode)
DedicatedWorkerThread::DedicatedWorkerThread(const KURL& url, const String& userAgent, const String& sourceCode, WorkerLoaderProxy& workerLoaderProxy, WorkerObjectProxy& workerObjectProxy, WorkerThreadStartMode startMode, const String& contentSecurityPolicy, ContentSecurityPolicy::HeaderType contentSecurityPolicyType)
: WorkerThread(url, userAgent, sourceCode, workerLoaderProxy, workerObjectProxy, startMode, contentSecurityPolicy, contentSecurityPolicyType)
, m_workerObjectProxy(workerObjectProxy)
{
}
......@@ -54,9 +54,9 @@ DedicatedWorkerThread::~DedicatedWorkerThread()
{
}
PassRefPtr<WorkerContext> DedicatedWorkerThread::createWorkerContext(const KURL& url, const String& userAgent)
PassRefPtr<WorkerContext> DedicatedWorkerThread::createWorkerContext(const KURL& url, const String& userAgent, const String& contentSecurityPolicy, ContentSecurityPolicy::HeaderType contentSecurityPolicyType)
{
return DedicatedWorkerContext::create(url, userAgent, this);
return DedicatedWorkerContext::create(url, userAgent, this, contentSecurityPolicy, contentSecurityPolicyType);
}
void DedicatedWorkerThread::runEventLoop()
......
......@@ -32,6 +32,7 @@
#if ENABLE(WORKERS)
#include "ContentSecurityPolicy.h"
#include "WorkerThread.h"
namespace WebCore {
......@@ -40,16 +41,16 @@ namespace WebCore {
class DedicatedWorkerThread : public WorkerThread {
public:
static PassRefPtr<DedicatedWorkerThread> create(const KURL& scriptURL, const String& userAgent, const String& sourceCode, WorkerLoaderProxy&, WorkerObjectProxy&, WorkerThreadStartMode);
static PassRefPtr<DedicatedWorkerThread> create(const KURL& scriptURL, const String& userAgent, const String& sourceCode, WorkerLoaderProxy&, WorkerObjectProxy&, WorkerThreadStartMode, const String& contentSecurityPolicy, ContentSecurityPolicy::HeaderType);
WorkerObjectProxy& workerObjectProxy() const { return m_workerObjectProxy; }
~DedicatedWorkerThread();
protected:
virtual PassRefPtr<WorkerContext> createWorkerContext(const KURL& url, const String& userAgent);
virtual PassRefPtr<WorkerContext> createWorkerContext(const KURL&, const String& userAgent, const String& contentSecurityPolicy, ContentSecurityPolicy::HeaderType);
virtual void runEventLoop();
private:
DedicatedWorkerThread(const KURL&, const String& userAgent, const String& sourceCode, WorkerLoaderProxy&, WorkerObjectProxy&, WorkerThreadStartMode);
DedicatedWorkerThread(const KURL&, const String& userAgent, const String& sourceCode, WorkerLoaderProxy&, WorkerObjectProxy&, WorkerThreadStartMode, const String& contentSecurityPolicy, ContentSecurityPolicy::HeaderType);
WorkerObjectProxy& m_workerObjectProxy;
};
......
......@@ -319,7 +319,10 @@ void SharedWorkerScriptLoader::notifyFinished()
m_worker->dispatchEvent(Event::create(eventNames().errorEvent, false, true));
else {
InspectorInstrumentation::scriptImported(m_worker->scriptExecutionContext(), m_scriptLoader->identifier(), m_scriptLoader->script());
DefaultSharedWorkerRepository::instance().workerScriptLoaded(*m_proxy, m_worker->scriptExecutionContext()->userAgent(m_scriptLoader->url()), m_scriptLoader->script(), m_port.release());
DefaultSharedWorkerRepository::instance().workerScriptLoaded(*m_proxy, m_worker->scriptExecutionContext()->userAgent(m_scriptLoader->url()),
m_scriptLoader->script(), m_port.release(),
m_worker->scriptExecutionContext()->contentSecurityPolicy()->policy(),
m_worker->scriptExecutionContext()->contentSecurityPolicy()->headerType());
}
m_worker->unsetPendingActivity(m_worker.get());
this->deref(); // This frees this object - must be the last action in this function.
......@@ -331,7 +334,7 @@ DefaultSharedWorkerRepository& DefaultSharedWorkerRepository::instance()
return *instance;
}
void DefaultSharedWorkerRepository::workerScriptLoaded(SharedWorkerProxy& proxy, const String& userAgent, const String& workerScript, PassOwnPtr<MessagePortChannel> port)
void DefaultSharedWorkerRepository::workerScriptLoaded(SharedWorkerProxy& proxy, const String& userAgent, const String& workerScript, PassOwnPtr<MessagePortChannel> port, const String& contentSecurityPolicy, ContentSecurityPolicy::HeaderType contentSecurityPolicyType)
{
MutexLocker lock(m_lock);
if (proxy.isClosing())
......@@ -339,7 +342,7 @@ void DefaultSharedWorkerRepository::workerScriptLoaded(SharedWorkerProxy& proxy,
// Another loader may have already started up a thread for this proxy - if so, just send a connect to the pre-existing thread.
if (!proxy.thread()) {
RefPtr<SharedWorkerThread> thread = SharedWorkerThread::create(proxy.name(), proxy.url(), userAgent, workerScript, proxy, proxy, DontPauseWorkerContextOnStart);
RefPtr<SharedWorkerThread> thread = SharedWorkerThread::create(proxy.name(), proxy.url(), userAgent, workerScript, proxy, proxy, DontPauseWorkerContextOnStart, contentSecurityPolicy, contentSecurityPolicyType);
proxy.setThread(thread);
thread->start();
}
......
......@@ -33,6 +33,7 @@
#if ENABLE(SHARED_WORKERS)
#include "ContentSecurityPolicy.h"
#include <wtf/Forward.h>
#include <wtf/HashMap.h>
#include <wtf/Noncopyable.h>
......@@ -58,7 +59,7 @@ namespace WebCore {
WTF_MAKE_NONCOPYABLE(DefaultSharedWorkerRepository); WTF_MAKE_FAST_ALLOCATED;
public:
// Invoked once the worker script has been loaded to fire up the worker thread.
void workerScriptLoaded(SharedWorkerProxy&, const String& userAgent, const String& workerScript, PassOwnPtr<MessagePortChannel>);
void workerScriptLoaded(SharedWorkerProxy&, const String& userAgent, const String& workerScript, PassOwnPtr<MessagePortChannel>, const String& contentSecurityPolicy, ContentSecurityPolicy::HeaderType);
// Internal implementation of SharedWorkerRepository::connect()
void connectToWorker(PassRefPtr<SharedWorker>, PassOwnPtr<MessagePortChannel>, const KURL&, const String& name, ExceptionCode&);
......
......@@ -50,8 +50,8 @@ PassRefPtr<MessageEvent> createConnectEvent(PassRefPtr<MessagePort> port)
return event.release();
}
SharedWorkerContext::SharedWorkerContext(const String& name, const KURL& url, const String& userAgent, SharedWorkerThread* thread)
: WorkerContext(url, userAgent, thread)
SharedWorkerContext::SharedWorkerContext(const String& name, const KURL& url, const String& userAgent, SharedWorkerThread* thread, const String& contentSecurityPolicy, ContentSecurityPolicy::HeaderType contentSecurityPolicyType)
: WorkerContext(url, userAgent, thread, contentSecurityPolicy, contentSecurityPolicyType)
, m_name(name)
{
}
......
......@@ -33,6 +33,7 @@
#if ENABLE(SHARED_WORKERS)
#include "ContentSecurityPolicy.h"
#include "WorkerContext.h"
namespace WebCore {
......@@ -43,9 +44,9 @@ namespace WebCore {
class SharedWorkerContext : public WorkerContext {
public:
typedef WorkerContext Base;
static PassRefPtr<SharedWorkerContext> create(const String& name, const KURL& url, const String& userAgent, SharedWorkerThread* thread)
static PassRefPtr<SharedWorkerContext> create(const String& name, const KURL& url, const String& userAgent, SharedWorkerThread* thread, const String& contentSecurityPolicy, ContentSecurityPolicy::HeaderType contentSecurityPolicyType)
{
return adoptRef(new SharedWorkerContext(name, url, userAgent, thread));
return adoptRef(new SharedWorkerContext(name, url, userAgent, thread, contentSecurityPolicy, contentSecurityPolicyType));
}
virtual ~SharedWorkerContext();
......@@ -60,7 +61,7 @@ namespace WebCore {
SharedWorkerThread* thread();
private:
SharedWorkerContext(const String& name, const KURL&, const String&, SharedWorkerThread*);
SharedWorkerContext(const String& name, const KURL&, const String&, SharedWorkerThread*, const String& contentSecurityPolicy, ContentSecurityPolicy::HeaderType);
virtual void logExceptionToConsole(const String& errorMessage, int lineNumber, const String& sourceURL, PassRefPtr<ScriptCallStack>);
......
......@@ -38,13 +38,13 @@
namespace WebCore {
PassRefPtr<SharedWorkerThread> SharedWorkerThread::create(const String& name, const KURL& scriptURL, const String& userAgent, const String& sourceCode, WorkerLoaderProxy& workerLoaderProxy, WorkerReportingProxy& workerReportingProxy, WorkerThreadStartMode startMode)
PassRefPtr<SharedWorkerThread> SharedWorkerThread::create(const String& name, const KURL& scriptURL, const String& userAgent, const String& sourceCode, WorkerLoaderProxy& workerLoaderProxy, WorkerReportingProxy& workerReportingProxy, WorkerThreadStartMode startMode, const String& contentSecurityPolicy, ContentSecurityPolicy::HeaderType contentSecurityPolicyType)
{
return adoptRef(new SharedWorkerThread(name, scriptURL, userAgent, sourceCode, workerLoaderProxy, workerReportingProxy, startMode));
return adoptRef(new SharedWorkerThread(name, scriptURL, userAgent, sourceCode, workerLoaderProxy, workerReportingProxy, startMode, contentSecurityPolicy, contentSecurityPolicyType));
}
SharedWorkerThread::SharedWorkerThread(const String& name, const KURL& url, const String& userAgent, const String& sourceCode, WorkerLoaderProxy& workerLoaderProxy, WorkerReportingProxy& workerReportingProxy, WorkerThreadStartMode startMode)
: WorkerThread(url, userAgent, sourceCode, workerLoaderProxy, workerReportingProxy, startMode)
SharedWorkerThread::SharedWorkerThread(const String& name, const KURL& url, const String& userAgent, const String& sourceCode, WorkerLoaderProxy& workerLoaderProxy, WorkerReportingProxy& workerReportingProxy, WorkerThreadStartMode startMode, const String& contentSecurityPolicy, ContentSecurityPolicy::HeaderType contentSecurityPolicyType)
: WorkerThread(url, userAgent, sourceCode, workerLoaderProxy, workerReportingProxy, startMode, contentSecurityPolicy, contentSecurityPolicyType)
, m_name(name.isolatedCopy())
{
}
......@@ -53,9 +53,9 @@ SharedWorkerThread::~SharedWorkerThread()
{
}
PassRefPtr<WorkerContext> SharedWorkerThread::createWorkerContext(const KURL& url, const String& userAgent)
PassRefPtr<WorkerContext> SharedWorkerThread::createWorkerContext(const KURL& url, const String& userAgent, const String& contentSecurityPolicy, ContentSecurityPolicy::HeaderType contentSecurityPolicyType)
{
return SharedWorkerContext::create(m_name, url, userAgent, this);
return SharedWorkerContext::create(m_name, url, userAgent, this, contentSecurityPolicy, contentSecurityPolicyType);
}
} // namespace WebCore
......
......@@ -32,20 +32,21 @@
#if ENABLE(SHARED_WORKERS)
#include "ContentSecurityPolicy.h"
#include "WorkerThread.h"
namespace WebCore {
class SharedWorkerThread : public WorkerThread {
public:
static PassRefPtr<SharedWorkerThread> create(const String& name, const KURL&, const String& userAgent, const String& sourceCode, WorkerLoaderProxy&, WorkerReportingProxy&, WorkerThreadStartMode);
static PassRefPtr<SharedWorkerThread> create(const String& name, const KURL&, const String& userAgent, const String& sourceCode, WorkerLoaderProxy&, WorkerReportingProxy&, WorkerThreadStartMode, const String& contentSecurityPolicy, ContentSecurityPolicy::HeaderType);
~SharedWorkerThread();
protected:
virtual PassRefPtr<WorkerContext> createWorkerContext(const KURL&, const String&);
virtual PassRefPtr<WorkerContext> createWorkerContext(const KURL&, const String&, const String& contentSecurityPolicy, ContentSecurityPolicy::HeaderType);
private:
SharedWorkerThread(const String& name, const KURL&, const String& userAgent, const String& sourceCode, WorkerLoaderProxy&, WorkerReportingProxy&, WorkerThreadStartMode);
SharedWorkerThread(const String& name, const KURL&, const String& userAgent, const String& sourceCode, WorkerLoaderProxy&, WorkerReportingProxy&, WorkerThreadStartMode, const String& contentSecurityPolicy, ContentSecurityPolicy::HeaderType);
String m_name;
};
......
......@@ -108,7 +108,7 @@ public:
virtual bool isCleanupTask() const { return true; }
};
WorkerContext::WorkerContext(const KURL& url, const String& userAgent, WorkerThread* thread)
WorkerContext::WorkerContext(const KURL& url, const String& userAgent, WorkerThread* thread, const String& policy, ContentSecurityPolicy::HeaderType contentSecurityPolicyType)
: m_url(url)
, m_userAgent(userAgent)
, m_script(adoptPtr(new WorkerScriptController(this)))
......@@ -120,10 +120,8 @@ WorkerContext::WorkerContext(const KURL& url, const String& userAgent, WorkerThr
, m_eventQueue(WorkerEventQueue::create(this))
{
setSecurityOrigin(SecurityOrigin::create(url));
// FIXME: This should probably adopt the ContentSecurityPolicy of the document
// that created this worker or use the header that came with the worker script.
setContentSecurityPolicy(ContentSecurityPolicy::create(this));
contentSecurityPolicy()->didReceiveHeader(policy, contentSecurityPolicyType);
}
WorkerContext::~WorkerContext()
......
......@@ -29,6 +29,7 @@
#if ENABLE(WORKERS)
#include "ContentSecurityPolicy.h"
#include "EventListener.h"
#include "EventNames.h"
#include "EventTarget.h"
......@@ -179,7 +180,7 @@ namespace WebCore {
#endif
protected:
WorkerContext(const KURL&, const String&, WorkerThread*);
WorkerContext(const KURL&, const String&, WorkerThread*, const String& contentSecurityPolicy, ContentSecurityPolicy::HeaderType);
virtual void logExceptionToConsole(const String& errorMessage, int lineNumber, const String& sourceURL, PassRefPtr<ScriptCallStack>);
void addMessageToWorkerConsole(MessageSource, MessageType, MessageLevel, const String& message, unsigned lineNumber, const String& sourceURL, PassRefPtr<ScriptCallStack>);
......
......@@ -31,6 +31,7 @@
#include "WorkerMessagingProxy.h"
#include "ContentSecurityPolicy.h"
#include "CrossThreadTask.h"
#include "DedicatedWorkerContext.h"
#include "DedicatedWorkerThread.h"
......@@ -270,7 +271,9 @@ WorkerMessagingProxy::~WorkerMessagingProxy()
void WorkerMessagingProxy::startWorkerContext(const KURL& scriptURL, const String& userAgent, const String& sourceCode, WorkerThreadStartMode startMode)
{
RefPtr<DedicatedWorkerThread> thread = DedicatedWorkerThread::create(scriptURL, userAgent, sourceCode, *this, *this, startMode);
RefPtr<DedicatedWorkerThread> thread = DedicatedWorkerThread::create(scriptURL, userAgent, sourceCode, *this, *this, startMode,
m_scriptExecutionContext->contentSecurityPolicy()->policy(),
m_scriptExecutionContext->contentSecurityPolicy()->headerType());
workerThreadCreated(thread);
thread->start();
}
......
......@@ -65,32 +65,36 @@ unsigned WorkerThread::workerThreadCount()
struct WorkerThreadStartupData {
WTF_MAKE_NONCOPYABLE(WorkerThreadStartupData); WTF_MAKE_FAST_ALLOCATED;
public:
static PassOwnPtr<WorkerThreadStartupData> create(const KURL& scriptURL, const String& userAgent, const String& sourceCode, WorkerThreadStartMode startMode)
static PassOwnPtr<WorkerThreadStartupData> create(const KURL& scriptURL, const String& userAgent, const String& sourceCode, WorkerThreadStartMode startMode, const String& contentSecurityPolicy, ContentSecurityPolicy::HeaderType contentSecurityPolicyType)
{
return adoptPtr(new WorkerThreadStartupData(scriptURL, userAgent, sourceCode, startMode));
return adoptPtr(new WorkerThreadStartupData(scriptURL, userAgent, sourceCode, startMode, contentSecurityPolicy, contentSecurityPolicyType));
}
KURL m_scriptURL;
String m_userAgent;
String m_sourceCode;
WorkerThreadStartMode m_startMode;
String m_contentSecurityPolicy;
ContentSecurityPolicy::HeaderType m_contentSecurityPolicyType;
private:
WorkerThreadStartupData(const KURL& scriptURL, const String& userAgent, const String& sourceCode, WorkerThreadStartMode);
WorkerThreadStartupData(const KURL& scriptURL, const String& userAgent, const String& sourceCode, WorkerThreadStartMode, const String& contentSecurityPolicy, ContentSecurityPolicy::HeaderType contentSecurityPolicyType);
};
WorkerThreadStartupData::WorkerThreadStartupData(const KURL& scriptURL, const String& userAgent, const String& sourceCode, WorkerThreadStartMode startMode)
WorkerThreadStartupData::WorkerThreadStartupData(const KURL& scriptURL, const String& userAgent, const String& sourceCode, WorkerThreadStartMode startMode, const String& contentSecurityPolicy, ContentSecurityPolicy::HeaderType contentSecurityPolicyType)
: m_scriptURL(scriptURL.copy())
, m_userAgent(userAgent.isolatedCopy())
, m_sourceCode(sourceCode.isolatedCopy())
, m_startMode(startMode)
, m_contentSecurityPolicy(contentSecurityPolicy.isolatedCopy())