OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Apple Inc. All rights reserved. | 2 * Copyright (C) 2013 Apple 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 | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 30 matching lines...) Expand all Loading... |
41 { | 41 { |
42 return adoptRef(new MediaKeySession(context, cdm, keys)); | 42 return adoptRef(new MediaKeySession(context, cdm, keys)); |
43 } | 43 } |
44 | 44 |
45 MediaKeySession::MediaKeySession(ExecutionContext* context, ContentDecryptionMod
ule* cdm, MediaKeys* keys) | 45 MediaKeySession::MediaKeySession(ExecutionContext* context, ContentDecryptionMod
ule* cdm, MediaKeys* keys) |
46 : ContextLifecycleObserver(context) | 46 : ContextLifecycleObserver(context) |
47 , m_keySystem(keys->keySystem()) | 47 , m_keySystem(keys->keySystem()) |
48 , m_asyncEventQueue(GenericEventQueue::create(this)) | 48 , m_asyncEventQueue(GenericEventQueue::create(this)) |
49 , m_session(cdm->createSession(this)) | 49 , m_session(cdm->createSession(this)) |
50 , m_keys(keys) | 50 , m_keys(keys) |
51 , m_initializeNewSessionTimer(this, &MediaKeySession::initializeNewSessionTi
merFired) | |
52 , m_updateTimer(this, &MediaKeySession::updateTimerFired) | 51 , m_updateTimer(this, &MediaKeySession::updateTimerFired) |
53 { | 52 { |
54 ScriptWrappable::init(this); | 53 ScriptWrappable::init(this); |
55 ASSERT(m_session); | 54 ASSERT(m_session); |
56 } | 55 } |
57 | 56 |
58 MediaKeySession::~MediaKeySession() | 57 MediaKeySession::~MediaKeySession() |
59 { | 58 { |
60 m_session.clear(); | 59 m_session.clear(); |
61 m_asyncEventQueue->cancelAllEvents(); | 60 m_asyncEventQueue->cancelAllEvents(); |
(...skipping 11 matching lines...) Expand all Loading... |
73 void MediaKeySession::release(ExceptionState& exceptionState) | 72 void MediaKeySession::release(ExceptionState& exceptionState) |
74 { | 73 { |
75 m_session->release(); | 74 m_session->release(); |
76 } | 75 } |
77 | 76 |
78 String MediaKeySession::sessionId() const | 77 String MediaKeySession::sessionId() const |
79 { | 78 { |
80 return m_session->sessionId(); | 79 return m_session->sessionId(); |
81 } | 80 } |
82 | 81 |
83 void MediaKeySession::initializeNewSession(const String& mimeType, Uint8Array* i
nitData) | 82 void MediaKeySession::initializeNewSession(const String& mimeType, const Uint8Ar
ray& initData) |
84 { | 83 { |
85 m_pendingInitializeNewSessionData.append(InitializeNewSessionData(mimeType,
initData)); | 84 m_session->initializeNewSession(mimeType, initData); |
86 m_initializeNewSessionTimer.startOneShot(0); | |
87 } | |
88 | |
89 void MediaKeySession::initializeNewSessionTimerFired(Timer<MediaKeySession>*) | |
90 { | |
91 ASSERT(m_pendingInitializeNewSessionData.size()); | |
92 | |
93 while (!m_pendingInitializeNewSessionData.isEmpty()) { | |
94 InitializeNewSessionData data = m_pendingInitializeNewSessionData.takeFi
rst(); | |
95 // FIXME: Refer to the spec to see what needs to be done in blink. | |
96 m_session->initializeNewSession(data.mimeType, *data.initData); | |
97 } | |
98 } | 85 } |
99 | 86 |
100 void MediaKeySession::update(Uint8Array* response, ExceptionState& exceptionStat
e) | 87 void MediaKeySession::update(Uint8Array* response, ExceptionState& exceptionStat
e) |
101 { | 88 { |
102 // From <https://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/
encrypted-media.html#dom-update>: | 89 // From <https://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/
encrypted-media.html#dom-update>: |
103 // The update(response) method must run the following steps: | 90 // The update(response) method must run the following steps: |
104 // 1. If the argument is null or an empty array, throw an INVALID_ACCESS_ERR
. | 91 // 1. If the argument is null or an empty array, throw an INVALID_ACCESS_ERR
. |
105 if (!response || !response->length()) { | 92 if (!response || !response->length()) { |
106 exceptionState.throwDOMException(InvalidAccessError, String::format("The
response argument provided is %s.", response ? "an empty array" : "invalid")); | 93 exceptionState.throwDOMException(InvalidAccessError, String::format("The
response argument provided is %s.", response ? "an empty array" : "invalid")); |
107 return; | 94 return; |
108 } | 95 } |
109 | 96 |
110 // 2. If the session is not in the PENDING state, throw an INVALID_STATE_ERR
. | 97 // 2. If the session is not in the PENDING state, throw an INVALID_STATE_ERR
. |
111 // FIXME: Implement states in MediaKeySession. | 98 // FIXME: Implement states in MediaKeySession. |
112 | 99 |
113 // 3. Schedule a task to handle the call, providing response. | 100 // 3. Schedule a task to handle the call, providing response. |
114 m_pendingKeys.append(response); | 101 m_pendingKeys.append(response); |
115 m_updateTimer.startOneShot(0); | 102 |
| 103 if (!m_updateTimer.isActive()) |
| 104 m_updateTimer.startOneShot(0); |
116 } | 105 } |
117 | 106 |
118 void MediaKeySession::updateTimerFired(Timer<MediaKeySession>*) | 107 void MediaKeySession::updateTimerFired(Timer<MediaKeySession>*) |
119 { | 108 { |
120 ASSERT(m_pendingKeys.size()); | 109 ASSERT(m_pendingKeys.size()); |
121 | 110 |
122 while (!m_pendingKeys.isEmpty()) { | 111 while (!m_pendingKeys.isEmpty()) { |
123 RefPtr<Uint8Array> pendingKey = m_pendingKeys.takeFirst(); | 112 RefPtr<Uint8Array> pendingKey = m_pendingKeys.takeFirst(); |
124 | 113 |
125 // NOTE: Continued from step 2. of MediaKeySession::update() | 114 // NOTE: Continued from step 2. of MediaKeySession::update() |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 { | 171 { |
183 return EventTargetNames::MediaKeySession; | 172 return EventTargetNames::MediaKeySession; |
184 } | 173 } |
185 | 174 |
186 ExecutionContext* MediaKeySession::executionContext() const | 175 ExecutionContext* MediaKeySession::executionContext() const |
187 { | 176 { |
188 return ContextLifecycleObserver::executionContext(); | 177 return ContextLifecycleObserver::executionContext(); |
189 } | 178 } |
190 | 179 |
191 } | 180 } |
OLD | NEW |