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

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

Issue 1375663003: Verify EME calls made on same thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months 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/numerics/safe_conversions.h" 10 #include "base/numerics/safe_conversions.h"
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 return true; 219 return true;
220 } 220 }
221 221
222 WebContentDecryptionModuleSessionImpl::WebContentDecryptionModuleSessionImpl( 222 WebContentDecryptionModuleSessionImpl::WebContentDecryptionModuleSessionImpl(
223 const scoped_refptr<CdmSessionAdapter>& adapter) 223 const scoped_refptr<CdmSessionAdapter>& adapter)
224 : adapter_(adapter), is_closed_(false), weak_ptr_factory_(this) { 224 : adapter_(adapter), is_closed_(false), weak_ptr_factory_(this) {
225 } 225 }
226 226
227 WebContentDecryptionModuleSessionImpl:: 227 WebContentDecryptionModuleSessionImpl::
228 ~WebContentDecryptionModuleSessionImpl() { 228 ~WebContentDecryptionModuleSessionImpl() {
229 DCHECK(thread_checker_.CalledOnValidThread());
229 if (!session_id_.empty()) 230 if (!session_id_.empty())
230 adapter_->UnregisterSession(session_id_); 231 adapter_->UnregisterSession(session_id_);
231 } 232 }
232 233
233 void WebContentDecryptionModuleSessionImpl::setClientInterface(Client* client) { 234 void WebContentDecryptionModuleSessionImpl::setClientInterface(Client* client) {
234 client_ = client; 235 client_ = client;
235 } 236 }
236 237
237 blink::WebString WebContentDecryptionModuleSessionImpl::sessionId() const { 238 blink::WebString WebContentDecryptionModuleSessionImpl::sessionId() const {
238 return blink::WebString::fromUTF8(session_id_); 239 return blink::WebString::fromUTF8(session_id_);
239 } 240 }
240 241
241 void WebContentDecryptionModuleSessionImpl::initializeNewSession( 242 void WebContentDecryptionModuleSessionImpl::initializeNewSession(
242 blink::WebEncryptedMediaInitDataType init_data_type, 243 blink::WebEncryptedMediaInitDataType init_data_type,
243 const unsigned char* init_data, 244 const unsigned char* init_data,
244 size_t init_data_length, 245 size_t init_data_length,
245 blink::WebEncryptedMediaSessionType session_type, 246 blink::WebEncryptedMediaSessionType session_type,
246 blink::WebContentDecryptionModuleResult result) { 247 blink::WebContentDecryptionModuleResult result) {
247 DCHECK(init_data); 248 DCHECK(init_data);
248 DCHECK(session_id_.empty()); 249 DCHECK(session_id_.empty());
250 DCHECK(thread_checker_.CalledOnValidThread());
249 251
250 // From https://w3c.github.io/encrypted-media/#generateRequest. 252 // From https://w3c.github.io/encrypted-media/#generateRequest.
251 // 5. If the Key System implementation represented by this object's cdm 253 // 5. If the Key System implementation represented by this object's cdm
252 // implementation value does not support initDataType as an Initialization 254 // implementation value does not support initDataType as an Initialization
253 // Data Type, return a promise rejected with a new DOMException whose name 255 // Data Type, return a promise rejected with a new DOMException whose name
254 // is NotSupportedError. String comparison is case-sensitive. 256 // is NotSupportedError. String comparison is case-sensitive.
255 EmeInitDataType eme_init_data_type = ConvertToEmeInitDataType(init_data_type); 257 EmeInitDataType eme_init_data_type = ConvertToEmeInitDataType(init_data_type);
256 if (!IsSupportedKeySystemWithInitDataType(adapter_->GetKeySystem(), 258 if (!IsSupportedKeySystemWithInitDataType(adapter_->GetKeySystem(),
257 eme_init_data_type)) { 259 eme_init_data_type)) {
258 std::string message = 260 std::string message =
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 base::Bind( 305 base::Bind(
304 &WebContentDecryptionModuleSessionImpl::OnSessionInitialized, 306 &WebContentDecryptionModuleSessionImpl::OnSessionInitialized,
305 base::Unretained(this))))); 307 base::Unretained(this)))));
306 } 308 }
307 309
308 void WebContentDecryptionModuleSessionImpl::load( 310 void WebContentDecryptionModuleSessionImpl::load(
309 const blink::WebString& session_id, 311 const blink::WebString& session_id,
310 blink::WebContentDecryptionModuleResult result) { 312 blink::WebContentDecryptionModuleResult result) {
311 DCHECK(!session_id.isEmpty()); 313 DCHECK(!session_id.isEmpty());
312 DCHECK(session_id_.empty()); 314 DCHECK(session_id_.empty());
315 DCHECK(thread_checker_.CalledOnValidThread());
313 316
314 std::string sanitized_session_id; 317 std::string sanitized_session_id;
315 if (!SanitizeSessionId(session_id, &sanitized_session_id)) { 318 if (!SanitizeSessionId(session_id, &sanitized_session_id)) {
316 result.completeWithError( 319 result.completeWithError(
317 blink::WebContentDecryptionModuleExceptionInvalidAccessError, 0, 320 blink::WebContentDecryptionModuleExceptionInvalidAccessError, 0,
318 "Invalid session ID."); 321 "Invalid session ID.");
319 return; 322 return;
320 } 323 }
321 324
322 // TODO(jrummell): Now that there are 2 types of persistent sessions, the 325 // TODO(jrummell): Now that there are 2 types of persistent sessions, the
323 // session type should be passed from blink. Type should also be passed in the 326 // session type should be passed from blink. Type should also be passed in the
324 // constructor (and removed from initializeNewSession()). 327 // constructor (and removed from initializeNewSession()).
325 adapter_->LoadSession( 328 adapter_->LoadSession(
326 MediaKeys::PERSISTENT_LICENSE_SESSION, sanitized_session_id, 329 MediaKeys::PERSISTENT_LICENSE_SESSION, sanitized_session_id,
327 scoped_ptr<NewSessionCdmPromise>(new NewSessionCdmResultPromise( 330 scoped_ptr<NewSessionCdmPromise>(new NewSessionCdmResultPromise(
328 result, adapter_->GetKeySystemUMAPrefix() + kLoadSessionUMAName, 331 result, adapter_->GetKeySystemUMAPrefix() + kLoadSessionUMAName,
329 base::Bind( 332 base::Bind(
330 &WebContentDecryptionModuleSessionImpl::OnSessionInitialized, 333 &WebContentDecryptionModuleSessionImpl::OnSessionInitialized,
331 base::Unretained(this))))); 334 base::Unretained(this)))));
332 } 335 }
333 336
334 void WebContentDecryptionModuleSessionImpl::update( 337 void WebContentDecryptionModuleSessionImpl::update(
335 const uint8* response, 338 const uint8* response,
336 size_t response_length, 339 size_t response_length,
337 blink::WebContentDecryptionModuleResult result) { 340 blink::WebContentDecryptionModuleResult result) {
338 DCHECK(response); 341 DCHECK(response);
339 DCHECK(!session_id_.empty()); 342 DCHECK(!session_id_.empty());
343 DCHECK(thread_checker_.CalledOnValidThread());
340 344
341 std::vector<uint8> sanitized_response; 345 std::vector<uint8> sanitized_response;
342 if (!SanitizeResponse(adapter_->GetKeySystem(), response, response_length, 346 if (!SanitizeResponse(adapter_->GetKeySystem(), response, response_length,
343 &sanitized_response)) { 347 &sanitized_response)) {
344 result.completeWithError( 348 result.completeWithError(
345 blink::WebContentDecryptionModuleExceptionInvalidAccessError, 0, 349 blink::WebContentDecryptionModuleExceptionInvalidAccessError, 0,
346 "Invalid response."); 350 "Invalid response.");
347 return; 351 return;
348 } 352 }
349 353
350 adapter_->UpdateSession( 354 adapter_->UpdateSession(
351 session_id_, sanitized_response, 355 session_id_, sanitized_response,
352 scoped_ptr<SimpleCdmPromise>(new CdmResultPromise<>( 356 scoped_ptr<SimpleCdmPromise>(new CdmResultPromise<>(
353 result, adapter_->GetKeySystemUMAPrefix() + kUpdateSessionUMAName))); 357 result, adapter_->GetKeySystemUMAPrefix() + kUpdateSessionUMAName)));
354 } 358 }
355 359
356 void WebContentDecryptionModuleSessionImpl::close( 360 void WebContentDecryptionModuleSessionImpl::close(
357 blink::WebContentDecryptionModuleResult result) { 361 blink::WebContentDecryptionModuleResult result) {
358 DCHECK(!session_id_.empty()); 362 DCHECK(!session_id_.empty());
363 DCHECK(thread_checker_.CalledOnValidThread());
359 adapter_->CloseSession( 364 adapter_->CloseSession(
360 session_id_, 365 session_id_,
361 scoped_ptr<SimpleCdmPromise>(new CdmResultPromise<>( 366 scoped_ptr<SimpleCdmPromise>(new CdmResultPromise<>(
362 result, adapter_->GetKeySystemUMAPrefix() + kCloseSessionUMAName))); 367 result, adapter_->GetKeySystemUMAPrefix() + kCloseSessionUMAName)));
363 } 368 }
364 369
365 void WebContentDecryptionModuleSessionImpl::remove( 370 void WebContentDecryptionModuleSessionImpl::remove(
366 blink::WebContentDecryptionModuleResult result) { 371 blink::WebContentDecryptionModuleResult result) {
367 DCHECK(!session_id_.empty()); 372 DCHECK(!session_id_.empty());
373 DCHECK(thread_checker_.CalledOnValidThread());
368 adapter_->RemoveSession( 374 adapter_->RemoveSession(
369 session_id_, 375 session_id_,
370 scoped_ptr<SimpleCdmPromise>(new CdmResultPromise<>( 376 scoped_ptr<SimpleCdmPromise>(new CdmResultPromise<>(
371 result, adapter_->GetKeySystemUMAPrefix() + kRemoveSessionUMAName))); 377 result, adapter_->GetKeySystemUMAPrefix() + kRemoveSessionUMAName)));
372 } 378 }
373 379
374 void WebContentDecryptionModuleSessionImpl::OnSessionMessage( 380 void WebContentDecryptionModuleSessionImpl::OnSessionMessage(
375 MediaKeys::MessageType message_type, 381 MediaKeys::MessageType message_type,
376 const std::vector<uint8>& message) { 382 const std::vector<uint8>& message) {
377 DCHECK(client_) << "Client not set before message event"; 383 DCHECK(client_) << "Client not set before message event";
384 DCHECK(thread_checker_.CalledOnValidThread());
378 client_->message(convertMessageType(message_type), vector_as_array(&message), 385 client_->message(convertMessageType(message_type), vector_as_array(&message),
379 message.size()); 386 message.size());
380 } 387 }
381 388
382 void WebContentDecryptionModuleSessionImpl::OnSessionKeysChange( 389 void WebContentDecryptionModuleSessionImpl::OnSessionKeysChange(
383 bool has_additional_usable_key, 390 bool has_additional_usable_key,
384 CdmKeysInfo keys_info) { 391 CdmKeysInfo keys_info) {
392 DCHECK(thread_checker_.CalledOnValidThread());
385 blink::WebVector<blink::WebEncryptedMediaKeyInformation> keys( 393 blink::WebVector<blink::WebEncryptedMediaKeyInformation> keys(
386 keys_info.size()); 394 keys_info.size());
387 for (size_t i = 0; i < keys_info.size(); ++i) { 395 for (size_t i = 0; i < keys_info.size(); ++i) {
388 const auto& key_info = keys_info[i]; 396 const auto& key_info = keys_info[i];
389 keys[i].setId(blink::WebData(reinterpret_cast<char*>(&key_info->key_id[0]), 397 keys[i].setId(blink::WebData(reinterpret_cast<char*>(&key_info->key_id[0]),
390 key_info->key_id.size())); 398 key_info->key_id.size()));
391 keys[i].setStatus(convertStatus(key_info->status)); 399 keys[i].setStatus(convertStatus(key_info->status));
392 keys[i].setSystemCode(key_info->system_code); 400 keys[i].setSystemCode(key_info->system_code);
393 } 401 }
394 402
395 // Now send the event to blink. 403 // Now send the event to blink.
396 client_->keysStatusesChange(keys, has_additional_usable_key); 404 client_->keysStatusesChange(keys, has_additional_usable_key);
397 } 405 }
398 406
399 void WebContentDecryptionModuleSessionImpl::OnSessionExpirationUpdate( 407 void WebContentDecryptionModuleSessionImpl::OnSessionExpirationUpdate(
400 const base::Time& new_expiry_time) { 408 const base::Time& new_expiry_time) {
409 DCHECK(thread_checker_.CalledOnValidThread());
401 client_->expirationChanged(new_expiry_time.ToJsTime()); 410 client_->expirationChanged(new_expiry_time.ToJsTime());
402 } 411 }
403 412
404 void WebContentDecryptionModuleSessionImpl::OnSessionClosed() { 413 void WebContentDecryptionModuleSessionImpl::OnSessionClosed() {
414 DCHECK(thread_checker_.CalledOnValidThread());
405 if (is_closed_) 415 if (is_closed_)
406 return; 416 return;
407 417
408 is_closed_ = true; 418 is_closed_ = true;
409 client_->close(); 419 client_->close();
410 } 420 }
411 421
412 blink::WebContentDecryptionModuleResult::SessionStatus 422 blink::WebContentDecryptionModuleResult::SessionStatus
413 WebContentDecryptionModuleSessionImpl::OnSessionInitialized( 423 WebContentDecryptionModuleSessionImpl::OnSessionInitialized(
414 const std::string& session_id) { 424 const std::string& session_id) {
425 DCHECK(thread_checker_.CalledOnValidThread());
415 // CDM will return NULL if the session to be loaded can't be found. 426 // CDM will return NULL if the session to be loaded can't be found.
416 if (session_id.empty()) 427 if (session_id.empty())
417 return blink::WebContentDecryptionModuleResult::SessionNotFound; 428 return blink::WebContentDecryptionModuleResult::SessionNotFound;
418 429
419 DCHECK(session_id_.empty()) << "Session ID may not be changed once set."; 430 DCHECK(session_id_.empty()) << "Session ID may not be changed once set.";
420 session_id_ = session_id; 431 session_id_ = session_id;
421 return adapter_->RegisterSession(session_id_, weak_ptr_factory_.GetWeakPtr()) 432 return adapter_->RegisterSession(session_id_, weak_ptr_factory_.GetWeakPtr())
422 ? blink::WebContentDecryptionModuleResult::NewSession 433 ? blink::WebContentDecryptionModuleResult::NewSession
423 : blink::WebContentDecryptionModuleResult::SessionAlreadyExists; 434 : blink::WebContentDecryptionModuleResult::SessionAlreadyExists;
424 } 435 }
425 436
426 } // namespace media 437 } // 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