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