OLD | NEW |
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 "webcontentdecryptionmoduleaccess_impl.h" | 5 #include "media/blink/webcontentdecryptionmoduleaccess_impl.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
11 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h" | 11 #include "media/blink/webencryptedmediaclient_impl.h" |
12 #include "webcontentdecryptionmodule_impl.h" | |
13 | 12 |
14 namespace media { | 13 namespace media { |
15 | 14 |
16 // The caller owns the created cdm (passed back using |result|). | 15 // The caller owns the created cdm (passed back using |result|). |
17 static void CreateCdm(CdmFactory* cdm_factory, | 16 static void CreateCdm(const base::WeakPtr<WebEncryptedMediaClientImpl>& client, |
18 blink::WebSecurityOrigin security_origin, | 17 const blink::WebString& key_system, |
19 blink::WebString key_system, | 18 const blink::WebSecurityOrigin& security_origin, |
20 blink::WebContentDecryptionModuleResult result) { | 19 blink::WebContentDecryptionModuleResult result) { |
21 WebContentDecryptionModuleImpl::Create(cdm_factory, security_origin, | 20 // If |client| is gone (due to the frame getting destroyed), it is |
22 key_system, result); | 21 // impossible to create the CDM, so fail. |
| 22 if (!client) { |
| 23 result.completeWithError( |
| 24 blink::WebContentDecryptionModuleExceptionInvalidStateError, 0, |
| 25 "Failed to create CDM."); |
| 26 return; |
| 27 } |
| 28 |
| 29 client->CreateCdm(key_system, security_origin, result); |
23 } | 30 } |
24 | 31 |
25 WebContentDecryptionModuleAccessImpl* | 32 WebContentDecryptionModuleAccessImpl* |
26 WebContentDecryptionModuleAccessImpl::Create( | 33 WebContentDecryptionModuleAccessImpl::Create( |
27 const blink::WebString& key_system, | 34 const blink::WebString& key_system, |
28 const blink::WebMediaKeySystemConfiguration& configuration, | 35 const blink::WebMediaKeySystemConfiguration& configuration, |
29 const blink::WebSecurityOrigin& security_origin, | 36 const blink::WebSecurityOrigin& security_origin, |
30 CdmFactory* cdm_factory) { | 37 const base::WeakPtr<WebEncryptedMediaClientImpl>& client) { |
31 return new WebContentDecryptionModuleAccessImpl(key_system, configuration, | 38 return new WebContentDecryptionModuleAccessImpl(key_system, configuration, |
32 security_origin, cdm_factory); | 39 security_origin, client); |
33 } | 40 } |
34 | 41 |
35 WebContentDecryptionModuleAccessImpl::WebContentDecryptionModuleAccessImpl( | 42 WebContentDecryptionModuleAccessImpl::WebContentDecryptionModuleAccessImpl( |
36 const blink::WebString& key_system, | 43 const blink::WebString& key_system, |
37 const blink::WebMediaKeySystemConfiguration& configuration, | 44 const blink::WebMediaKeySystemConfiguration& configuration, |
38 const blink::WebSecurityOrigin& security_origin, | 45 const blink::WebSecurityOrigin& security_origin, |
39 CdmFactory* cdm_factory) | 46 const base::WeakPtr<WebEncryptedMediaClientImpl>& client) |
40 : key_system_(key_system), | 47 : key_system_(key_system), |
41 configuration_(configuration), | 48 configuration_(configuration), |
42 security_origin_(security_origin), | 49 security_origin_(security_origin), |
43 cdm_factory_(cdm_factory) { | 50 client_(client) { |
44 } | 51 } |
45 | 52 |
46 WebContentDecryptionModuleAccessImpl::~WebContentDecryptionModuleAccessImpl() { | 53 WebContentDecryptionModuleAccessImpl::~WebContentDecryptionModuleAccessImpl() { |
47 } | 54 } |
48 | 55 |
49 blink::WebMediaKeySystemConfiguration | 56 blink::WebMediaKeySystemConfiguration |
50 WebContentDecryptionModuleAccessImpl::getConfiguration() { | 57 WebContentDecryptionModuleAccessImpl::getConfiguration() { |
51 return configuration_; | 58 return configuration_; |
52 } | 59 } |
53 | 60 |
54 void WebContentDecryptionModuleAccessImpl::createContentDecryptionModule( | 61 void WebContentDecryptionModuleAccessImpl::createContentDecryptionModule( |
55 blink::WebContentDecryptionModuleResult result) { | 62 blink::WebContentDecryptionModuleResult result) { |
56 // This method needs to run asynchronously, as it may need to load the CDM. | 63 // This method needs to run asynchronously, as it may need to load the CDM. |
57 // As this object's lifetime is controlled by MediaKeySystemAccess on the | 64 // As this object's lifetime is controlled by MediaKeySystemAccess on the |
58 // blink side, copy all values needed by CreateCdm() in case the blink object | 65 // blink side, copy all values needed by CreateCdm() in case the blink object |
59 // gets garbage-collected. | 66 // gets garbage-collected. |
60 base::MessageLoopProxy::current()->PostTask( | 67 base::MessageLoopProxy::current()->PostTask( |
61 FROM_HERE, base::Bind(&CreateCdm, cdm_factory_, security_origin_, | 68 FROM_HERE, |
62 key_system_, result)); | 69 base::Bind(&CreateCdm, client_, key_system_, security_origin_, result)); |
63 } | 70 } |
64 | 71 |
65 } // namespace media | 72 } // namespace media |
OLD | NEW |