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

Unified Diff: webkit/media/webmediaplayer_impl.cc

Issue 10020053: Initial implementation of Encrypted Media Extensions in Chrome. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: review feedback Created 8 years, 8 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 e5afb5d04cf465be009f49053a6fa792c62447df..aa5f80e83999140e1270436b5186e0371d289706 100644
--- a/webkit/media/webmediaplayer_impl.cc
+++ b/webkit/media/webmediaplayer_impl.cc
@@ -12,6 +12,7 @@
#include "base/command_line.h"
#include "base/message_loop_proxy.h"
#include "base/metrics/histogram.h"
+#include "base/string_number_conversions.h"
#include "base/synchronization/waitable_event.h"
#include "media/audio/null_audio_sink.h"
#include "media/base/filter_collection.h"
@@ -26,10 +27,12 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
#include "v8/include/v8.h"
#include "webkit/media/buffered_data_source.h"
#include "webkit/media/filter_helpers.h"
+#include "webkit/media/mime_util.h"
#include "webkit/media/webmediaplayer_delegate.h"
#include "webkit/media/webmediaplayer_proxy.h"
#include "webkit/media/webvideoframe_impl.h"
@@ -668,6 +671,57 @@ void WebMediaPlayerImpl::sourceEndOfStream(
proxy_->DemuxerEndOfStream(pipeline_status);
}
+WebKit::WebMediaPlayer::MediaKeyException
+WebMediaPlayerImpl::generateKeyRequest(const WebKit::WebString& key_system,
+ const unsigned char* init_data,
+ unsigned init_data_length) {
+ if (!mime_util::isKeySystemSupported(key_system))
+ return WebKit::WebMediaPlayer::KeySystemNotSupported;
+
+ MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
+ &WebMediaPlayerImpl::generateKeyRequestTask,
scherkus (not reviewing) 2012/04/13 02:43:59 this (and rest of args) should be indented 4 space
ddorwin 2012/04/13 21:48:49 Done. I misinterpreted your preferred style commen
+ AsWeakPtr(),
+ key_system,
+ init_data,
+ init_data_length));
+
+ return WebKit::WebMediaPlayer::NoError;
+}
+
+WebKit::WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::addKey(
+ const WebKit::WebString& key_system,
+ const unsigned char* key,
+ unsigned key_length,
+ const unsigned char* init_data,
+ unsigned init_data_length,
+ const WebKit::WebString& session_id) {
+ if (!mime_util::isKeySystemSupported(key_system))
+ return WebKit::WebMediaPlayer::KeySystemNotSupported;
+
+ MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
+ &WebMediaPlayerImpl::addKeyTask,
+ AsWeakPtr(),
+ key_system,
+ key,
+ key_length,
+ init_data,
+ init_data_length,
+ session_id));
+
+ return WebKit::WebMediaPlayer::NoError;
+}
+
+WebKit::WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::cancelKeyRequest(
+ const WebKit::WebString& key_system,
+ const WebKit::WebString& session_id) {
+ if (!mime_util::isKeySystemSupported(key_system))
+ return WebKit::WebMediaPlayer::KeySystemNotSupported;
+
+ // TODO(ddorwin): Cancel the key request in the decrypter.
+
+ return WebKit::WebMediaPlayer::NoError;
+}
+
void WebMediaPlayerImpl::WillDestroyCurrentMessageLoop() {
Destroy();
main_loop_ = NULL;
@@ -920,4 +974,59 @@ void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() {
v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory);
}
+void WebMediaPlayerImpl::generateKeyRequestTask(
scherkus (not reviewing) 2012/04/13 02:43:59 per email discussion just nuke these tasks for now
ddorwin 2012/04/13 21:48:49 Done.
+ const WebKit::WebString& key_system,
+ const unsigned char* init_data,
+ unsigned init_data_length) {
+ // 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
scherkus (not reviewing) 2012/04/13 02:43:59 I do have to say this is one area that makes me th
ddorwin 2012/04/13 21:48:49 Filing a bug on this is on my task list (also affe
ddorwin 2012/04/13 22:29:03 Filed: https://www.w3.org/Bugs/Public/show_bug.cgi
+ // need globally unique IDs.
+ static uint32_t next_available_session_id = 1;
+ uint32_t session_id = next_available_session_id++;
+
+ WebKit::WebString sessionIdString(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))
+ << " [" << sessionIdString.utf8().data() << "]";
+
+ // TODO(ddorwin): Generate a key request in the decrypter 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 messageLength = init_data_length;
+
+ GetClient()->keyMessage(key_system, sessionIdString, message, messageLength);
+}
+
+void WebMediaPlayerImpl::addKeyTask(const WebKit::WebString& key_system,
+ const unsigned char* key,
+ unsigned key_length,
+ const unsigned char* init_data,
+ unsigned init_data_length,
+ const WebKit::WebString& session_id) {
+ 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() << "]";
+
+ // TODO(ddorwin): Add the key to the decrypter and fire keyAdded when it
+ // completes. Check the key length there.
+ // 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 int kSupportedKeyLength = 16; // 128-bit key.
+ if (key_length != kSupportedKeyLength) {
+ DLOG(ERROR) << "invalid key length: " << key_length;
+ GetClient()->keyError(key_system, session_id,
+ WebKit::WebMediaPlayerClient::UnknownError, 0);
+ return;
+ }
+
+ GetClient()->keyAdded(key_system, session_id);
+}
+
} // namespace webkit_media

Powered by Google App Engine
This is Rietveld 408576698