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/memory/ptr_util.h" | |
| 10 #include "base/numerics/safe_conversions.h" | 11 #include "base/numerics/safe_conversions.h" |
| 11 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 13 #include "media/base/cdm_key_information.h" | 14 #include "media/base/cdm_key_information.h" |
| 14 #include "media/base/cdm_promise.h" | 15 #include "media/base/cdm_promise.h" |
| 15 #include "media/base/key_system_names.h" | 16 #include "media/base/key_system_names.h" |
| 16 #include "media/base/key_systems.h" | 17 #include "media/base/key_systems.h" |
| 17 #include "media/base/limits.h" | 18 #include "media/base/limits.h" |
| 18 #include "media/base/media_keys.h" | 19 #include "media/base/media_keys.h" |
| 19 #include "media/blink/cdm_result_promise.h" | 20 #include "media/blink/cdm_result_promise.h" |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 std::string sanitized_data = GenerateJWKSet(keys, session_type); | 218 std::string sanitized_data = GenerateJWKSet(keys, session_type); |
| 218 sanitized_response->assign(sanitized_data.begin(), sanitized_data.end()); | 219 sanitized_response->assign(sanitized_data.begin(), sanitized_data.end()); |
| 219 return true; | 220 return true; |
| 220 } | 221 } |
| 221 | 222 |
| 222 // TODO(jrummell): Verify responses for Widevine. | 223 // TODO(jrummell): Verify responses for Widevine. |
| 223 sanitized_response->assign(response, response + response_length); | 224 sanitized_response->assign(response, response + response_length); |
| 224 return true; | 225 return true; |
| 225 } | 226 } |
| 226 | 227 |
| 228 // If we need to call close() on destruction, we need a promise that won't | |
|
ddorwin
2016/11/07 19:45:30
"call close()" (and similar wording in the descrip
jrummell
2016/11/07 22:51:40
Done.
| |
| 229 // do anything. | |
| 230 class IgnoreResponsePromise : public SimpleCdmPromise { | |
| 231 public: | |
| 232 IgnoreResponsePromise() {} | |
| 233 ~IgnoreResponsePromise() override {} | |
| 234 | |
| 235 // SimpleCdmPromise implementation. | |
| 236 void resolve() final { MarkPromiseSettled(); } | |
| 237 void reject(CdmPromise::Exception exception_code, | |
| 238 uint32_t system_code, | |
| 239 const std::string& error_message) final { | |
| 240 MarkPromiseSettled(); | |
| 241 } | |
| 242 }; | |
| 243 | |
| 227 WebContentDecryptionModuleSessionImpl::WebContentDecryptionModuleSessionImpl( | 244 WebContentDecryptionModuleSessionImpl::WebContentDecryptionModuleSessionImpl( |
| 228 const scoped_refptr<CdmSessionAdapter>& adapter) | 245 const scoped_refptr<CdmSessionAdapter>& adapter) |
| 229 : adapter_(adapter), is_closed_(false), weak_ptr_factory_(this) { | 246 : adapter_(adapter), |
| 230 } | 247 is_closed_(false), |
| 248 has_close_been_called_(false), | |
| 249 weak_ptr_factory_(this) {} | |
| 231 | 250 |
| 232 WebContentDecryptionModuleSessionImpl:: | 251 WebContentDecryptionModuleSessionImpl:: |
| 233 ~WebContentDecryptionModuleSessionImpl() { | 252 ~WebContentDecryptionModuleSessionImpl() { |
| 234 DCHECK(thread_checker_.CalledOnValidThread()); | 253 DCHECK(thread_checker_.CalledOnValidThread()); |
| 235 if (!session_id_.empty()) | 254 |
| 255 if (!session_id_.empty()) { | |
| 236 adapter_->UnregisterSession(session_id_); | 256 adapter_->UnregisterSession(session_id_); |
| 257 | |
| 258 // From http://w3c.github.io/encrypted-media/#mediakeysession-interface | |
|
ddorwin
2016/11/07 19:45:30
This text was just updated. (MediaKeySession destr
jrummell
2016/11/07 22:51:40
Done.
| |
| 259 // "If a MediaKeySession object becomes inaccessible to the page and is not | |
| 260 // closed, the User Agent must run the MediaKeySession destroyed algorithm | |
| 261 // before User Agent state associated with the session is deleted." | |
|
ddorwin
2016/11/07 19:45:31
We don't actually do this last part and can't beca
jrummell
2016/11/07 22:51:40
Acknowledged.
| |
| 262 // | |
| 263 // So if the session is not closed and CloseSession() has not yet been | |
| 264 // called, call CloseSession() now. Since this object is being destroyed, | |
| 265 // there is no need for the promise to do anything as this session will | |
| 266 // be gone. | |
| 267 if (!is_closed_ && !has_close_been_called_) { | |
| 268 adapter_->CloseSession(session_id_, | |
| 269 base::MakeUnique<IgnoreResponsePromise>()); | |
| 270 } | |
| 271 } | |
| 237 } | 272 } |
| 238 | 273 |
| 239 void WebContentDecryptionModuleSessionImpl::setClientInterface(Client* client) { | 274 void WebContentDecryptionModuleSessionImpl::setClientInterface(Client* client) { |
| 240 client_ = client; | 275 client_ = client; |
| 241 } | 276 } |
| 242 | 277 |
| 243 blink::WebString WebContentDecryptionModuleSessionImpl::sessionId() const { | 278 blink::WebString WebContentDecryptionModuleSessionImpl::sessionId() const { |
| 244 return blink::WebString::fromUTF8(session_id_); | 279 return blink::WebString::fromUTF8(session_id_); |
| 245 } | 280 } |
| 246 | 281 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 387 adapter_->UpdateSession( | 422 adapter_->UpdateSession( |
| 388 session_id_, sanitized_response, | 423 session_id_, sanitized_response, |
| 389 std::unique_ptr<SimpleCdmPromise>(new CdmResultPromise<>( | 424 std::unique_ptr<SimpleCdmPromise>(new CdmResultPromise<>( |
| 390 result, adapter_->GetKeySystemUMAPrefix() + kUpdateSessionUMAName))); | 425 result, adapter_->GetKeySystemUMAPrefix() + kUpdateSessionUMAName))); |
| 391 } | 426 } |
| 392 | 427 |
| 393 void WebContentDecryptionModuleSessionImpl::close( | 428 void WebContentDecryptionModuleSessionImpl::close( |
| 394 blink::WebContentDecryptionModuleResult result) { | 429 blink::WebContentDecryptionModuleResult result) { |
| 395 DCHECK(!session_id_.empty()); | 430 DCHECK(!session_id_.empty()); |
| 396 DCHECK(thread_checker_.CalledOnValidThread()); | 431 DCHECK(thread_checker_.CalledOnValidThread()); |
| 432 | |
| 433 has_close_been_called_ = true; | |
| 397 adapter_->CloseSession( | 434 adapter_->CloseSession( |
| 398 session_id_, | 435 session_id_, |
| 399 std::unique_ptr<SimpleCdmPromise>(new CdmResultPromise<>( | 436 std::unique_ptr<SimpleCdmPromise>(new CdmResultPromise<>( |
| 400 result, adapter_->GetKeySystemUMAPrefix() + kCloseSessionUMAName))); | 437 result, adapter_->GetKeySystemUMAPrefix() + kCloseSessionUMAName))); |
| 401 } | 438 } |
| 402 | 439 |
| 403 void WebContentDecryptionModuleSessionImpl::remove( | 440 void WebContentDecryptionModuleSessionImpl::remove( |
| 404 blink::WebContentDecryptionModuleResult result) { | 441 blink::WebContentDecryptionModuleResult result) { |
| 405 DCHECK(!session_id_.empty()); | 442 DCHECK(!session_id_.empty()); |
| 406 DCHECK(thread_checker_.CalledOnValidThread()); | 443 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 464 | 501 |
| 465 DCHECK(session_id_.empty()) << "Session ID may not be changed once set."; | 502 DCHECK(session_id_.empty()) << "Session ID may not be changed once set."; |
| 466 session_id_ = session_id; | 503 session_id_ = session_id; |
| 467 *status = | 504 *status = |
| 468 adapter_->RegisterSession(session_id_, weak_ptr_factory_.GetWeakPtr()) | 505 adapter_->RegisterSession(session_id_, weak_ptr_factory_.GetWeakPtr()) |
| 469 ? SessionInitStatus::NEW_SESSION | 506 ? SessionInitStatus::NEW_SESSION |
| 470 : SessionInitStatus::SESSION_ALREADY_EXISTS; | 507 : SessionInitStatus::SESSION_ALREADY_EXISTS; |
| 471 } | 508 } |
| 472 | 509 |
| 473 } // namespace media | 510 } // namespace media |
| OLD | NEW |