OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/media/cdm_session_adapter.h" | 5 #include "content/renderer/media/cdm_session_adapter.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 security_origin, | 43 security_origin, |
44 #if defined(ENABLE_PEPPER_CDMS) | 44 #if defined(ENABLE_PEPPER_CDMS) |
45 create_pepper_cdm_cb, | 45 create_pepper_cdm_cb, |
46 #elif defined(ENABLE_BROWSER_CDMS) | 46 #elif defined(ENABLE_BROWSER_CDMS) |
47 manager, | 47 manager, |
48 &cdm_id_, | 48 &cdm_id_, |
49 #endif // defined(ENABLE_PEPPER_CDMS) | 49 #endif // defined(ENABLE_PEPPER_CDMS) |
50 base::Bind(&CdmSessionAdapter::OnSessionMessage, weak_this), | 50 base::Bind(&CdmSessionAdapter::OnSessionMessage, weak_this), |
51 base::Bind(&CdmSessionAdapter::OnSessionReady, weak_this), | 51 base::Bind(&CdmSessionAdapter::OnSessionReady, weak_this), |
52 base::Bind(&CdmSessionAdapter::OnSessionClosed, weak_this), | 52 base::Bind(&CdmSessionAdapter::OnSessionClosed, weak_this), |
53 base::Bind(&CdmSessionAdapter::OnSessionError, weak_this)); | 53 base::Bind(&CdmSessionAdapter::OnSessionError, weak_this), |
| 54 base::Bind(&CdmSessionAdapter::OnSessionKeysChange, weak_this), |
| 55 base::Bind(&CdmSessionAdapter::OnSessionExpirationUpdate, weak_this)); |
54 | 56 |
55 // Success if |media_keys_| created. | 57 // Success if |media_keys_| created. |
56 return media_keys_; | 58 return media_keys_; |
57 } | 59 } |
58 | 60 |
| 61 void CdmSessionAdapter::SetServerCertificate( |
| 62 const uint8* server_certificate, |
| 63 int server_certificate_length, |
| 64 scoped_ptr<media::SimpleCdmPromise> promise) { |
| 65 media_keys_->SetServerCertificate( |
| 66 server_certificate, server_certificate_length, promise.Pass()); |
| 67 } |
| 68 |
59 WebContentDecryptionModuleSessionImpl* CdmSessionAdapter::CreateSession() { | 69 WebContentDecryptionModuleSessionImpl* CdmSessionAdapter::CreateSession() { |
60 return new WebContentDecryptionModuleSessionImpl(this); | 70 return new WebContentDecryptionModuleSessionImpl(this); |
61 } | 71 } |
62 | 72 |
63 bool CdmSessionAdapter::RegisterSession( | 73 bool CdmSessionAdapter::RegisterSession( |
64 const std::string& web_session_id, | 74 const std::string& web_session_id, |
65 base::WeakPtr<WebContentDecryptionModuleSessionImpl> session) { | 75 base::WeakPtr<WebContentDecryptionModuleSessionImpl> session) { |
66 // If this session ID is already registered, don't register it again. | 76 // If this session ID is already registered, don't register it again. |
67 if (ContainsKey(sessions_, web_session_id)) | 77 if (ContainsKey(sessions_, web_session_id)) |
68 return false; | 78 return false; |
69 | 79 |
70 sessions_[web_session_id] = session; | 80 sessions_[web_session_id] = session; |
71 return true; | 81 return true; |
72 } | 82 } |
73 | 83 |
74 void CdmSessionAdapter::RemoveSession(const std::string& web_session_id) { | 84 void CdmSessionAdapter::UnregisterSession(const std::string& web_session_id) { |
75 DCHECK(ContainsKey(sessions_, web_session_id)); | 85 DCHECK(ContainsKey(sessions_, web_session_id)); |
76 sessions_.erase(web_session_id); | 86 sessions_.erase(web_session_id); |
77 } | 87 } |
78 | 88 |
79 void CdmSessionAdapter::InitializeNewSession( | 89 void CdmSessionAdapter::InitializeNewSession( |
80 const std::string& init_data_type, | 90 const std::string& init_data_type, |
81 const uint8* init_data, | 91 const uint8* init_data, |
82 int init_data_length, | 92 int init_data_length, |
83 media::MediaKeys::SessionType session_type, | 93 media::MediaKeys::SessionType session_type, |
84 scoped_ptr<media::NewSessionCdmPromise> promise) { | 94 scoped_ptr<media::NewSessionCdmPromise> promise) { |
85 media_keys_->CreateSession(init_data_type, | 95 media_keys_->CreateSession(init_data_type, |
86 init_data, | 96 init_data, |
87 init_data_length, | 97 init_data_length, |
88 session_type, | 98 session_type, |
89 promise.Pass()); | 99 promise.Pass()); |
90 } | 100 } |
91 | 101 |
92 void CdmSessionAdapter::UpdateSession( | 102 void CdmSessionAdapter::UpdateSession( |
93 const std::string& web_session_id, | 103 const std::string& web_session_id, |
94 const uint8* response, | 104 const uint8* response, |
95 int response_length, | 105 int response_length, |
96 scoped_ptr<media::SimpleCdmPromise> promise) { | 106 scoped_ptr<media::SimpleCdmPromise> promise) { |
97 media_keys_->UpdateSession( | 107 media_keys_->UpdateSession( |
98 web_session_id, response, response_length, promise.Pass()); | 108 web_session_id, response, response_length, promise.Pass()); |
99 } | 109 } |
100 | 110 |
101 void CdmSessionAdapter::ReleaseSession( | 111 void CdmSessionAdapter::CloseSession( |
102 const std::string& web_session_id, | 112 const std::string& web_session_id, |
103 scoped_ptr<media::SimpleCdmPromise> promise) { | 113 scoped_ptr<media::SimpleCdmPromise> promise) { |
104 media_keys_->ReleaseSession(web_session_id, promise.Pass()); | 114 media_keys_->CloseSession(web_session_id, promise.Pass()); |
| 115 } |
| 116 |
| 117 void CdmSessionAdapter::RemoveSession( |
| 118 const std::string& web_session_id, |
| 119 scoped_ptr<media::SimpleCdmPromise> promise) { |
| 120 media_keys_->RemoveSession(web_session_id, promise.Pass()); |
| 121 } |
| 122 |
| 123 void CdmSessionAdapter::GetUsableKeyIds( |
| 124 const std::string& web_session_id, |
| 125 scoped_ptr<media::KeyIdsPromise> promise) { |
| 126 media_keys_->GetUsableKeyIds(web_session_id, promise.Pass()); |
105 } | 127 } |
106 | 128 |
107 media::Decryptor* CdmSessionAdapter::GetDecryptor() { | 129 media::Decryptor* CdmSessionAdapter::GetDecryptor() { |
108 return media_keys_->GetDecryptor(); | 130 return media_keys_->GetDecryptor(); |
109 } | 131 } |
110 | 132 |
111 const std::string& CdmSessionAdapter::GetKeySystemUMAPrefix() const { | 133 const std::string& CdmSessionAdapter::GetKeySystemUMAPrefix() const { |
112 return key_system_uma_prefix_; | 134 return key_system_uma_prefix_; |
113 } | 135 } |
114 | 136 |
115 #if defined(ENABLE_BROWSER_CDMS) | 137 #if defined(ENABLE_BROWSER_CDMS) |
116 int CdmSessionAdapter::GetCdmId() const { | 138 int CdmSessionAdapter::GetCdmId() const { |
117 return cdm_id_; | 139 return cdm_id_; |
118 } | 140 } |
119 #endif // defined(ENABLE_BROWSER_CDMS) | 141 #endif // defined(ENABLE_BROWSER_CDMS) |
120 | 142 |
121 void CdmSessionAdapter::OnSessionMessage(const std::string& web_session_id, | 143 void CdmSessionAdapter::OnSessionMessage(const std::string& web_session_id, |
122 const std::vector<uint8>& message, | 144 const std::vector<uint8>& message, |
123 const GURL& destination_url) { | 145 const GURL& destination_url) { |
124 WebContentDecryptionModuleSessionImpl* session = GetSession(web_session_id); | 146 WebContentDecryptionModuleSessionImpl* session = GetSession(web_session_id); |
125 DLOG_IF(WARNING, !session) << __FUNCTION__ << " for unknown session " | 147 DLOG_IF(WARNING, !session) << __FUNCTION__ << " for unknown session " |
126 << web_session_id; | 148 << web_session_id; |
127 if (session) | 149 if (session) |
128 session->OnSessionMessage(message, destination_url); | 150 session->OnSessionMessage(message, destination_url); |
129 } | 151 } |
130 | 152 |
| 153 void CdmSessionAdapter::OnSessionKeysChange(const std::string& web_session_id, |
| 154 bool has_additional_usable_key) { |
| 155 WebContentDecryptionModuleSessionImpl* session = GetSession(web_session_id); |
| 156 DLOG_IF(WARNING, !session) << __FUNCTION__ << " for unknown session " |
| 157 << web_session_id; |
| 158 if (session) |
| 159 session->OnSessionKeysChange(has_additional_usable_key); |
| 160 } |
| 161 |
| 162 void CdmSessionAdapter::OnSessionExpirationUpdate( |
| 163 const std::string& web_session_id, |
| 164 const base::Time& new_expiry_time) { |
| 165 WebContentDecryptionModuleSessionImpl* session = GetSession(web_session_id); |
| 166 DLOG_IF(WARNING, !session) << __FUNCTION__ << " for unknown session " |
| 167 << web_session_id; |
| 168 if (session) |
| 169 session->OnSessionExpirationUpdate(new_expiry_time); |
| 170 } |
| 171 |
131 void CdmSessionAdapter::OnSessionReady(const std::string& web_session_id) { | 172 void CdmSessionAdapter::OnSessionReady(const std::string& web_session_id) { |
132 WebContentDecryptionModuleSessionImpl* session = GetSession(web_session_id); | 173 WebContentDecryptionModuleSessionImpl* session = GetSession(web_session_id); |
133 DLOG_IF(WARNING, !session) << __FUNCTION__ << " for unknown session " | 174 DLOG_IF(WARNING, !session) << __FUNCTION__ << " for unknown session " |
134 << web_session_id; | 175 << web_session_id; |
135 if (session) | 176 if (session) |
136 session->OnSessionReady(); | 177 session->OnSessionReady(); |
137 } | 178 } |
138 | 179 |
139 void CdmSessionAdapter::OnSessionClosed(const std::string& web_session_id) { | 180 void CdmSessionAdapter::OnSessionClosed(const std::string& web_session_id) { |
140 WebContentDecryptionModuleSessionImpl* session = GetSession(web_session_id); | 181 WebContentDecryptionModuleSessionImpl* session = GetSession(web_session_id); |
(...skipping 18 matching lines...) Expand all Loading... |
159 WebContentDecryptionModuleSessionImpl* CdmSessionAdapter::GetSession( | 200 WebContentDecryptionModuleSessionImpl* CdmSessionAdapter::GetSession( |
160 const std::string& web_session_id) { | 201 const std::string& web_session_id) { |
161 // Since session objects may get garbage collected, it is possible that there | 202 // Since session objects may get garbage collected, it is possible that there |
162 // are events coming back from the CDM and the session has been unregistered. | 203 // are events coming back from the CDM and the session has been unregistered. |
163 // We can not tell if the CDM is firing events at sessions that never existed. | 204 // We can not tell if the CDM is firing events at sessions that never existed. |
164 SessionMap::iterator session = sessions_.find(web_session_id); | 205 SessionMap::iterator session = sessions_.find(web_session_id); |
165 return (session != sessions_.end()) ? session->second.get() : NULL; | 206 return (session != sessions_.end()) ? session->second.get() : NULL; |
166 } | 207 } |
167 | 208 |
168 } // namespace content | 209 } // namespace content |
OLD | NEW |