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/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/numerics/safe_conversions.h" | 11 #include "base/numerics/safe_conversions.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "media/base/cdm_key_information.h" | 14 #include "media/base/cdm_key_information.h" |
15 #include "media/base/cdm_promise.h" | 15 #include "media/base/cdm_promise.h" |
| 16 #include "media/base/content_decryption_module.h" |
16 #include "media/base/key_system_names.h" | 17 #include "media/base/key_system_names.h" |
17 #include "media/base/key_systems.h" | 18 #include "media/base/key_systems.h" |
18 #include "media/base/limits.h" | 19 #include "media/base/limits.h" |
19 #include "media/base/media_keys.h" | |
20 #include "media/blink/cdm_result_promise.h" | 20 #include "media/blink/cdm_result_promise.h" |
21 #include "media/blink/cdm_session_adapter.h" | 21 #include "media/blink/cdm_session_adapter.h" |
22 #include "media/blink/webmediaplayer_util.h" | 22 #include "media/blink/webmediaplayer_util.h" |
23 #include "media/cdm/json_web_key.h" | 23 #include "media/cdm/json_web_key.h" |
24 #include "third_party/WebKit/public/platform/WebData.h" | 24 #include "third_party/WebKit/public/platform/WebData.h" |
25 #include "third_party/WebKit/public/platform/WebEncryptedMediaKeyInformation.h" | 25 #include "third_party/WebKit/public/platform/WebEncryptedMediaKeyInformation.h" |
26 #include "third_party/WebKit/public/platform/WebString.h" | 26 #include "third_party/WebKit/public/platform/WebString.h" |
27 #include "third_party/WebKit/public/platform/WebURL.h" | 27 #include "third_party/WebKit/public/platform/WebURL.h" |
28 #include "third_party/WebKit/public/platform/WebVector.h" | 28 #include "third_party/WebKit/public/platform/WebVector.h" |
29 | 29 |
30 #if defined(USE_PROPRIETARY_CODECS) | 30 #if defined(USE_PROPRIETARY_CODECS) |
31 #include "media/cdm/cenc_utils.h" | 31 #include "media/cdm/cenc_utils.h" |
32 #endif | 32 #endif |
33 | 33 |
34 namespace media { | 34 namespace media { |
35 | 35 |
36 namespace { | 36 namespace { |
37 | 37 |
38 const char kCloseSessionUMAName[] = "CloseSession"; | 38 const char kCloseSessionUMAName[] = "CloseSession"; |
39 const char kGenerateRequestUMAName[] = "GenerateRequest"; | 39 const char kGenerateRequestUMAName[] = "GenerateRequest"; |
40 const char kLoadSessionUMAName[] = "LoadSession"; | 40 const char kLoadSessionUMAName[] = "LoadSession"; |
41 const char kRemoveSessionUMAName[] = "RemoveSession"; | 41 const char kRemoveSessionUMAName[] = "RemoveSession"; |
42 const char kUpdateSessionUMAName[] = "UpdateSession"; | 42 const char kUpdateSessionUMAName[] = "UpdateSession"; |
43 | 43 |
44 blink::WebContentDecryptionModuleSession::Client::MessageType | 44 blink::WebContentDecryptionModuleSession::Client::MessageType |
45 convertMessageType(MediaKeys::MessageType message_type) { | 45 convertMessageType(ContentDecryptionModule::MessageType message_type) { |
46 switch (message_type) { | 46 switch (message_type) { |
47 case media::MediaKeys::LICENSE_REQUEST: | 47 case ContentDecryptionModule::LICENSE_REQUEST: |
48 return blink::WebContentDecryptionModuleSession::Client::MessageType:: | 48 return blink::WebContentDecryptionModuleSession::Client::MessageType:: |
49 LicenseRequest; | 49 LicenseRequest; |
50 case media::MediaKeys::LICENSE_RENEWAL: | 50 case ContentDecryptionModule::LICENSE_RENEWAL: |
51 return blink::WebContentDecryptionModuleSession::Client::MessageType:: | 51 return blink::WebContentDecryptionModuleSession::Client::MessageType:: |
52 LicenseRenewal; | 52 LicenseRenewal; |
53 case media::MediaKeys::LICENSE_RELEASE: | 53 case ContentDecryptionModule::LICENSE_RELEASE: |
54 return blink::WebContentDecryptionModuleSession::Client::MessageType:: | 54 return blink::WebContentDecryptionModuleSession::Client::MessageType:: |
55 LicenseRelease; | 55 LicenseRelease; |
56 } | 56 } |
57 | 57 |
58 NOTREACHED(); | 58 NOTREACHED(); |
59 return blink::WebContentDecryptionModuleSession::Client::MessageType:: | 59 return blink::WebContentDecryptionModuleSession::Client::MessageType:: |
60 LicenseRequest; | 60 LicenseRequest; |
61 } | 61 } |
62 | 62 |
63 blink::WebEncryptedMediaKeyInformation::KeyStatus convertStatus( | 63 blink::WebEncryptedMediaKeyInformation::KeyStatus convertStatus( |
(...skipping 14 matching lines...) Expand all Loading... |
78 case media::CdmKeyInformation::KEY_STATUS_PENDING: | 78 case media::CdmKeyInformation::KEY_STATUS_PENDING: |
79 return blink::WebEncryptedMediaKeyInformation::KeyStatus::StatusPending; | 79 return blink::WebEncryptedMediaKeyInformation::KeyStatus::StatusPending; |
80 case media::CdmKeyInformation::RELEASED: | 80 case media::CdmKeyInformation::RELEASED: |
81 return blink::WebEncryptedMediaKeyInformation::KeyStatus::Released; | 81 return blink::WebEncryptedMediaKeyInformation::KeyStatus::Released; |
82 } | 82 } |
83 | 83 |
84 NOTREACHED(); | 84 NOTREACHED(); |
85 return blink::WebEncryptedMediaKeyInformation::KeyStatus::InternalError; | 85 return blink::WebEncryptedMediaKeyInformation::KeyStatus::InternalError; |
86 } | 86 } |
87 | 87 |
88 MediaKeys::SessionType convertSessionType( | 88 ContentDecryptionModule::SessionType convertSessionType( |
89 blink::WebEncryptedMediaSessionType session_type) { | 89 blink::WebEncryptedMediaSessionType session_type) { |
90 switch (session_type) { | 90 switch (session_type) { |
91 case blink::WebEncryptedMediaSessionType::Temporary: | 91 case blink::WebEncryptedMediaSessionType::Temporary: |
92 return MediaKeys::TEMPORARY_SESSION; | 92 return ContentDecryptionModule::TEMPORARY_SESSION; |
93 case blink::WebEncryptedMediaSessionType::PersistentLicense: | 93 case blink::WebEncryptedMediaSessionType::PersistentLicense: |
94 return MediaKeys::PERSISTENT_LICENSE_SESSION; | 94 return ContentDecryptionModule::PERSISTENT_LICENSE_SESSION; |
95 case blink::WebEncryptedMediaSessionType::PersistentReleaseMessage: | 95 case blink::WebEncryptedMediaSessionType::PersistentReleaseMessage: |
96 return MediaKeys::PERSISTENT_RELEASE_MESSAGE_SESSION; | 96 return ContentDecryptionModule::PERSISTENT_RELEASE_MESSAGE_SESSION; |
97 case blink::WebEncryptedMediaSessionType::Unknown: | 97 case blink::WebEncryptedMediaSessionType::Unknown: |
98 break; | 98 break; |
99 } | 99 } |
100 | 100 |
101 NOTREACHED(); | 101 NOTREACHED(); |
102 return MediaKeys::TEMPORARY_SESSION; | 102 return ContentDecryptionModule::TEMPORARY_SESSION; |
103 } | 103 } |
104 | 104 |
105 bool SanitizeInitData(EmeInitDataType init_data_type, | 105 bool SanitizeInitData(EmeInitDataType init_data_type, |
106 const unsigned char* init_data, | 106 const unsigned char* init_data, |
107 size_t init_data_length, | 107 size_t init_data_length, |
108 std::vector<uint8_t>* sanitized_init_data, | 108 std::vector<uint8_t>* sanitized_init_data, |
109 std::string* error_message) { | 109 std::string* error_message) { |
110 DCHECK_GT(init_data_length, 0u); | 110 DCHECK_GT(init_data_length, 0u); |
111 if (init_data_length > limits::kMaxInitDataLength) { | 111 if (init_data_length > limits::kMaxInitDataLength) { |
112 error_message->assign("Initialization data too long."); | 112 error_message->assign("Initialization data too long."); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 // stripping irrelevant data or fields, pre-parsing it, sanitizing it, | 195 // stripping irrelevant data or fields, pre-parsing it, sanitizing it, |
196 // and/or generating a fully sanitized version. The user agent should check | 196 // and/or generating a fully sanitized version. The user agent should check |
197 // that the length and values of fields are reasonable. Unknown fields should | 197 // that the length and values of fields are reasonable. Unknown fields should |
198 // be rejected or removed. | 198 // be rejected or removed. |
199 if (response_length > limits::kMaxSessionResponseLength) | 199 if (response_length > limits::kMaxSessionResponseLength) |
200 return false; | 200 return false; |
201 | 201 |
202 if (IsClearKey(key_system) || IsExternalClearKey(key_system)) { | 202 if (IsClearKey(key_system) || IsExternalClearKey(key_system)) { |
203 std::string key_string(response, response + response_length); | 203 std::string key_string(response, response + response_length); |
204 KeyIdAndKeyPairs keys; | 204 KeyIdAndKeyPairs keys; |
205 MediaKeys::SessionType session_type = MediaKeys::TEMPORARY_SESSION; | 205 ContentDecryptionModule::SessionType session_type = |
| 206 ContentDecryptionModule::TEMPORARY_SESSION; |
206 if (!ExtractKeysFromJWKSet(key_string, &keys, &session_type)) | 207 if (!ExtractKeysFromJWKSet(key_string, &keys, &session_type)) |
207 return false; | 208 return false; |
208 | 209 |
209 // Must contain at least one key. | 210 // Must contain at least one key. |
210 if (keys.empty()) | 211 if (keys.empty()) |
211 return false; | 212 return false; |
212 | 213 |
213 for (const auto key_pair : keys) { | 214 for (const auto key_pair : keys) { |
214 if (key_pair.first.size() < limits::kMinKeyIdLength || | 215 if (key_pair.first.size() < limits::kMinKeyIdLength || |
215 key_pair.first.size() > limits::kMaxKeyIdLength) { | 216 key_pair.first.size() > limits::kMaxKeyIdLength) { |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 result.completeWithError( | 385 result.completeWithError( |
385 blink::WebContentDecryptionModuleExceptionTypeError, 0, | 386 blink::WebContentDecryptionModuleExceptionTypeError, 0, |
386 "Invalid session ID."); | 387 "Invalid session ID."); |
387 return; | 388 return; |
388 } | 389 } |
389 | 390 |
390 // TODO(jrummell): Now that there are 2 types of persistent sessions, the | 391 // TODO(jrummell): Now that there are 2 types of persistent sessions, the |
391 // session type should be passed from blink. Type should also be passed in the | 392 // session type should be passed from blink. Type should also be passed in the |
392 // constructor (and removed from initializeNewSession()). | 393 // constructor (and removed from initializeNewSession()). |
393 adapter_->LoadSession( | 394 adapter_->LoadSession( |
394 MediaKeys::PERSISTENT_LICENSE_SESSION, sanitized_session_id, | 395 ContentDecryptionModule::PERSISTENT_LICENSE_SESSION, sanitized_session_id, |
395 std::unique_ptr<NewSessionCdmPromise>(new NewSessionCdmResultPromise( | 396 std::unique_ptr<NewSessionCdmPromise>(new NewSessionCdmResultPromise( |
396 result, adapter_->GetKeySystemUMAPrefix() + kLoadSessionUMAName, | 397 result, adapter_->GetKeySystemUMAPrefix() + kLoadSessionUMAName, |
397 base::Bind( | 398 base::Bind( |
398 &WebContentDecryptionModuleSessionImpl::OnSessionInitialized, | 399 &WebContentDecryptionModuleSessionImpl::OnSessionInitialized, |
399 weak_ptr_factory_.GetWeakPtr())))); | 400 weak_ptr_factory_.GetWeakPtr())))); |
400 } | 401 } |
401 | 402 |
402 void WebContentDecryptionModuleSessionImpl::update( | 403 void WebContentDecryptionModuleSessionImpl::update( |
403 const uint8_t* response, | 404 const uint8_t* response, |
404 size_t response_length, | 405 size_t response_length, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 blink::WebContentDecryptionModuleResult result) { | 455 blink::WebContentDecryptionModuleResult result) { |
455 DCHECK(!session_id_.empty()); | 456 DCHECK(!session_id_.empty()); |
456 DCHECK(thread_checker_.CalledOnValidThread()); | 457 DCHECK(thread_checker_.CalledOnValidThread()); |
457 adapter_->RemoveSession( | 458 adapter_->RemoveSession( |
458 session_id_, | 459 session_id_, |
459 std::unique_ptr<SimpleCdmPromise>(new CdmResultPromise<>( | 460 std::unique_ptr<SimpleCdmPromise>(new CdmResultPromise<>( |
460 result, adapter_->GetKeySystemUMAPrefix() + kRemoveSessionUMAName))); | 461 result, adapter_->GetKeySystemUMAPrefix() + kRemoveSessionUMAName))); |
461 } | 462 } |
462 | 463 |
463 void WebContentDecryptionModuleSessionImpl::OnSessionMessage( | 464 void WebContentDecryptionModuleSessionImpl::OnSessionMessage( |
464 MediaKeys::MessageType message_type, | 465 ContentDecryptionModule::MessageType message_type, |
465 const std::vector<uint8_t>& message) { | 466 const std::vector<uint8_t>& message) { |
466 DCHECK(client_) << "Client not set before message event"; | 467 DCHECK(client_) << "Client not set before message event"; |
467 DCHECK(thread_checker_.CalledOnValidThread()); | 468 DCHECK(thread_checker_.CalledOnValidThread()); |
468 client_->message(convertMessageType(message_type), message.data(), | 469 client_->message(convertMessageType(message_type), message.data(), |
469 message.size()); | 470 message.size()); |
470 } | 471 } |
471 | 472 |
472 void WebContentDecryptionModuleSessionImpl::OnSessionKeysChange( | 473 void WebContentDecryptionModuleSessionImpl::OnSessionKeysChange( |
473 bool has_additional_usable_key, | 474 bool has_additional_usable_key, |
474 CdmKeysInfo keys_info) { | 475 CdmKeysInfo keys_info) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 | 517 |
517 DCHECK(session_id_.empty()) << "Session ID may not be changed once set."; | 518 DCHECK(session_id_.empty()) << "Session ID may not be changed once set."; |
518 session_id_ = session_id; | 519 session_id_ = session_id; |
519 *status = | 520 *status = |
520 adapter_->RegisterSession(session_id_, weak_ptr_factory_.GetWeakPtr()) | 521 adapter_->RegisterSession(session_id_, weak_ptr_factory_.GetWeakPtr()) |
521 ? SessionInitStatus::NEW_SESSION | 522 ? SessionInitStatus::NEW_SESSION |
522 : SessionInitStatus::SESSION_ALREADY_EXISTS; | 523 : SessionInitStatus::SESSION_ALREADY_EXISTS; |
523 } | 524 } |
524 | 525 |
525 } // namespace media | 526 } // namespace media |
OLD | NEW |