Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: media/blink/webcontentdecryptionmodulesession_impl.cc

Issue 2484873002: EME: Make sure sessions are closed before they are destroyed (Closed)
Patch Set: comments only Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/blink/webcontentdecryptionmodulesession_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 close the session while destroying this object, we need a
229 // dummy promise that won't call back into this object (or try to pass
230 // something back to blink).
231 class IgnoreResponsePromise : public SimpleCdmPromise {
232 public:
233 IgnoreResponsePromise() {}
234 ~IgnoreResponsePromise() override {}
235
236 // SimpleCdmPromise implementation.
237 void resolve() final { MarkPromiseSettled(); }
238 void reject(CdmPromise::Exception exception_code,
239 uint32_t system_code,
240 const std::string& error_message) final {
241 MarkPromiseSettled();
242 }
243 };
244
227 WebContentDecryptionModuleSessionImpl::WebContentDecryptionModuleSessionImpl( 245 WebContentDecryptionModuleSessionImpl::WebContentDecryptionModuleSessionImpl(
228 const scoped_refptr<CdmSessionAdapter>& adapter) 246 const scoped_refptr<CdmSessionAdapter>& adapter)
229 : adapter_(adapter), is_closed_(false), weak_ptr_factory_(this) { 247 : adapter_(adapter),
230 } 248 is_closed_(false),
249 has_close_been_called_(false),
250 weak_ptr_factory_(this) {}
231 251
232 WebContentDecryptionModuleSessionImpl:: 252 WebContentDecryptionModuleSessionImpl::
233 ~WebContentDecryptionModuleSessionImpl() { 253 ~WebContentDecryptionModuleSessionImpl() {
234 DCHECK(thread_checker_.CalledOnValidThread()); 254 DCHECK(thread_checker_.CalledOnValidThread());
235 if (!session_id_.empty()) 255
256 if (!session_id_.empty()) {
236 adapter_->UnregisterSession(session_id_); 257 adapter_->UnregisterSession(session_id_);
258
259 // From http://w3c.github.io/encrypted-media/#mediakeysession-interface
260 // "If a MediaKeySession object becomes inaccessible to the page and is
261 // not closed, the User Agent must use the CDM to close the session
262 // before User Agent state associated with the session is deleted."
ddorwin 2016/11/08 00:41:13 You might note that this will happen after, but th
ddorwin 2016/11/08 01:05:20 Filed https://github.com/w3c/encrypted-media/issue
jrummell 2016/11/10 00:04:57 Updated comment copied from spec.
263 //
264 // So if the session is not closed and CloseSession() has not yet been
265 // called, call CloseSession() now. Since this object is being destroyed,
266 // there is no need for the promise to do anything as this session will
267 // be gone.
268 if (!is_closed_ && !has_close_been_called_) {
269 adapter_->CloseSession(session_id_,
270 base::MakeUnique<IgnoreResponsePromise>());
271 }
272 }
237 } 273 }
238 274
239 void WebContentDecryptionModuleSessionImpl::setClientInterface(Client* client) { 275 void WebContentDecryptionModuleSessionImpl::setClientInterface(Client* client) {
240 client_ = client; 276 client_ = client;
241 } 277 }
242 278
243 blink::WebString WebContentDecryptionModuleSessionImpl::sessionId() const { 279 blink::WebString WebContentDecryptionModuleSessionImpl::sessionId() const {
244 return blink::WebString::fromUTF8(session_id_); 280 return blink::WebString::fromUTF8(session_id_);
245 } 281 }
246 282
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 adapter_->UpdateSession( 423 adapter_->UpdateSession(
388 session_id_, sanitized_response, 424 session_id_, sanitized_response,
389 std::unique_ptr<SimpleCdmPromise>(new CdmResultPromise<>( 425 std::unique_ptr<SimpleCdmPromise>(new CdmResultPromise<>(
390 result, adapter_->GetKeySystemUMAPrefix() + kUpdateSessionUMAName))); 426 result, adapter_->GetKeySystemUMAPrefix() + kUpdateSessionUMAName)));
391 } 427 }
392 428
393 void WebContentDecryptionModuleSessionImpl::close( 429 void WebContentDecryptionModuleSessionImpl::close(
394 blink::WebContentDecryptionModuleResult result) { 430 blink::WebContentDecryptionModuleResult result) {
395 DCHECK(!session_id_.empty()); 431 DCHECK(!session_id_.empty());
396 DCHECK(thread_checker_.CalledOnValidThread()); 432 DCHECK(thread_checker_.CalledOnValidThread());
433
434 has_close_been_called_ = true;
397 adapter_->CloseSession( 435 adapter_->CloseSession(
398 session_id_, 436 session_id_,
399 std::unique_ptr<SimpleCdmPromise>(new CdmResultPromise<>( 437 std::unique_ptr<SimpleCdmPromise>(new CdmResultPromise<>(
400 result, adapter_->GetKeySystemUMAPrefix() + kCloseSessionUMAName))); 438 result, adapter_->GetKeySystemUMAPrefix() + kCloseSessionUMAName)));
401 } 439 }
402 440
403 void WebContentDecryptionModuleSessionImpl::remove( 441 void WebContentDecryptionModuleSessionImpl::remove(
404 blink::WebContentDecryptionModuleResult result) { 442 blink::WebContentDecryptionModuleResult result) {
405 DCHECK(!session_id_.empty()); 443 DCHECK(!session_id_.empty());
406 DCHECK(thread_checker_.CalledOnValidThread()); 444 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 502
465 DCHECK(session_id_.empty()) << "Session ID may not be changed once set."; 503 DCHECK(session_id_.empty()) << "Session ID may not be changed once set.";
466 session_id_ = session_id; 504 session_id_ = session_id;
467 *status = 505 *status =
468 adapter_->RegisterSession(session_id_, weak_ptr_factory_.GetWeakPtr()) 506 adapter_->RegisterSession(session_id_, weak_ptr_factory_.GetWeakPtr())
469 ? SessionInitStatus::NEW_SESSION 507 ? SessionInitStatus::NEW_SESSION
470 : SessionInitStatus::SESSION_ALREADY_EXISTS; 508 : SessionInitStatus::SESSION_ALREADY_EXISTS;
471 } 509 }
472 510
473 } // namespace media 511 } // namespace media
OLDNEW
« no previous file with comments | « media/blink/webcontentdecryptionmodulesession_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698