Index: content/renderer/media/webmediaplayer_impl.cc |
diff --git a/content/renderer/media/webmediaplayer_impl.cc b/content/renderer/media/webmediaplayer_impl.cc |
index 901fa0b33e67644fe86d4f5b0aa1fcd197834ef2..9b8cfa8cace58f1ac7bd4b47b14169a5f6588a90 100644 |
--- a/content/renderer/media/webmediaplayer_impl.cc |
+++ b/content/renderer/media/webmediaplayer_impl.cc |
@@ -674,7 +674,7 @@ bool WebMediaPlayerImpl::copyVideoTextureToPlatformTexture( |
// UMA_HISTOGRAM_COUNTS. The reason that we cannot use those macros directly is |
// that UMA_* macros require the names to be constant throughout the process' |
// lifetime. |
-static void EmeUMAHistogramEnumeration(const blink::WebString& key_system, |
+static void EmeUMAHistogramEnumeration(const std::string& key_system, |
const std::string& method, |
int sample, |
int boundary_value) { |
@@ -684,7 +684,7 @@ static void EmeUMAHistogramEnumeration(const blink::WebString& key_system, |
base::Histogram::kUmaTargetedHistogramFlag)->Add(sample); |
} |
-static void EmeUMAHistogramCounts(const blink::WebString& key_system, |
+static void EmeUMAHistogramCounts(const std::string& key_system, |
const std::string& method, |
int sample) { |
// Use the same parameters as UMA_HISTOGRAM_COUNTS. |
@@ -720,7 +720,7 @@ static MediaKeyException MediaKeyExceptionForUMA( |
// values from above, for reporting to UMA. |
static void ReportMediaKeyExceptionToUMA( |
const std::string& method, |
- const WebString& key_system, |
+ const std::string& key_system, |
WebMediaPlayer::MediaKeyException e) { |
MediaKeyException result_id = MediaKeyExceptionForUMA(e); |
DCHECK_NE(result_id, kUnknownResultId) << e; |
@@ -728,32 +728,40 @@ static void ReportMediaKeyExceptionToUMA( |
key_system, method, result_id, kMaxMediaKeyException); |
} |
+// Convert a WebString to ASCII, falling back on an empty string in the case |
+// of a non-ASCII string. |
+static std::string ToASCIIOrEmpty(const blink::WebString& string) { |
+ return IsStringASCII(string) ? UTF16ToASCII(string) : std::string(); |
+} |
+ |
WebMediaPlayer::MediaKeyException |
WebMediaPlayerImpl::generateKeyRequest(const WebString& key_system, |
const unsigned char* init_data, |
unsigned init_data_length) { |
+ DVLOG(1) << "generateKeyRequest: " << base::string16(key_system) << ": " |
+ << std::string(reinterpret_cast<const char*>(init_data), |
+ static_cast<size_t>(init_data_length)); |
+ |
+ std::string ascii_key_system = ToASCIIOrEmpty(key_system); |
+ |
WebMediaPlayer::MediaKeyException e = |
- GenerateKeyRequestInternal(key_system, init_data, init_data_length); |
- ReportMediaKeyExceptionToUMA("generateKeyRequest", key_system, e); |
+ GenerateKeyRequestInternal(ascii_key_system, init_data, init_data_length); |
+ ReportMediaKeyExceptionToUMA("generateKeyRequest", ascii_key_system, e); |
return e; |
} |
WebMediaPlayer::MediaKeyException |
WebMediaPlayerImpl::GenerateKeyRequestInternal( |
- const WebString& key_system, |
+ const std::string& key_system, |
const unsigned char* init_data, |
unsigned init_data_length) { |
DCHECK(main_loop_->BelongsToCurrentThread()); |
- DVLOG(1) << "generateKeyRequest: " << key_system.utf8().data() << ": " |
- << std::string(reinterpret_cast<const char*>(init_data), |
- static_cast<size_t>(init_data_length)); |
- |
if (!IsConcreteSupportedKeySystem(key_system)) |
return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; |
// We do not support run-time switching between key systems for now. |
- if (current_key_system_.isEmpty()) { |
+ if (current_key_system_.empty()) { |
if (!proxy_decryptor_) { |
proxy_decryptor_.reset(new ProxyDecryptor( |
#if defined(ENABLE_PEPPER_CDMS) |
@@ -765,7 +773,7 @@ WebMediaPlayerImpl::GenerateKeyRequestInternal( |
BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnKeyMessage))); |
} |
- if (!proxy_decryptor_->InitializeCDM(key_system.utf8(), |
+ if (!proxy_decryptor_->InitializeCDM(key_system, |
frame_->document().url())) |
return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; |
@@ -784,7 +792,7 @@ WebMediaPlayerImpl::GenerateKeyRequestInternal( |
// from the application. |
if (!proxy_decryptor_->GenerateKeyRequest( |
init_data_type_, init_data, init_data_length)) { |
- current_key_system_.reset(); |
+ current_key_system_.clear(); |
return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; |
} |
@@ -798,60 +806,73 @@ WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::addKey( |
const unsigned char* init_data, |
unsigned init_data_length, |
const WebString& session_id) { |
- WebMediaPlayer::MediaKeyException e = AddKeyInternal( |
- key_system, key, key_length, init_data, init_data_length, session_id); |
- ReportMediaKeyExceptionToUMA("addKey", key_system, e); |
+ DVLOG(1) << "addKey: " << base::string16(key_system) << ": " |
+ << std::string(reinterpret_cast<const char*>(key), |
+ static_cast<size_t>(key_length)) << ", " |
+ << std::string(reinterpret_cast<const char*>(init_data), |
+ static_cast<size_t>(init_data_length)) |
+ << " [" << base::string16(session_id) << "]"; |
+ |
+ std::string ascii_key_system = ToASCIIOrEmpty(key_system); |
+ std::string ascii_session_id = ToASCIIOrEmpty(session_id); |
+ |
+ WebMediaPlayer::MediaKeyException e = AddKeyInternal(ascii_key_system, |
+ key, |
+ key_length, |
+ init_data, |
+ init_data_length, |
+ ascii_session_id); |
+ ReportMediaKeyExceptionToUMA("addKey", ascii_key_system, e); |
return e; |
} |
WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::AddKeyInternal( |
- const WebString& key_system, |
+ const std::string& key_system, |
const unsigned char* key, |
unsigned key_length, |
const unsigned char* init_data, |
unsigned init_data_length, |
- const WebString& session_id) { |
+ const std::string& session_id) { |
DCHECK(key); |
DCHECK_GT(key_length, 0u); |
- DVLOG(1) << "addKey: " << key_system.utf8().data() << ": " |
- << std::string(reinterpret_cast<const char*>(key), |
- static_cast<size_t>(key_length)) << ", " |
- << std::string(reinterpret_cast<const char*>(init_data), |
- static_cast<size_t>(init_data_length)) |
- << " [" << session_id.utf8().data() << "]"; |
- |
if (!IsConcreteSupportedKeySystem(key_system)) |
return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; |
- if (current_key_system_.isEmpty() || key_system != current_key_system_) |
+ if (current_key_system_.empty() || key_system != current_key_system_) |
return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; |
proxy_decryptor_->AddKey( |
- key, key_length, init_data, init_data_length, session_id.utf8()); |
+ key, key_length, init_data, init_data_length, session_id); |
return WebMediaPlayer::MediaKeyExceptionNoError; |
} |
WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::cancelKeyRequest( |
const WebString& key_system, |
const WebString& session_id) { |
+ DVLOG(1) << "cancelKeyRequest: " << base::string16(key_system) << ": " |
+ << " [" << base::string16(session_id) << "]"; |
+ |
+ std::string ascii_key_system = ToASCIIOrEmpty(key_system); |
+ std::string ascii_session_id = ToASCIIOrEmpty(session_id); |
+ |
WebMediaPlayer::MediaKeyException e = |
- CancelKeyRequestInternal(key_system, session_id); |
- ReportMediaKeyExceptionToUMA("cancelKeyRequest", key_system, e); |
+ CancelKeyRequestInternal(ascii_key_system, ascii_session_id); |
+ ReportMediaKeyExceptionToUMA("cancelKeyRequest", ascii_key_system, e); |
return e; |
} |
WebMediaPlayer::MediaKeyException |
WebMediaPlayerImpl::CancelKeyRequestInternal( |
- const WebString& key_system, |
- const WebString& session_id) { |
+ const std::string& key_system, |
+ const std::string& session_id) { |
if (!IsConcreteSupportedKeySystem(key_system)) |
return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; |
- if (current_key_system_.isEmpty() || key_system != current_key_system_) |
+ if (current_key_system_.empty() || key_system != current_key_system_) |
return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; |
- proxy_decryptor_->CancelKeyRequest(session_id.utf8()); |
+ proxy_decryptor_->CancelKeyRequest(session_id); |
return WebMediaPlayer::MediaKeyExceptionNoError; |
} |
@@ -980,7 +1001,8 @@ void WebMediaPlayerImpl::OnDemuxerOpened() { |
void WebMediaPlayerImpl::OnKeyAdded(const std::string& session_id) { |
DCHECK(main_loop_->BelongsToCurrentThread()); |
EmeUMAHistogramCounts(current_key_system_, "KeyAdded", 1); |
- client_->keyAdded(current_key_system_, WebString::fromUTF8(session_id)); |
+ client_->keyAdded(WebString::fromUTF8(current_key_system_), |
+ WebString::fromUTF8(session_id)); |
} |
void WebMediaPlayerImpl::OnNeedKey(const std::string& type, |
@@ -1037,7 +1059,7 @@ void WebMediaPlayerImpl::OnKeyError(const std::string& session_id, |
error_code, media::MediaKeys::kMaxKeyError); |
client_->keyError( |
- current_key_system_, |
+ WebString::fromUTF8(current_key_system_), |
WebString::fromUTF8(session_id), |
static_cast<blink::WebMediaPlayerClient::MediaKeyErrorCode>(error_code), |
system_code); |
@@ -1052,7 +1074,7 @@ void WebMediaPlayerImpl::OnKeyMessage(const std::string& session_id, |
DLOG_IF(WARNING, !default_url.empty() && !default_url_gurl.is_valid()) |
<< "Invalid URL in default_url: " << default_url; |
- client_->keyMessage(current_key_system_, |
+ client_->keyMessage(WebString::fromUTF8(current_key_system_), |
WebString::fromUTF8(session_id), |
message.empty() ? NULL : &message[0], |
message.size(), |