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 "chrome/browser/extensions/api/developer_private/developer_private_api.
h" | 5 #include "chrome/browser/extensions/api/developer_private/developer_private_api.
h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 DevToolsWindow::OpenDevToolsWindow(host); | 578 DevToolsWindow::OpenDevToolsWindow(host); |
579 return true; | 579 return true; |
580 } | 580 } |
581 | 581 |
582 DeveloperPrivateInspectFunction::~DeveloperPrivateInspectFunction() {} | 582 DeveloperPrivateInspectFunction::~DeveloperPrivateInspectFunction() {} |
583 | 583 |
584 bool DeveloperPrivateLoadUnpackedFunction::RunImpl() { | 584 bool DeveloperPrivateLoadUnpackedFunction::RunImpl() { |
585 string16 select_title = | 585 string16 select_title = |
586 l10n_util::GetStringUTF16(IDS_EXTENSION_LOAD_FROM_DIRECTORY); | 586 l10n_util::GetStringUTF16(IDS_EXTENSION_LOAD_FROM_DIRECTORY); |
587 | 587 |
588 const ui::SelectFileDialog::Type kSelectType = | |
589 ui::SelectFileDialog::SELECT_FOLDER; | |
590 const FilePath& last_unpacked_directory = | |
591 DeveloperPrivateAPI::Get(profile())->getLastUnpackedDirectory(); | |
592 SetResult(Value::CreateBooleanValue(true)); | 588 SetResult(Value::CreateBooleanValue(true)); |
593 return ShowPicker(kSelectType, last_unpacked_directory, select_title); | 589 int result = |
| 590 ShowPicker( |
| 591 ui::SelectFileDialog::SELECT_FOLDER, |
| 592 DeveloperPrivateAPI::Get(profile())->GetLastUnpackedDirectory(), |
| 593 select_title, |
| 594 ui::SelectFileDialog::FileTypeInfo(), |
| 595 0); |
| 596 return result; |
594 } | 597 } |
595 | 598 |
596 bool DeveloperPrivateChooseEntryFunction::ShowPicker( | 599 void DeveloperPrivateLoadUnpackedFunction::FileSelected(const FilePath& path) { |
| 600 |
| 601 DeveloperPrivateAPI::Get(profile())->LoadUnpacked(path); |
| 602 SendResponse(true); |
| 603 } |
| 604 |
| 605 void DeveloperPrivateLoadUnpackedFunction::FileSelectionCanceled() { |
| 606 SendResponse(false); |
| 607 } |
| 608 |
| 609 bool DeveloperPrivateChooseEntryFunction::ShowPicker( |
597 ui::SelectFileDialog::Type picker_type, | 610 ui::SelectFileDialog::Type picker_type, |
598 const FilePath& last_directory, | 611 const FilePath& last_directory, |
599 const string16& select_title) { | 612 const string16& select_title, |
| 613 const ui::SelectFileDialog::FileTypeInfo& info, |
| 614 int file_type_index) { |
600 ShellWindowRegistry* registry = ShellWindowRegistry::Get(profile()); | 615 ShellWindowRegistry* registry = ShellWindowRegistry::Get(profile()); |
601 DCHECK(registry); | 616 DCHECK(registry); |
602 ShellWindow* shell_window = registry->GetShellWindowForRenderViewHost( | 617 ShellWindow* shell_window = registry->GetShellWindowForRenderViewHost( |
603 render_view_host()); | 618 render_view_host()); |
604 if (!shell_window) { | 619 if (!shell_window) { |
605 return false; | 620 return false; |
606 } | 621 } |
607 | 622 |
608 // The entry picker will hold a reference to this function instance, | 623 // The entry picker will hold a reference to this function instance, |
609 // preventing its destruction (and subsequent sending of the function | 624 // preventing its destruction (and subsequent sending of the function |
610 // response) until the user has selected a file or cancelled the picker. | 625 // response) until the user has selected a file or cancelled the picker. |
611 // At that point, the picker will delete itself, which will also free the | 626 // At that point, the picker will delete itself, which will also free the |
612 // function instance. | 627 // function instance. |
613 new EntryPicker(this, shell_window->web_contents(), picker_type, | 628 new EntryPicker(this, shell_window->web_contents(), picker_type, |
614 last_directory, select_title); | 629 last_directory, select_title, info, file_type_index); |
615 return true; | 630 return true; |
616 } | 631 } |
617 | 632 |
618 bool DeveloperPrivateChooseEntryFunction::RunImpl() { return false; } | 633 bool DeveloperPrivateChooseEntryFunction::RunImpl() { return false; } |
619 | 634 |
620 DeveloperPrivateChooseEntryFunction::~DeveloperPrivateChooseEntryFunction() {} | 635 DeveloperPrivateChooseEntryFunction::~DeveloperPrivateChooseEntryFunction() {} |
621 | 636 |
622 void DeveloperPrivateChooseEntryFunction::FileSelected(const FilePath& path) { | 637 void DeveloperPrivatePackDirectoryFunction::OnPackSuccess( |
| 638 const FilePath& crx_file, |
| 639 const FilePath& pem_file) { |
| 640 developer::PackDirectoryResponse response; |
| 641 response.message = |
| 642 UTF16ToUTF8(extensions::PackExtensionJob::StandardSuccessMessage( |
| 643 crx_file, pem_file)); |
| 644 response.status = developer::DEVELOPER_PRIVATE_PACK_STATUS_SUCCESS; |
| 645 results_ = developer::PackDirectory::Results::Create(response); |
| 646 SendResponse(true); |
| 647 Release(); |
| 648 } |
623 | 649 |
624 DeveloperPrivateAPI::Get(profile())->LoadUnpacked(path); | 650 void DeveloperPrivatePackDirectoryFunction::OnPackFailure( |
| 651 const std::string& error, |
| 652 extensions::ExtensionCreator::ErrorType error_type) { |
| 653 developer::PackDirectoryResponse response; |
| 654 response.message = error; |
| 655 if (error_type == extensions::ExtensionCreator::kCRXExists) { |
| 656 response.item_path = item_path_str_; |
| 657 response.pem_path = key_path_str_; |
| 658 response.override_flags = extensions::ExtensionCreator::kOverwriteCRX; |
| 659 response.status = developer::DEVELOPER_PRIVATE_PACK_STATUS_WARNING; |
| 660 } else { |
| 661 response.status = developer::DEVELOPER_PRIVATE_PACK_STATUS_ERROR; |
| 662 } |
| 663 results_ = developer::PackDirectory::Results::Create(response); |
| 664 SendResponse(true); |
| 665 Release(); |
| 666 } |
| 667 |
| 668 bool DeveloperPrivatePackDirectoryFunction::RunImpl() { |
| 669 int flags; |
| 670 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &item_path_str_)); |
| 671 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &key_path_str_)); |
| 672 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(2, &flags)); |
| 673 |
| 674 FilePath root_directory = |
| 675 FilePath::FromWStringHack(UTF8ToWide(item_path_str_)); |
| 676 |
| 677 FilePath key_file = |
| 678 FilePath::FromWStringHack(UTF8ToWide(key_path_str_)); |
| 679 |
| 680 developer::PackDirectoryResponse response; |
| 681 if (root_directory.empty()) { |
| 682 if (item_path_str_.empty()) |
| 683 response.message = l10n_util::GetStringUTF8( |
| 684 IDS_EXTENSION_PACK_DIALOG_ERROR_ROOT_REQUIRED); |
| 685 else |
| 686 response.message = l10n_util::GetStringUTF8( |
| 687 IDS_EXTENSION_PACK_DIALOG_ERROR_ROOT_INVALID); |
| 688 |
| 689 response.status = developer::DEVELOPER_PRIVATE_PACK_STATUS_ERROR; |
| 690 results_ = developer::PackDirectory::Results::Create(response); |
| 691 SendResponse(true); |
| 692 return true; |
| 693 } |
| 694 |
| 695 if (!key_path_str_.empty() && key_file.empty()) { |
| 696 response.message = l10n_util::GetStringUTF8( |
| 697 IDS_EXTENSION_PACK_DIALOG_ERROR_KEY_INVALID); |
| 698 response.status = developer::DEVELOPER_PRIVATE_PACK_STATUS_ERROR; |
| 699 results_ = developer::PackDirectory::Results::Create(response); |
| 700 SendResponse(true); |
| 701 return true; |
| 702 } |
| 703 |
| 704 // Pack job will release the function instance. |
| 705 AddRef(); |
| 706 |
| 707 pack_job_ = new extensions::PackExtensionJob( |
| 708 this, root_directory, key_file, flags); |
| 709 pack_job_->Start(); |
| 710 return true; |
| 711 } |
| 712 |
| 713 DeveloperPrivatePackDirectoryFunction::DeveloperPrivatePackDirectoryFunction() |
| 714 {} |
| 715 |
| 716 DeveloperPrivatePackDirectoryFunction::~DeveloperPrivatePackDirectoryFunction() |
| 717 {} |
| 718 |
| 719 DeveloperPrivateLoadUnpackedFunction::~DeveloperPrivateLoadUnpackedFunction() {} |
| 720 |
| 721 bool DeveloperPrivateChoosePathFunction::RunImpl() { |
| 722 |
| 723 scoped_ptr<developer::ChoosePath::Params> params( |
| 724 developer::ChoosePath::Params::Create(*args_)); |
| 725 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
| 726 |
| 727 ui::SelectFileDialog::Type type = ui::SelectFileDialog::SELECT_FOLDER; |
| 728 ui::SelectFileDialog::FileTypeInfo info; |
| 729 if (params->select_type == developer::DEVELOPER_PRIVATE_SELECT_TYPE_FILE) { |
| 730 type = ui::SelectFileDialog::SELECT_OPEN_FILE; |
| 731 } |
| 732 string16 select_title; |
| 733 |
| 734 int file_type_index = 0; |
| 735 if (params->file_type == developer::DEVELOPER_PRIVATE_FILE_TYPE_LOAD) |
| 736 select_title = l10n_util::GetStringUTF16(IDS_EXTENSION_LOAD_FROM_DIRECTORY); |
| 737 else if (params->file_type== developer::DEVELOPER_PRIVATE_FILE_TYPE_PEM) { |
| 738 select_title = l10n_util::GetStringUTF16( |
| 739 IDS_EXTENSION_PACK_DIALOG_SELECT_KEY); |
| 740 info.extensions.push_back(std::vector<FilePath::StringType>()); |
| 741 info.extensions.front().push_back(FILE_PATH_LITERAL("pem")); |
| 742 info.extension_description_overrides.push_back( |
| 743 l10n_util::GetStringUTF16( |
| 744 IDS_EXTENSION_PACK_DIALOG_KEY_FILE_TYPE_DESCRIPTION)); |
| 745 info.include_all_files = true; |
| 746 file_type_index = 1; |
| 747 } else { |
| 748 NOTREACHED(); |
| 749 } |
| 750 |
| 751 int result = |
| 752 ShowPicker( |
| 753 type, |
| 754 DeveloperPrivateAPI::Get(profile())->GetLastUnpackedDirectory(), |
| 755 select_title, |
| 756 info, |
| 757 file_type_index); |
| 758 return result; |
| 759 } |
| 760 |
| 761 void DeveloperPrivateChoosePathFunction::FileSelected(const FilePath& path) { |
| 762 SetResult(base::Value::CreateStringValue( |
| 763 UTF16ToUTF8(path.LossyDisplayName()))); |
625 SendResponse(true); | 764 SendResponse(true); |
626 } | 765 } |
627 | 766 |
628 void DeveloperPrivateChooseEntryFunction::FileSelectionCanceled() { | 767 void DeveloperPrivateChoosePathFunction::FileSelectionCanceled() { |
629 SendResponse(false); | 768 SendResponse(false); |
630 } | 769 } |
631 | 770 |
632 DeveloperPrivateLoadUnpackedFunction::~DeveloperPrivateLoadUnpackedFunction() {} | 771 DeveloperPrivateChoosePathFunction::~DeveloperPrivateChoosePathFunction() {} |
633 | 772 |
634 bool DeveloperPrivateGetStringsFunction::RunImpl() { | 773 bool DeveloperPrivateGetStringsFunction::RunImpl() { |
635 DictionaryValue* dict = new DictionaryValue(); | 774 DictionaryValue* dict = new DictionaryValue(); |
636 SetResult(dict); | 775 SetResult(dict); |
637 | 776 |
638 #define SET_STRING(id, idr) \ | 777 #define SET_STRING(id, idr) \ |
639 dict->SetString(id, l10n_util::GetStringUTF16(idr)) | 778 dict->SetString(id, l10n_util::GetStringUTF16(idr)) |
640 SET_STRING("extensionSettings", IDS_MANAGE_EXTENSIONS_SETTING_WINDOWS_TITLE); | 779 SET_STRING("extensionSettings", IDS_MANAGE_EXTENSIONS_SETTING_WINDOWS_TITLE); |
641 | 780 |
642 SET_STRING("extensionSettingsNoExtensions", IDS_EXTENSIONS_NONE_INSTALLED); | 781 SET_STRING("extensionSettingsNoExtensions", IDS_EXTENSIONS_NONE_INSTALLED); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 | 836 |
698 #undef SET_STRING | 837 #undef SET_STRING |
699 return true; | 838 return true; |
700 } | 839 } |
701 | 840 |
702 DeveloperPrivateGetStringsFunction::~DeveloperPrivateGetStringsFunction() {} | 841 DeveloperPrivateGetStringsFunction::~DeveloperPrivateGetStringsFunction() {} |
703 | 842 |
704 } // namespace api | 843 } // namespace api |
705 | 844 |
706 } // namespace extensions | 845 } // namespace extensions |
OLD | NEW |