2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
32 #include "core/workers/DedicatedWorkerGlobalScope.h"
34 #include "bindings/core/v8/ExceptionState.h"
35 #include "bindings/core/v8/SerializedScriptValue.h"
36 #include "core/frame/LocalDOMWindow.h"
37 #include "core/workers/DedicatedWorkerThread.h"
38 #include "core/workers/WorkerClients.h"
39 #include "core/workers/WorkerObjectProxy.h"
40 #include "core/workers/WorkerThreadStartupData.h"
44 PassRefPtrWillBeRawPtr<DedicatedWorkerGlobalScope> DedicatedWorkerGlobalScope::create(DedicatedWorkerThread* thread, PassOwnPtrWillBeRawPtr<WorkerThreadStartupData> startupData, double timeOrigin)
46 RefPtrWillBeRawPtr<DedicatedWorkerGlobalScope> context = adoptRefWillBeRefCountedGarbageCollected(new DedicatedWorkerGlobalScope(startupData->m_scriptURL, startupData->m_userAgent, thread, timeOrigin, startupData->m_workerClients.release()));
47 context->applyContentSecurityPolicyFromString(startupData->m_contentSecurityPolicy, startupData->m_contentSecurityPolicyType);
48 return context.release();
51 DedicatedWorkerGlobalScope::DedicatedWorkerGlobalScope(const KURL& url, const String& userAgent, DedicatedWorkerThread* thread, double timeOrigin, PassOwnPtrWillBeRawPtr<WorkerClients> workerClients)
52 : WorkerGlobalScope(url, userAgent, thread, timeOrigin, workerClients)
54 ScriptWrappable::init(this);
57 DedicatedWorkerGlobalScope::~DedicatedWorkerGlobalScope()
61 const AtomicString& DedicatedWorkerGlobalScope::interfaceName() const
63 return EventTargetNames::DedicatedWorkerGlobalScope;
66 void DedicatedWorkerGlobalScope::postMessage(ExecutionContext*, PassRefPtr<SerializedScriptValue> message, const MessagePortArray* ports, ExceptionState& exceptionState)
68 // Disentangle the port in preparation for sending it to the remote context.
69 OwnPtr<MessagePortChannelArray> channels = MessagePort::disentanglePorts(ports, exceptionState);
70 if (exceptionState.hadException())
72 thread()->workerObjectProxy().postMessageToWorkerObject(message, channels.release());
75 void DedicatedWorkerGlobalScope::importScripts(const Vector<String>& urls, ExceptionState& exceptionState)
77 Base::importScripts(urls, exceptionState);
78 thread()->workerObjectProxy().reportPendingActivity(hasPendingActivity());
81 DedicatedWorkerThread* DedicatedWorkerGlobalScope::thread() const
83 return static_cast<DedicatedWorkerThread*>(Base::thread());
86 class UseCounterTask : public ExecutionContextTask {
88 static PassOwnPtr<UseCounterTask> createCount(UseCounter::Feature feature) { return adoptPtr(new UseCounterTask(feature, false)); }
89 static PassOwnPtr<UseCounterTask> createDeprecation(UseCounter::Feature feature) { return adoptPtr(new UseCounterTask(feature, true)); }
92 UseCounterTask(UseCounter::Feature feature, bool isDeprecation)
94 , m_isDeprecation(isDeprecation)
98 virtual void performTask(ExecutionContext* context) OVERRIDE
100 ASSERT(context->isDocument());
102 UseCounter::countDeprecation(context, m_feature);
104 UseCounter::count(context, m_feature);
107 UseCounter::Feature m_feature;
108 bool m_isDeprecation;
111 void DedicatedWorkerGlobalScope::countFeature(UseCounter::Feature feature) const
113 thread()->workerObjectProxy().postTaskToMainExecutionContext(UseCounterTask::createCount(feature));
116 void DedicatedWorkerGlobalScope::countDeprecation(UseCounter::Feature feature) const
118 thread()->workerObjectProxy().postTaskToMainExecutionContext(UseCounterTask::createDeprecation(feature));
121 void DedicatedWorkerGlobalScope::trace(Visitor* visitor)
123 WorkerGlobalScope::trace(visitor);