| 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 #include "platform/TraceEvent.h" |
| 13 #include "wtf/TemporaryChange.h" |
| 14 #include "wtf/ThreadingPrimitives.h" |
| 12 | 15 |
| 13 namespace blink { | 16 namespace blink { |
| 14 | 17 |
| 15 PassRefPtrWillBeRawPtr<CompositorWorkerGlobalScope> CompositorWorkerGlobalScope:
:create(CompositorWorkerThread* thread, PassOwnPtr<WorkerThreadStartupData> star
tupData, double timeOrigin) | 18 PassRefPtrWillBeRawPtr<CompositorWorkerGlobalScope> CompositorWorkerGlobalScope:
:create(CompositorWorkerThread* thread, PassOwnPtr<WorkerThreadStartupData> star
tupData, double timeOrigin) |
| 16 { | 19 { |
| 20 TRACE_EVENT0("compositor-worker", "CompositorWorkerGlobalScope::create"); |
| 17 // Note: startupData is finalized on return. After the relevant parts has be
en | 21 // Note: startupData is finalized on return. After the relevant parts has be
en |
| 18 // passed along to the created 'context'. | 22 // passed along to the created 'context'. |
| 19 RefPtrWillBeRawPtr<CompositorWorkerGlobalScope> context = adoptRefWillBeNoop
(new CompositorWorkerGlobalScope(startupData->m_scriptURL, startupData->m_userAg
ent, thread, timeOrigin, startupData->m_starterOriginPrivilegeData.release(), st
artupData->m_workerClients.release())); | 23 RefPtrWillBeRawPtr<CompositorWorkerGlobalScope> context = adoptRefWillBeNoop
(new CompositorWorkerGlobalScope(startupData->m_scriptURL, startupData->m_userAg
ent, thread, timeOrigin, startupData->m_starterOriginPrivilegeData.release(), st
artupData->m_workerClients.release())); |
| 20 context->applyContentSecurityPolicyFromVector(*startupData->m_contentSecurit
yPolicyHeaders); | 24 context->applyContentSecurityPolicyFromVector(*startupData->m_contentSecurit
yPolicyHeaders); |
| 21 return context.release(); | 25 return context.release(); |
| 22 } | 26 } |
| 23 | 27 |
| 24 CompositorWorkerGlobalScope::CompositorWorkerGlobalScope(const KURL& url, const
String& userAgent, CompositorWorkerThread* thread, double timeOrigin, PassOwnPtr
<SecurityOrigin::PrivilegeData> starterOriginPrivilegeData, PassOwnPtrWillBeRawP
tr<WorkerClients> workerClients) | 28 CompositorWorkerGlobalScope::CompositorWorkerGlobalScope(const KURL& url, const
String& userAgent, CompositorWorkerThread* thread, double timeOrigin, PassOwnPtr
<SecurityOrigin::PrivilegeData> starterOriginPrivilegeData, PassOwnPtrWillBeRawP
tr<WorkerClients> workerClients) |
| 25 : WorkerGlobalScope(url, userAgent, thread, timeOrigin, starterOriginPrivile
geData, workerClients) | 29 : WorkerGlobalScope(url, userAgent, thread, timeOrigin, starterOriginPrivile
geData, workerClients) |
| 30 , m_executingAnimationFrameCallbacks(false) |
| 26 , m_callbackCollection(this) | 31 , m_callbackCollection(this) |
| 32 , m_client(CompositorProxyClient::from(clients())) |
| 27 { | 33 { |
| 34 m_client->setGlobalScope(this); |
| 28 } | 35 } |
| 29 | 36 |
| 30 CompositorWorkerGlobalScope::~CompositorWorkerGlobalScope() | 37 CompositorWorkerGlobalScope::~CompositorWorkerGlobalScope() |
| 31 { | 38 { |
| 39 TRACE_EVENT0("compositor-worker", "CompositorWorkerGlobalScope::~CompositorW
orkerGlobalScope"); |
| 32 } | 40 } |
| 33 | 41 |
| 34 DEFINE_TRACE(CompositorWorkerGlobalScope) | 42 DEFINE_TRACE(CompositorWorkerGlobalScope) |
| 35 { | 43 { |
| 36 visitor->trace(m_callbackCollection); | 44 visitor->trace(m_callbackCollection); |
| 37 WorkerGlobalScope::trace(visitor); | 45 WorkerGlobalScope::trace(visitor); |
| 38 } | 46 } |
| 39 | 47 |
| 40 const AtomicString& CompositorWorkerGlobalScope::interfaceName() const | 48 const AtomicString& CompositorWorkerGlobalScope::interfaceName() const |
| 41 { | 49 { |
| 42 return EventTargetNames::CompositorWorkerGlobalScope; | 50 return EventTargetNames::CompositorWorkerGlobalScope; |
| 43 } | 51 } |
| 44 | 52 |
| 45 void CompositorWorkerGlobalScope::postMessage(ExecutionContext* executionContext
, PassRefPtr<SerializedScriptValue> message, const MessagePortArray* ports, Exce
ptionState& exceptionState) | 53 void CompositorWorkerGlobalScope::postMessage(ExecutionContext* executionContext
, PassRefPtr<SerializedScriptValue> message, const MessagePortArray* ports, Exce
ptionState& exceptionState) |
| 46 { | 54 { |
| 55 TRACE_EVENT0("compositor-worker", "CompositorWorkerGlobalScope::postMessage"
); |
| 56 |
| 47 // Disentangle the port in preparation for sending it to the remote context. | 57 // Disentangle the port in preparation for sending it to the remote context. |
| 48 OwnPtr<MessagePortChannelArray> channels = MessagePort::disentanglePorts(exe
cutionContext, ports, exceptionState); | 58 OwnPtr<MessagePortChannelArray> channels = MessagePort::disentanglePorts(exe
cutionContext, ports, exceptionState); |
| 49 if (exceptionState.hadException()) | 59 if (exceptionState.hadException()) |
| 50 return; | 60 return; |
| 51 thread()->workerObjectProxy().postMessageToWorkerObject(message, channels.re
lease()); | 61 thread()->workerObjectProxy().postMessageToWorkerObject(message, channels.re
lease()); |
| 52 } | 62 } |
| 53 | 63 |
| 54 int CompositorWorkerGlobalScope::requestAnimationFrame(FrameRequestCallback* cal
lback) | 64 int CompositorWorkerGlobalScope::requestAnimationFrame(FrameRequestCallback* cal
lback) |
| 55 { | 65 { |
| 66 TRACE_EVENT0("compositor-worker", "CompositorWorkerGlobalScope::requestAnima
tionFrame"); |
| 67 const bool shouldSignal = !m_executingAnimationFrameCallbacks && m_callbackC
ollection.isEmpty(); |
| 68 if (shouldSignal) |
| 69 m_client->requestMutation(); |
| 56 return m_callbackCollection.registerCallback(callback); | 70 return m_callbackCollection.registerCallback(callback); |
| 57 } | 71 } |
| 58 | 72 |
| 59 void CompositorWorkerGlobalScope::cancelAnimationFrame(int id) | 73 void CompositorWorkerGlobalScope::cancelAnimationFrame(int id) |
| 60 { | 74 { |
| 75 TRACE_EVENT0("compositor-worker", "CompositorWorkerGlobalScope::cancelAnimat
ionFrame"); |
| 61 m_callbackCollection.cancelCallback(id); | 76 m_callbackCollection.cancelCallback(id); |
| 62 } | 77 } |
| 63 | 78 |
| 64 void CompositorWorkerGlobalScope::executeAnimationFrameCallbacks(double highResT
imeNow) | 79 bool CompositorWorkerGlobalScope::executeAnimationFrameCallbacks(double highResT
imeNow) |
| 65 { | 80 { |
| 81 TRACE_EVENT0("compositor-worker", "CompositorWorkerGlobalScope::executeAnima
tionFrameCallbacks"); |
| 82 TemporaryChange<bool> temporaryChange(m_executingAnimationFrameCallbacks, tr
ue); |
| 66 m_callbackCollection.executeCallbacks(highResTimeNow, highResTimeNow); | 83 m_callbackCollection.executeCallbacks(highResTimeNow, highResTimeNow); |
| 84 return !m_callbackCollection.isEmpty(); |
| 67 } | 85 } |
| 68 | 86 |
| 69 CompositorWorkerThread* CompositorWorkerGlobalScope::thread() const | 87 CompositorWorkerThread* CompositorWorkerGlobalScope::thread() const |
| 70 { | 88 { |
| 89 TRACE_EVENT0("compositor-worker", "CompositorWorkerGlobalScope::thread"); |
| 71 return static_cast<CompositorWorkerThread*>(WorkerGlobalScope::thread()); | 90 return static_cast<CompositorWorkerThread*>(WorkerGlobalScope::thread()); |
| 72 } | 91 } |
| 73 | 92 |
| 74 } // namespace blink | 93 } // namespace blink |
| OLD | NEW |