Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "webcontentdecryptionmodulesession_impl.h" | 5 #include "webcontentdecryptionmodulesession_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/numerics/safe_conversions.h" | 10 #include "base/numerics/safe_conversions.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "media/base/cdm_key_information.h" | 13 #include "media/base/cdm_key_information.h" |
| 14 #include "media/base/cdm_promise.h" | 14 #include "media/base/cdm_promise.h" |
| 15 #include "media/base/media_keys.h" | 15 #include "media/base/media_keys.h" |
| 16 #include "media/blink/cdm_result_promise.h" | 16 #include "media/blink/cdm_result_promise.h" |
| 17 #include "media/blink/cdm_session_adapter.h" | 17 #include "media/blink/cdm_session_adapter.h" |
| 18 #include "media/blink/new_session_cdm_result_promise.h" | 18 #include "media/blink/new_session_cdm_result_promise.h" |
| 19 #include "third_party/WebKit/public/platform/WebData.h" | 19 #include "third_party/WebKit/public/platform/WebData.h" |
| 20 #include "third_party/WebKit/public/platform/WebEncryptedMediaKeyInformation.h" | 20 #include "third_party/WebKit/public/platform/WebEncryptedMediaKeyInformation.h" |
| 21 #include "third_party/WebKit/public/platform/WebString.h" | 21 #include "third_party/WebKit/public/platform/WebString.h" |
| 22 #include "third_party/WebKit/public/platform/WebURL.h" | 22 #include "third_party/WebKit/public/platform/WebURL.h" |
| 23 #include "third_party/WebKit/public/platform/WebVector.h" | 23 #include "third_party/WebKit/public/platform/WebVector.h" |
| 24 | 24 |
| 25 namespace media { | 25 namespace media { |
| 26 | 26 |
| 27 const char kCreateSessionUMAName[] = "CreateSession"; | 27 const char kGenerateRequestUMAName[] = "GenerateRequest"; |
| 28 const char kLoadSessionUMAName[] = "LoadSession"; | 28 const char kLoadSessionUMAName[] = "LoadSession"; |
| 29 const char kUpdateSessionUMAName[] = "UpdateSession"; | |
| 30 const char kCloseSessionUMAName[] = "CloseSession"; | |
| 31 const char kRemoveSessionUMAName[] = "RemoveSession"; | |
|
Ilya Sherman
2015/01/27 00:28:31
nit: Mebbe alphabetize?
jrummell
2015/01/27 01:18:21
Done.
| |
| 29 | 32 |
| 30 // TODO(jrummell): Pass an enum from blink. http://crbug.com/418239. | 33 // TODO(jrummell): Pass an enum from blink. http://crbug.com/418239. |
| 31 const char kTemporarySessionType[] = "temporary"; | 34 const char kTemporarySessionType[] = "temporary"; |
| 32 const char kPersistentLicenseSessionType[] = "persistent-license"; | 35 const char kPersistentLicenseSessionType[] = "persistent-license"; |
| 33 const char kPersistentReleaseMessageSessionType[] = | 36 const char kPersistentReleaseMessageSessionType[] = |
| 34 "persistent-release-message"; | 37 "persistent-release-message"; |
| 35 | 38 |
| 36 static blink::WebContentDecryptionModuleSession::Client::MessageType | 39 static blink::WebContentDecryptionModuleSession::Client::MessageType |
| 37 convertMessageType(MediaKeys::MessageType message_type) { | 40 convertMessageType(MediaKeys::MessageType message_type) { |
| 38 switch (message_type) { | 41 switch (message_type) { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 session_type_enum = MediaKeys::PERSISTENT_RELEASE_MESSAGE_SESSION; | 144 session_type_enum = MediaKeys::PERSISTENT_RELEASE_MESSAGE_SESSION; |
| 142 } else { | 145 } else { |
| 143 DCHECK(session_type == kTemporarySessionType); | 146 DCHECK(session_type == kTemporarySessionType); |
| 144 session_type_enum = MediaKeys::TEMPORARY_SESSION; | 147 session_type_enum = MediaKeys::TEMPORARY_SESSION; |
| 145 } | 148 } |
| 146 | 149 |
| 147 adapter_->InitializeNewSession( | 150 adapter_->InitializeNewSession( |
| 148 init_data_type_as_ascii, init_data, | 151 init_data_type_as_ascii, init_data, |
| 149 base::saturated_cast<int>(init_data_length), session_type_enum, | 152 base::saturated_cast<int>(init_data_length), session_type_enum, |
| 150 scoped_ptr<NewSessionCdmPromise>(new NewSessionCdmResultPromise( | 153 scoped_ptr<NewSessionCdmPromise>(new NewSessionCdmResultPromise( |
| 151 result, adapter_->GetKeySystemUMAPrefix() + kCreateSessionUMAName, | 154 result, adapter_->GetKeySystemUMAPrefix() + kGenerateRequestUMAName, |
| 152 base::Bind( | 155 base::Bind( |
| 153 &WebContentDecryptionModuleSessionImpl::OnSessionInitialized, | 156 &WebContentDecryptionModuleSessionImpl::OnSessionInitialized, |
| 154 base::Unretained(this))))); | 157 base::Unretained(this))))); |
| 155 } | 158 } |
| 156 | 159 |
| 157 void WebContentDecryptionModuleSessionImpl::load( | 160 void WebContentDecryptionModuleSessionImpl::load( |
| 158 const blink::WebString& session_id, | 161 const blink::WebString& session_id, |
| 159 blink::WebContentDecryptionModuleResult result) { | 162 blink::WebContentDecryptionModuleResult result) { |
| 160 DCHECK(!session_id.isEmpty()); | 163 DCHECK(!session_id.isEmpty()); |
| 161 DCHECK(web_session_id_.empty()); | 164 DCHECK(web_session_id_.empty()); |
| 162 | 165 |
| 163 // TODO(jrummell): Now that there are 2 types of persistent sessions, the | 166 // TODO(jrummell): Now that there are 2 types of persistent sessions, the |
| 164 // session type should be passed from blink. Type should also be passed in the | 167 // session type should be passed from blink. Type should also be passed in the |
| 165 // constructor (and removed from initializeNewSession()). | 168 // constructor (and removed from initializeNewSession()). |
| 166 adapter_->LoadSession( | 169 adapter_->LoadSession( |
| 167 MediaKeys::PERSISTENT_LICENSE_SESSION, base::UTF16ToASCII(session_id), | 170 MediaKeys::PERSISTENT_LICENSE_SESSION, base::UTF16ToASCII(session_id), |
| 168 scoped_ptr<NewSessionCdmPromise>(new NewSessionCdmResultPromise( | 171 scoped_ptr<NewSessionCdmPromise>(new NewSessionCdmResultPromise( |
| 169 result, adapter_->GetKeySystemUMAPrefix() + kLoadSessionUMAName, | 172 result, adapter_->GetKeySystemUMAPrefix() + kLoadSessionUMAName, |
| 170 base::Bind( | 173 base::Bind( |
| 171 &WebContentDecryptionModuleSessionImpl::OnSessionInitialized, | 174 &WebContentDecryptionModuleSessionImpl::OnSessionInitialized, |
| 172 base::Unretained(this))))); | 175 base::Unretained(this))))); |
| 173 } | 176 } |
| 174 | 177 |
| 175 void WebContentDecryptionModuleSessionImpl::update( | 178 void WebContentDecryptionModuleSessionImpl::update( |
| 176 const uint8* response, | 179 const uint8* response, |
| 177 size_t response_length, | 180 size_t response_length, |
| 178 blink::WebContentDecryptionModuleResult result) { | 181 blink::WebContentDecryptionModuleResult result) { |
| 179 DCHECK(response); | 182 DCHECK(response); |
| 180 DCHECK(!web_session_id_.empty()); | 183 DCHECK(!web_session_id_.empty()); |
| 181 adapter_->UpdateSession(web_session_id_, response, | 184 adapter_->UpdateSession( |
| 182 base::saturated_cast<int>(response_length), | 185 web_session_id_, response, base::saturated_cast<int>(response_length), |
| 183 scoped_ptr<SimpleCdmPromise>( | 186 scoped_ptr<SimpleCdmPromise>(new CdmResultPromise<>( |
| 184 new CdmResultPromise<>(result, std::string()))); | 187 result, adapter_->GetKeySystemUMAPrefix() + kUpdateSessionUMAName))); |
| 185 } | 188 } |
| 186 | 189 |
| 187 void WebContentDecryptionModuleSessionImpl::close( | 190 void WebContentDecryptionModuleSessionImpl::close( |
| 188 blink::WebContentDecryptionModuleResult result) { | 191 blink::WebContentDecryptionModuleResult result) { |
| 189 DCHECK(!web_session_id_.empty()); | 192 DCHECK(!web_session_id_.empty()); |
| 190 adapter_->CloseSession(web_session_id_, | 193 adapter_->CloseSession( |
| 191 scoped_ptr<SimpleCdmPromise>( | 194 web_session_id_, |
| 192 new CdmResultPromise<>(result, std::string()))); | 195 scoped_ptr<SimpleCdmPromise>(new CdmResultPromise<>( |
| 196 result, adapter_->GetKeySystemUMAPrefix() + kCloseSessionUMAName))); | |
| 193 } | 197 } |
| 194 | 198 |
| 195 void WebContentDecryptionModuleSessionImpl::remove( | 199 void WebContentDecryptionModuleSessionImpl::remove( |
| 196 blink::WebContentDecryptionModuleResult result) { | 200 blink::WebContentDecryptionModuleResult result) { |
| 197 DCHECK(!web_session_id_.empty()); | 201 DCHECK(!web_session_id_.empty()); |
| 198 adapter_->RemoveSession(web_session_id_, | 202 adapter_->RemoveSession( |
| 199 scoped_ptr<SimpleCdmPromise>( | 203 web_session_id_, |
| 200 new CdmResultPromise<>(result, std::string()))); | 204 scoped_ptr<SimpleCdmPromise>(new CdmResultPromise<>( |
| 205 result, adapter_->GetKeySystemUMAPrefix() + kRemoveSessionUMAName))); | |
| 201 } | 206 } |
| 202 | 207 |
| 203 void WebContentDecryptionModuleSessionImpl::release( | 208 void WebContentDecryptionModuleSessionImpl::release( |
| 204 blink::WebContentDecryptionModuleResult result) { | 209 blink::WebContentDecryptionModuleResult result) { |
| 205 close(result); | 210 close(result); |
| 206 } | 211 } |
| 207 | 212 |
| 208 void WebContentDecryptionModuleSessionImpl::OnSessionMessage( | 213 void WebContentDecryptionModuleSessionImpl::OnSessionMessage( |
| 209 MediaKeys::MessageType message_type, | 214 MediaKeys::MessageType message_type, |
| 210 const std::vector<uint8>& message) { | 215 const std::vector<uint8>& message) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 | 257 |
| 253 DCHECK(web_session_id_.empty()) << "Session ID may not be changed once set."; | 258 DCHECK(web_session_id_.empty()) << "Session ID may not be changed once set."; |
| 254 web_session_id_ = web_session_id; | 259 web_session_id_ = web_session_id; |
| 255 return adapter_->RegisterSession(web_session_id_, | 260 return adapter_->RegisterSession(web_session_id_, |
| 256 weak_ptr_factory_.GetWeakPtr()) | 261 weak_ptr_factory_.GetWeakPtr()) |
| 257 ? blink::WebContentDecryptionModuleResult::NewSession | 262 ? blink::WebContentDecryptionModuleResult::NewSession |
| 258 : blink::WebContentDecryptionModuleResult::SessionAlreadyExists; | 263 : blink::WebContentDecryptionModuleResult::SessionAlreadyExists; |
| 259 } | 264 } |
| 260 | 265 |
| 261 } // namespace media | 266 } // namespace media |
| OLD | NEW |