| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "chrome/test/chromedriver/chrome_launcher.h" | 5 #include "chrome/test/chromedriver/chrome_launcher.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 // Get extension's ID from public key in crx file. | 490 // Get extension's ID from public key in crx file. |
| 491 // Assumes crx v2. See http://developer.chrome.com/extensions/crx.html. | 491 // Assumes crx v2. See http://developer.chrome.com/extensions/crx.html. |
| 492 std::string key_len_str = decoded_extension.substr(8, 4); | 492 std::string key_len_str = decoded_extension.substr(8, 4); |
| 493 if (key_len_str.size() != 4) | 493 if (key_len_str.size() != 4) |
| 494 return Status(kUnknownError, "cannot extract public key length"); | 494 return Status(kUnknownError, "cannot extract public key length"); |
| 495 uint32 key_len = *reinterpret_cast<const uint32*>(key_len_str.c_str()); | 495 uint32 key_len = *reinterpret_cast<const uint32*>(key_len_str.c_str()); |
| 496 std::string public_key = decoded_extension.substr(16, key_len); | 496 std::string public_key = decoded_extension.substr(16, key_len); |
| 497 if (key_len != public_key.size()) | 497 if (key_len != public_key.size()) |
| 498 return Status(kUnknownError, "invalid public key length"); | 498 return Status(kUnknownError, "invalid public key length"); |
| 499 std::string public_key_base64; | 499 std::string public_key_base64; |
| 500 if (!base::Base64Encode(public_key, &public_key_base64)) | 500 base::Base64Encode(public_key, &public_key_base64); |
| 501 return Status(kUnknownError, "cannot base64 encode public key"); | |
| 502 std::string id = GenerateExtensionId(public_key); | 501 std::string id = GenerateExtensionId(public_key); |
| 503 | 502 |
| 504 // Unzip the crx file. | 503 // Unzip the crx file. |
| 505 base::ScopedTempDir temp_crx_dir; | 504 base::ScopedTempDir temp_crx_dir; |
| 506 if (!temp_crx_dir.CreateUniqueTempDir()) | 505 if (!temp_crx_dir.CreateUniqueTempDir()) |
| 507 return Status(kUnknownError, "cannot create temp dir"); | 506 return Status(kUnknownError, "cannot create temp dir"); |
| 508 base::FilePath extension_crx = temp_crx_dir.path().AppendASCII("temp.crx"); | 507 base::FilePath extension_crx = temp_crx_dir.path().AppendASCII("temp.crx"); |
| 509 int size = static_cast<int>(decoded_extension.length()); | 508 int size = static_cast<int>(decoded_extension.length()); |
| 510 if (file_util::WriteFile(extension_crx, decoded_extension.c_str(), size) != | 509 if (file_util::WriteFile(extension_crx, decoded_extension.c_str(), size) != |
| 511 size) { | 510 size) { |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 // Write empty "First Run" file, otherwise Chrome will wipe the default | 676 // Write empty "First Run" file, otherwise Chrome will wipe the default |
| 678 // profile that was written. | 677 // profile that was written. |
| 679 if (file_util::WriteFile( | 678 if (file_util::WriteFile( |
| 680 user_data_dir.AppendASCII("First Run"), "", 0) != 0) { | 679 user_data_dir.AppendASCII("First Run"), "", 0) != 0) { |
| 681 return Status(kUnknownError, "failed to write first run file"); | 680 return Status(kUnknownError, "failed to write first run file"); |
| 682 } | 681 } |
| 683 return Status(kOk); | 682 return Status(kOk); |
| 684 } | 683 } |
| 685 | 684 |
| 686 } // namespace internal | 685 } // namespace internal |
| OLD | NEW |