| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "webcontentdecryptionmodulesession_impl.h" | 5 #include "webcontentdecryptionmodulesession_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/numerics/safe_conversions.h" | 10 #include "base/numerics/safe_conversions.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "media/base/cdm_key_information.h" |
| 13 #include "media/base/cdm_promise.h" | 14 #include "media/base/cdm_promise.h" |
| 14 #include "media/base/media_keys.h" | 15 #include "media/base/media_keys.h" |
| 15 #include "media/blink/cdm_result_promise.h" | 16 #include "media/blink/cdm_result_promise.h" |
| 16 #include "media/blink/cdm_session_adapter.h" | 17 #include "media/blink/cdm_session_adapter.h" |
| 17 #include "media/blink/new_session_cdm_result_promise.h" | 18 #include "media/blink/new_session_cdm_result_promise.h" |
| 19 #include "third_party/WebKit/public/platform/WebData.h" |
| 20 #include "third_party/WebKit/public/platform/WebEncryptedMediaKeyInformation.h" |
| 18 #include "third_party/WebKit/public/platform/WebString.h" | 21 #include "third_party/WebKit/public/platform/WebString.h" |
| 19 #include "third_party/WebKit/public/platform/WebURL.h" | 22 #include "third_party/WebKit/public/platform/WebURL.h" |
| 23 #include "third_party/WebKit/public/platform/WebVector.h" |
| 20 | 24 |
| 21 namespace media { | 25 namespace media { |
| 22 | 26 |
| 23 const char kCreateSessionUMAName[] = "CreateSession"; | 27 const char kCreateSessionUMAName[] = "CreateSession"; |
| 24 const char kLoadSessionUMAName[] = "LoadSession"; | 28 const char kLoadSessionUMAName[] = "LoadSession"; |
| 25 | 29 |
| 26 // TODO(jrummell): Pass an enum from blink. http://crbug.com/418239. | 30 // TODO(jrummell): Pass an enum from blink. http://crbug.com/418239. |
| 27 const char kTemporarySessionType[] = "temporary"; | 31 const char kTemporarySessionType[] = "temporary"; |
| 28 const char kPersistentLicenseSessionType[] = "persistent-license"; | 32 const char kPersistentLicenseSessionType[] = "persistent-license"; |
| 29 const char kPersistentReleaseMessageSessionType[] = | 33 const char kPersistentReleaseMessageSessionType[] = |
| (...skipping 11 matching lines...) Expand all Loading... |
| 41 case media::MediaKeys::LICENSE_RELEASE: | 45 case media::MediaKeys::LICENSE_RELEASE: |
| 42 return blink::WebContentDecryptionModuleSession::Client::MessageType:: | 46 return blink::WebContentDecryptionModuleSession::Client::MessageType:: |
| 43 LicenseRelease; | 47 LicenseRelease; |
| 44 } | 48 } |
| 45 | 49 |
| 46 NOTREACHED(); | 50 NOTREACHED(); |
| 47 return blink::WebContentDecryptionModuleSession::Client::MessageType:: | 51 return blink::WebContentDecryptionModuleSession::Client::MessageType:: |
| 48 LicenseRequest; | 52 LicenseRequest; |
| 49 } | 53 } |
| 50 | 54 |
| 55 static blink::WebEncryptedMediaKeyInformation::KeyStatus convertStatus( |
| 56 media::CdmKeyInformation::KeyStatus status) { |
| 57 switch (status) { |
| 58 case media::CdmKeyInformation::USABLE: |
| 59 return blink::WebEncryptedMediaKeyInformation::KeyStatus::Usable; |
| 60 case media::CdmKeyInformation::INTERNAL_ERROR: |
| 61 return blink::WebEncryptedMediaKeyInformation::KeyStatus::InternalError; |
| 62 case media::CdmKeyInformation::EXPIRED: |
| 63 return blink::WebEncryptedMediaKeyInformation::KeyStatus::Expired; |
| 64 case media::CdmKeyInformation::OUTPUT_NOT_ALLOWED: |
| 65 return blink::WebEncryptedMediaKeyInformation::KeyStatus:: |
| 66 OutputNotAllowed; |
| 67 } |
| 68 |
| 69 NOTREACHED(); |
| 70 return blink::WebEncryptedMediaKeyInformation::KeyStatus::InternalError; |
| 71 } |
| 72 |
| 51 WebContentDecryptionModuleSessionImpl::WebContentDecryptionModuleSessionImpl( | 73 WebContentDecryptionModuleSessionImpl::WebContentDecryptionModuleSessionImpl( |
| 52 const scoped_refptr<CdmSessionAdapter>& adapter) | 74 const scoped_refptr<CdmSessionAdapter>& adapter) |
| 53 : adapter_(adapter), is_closed_(false), weak_ptr_factory_(this) { | 75 : adapter_(adapter), is_closed_(false), weak_ptr_factory_(this) { |
| 54 } | 76 } |
| 55 | 77 |
| 56 WebContentDecryptionModuleSessionImpl:: | 78 WebContentDecryptionModuleSessionImpl:: |
| 57 ~WebContentDecryptionModuleSessionImpl() { | 79 ~WebContentDecryptionModuleSessionImpl() { |
| 58 if (!web_session_id_.empty()) | 80 if (!web_session_id_.empty()) |
| 59 adapter_->UnregisterSession(web_session_id_); | 81 adapter_->UnregisterSession(web_session_id_); |
| 60 } | 82 } |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 | 207 |
| 186 void WebContentDecryptionModuleSessionImpl::OnSessionMessage( | 208 void WebContentDecryptionModuleSessionImpl::OnSessionMessage( |
| 187 MediaKeys::MessageType message_type, | 209 MediaKeys::MessageType message_type, |
| 188 const std::vector<uint8>& message) { | 210 const std::vector<uint8>& message) { |
| 189 DCHECK(client_) << "Client not set before message event"; | 211 DCHECK(client_) << "Client not set before message event"; |
| 190 client_->message(convertMessageType(message_type), | 212 client_->message(convertMessageType(message_type), |
| 191 message.empty() ? NULL : &message[0], message.size()); | 213 message.empty() ? NULL : &message[0], message.size()); |
| 192 } | 214 } |
| 193 | 215 |
| 194 void WebContentDecryptionModuleSessionImpl::OnSessionKeysChange( | 216 void WebContentDecryptionModuleSessionImpl::OnSessionKeysChange( |
| 195 bool has_additional_usable_key) { | 217 bool has_additional_usable_key, |
| 196 // TODO(jrummell): Update this once Blink client supports this. | 218 CdmKeysInfo keys_info) { |
| 219 blink::WebVector<blink::WebEncryptedMediaKeyInformation> keys( |
| 220 keys_info.size()); |
| 221 for (size_t i = 0; i < keys_info.size(); ++i) { |
| 222 const auto& key_info = keys_info[i]; |
| 223 keys[i].setId(blink::WebData(reinterpret_cast<char*>(&key_info->key_id[0]), |
| 224 key_info->key_id.size())); |
| 225 keys[i].setStatus(convertStatus(key_info->status)); |
| 226 keys[i].setSystemCode(key_info->system_code); |
| 227 } |
| 228 |
| 229 // Now send the event to blink. |
| 230 client_->keysStatusesChange(keys, has_additional_usable_key); |
| 197 } | 231 } |
| 198 | 232 |
| 199 void WebContentDecryptionModuleSessionImpl::OnSessionExpirationUpdate( | 233 void WebContentDecryptionModuleSessionImpl::OnSessionExpirationUpdate( |
| 200 const base::Time& new_expiry_time) { | 234 const base::Time& new_expiry_time) { |
| 201 client_->expirationChanged(new_expiry_time.ToJsTime()); | 235 client_->expirationChanged(new_expiry_time.ToJsTime()); |
| 202 } | 236 } |
| 203 | 237 |
| 204 void WebContentDecryptionModuleSessionImpl::OnSessionClosed() { | 238 void WebContentDecryptionModuleSessionImpl::OnSessionClosed() { |
| 205 if (is_closed_) | 239 if (is_closed_) |
| 206 return; | 240 return; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 218 | 252 |
| 219 DCHECK(web_session_id_.empty()) << "Session ID may not be changed once set."; | 253 DCHECK(web_session_id_.empty()) << "Session ID may not be changed once set."; |
| 220 web_session_id_ = web_session_id; | 254 web_session_id_ = web_session_id; |
| 221 return adapter_->RegisterSession(web_session_id_, | 255 return adapter_->RegisterSession(web_session_id_, |
| 222 weak_ptr_factory_.GetWeakPtr()) | 256 weak_ptr_factory_.GetWeakPtr()) |
| 223 ? blink::WebContentDecryptionModuleResult::NewSession | 257 ? blink::WebContentDecryptionModuleResult::NewSession |
| 224 : blink::WebContentDecryptionModuleResult::SessionAlreadyExists; | 258 : blink::WebContentDecryptionModuleResult::SessionAlreadyExists; |
| 225 } | 259 } |
| 226 | 260 |
| 227 } // namespace media | 261 } // namespace media |
| OLD | NEW |