| 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/encrypted_media_player_support_impl.h" | 5 #include "content/renderer/media/crypto/encrypted_media_player_support_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.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 "content/renderer/media/crypto/key_systems.h" | 15 #include "content/renderer/media/crypto/key_systems.h" |
| 16 #include "content/renderer/media/crypto/render_cdm_factory.h" |
| 16 #include "content/renderer/media/webcontentdecryptionmodule_impl.h" | 17 #include "content/renderer/media/webcontentdecryptionmodule_impl.h" |
| 17 #include "content/renderer/pepper/pepper_webplugin_impl.h" | |
| 18 #include "media/base/bind_to_current_loop.h" | 18 #include "media/base/bind_to_current_loop.h" |
| 19 #include "media/blink/encrypted_media_player_support.h" | 19 #include "media/blink/encrypted_media_player_support.h" |
| 20 #include "third_party/WebKit/public/platform/WebContentDecryptionModule.h" | 20 #include "third_party/WebKit/public/platform/WebContentDecryptionModule.h" |
| 21 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h" | 21 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h" |
| 22 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" | 22 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" |
| 23 #include "third_party/WebKit/public/web/WebDocument.h" | 23 #include "third_party/WebKit/public/web/WebDocument.h" |
| 24 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 24 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 25 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 25 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
| 26 | 26 |
| 27 #if defined(ENABLE_PEPPER_CDMS) | 27 #if defined(ENABLE_PEPPER_CDMS) |
| 28 #include "content/renderer/media/crypto/pepper_cdm_wrapper_impl.h" | 28 #include "content/renderer/media/crypto/pepper_cdm_wrapper_impl.h" |
| 29 #elif defined(ENABLE_BROWSER_CDMS) |
| 30 #error Browser side CDM in WMPI for prefixed EME API not supported yet. |
| 29 #endif | 31 #endif |
| 30 | 32 |
| 31 using blink::WebMediaPlayer; | 33 using blink::WebMediaPlayer; |
| 32 using blink::WebMediaPlayerClient; | 34 using blink::WebMediaPlayerClient; |
| 33 using blink::WebString; | 35 using blink::WebString; |
| 34 | 36 |
| 35 namespace content { | 37 namespace content { |
| 36 | 38 |
| 37 #define BIND_TO_RENDER_LOOP(function) \ | 39 #define BIND_TO_RENDER_LOOP(function) \ |
| 38 (media::BindToCurrentLoop(base::Bind(function, AsWeakPtr()))) | 40 (media::BindToCurrentLoop(base::Bind(function, AsWeakPtr()))) |
| 39 | 41 |
| 40 #define BIND_TO_RENDER_LOOP1(function, arg1) \ | 42 #define BIND_TO_RENDER_LOOP1(function, arg1) \ |
| 41 (media::BindToCurrentLoop(base::Bind(function, AsWeakPtr(), arg1))) | 43 (media::BindToCurrentLoop(base::Bind(function, AsWeakPtr(), arg1))) |
| 42 | 44 |
| 43 | |
| 44 // Prefix for histograms related to Encrypted Media Extensions. | 45 // Prefix for histograms related to Encrypted Media Extensions. |
| 45 static const char* kMediaEme = "Media.EME."; | 46 static const char* kMediaEme = "Media.EME."; |
| 46 | 47 |
| 47 // Used for calls to decryptor_ready_cb where the result can be ignored. | 48 // Used for calls to decryptor_ready_cb where the result can be ignored. |
| 48 static void DoNothing(bool success) { | 49 static void DoNothing(bool success) { |
| 49 } | 50 } |
| 50 | 51 |
| 51 // Convert a WebString to ASCII, falling back on an empty string in the case | 52 // Convert a WebString to ASCII, falling back on an empty string in the case |
| 52 // of a non-ASCII string. | 53 // of a non-ASCII string. |
| 53 static std::string ToASCIIOrEmpty(const WebString& string) { | 54 static std::string ToASCIIOrEmpty(const WebString& string) { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 std::string ascii_key_system = | 153 std::string ascii_key_system = |
| 153 GetUnprefixedKeySystemName(ToASCIIOrEmpty(key_system)); | 154 GetUnprefixedKeySystemName(ToASCIIOrEmpty(key_system)); |
| 154 | 155 |
| 155 WebMediaPlayer::MediaKeyException e = | 156 WebMediaPlayer::MediaKeyException e = |
| 156 GenerateKeyRequestInternal(frame, ascii_key_system, init_data, | 157 GenerateKeyRequestInternal(frame, ascii_key_system, init_data, |
| 157 init_data_length); | 158 init_data_length); |
| 158 ReportMediaKeyExceptionToUMA("generateKeyRequest", ascii_key_system, e); | 159 ReportMediaKeyExceptionToUMA("generateKeyRequest", ascii_key_system, e); |
| 159 return e; | 160 return e; |
| 160 } | 161 } |
| 161 | 162 |
| 162 | |
| 163 WebMediaPlayer::MediaKeyException | 163 WebMediaPlayer::MediaKeyException |
| 164 EncryptedMediaPlayerSupportImpl::GenerateKeyRequestInternal( | 164 EncryptedMediaPlayerSupportImpl::GenerateKeyRequestInternal( |
| 165 blink::WebLocalFrame* frame, | 165 blink::WebLocalFrame* frame, |
| 166 const std::string& key_system, | 166 const std::string& key_system, |
| 167 const unsigned char* init_data, | 167 const unsigned char* init_data, |
| 168 unsigned init_data_length) { | 168 unsigned init_data_length) { |
| 169 if (!IsConcreteSupportedKeySystem(key_system)) | 169 if (!IsConcreteSupportedKeySystem(key_system)) |
| 170 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; | 170 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; |
| 171 | 171 |
| 172 // We do not support run-time switching between key systems for now. | 172 // We do not support run-time switching between key systems for now. |
| 173 if (current_key_system_.empty()) { | 173 if (current_key_system_.empty()) { |
| 174 if (!proxy_decryptor_) { | 174 if (!proxy_decryptor_) { |
| 175 proxy_decryptor_.reset(new ProxyDecryptor( | 175 proxy_decryptor_.reset(new ProxyDecryptor( |
| 176 #if defined(ENABLE_PEPPER_CDMS) | |
| 177 // Create() must be called synchronously as |frame| may not be | |
| 178 // valid afterwards. | |
| 179 base::Bind(&PepperCdmWrapperImpl::Create, frame), | |
| 180 #elif defined(ENABLE_BROWSER_CDMS) | |
| 181 #error Browser side CDM in WMPI for prefixed EME API not supported yet. | |
| 182 #endif | |
| 183 BIND_TO_RENDER_LOOP(&EncryptedMediaPlayerSupportImpl::OnKeyAdded), | 176 BIND_TO_RENDER_LOOP(&EncryptedMediaPlayerSupportImpl::OnKeyAdded), |
| 184 BIND_TO_RENDER_LOOP(&EncryptedMediaPlayerSupportImpl::OnKeyError), | 177 BIND_TO_RENDER_LOOP(&EncryptedMediaPlayerSupportImpl::OnKeyError), |
| 185 BIND_TO_RENDER_LOOP(&EncryptedMediaPlayerSupportImpl::OnKeyMessage))); | 178 BIND_TO_RENDER_LOOP(&EncryptedMediaPlayerSupportImpl::OnKeyMessage))); |
| 186 } | 179 } |
| 187 | 180 |
| 188 GURL security_origin(frame->document().securityOrigin().toString()); | 181 GURL security_origin(frame->document().securityOrigin().toString()); |
| 189 if (!proxy_decryptor_->InitializeCDM(key_system, security_origin)) | 182 |
| 183 RenderCdmFactory cdm_factory( |
| 184 #if defined(ENABLE_PEPPER_CDMS) |
| 185 base::Bind(&PepperCdmWrapperImpl::Create, frame) |
| 186 #endif |
| 187 ); |
| 188 |
| 189 if (!proxy_decryptor_->InitializeCDM(&cdm_factory, key_system, |
| 190 security_origin)) { |
| 190 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; | 191 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; |
| 192 } |
| 191 | 193 |
| 192 if (proxy_decryptor_ && !decryptor_ready_cb_.is_null()) { | 194 if (proxy_decryptor_ && !decryptor_ready_cb_.is_null()) { |
| 193 base::ResetAndReturn(&decryptor_ready_cb_) | 195 base::ResetAndReturn(&decryptor_ready_cb_) |
| 194 .Run(proxy_decryptor_->GetDecryptor(), base::Bind(DoNothing)); | 196 .Run(proxy_decryptor_->GetDecryptor(), base::Bind(DoNothing)); |
| 195 } | 197 } |
| 196 | 198 |
| 197 current_key_system_ = key_system; | 199 current_key_system_ = key_system; |
| 198 } else if (key_system != current_key_system_) { | 200 } else if (key_system != current_key_system_) { |
| 199 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; | 201 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; |
| 200 } | 202 } |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 | 465 |
| 464 if (web_cdm_) { | 466 if (web_cdm_) { |
| 465 decryptor_ready_cb.Run(web_cdm_->GetDecryptor(), base::Bind(DoNothing)); | 467 decryptor_ready_cb.Run(web_cdm_->GetDecryptor(), base::Bind(DoNothing)); |
| 466 return; | 468 return; |
| 467 } | 469 } |
| 468 | 470 |
| 469 decryptor_ready_cb_ = decryptor_ready_cb; | 471 decryptor_ready_cb_ = decryptor_ready_cb; |
| 470 } | 472 } |
| 471 | 473 |
| 472 } // namespace content | 474 } // namespace content |
| OLD | NEW |