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/single_thread_task_runner.h"
10 #include "base/thread_task_runner_handle.h"
11 #include "media/blink/webencryptedmediaclient_impl.h"
15 // The caller owns the created cdm (passed back using |result|).
16 static void CreateCdm(const base::WeakPtr
<WebEncryptedMediaClientImpl
>& client
,
17 const blink::WebString
& key_system
,
18 const blink::WebSecurityOrigin
& security_origin
,
19 const CdmConfig
& cdm_config
,
20 blink::WebContentDecryptionModuleResult result
) {
21 // If |client| is gone (due to the frame getting destroyed), it is
22 // impossible to create the CDM, so fail.
24 result
.completeWithError(
25 blink::WebContentDecryptionModuleExceptionInvalidStateError
, 0,
26 "Failed to create CDM.");
30 client
->CreateCdm(key_system
, security_origin
, cdm_config
, result
);
33 WebContentDecryptionModuleAccessImpl
*
34 WebContentDecryptionModuleAccessImpl::Create(
35 const blink::WebString
& key_system
,
36 const blink::WebSecurityOrigin
& security_origin
,
37 const blink::WebMediaKeySystemConfiguration
& configuration
,
38 const CdmConfig
& cdm_config
,
39 const base::WeakPtr
<WebEncryptedMediaClientImpl
>& client
) {
40 return new WebContentDecryptionModuleAccessImpl(
41 key_system
, security_origin
, configuration
, cdm_config
, client
);
44 WebContentDecryptionModuleAccessImpl::WebContentDecryptionModuleAccessImpl(
45 const blink::WebString
& key_system
,
46 const blink::WebSecurityOrigin
& security_origin
,
47 const blink::WebMediaKeySystemConfiguration
& configuration
,
48 const CdmConfig
& cdm_config
,
49 const base::WeakPtr
<WebEncryptedMediaClientImpl
>& client
)
50 : key_system_(key_system
),
51 security_origin_(security_origin
),
52 configuration_(configuration
),
53 cdm_config_(cdm_config
),
57 WebContentDecryptionModuleAccessImpl::~WebContentDecryptionModuleAccessImpl() {
60 blink::WebMediaKeySystemConfiguration
61 WebContentDecryptionModuleAccessImpl::getConfiguration() {
62 return configuration_
;
65 void WebContentDecryptionModuleAccessImpl::createContentDecryptionModule(
66 blink::WebContentDecryptionModuleResult result
) {
67 // This method needs to run asynchronously, as it may need to load the CDM.
68 // As this object's lifetime is controlled by MediaKeySystemAccess on the
69 // blink side, copy all values needed by CreateCdm() in case the blink object
70 // gets garbage-collected.
71 base::ThreadTaskRunnerHandle::Get()->PostTask(
73 base::Bind(&CreateCdm
, client_
, key_system_
, security_origin_
,
74 cdm_config_
, result
));