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 "core/dom/CompositorProxy.h" | 6 #include "core/dom/CompositorProxy.h" |
7 | 7 |
8 #include "bindings/core/v8/ExceptionMessages.h" | 8 #include "bindings/core/v8/ExceptionMessages.h" |
9 #include "bindings/core/v8/ExceptionState.h" | 9 #include "bindings/core/v8/ExceptionState.h" |
10 #include "core/dom/DOMNodeIds.h" | 10 #include "core/dom/DOMNodeIds.h" |
11 #include "core/dom/ExceptionCode.h" | 11 #include "core/dom/ExceptionCode.h" |
12 #include "core/dom/ExecutionContext.h" | 12 #include "core/dom/ExecutionContext.h" |
| 13 #include "public/platform/Platform.h" |
| 14 #include "public/platform/WebTraceLocation.h" |
13 | 15 |
14 namespace blink { | 16 namespace blink { |
15 | 17 |
16 struct AttributeFlagMapping { | 18 struct AttributeFlagMapping { |
17 const char* name; | 19 const char* name; |
18 unsigned length; | 20 unsigned length; |
19 CompositorProxy::Attributes attribute; | 21 CompositorProxy::Attributes attribute; |
20 }; | 22 }; |
21 | 23 |
22 static AttributeFlagMapping allowedAttributes[] = { | 24 static AttributeFlagMapping allowedAttributes[] = { |
(...skipping 28 matching lines...) Expand all Loading... |
51 { | 53 { |
52 return !isMainThread(); | 54 return !isMainThread(); |
53 } | 55 } |
54 | 56 |
55 static bool isCallingCompositorFrameCallback() | 57 static bool isCallingCompositorFrameCallback() |
56 { | 58 { |
57 // TODO(sad): Check that the requestCompositorFrame callbacks are currently
being called. | 59 // TODO(sad): Check that the requestCompositorFrame callbacks are currently
being called. |
58 return true; | 60 return true; |
59 } | 61 } |
60 | 62 |
| 63 static void decrementCountForElement(uint64_t elementId) |
| 64 { |
| 65 ASSERT(isMainThread()); |
| 66 Node* node = DOMNodeIds::nodeForId(elementId); |
| 67 if (!node) |
| 68 return; |
| 69 Element* element = toElement(node); |
| 70 element->decrementProxyCount(); |
| 71 } |
| 72 |
| 73 static void incrementProxyCountForElement(uint64_t elementId) |
| 74 { |
| 75 ASSERT(isMainThread()); |
| 76 Node* node = DOMNodeIds::nodeForId(elementId); |
| 77 if (!node) |
| 78 return; |
| 79 Element* element = toElement(node); |
| 80 element->incrementProxyCount(); |
| 81 } |
| 82 |
61 static bool raiseExceptionIfMutationNotAllowed(ExceptionState& exceptionState) | 83 static bool raiseExceptionIfMutationNotAllowed(ExceptionState& exceptionState) |
62 { | 84 { |
63 if (!isControlThread()) { | 85 if (!isControlThread()) { |
64 exceptionState.throwDOMException(NoModificationAllowedError, "Cannot mut
ate a proxy attribute from the main page."); | 86 exceptionState.throwDOMException(NoModificationAllowedError, "Cannot mut
ate a proxy attribute from the main page."); |
65 return true; | 87 return true; |
66 } | 88 } |
67 if (!isCallingCompositorFrameCallback()) { | 89 if (!isCallingCompositorFrameCallback()) { |
68 exceptionState.throwDOMException(NoModificationAllowedError, "Cannot mut
ate a proxy attribute outside of a requestCompositorFrame callback."); | 90 exceptionState.throwDOMException(NoModificationAllowedError, "Cannot mut
ate a proxy attribute outside of a requestCompositorFrame callback."); |
69 return true; | 91 return true; |
70 } | 92 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 return new CompositorProxy(elementId, attributeFlags); | 129 return new CompositorProxy(elementId, attributeFlags); |
108 } | 130 } |
109 | 131 |
110 CompositorProxy::CompositorProxy(Element& element, const Vector<String>& attribu
teArray) | 132 CompositorProxy::CompositorProxy(Element& element, const Vector<String>& attribu
teArray) |
111 : m_elementId(DOMNodeIds::idForNode(&element)) | 133 : m_elementId(DOMNodeIds::idForNode(&element)) |
112 , m_bitfieldsSupported(attributesBitfieldFromNames(attributeArray)) | 134 , m_bitfieldsSupported(attributesBitfieldFromNames(attributeArray)) |
113 { | 135 { |
114 ASSERT(isMainThread()); | 136 ASSERT(isMainThread()); |
115 ASSERT(m_bitfieldsSupported); | 137 ASSERT(m_bitfieldsSupported); |
116 ASSERT(sanityCheckAttributeFlags(m_bitfieldsSupported)); | 138 ASSERT(sanityCheckAttributeFlags(m_bitfieldsSupported)); |
| 139 |
| 140 incrementProxyCountForElement(m_elementId); |
117 } | 141 } |
118 | 142 |
119 CompositorProxy::CompositorProxy(uint64_t elementId, uint32_t attributeFlags) | 143 CompositorProxy::CompositorProxy(uint64_t elementId, uint32_t attributeFlags) |
120 : m_elementId(elementId) | 144 : m_elementId(elementId) |
121 , m_bitfieldsSupported(attributeFlags) | 145 , m_bitfieldsSupported(attributeFlags) |
122 { | 146 { |
123 ASSERT(isControlThread()); | 147 ASSERT(isControlThread()); |
124 ASSERT(sanityCheckAttributeFlags(m_bitfieldsSupported)); | 148 ASSERT(sanityCheckAttributeFlags(m_bitfieldsSupported)); |
| 149 Platform::current()->mainThread()->postTask(FROM_HERE, bind(&incrementProxyC
ountForElement, m_elementId)); |
125 } | 150 } |
126 | 151 |
127 CompositorProxy::~CompositorProxy() | 152 CompositorProxy::~CompositorProxy() |
128 { | 153 { |
| 154 if (m_connected) |
| 155 disconnect(); |
129 } | 156 } |
130 | 157 |
131 bool CompositorProxy::supports(const String& attributeName) const | 158 bool CompositorProxy::supports(const String& attributeName) const |
132 { | 159 { |
133 return !!(m_bitfieldsSupported & static_cast<uint32_t>(attributeFlagForName(
attributeName))); | 160 return !!(m_bitfieldsSupported & static_cast<uint32_t>(attributeFlagForName(
attributeName))); |
134 } | 161 } |
135 | 162 |
136 double CompositorProxy::opacity(ExceptionState& exceptionState) const | 163 double CompositorProxy::opacity(ExceptionState& exceptionState) const |
137 { | 164 { |
138 if (raiseExceptionIfMutationNotAllowed(exceptionState)) | 165 if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 if (raiseExceptionIfMutationNotAllowed(exceptionState)) | 231 if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
205 return; | 232 return; |
206 if (raiseExceptionIfNotMutable(Attributes::TRANSFORM, exceptionState)) | 233 if (raiseExceptionIfNotMutable(Attributes::TRANSFORM, exceptionState)) |
207 return; | 234 return; |
208 m_transform = transform; | 235 m_transform = transform; |
209 m_mutatedAttributes |= static_cast<uint32_t>(Attributes::TRANSFORM); | 236 m_mutatedAttributes |= static_cast<uint32_t>(Attributes::TRANSFORM); |
210 } | 237 } |
211 | 238 |
212 bool CompositorProxy::raiseExceptionIfNotMutable(Attributes attribute, Exception
State& exceptionState) const | 239 bool CompositorProxy::raiseExceptionIfNotMutable(Attributes attribute, Exception
State& exceptionState) const |
213 { | 240 { |
214 if (m_bitfieldsSupported & static_cast<uint32_t>(attribute)) | 241 if (m_connected && (m_bitfieldsSupported & static_cast<uint32_t>(attribute))
) |
215 return false; | 242 return false; |
216 exceptionState.throwDOMException(NoModificationAllowedError, "Attempted to m
utate non-mutable attribute."); | 243 exceptionState.throwDOMException(NoModificationAllowedError, |
| 244 m_connected ? "Attempted to mutate non-mutable attribute." : "Attempted
to mutate attribute on a disconnected proxy."); |
217 return true; | 245 return true; |
218 } | 246 } |
219 | 247 |
| 248 void CompositorProxy::disconnect() |
| 249 { |
| 250 m_connected = false; |
| 251 if (isMainThread()) |
| 252 decrementCountForElement(m_elementId); |
| 253 else |
| 254 Platform::current()->mainThread()->postTask(FROM_HERE, bind(&decrementCo
untForElement, m_elementId)); |
| 255 } |
| 256 |
220 } // namespace blink | 257 } // namespace blink |
OLD | NEW |