Chromium Code Reviews| Index: chrome/browser/extensions/api/developer_private/developer_private_api.cc |
| diff --git a/chrome/browser/extensions/api/developer_private/developer_private_api.cc b/chrome/browser/extensions/api/developer_private/developer_private_api.cc |
| index 73c484031f0de6f72d75edf9631ada8625b6ac11..633262c1cad6a09cb756de63c5802ce31df78d49 100644 |
| --- a/chrome/browser/extensions/api/developer_private/developer_private_api.cc |
| +++ b/chrome/browser/extensions/api/developer_private/developer_private_api.cc |
| @@ -589,13 +589,20 @@ bool DeveloperPrivateLoadUnpackedFunction::RunImpl() { |
| const FilePath& last_unpacked_directory = |
| DeveloperPrivateAPI::Get(profile())->getLastUnpackedDirectory(); |
| SetResult(Value::CreateBooleanValue(true)); |
| - return ShowPicker(kSelectType, last_unpacked_directory, select_title); |
| + 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.
|
| + ShowPicker(kSelectType, |
| + last_unpacked_directory, |
| + select_title, |
| + ui::SelectFileDialog::FileTypeInfo(), |
| + 0); |
| } |
| 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.
|
| ui::SelectFileDialog::Type picker_type, |
| const FilePath& last_directory, |
| - const string16& select_title) { |
| + const string16& select_title, |
| + const ui::SelectFileDialog::FileTypeInfo& info, |
| + int file_type_index) { |
| ShellWindowRegistry* registry = ShellWindowRegistry::Get(profile()); |
| DCHECK(registry); |
| ShellWindow* shell_window = registry->GetShellWindowForRenderViewHost( |
| @@ -610,7 +617,7 @@ bool DeveloperPrivateChooseEntryFunction::ShowPicker( |
| // At that point, the picker will delete itself, which will also free the |
| // function instance. |
| new EntryPicker(this, shell_window->web_contents(), picker_type, |
| - last_directory, select_title); |
| + last_directory, select_title, info, file_type_index); |
| return true; |
| } |
| @@ -628,8 +635,142 @@ void DeveloperPrivateChooseEntryFunction::FileSelectionCanceled() { |
| SendResponse(false); |
| } |
| + |
| +void DeveloperPrivatePackItemFunction::OnPackSuccess( |
| + const FilePath& crx_file, |
| + const FilePath& pem_file) { |
| + std::string success_message(UTF16ToUTF8( |
| + extensions::PackExtensionJob::StandardSuccessMessage( |
| + 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.
|
| + developer::PackItemResponse response; |
| + response.message = success_message; |
| + response.status = developer::DEVELOPER_PRIVATE_PACK_STATUS_SUCCESS; |
| + results_ = developer::PackItem::Results::Create(response); |
| + SendResponse(true); |
| + Release(); |
| +} |
| + |
| +void DeveloperPrivatePackItemFunction::OnPackFailure( |
| + const std::string& error, |
| + extensions::ExtensionCreator::ErrorType error_type) { |
| + developer::PackItemResponse response; |
| + response.message = error; |
| + if (error_type == extensions::ExtensionCreator::kCRXExists) { |
| + response.item_path = item_path_str_; |
| + response.pem_path = key_path_str_; |
| + response.override_flags = extensions::ExtensionCreator::kOverwriteCRX; |
| + response.status = developer::DEVELOPER_PRIVATE_PACK_STATUS_WARNING; |
| + } else { |
| + response.status = developer::DEVELOPER_PRIVATE_PACK_STATUS_ERROR; |
| + } |
| + results_ = developer::PackItem::Results::Create(response); |
| + SendResponse(true); |
| + Release(); |
| +} |
| + |
| +bool DeveloperPrivatePackItemFunction::RunImpl() { |
| + int flags; |
| + EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &item_path_str_)); |
| + EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &key_path_str_)); |
| + EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(2, &flags)); |
| + |
| + FilePath root_directory = |
| + FilePath::FromWStringHack(UTF8ToWide(item_path_str_)); |
| + |
| + FilePath key_file = |
| + FilePath::FromWStringHack(UTF8ToWide(key_path_str_)); |
| + |
| + developer::PackItemResponse response; |
| + if (root_directory.empty()) { |
| + if (item_path_str_.empty()) { |
| + response.message = l10n_util::GetStringUTF8( |
| + IDS_EXTENSION_PACK_DIALOG_ERROR_ROOT_REQUIRED); |
| + } else { |
| + 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.
|
| + IDS_EXTENSION_PACK_DIALOG_ERROR_ROOT_INVALID); |
| + } |
| + |
| + response.status = developer::DEVELOPER_PRIVATE_PACK_STATUS_ERROR; |
| + results_ = developer::PackItem::Results::Create(response); |
| + SendResponse(true); |
| + return true; |
| + } |
| + |
| + if (!key_path_str_.empty() && key_file.empty()) { |
| + 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
|
| + IDS_EXTENSION_PACK_DIALOG_ERROR_KEY_INVALID); |
| + results_ = developer::PackItem::Results::Create(response); |
| + SendResponse(true); |
| + return true; |
| + } |
| + |
| + // Pack job will release the function instance. |
| + AddRef(); |
| + |
| + pack_job_ = new extensions::PackExtensionJob( |
| + this, root_directory, key_file, flags); |
| + pack_job_->Start(); |
| + return true; |
| +} |
| + |
| +DeveloperPrivatePackItemFunction::DeveloperPrivatePackItemFunction() {} |
| + |
| +DeveloperPrivatePackItemFunction::~DeveloperPrivatePackItemFunction() {} |
| + |
| DeveloperPrivateLoadUnpackedFunction::~DeveloperPrivateLoadUnpackedFunction() {} |
| +bool DeveloperPrivateChooseItemFunction::RunImpl() { |
| + |
| + std::string select_type; |
| + std::string file_type; |
| + EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &select_type)); |
| + EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &file_type)); |
| + ui::SelectFileDialog::Type type = ui::SelectFileDialog::SELECT_FOLDER; |
| + ui::SelectFileDialog::FileTypeInfo info; |
| + if (select_type == "file") { |
| + type = ui::SelectFileDialog::SELECT_OPEN_FILE; |
|
miket_OOO
2013/01/09 18:52:41
No braces
Gaurav
2013/01/12 01:08:26
Done.
|
| + } |
| + string16 select_title; |
| + |
| + int file_type_index = 0; |
| + if (file_type == "load") { |
| + select_title = l10n_util::GetStringUTF16(IDS_EXTENSION_LOAD_FROM_DIRECTORY); |
| + } else if (file_type == "pem") { |
| + select_title = l10n_util::GetStringUTF16( |
| + IDS_EXTENSION_PACK_DIALOG_SELECT_KEY); |
| + info.extensions.push_back(std::vector<FilePath::StringType>()); |
| + info.extensions.front().push_back(FILE_PATH_LITERAL("pem")); |
| + info.extension_description_overrides.push_back( |
| + l10n_util::GetStringUTF16( |
| + IDS_EXTENSION_PACK_DIALOG_KEY_FILE_TYPE_DESCRIPTION)); |
| + info.include_all_files = true; |
| + file_type_index = 1; |
| + } else { |
| + NOTREACHED(); |
| + } |
| + |
| + const FilePath& last_unpacked_directory = |
| + 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.
|
| + return |
| + ShowPicker(type, |
|
miket_OOO
2013/01/09 18:52:41
Don't wrap after the return.
Gaurav
2013/01/12 01:08:26
Done.
|
| + last_unpacked_directory, |
| + select_title, |
| + info, |
| + file_type_index); |
| +} |
| + |
| +void DeveloperPrivateChooseItemFunction::FileSelected(const FilePath& path) { |
| + 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.
|
| + SetResult(base::Value::CreateStringValue(result)); |
| + SendResponse(true); |
| +} |
| + |
| +void DeveloperPrivateChooseItemFunction::FileSelectionCanceled() { |
| + SendResponse(false); |
| +} |
| + |
| +DeveloperPrivateChooseItemFunction::~DeveloperPrivateChooseItemFunction() {} |
| + |
| bool DeveloperPrivateGetStringsFunction::RunImpl() { |
| DictionaryValue* dict = new DictionaryValue(); |
| SetResult(dict); |