| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/compositorworker/CompositorWorkerGlobalScope.h" | 5 #include "modules/compositorworker/CompositorWorkerGlobalScope.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/SerializedScriptValue.h" | 7 #include "bindings/core/v8/SerializedScriptValue.h" |
| 8 #include "core/workers/WorkerObjectProxy.h" | 8 #include "core/workers/WorkerObjectProxy.h" |
| 9 #include "core/workers/WorkerThreadStartupData.h" | 9 #include "core/workers/WorkerThreadStartupData.h" |
| 10 #include "modules/EventTargetModules.h" | 10 #include "modules/EventTargetModules.h" |
| 11 #include "modules/compositorworker/CompositorWorkerThread.h" | 11 #include "modules/compositorworker/CompositorWorkerThread.h" |
| 12 | 12 |
| 13 namespace blink { | 13 namespace blink { |
| 14 | 14 |
| 15 CompositorWorkerGlobalScope* CompositorWorkerGlobalScope::create(CompositorWorke
rThread* thread, PassOwnPtr<WorkerThreadStartupData> startupData, double timeOri
gin) | 15 CompositorWorkerGlobalScope* CompositorWorkerGlobalScope::create(CompositorWorke
rThread* thread, PassOwnPtr<WorkerThreadStartupData> startupData, double timeOri
gin) |
| 16 { | 16 { |
| 17 // Note: startupData is finalized on return. After the relevant parts has be
en | 17 // Note: startupData is finalized on return. After the relevant parts has be
en |
| 18 // passed along to the created 'context'. | 18 // passed along to the created 'context'. |
| 19 CompositorWorkerGlobalScope* context = new CompositorWorkerGlobalScope(start
upData->m_scriptURL, startupData->m_userAgent, thread, timeOrigin, startupData->
m_starterOriginPrivilegeData.release(), startupData->m_workerClients.release()); | 19 CompositorWorkerGlobalScope* context = new CompositorWorkerGlobalScope(start
upData->m_scriptURL, startupData->m_userAgent, thread, timeOrigin, startupData->
m_starterOriginPrivilegeData.release(), startupData->m_workerClients.release()); |
| 20 context->applyContentSecurityPolicyFromVector(*startupData->m_contentSecurit
yPolicyHeaders); | 20 context->applyContentSecurityPolicyFromVector(*startupData->m_contentSecurit
yPolicyHeaders); |
| 21 context->setAddressSpace(startupData->m_addressSpace); | 21 context->setAddressSpace(startupData->m_addressSpace); |
| 22 return context; | 22 return context; |
| 23 } | 23 } |
| 24 | 24 |
| 25 CompositorWorkerGlobalScope::CompositorWorkerGlobalScope(const KURL& url, const
String& userAgent, CompositorWorkerThread* thread, double timeOrigin, PassOwnPtr
<SecurityOrigin::PrivilegeData> starterOriginPrivilegeData, WorkerClients* worke
rClients) | 25 CompositorWorkerGlobalScope::CompositorWorkerGlobalScope(const KURL& url, const
String& userAgent, CompositorWorkerThread* thread, double timeOrigin, PassOwnPtr
<SecurityOrigin::PrivilegeData> starterOriginPrivilegeData, WorkerClients* worke
rClients) |
| 26 : WorkerGlobalScope(url, userAgent, thread, timeOrigin, starterOriginPrivile
geData, workerClients) | 26 : WorkerGlobalScope(url, userAgent, thread, timeOrigin, starterOriginPrivile
geData, workerClients) |
| 27 , m_executingAnimationFrameCallbacks(false) |
| 27 , m_callbackCollection(this) | 28 , m_callbackCollection(this) |
| 29 , m_client(CompositorProxyClient::from(clients())) |
| 28 { | 30 { |
| 31 m_client->setGlobalScope(this); |
| 32 ThreadState::current()->registerPreFinalizer(this); |
| 33 } |
| 34 |
| 35 void CompositorWorkerGlobalScope::dispose() |
| 36 { |
| 37 m_client->setGlobalScope(nullptr); |
| 29 } | 38 } |
| 30 | 39 |
| 31 CompositorWorkerGlobalScope::~CompositorWorkerGlobalScope() | 40 CompositorWorkerGlobalScope::~CompositorWorkerGlobalScope() |
| 32 { | 41 { |
| 33 } | 42 } |
| 34 | 43 |
| 35 DEFINE_TRACE(CompositorWorkerGlobalScope) | 44 DEFINE_TRACE(CompositorWorkerGlobalScope) |
| 36 { | 45 { |
| 37 visitor->trace(m_callbackCollection); | 46 visitor->trace(m_callbackCollection); |
| 47 visitor->trace(m_client); |
| 38 WorkerGlobalScope::trace(visitor); | 48 WorkerGlobalScope::trace(visitor); |
| 39 } | 49 } |
| 40 | 50 |
| 41 const AtomicString& CompositorWorkerGlobalScope::interfaceName() const | 51 const AtomicString& CompositorWorkerGlobalScope::interfaceName() const |
| 42 { | 52 { |
| 43 return EventTargetNames::CompositorWorkerGlobalScope; | 53 return EventTargetNames::CompositorWorkerGlobalScope; |
| 44 } | 54 } |
| 45 | 55 |
| 46 void CompositorWorkerGlobalScope::postMessage(ExecutionContext* executionContext
, PassRefPtr<SerializedScriptValue> message, const MessagePortArray& ports, Exce
ptionState& exceptionState) | 56 void CompositorWorkerGlobalScope::postMessage(ExecutionContext* executionContext
, PassRefPtr<SerializedScriptValue> message, const MessagePortArray& ports, Exce
ptionState& exceptionState) |
| 47 { | 57 { |
| 48 // Disentangle the port in preparation for sending it to the remote context. | 58 // Disentangle the port in preparation for sending it to the remote context. |
| 49 OwnPtr<MessagePortChannelArray> channels = MessagePort::disentanglePorts(exe
cutionContext, ports, exceptionState); | 59 OwnPtr<MessagePortChannelArray> channels = MessagePort::disentanglePorts(exe
cutionContext, ports, exceptionState); |
| 50 if (exceptionState.hadException()) | 60 if (exceptionState.hadException()) |
| 51 return; | 61 return; |
| 52 thread()->workerObjectProxy().postMessageToWorkerObject(message, channels.re
lease()); | 62 thread()->workerObjectProxy().postMessageToWorkerObject(message, channels.re
lease()); |
| 53 } | 63 } |
| 54 | 64 |
| 55 int CompositorWorkerGlobalScope::requestAnimationFrame(FrameRequestCallback* cal
lback) | 65 int CompositorWorkerGlobalScope::requestAnimationFrame(FrameRequestCallback* cal
lback) |
| 56 { | 66 { |
| 67 const bool shouldSignal = !m_executingAnimationFrameCallbacks && m_callbackC
ollection.isEmpty(); |
| 68 if (shouldSignal) |
| 69 m_client->requestMutation(); |
| 57 return m_callbackCollection.registerCallback(callback); | 70 return m_callbackCollection.registerCallback(callback); |
| 58 } | 71 } |
| 59 | 72 |
| 60 void CompositorWorkerGlobalScope::cancelAnimationFrame(int id) | 73 void CompositorWorkerGlobalScope::cancelAnimationFrame(int id) |
| 61 { | 74 { |
| 62 m_callbackCollection.cancelCallback(id); | 75 m_callbackCollection.cancelCallback(id); |
| 63 } | 76 } |
| 64 | 77 |
| 65 void CompositorWorkerGlobalScope::executeAnimationFrameCallbacks(double highResT
imeNow) | 78 bool CompositorWorkerGlobalScope::executeAnimationFrameCallbacks(double highResT
imeNow) |
| 66 { | 79 { |
| 80 TemporaryChange<bool> temporaryChange(m_executingAnimationFrameCallbacks, tr
ue); |
| 67 m_callbackCollection.executeCallbacks(highResTimeNow, highResTimeNow); | 81 m_callbackCollection.executeCallbacks(highResTimeNow, highResTimeNow); |
| 82 return !m_callbackCollection.isEmpty(); |
| 68 } | 83 } |
| 69 | 84 |
| 70 CompositorWorkerThread* CompositorWorkerGlobalScope::thread() const | 85 CompositorWorkerThread* CompositorWorkerGlobalScope::thread() const |
| 71 { | 86 { |
| 72 return static_cast<CompositorWorkerThread*>(WorkerGlobalScope::thread()); | 87 return static_cast<CompositorWorkerThread*>(WorkerGlobalScope::thread()); |
| 73 } | 88 } |
| 74 | 89 |
| 75 } // namespace blink | 90 } // namespace blink |
| OLD | NEW |