OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "webkit/media/crypto/proxy_decryptor.h" | 5 #include "webkit/media/crypto/proxy_decryptor.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "media/base/decoder_buffer.h" | 8 #include "media/base/decoder_buffer.h" |
9 #include "media/base/decryptor_client.h" | 9 #include "media/base/decryptor_client.h" |
10 #include "media/crypto/aes_decryptor.h" | 10 #include "media/crypto/aes_decryptor.h" |
11 #include "webkit/media/crypto/key_systems.h" | 11 #include "webkit/media/crypto/key_systems.h" |
12 #include "webkit/media/crypto/ppapi_decryptor.h" | |
12 | 13 |
13 namespace webkit_media { | 14 namespace webkit_media { |
14 | 15 |
15 ProxyDecryptor::ProxyDecryptor(media::DecryptorClient* client) | 16 ProxyDecryptor::ProxyDecryptor( |
16 : client_(client) { | 17 media::DecryptorClient* decryptor_client, |
18 WebKit::WebMediaPlayerClient* web_media_player_client, | |
19 WebKit::WebFrame* web_frame) | |
20 : client_(decryptor_client), | |
21 web_media_player_client_(web_media_player_client), | |
22 web_frame_(web_frame) { | |
17 } | 23 } |
18 | 24 |
19 ProxyDecryptor::~ProxyDecryptor() { | 25 ProxyDecryptor::~ProxyDecryptor() { |
20 } | 26 } |
21 | 27 |
22 void ProxyDecryptor::GenerateKeyRequest(const std::string& key_system, | 28 void ProxyDecryptor::GenerateKeyRequest(const std::string& key_system, |
23 const uint8* init_data, | 29 const uint8* init_data, |
24 int init_data_length) { | 30 int init_data_length) { |
25 // We do not support run-time switching of decryptors. GenerateKeyRequest() | 31 // We do not support run-time switching of decryptors. GenerateKeyRequest() |
26 // only creates a new decryptor when |decryptor_| is not initialized. | 32 // only creates a new decryptor when |decryptor_| is not initialized. |
27 if (!decryptor_.get()) { | 33 if (!decryptor_.get()) { |
28 base::AutoLock auto_lock(lock_); | 34 base::AutoLock auto_lock(lock_); |
29 decryptor_ = CreateDecryptor(key_system, client_); | 35 decryptor_ = CreateDecryptor(key_system); |
30 } | 36 } |
31 | 37 |
32 DCHECK(decryptor_.get()); | 38 DCHECK(client_); |
39 if (!decryptor_.get()) { | |
40 // TODO(ddorwin): Update the spec about generateKeyRequest to include an | |
41 // error for handler loading failure. In our case, this can happen when the | |
42 // plugin cannot be loaded. | |
43 client_->KeyError(key_system, "", Decryptor::kUnknownError, 0); | |
44 return; | |
45 } | |
46 | |
33 decryptor_->GenerateKeyRequest(key_system, init_data, init_data_length); | 47 decryptor_->GenerateKeyRequest(key_system, init_data, init_data_length); |
34 } | 48 } |
35 | 49 |
36 void ProxyDecryptor::AddKey(const std::string& key_system, | 50 void ProxyDecryptor::AddKey(const std::string& key_system, |
37 const uint8* key, | 51 const uint8* key, |
38 int key_length, | 52 int key_length, |
39 const uint8* init_data, | 53 const uint8* init_data, |
40 int init_data_length, | 54 int init_data_length, |
41 const std::string& session_id) { | 55 const std::string& session_id) { |
42 // WebMediaPlayerImpl ensures GenerateKeyRequest() has been called. | 56 // WebMediaPlayerImpl ensures GenerateKeyRequest() has been called. |
(...skipping 17 matching lines...) Expand all Loading... | |
60 { | 74 { |
61 base::AutoLock auto_lock(lock_); | 75 base::AutoLock auto_lock(lock_); |
62 decryptor = decryptor_.get(); | 76 decryptor = decryptor_.get(); |
63 } | 77 } |
64 if (!decryptor) | 78 if (!decryptor) |
65 decrypt_cb.Run(kError, NULL); | 79 decrypt_cb.Run(kError, NULL); |
66 | 80 |
67 return decryptor->Decrypt(encrypted, decrypt_cb); | 81 return decryptor->Decrypt(encrypted, decrypt_cb); |
68 } | 82 } |
69 | 83 |
84 scoped_ptr<media::Decryptor> ProxyDecryptor::CreateDecryptor( | |
85 const std::string& key_system) { | |
86 DCHECK(client_); | |
87 DCHECK(web_media_player_client_); | |
88 DCHECK(web_frame_); | |
89 | |
90 if (CanUseAesDecryptor(key_system)) | |
91 return scoped_ptr<media::Decryptor>(new media::AesDecryptor(client_)); | |
92 | |
93 // For now, we only support AesDecryptor and PpapiDecryptor. So if we cannot | |
ddorwin
2012/07/19 01:12:34
You can remove "For now, ".
xhwang
2012/07/19 15:54:34
Done.
| |
94 // use the AesDecryptor, then we'll try to create a PpapiDecryptor for given | |
95 // |key_system|. | |
96 scoped_ptr<PpapiDecryptor> ppapi_decryptor(new PpapiDecryptor(client_)); | |
97 if (ppapi_decryptor->Init(key_system, web_media_player_client_, web_frame_)) | |
ddorwin
2012/07/19 01:12:34
Since we are creating and initializing a PpapiDecr
xhwang
2012/07/19 15:54:34
Done.
| |
98 return scoped_ptr<media::Decryptor>(ppapi_decryptor.release()); | |
99 | |
100 return scoped_ptr<media::Decryptor>(); | |
101 } | |
102 | |
70 } // namespace webkit_media | 103 } // namespace webkit_media |
OLD | NEW |