OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 11 matching lines...) Expand all Loading... |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "modules/mediasource/SourceBufferList.h" | 32 #include "modules/crypto/KeyOperation.h" |
33 | 33 |
34 #include "core/dom/Event.h" | 34 #include "V8Key.h" // NOTE: This must appear before ScriptPromiseResolver to def
ine toV8() |
35 #include "core/dom/GenericEventQueue.h" | 35 #include "bindings/v8/ScriptPromiseResolver.h" |
36 #include "modules/mediasource/SourceBuffer.h" | 36 #include "core/dom/ExceptionCode.h" |
| 37 #include "modules/crypto/Key.h" |
| 38 #include "public/platform/WebCrypto.h" |
37 | 39 |
38 namespace WebCore { | 40 namespace WebCore { |
39 | 41 |
40 SourceBufferList::SourceBufferList(ScriptExecutionContext* context, GenericEvent
Queue* asyncEventQueue) | 42 KeyOperation::KeyOperation() |
41 : m_scriptExecutionContext(context) | 43 : m_state(Initializing) |
42 , m_asyncEventQueue(asyncEventQueue) | 44 , m_impl(0) |
| 45 , m_exceptionCode(0) |
43 { | 46 { |
44 ScriptWrappable::init(this); | |
45 } | 47 } |
46 | 48 |
47 SourceBufferList::~SourceBufferList() | 49 KeyOperation::~KeyOperation() |
48 { | 50 { |
49 ASSERT(m_list.isEmpty()); | 51 ASSERT(!m_impl); |
50 } | 52 } |
51 | 53 |
52 void SourceBufferList::add(PassRefPtr<SourceBuffer> buffer) | 54 void KeyOperation::initializationFailed() |
53 { | 55 { |
54 m_list.append(buffer); | 56 ASSERT(m_state == Initializing); |
55 scheduleEvent(eventNames().addsourcebufferEvent); | 57 ASSERT(!m_impl); |
| 58 |
| 59 m_exceptionCode = NotSupportedError; |
| 60 m_state = Done; |
56 } | 61 } |
57 | 62 |
58 void SourceBufferList::remove(SourceBuffer* buffer) | 63 void KeyOperation::initializationSucceeded(WebKit::WebCryptoKeyOperation* operat
ionImpl) |
59 { | 64 { |
60 size_t index = m_list.find(buffer); | 65 ASSERT(m_state == Initializing); |
61 if (index == notFound) | 66 ASSERT(operationImpl); |
62 return; | 67 ASSERT(!m_impl); |
63 m_list.remove(index); | 68 |
64 scheduleEvent(eventNames().removesourcebufferEvent); | 69 m_impl = operationImpl; |
| 70 m_state = InProgress; |
65 } | 71 } |
66 | 72 |
67 void SourceBufferList::clear() | 73 void KeyOperation::completeWithError() |
68 { | 74 { |
69 m_list.clear(); | 75 ASSERT(m_state == Initializing || m_state == InProgress); |
70 scheduleEvent(eventNames().removesourcebufferEvent); | 76 |
| 77 m_impl = 0; |
| 78 m_state = Done; |
| 79 |
| 80 promiseResolver()->reject(ScriptValue::createNull()); |
71 } | 81 } |
72 | 82 |
73 void SourceBufferList::scheduleEvent(const AtomicString& eventName) | 83 void KeyOperation::completeWithKey(const WebKit::WebCryptoKey& key) |
74 { | 84 { |
75 ASSERT(m_asyncEventQueue); | 85 ASSERT(m_state == Initializing || m_state == InProgress); |
76 | 86 |
77 RefPtr<Event> event = Event::create(eventName, false, false); | 87 m_impl = 0; |
78 event->setTarget(this); | 88 m_state = Done; |
79 | 89 |
80 m_asyncEventQueue->enqueueEvent(event.release()); | 90 promiseResolver()->fulfill(Key::create(key)); |
81 } | 91 } |
82 | 92 |
83 const AtomicString& SourceBufferList::interfaceName() const | 93 ScriptObject KeyOperation::returnValue(ExceptionCode& ec) |
84 { | 94 { |
85 return eventNames().interfaceForSourceBufferList; | 95 ASSERT(m_state != Initializing); |
| 96 |
| 97 if (m_exceptionCode) { |
| 98 ec = m_exceptionCode; |
| 99 return ScriptObject(); |
| 100 } |
| 101 |
| 102 return promiseResolver()->promise(); |
86 } | 103 } |
87 | 104 |
88 ScriptExecutionContext* SourceBufferList::scriptExecutionContext() const | 105 ScriptPromiseResolver* KeyOperation::promiseResolver() |
89 { | 106 { |
90 return m_scriptExecutionContext; | 107 if (!m_promiseResolver) |
91 } | 108 m_promiseResolver = ScriptPromiseResolver::create(); |
92 | 109 return m_promiseResolver.get(); |
93 EventTargetData* SourceBufferList::eventTargetData() | |
94 { | |
95 return &m_eventTargetData; | |
96 } | |
97 | |
98 EventTargetData* SourceBufferList::ensureEventTargetData() | |
99 { | |
100 return &m_eventTargetData; | |
101 } | 110 } |
102 | 111 |
103 } // namespace WebCore | 112 } // namespace WebCore |
OLD | NEW |