Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/renderer/media/cdm_session_adapter.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "base/memory/weak_ptr.h" | |
| 10 #include "content/renderer/media/crypto/content_decryption_module_factory.h" | |
| 11 #include "content/renderer/media/webcontentdecryptionmodulesession_impl.h" | |
| 12 #include "media/base/media_keys.h" | |
| 13 #include "url/gurl.h" | |
| 14 | |
| 15 namespace content { | |
| 16 | |
| 17 const uint32 kStartingSessionId = 1; | |
| 18 uint32 CdmSessionAdapter::next_session_id_ = kStartingSessionId; | |
| 19 COMPILE_ASSERT(kStartingSessionId > media::MediaKeys::kInvalidSessionId, | |
| 20 invalid_starting_value); | |
| 21 | |
| 22 CdmSessionAdapter::CdmSessionAdapter() : weak_ptr_factory_(this) {} | |
| 23 | |
| 24 CdmSessionAdapter::~CdmSessionAdapter() {} | |
| 25 | |
| 26 bool CdmSessionAdapter::Initialize(const std::string& key_system) { | |
| 27 base::WeakPtr<CdmSessionAdapter> weak_this = weak_ptr_factory_.GetWeakPtr(); | |
| 28 media_keys_ = | |
| 29 ContentDecryptionModuleFactory::Create( | |
| 30 // TODO(ddorwin): Address lower in the stack: http://crbug.com/252065 | |
| 31 "webkit-" + key_system, | |
| 32 #if defined(ENABLE_PEPPER_CDMS) | |
| 33 // TODO(ddorwin): Support Pepper-based CDMs: http://crbug.com/250049 | |
| 34 NULL, | |
| 35 NULL, | |
| 36 base::Closure(), | |
| 37 #elif defined(OS_ANDROID) | |
| 38 // TODO(xhwang): Support Android. | |
| 39 NULL, | |
| 40 0, | |
| 41 // TODO(ddorwin): Get the URL for the frame containing the MediaKeys. | |
| 42 GURL(), | |
| 43 #endif // defined(ENABLE_PEPPER_CDMS) | |
| 44 base::Bind(&CdmSessionAdapter::OnSessionCreated, weak_this), | |
| 45 base::Bind(&CdmSessionAdapter::OnSessionMessage, weak_this), | |
| 46 base::Bind(&CdmSessionAdapter::OnSessionReady, weak_this), | |
| 47 base::Bind(&CdmSessionAdapter::OnSessionClosed, weak_this), | |
| 48 base::Bind(&CdmSessionAdapter::OnSessionError, weak_this)); | |
| 49 if (!media_keys_) | |
|
ddorwin
2014/02/19 01:41:53
collapse these 4 lines.
OR log the failure if we
jrummell
2014/02/19 20:42:10
Done.
| |
| 50 return false; | |
| 51 | |
| 52 return true; | |
| 53 } | |
| 54 | |
| 55 WebContentDecryptionModuleSessionImpl* CdmSessionAdapter::NewSession( | |
| 56 blink::WebContentDecryptionModuleSession::Client* client) { | |
| 57 // Generate a unique internal session id for the new session. | |
| 58 uint32 session_id = next_session_id_++; | |
| 59 DCHECK(sessions_.find(session_id) == sessions_.end()); | |
| 60 WebContentDecryptionModuleSessionImpl* session = | |
| 61 new WebContentDecryptionModuleSessionImpl(session_id, client, this); | |
| 62 sessions_[session_id] = session; | |
| 63 return session; | |
| 64 } | |
| 65 | |
| 66 void CdmSessionAdapter::RemoveSession(uint32 session_id) { | |
| 67 DCHECK(sessions_.find(session_id) != sessions_.end()); | |
| 68 sessions_.erase(session_id); | |
| 69 } | |
| 70 | |
| 71 void CdmSessionAdapter::CreateSession(uint32 session_id, | |
| 72 const std::string& content_type, | |
| 73 const uint8* init_data, | |
| 74 int init_data_length) { | |
| 75 DCHECK(sessions_.find(session_id) != sessions_.end()); | |
| 76 media_keys_->CreateSession( | |
| 77 session_id, content_type, init_data, init_data_length); | |
| 78 } | |
| 79 | |
| 80 void CdmSessionAdapter::UpdateSession(uint32 session_id, | |
| 81 const uint8* response, | |
| 82 int response_length) { | |
| 83 DCHECK(sessions_.find(session_id) != sessions_.end()); | |
| 84 media_keys_->UpdateSession(session_id, response, response_length); | |
| 85 } | |
| 86 | |
| 87 void CdmSessionAdapter::ReleaseSession(uint32 session_id) { | |
| 88 DCHECK(sessions_.find(session_id) != sessions_.end()); | |
| 89 media_keys_->ReleaseSession(session_id); | |
| 90 } | |
| 91 | |
| 92 media::Decryptor* CdmSessionAdapter::GetDecryptor() { | |
| 93 return media_keys_->GetDecryptor(); | |
| 94 } | |
| 95 | |
| 96 void CdmSessionAdapter::OnSessionCreated(uint32 session_id, | |
| 97 const std::string& web_session_id) { | |
| 98 WebContentDecryptionModuleSessionImpl* session = GetSession(session_id); | |
| 99 if (session) | |
|
ddorwin
2014/02/19 01:41:53
I wonder if we should:
DLOG_IF(session) << __FUNCT
jrummell
2014/02/19 20:42:10
Good idea. Done.
| |
| 100 session->OnSessionCreated(web_session_id); | |
| 101 } | |
| 102 | |
| 103 void CdmSessionAdapter::OnSessionMessage(uint32 session_id, | |
| 104 const std::vector<uint8>& message, | |
| 105 const std::string& destination_url) { | |
| 106 WebContentDecryptionModuleSessionImpl* session = GetSession(session_id); | |
| 107 if (session) | |
| 108 session->OnSessionMessage(message, destination_url); | |
| 109 } | |
| 110 | |
| 111 void CdmSessionAdapter::OnSessionReady(uint32 session_id) { | |
| 112 WebContentDecryptionModuleSessionImpl* session = GetSession(session_id); | |
| 113 if (session) | |
| 114 session->OnSessionReady(); | |
| 115 } | |
| 116 | |
| 117 void CdmSessionAdapter::OnSessionClosed(uint32 session_id) { | |
| 118 WebContentDecryptionModuleSessionImpl* session = GetSession(session_id); | |
| 119 if (session) | |
| 120 session->OnSessionClosed(); | |
| 121 } | |
| 122 | |
| 123 void CdmSessionAdapter::OnSessionError(uint32 session_id, | |
| 124 media::MediaKeys::KeyError error_code, | |
| 125 int system_code) { | |
| 126 WebContentDecryptionModuleSessionImpl* session = GetSession(session_id); | |
| 127 if (session) | |
| 128 session->OnSessionError(error_code, system_code); | |
| 129 } | |
| 130 | |
| 131 WebContentDecryptionModuleSessionImpl* CdmSessionAdapter::GetSession( | |
| 132 uint32 session_id) { | |
| 133 // Since session objects may get garbage collected, it is possible that there | |
| 134 // are events coming back from the CDM and the session has been unregistered. | |
| 135 // We can not tell if the CDM is firing events at sessions that never existed. | |
| 136 SessionMap::iterator session = sessions_.find(session_id); | |
| 137 return (session != sessions_.end()) ? session->second : NULL; | |
| 138 } | |
| 139 | |
| 140 } // namespace content | |
| OLD | NEW |