Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(407)

Unified Diff: webkit/media/webmediaplayer_impl.cc

Issue 10534096: Generalize AesDecryptor to make it more spec compliant. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webkit/media/webmediaplayer_impl.cc
diff --git a/webkit/media/webmediaplayer_impl.cc b/webkit/media/webmediaplayer_impl.cc
index 66a36faef819a603ef34081053131cea1759ed6a..984daed300fdaa1181e461090fa9cbff0b4812bc 100644
--- a/webkit/media/webmediaplayer_impl.cc
+++ b/webkit/media/webmediaplayer_impl.cc
@@ -6,6 +6,7 @@
#include <limits>
#include <string>
+#include <vector>
#include "base/bind.h"
#include "base/callback.h"
@@ -157,6 +158,7 @@ WebMediaPlayerImpl::WebMediaPlayerImpl(
new media::AudioRendererImpl(new media::NullAudioSink()));
decryptor_.reset(new media::AesDecryptor());
+ decryptor_->Init(proxy_.get());
}
WebMediaPlayerImpl::~WebMediaPlayerImpl() {
@@ -699,7 +701,7 @@ void WebMediaPlayerImpl::sourceEndOfStream(
DCHECK_EQ(main_loop_, MessageLoop::current());
media::PipelineStatus pipeline_status = media::PIPELINE_OK;
- switch(status) {
+ switch (status) {
case WebMediaPlayer::EndOfStreamStatusNoError:
break;
case WebMediaPlayer::EndOfStreamStatusNetworkError:
@@ -722,36 +724,12 @@ WebMediaPlayerImpl::generateKeyRequest(const WebString& key_system,
if (!IsSupportedKeySystem(key_system))
return WebKit::WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported;
- // Every request call creates a unique ID.
- // TODO(ddorwin): Move this to the CDM implementations since the CDMs may
- // create their own IDs and since CDMs supporting multiple renderer processes
- // need globally unique IDs.
- // Everything from here until the return should probably be handled by
- // the decryptor - see http://crbug.com/123260.
- static uint32_t next_available_session_id = 1;
- uint32_t session_id = next_available_session_id++;
-
- WebString session_id_string(base::UintToString16(session_id));
-
DVLOG(1) << "generateKeyRequest: " << key_system.utf8().data() << ": "
<< std::string(reinterpret_cast<const char*>(init_data),
- static_cast<size_t>(init_data_length))
- << " [" << session_id_string.utf8().data() << "]";
-
- // TODO(ddorwin): Generate a key request in the decryptor and fire
- // keyMessage when it completes.
- // For now, just fire the event with the init_data as the request.
- const unsigned char* message = init_data;
- unsigned message_length = init_data_length;
-
- MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
- &WebKit::WebMediaPlayerClient::keyMessage,
- base::Unretained(GetClient()),
- key_system,
- session_id_string,
- message,
- message_length));
+ static_cast<size_t>(init_data_length));
+ decryptor_->GenerateKeyRequest(key_system.utf8(),
ddorwin 2012/06/11 21:02:40 At some point, we will need to post these operatio
xhwang 2012/06/12 19:01:15 I suppose these key operations called on the rende
+ init_data, init_data_length);
return WebKit::WebMediaPlayer::MediaKeyExceptionNoError;
}
@@ -768,7 +746,6 @@ WebKit::WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::addKey(
if (!IsSupportedKeySystem(key_system))
return WebKit::WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported;
-
DVLOG(1) << "addKey: " << key_system.utf8().data() << ": "
<< std::string(reinterpret_cast<const char*>(key),
static_cast<size_t>(key_length)) << ", "
@@ -776,38 +753,8 @@ WebKit::WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::addKey(
static_cast<size_t>(init_data_length))
<< " [" << session_id.utf8().data() << "]";
- // TODO(ddorwin): Everything from here until the return should probably be
- // handled by the decryptor - see http://crbug.com/123260.
- // Temporarily, fire an error for invalid key length so we can test the error
- // event and fire the keyAdded event in all other cases.
- const unsigned kSupportedKeyLength = 16; // 128-bit key.
- if (key_length != kSupportedKeyLength) {
- DLOG(ERROR) << "addKey: invalid key length: " << key_length;
- MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
- &WebKit::WebMediaPlayerClient::keyError,
- base::Unretained(GetClient()),
- key_system,
- session_id,
- WebKit::WebMediaPlayerClient::MediaKeyErrorCodeUnknown,
- 0));
- } else {
- // TODO(ddorwin): Fix the decryptor to accept no |init_data|. See
- // http://crbug.com/123265. Until then, ensure a non-empty value is passed.
- static const unsigned char kDummyInitData[1] = {0};
- if (!init_data) {
- init_data = kDummyInitData;
- init_data_length = arraysize(kDummyInitData);
- }
-
- decryptor_->AddKey(init_data, init_data_length, key, key_length);
-
- MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
- &WebKit::WebMediaPlayerClient::keyAdded,
- base::Unretained(GetClient()),
- key_system,
- session_id));
- }
-
+ decryptor_->AddKey(key_system.utf8(), init_data, init_data_length,
+ key, key_length, session_id.utf8());
return WebKit::WebMediaPlayer::MediaKeyExceptionNoError;
}
@@ -817,8 +764,7 @@ WebKit::WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::cancelKeyRequest(
if (!IsSupportedKeySystem(key_system))
return WebKit::WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported;
- // TODO(ddorwin): Cancel the key request in the decryptor.
-
+ decryptor_->CancelKeyRequest(key_system.utf8(), session_id.utf8());
return WebKit::WebMediaPlayer::MediaKeyExceptionNoError;
}
@@ -931,7 +877,7 @@ void WebMediaPlayerImpl::OnPipelineError(PipelineStatus error) {
void WebMediaPlayerImpl::OnNetworkEvent(NetworkEvent type) {
DCHECK_EQ(main_loop_, MessageLoop::current());
- switch(type) {
+ switch (type) {
case media::DOWNLOAD_CONTINUED:
SetNetworkState(WebMediaPlayer::NetworkStateLoading);
break;
@@ -955,11 +901,50 @@ void WebMediaPlayerImpl::OnDemuxerOpened() {
GetClient()->sourceOpened();
}
-void WebMediaPlayerImpl::OnKeyNeeded(scoped_array<uint8> init_data,
+void WebMediaPlayerImpl::OnKeyAdded(const std::string& key_system,
+ const std::string& session_id) {
+ DCHECK_EQ(main_loop_, MessageLoop::current());
+
+ GetClient()->keyAdded(WebString::fromUTF8(key_system),
+ WebString::fromUTF8(session_id));
+}
+
+void WebMediaPlayerImpl::OnKeyNeeded(const std::string& key_system,
+ const std::string& session_id,
+ scoped_array<uint8> init_data,
int init_data_size) {
DCHECK_EQ(main_loop_, MessageLoop::current());
- GetClient()->keyNeeded("", "", init_data.get(), init_data_size);
+ GetClient()->keyNeeded(WebString::fromUTF8(key_system),
+ WebString::fromUTF8(session_id),
+ init_data.get(),
+ init_data_size);
+}
+
+void WebMediaPlayerImpl::OnKeyError(const std::string& key_system,
+ const std::string& session_id,
+ media::AesDecryptor::KeyError error_code,
+ int system_code) {
+ DCHECK_EQ(main_loop_, MessageLoop::current());
+
+ GetClient()->keyError(
+ WebString::fromUTF8(key_system),
+ WebString::fromUTF8(session_id),
+ static_cast<WebKit::WebMediaPlayerClient::MediaKeyErrorCode>(error_code),
+ system_code);
+}
+
+void WebMediaPlayerImpl::OnKeyMessage(const std::string& key_system,
+ const std::string& session_id,
+ scoped_array<uint8> message,
+ int message_length,
+ const std::string& /* default_url */) {
+ DCHECK_EQ(main_loop_, MessageLoop::current());
+
+ GetClient()->keyMessage(WebString::fromUTF8(key_system),
+ WebString::fromUTF8(session_id),
+ message.get(),
+ message_length);
}
void WebMediaPlayerImpl::SetOpaque(bool opaque) {

Powered by Google App Engine
This is Rietveld 408576698