| Index: Source/modules/crypto/KeyOperation.cpp
|
| diff --git a/Source/modules/mediasource/SourceBufferList.cpp b/Source/modules/crypto/KeyOperation.cpp
|
| similarity index 51%
|
| copy from Source/modules/mediasource/SourceBufferList.cpp
|
| copy to Source/modules/crypto/KeyOperation.cpp
|
| index ee0aa7d79cef3308e52d427dae44bc67381bd7ce..280c4be989d27378536ea879dd8e22568f817e0a 100644
|
| --- a/Source/modules/mediasource/SourceBufferList.cpp
|
| +++ b/Source/modules/crypto/KeyOperation.cpp
|
| @@ -29,75 +29,84 @@
|
| */
|
|
|
| #include "config.h"
|
| -#include "modules/mediasource/SourceBufferList.h"
|
| +#include "modules/crypto/KeyOperation.h"
|
|
|
| -#include "core/dom/Event.h"
|
| -#include "core/dom/GenericEventQueue.h"
|
| -#include "modules/mediasource/SourceBuffer.h"
|
| +#include "V8Key.h" // NOTE: This must appear before ScriptPromiseResolver to define toV8()
|
| +#include "bindings/v8/ScriptPromiseResolver.h"
|
| +#include "core/dom/ExceptionCode.h"
|
| +#include "modules/crypto/Key.h"
|
| +#include "public/platform/WebCrypto.h"
|
|
|
| namespace WebCore {
|
|
|
| -SourceBufferList::SourceBufferList(ScriptExecutionContext* context, GenericEventQueue* asyncEventQueue)
|
| - : m_scriptExecutionContext(context)
|
| - , m_asyncEventQueue(asyncEventQueue)
|
| +KeyOperation::KeyOperation()
|
| + : m_state(Initializing)
|
| + , m_impl(0)
|
| + , m_exceptionCode(0)
|
| {
|
| - ScriptWrappable::init(this);
|
| }
|
|
|
| -SourceBufferList::~SourceBufferList()
|
| +KeyOperation::~KeyOperation()
|
| {
|
| - ASSERT(m_list.isEmpty());
|
| + ASSERT(!m_impl);
|
| }
|
|
|
| -void SourceBufferList::add(PassRefPtr<SourceBuffer> buffer)
|
| +void KeyOperation::initializationFailed()
|
| {
|
| - m_list.append(buffer);
|
| - scheduleEvent(eventNames().addsourcebufferEvent);
|
| -}
|
| + ASSERT(m_state == Initializing);
|
| + ASSERT(!m_impl);
|
|
|
| -void SourceBufferList::remove(SourceBuffer* buffer)
|
| -{
|
| - size_t index = m_list.find(buffer);
|
| - if (index == notFound)
|
| - return;
|
| - m_list.remove(index);
|
| - scheduleEvent(eventNames().removesourcebufferEvent);
|
| + m_exceptionCode = NotSupportedError;
|
| + m_state = Done;
|
| }
|
|
|
| -void SourceBufferList::clear()
|
| +void KeyOperation::initializationSucceeded(WebKit::WebCryptoKeyOperation* operationImpl)
|
| {
|
| - m_list.clear();
|
| - scheduleEvent(eventNames().removesourcebufferEvent);
|
| + ASSERT(m_state == Initializing);
|
| + ASSERT(operationImpl);
|
| + ASSERT(!m_impl);
|
| +
|
| + m_impl = operationImpl;
|
| + m_state = InProgress;
|
| }
|
|
|
| -void SourceBufferList::scheduleEvent(const AtomicString& eventName)
|
| +void KeyOperation::completeWithError()
|
| {
|
| - ASSERT(m_asyncEventQueue);
|
| + ASSERT(m_state == Initializing || m_state == InProgress);
|
|
|
| - RefPtr<Event> event = Event::create(eventName, false, false);
|
| - event->setTarget(this);
|
| + m_impl = 0;
|
| + m_state = Done;
|
|
|
| - m_asyncEventQueue->enqueueEvent(event.release());
|
| + promiseResolver()->reject(ScriptValue::createNull());
|
| }
|
|
|
| -const AtomicString& SourceBufferList::interfaceName() const
|
| +void KeyOperation::completeWithKey(const WebKit::WebCryptoKey& key)
|
| {
|
| - return eventNames().interfaceForSourceBufferList;
|
| -}
|
| + ASSERT(m_state == Initializing || m_state == InProgress);
|
|
|
| -ScriptExecutionContext* SourceBufferList::scriptExecutionContext() const
|
| -{
|
| - return m_scriptExecutionContext;
|
| + m_impl = 0;
|
| + m_state = Done;
|
| +
|
| + promiseResolver()->fulfill(Key::create(key));
|
| }
|
|
|
| -EventTargetData* SourceBufferList::eventTargetData()
|
| +ScriptObject KeyOperation::returnValue(ExceptionCode& ec)
|
| {
|
| - return &m_eventTargetData;
|
| + ASSERT(m_state != Initializing);
|
| +
|
| + if (m_exceptionCode) {
|
| + ec = m_exceptionCode;
|
| + return ScriptObject();
|
| + }
|
| +
|
| + return promiseResolver()->promise();
|
| }
|
|
|
| -EventTargetData* SourceBufferList::ensureEventTargetData()
|
| +ScriptPromiseResolver* KeyOperation::promiseResolver()
|
| {
|
| - return &m_eventTargetData;
|
| + if (!m_promiseResolver)
|
| + m_promiseResolver = ScriptPromiseResolver::create();
|
| + return m_promiseResolver.get();
|
| }
|
|
|
| } // namespace WebCore
|
|
|