OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/media/crypto/proxy_media_keys.h" | 5 #include "content/renderer/media/crypto/proxy_media_keys.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "content/renderer/media/crypto/key_systems.h" | 12 #include "content/renderer/media/crypto/key_systems.h" |
13 #include "content/renderer/media/crypto/renderer_cdm_manager.h" | 13 #include "content/renderer/media/crypto/renderer_cdm_manager.h" |
14 #include "media/base/cdm_promise.h" | 14 #include "media/base/cdm_promise.h" |
15 | 15 |
16 namespace content { | 16 namespace content { |
17 | 17 |
18 scoped_ptr<ProxyMediaKeys> ProxyMediaKeys::Create( | 18 scoped_ptr<ProxyMediaKeys> ProxyMediaKeys::Create( |
19 const std::string& key_system, | 19 const std::string& key_system, |
20 const GURL& security_origin, | 20 const GURL& security_origin, |
21 RendererCdmManager* manager, | 21 RendererCdmManager* manager, |
22 const media::SessionMessageCB& session_message_cb, | 22 const media::SessionMessageCB& session_message_cb, |
23 const media::SessionReadyCB& session_ready_cb, | 23 const media::SessionReadyCB& session_ready_cb, |
24 const media::SessionClosedCB& session_closed_cb, | 24 const media::SessionClosedCB& session_closed_cb, |
25 const media::SessionErrorCB& session_error_cb) { | 25 const media::SessionErrorCB& session_error_cb, |
26 const media::SessionKeysChangeCB& session_keys_change_cb, | |
27 const media::SessionExpirationChangeCB& session_expiration_change_cb) { | |
26 DCHECK(manager); | 28 DCHECK(manager); |
29 | |
30 // TODO(jrummell): Add support for SessionKeysChangeCB and | |
31 // SessionExpirationChangeCB. | |
27 scoped_ptr<ProxyMediaKeys> proxy_media_keys( | 32 scoped_ptr<ProxyMediaKeys> proxy_media_keys( |
28 new ProxyMediaKeys(manager, | 33 new ProxyMediaKeys(manager, |
29 session_message_cb, | 34 session_message_cb, |
30 session_ready_cb, | 35 session_ready_cb, |
31 session_closed_cb, | 36 session_closed_cb, |
32 session_error_cb)); | 37 session_error_cb)); |
33 proxy_media_keys->InitializeCdm(key_system, security_origin); | 38 proxy_media_keys->InitializeCdm(key_system, security_origin); |
34 return proxy_media_keys.Pass(); | 39 return proxy_media_keys.Pass(); |
35 } | 40 } |
36 | 41 |
37 ProxyMediaKeys::~ProxyMediaKeys() { | 42 ProxyMediaKeys::~ProxyMediaKeys() { |
38 manager_->DestroyCdm(cdm_id_); | 43 manager_->DestroyCdm(cdm_id_); |
39 manager_->UnregisterMediaKeys(cdm_id_); | 44 manager_->UnregisterMediaKeys(cdm_id_); |
40 | 45 |
41 // Reject any outstanding promises. | 46 // Reject any outstanding promises. |
42 for (PromiseMap::iterator it = session_id_to_promise_map_.begin(); | 47 for (PromiseMap::iterator it = session_id_to_promise_map_.begin(); |
43 it != session_id_to_promise_map_.end(); | 48 it != session_id_to_promise_map_.end(); |
44 ++it) { | 49 ++it) { |
45 it->second->reject( | 50 it->second->reject( |
46 media::MediaKeys::NOT_SUPPORTED_ERROR, 0, "The operation was aborted."); | 51 media::MediaKeys::NOT_SUPPORTED_ERROR, 0, "The operation was aborted."); |
47 } | 52 } |
48 session_id_to_promise_map_.clear(); | 53 session_id_to_promise_map_.clear(); |
49 } | 54 } |
50 | 55 |
56 void ProxyMediaKeys::SetServerCertificate( | |
57 const uint8* certificate_data, | |
58 int certificate_data_length, | |
59 scoped_ptr<media::SimpleCdmPromise> promise) { | |
60 promise->reject(NOT_SUPPORTED_ERROR, 0, "Not yet implemented."); | |
61 } | |
62 | |
51 void ProxyMediaKeys::CreateSession( | 63 void ProxyMediaKeys::CreateSession( |
52 const std::string& init_data_type, | 64 const std::string& init_data_type, |
53 const uint8* init_data, | 65 const uint8* init_data, |
54 int init_data_length, | 66 int init_data_length, |
55 SessionType session_type, | 67 SessionType session_type, |
56 scoped_ptr<media::NewSessionCdmPromise> promise) { | 68 scoped_ptr<media::NewSessionCdmPromise> promise) { |
57 // TODO(xhwang): Move these checks up to blink and DCHECK here. | 69 // TODO(xhwang): Move these checks up to blink and DCHECK here. |
58 // See http://crbug.com/342510 | 70 // See http://crbug.com/342510 |
59 CdmHostMsg_CreateSession_ContentType create_session_content_type; | 71 CdmHostMsg_CreateSession_ContentType create_session_content_type; |
60 if (init_data_type == "cenc") { | 72 if (init_data_type == "cenc") { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 return; | 112 return; |
101 } | 113 } |
102 | 114 |
103 SavePromise(session_id, promise.PassAs<media::CdmPromise>()); | 115 SavePromise(session_id, promise.PassAs<media::CdmPromise>()); |
104 manager_->UpdateSession( | 116 manager_->UpdateSession( |
105 cdm_id_, | 117 cdm_id_, |
106 session_id, | 118 session_id, |
107 std::vector<uint8>(response, response + response_length)); | 119 std::vector<uint8>(response, response + response_length)); |
108 } | 120 } |
109 | 121 |
110 void ProxyMediaKeys::ReleaseSession( | 122 void ProxyMediaKeys::CloseSession(const std::string& web_session_id, |
111 const std::string& web_session_id, | 123 scoped_ptr<media::SimpleCdmPromise> promise) { |
112 scoped_ptr<media::SimpleCdmPromise> promise) { | 124 // Both CloseSession() and RemoveSession() call ReleaseSession(), so calling |
125 // either one will release the session. Calling both will result in an error | |
126 // for the second call. | |
127 // TODO(jrummell): Implement Close/Remove properly. | |
113 uint32 session_id = LookupSessionId(web_session_id); | 128 uint32 session_id = LookupSessionId(web_session_id); |
114 if (!session_id) { | 129 if (!session_id) { |
115 promise->reject(INVALID_ACCESS_ERROR, 0, "Session does not exist."); | 130 promise->reject(INVALID_ACCESS_ERROR, 0, "Session does not exist."); |
131 return; | |
132 } | |
133 | |
134 SavePromise(session_id, promise.PassAs<media::CdmPromise>()); | |
135 manager_->ReleaseSession(cdm_id_, session_id); | |
136 } | |
137 | |
138 void ProxyMediaKeys::RemoveSession( | |
139 const std::string& web_session_id, | |
140 scoped_ptr<media::SimpleCdmPromise> promise) { | |
141 // Both CloseSession() and RemoveSession() call ReleaseSession(), so calling | |
ddorwin
2014/09/11 23:31:11
Remove is not implemented on Android because persi
jrummell
2014/09/15 18:22:39
Done. I was more concerned about v0.1b calling CKR
| |
142 // either one will release the session. Calling both will result in an error | |
143 // for the second call. | |
144 uint32 session_id = LookupSessionId(web_session_id); | |
145 if (!session_id) { | |
146 promise->reject(INVALID_ACCESS_ERROR, 0, "Session does not exist."); | |
116 return; | 147 return; |
117 } | 148 } |
118 | 149 |
119 SavePromise(session_id, promise.PassAs<media::CdmPromise>()); | 150 SavePromise(session_id, promise.PassAs<media::CdmPromise>()); |
120 manager_->ReleaseSession(cdm_id_, session_id); | 151 manager_->ReleaseSession(cdm_id_, session_id); |
121 } | 152 } |
122 | 153 |
154 void ProxyMediaKeys::GetUsableKeyIds(const std::string& web_session_id, | |
155 scoped_ptr<media::KeyIdsPromise> promise) { | |
156 promise->reject(NOT_SUPPORTED_ERROR, 0, "Not yet implemented."); | |
157 } | |
158 | |
123 void ProxyMediaKeys::OnSessionCreated(uint32 session_id, | 159 void ProxyMediaKeys::OnSessionCreated(uint32 session_id, |
124 const std::string& web_session_id) { | 160 const std::string& web_session_id) { |
125 AssignWebSessionId(session_id, web_session_id); | 161 AssignWebSessionId(session_id, web_session_id); |
126 scoped_ptr<media::CdmPromise> promise = TakePromise(session_id); | 162 scoped_ptr<media::CdmPromise> promise = TakePromise(session_id); |
127 if (promise) { | 163 if (promise) { |
128 media::NewSessionCdmPromise* session_promise( | 164 media::NewSessionCdmPromise* session_promise( |
129 static_cast<media::NewSessionCdmPromise*>(promise.get())); | 165 static_cast<media::NewSessionCdmPromise*>(promise.get())); |
130 session_promise->resolve(web_session_id); | 166 session_promise->resolve(web_session_id); |
131 } | 167 } |
132 } | 168 } |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
264 | 300 |
265 scoped_ptr<media::CdmPromise> ProxyMediaKeys::TakePromise(uint32_t session_id) { | 301 scoped_ptr<media::CdmPromise> ProxyMediaKeys::TakePromise(uint32_t session_id) { |
266 PromiseMap::iterator it = session_id_to_promise_map_.find(session_id); | 302 PromiseMap::iterator it = session_id_to_promise_map_.find(session_id); |
267 // May not be a promise associated with this session for asynchronous events. | 303 // May not be a promise associated with this session for asynchronous events. |
268 if (it == session_id_to_promise_map_.end()) | 304 if (it == session_id_to_promise_map_.end()) |
269 return scoped_ptr<media::CdmPromise>(); | 305 return scoped_ptr<media::CdmPromise>(); |
270 return session_id_to_promise_map_.take_and_erase(it); | 306 return session_id_to_promise_map_.take_and_erase(it); |
271 } | 307 } |
272 | 308 |
273 } // namespace content | 309 } // namespace content |
OLD | NEW |