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..525ec73d74aad226caa89c67aba69494b5285ecd 100644 |
--- a/content/renderer/media/webcontentdecryptionmodulesession_impl.cc |
+++ b/content/renderer/media/webcontentdecryptionmodulesession_impl.cc |
@@ -4,69 +4,87 @@ |
#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/media_keys.h" |
ddorwin
2014/05/05 18:35:42
duplicate with .h
jrummell
2014/05/08 23:37:45
Done.
|
+#include "media/base/media_keys_session_promise.h" |
#include "third_party/WebKit/public/platform/WebURL.h" |
namespace content { |
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( |
ddorwin
2014/05/05 18:35:42
I wonder if we'll eventually want to move session
|
- const blink::WebString& mime_type, |
- const uint8* init_data, size_t init_data_length) { |
+ const blink::WebString& init_data_type, |
ddorwin
2014/05/05 18:35:42
We might want to DLOG(WARNING) if this includes a
jrummell
2014/05/08 23:37:45
Done.
|
+ 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("InvalidCharacterError", |
ddorwin
2014/05/05 18:35:42
This is a Chromium choice, not a spec issue, so we
jrummell
2014/05/08 23:37:45
Done.
|
+ 0, |
+ "init_data_type contains non-ASCII characters."); |
return; |
} |
- adapter_->InitializeNewSession( |
- session_id_, base::UTF16ToASCII(mime_type), init_data, init_data_length); |
+ scoped_ptr<media::MediaKeysSessionPromise> promise( |
+ new media::MediaKeysSessionPromise( |
+ media::PromiseResolvedCB(), |
ddorwin
2014/05/05 18:35:42
This is weird. As noted in the promise header, we
jrummell
2014/05/08 23:37:45
Done.
|
+ base::Bind(&WebContentDecryptionModuleSessionImpl::setSessionId, |
ddorwin
2014/05/05 18:35:42
I think we're going to need to do more than set th
jrummell
2014/05/08 23:37:45
Done.
|
+ weak_ptr_factory_.GetWeakPtr()), |
+ base::Bind(&WebContentDecryptionModuleSessionImpl::OnSessionError, |
ddorwin
2014/05/05 18:35:42
Even if we rely on the same code in the interim, t
jrummell
2014/05/08 23:37:45
Done.
|
+ weak_ptr_factory_.GetWeakPtr()))); |
+ adapter_->InitializeNewSession(base::UTF16ToASCII(init_data_type), |
+ init_data, |
+ init_data_length, |
+ media::MediaKeys::SessionType::kTemporary, |
+ promise.Pass()); |
} |
void WebContentDecryptionModuleSessionImpl::update(const uint8* response, |
size_t response_length) { |
DCHECK(response); |
- adapter_->UpdateSession(session_id_, response, response_length); |
+ scoped_ptr<media::MediaKeysSessionPromise> promise( |
ddorwin
2014/05/05 18:35:42
You might consider helper functions for creating t
jrummell
2014/05/08 23:37:45
Done as a macro. If everybody is OK with it, I'll
|
+ new media::MediaKeysSessionPromise( |
+ base::Bind(&WebContentDecryptionModuleSessionImpl::OnSessionReady, |
+ weak_ptr_factory_.GetWeakPtr()), |
+ media::PromiseResolvedWithSessionCB(), |
+ base::Bind(&WebContentDecryptionModuleSessionImpl::OnSessionError, |
+ weak_ptr_factory_.GetWeakPtr()))); |
+ 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::MediaKeysSessionPromise> promise( |
+ new media::MediaKeysSessionPromise( |
+ base::Bind(&WebContentDecryptionModuleSessionImpl::OnSessionClosed, |
+ weak_ptr_factory_.GetWeakPtr()), |
+ media::PromiseResolvedWithSessionCB(), |
+ base::Bind(&WebContentDecryptionModuleSessionImpl::OnSessionError, |
+ weak_ptr_factory_.GetWeakPtr()))); |
+ adapter_->ReleaseSession(web_session_id_, promise.Pass()); |
} |
void WebContentDecryptionModuleSessionImpl::OnSessionMessage( |
@@ -86,10 +104,28 @@ void WebContentDecryptionModuleSessionImpl::OnSessionClosed() { |
} |
void WebContentDecryptionModuleSessionImpl::OnSessionError( |
- media::MediaKeys::KeyError error_code, |
- uint32 system_code) { |
- client_->error(static_cast<Client::MediaKeyErrorCode>(error_code), |
- system_code); |
+ const std::string& error_name, |
+ uint32 system_code, |
+ const std::string& error_message) { |
+ // Convert |error_name| back to MediaKeyErrorCode if possible. |
+ // TODO(jrummell): Remove this conversion when promises flow |
+ // back into blink:: (as the code there will handle the names). |
ddorwin
2014/05/05 18:35:42
Not if it is "CDM4ClientError"
jrummell
2014/05/08 23:37:45
True. Changes with exception_code.
|
+ if (error_name == "CDM4ClientError") { |
ddorwin
2014/05/05 18:35:42
What about output error?
jrummell
2014/05/08 23:37:45
Client doesn't have a output error. Only unknown a
|
+ client_->error(Client::MediaKeyErrorCode::MediaKeyErrorCodeClient, |
+ system_code); |
+ } else { |
+ // This will include all other CDM4 errors and any error generated |
+ // by CDM5 or later. |
+ client_->error(Client::MediaKeyErrorCode::MediaKeyErrorCodeUnknown, |
+ system_code); |
+ } |
+} |
+ |
+void WebContentDecryptionModuleSessionImpl::setSessionId( |
+ 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()); |
} |
} // namespace content |