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 return true; | 578 return true; |
579 } | 579 } |
580 | 580 |
581 DeveloperPrivateInspectFunction::~DeveloperPrivateInspectFunction() {} | 581 DeveloperPrivateInspectFunction::~DeveloperPrivateInspectFunction() {} |
582 | 582 |
583 bool DeveloperPrivateLoadUnpackedFunction::RunImpl() { | 583 bool DeveloperPrivateLoadUnpackedFunction::RunImpl() { |
584 string16 select_title = | 584 string16 select_title = |
585 l10n_util::GetStringUTF16(IDS_EXTENSION_LOAD_FROM_DIRECTORY); | 585 l10n_util::GetStringUTF16(IDS_EXTENSION_LOAD_FROM_DIRECTORY); |
586 | 586 |
587 const ui::SelectFileDialog::Type kSelectType = | 587 const ui::SelectFileDialog::Type kSelectType = |
588 ui::SelectFileDialog::SELECT_FOLDER; | 588 ui::SelectFileDialog::SELECT_FOLDER; |
miket_OOO
2013/01/09 18:52:41
This local constant definition doesn't really make
Gaurav
2013/01/12 01:08:26
Done.
| |
589 const FilePath& last_unpacked_directory = | 589 const FilePath& last_unpacked_directory = |
590 DeveloperPrivateAPI::Get(profile())->getLastUnpackedDirectory(); | 590 DeveloperPrivateAPI::Get(profile())->getLastUnpackedDirectory(); |
591 SetResult(Value::CreateBooleanValue(true)); | 591 SetResult(Value::CreateBooleanValue(true)); |
592 return ShowPicker(kSelectType, last_unpacked_directory, select_title); | 592 return |
miket_OOO
2013/01/09 18:52:41
The newline after this return shouldn't be necessa
Gaurav
2013/01/12 01:08:26
Done.
| |
593 ShowPicker(kSelectType, | |
594 last_unpacked_directory, | |
595 select_title, | |
596 ui::SelectFileDialog::FileTypeInfo(), | |
597 0); | |
593 } | 598 } |
594 | 599 |
595 bool DeveloperPrivateChooseEntryFunction::ShowPicker( | 600 bool DeveloperPrivateChooseEntryFunction::ShowPicker( |
asargent_no_longer_on_chrome
2013/01/09 00:48:05
nit: remove the extra space on this line between b
Gaurav
2013/01/12 01:08:26
Done.
| |
596 ui::SelectFileDialog::Type picker_type, | 601 ui::SelectFileDialog::Type picker_type, |
597 const FilePath& last_directory, | 602 const FilePath& last_directory, |
598 const string16& select_title) { | 603 const string16& select_title, |
604 const ui::SelectFileDialog::FileTypeInfo& info, | |
605 int file_type_index) { | |
599 ShellWindowRegistry* registry = ShellWindowRegistry::Get(profile()); | 606 ShellWindowRegistry* registry = ShellWindowRegistry::Get(profile()); |
600 DCHECK(registry); | 607 DCHECK(registry); |
601 ShellWindow* shell_window = registry->GetShellWindowForRenderViewHost( | 608 ShellWindow* shell_window = registry->GetShellWindowForRenderViewHost( |
602 render_view_host()); | 609 render_view_host()); |
603 if (!shell_window) { | 610 if (!shell_window) { |
604 return false; | 611 return false; |
605 } | 612 } |
606 | 613 |
607 // The entry picker will hold a reference to this function instance, | 614 // The entry picker will hold a reference to this function instance, |
608 // preventing its destruction (and subsequent sending of the function | 615 // preventing its destruction (and subsequent sending of the function |
609 // response) until the user has selected a file or cancelled the picker. | 616 // response) until the user has selected a file or cancelled the picker. |
610 // At that point, the picker will delete itself, which will also free the | 617 // At that point, the picker will delete itself, which will also free the |
611 // function instance. | 618 // function instance. |
612 new EntryPicker(this, shell_window->web_contents(), picker_type, | 619 new EntryPicker(this, shell_window->web_contents(), picker_type, |
613 last_directory, select_title); | 620 last_directory, select_title, info, file_type_index); |
614 return true; | 621 return true; |
615 } | 622 } |
616 | 623 |
617 bool DeveloperPrivateChooseEntryFunction::RunImpl() { return false; } | 624 bool DeveloperPrivateChooseEntryFunction::RunImpl() { return false; } |
618 | 625 |
619 DeveloperPrivateChooseEntryFunction::~DeveloperPrivateChooseEntryFunction() {} | 626 DeveloperPrivateChooseEntryFunction::~DeveloperPrivateChooseEntryFunction() {} |
620 | 627 |
621 void DeveloperPrivateChooseEntryFunction::FileSelected(const FilePath& path) { | 628 void DeveloperPrivateChooseEntryFunction::FileSelected(const FilePath& path) { |
622 | 629 |
623 DeveloperPrivateAPI::Get(profile())->LoadUnpacked(path); | 630 DeveloperPrivateAPI::Get(profile())->LoadUnpacked(path); |
624 SendResponse(true); | 631 SendResponse(true); |
625 } | 632 } |
626 | 633 |
627 void DeveloperPrivateChooseEntryFunction::FileSelectionCanceled() { | 634 void DeveloperPrivateChooseEntryFunction::FileSelectionCanceled() { |
628 SendResponse(false); | 635 SendResponse(false); |
629 } | 636 } |
630 | 637 |
638 | |
639 void DeveloperPrivatePackItemFunction::OnPackSuccess( | |
640 const FilePath& crx_file, | |
641 const FilePath& pem_file) { | |
642 std::string success_message(UTF16ToUTF8( | |
643 extensions::PackExtensionJob::StandardSuccessMessage( | |
644 crx_file, pem_file))); | |
miket_OOO
2013/01/09 18:52:41
Similar comment as earlier in this file: why creat
Gaurav
2013/01/12 01:08:26
Done.
| |
645 developer::PackItemResponse response; | |
646 response.message = success_message; | |
647 response.status = developer::DEVELOPER_PRIVATE_PACK_STATUS_SUCCESS; | |
648 results_ = developer::PackItem::Results::Create(response); | |
649 SendResponse(true); | |
650 Release(); | |
651 } | |
652 | |
653 void DeveloperPrivatePackItemFunction::OnPackFailure( | |
654 const std::string& error, | |
655 extensions::ExtensionCreator::ErrorType error_type) { | |
656 developer::PackItemResponse response; | |
657 response.message = error; | |
658 if (error_type == extensions::ExtensionCreator::kCRXExists) { | |
659 response.item_path = item_path_str_; | |
660 response.pem_path = key_path_str_; | |
661 response.override_flags = extensions::ExtensionCreator::kOverwriteCRX; | |
662 response.status = developer::DEVELOPER_PRIVATE_PACK_STATUS_WARNING; | |
663 } else { | |
664 response.status = developer::DEVELOPER_PRIVATE_PACK_STATUS_ERROR; | |
665 } | |
666 results_ = developer::PackItem::Results::Create(response); | |
667 SendResponse(true); | |
668 Release(); | |
669 } | |
670 | |
671 bool DeveloperPrivatePackItemFunction::RunImpl() { | |
672 int flags; | |
673 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &item_path_str_)); | |
674 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &key_path_str_)); | |
675 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(2, &flags)); | |
676 | |
677 FilePath root_directory = | |
678 FilePath::FromWStringHack(UTF8ToWide(item_path_str_)); | |
679 | |
680 FilePath key_file = | |
681 FilePath::FromWStringHack(UTF8ToWide(key_path_str_)); | |
682 | |
683 developer::PackItemResponse response; | |
684 if (root_directory.empty()) { | |
685 if (item_path_str_.empty()) { | |
686 response.message = l10n_util::GetStringUTF8( | |
687 IDS_EXTENSION_PACK_DIALOG_ERROR_ROOT_REQUIRED); | |
688 } else { | |
689 response.message = l10n_util::GetStringUTF8( | |
miket_OOO
2013/01/09 18:52:41
These inner braces aren't needed.
Gaurav
2013/01/12 01:08:26
Done.
| |
690 IDS_EXTENSION_PACK_DIALOG_ERROR_ROOT_INVALID); | |
691 } | |
692 | |
693 response.status = developer::DEVELOPER_PRIVATE_PACK_STATUS_ERROR; | |
694 results_ = developer::PackItem::Results::Create(response); | |
695 SendResponse(true); | |
696 return true; | |
697 } | |
698 | |
699 if (!key_path_str_.empty() && key_file.empty()) { | |
700 response.message = l10n_util::GetStringUTF8( | |
miket_OOO
2013/01/09 18:52:41
Did you mean to set response.status in this case?
Gaurav
2013/01/12 01:08:26
yes. Fixed now.
On 2013/01/09 18:52:41, miket wrot
| |
701 IDS_EXTENSION_PACK_DIALOG_ERROR_KEY_INVALID); | |
702 results_ = developer::PackItem::Results::Create(response); | |
703 SendResponse(true); | |
704 return true; | |
705 } | |
706 | |
707 // Pack job will release the function instance. | |
708 AddRef(); | |
709 | |
710 pack_job_ = new extensions::PackExtensionJob( | |
711 this, root_directory, key_file, flags); | |
712 pack_job_->Start(); | |
713 return true; | |
714 } | |
715 | |
716 DeveloperPrivatePackItemFunction::DeveloperPrivatePackItemFunction() {} | |
717 | |
718 DeveloperPrivatePackItemFunction::~DeveloperPrivatePackItemFunction() {} | |
719 | |
631 DeveloperPrivateLoadUnpackedFunction::~DeveloperPrivateLoadUnpackedFunction() {} | 720 DeveloperPrivateLoadUnpackedFunction::~DeveloperPrivateLoadUnpackedFunction() {} |
632 | 721 |
722 bool DeveloperPrivateChooseItemFunction::RunImpl() { | |
723 | |
724 std::string select_type; | |
725 std::string file_type; | |
726 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &select_type)); | |
727 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &file_type)); | |
728 ui::SelectFileDialog::Type type = ui::SelectFileDialog::SELECT_FOLDER; | |
729 ui::SelectFileDialog::FileTypeInfo info; | |
730 if (select_type == "file") { | |
731 type = ui::SelectFileDialog::SELECT_OPEN_FILE; | |
miket_OOO
2013/01/09 18:52:41
No braces
Gaurav
2013/01/12 01:08:26
Done.
| |
732 } | |
733 string16 select_title; | |
734 | |
735 int file_type_index = 0; | |
736 if (file_type == "load") { | |
737 select_title = l10n_util::GetStringUTF16(IDS_EXTENSION_LOAD_FROM_DIRECTORY); | |
738 } else if (file_type == "pem") { | |
739 select_title = l10n_util::GetStringUTF16( | |
740 IDS_EXTENSION_PACK_DIALOG_SELECT_KEY); | |
741 info.extensions.push_back(std::vector<FilePath::StringType>()); | |
742 info.extensions.front().push_back(FILE_PATH_LITERAL("pem")); | |
743 info.extension_description_overrides.push_back( | |
744 l10n_util::GetStringUTF16( | |
745 IDS_EXTENSION_PACK_DIALOG_KEY_FILE_TYPE_DESCRIPTION)); | |
746 info.include_all_files = true; | |
747 file_type_index = 1; | |
748 } else { | |
749 NOTREACHED(); | |
750 } | |
751 | |
752 const FilePath& last_unpacked_directory = | |
753 DeveloperPrivateAPI::Get(profile())->getLastUnpackedDirectory(); | |
miket_OOO
2013/01/09 18:52:41
That's a weirdly capitalized method (probably not
Gaurav
2013/01/12 01:08:26
Done.
| |
754 return | |
755 ShowPicker(type, | |
miket_OOO
2013/01/09 18:52:41
Don't wrap after the return.
Gaurav
2013/01/12 01:08:26
Done.
| |
756 last_unpacked_directory, | |
757 select_title, | |
758 info, | |
759 file_type_index); | |
760 } | |
761 | |
762 void DeveloperPrivateChooseItemFunction::FileSelected(const FilePath& path) { | |
763 std::string result(std::string(UTF16ToUTF8(path.LossyDisplayName()))); | |
miket_OOO
2013/01/09 18:52:41
Similar to above (temp variable doesn't add anythi
Gaurav
2013/01/12 01:08:26
Done.
| |
764 SetResult(base::Value::CreateStringValue(result)); | |
765 SendResponse(true); | |
766 } | |
767 | |
768 void DeveloperPrivateChooseItemFunction::FileSelectionCanceled() { | |
769 SendResponse(false); | |
770 } | |
771 | |
772 DeveloperPrivateChooseItemFunction::~DeveloperPrivateChooseItemFunction() {} | |
773 | |
633 bool DeveloperPrivateGetStringsFunction::RunImpl() { | 774 bool DeveloperPrivateGetStringsFunction::RunImpl() { |
634 DictionaryValue* dict = new DictionaryValue(); | 775 DictionaryValue* dict = new DictionaryValue(); |
635 SetResult(dict); | 776 SetResult(dict); |
636 | 777 |
637 #define SET_STRING(id, idr) \ | 778 #define SET_STRING(id, idr) \ |
638 dict->SetString(id, l10n_util::GetStringUTF16(idr)) | 779 dict->SetString(id, l10n_util::GetStringUTF16(idr)) |
639 SET_STRING("extensionSettings", IDS_MANAGE_EXTENSIONS_SETTING_WINDOWS_TITLE); | 780 SET_STRING("extensionSettings", IDS_MANAGE_EXTENSIONS_SETTING_WINDOWS_TITLE); |
640 | 781 |
641 SET_STRING("extensionSettingsNoExtensions", IDS_EXTENSIONS_NONE_INSTALLED); | 782 SET_STRING("extensionSettingsNoExtensions", IDS_EXTENSIONS_NONE_INSTALLED); |
642 SET_STRING("extensionSettingsGetMoreExtensions", IDS_GET_MORE_EXTENSIONS); | 783 SET_STRING("extensionSettingsGetMoreExtensions", IDS_GET_MORE_EXTENSIONS); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
696 | 837 |
697 #undef SET_STRING | 838 #undef SET_STRING |
698 return true; | 839 return true; |
699 } | 840 } |
700 | 841 |
701 DeveloperPrivateGetStringsFunction::~DeveloperPrivateGetStringsFunction() {} | 842 DeveloperPrivateGetStringsFunction::~DeveloperPrivateGetStringsFunction() {} |
702 | 843 |
703 } // namespace api | 844 } // namespace api |
704 | 845 |
705 } // namespace extensions | 846 } // namespace extensions |
OLD | NEW |