• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
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
13  * distribution.
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.
17  *
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.
29  */
30 
31 #include "config.h"
32 #include "core/workers/DedicatedWorkerGlobalScope.h"
33 
34 #include "bindings/v8/ExceptionState.h"
35 #include "bindings/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"
41 
42 namespace WebCore {
43 
create(DedicatedWorkerThread * thread,PassOwnPtrWillBeRawPtr<WorkerThreadStartupData> startupData,double timeOrigin)44 PassRefPtrWillBeRawPtr<DedicatedWorkerGlobalScope> DedicatedWorkerGlobalScope::create(DedicatedWorkerThread* thread, PassOwnPtrWillBeRawPtr<WorkerThreadStartupData> startupData, double timeOrigin)
45 {
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();
49 }
50 
DedicatedWorkerGlobalScope(const KURL & url,const String & userAgent,DedicatedWorkerThread * thread,double timeOrigin,PassOwnPtrWillBeRawPtr<WorkerClients> workerClients)51 DedicatedWorkerGlobalScope::DedicatedWorkerGlobalScope(const KURL& url, const String& userAgent, DedicatedWorkerThread* thread, double timeOrigin, PassOwnPtrWillBeRawPtr<WorkerClients> workerClients)
52     : WorkerGlobalScope(url, userAgent, thread, timeOrigin, workerClients)
53 {
54     ScriptWrappable::init(this);
55 }
56 
~DedicatedWorkerGlobalScope()57 DedicatedWorkerGlobalScope::~DedicatedWorkerGlobalScope()
58 {
59 }
60 
interfaceName() const61 const AtomicString& DedicatedWorkerGlobalScope::interfaceName() const
62 {
63     return EventTargetNames::DedicatedWorkerGlobalScope;
64 }
65 
postMessage(PassRefPtr<SerializedScriptValue> message,const MessagePortArray * ports,ExceptionState & exceptionState)66 void DedicatedWorkerGlobalScope::postMessage(PassRefPtr<SerializedScriptValue> message, const MessagePortArray* ports, ExceptionState& exceptionState)
67 {
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())
71         return;
72     thread()->workerObjectProxy().postMessageToWorkerObject(message, channels.release());
73 }
74 
importScripts(const Vector<String> & urls,ExceptionState & exceptionState)75 void DedicatedWorkerGlobalScope::importScripts(const Vector<String>& urls, ExceptionState& exceptionState)
76 {
77     Base::importScripts(urls, exceptionState);
78     thread()->workerObjectProxy().reportPendingActivity(hasPendingActivity());
79 }
80 
thread() const81 DedicatedWorkerThread* DedicatedWorkerGlobalScope::thread() const
82 {
83     return static_cast<DedicatedWorkerThread*>(Base::thread());
84 }
85 
86 class UseCounterTask : public ExecutionContextTask {
87 public:
createCount(UseCounter::Feature feature)88     static PassOwnPtr<UseCounterTask> createCount(UseCounter::Feature feature) { return adoptPtr(new UseCounterTask(feature, false)); }
createDeprecation(UseCounter::Feature feature)89     static PassOwnPtr<UseCounterTask> createDeprecation(UseCounter::Feature feature) { return adoptPtr(new UseCounterTask(feature, true)); }
90 
91 private:
UseCounterTask(UseCounter::Feature feature,bool isDeprecation)92     UseCounterTask(UseCounter::Feature feature, bool isDeprecation)
93         : m_feature(feature)
94         , m_isDeprecation(isDeprecation)
95     {
96     }
97 
performTask(ExecutionContext * context)98     virtual void performTask(ExecutionContext* context) OVERRIDE
99     {
100         if (m_isDeprecation)
101             UseCounter::countDeprecation(*toDocument(context), m_feature);
102         else
103             UseCounter::count(*toDocument(context), m_feature);
104     }
105 
106     UseCounter::Feature m_feature;
107     bool m_isDeprecation;
108 };
109 
countFeature(UseCounter::Feature feature) const110 void DedicatedWorkerGlobalScope::countFeature(UseCounter::Feature feature) const
111 {
112     thread()->workerObjectProxy().postTaskToMainExecutionContext(UseCounterTask::createCount(feature));
113 }
114 
countDeprecation(UseCounter::Feature feature) const115 void DedicatedWorkerGlobalScope::countDeprecation(UseCounter::Feature feature) const
116 {
117     thread()->workerObjectProxy().postTaskToMainExecutionContext(UseCounterTask::createDeprecation(feature));
118 }
119 
trace(Visitor * visitor)120 void DedicatedWorkerGlobalScope::trace(Visitor* visitor)
121 {
122     WorkerGlobalScope::trace(visitor);
123 }
124 
125 } // namespace WebCore
126