| 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 "media/blink/encrypted_media_player_support.h" | 5 #include "media/blink/encrypted_media_player_support.h" |
| 6 | 6 |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/numerics/safe_conversions.h" | 11 #include "base/numerics/safe_conversions.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "media/base/bind_to_current_loop.h" | 15 #include "media/base/bind_to_current_loop.h" |
| 16 #include "media/base/key_systems.h" | 16 #include "media/base/key_systems.h" |
| 17 #include "media/blink/webcontentdecryptionmodule_impl.h" | 17 #include "media/blink/webcontentdecryptionmodule_impl.h" |
| 18 #include "third_party/WebKit/public/platform/WebContentDecryptionModule.h" | 18 #include "third_party/WebKit/public/platform/WebContentDecryptionModule.h" |
| 19 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" | 19 #include "third_party/WebKit/public/platform/WebMediaPlayerEncryptedMediaClient.
h" |
| 20 #include "third_party/WebKit/public/web/WebDocument.h" | 20 #include "third_party/WebKit/public/web/WebDocument.h" |
| 21 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 21 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 22 | 22 |
| 23 using blink::WebMediaPlayer; | 23 using blink::WebMediaPlayer; |
| 24 using blink::WebMediaPlayerClient; | 24 using blink::WebMediaPlayerEncryptedMediaClient; |
| 25 using blink::WebString; | 25 using blink::WebString; |
| 26 | 26 |
| 27 namespace media { | 27 namespace media { |
| 28 | 28 |
| 29 #define BIND_TO_RENDER_LOOP(function) \ | 29 #define BIND_TO_RENDER_LOOP(function) \ |
| 30 (BindToCurrentLoop(base::Bind(function, AsWeakPtr()))) | 30 (BindToCurrentLoop(base::Bind(function, AsWeakPtr()))) |
| 31 | 31 |
| 32 #define BIND_TO_RENDER_LOOP1(function, arg1) \ | 32 #define BIND_TO_RENDER_LOOP1(function, arg1) \ |
| 33 (BindToCurrentLoop(base::Bind(function, AsWeakPtr(), arg1))) | 33 (BindToCurrentLoop(base::Bind(function, AsWeakPtr(), arg1))) |
| 34 | 34 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 // Most WebM files use KeyId of 16 bytes. CENC init data is always >16 bytes. | 108 // Most WebM files use KeyId of 16 bytes. CENC init data is always >16 bytes. |
| 109 if (init_data_length > 16) | 109 if (init_data_length > 16) |
| 110 return EmeInitDataType::CENC; | 110 return EmeInitDataType::CENC; |
| 111 #endif | 111 #endif |
| 112 | 112 |
| 113 return EmeInitDataType::WEBM; | 113 return EmeInitDataType::WEBM; |
| 114 } | 114 } |
| 115 | 115 |
| 116 EncryptedMediaPlayerSupport::EncryptedMediaPlayerSupport( | 116 EncryptedMediaPlayerSupport::EncryptedMediaPlayerSupport( |
| 117 CdmFactory* cdm_factory, | 117 CdmFactory* cdm_factory, |
| 118 blink::WebMediaPlayerClient* client, | 118 WebMediaPlayerEncryptedMediaClient* client, |
| 119 MediaPermission* media_permission, | 119 MediaPermission* media_permission, |
| 120 const CdmContextReadyCB& cdm_context_ready_cb) | 120 const CdmContextReadyCB& cdm_context_ready_cb) |
| 121 : cdm_factory_(cdm_factory), | 121 : cdm_factory_(cdm_factory), |
| 122 client_(client), | 122 client_(client), |
| 123 media_permission_(media_permission), | 123 media_permission_(media_permission), |
| 124 init_data_type_(EmeInitDataType::UNKNOWN), | 124 init_data_type_(EmeInitDataType::UNKNOWN), |
| 125 cdm_context_ready_cb_(cdm_context_ready_cb) { | 125 cdm_context_ready_cb_(cdm_context_ready_cb) { |
| 126 } | 126 } |
| 127 | 127 |
| 128 EncryptedMediaPlayerSupport::~EncryptedMediaPlayerSupport() { | 128 EncryptedMediaPlayerSupport::~EncryptedMediaPlayerSupport() { |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 if (system_code > std::numeric_limits<uint16>::max()) { | 298 if (system_code > std::numeric_limits<uint16>::max()) { |
| 299 LOG(WARNING) << "system_code exceeds unsigned short limit."; | 299 LOG(WARNING) << "system_code exceeds unsigned short limit."; |
| 300 short_system_code = std::numeric_limits<uint16>::max(); | 300 short_system_code = std::numeric_limits<uint16>::max(); |
| 301 } else { | 301 } else { |
| 302 short_system_code = static_cast<uint16>(system_code); | 302 short_system_code = static_cast<uint16>(system_code); |
| 303 } | 303 } |
| 304 | 304 |
| 305 client_->keyError( | 305 client_->keyError( |
| 306 WebString::fromUTF8(GetPrefixedKeySystemName(current_key_system_)), | 306 WebString::fromUTF8(GetPrefixedKeySystemName(current_key_system_)), |
| 307 WebString::fromUTF8(session_id), | 307 WebString::fromUTF8(session_id), |
| 308 static_cast<WebMediaPlayerClient::MediaKeyErrorCode>(error_code), | 308 static_cast<WebMediaPlayerEncryptedMediaClient::MediaKeyErrorCode>( |
| 309 error_code), |
| 309 short_system_code); | 310 short_system_code); |
| 310 } | 311 } |
| 311 | 312 |
| 312 void EncryptedMediaPlayerSupport::OnKeyMessage( | 313 void EncryptedMediaPlayerSupport::OnKeyMessage( |
| 313 const std::string& session_id, | 314 const std::string& session_id, |
| 314 const std::vector<uint8>& message, | 315 const std::vector<uint8>& message, |
| 315 const GURL& destination_url) { | 316 const GURL& destination_url) { |
| 316 DCHECK(destination_url.is_empty() || destination_url.is_valid()); | 317 DCHECK(destination_url.is_empty() || destination_url.is_valid()); |
| 317 | 318 |
| 318 client_->keyMessage( | 319 client_->keyMessage( |
| 319 WebString::fromUTF8(GetPrefixedKeySystemName(current_key_system_)), | 320 WebString::fromUTF8(GetPrefixedKeySystemName(current_key_system_)), |
| 320 WebString::fromUTF8(session_id), | 321 WebString::fromUTF8(session_id), |
| 321 message.empty() ? NULL : &message[0], | 322 message.empty() ? NULL : &message[0], |
| 322 base::saturated_cast<unsigned int>(message.size()), | 323 base::saturated_cast<unsigned int>(message.size()), |
| 323 destination_url); | 324 destination_url); |
| 324 } | 325 } |
| 325 | 326 |
| 326 } // namespace media | 327 } // namespace media |
| OLD | NEW |