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/message_loop/message_loop_proxy.h"
10 #include "media/blink/webencryptedmediaclient_impl.h"
14 // The caller owns the created cdm (passed back using |result|).
15 static void CreateCdm(const base::WeakPtr
<WebEncryptedMediaClientImpl
>& client
,
16 const blink::WebString
& key_system
,
17 bool allow_distinctive_identifier
,
18 bool allow_persistent_state
,
19 const blink::WebSecurityOrigin
& security_origin
,
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
, allow_distinctive_identifier
,
31 allow_persistent_state
, security_origin
, result
);
34 WebContentDecryptionModuleAccessImpl
*
35 WebContentDecryptionModuleAccessImpl::Create(
36 const blink::WebString
& key_system
,
37 const blink::WebMediaKeySystemConfiguration
& configuration
,
38 const blink::WebSecurityOrigin
& security_origin
,
39 const base::WeakPtr
<WebEncryptedMediaClientImpl
>& client
) {
40 return new WebContentDecryptionModuleAccessImpl(key_system
, configuration
,
41 security_origin
, client
);
44 WebContentDecryptionModuleAccessImpl::WebContentDecryptionModuleAccessImpl(
45 const blink::WebString
& key_system
,
46 const blink::WebMediaKeySystemConfiguration
& configuration
,
47 const blink::WebSecurityOrigin
& security_origin
,
48 const base::WeakPtr
<WebEncryptedMediaClientImpl
>& client
)
49 : key_system_(key_system
),
50 configuration_(configuration
),
51 security_origin_(security_origin
),
55 WebContentDecryptionModuleAccessImpl::~WebContentDecryptionModuleAccessImpl() {
58 blink::WebMediaKeySystemConfiguration
59 WebContentDecryptionModuleAccessImpl::getConfiguration() {
60 return configuration_
;
63 void WebContentDecryptionModuleAccessImpl::createContentDecryptionModule(
64 blink::WebContentDecryptionModuleResult result
) {
65 // Convert the accumulated configuration requirements to bools. Accumulated
66 // configurations never have optional requirements.
67 DCHECK(configuration_
.distinctiveIdentifier
!=
68 blink::WebMediaKeySystemConfiguration::Requirement::Optional
);
69 DCHECK(configuration_
.persistentState
!=
70 blink::WebMediaKeySystemConfiguration::Requirement::Optional
);
71 bool allow_distinctive_identifier
=
72 (configuration_
.distinctiveIdentifier
==
73 blink::WebMediaKeySystemConfiguration::Requirement::Required
);
74 bool allow_persistent_state
=
75 (configuration_
.persistentState
==
76 blink::WebMediaKeySystemConfiguration::Requirement::Required
);
78 // This method needs to run asynchronously, as it may need to load the CDM.
79 // As this object's lifetime is controlled by MediaKeySystemAccess on the
80 // blink side, copy all values needed by CreateCdm() in case the blink object
81 // gets garbage-collected.
82 base::MessageLoopProxy::current()->PostTask(
84 base::Bind(&CreateCdm
, client_
, key_system_
, allow_distinctive_identifier
,
85 allow_persistent_state
, security_origin_
, result
));