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" |
(...skipping 22 matching lines...) Expand all Loading... |
33 return proxy_media_keys.Pass(); | 33 return proxy_media_keys.Pass(); |
34 } | 34 } |
35 | 35 |
36 ProxyMediaKeys::~ProxyMediaKeys() { | 36 ProxyMediaKeys::~ProxyMediaKeys() { |
37 manager_->DestroyCdm(cdm_id_); | 37 manager_->DestroyCdm(cdm_id_); |
38 manager_->UnregisterMediaKeys(cdm_id_); | 38 manager_->UnregisterMediaKeys(cdm_id_); |
39 cdm_promise_adapter_.Clear(); | 39 cdm_promise_adapter_.Clear(); |
40 } | 40 } |
41 | 41 |
42 void ProxyMediaKeys::SetServerCertificate( | 42 void ProxyMediaKeys::SetServerCertificate( |
43 const uint8* certificate_data, | 43 const std::vector<uint8_t>& certificate, |
44 int certificate_data_length, | |
45 scoped_ptr<media::SimpleCdmPromise> promise) { | 44 scoped_ptr<media::SimpleCdmPromise> promise) { |
46 uint32_t promise_id = cdm_promise_adapter_.SavePromise(promise.Pass()); | 45 uint32_t promise_id = cdm_promise_adapter_.SavePromise(promise.Pass()); |
47 manager_->SetServerCertificate( | 46 manager_->SetServerCertificate(cdm_id_, promise_id, certificate); |
48 cdm_id_, promise_id, | |
49 std::vector<uint8>(certificate_data, | |
50 certificate_data + certificate_data_length)); | |
51 } | 47 } |
52 | 48 |
53 void ProxyMediaKeys::CreateSessionAndGenerateRequest( | 49 void ProxyMediaKeys::CreateSessionAndGenerateRequest( |
54 SessionType session_type, | 50 SessionType session_type, |
55 media::EmeInitDataType init_data_type, | 51 media::EmeInitDataType init_data_type, |
56 const uint8* init_data, | 52 const std::vector<uint8_t>& init_data, |
57 int init_data_length, | |
58 scoped_ptr<media::NewSessionCdmPromise> promise) { | 53 scoped_ptr<media::NewSessionCdmPromise> promise) { |
59 if (session_type != media::MediaKeys::TEMPORARY_SESSION) { | 54 if (session_type != media::MediaKeys::TEMPORARY_SESSION) { |
60 promise->reject(NOT_SUPPORTED_ERROR, 0, | 55 promise->reject(NOT_SUPPORTED_ERROR, 0, |
61 "Only the temporary session type is supported."); | 56 "Only the temporary session type is supported."); |
62 return; | 57 return; |
63 } | 58 } |
64 | 59 |
65 // TODO(xhwang): Move these checks up to blink and DCHECK here. | 60 // TODO(xhwang): Move these checks up to blink and DCHECK here. |
66 // See http://crbug.com/342510 | 61 // See http://crbug.com/342510 |
67 CdmHostMsg_CreateSession_InitDataType create_session_init_data_type = | 62 CdmHostMsg_CreateSession_InitDataType create_session_init_data_type = |
68 INIT_DATA_TYPE_WEBM; | 63 INIT_DATA_TYPE_WEBM; |
69 switch (init_data_type) { | 64 switch (init_data_type) { |
70 case media::EmeInitDataType::CENC: | 65 case media::EmeInitDataType::CENC: |
71 create_session_init_data_type = INIT_DATA_TYPE_CENC; | 66 create_session_init_data_type = INIT_DATA_TYPE_CENC; |
72 break; | 67 break; |
73 case media::EmeInitDataType::WEBM: | 68 case media::EmeInitDataType::WEBM: |
74 create_session_init_data_type = INIT_DATA_TYPE_WEBM; | 69 create_session_init_data_type = INIT_DATA_TYPE_WEBM; |
75 break; | 70 break; |
76 case media::EmeInitDataType::KEYIDS: | 71 case media::EmeInitDataType::KEYIDS: |
77 case media::EmeInitDataType::UNKNOWN: | 72 case media::EmeInitDataType::UNKNOWN: |
78 DLOG(ERROR) << "Unsupported EME CreateSession init data type"; | 73 DLOG(ERROR) << "Unsupported EME CreateSession init data type"; |
79 promise->reject(NOT_SUPPORTED_ERROR, 0, | 74 promise->reject(NOT_SUPPORTED_ERROR, 0, |
80 "Unsupported EME CreateSession init data type"); | 75 "Unsupported EME CreateSession init data type"); |
81 return; | 76 return; |
82 } | 77 } |
83 | 78 |
84 uint32_t promise_id = cdm_promise_adapter_.SavePromise(promise.Pass()); | 79 uint32_t promise_id = cdm_promise_adapter_.SavePromise(promise.Pass()); |
85 manager_->CreateSessionAndGenerateRequest( | 80 manager_->CreateSessionAndGenerateRequest( |
86 cdm_id_, promise_id, create_session_init_data_type, | 81 cdm_id_, promise_id, create_session_init_data_type, init_data); |
87 std::vector<uint8>(init_data, init_data + init_data_length)); | |
88 } | 82 } |
89 | 83 |
90 void ProxyMediaKeys::LoadSession( | 84 void ProxyMediaKeys::LoadSession( |
91 SessionType session_type, | 85 SessionType session_type, |
92 const std::string& session_id, | 86 const std::string& session_id, |
93 scoped_ptr<media::NewSessionCdmPromise> promise) { | 87 scoped_ptr<media::NewSessionCdmPromise> promise) { |
94 // TODO(xhwang): Check key system and platform support for LoadSession in | 88 // TODO(xhwang): Check key system and platform support for LoadSession in |
95 // blink and add NOTREACHED() here. See http://crbug.com/384152 | 89 // blink and add NOTREACHED() here. See http://crbug.com/384152 |
96 DLOG(ERROR) << "ProxyMediaKeys doesn't support session loading."; | 90 DLOG(ERROR) << "ProxyMediaKeys doesn't support session loading."; |
97 promise->reject(NOT_SUPPORTED_ERROR, 0, "LoadSession() is not supported."); | 91 promise->reject(NOT_SUPPORTED_ERROR, 0, "LoadSession() is not supported."); |
98 } | 92 } |
99 | 93 |
100 void ProxyMediaKeys::UpdateSession( | 94 void ProxyMediaKeys::UpdateSession( |
101 const std::string& session_id, | 95 const std::string& session_id, |
102 const uint8* response, | 96 const std::vector<uint8_t>& response, |
103 int response_length, | |
104 scoped_ptr<media::SimpleCdmPromise> promise) { | 97 scoped_ptr<media::SimpleCdmPromise> promise) { |
105 uint32_t promise_id = cdm_promise_adapter_.SavePromise(promise.Pass()); | 98 uint32_t promise_id = cdm_promise_adapter_.SavePromise(promise.Pass()); |
106 manager_->UpdateSession( | 99 manager_->UpdateSession(cdm_id_, promise_id, session_id, response); |
107 cdm_id_, promise_id, session_id, | |
108 std::vector<uint8>(response, response + response_length)); | |
109 } | 100 } |
110 | 101 |
111 void ProxyMediaKeys::CloseSession(const std::string& session_id, | 102 void ProxyMediaKeys::CloseSession(const std::string& session_id, |
112 scoped_ptr<media::SimpleCdmPromise> promise) { | 103 scoped_ptr<media::SimpleCdmPromise> promise) { |
113 uint32_t promise_id = cdm_promise_adapter_.SavePromise(promise.Pass()); | 104 uint32_t promise_id = cdm_promise_adapter_.SavePromise(promise.Pass()); |
114 manager_->CloseSession(cdm_id_, promise_id, session_id); | 105 manager_->CloseSession(cdm_id_, promise_id, session_id); |
115 } | 106 } |
116 | 107 |
117 void ProxyMediaKeys::RemoveSession( | 108 void ProxyMediaKeys::RemoveSession( |
118 const std::string& session_id, | 109 const std::string& session_id, |
(...skipping 11 matching lines...) Expand all Loading... |
130 return nullptr; | 121 return nullptr; |
131 } | 122 } |
132 | 123 |
133 int ProxyMediaKeys::GetCdmId() const { | 124 int ProxyMediaKeys::GetCdmId() const { |
134 return cdm_id_; | 125 return cdm_id_; |
135 } | 126 } |
136 | 127 |
137 void ProxyMediaKeys::OnSessionMessage( | 128 void ProxyMediaKeys::OnSessionMessage( |
138 const std::string& session_id, | 129 const std::string& session_id, |
139 media::MediaKeys::MessageType message_type, | 130 media::MediaKeys::MessageType message_type, |
140 const std::vector<uint8>& message, | 131 const std::vector<uint8_t>& message, |
141 const GURL& legacy_destination_url) { | 132 const GURL& legacy_destination_url) { |
142 session_message_cb_.Run(session_id, message_type, message, | 133 session_message_cb_.Run(session_id, message_type, message, |
143 legacy_destination_url); | 134 legacy_destination_url); |
144 } | 135 } |
145 | 136 |
146 void ProxyMediaKeys::OnSessionClosed(const std::string& session_id) { | 137 void ProxyMediaKeys::OnSessionClosed(const std::string& session_id) { |
147 session_closed_cb_.Run(session_id); | 138 session_closed_cb_.Run(session_id); |
148 } | 139 } |
149 | 140 |
150 void ProxyMediaKeys::OnLegacySessionError(const std::string& session_id, | 141 void ProxyMediaKeys::OnLegacySessionError(const std::string& session_id, |
151 media::MediaKeys::Exception exception, | 142 media::MediaKeys::Exception exception, |
152 uint32 system_code, | 143 uint32_t system_code, |
153 const std::string& error_message) { | 144 const std::string& error_message) { |
154 legacy_session_error_cb_.Run(session_id, exception, system_code, | 145 legacy_session_error_cb_.Run(session_id, exception, system_code, |
155 error_message); | 146 error_message); |
156 } | 147 } |
157 | 148 |
158 void ProxyMediaKeys::OnSessionKeysChange(const std::string& session_id, | 149 void ProxyMediaKeys::OnSessionKeysChange(const std::string& session_id, |
159 bool has_additional_usable_key, | 150 bool has_additional_usable_key, |
160 media::CdmKeysInfo keys_info) { | 151 media::CdmKeysInfo keys_info) { |
161 session_keys_change_cb_.Run(session_id, has_additional_usable_key, | 152 session_keys_change_cb_.Run(session_id, has_additional_usable_key, |
162 keys_info.Pass()); | 153 keys_info.Pass()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 session_expiration_update_cb_(session_expiration_update_cb) { | 192 session_expiration_update_cb_(session_expiration_update_cb) { |
202 cdm_id_ = manager->RegisterMediaKeys(this); | 193 cdm_id_ = manager->RegisterMediaKeys(this); |
203 } | 194 } |
204 | 195 |
205 void ProxyMediaKeys::InitializeCdm(const std::string& key_system, | 196 void ProxyMediaKeys::InitializeCdm(const std::string& key_system, |
206 const GURL& security_origin) { | 197 const GURL& security_origin) { |
207 manager_->InitializeCdm(cdm_id_, this, key_system, security_origin); | 198 manager_->InitializeCdm(cdm_id_, this, key_system, security_origin); |
208 } | 199 } |
209 | 200 |
210 } // namespace content | 201 } // namespace content |
OLD | NEW |