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_addKeyTimer(this, &MediaKeySession::addKeyTimerFired) | 52 , m_addKeyTimer(this, &MediaKeySession::addKeyTimerFired) |
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 ASSERT(m_session); |
ddorwin
2014/01/09 18:05:33
Probably not necessary. We don't have it elsewhere
xhwang
2014/01/09 20:01:26
Done.
| |
70 | 76 m_session->release(); |
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 } | 77 } |
80 | 78 |
81 String MediaKeySession::sessionId() const | 79 String MediaKeySession::sessionId() const |
82 { | 80 { |
83 return m_session->sessionId(); | 81 return m_session->sessionId(); |
84 } | 82 } |
85 | 83 |
86 void MediaKeySession::generateKeyRequest(const String& mimeType, Uint8Array* ini tData) | 84 void MediaKeySession::initializeNewSession(const String& mimeType, Uint8Array* i nitData) |
87 { | 85 { |
88 m_pendingKeyRequests.append(PendingKeyRequest(mimeType, initData)); | 86 m_pendingInitializeNewSessionData.append(InitializeNewSessionData(mimeType, initData)); |
89 // FIXME: Eliminate timers. Asynchronicity will be handled in Chromium. | 87 m_initializeNewSessionTimer.startOneShot(0); |
90 m_keyRequestTimer.startOneShot(0); | |
91 } | 88 } |
92 | 89 |
93 void MediaKeySession::keyRequestTimerFired(Timer<MediaKeySession>*) | 90 void MediaKeySession::initializeNewSessionTimerFired(Timer<MediaKeySession>*) |
94 { | 91 { |
95 ASSERT(m_pendingKeyRequests.size()); | 92 ASSERT(m_pendingInitializeNewSessionData.size()); |
96 if (!m_session) | |
97 return; | |
98 | 93 |
99 while (!m_pendingKeyRequests.isEmpty()) { | 94 while (!m_pendingInitializeNewSessionData.isEmpty()) { |
100 PendingKeyRequest request = m_pendingKeyRequests.takeFirst(); | 95 InitializeNewSessionData data = m_pendingInitializeNewSessionData.takeFi rst(); |
101 | 96 // FIXME: Refer to the spec to see what needs to be done in blink. |
102 // NOTE: Continued from step 5 in MediaKeys::createSession(). | 97 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 } | 98 } |
111 } | 99 } |
112 | 100 |
113 void MediaKeySession::update(Uint8Array* key, ExceptionState& exceptionState) | 101 void MediaKeySession::update(Uint8Array* key, ExceptionState& exceptionState) |
114 { | 102 { |
115 // From <http://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/e ncrypted-media.html#dom-addkey>: | 103 // From <http://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/e ncrypted-media.html#dom-addkey>: |
116 // The addKey(key) method must run the following steps: | 104 // The addKey(key) method must run the following steps: |
117 // 1. If the first or second argument [sic] is null or an empty array, throw an InvalidAccessError. | 105 // 1. If the first or second argument [sic] is null or an empty array, throw an InvalidAccessError. |
118 // NOTE: the reference to a "second argument" is a spec bug. | 106 // NOTE: the reference to a "second argument" is a spec bug. |
119 if (!key || !key->length()) { | 107 if (!key || !key->length()) { |
120 exceptionState.throwUninformativeAndGenericDOMException(InvalidAccessErr or); | 108 exceptionState.throwUninformativeAndGenericDOMException(InvalidAccessErr or); |
121 return; | 109 return; |
122 } | 110 } |
123 | 111 |
124 // 2. Schedule a task to handle the call, providing key. | 112 // 2. Schedule a task to handle the call, providing key. |
125 m_pendingKeys.append(key); | 113 m_pendingKeys.append(key); |
126 m_addKeyTimer.startOneShot(0); | 114 m_addKeyTimer.startOneShot(0); |
127 } | 115 } |
128 | 116 |
129 void MediaKeySession::addKeyTimerFired(Timer<MediaKeySession>*) | 117 void MediaKeySession::addKeyTimerFired(Timer<MediaKeySession>*) |
130 { | 118 { |
131 ASSERT(m_pendingKeys.size()); | 119 ASSERT(m_pendingKeys.size()); |
132 if (!m_session) | |
133 return; | |
134 | 120 |
135 while (!m_pendingKeys.isEmpty()) { | 121 while (!m_pendingKeys.isEmpty()) { |
136 RefPtr<Uint8Array> pendingKey = m_pendingKeys.takeFirst(); | 122 RefPtr<Uint8Array> pendingKey = m_pendingKeys.takeFirst(); |
137 | 123 |
138 // NOTE: Continued from step 2. of MediaKeySession::update() | 124 // NOTE: Continued from step 2. of MediaKeySession::update() |
139 // 2.1. Let cdm be the cdm loaded in the MediaKeys constructor. | 125 // 2.1. Let cdm be the cdm loaded in the MediaKeys constructor. |
140 // NOTE: This is m_session. | 126 // NOTE: This is m_session. |
141 // 2.2. Let 'did store key' be false. | 127 // 2.2. Let 'did store key' be false. |
142 // 2.3. Let 'next message' be null. | 128 // 2.3. Let 'next message' be null. |
143 // 2.4. Use cdm to handle key. | 129 // 2.4. Use cdm to handle key. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
195 { | 181 { |
196 return EventTargetNames::MediaKeySession; | 182 return EventTargetNames::MediaKeySession; |
197 } | 183 } |
198 | 184 |
199 ExecutionContext* MediaKeySession::executionContext() const | 185 ExecutionContext* MediaKeySession::executionContext() const |
200 { | 186 { |
201 return ContextLifecycleObserver::executionContext(); | 187 return ContextLifecycleObserver::executionContext(); |
202 } | 188 } |
203 | 189 |
204 } | 190 } |
OLD | NEW |