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"
7 #include "base/basictypes.h"
9 #include "base/location.h"
10 #include "base/message_loop/message_loop_proxy.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 bool allow_distinctive_identifier
,
19 bool allow_persistent_state
,
20 const blink::WebSecurityOrigin
& security_origin
,
21 blink::WebContentDecryptionModuleResult result
) {
22 // If |client| is gone (due to the frame getting destroyed), it is
23 // impossible to create the CDM, so fail.
25 result
.completeWithError(
26 blink::WebContentDecryptionModuleExceptionInvalidStateError
, 0,
27 "Failed to create CDM.");
31 client
->CreateCdm(key_system
, allow_distinctive_identifier
,
32 allow_persistent_state
, security_origin
, result
);
35 WebContentDecryptionModuleAccessImpl
*
36 WebContentDecryptionModuleAccessImpl::Create(
37 const blink::WebString
& key_system
,
38 const blink::WebMediaKeySystemConfiguration
& configuration
,
39 const blink::WebSecurityOrigin
& security_origin
,
40 const base::WeakPtr
<WebEncryptedMediaClientImpl
>& client
) {
41 return new WebContentDecryptionModuleAccessImpl(key_system
, configuration
,
42 security_origin
, client
);
45 WebContentDecryptionModuleAccessImpl::WebContentDecryptionModuleAccessImpl(
46 const blink::WebString
& key_system
,
47 const blink::WebMediaKeySystemConfiguration
& configuration
,
48 const blink::WebSecurityOrigin
& security_origin
,
49 const base::WeakPtr
<WebEncryptedMediaClientImpl
>& client
)
50 : key_system_(key_system
),
51 configuration_(configuration
),
52 security_origin_(security_origin
),
56 WebContentDecryptionModuleAccessImpl::~WebContentDecryptionModuleAccessImpl() {
59 blink::WebMediaKeySystemConfiguration
60 WebContentDecryptionModuleAccessImpl::getConfiguration() {
61 return configuration_
;
64 void WebContentDecryptionModuleAccessImpl::createContentDecryptionModule(
65 blink::WebContentDecryptionModuleResult result
) {
66 // Convert the accumulated configuration requirements to bools. Accumulated
67 // configurations never have optional requirements.
68 DCHECK(configuration_
.distinctiveIdentifier
!=
69 blink::WebMediaKeySystemConfiguration::Requirement::Optional
);
70 DCHECK(configuration_
.persistentState
!=
71 blink::WebMediaKeySystemConfiguration::Requirement::Optional
);
72 bool allow_distinctive_identifier
=
73 (configuration_
.distinctiveIdentifier
==
74 blink::WebMediaKeySystemConfiguration::Requirement::Required
);
75 bool allow_persistent_state
=
76 (configuration_
.persistentState
==
77 blink::WebMediaKeySystemConfiguration::Requirement::Required
);
79 // This method needs to run asynchronously, as it may need to load the CDM.
80 // As this object's lifetime is controlled by MediaKeySystemAccess on the
81 // blink side, copy all values needed by CreateCdm() in case the blink object
82 // gets garbage-collected.
83 base::MessageLoopProxy::current()->PostTask(
85 base::Bind(&CreateCdm
, client_
, key_system_
, allow_distinctive_identifier
,
86 allow_persistent_state
, security_origin_
, result
));