| 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 "media/cdm/ppapi/external_clear_key/clear_key_cdm.h" | 5 #include "media/cdm/ppapi/external_clear_key/clear_key_cdm.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cstring> | 8 #include <cstring> |
| 9 #include <sstream> | 9 #include <sstream> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 | 265 |
| 266 const char* GetCdmVersion() { | 266 const char* GetCdmVersion() { |
| 267 return kClearKeyCdmVersion; | 267 return kClearKeyCdmVersion; |
| 268 } | 268 } |
| 269 | 269 |
| 270 static bool g_verify_host_files_result = false; | 270 static bool g_verify_host_files_result = false; |
| 271 | 271 |
| 272 // Makes sure files and corresponding signature files are readable but not | 272 // Makes sure files and corresponding signature files are readable but not |
| 273 // writable. | 273 // writable. |
| 274 bool VerifyCdmHost_0(const cdm::HostFile* host_files, uint32_t num_files) { | 274 bool VerifyCdmHost_0(const cdm::HostFile* host_files, uint32_t num_files) { |
| 275 DVLOG(1) << __func__ << ": " << num_files; | 275 DVLOG(1) << __func__; |
| 276 | |
| 277 // We should always have the CDM and CDM adapter and at lease one common file. | |
| 278 // The common CDM host file (e.g. chrome) might not exist since we are running | |
| 279 // in browser_tests. | |
| 280 const uint32_t kMinNumHostFiles = 3; | |
| 281 | 276 |
| 282 // We should always have the CDM and CDM adapter. | 277 // We should always have the CDM and CDM adapter. |
| 283 const int kNumCdmFiles = 2; | 278 // We might not have any common CDM host file (e.g. chrome) since we are |
| 284 | 279 // running in browser_tests. |
| 285 if (num_files < kMinNumHostFiles) { | 280 if (num_files < 2) { |
| 286 LOG(ERROR) << "Too few host files: " << num_files; | 281 LOG(ERROR) << "Too few host files: " << num_files; |
| 287 g_verify_host_files_result = false; | 282 g_verify_host_files_result = false; |
| 288 return true; | 283 return true; |
| 289 } | 284 } |
| 290 | 285 |
| 291 int num_opened_files = 0; | |
| 292 for (uint32_t i = 0; i < num_files; ++i) { | 286 for (uint32_t i = 0; i < num_files; ++i) { |
| 293 const int kBytesToRead = 10; | 287 const int kBytesToRead = 10; |
| 294 std::vector<char> buffer(kBytesToRead); | 288 std::vector<char> buffer(kBytesToRead); |
| 295 | 289 |
| 296 base::File file(static_cast<base::PlatformFile>(host_files[i].file)); | 290 base::File file(static_cast<base::PlatformFile>(host_files[i].file)); |
| 297 if (!file.IsValid()) | |
| 298 continue; | |
| 299 | |
| 300 num_opened_files++; | |
| 301 | |
| 302 int bytes_read = file.Read(0, buffer.data(), buffer.size()); | 291 int bytes_read = file.Read(0, buffer.data(), buffer.size()); |
| 303 if (bytes_read != kBytesToRead) { | 292 if (bytes_read != kBytesToRead) { |
| 304 LOG(ERROR) << "File bytes read: " << bytes_read; | 293 LOG(ERROR) << "File bytes read: " << bytes_read; |
| 305 g_verify_host_files_result = false; | 294 g_verify_host_files_result = false; |
| 306 return true; | 295 return true; |
| 307 } | 296 } |
| 308 | 297 |
| 309 // TODO(xhwang): Check that the files are not writable. | 298 // TODO(xhwang): Check that the files are not writable. |
| 310 // TODO(xhwang): Also verify the signature file when it's available. | 299 // TODO(xhwang): Also verify the signature file when it's available. |
| 311 } | 300 } |
| 312 | 301 |
| 313 // We should always have CDM files opened. | |
| 314 if (num_opened_files < kNumCdmFiles) { | |
| 315 LOG(ERROR) << "Too few opened files: " << num_opened_files; | |
| 316 g_verify_host_files_result = false; | |
| 317 return true; | |
| 318 } | |
| 319 | |
| 320 g_verify_host_files_result = true; | 302 g_verify_host_files_result = true; |
| 321 return true; | 303 return true; |
| 322 } | 304 } |
| 323 | 305 |
| 324 namespace media { | 306 namespace media { |
| 325 | 307 |
| 326 ClearKeyCdm::ClearKeyCdm(ClearKeyCdmHost* host, | 308 ClearKeyCdm::ClearKeyCdm(ClearKeyCdmHost* host, |
| 327 const std::string& key_system, | 309 const std::string& key_system, |
| 328 const GURL& origin) | 310 const GURL& origin) |
| 329 : decryptor_(new AesDecryptor( | 311 : decryptor_(new AesDecryptor( |
| (...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1065 challenge.data(), challenge.size()); | 1047 challenge.data(), challenge.size()); |
| 1066 } | 1048 } |
| 1067 | 1049 |
| 1068 void ClearKeyCdm::VerifyCdmHostTest() { | 1050 void ClearKeyCdm::VerifyCdmHostTest() { |
| 1069 // VerifyCdmHost() should have already been called and test result stored | 1051 // VerifyCdmHost() should have already been called and test result stored |
| 1070 // in |g_verify_host_files_result|. | 1052 // in |g_verify_host_files_result|. |
| 1071 OnUnitTestComplete(g_verify_host_files_result); | 1053 OnUnitTestComplete(g_verify_host_files_result); |
| 1072 } | 1054 } |
| 1073 | 1055 |
| 1074 } // namespace media | 1056 } // namespace media |
| OLD | NEW |