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/ExecutionContext.h" | 12 #include "core/dom/ExecutionContext.h" |
12 | 13 |
13 namespace blink { | 14 namespace blink { |
14 | 15 |
15 struct AttributeFlagMapping { | 16 struct AttributeFlagMapping { |
16 const char* name; | 17 const char* name; |
17 unsigned length; | 18 unsigned length; |
18 CompositorProxy::Attributes attribute; | 19 CompositorProxy::Attributes attribute; |
19 }; | 20 }; |
20 | 21 |
(...skipping 18 matching lines...) Expand all Loading... | |
39 const AttributeFlagMapping* start = allowedAttributes; | 40 const AttributeFlagMapping* start = allowedAttributes; |
40 const AttributeFlagMapping* end = allowedAttributes + WTF_ARRAY_LENGTH(allow edAttributes); | 41 const AttributeFlagMapping* end = allowedAttributes + WTF_ARRAY_LENGTH(allow edAttributes); |
41 if (attributeLower.impl()->is8Bit()) { | 42 if (attributeLower.impl()->is8Bit()) { |
42 const AttributeFlagMapping* match = std::lower_bound(start, end, attribu teLower.impl(), CompareAttributeName); | 43 const AttributeFlagMapping* match = std::lower_bound(start, end, attribu teLower.impl(), CompareAttributeName); |
43 if (match != end) | 44 if (match != end) |
44 attributeFlag = match->attribute; | 45 attributeFlag = match->attribute; |
45 } | 46 } |
46 return attributeFlag; | 47 return attributeFlag; |
47 } | 48 } |
48 | 49 |
50 static bool isControlThread() | |
51 { | |
52 return !isMainThread(); | |
53 } | |
54 | |
55 static bool isCallingCompositorFrameCallback() | |
56 { | |
57 // TODO(sad): | |
esprehn
2015/03/29 04:44:56
TODO what?
sadrul
2015/03/30 16:07:45
Oops. My bad. Done.
| |
58 return true; | |
59 } | |
60 | |
61 static bool raiseExceptionIfMutationNotAllowed(ExceptionState& exceptionState) | |
62 { | |
63 if (!isControlThread()) { | |
64 exceptionState.throwDOMException(NoModificationAllowedError, "Cannot mut ate a proxy attribute from the main page."); | |
65 return true; | |
66 } | |
67 if (!isCallingCompositorFrameCallback()) { | |
68 exceptionState.throwDOMException(NoModificationAllowedError, "Cannot mut ate a proxy attribute outside of a requestCompositorFrame callback."); | |
69 return true; | |
70 } | |
71 return false; | |
72 } | |
73 | |
49 static uint32_t attributesBitfieldFromNames(const Vector<String>& attributeArray ) | 74 static uint32_t attributesBitfieldFromNames(const Vector<String>& attributeArray ) |
50 { | 75 { |
51 uint32_t attributesBitfield = 0; | 76 uint32_t attributesBitfield = 0; |
52 for (const auto& attribute : attributeArray) { | 77 for (const auto& attribute : attributeArray) { |
53 attributesBitfield |= static_cast<uint32_t>(attributeFlagForName(attribu te)); | 78 attributesBitfield |= static_cast<uint32_t>(attributeFlagForName(attribu te)); |
54 } | 79 } |
55 return attributesBitfield; | 80 return attributesBitfield; |
56 } | 81 } |
57 | 82 |
58 #if ENABLE(ASSERT) | 83 #if ENABLE(ASSERT) |
(...skipping 19 matching lines...) Expand all Loading... | |
78 } | 103 } |
79 | 104 |
80 CompositorProxy* CompositorProxy::create(uint64_t elementId, uint32_t attributeF lags) | 105 CompositorProxy* CompositorProxy::create(uint64_t elementId, uint32_t attributeF lags) |
81 { | 106 { |
82 return new CompositorProxy(elementId, attributeFlags); | 107 return new CompositorProxy(elementId, attributeFlags); |
83 } | 108 } |
84 | 109 |
85 CompositorProxy::CompositorProxy(Element& element, const Vector<String>& attribu teArray) | 110 CompositorProxy::CompositorProxy(Element& element, const Vector<String>& attribu teArray) |
86 : m_elementId(DOMNodeIds::idForNode(&element)) | 111 : m_elementId(DOMNodeIds::idForNode(&element)) |
87 , m_bitfieldsSupported(attributesBitfieldFromNames(attributeArray)) | 112 , m_bitfieldsSupported(attributesBitfieldFromNames(attributeArray)) |
113 , m_mutatedAttributes(0) | |
88 { | 114 { |
89 ASSERT(isMainThread()); | 115 ASSERT(isMainThread()); |
90 ASSERT(m_bitfieldsSupported); | 116 ASSERT(m_bitfieldsSupported); |
91 ASSERT(sanityCheckAttributeFlags(m_bitfieldsSupported)); | 117 ASSERT(sanityCheckAttributeFlags(m_bitfieldsSupported)); |
92 } | 118 } |
93 | 119 |
94 CompositorProxy::CompositorProxy(uint64_t elementId, uint32_t attributeFlags) | 120 CompositorProxy::CompositorProxy(uint64_t elementId, uint32_t attributeFlags) |
95 : m_elementId(elementId) | 121 : m_elementId(elementId) |
96 , m_bitfieldsSupported(attributeFlags) | 122 , m_bitfieldsSupported(attributeFlags) |
123 , m_mutatedAttributes(0) | |
97 { | 124 { |
98 ASSERT(!isMainThread()); | 125 ASSERT(isControlThread()); |
99 ASSERT(sanityCheckAttributeFlags(m_bitfieldsSupported)); | 126 ASSERT(sanityCheckAttributeFlags(m_bitfieldsSupported)); |
100 } | 127 } |
101 | 128 |
102 CompositorProxy::~CompositorProxy() | 129 CompositorProxy::~CompositorProxy() |
103 { | 130 { |
104 } | 131 } |
105 | 132 |
106 bool CompositorProxy::supports(const String& attributeName) const | 133 bool CompositorProxy::supports(const String& attributeName) const |
107 { | 134 { |
108 return !!(m_bitfieldsSupported & static_cast<uint32_t>(attributeFlagForName( attributeName))); | 135 return !!(m_bitfieldsSupported & static_cast<uint32_t>(attributeFlagForName( attributeName))); |
109 } | 136 } |
110 | 137 |
138 double CompositorProxy::opacity(ExceptionState& exceptionState) const | |
139 { | |
140 if (raiseExceptionIfMutationNotAllowed(exceptionState)) | |
141 return 0.0; | |
142 if (raiseExceptionIfNotMutable(Attributes::OPACITY, exceptionState)) | |
143 return 0.0; | |
144 return m_opacity; | |
145 } | |
146 | |
147 double CompositorProxy::scrollLeft(ExceptionState& exceptionState) const | |
148 { | |
149 if (raiseExceptionIfMutationNotAllowed(exceptionState)) | |
150 return 0.0; | |
151 if (raiseExceptionIfNotMutable(Attributes::SCROLL_LEFT, exceptionState)) | |
152 return 0.0; | |
153 return m_scrollLeft; | |
154 } | |
155 | |
156 double CompositorProxy::scrollTop(ExceptionState& exceptionState) const | |
157 { | |
158 if (raiseExceptionIfMutationNotAllowed(exceptionState)) | |
159 return 0.0; | |
160 if (raiseExceptionIfNotMutable(Attributes::SCROLL_TOP, exceptionState)) | |
161 return 0.0; | |
162 return m_scrollTop; | |
163 } | |
164 | |
165 DOMMatrix* CompositorProxy::transform(ExceptionState& exceptionState) const | |
166 { | |
167 if (raiseExceptionIfMutationNotAllowed(exceptionState)) | |
168 return nullptr; | |
169 if (raiseExceptionIfNotMutable(Attributes::TRANSFORM, exceptionState)) | |
170 return nullptr; | |
171 return m_transform; | |
172 } | |
173 | |
174 void CompositorProxy::setOpacity(double opacity, ExceptionState& exceptionState) | |
175 { | |
176 if (raiseExceptionIfMutationNotAllowed(exceptionState)) | |
177 return; | |
178 if (raiseExceptionIfNotMutable(Attributes::OPACITY, exceptionState)) | |
179 return; | |
180 m_opacity = opacity; | |
esprehn
2015/03/29 04:44:56
opacity must be positive, you probably want to jus
sadrul
2015/03/30 16:07:45
Looks like setting style.opacity on an element in
| |
181 m_mutatedAttributes |= static_cast<uint32_t>(Attributes::OPACITY); | |
182 } | |
183 | |
184 void CompositorProxy::setScrollLeft(double scrollLeft, ExceptionState& exception State) | |
185 { | |
186 if (raiseExceptionIfMutationNotAllowed(exceptionState)) | |
187 return; | |
188 if (raiseExceptionIfNotMutable(Attributes::SCROLL_LEFT, exceptionState)) | |
189 return; | |
190 m_scrollLeft = scrollLeft; | |
191 m_mutatedAttributes |= static_cast<uint32_t>(Attributes::SCROLL_LEFT); | |
192 } | |
193 | |
194 void CompositorProxy::setScrollTop(double scrollTop, ExceptionState& exceptionSt ate) | |
195 { | |
196 if (raiseExceptionIfMutationNotAllowed(exceptionState)) | |
197 return; | |
198 if (raiseExceptionIfNotMutable(Attributes::SCROLL_TOP, exceptionState)) | |
199 return; | |
200 m_scrollTop = scrollTop; | |
201 m_mutatedAttributes |= static_cast<uint32_t>(Attributes::SCROLL_TOP); | |
202 } | |
203 | |
204 void CompositorProxy::setTransform(DOMMatrix* transform, ExceptionState& excepti onState) | |
205 { | |
206 if (raiseExceptionIfMutationNotAllowed(exceptionState)) | |
207 return; | |
208 if (raiseExceptionIfNotMutable(Attributes::TRANSFORM, exceptionState)) | |
209 return; | |
210 m_transform = transform; | |
211 m_mutatedAttributes |= static_cast<uint32_t>(Attributes::TRANSFORM); | |
212 } | |
213 | |
214 bool CompositorProxy::raiseExceptionIfNotMutable(Attributes attribute, Exception State& exceptionState) const | |
215 { | |
216 if (m_bitfieldsSupported & static_cast<uint32_t>(attribute)) | |
217 return false; | |
218 exceptionState.throwDOMException(NoModificationAllowedError, "Attempted to m utate non-mutable attribute."); | |
219 return true; | |
220 } | |
221 | |
111 } // namespace blink | 222 } // namespace blink |
OLD | NEW |