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
3 // found in the LICENSE file.
5 #include "media/blink/webcontentdecryptionmoduleaccess_impl.h"
8 #include "base/location.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/single_thread_task_runner.h"
11 #include "base/thread_task_runner_handle.h"
12 #include "media/blink/webencryptedmediaclient_impl.h"
16 // The caller owns the created cdm (passed back using |result|).
17 static void CreateCdm(
18 const base::WeakPtr
<WebEncryptedMediaClientImpl
>& client
,
19 const blink::WebString
& key_system
,
20 const blink::WebSecurityOrigin
& security_origin
,
21 const CdmConfig
& cdm_config
,
22 scoped_ptr
<blink::WebContentDecryptionModuleResult
> result
) {
23 // If |client| is gone (due to the frame getting destroyed), it is
24 // impossible to create the CDM, so fail.
26 result
->completeWithError(
27 blink::WebContentDecryptionModuleExceptionInvalidStateError
, 0,
28 "Failed to create CDM.");
32 client
->CreateCdm(key_system
, security_origin
, cdm_config
, result
.Pass());
35 WebContentDecryptionModuleAccessImpl
*
36 WebContentDecryptionModuleAccessImpl::Create(
37 const blink::WebString
& key_system
,
38 const blink::WebSecurityOrigin
& security_origin
,
39 const blink::WebMediaKeySystemConfiguration
& configuration
,
40 const CdmConfig
& cdm_config
,
41 const base::WeakPtr
<WebEncryptedMediaClientImpl
>& client
) {
42 return new WebContentDecryptionModuleAccessImpl(
43 key_system
, security_origin
, configuration
, cdm_config
, client
);
46 WebContentDecryptionModuleAccessImpl::WebContentDecryptionModuleAccessImpl(
47 const blink::WebString
& key_system
,
48 const blink::WebSecurityOrigin
& security_origin
,
49 const blink::WebMediaKeySystemConfiguration
& configuration
,
50 const CdmConfig
& cdm_config
,
51 const base::WeakPtr
<WebEncryptedMediaClientImpl
>& client
)
52 : key_system_(key_system
),
53 security_origin_(security_origin
),
54 configuration_(configuration
),
55 cdm_config_(cdm_config
),
59 WebContentDecryptionModuleAccessImpl::~WebContentDecryptionModuleAccessImpl() {
62 blink::WebMediaKeySystemConfiguration
63 WebContentDecryptionModuleAccessImpl::getConfiguration() {
64 return configuration_
;
67 void WebContentDecryptionModuleAccessImpl::createContentDecryptionModule(
68 blink::WebContentDecryptionModuleResult result
) {
69 // This method needs to run asynchronously, as it may need to load the CDM.
70 // As this object's lifetime is controlled by MediaKeySystemAccess on the
71 // blink side, copy all values needed by CreateCdm() in case the blink object
72 // gets garbage-collected.
73 scoped_ptr
<blink::WebContentDecryptionModuleResult
> result_copy(
74 new blink::WebContentDecryptionModuleResult(result
));
75 base::ThreadTaskRunnerHandle::Get()->PostTask(
76 FROM_HERE
, base::Bind(&CreateCdm
, client_
, key_system_
, security_origin_
,
77 cdm_config_
, base::Passed(&result_copy
)));