WebSharedWorkerImpl.cpp [plain text]
#include "config.h"
#include "WebSharedWorkerImpl.h"
#include "GenericWorkerTask.h"
#include "KURL.h"
#include "MessageEvent.h"
#include "MessagePortChannel.h"
#include "PlatformMessagePortChannel.h"
#include "ScriptExecutionContext.h"
#include "SharedWorkerContext.h"
#include "SharedWorkerThread.h"
#include "WebMessagePortChannel.h"
#include "WebString.h"
#include "WebURL.h"
using namespace WebCore;
namespace WebKit {
#if ENABLE(SHARED_WORKERS)
WebSharedWorkerImpl::WebSharedWorkerImpl(WebCommonWorkerClient* client)
: m_client(client)
{
}
WebSharedWorkerImpl::~WebSharedWorkerImpl()
{
}
bool WebSharedWorkerImpl::isStarted()
{
ASSERT_NOT_REACHED();
return workerThread();
}
void WebSharedWorkerImpl::connect(WebMessagePortChannel* webChannel, ConnectListener* listener)
{
RefPtr<PlatformMessagePortChannel> platform_channel =
PlatformMessagePortChannel::create(webChannel);
webChannel->setClient(platform_channel.get());
OwnPtr<MessagePortChannel> channel =
MessagePortChannel::create(platform_channel);
workerThread()->runLoop().postTask(
createCallbackTask(&connectTask, this, channel.release()));
if (listener)
listener->connected();
}
void WebSharedWorkerImpl::connectTask(ScriptExecutionContext* context, WebSharedWorkerImpl* worker, PassOwnPtr<MessagePortChannel> channel)
{
RefPtr<MessagePort> port = MessagePort::create(*context);
port->entangle(channel.release());
ASSERT(context->isWorkerContext());
WorkerContext* workerContext = static_cast<WorkerContext*>(context);
ASSERT(workerContext->isSharedWorkerContext());
workerContext->toSharedWorkerContext()->dispatchEvent(createConnectEvent(port));
}
void WebSharedWorkerImpl::startWorkerContext(const WebURL& url, const WebString& name, const WebString& userAgent, const WebString& sourceCode)
{
initializeLoader(url);
setWorkerThread(SharedWorkerThread::create(name, url, userAgent, sourceCode, *this, *this));
workerThread()->start();
}
void WebSharedWorkerImpl::terminateWorkerContext()
{
stopWorkerThread();
}
void WebSharedWorkerImpl::clientDestroyed()
{
m_client = 0;
}
WebWorkerClient* WebSharedWorkerImpl::client()
{
ASSERT_NOT_REACHED();
return 0;
}
WebSharedWorker* WebSharedWorker::create(WebCommonWorkerClient* client)
{
return new WebSharedWorkerImpl(client);
}
#endif // ENABLE(SHARED_WORKERS)
}