Chromium Code Reviews| Index: Source/core/dom/CompositorProxy.cpp |
| diff --git a/Source/core/dom/CompositorProxy.cpp b/Source/core/dom/CompositorProxy.cpp |
| index 7c346997c79c0e9b869c97a8afd73d2fc85ba667..e4e1e9a7d4108582e8b505b9b078f2fd316d4276 100644 |
| --- a/Source/core/dom/CompositorProxy.cpp |
| +++ b/Source/core/dom/CompositorProxy.cpp |
| @@ -8,6 +8,7 @@ |
| #include "bindings/core/v8/ExceptionMessages.h" |
| #include "bindings/core/v8/ExceptionState.h" |
| #include "core/dom/DOMNodeIds.h" |
| +#include "core/dom/ExceptionCode.h" |
| #include "core/dom/ExecutionContext.h" |
| namespace blink { |
| @@ -46,6 +47,30 @@ static CompositorProxy::Attributes attributeFlagForName(const String& attributeN |
| return attributeFlag; |
| } |
| +static bool isControlThread() |
| +{ |
| + return !isMainThread(); |
| +} |
| + |
| +static bool isCallingCompositorFrameCallback() |
| +{ |
| + // TODO(sad): |
|
esprehn
2015/03/29 04:44:56
TODO what?
sadrul
2015/03/30 16:07:45
Oops. My bad. Done.
|
| + return true; |
| +} |
| + |
| +static bool raiseExceptionIfMutationNotAllowed(ExceptionState& exceptionState) |
| +{ |
| + if (!isControlThread()) { |
| + exceptionState.throwDOMException(NoModificationAllowedError, "Cannot mutate a proxy attribute from the main page."); |
| + return true; |
| + } |
| + if (!isCallingCompositorFrameCallback()) { |
| + exceptionState.throwDOMException(NoModificationAllowedError, "Cannot mutate a proxy attribute outside of a requestCompositorFrame callback."); |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| static uint32_t attributesBitfieldFromNames(const Vector<String>& attributeArray) |
| { |
| uint32_t attributesBitfield = 0; |
| @@ -85,6 +110,7 @@ CompositorProxy* CompositorProxy::create(uint64_t elementId, uint32_t attributeF |
| CompositorProxy::CompositorProxy(Element& element, const Vector<String>& attributeArray) |
| : m_elementId(DOMNodeIds::idForNode(&element)) |
| , m_bitfieldsSupported(attributesBitfieldFromNames(attributeArray)) |
| + , m_mutatedAttributes(0) |
| { |
| ASSERT(isMainThread()); |
| ASSERT(m_bitfieldsSupported); |
| @@ -94,8 +120,9 @@ CompositorProxy::CompositorProxy(Element& element, const Vector<String>& attribu |
| CompositorProxy::CompositorProxy(uint64_t elementId, uint32_t attributeFlags) |
| : m_elementId(elementId) |
| , m_bitfieldsSupported(attributeFlags) |
| + , m_mutatedAttributes(0) |
| { |
| - ASSERT(!isMainThread()); |
| + ASSERT(isControlThread()); |
| ASSERT(sanityCheckAttributeFlags(m_bitfieldsSupported)); |
| } |
| @@ -108,4 +135,88 @@ bool CompositorProxy::supports(const String& attributeName) const |
| return !!(m_bitfieldsSupported & static_cast<uint32_t>(attributeFlagForName(attributeName))); |
| } |
| +double CompositorProxy::opacity(ExceptionState& exceptionState) const |
| +{ |
| + if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
| + return 0.0; |
| + if (raiseExceptionIfNotMutable(Attributes::OPACITY, exceptionState)) |
| + return 0.0; |
| + return m_opacity; |
| +} |
| + |
| +double CompositorProxy::scrollLeft(ExceptionState& exceptionState) const |
| +{ |
| + if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
| + return 0.0; |
| + if (raiseExceptionIfNotMutable(Attributes::SCROLL_LEFT, exceptionState)) |
| + return 0.0; |
| + return m_scrollLeft; |
| +} |
| + |
| +double CompositorProxy::scrollTop(ExceptionState& exceptionState) const |
| +{ |
| + if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
| + return 0.0; |
| + if (raiseExceptionIfNotMutable(Attributes::SCROLL_TOP, exceptionState)) |
| + return 0.0; |
| + return m_scrollTop; |
| +} |
| + |
| +DOMMatrix* CompositorProxy::transform(ExceptionState& exceptionState) const |
| +{ |
| + if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
| + return nullptr; |
| + if (raiseExceptionIfNotMutable(Attributes::TRANSFORM, exceptionState)) |
| + return nullptr; |
| + return m_transform; |
| +} |
| + |
| +void CompositorProxy::setOpacity(double opacity, ExceptionState& exceptionState) |
| +{ |
| + if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
| + return; |
| + if (raiseExceptionIfNotMutable(Attributes::OPACITY, exceptionState)) |
| + return; |
| + 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
|
| + m_mutatedAttributes |= static_cast<uint32_t>(Attributes::OPACITY); |
| +} |
| + |
| +void CompositorProxy::setScrollLeft(double scrollLeft, ExceptionState& exceptionState) |
| +{ |
| + if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
| + return; |
| + if (raiseExceptionIfNotMutable(Attributes::SCROLL_LEFT, exceptionState)) |
| + return; |
| + m_scrollLeft = scrollLeft; |
| + m_mutatedAttributes |= static_cast<uint32_t>(Attributes::SCROLL_LEFT); |
| +} |
| + |
| +void CompositorProxy::setScrollTop(double scrollTop, ExceptionState& exceptionState) |
| +{ |
| + if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
| + return; |
| + if (raiseExceptionIfNotMutable(Attributes::SCROLL_TOP, exceptionState)) |
| + return; |
| + m_scrollTop = scrollTop; |
| + m_mutatedAttributes |= static_cast<uint32_t>(Attributes::SCROLL_TOP); |
| +} |
| + |
| +void CompositorProxy::setTransform(DOMMatrix* transform, ExceptionState& exceptionState) |
| +{ |
| + if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
| + return; |
| + if (raiseExceptionIfNotMutable(Attributes::TRANSFORM, exceptionState)) |
| + return; |
| + m_transform = transform; |
| + m_mutatedAttributes |= static_cast<uint32_t>(Attributes::TRANSFORM); |
| +} |
| + |
| +bool CompositorProxy::raiseExceptionIfNotMutable(Attributes attribute, ExceptionState& exceptionState) const |
| +{ |
| + if (m_bitfieldsSupported & static_cast<uint32_t>(attribute)) |
| + return false; |
| + exceptionState.throwDOMException(NoModificationAllowedError, "Attempted to mutate non-mutable attribute."); |
| + return true; |
| +} |
| + |
| } // namespace blink |