This source file includes following definitions.
- create
- interfaceName
- setPreventGC
- unsetPreventGC
- trace
#include "config.h"
#include "core/workers/SharedWorker.h"
#include "bindings/v8/ExceptionState.h"
#include "core/dom/ExceptionCode.h"
#include "core/dom/ExecutionContext.h"
#include "core/dom/MessageChannel.h"
#include "core/dom/MessagePort.h"
#include "core/frame/LocalFrame.h"
#include "core/frame/UseCounter.h"
#include "core/inspector/InspectorInstrumentation.h"
#include "core/loader/FrameLoader.h"
#include "core/loader/FrameLoaderClient.h"
#include "core/workers/SharedWorkerRepositoryClient.h"
#include "platform/weborigin/KURL.h"
#include "platform/weborigin/SecurityOrigin.h"
namespace WebCore {
inline SharedWorker::SharedWorker(ExecutionContext* context)
: AbstractWorker(context)
{
ScriptWrappable::init(this);
}
PassRefPtrWillBeRawPtr<SharedWorker> SharedWorker::create(ExecutionContext* context, const String& url, const String& name, ExceptionState& exceptionState)
{
ASSERT(isMainThread());
ASSERT_WITH_SECURITY_IMPLICATION(context->isDocument());
UseCounter::count(context, UseCounter::SharedWorkerStart);
RefPtrWillBeRawPtr<SharedWorker> worker = adoptRefWillBeRefCountedGarbageCollected(new SharedWorker(context));
RefPtr<MessageChannel> channel = MessageChannel::create(context);
worker->m_port = channel->port1();
OwnPtr<blink::WebMessagePortChannel> remotePort = channel->port2()->disentangle();
ASSERT(remotePort);
worker->suspendIfNeeded();
Document* document = toDocument(context);
if (!document->securityOrigin()->canAccessSharedWorkers()) {
exceptionState.throwSecurityError("Access to shared workers is denied to origin '" + document->securityOrigin()->toString() + "'.");
return nullptr;
}
KURL scriptURL = worker->resolveURL(url, exceptionState);
if (scriptURL.isEmpty())
return nullptr;
if (document->frame()->loader().client()->sharedWorkerRepositoryClient())
document->frame()->loader().client()->sharedWorkerRepositoryClient()->connect(worker.get(), remotePort.release(), scriptURL, name, exceptionState);
return worker.release();
}
SharedWorker::~SharedWorker()
{
}
const AtomicString& SharedWorker::interfaceName() const
{
return EventTargetNames::SharedWorker;
}
void SharedWorker::setPreventGC()
{
setPendingActivity(this);
}
void SharedWorker::unsetPreventGC()
{
unsetPendingActivity(this);
}
void SharedWorker::trace(Visitor* visitor)
{
AbstractWorker::trace(visitor);
#if ENABLE(OILPAN)
HeapSupplementable<SharedWorker>::trace(visitor);
#endif
}
}