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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 #endif | 58 #endif |
59 | 59 |
60 Status UnpackAutomationExtension(const base::FilePath& temp_dir, | 60 Status UnpackAutomationExtension(const base::FilePath& temp_dir, |
61 base::FilePath* automation_extension) { | 61 base::FilePath* automation_extension) { |
62 std::string decoded_extension; | 62 std::string decoded_extension; |
63 if (!base::Base64Decode(kAutomationExtension, &decoded_extension)) | 63 if (!base::Base64Decode(kAutomationExtension, &decoded_extension)) |
64 return Status(kUnknownError, "failed to base64decode automation extension"); | 64 return Status(kUnknownError, "failed to base64decode automation extension"); |
65 | 65 |
66 base::FilePath extension_zip = temp_dir.AppendASCII("internal.zip"); | 66 base::FilePath extension_zip = temp_dir.AppendASCII("internal.zip"); |
67 int size = static_cast<int>(decoded_extension.length()); | 67 int size = static_cast<int>(decoded_extension.length()); |
68 if (file_util::WriteFile(extension_zip, decoded_extension.c_str(), size) | 68 if (base::WriteFile(extension_zip, decoded_extension.c_str(), size) |
69 != size) { | 69 != size) { |
70 return Status(kUnknownError, "failed to write automation extension zip"); | 70 return Status(kUnknownError, "failed to write automation extension zip"); |
71 } | 71 } |
72 | 72 |
73 base::FilePath extension_dir = temp_dir.AppendASCII("internal"); | 73 base::FilePath extension_dir = temp_dir.AppendASCII("internal"); |
74 if (!zip::Unzip(extension_zip, extension_dir)) | 74 if (!zip::Unzip(extension_zip, extension_dir)) |
75 return Status(kUnknownError, "failed to unzip automation extension"); | 75 return Status(kUnknownError, "failed to unzip automation extension"); |
76 | 76 |
77 *automation_extension = extension_dir; | 77 *automation_extension = extension_dir; |
78 return Status(kOk); | 78 return Status(kOk); |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 std::string public_key_base64; | 506 std::string public_key_base64; |
507 base::Base64Encode(public_key, &public_key_base64); | 507 base::Base64Encode(public_key, &public_key_base64); |
508 std::string id = GenerateExtensionId(public_key); | 508 std::string id = GenerateExtensionId(public_key); |
509 | 509 |
510 // Unzip the crx file. | 510 // Unzip the crx file. |
511 base::ScopedTempDir temp_crx_dir; | 511 base::ScopedTempDir temp_crx_dir; |
512 if (!temp_crx_dir.CreateUniqueTempDir()) | 512 if (!temp_crx_dir.CreateUniqueTempDir()) |
513 return Status(kUnknownError, "cannot create temp dir"); | 513 return Status(kUnknownError, "cannot create temp dir"); |
514 base::FilePath extension_crx = temp_crx_dir.path().AppendASCII("temp.crx"); | 514 base::FilePath extension_crx = temp_crx_dir.path().AppendASCII("temp.crx"); |
515 int size = static_cast<int>(decoded_extension.length()); | 515 int size = static_cast<int>(decoded_extension.length()); |
516 if (file_util::WriteFile(extension_crx, decoded_extension.c_str(), size) != | 516 if (base::WriteFile(extension_crx, decoded_extension.c_str(), size) != |
517 size) { | 517 size) { |
518 return Status(kUnknownError, "cannot write file"); | 518 return Status(kUnknownError, "cannot write file"); |
519 } | 519 } |
520 base::FilePath extension_dir = temp_dir.AppendASCII("extension_" + id); | 520 base::FilePath extension_dir = temp_dir.AppendASCII("extension_" + id); |
521 if (!zip::Unzip(extension_crx, extension_dir)) | 521 if (!zip::Unzip(extension_crx, extension_dir)) |
522 return Status(kUnknownError, "cannot unzip"); | 522 return Status(kUnknownError, "cannot unzip"); |
523 | 523 |
524 // Parse the manifest and set the 'key' if not already present. | 524 // Parse the manifest and set the 'key' if not already present. |
525 base::FilePath manifest_path(extension_dir.AppendASCII("manifest.json")); | 525 base::FilePath manifest_path(extension_dir.AppendASCII("manifest.json")); |
526 std::string manifest_data; | 526 std::string manifest_data; |
(...skipping 19 matching lines...) Expand all Loading... |
546 << std::endl << "key from header: " << public_key_base64 | 546 << std::endl << "key from header: " << public_key_base64 |
547 << std::endl << "key from manifest: " << manifest_key_base64 | 547 << std::endl << "key from manifest: " << manifest_key_base64 |
548 << std::endl << "generated extension id from header key: " << id | 548 << std::endl << "generated extension id from header key: " << id |
549 << std::endl << "generated extension id from manifest key: " | 549 << std::endl << "generated extension id from manifest key: " |
550 << manifest_id; | 550 << manifest_id; |
551 id = manifest_id; | 551 id = manifest_id; |
552 } | 552 } |
553 } else { | 553 } else { |
554 manifest->SetString("key", public_key_base64); | 554 manifest->SetString("key", public_key_base64); |
555 base::JSONWriter::Write(manifest, &manifest_data); | 555 base::JSONWriter::Write(manifest, &manifest_data); |
556 if (file_util::WriteFile( | 556 if (base::WriteFile( |
557 manifest_path, manifest_data.c_str(), manifest_data.size()) != | 557 manifest_path, manifest_data.c_str(), manifest_data.size()) != |
558 static_cast<int>(manifest_data.size())) { | 558 static_cast<int>(manifest_data.size())) { |
559 return Status(kUnknownError, "cannot add 'key' to manifest"); | 559 return Status(kUnknownError, "cannot add 'key' to manifest"); |
560 } | 560 } |
561 } | 561 } |
562 | 562 |
563 // Get extension's background page URL, if there is one. | 563 // Get extension's background page URL, if there is one. |
564 std::string bg_page_tmp; | 564 std::string bg_page_tmp; |
565 Status status = GetExtensionBackgroundPage(manifest, id, &bg_page_tmp); | 565 Status status = GetExtensionBackgroundPage(manifest, id, &bg_page_tmp); |
566 if (status.IsError()) | 566 if (status.IsError()) |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 for (base::DictionaryValue::Iterator it(*custom_prefs); !it.IsAtEnd(); | 644 for (base::DictionaryValue::Iterator it(*custom_prefs); !it.IsAtEnd(); |
645 it.Advance()) { | 645 it.Advance()) { |
646 prefs->Set(it.key(), it.value().DeepCopy()); | 646 prefs->Set(it.key(), it.value().DeepCopy()); |
647 } | 647 } |
648 } | 648 } |
649 | 649 |
650 std::string prefs_str; | 650 std::string prefs_str; |
651 base::JSONWriter::Write(prefs, &prefs_str); | 651 base::JSONWriter::Write(prefs, &prefs_str); |
652 VLOG(0) << "Populating " << path.BaseName().value() | 652 VLOG(0) << "Populating " << path.BaseName().value() |
653 << " file: " << PrettyPrintValue(*prefs); | 653 << " file: " << PrettyPrintValue(*prefs); |
654 if (static_cast<int>(prefs_str.length()) != file_util::WriteFile( | 654 if (static_cast<int>(prefs_str.length()) != base::WriteFile( |
655 path, prefs_str.c_str(), prefs_str.length())) { | 655 path, prefs_str.c_str(), prefs_str.length())) { |
656 return Status(kUnknownError, "failed to write prefs file"); | 656 return Status(kUnknownError, "failed to write prefs file"); |
657 } | 657 } |
658 return Status(kOk); | 658 return Status(kOk); |
659 } | 659 } |
660 | 660 |
661 Status PrepareUserDataDir( | 661 Status PrepareUserDataDir( |
662 const base::FilePath& user_data_dir, | 662 const base::FilePath& user_data_dir, |
663 const base::DictionaryValue* custom_prefs, | 663 const base::DictionaryValue* custom_prefs, |
664 const base::DictionaryValue* custom_local_state) { | 664 const base::DictionaryValue* custom_local_state) { |
(...skipping 10 matching lines...) Expand all Loading... |
675 return status; | 675 return status; |
676 | 676 |
677 status = WritePrefsFile(kLocalState, | 677 status = WritePrefsFile(kLocalState, |
678 custom_local_state, | 678 custom_local_state, |
679 user_data_dir.Append(chrome::kLocalStateFilename)); | 679 user_data_dir.Append(chrome::kLocalStateFilename)); |
680 if (status.IsError()) | 680 if (status.IsError()) |
681 return status; | 681 return status; |
682 | 682 |
683 // Write empty "First Run" file, otherwise Chrome will wipe the default | 683 // Write empty "First Run" file, otherwise Chrome will wipe the default |
684 // profile that was written. | 684 // profile that was written. |
685 if (file_util::WriteFile( | 685 if (base::WriteFile( |
686 user_data_dir.Append(chrome::kFirstRunSentinel), "", 0) != 0) { | 686 user_data_dir.Append(chrome::kFirstRunSentinel), "", 0) != 0) { |
687 return Status(kUnknownError, "failed to write first run file"); | 687 return Status(kUnknownError, "failed to write first run file"); |
688 } | 688 } |
689 return Status(kOk); | 689 return Status(kOk); |
690 } | 690 } |
691 | 691 |
692 } // namespace internal | 692 } // namespace internal |
OLD | NEW |