| Index: content/renderer/media/webcontentdecryptionmodulesession_impl.cc
|
| diff --git a/content/renderer/media/webcontentdecryptionmodulesession_impl.cc b/content/renderer/media/webcontentdecryptionmodulesession_impl.cc
|
| index 14fa798f22333ebfdb745c6dad6b1351507bf640..24d69f38d923e251ad388bbd81938e169107695f 100644
|
| --- a/content/renderer/media/webcontentdecryptionmodulesession_impl.cc
|
| +++ b/content/renderer/media/webcontentdecryptionmodulesession_impl.cc
|
| @@ -4,69 +4,84 @@
|
|
|
| #include "content/renderer/media/webcontentdecryptionmodulesession_impl.h"
|
|
|
| +#include "base/bind.h"
|
| #include "base/callback_helpers.h"
|
| #include "base/logging.h"
|
| #include "base/strings/string_util.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| #include "content/renderer/media/cdm_session_adapter.h"
|
| +#include "media/base/cdm_promise.h"
|
| #include "third_party/WebKit/public/platform/WebURL.h"
|
|
|
| namespace content {
|
|
|
| +#define CreatePromise(type, resolve_method, reject_method) \
|
| + new media::CdmPromise<type>( \
|
| + base::Bind(&WebContentDecryptionModuleSessionImpl::resolve_method, \
|
| + weak_ptr_factory_.GetWeakPtr()), \
|
| + base::Bind(&WebContentDecryptionModuleSessionImpl::reject_method, \
|
| + weak_ptr_factory_.GetWeakPtr()))
|
| +
|
| WebContentDecryptionModuleSessionImpl::WebContentDecryptionModuleSessionImpl(
|
| - uint32 session_id,
|
| Client* client,
|
| const scoped_refptr<CdmSessionAdapter>& adapter)
|
| : adapter_(adapter),
|
| client_(client),
|
| - session_id_(session_id) {
|
| + weak_ptr_factory_(this) {
|
| }
|
|
|
| WebContentDecryptionModuleSessionImpl::
|
| ~WebContentDecryptionModuleSessionImpl() {
|
| - adapter_->RemoveSession(session_id_);
|
| + if (!web_session_id_.empty())
|
| + adapter_->RemoveSession(web_session_id_);
|
| }
|
|
|
| blink::WebString WebContentDecryptionModuleSessionImpl::sessionId() const {
|
| - return web_session_id_;
|
| + return blink::WebString::fromUTF8(web_session_id_);
|
| }
|
|
|
| void WebContentDecryptionModuleSessionImpl::initializeNewSession(
|
| - const blink::WebString& mime_type,
|
| - const uint8* init_data, size_t init_data_length) {
|
| + const blink::WebString& init_data_type,
|
| + const uint8* init_data,
|
| + size_t init_data_length) {
|
| // TODO(ddorwin): Guard against this in supported types check and remove this.
|
| // Chromium only supports ASCII MIME types.
|
| - if (!IsStringASCII(mime_type)) {
|
| + if (!IsStringASCII(init_data_type)) {
|
| NOTREACHED();
|
| - OnSessionError(media::MediaKeys::kUnknownError, 0);
|
| + OnSessionError(media::MediaKeys::MEDIA_KEYS_EXCEPTION_NOT_SUPPORTED_ERROR,
|
| + 0,
|
| + "The initialization data type " + init_data_type.utf8() +
|
| + " is not supported by the key system.");
|
| return;
|
| }
|
|
|
| - adapter_->InitializeNewSession(
|
| - session_id_, base::UTF16ToASCII(mime_type), init_data, init_data_length);
|
| + std::string init_data_type_as_ascii = base::UTF16ToASCII(init_data_type);
|
| + DLOG_IF(WARNING, init_data_type_as_ascii.find('/') != std::string::npos)
|
| + << "init_data_type '" << init_data_type_as_ascii
|
| + << "' may be a MIME type";
|
| +
|
| + scoped_ptr<media::CdmPromise<std::string> > promise(
|
| + CreatePromise(std::string, SessionCreated, SessionCreateFailed));
|
| + adapter_->InitializeNewSession(init_data_type_as_ascii,
|
| + init_data,
|
| + init_data_length,
|
| + media::MediaKeys::SESSION_TYPE_TEMPORARY,
|
| + promise.Pass());
|
| }
|
|
|
| void WebContentDecryptionModuleSessionImpl::update(const uint8* response,
|
| size_t response_length) {
|
| DCHECK(response);
|
| - adapter_->UpdateSession(session_id_, response, response_length);
|
| + scoped_ptr<media::CdmPromise<void> > promise(
|
| + CreatePromise(void, SessionUpdated, SessionUpdateFailed));
|
| + adapter_->UpdateSession(
|
| + web_session_id_, response, response_length, promise.Pass());
|
| }
|
|
|
| void WebContentDecryptionModuleSessionImpl::release() {
|
| - adapter_->ReleaseSession(session_id_);
|
| -}
|
| -
|
| -void WebContentDecryptionModuleSessionImpl::OnSessionCreated(
|
| - const std::string& web_session_id) {
|
| - // Due to heartbeat messages, OnSessionCreated() can get called multiple
|
| - // times.
|
| - // TODO(jrummell): Once all CDMs are updated to support reference ids,
|
| - // OnSessionCreated() should only be called once, and the second check can be
|
| - // removed.
|
| - blink::WebString id = blink::WebString::fromUTF8(web_session_id);
|
| - DCHECK(web_session_id_.isEmpty() || web_session_id_ == id)
|
| - << "Session ID may not be changed once set.";
|
| - web_session_id_ = id;
|
| + scoped_ptr<media::CdmPromise<void> > promise(
|
| + CreatePromise(void, SessionReleased, SessionReleaseFailed));
|
| + adapter_->ReleaseSession(web_session_id_, promise.Pass());
|
| }
|
|
|
| void WebContentDecryptionModuleSessionImpl::OnSessionMessage(
|
| @@ -86,10 +101,63 @@ void WebContentDecryptionModuleSessionImpl::OnSessionClosed() {
|
| }
|
|
|
| void WebContentDecryptionModuleSessionImpl::OnSessionError(
|
| - media::MediaKeys::KeyError error_code,
|
| - uint32 system_code) {
|
| - client_->error(static_cast<Client::MediaKeyErrorCode>(error_code),
|
| - system_code);
|
| + media::MediaKeys::MediaKeysException exception_code,
|
| + uint32 system_code,
|
| + const std::string& error_message) {
|
| + // Convert |exception_code| back to MediaKeyErrorCode if possible.
|
| + // TODO(jrummell): Update this conversion when promises flow
|
| + // back into blink:: (as blink:: will have it's own error definition).
|
| + switch (exception_code) {
|
| + case media::MediaKeys::MEDIA_KEYS_EXCEPTION_CLIENT_ERROR:
|
| + client_->error(Client::MediaKeyErrorCodeClient, system_code);
|
| + break;
|
| + default:
|
| + // This will include all other CDM4 errors and any error generated
|
| + // by CDM5 or later.
|
| + client_->error(Client::MediaKeyErrorCodeUnknown, system_code);
|
| + break;
|
| + }
|
| +}
|
| +
|
| +void WebContentDecryptionModuleSessionImpl::SessionCreated(
|
| + const std::string& web_session_id) {
|
| + DCHECK(web_session_id_.empty()) << "Session ID may not be changed once set.";
|
| + web_session_id_ = web_session_id;
|
| + adapter_->RegisterSession(web_session_id_, weak_ptr_factory_.GetWeakPtr());
|
| +}
|
| +
|
| +void WebContentDecryptionModuleSessionImpl::SessionCreateFailed(
|
| + media::MediaKeys::MediaKeysException exception_code,
|
| + uint32 system_code,
|
| + const std::string& error_message) {
|
| + // For now, just report this as an error back to blink::.
|
| + OnSessionError(exception_code, system_code, error_message);
|
| +}
|
| +
|
| +void WebContentDecryptionModuleSessionImpl::SessionUpdated() {
|
| + // Pass back to blink:: as a ready event.
|
| + OnSessionReady();
|
| +}
|
| +
|
| +void WebContentDecryptionModuleSessionImpl::SessionUpdateFailed(
|
| + media::MediaKeys::MediaKeysException exception_code,
|
| + uint32 system_code,
|
| + const std::string& error_message) {
|
| + // For now, just report this as an error back to blink::.
|
| + OnSessionError(exception_code, system_code, error_message);
|
| +}
|
| +
|
| +void WebContentDecryptionModuleSessionImpl::SessionReleased() {
|
| + // Pass back to blink:: as a closed event.
|
| + OnSessionClosed();
|
| +}
|
| +
|
| +void WebContentDecryptionModuleSessionImpl::SessionReleaseFailed(
|
| + media::MediaKeys::MediaKeysException exception_code,
|
| + uint32 system_code,
|
| + const std::string& error_message) {
|
| + // For now, just report this as an error back to blink::.
|
| + OnSessionError(exception_code, system_code, error_message);
|
| }
|
|
|
| } // namespace content
|
|
|