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_keyRequestTimer(this, &MediaKeySession::keyRequestTimerFired) | 51 , m_initializeNewSessionTimer(this, &MediaKeySession::initializeNewSessionTi
merFired) |
52 , m_updateTimer(this, &MediaKeySession::updateTimerFired) | 52 , m_updateTimer(this, &MediaKeySession::updateTimerFired) |
53 { | 53 { |
54 ScriptWrappable::init(this); | 54 ScriptWrappable::init(this); |
| 55 ASSERT(m_session); |
55 } | 56 } |
56 | 57 |
57 MediaKeySession::~MediaKeySession() | 58 MediaKeySession::~MediaKeySession() |
58 { | 59 { |
59 close(); | 60 m_session.clear(); |
| 61 m_asyncEventQueue->cancelAllEvents(); |
| 62 |
| 63 // FIXME: Release ref that MediaKeys has by removing it from m_sessions. |
| 64 // if (m_keys) m_keys->sessionClosed(this); |
| 65 m_keys = 0; |
60 } | 66 } |
61 | 67 |
62 void MediaKeySession::setError(MediaKeyError* error) | 68 void MediaKeySession::setError(MediaKeyError* error) |
63 { | 69 { |
64 m_error = error; | 70 m_error = error; |
65 } | 71 } |
66 | 72 |
67 void MediaKeySession::close() | 73 void MediaKeySession::release(ExceptionState& exceptionState) |
68 { | 74 { |
69 ASSERT(!m_keys == !m_session); | 75 m_session->release(); |
70 | |
71 if (m_session) | |
72 m_session->close(); | |
73 m_session.clear(); | |
74 m_asyncEventQueue->cancelAllEvents(); | |
75 | |
76 // FIXME: Release ref that MediaKeys has by removing it from m_sessions. | |
77 // if (m_keys) m_keys->sessionClosed(this); | |
78 m_keys = 0; | |
79 } | 76 } |
80 | 77 |
81 String MediaKeySession::sessionId() const | 78 String MediaKeySession::sessionId() const |
82 { | 79 { |
83 return m_session->sessionId(); | 80 return m_session->sessionId(); |
84 } | 81 } |
85 | 82 |
86 void MediaKeySession::generateKeyRequest(const String& mimeType, Uint8Array* ini
tData) | 83 void MediaKeySession::initializeNewSession(const String& mimeType, Uint8Array* i
nitData) |
87 { | 84 { |
88 m_pendingKeyRequests.append(PendingKeyRequest(mimeType, initData)); | 85 m_pendingInitializeNewSessionData.append(InitializeNewSessionData(mimeType,
initData)); |
89 // FIXME: Eliminate timers. Asynchronicity will be handled in Chromium. | 86 m_initializeNewSessionTimer.startOneShot(0); |
90 m_keyRequestTimer.startOneShot(0); | |
91 } | 87 } |
92 | 88 |
93 void MediaKeySession::keyRequestTimerFired(Timer<MediaKeySession>*) | 89 void MediaKeySession::initializeNewSessionTimerFired(Timer<MediaKeySession>*) |
94 { | 90 { |
95 ASSERT(m_pendingKeyRequests.size()); | 91 ASSERT(m_pendingInitializeNewSessionData.size()); |
96 if (!m_session) | |
97 return; | |
98 | 92 |
99 while (!m_pendingKeyRequests.isEmpty()) { | 93 while (!m_pendingInitializeNewSessionData.isEmpty()) { |
100 PendingKeyRequest request = m_pendingKeyRequests.takeFirst(); | 94 InitializeNewSessionData data = m_pendingInitializeNewSessionData.takeFi
rst(); |
101 | 95 // FIXME: Refer to the spec to see what needs to be done in blink. |
102 // NOTE: Continued from step 5 in MediaKeys::createSession(). | 96 m_session->initializeNewSession(data.mimeType, *data.initData); |
103 // The user agent will asynchronously execute the following steps in the
task: | |
104 | |
105 // 1. Let cdm be the cdm loaded in the MediaKeys constructor. | |
106 // 2. Let destinationURL be null. | |
107 | |
108 // 3. Use cdm to generate a key request and follow the steps for the fir
st matching condition from the following list: | |
109 m_session->generateKeyRequest(request.mimeType, *request.initData); | |
110 } | 97 } |
111 } | 98 } |
112 | 99 |
113 void MediaKeySession::update(Uint8Array* response, ExceptionState& exceptionStat
e) | 100 void MediaKeySession::update(Uint8Array* response, ExceptionState& exceptionStat
e) |
114 { | 101 { |
115 // From <https://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/
encrypted-media.html#dom-update>: | 102 // From <https://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/
encrypted-media.html#dom-update>: |
116 // The update(response) method must run the following steps: | 103 // The update(response) method must run the following steps: |
117 // 1. If the argument is null or an empty array, throw an INVALID_ACCESS_ERR
. | 104 // 1. If the argument is null or an empty array, throw an INVALID_ACCESS_ERR
. |
118 if (!response || !response->length()) { | 105 if (!response || !response->length()) { |
119 exceptionState.throwDOMException(InvalidAccessError, String::format("The
response argument provided is %s.", response ? "an empty array" : "invalid")); | 106 exceptionState.throwDOMException(InvalidAccessError, String::format("The
response argument provided is %s.", response ? "an empty array" : "invalid")); |
120 return; | 107 return; |
121 } | 108 } |
122 | 109 |
123 // 2. If the session is not in the PENDING state, throw an INVALID_STATE_ERR
. | 110 // 2. If the session is not in the PENDING state, throw an INVALID_STATE_ERR
. |
124 // FIXME: Implement states in MediaKeySession. | 111 // FIXME: Implement states in MediaKeySession. |
125 | 112 |
126 // 3. Schedule a task to handle the call, providing response. | 113 // 3. Schedule a task to handle the call, providing response. |
127 m_pendingKeys.append(response); | 114 m_pendingKeys.append(response); |
128 m_updateTimer.startOneShot(0); | 115 m_updateTimer.startOneShot(0); |
129 } | 116 } |
130 | 117 |
131 void MediaKeySession::updateTimerFired(Timer<MediaKeySession>*) | 118 void MediaKeySession::updateTimerFired(Timer<MediaKeySession>*) |
132 { | 119 { |
133 ASSERT(m_pendingKeys.size()); | 120 ASSERT(m_pendingKeys.size()); |
134 if (!m_session) | |
135 return; | |
136 | 121 |
137 while (!m_pendingKeys.isEmpty()) { | 122 while (!m_pendingKeys.isEmpty()) { |
138 RefPtr<Uint8Array> pendingKey = m_pendingKeys.takeFirst(); | 123 RefPtr<Uint8Array> pendingKey = m_pendingKeys.takeFirst(); |
139 | 124 |
140 // NOTE: Continued from step 2. of MediaKeySession::update() | 125 // NOTE: Continued from step 2. of MediaKeySession::update() |
141 // 2.1. Let cdm be the cdm loaded in the MediaKeys constructor. | 126 // 2.1. Let cdm be the cdm loaded in the MediaKeys constructor. |
142 // NOTE: This is m_session. | 127 // NOTE: This is m_session. |
143 // 2.2. Let 'did store key' be false. | 128 // 2.2. Let 'did store key' be false. |
144 // 2.3. Let 'next message' be null. | 129 // 2.3. Let 'next message' be null. |
145 // 2.4. Use cdm to handle key. | 130 // 2.4. Use cdm to handle key. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 { | 182 { |
198 return EventTargetNames::MediaKeySession; | 183 return EventTargetNames::MediaKeySession; |
199 } | 184 } |
200 | 185 |
201 ExecutionContext* MediaKeySession::executionContext() const | 186 ExecutionContext* MediaKeySession::executionContext() const |
202 { | 187 { |
203 return ContextLifecycleObserver::executionContext(); | 188 return ContextLifecycleObserver::executionContext(); |
204 } | 189 } |
205 | 190 |
206 } | 191 } |
OLD | NEW |