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/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 // TODO(xhwang): Simplify this function. This is mostly caused by the fact that | 51 // TODO(xhwang): Simplify this function. This is mostly caused by the fact that |
52 // we need to copy a scoped_array<uint8>. | 52 // we need to copy a scoped_array<uint8>. |
53 static void FireNeedKey(media::DecryptorClient* client, | 53 static void FireNeedKey(media::DecryptorClient* client, |
54 const scoped_refptr<media::DecoderBuffer>& encrypted) { | 54 const scoped_refptr<media::DecoderBuffer>& encrypted) { |
55 DCHECK(client); | 55 DCHECK(client); |
56 DCHECK(encrypted); | 56 DCHECK(encrypted); |
57 DCHECK(encrypted->GetDecryptConfig()); | 57 DCHECK(encrypted->GetDecryptConfig()); |
58 std::string key_id = encrypted->GetDecryptConfig()->key_id(); | 58 std::string key_id = encrypted->GetDecryptConfig()->key_id(); |
59 scoped_array<uint8> key_id_array(new uint8[key_id.size()]); | 59 scoped_array<uint8> key_id_array(new uint8[key_id.size()]); |
60 memcpy(key_id_array.get(), key_id.data(), key_id.size()); | 60 memcpy(key_id_array.get(), key_id.data(), key_id.size()); |
61 client->NeedKey("", "", key_id_array.Pass(), key_id.size()); | 61 client->NeedKey("", "", "", key_id_array.Pass(), key_id.size()); |
62 } | 62 } |
63 | 63 |
64 ProxyDecryptor::ProxyDecryptor( | 64 ProxyDecryptor::ProxyDecryptor( |
65 const scoped_refptr<base::MessageLoopProxy>& message_loop, | 65 const scoped_refptr<base::MessageLoopProxy>& message_loop, |
66 media::DecryptorClient* decryptor_client, | 66 media::DecryptorClient* decryptor_client, |
67 WebKit::WebMediaPlayerClient* web_media_player_client, | 67 WebKit::WebMediaPlayerClient* web_media_player_client, |
68 WebKit::WebFrame* web_frame) | 68 WebKit::WebFrame* web_frame) |
69 : decryption_message_loop_(message_loop), | 69 : decryption_message_loop_(message_loop), |
70 client_(decryptor_client), | 70 client_(decryptor_client), |
71 web_media_player_client_(web_media_player_client), | 71 web_media_player_client_(web_media_player_client), |
(...skipping 22 matching lines...) Expand all Loading... |
94 // Normal decryptor request. | 94 // Normal decryptor request. |
95 DCHECK(decryptor_notification_cb_.is_null()); | 95 DCHECK(decryptor_notification_cb_.is_null()); |
96 if (decryptor_) { | 96 if (decryptor_) { |
97 decryptor_notification_cb.Run(decryptor_.get()); | 97 decryptor_notification_cb.Run(decryptor_.get()); |
98 return; | 98 return; |
99 } | 99 } |
100 decryptor_notification_cb_ = decryptor_notification_cb; | 100 decryptor_notification_cb_ = decryptor_notification_cb; |
101 } | 101 } |
102 | 102 |
103 bool ProxyDecryptor::GenerateKeyRequest(const std::string& key_system, | 103 bool ProxyDecryptor::GenerateKeyRequest(const std::string& key_system, |
| 104 const std::string& type, |
104 const uint8* init_data, | 105 const uint8* init_data, |
105 int init_data_length) { | 106 int init_data_length) { |
106 // We do not support run-time switching of decryptors. GenerateKeyRequest() | 107 // We do not support run-time switching of decryptors. GenerateKeyRequest() |
107 // only creates a new decryptor when |decryptor_| is not initialized. | 108 // only creates a new decryptor when |decryptor_| is not initialized. |
108 DVLOG(1) << "GenerateKeyRequest: key_system = " << key_system; | 109 DVLOG(1) << "GenerateKeyRequest: key_system = " << key_system; |
109 | 110 |
110 base::AutoLock auto_lock(lock_); | 111 base::AutoLock auto_lock(lock_); |
111 | 112 |
112 if (!decryptor_) { | 113 if (!decryptor_) { |
113 decryptor_ = CreateDecryptor(key_system); | 114 decryptor_ = CreateDecryptor(key_system); |
114 if (!decryptor_) { | 115 if (!decryptor_) { |
115 client_->KeyError(key_system, "", media::Decryptor::kUnknownError, 0); | 116 client_->KeyError(key_system, "", media::Decryptor::kUnknownError, 0); |
116 return false; | 117 return false; |
117 } | 118 } |
118 } | 119 } |
119 | 120 |
120 if (!decryptor_->GenerateKeyRequest(key_system, | 121 if (!decryptor_->GenerateKeyRequest(key_system, type, |
121 init_data, init_data_length)) { | 122 init_data, init_data_length)) { |
122 decryptor_.reset(); | 123 decryptor_.reset(); |
123 return false; | 124 return false; |
124 } | 125 } |
125 | 126 |
126 if (!decryptor_notification_cb_.is_null()) | 127 if (!decryptor_notification_cb_.is_null()) |
127 base::ResetAndReturn(&decryptor_notification_cb_).Run(decryptor_.get()); | 128 base::ResetAndReturn(&decryptor_notification_cb_).Run(decryptor_.get()); |
128 | 129 |
129 return true; | 130 return true; |
130 } | 131 } |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 return; | 353 return; |
353 } | 354 } |
354 | 355 |
355 // TODO(xhwang): The same NeedKey may be fired multiple times here and also | 356 // TODO(xhwang): The same NeedKey may be fired multiple times here and also |
356 // in Decrypt(). While the spec says only one NeedKey should be fired. Leave | 357 // in Decrypt(). While the spec says only one NeedKey should be fired. Leave |
357 // them as is since the spec about this may change. | 358 // them as is since the spec about this may change. |
358 FireNeedKey(client_, pending_buffer_to_decrypt_); | 359 FireNeedKey(client_, pending_buffer_to_decrypt_); |
359 } | 360 } |
360 | 361 |
361 } // namespace webkit_media | 362 } // namespace webkit_media |
OLD | NEW |