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 ba5ee7228b949845bcdf97b4932f25830c38495c..72c574513059b461c0a6089e42d506e822edeedf 100644 |
--- a/chrome/browser/extensions/api/developer_private/developer_private_api.cc |
+++ b/chrome/browser/extensions/api/developer_private/developer_private_api.cc |
@@ -585,18 +585,33 @@ bool DeveloperPrivateLoadUnpackedFunction::RunImpl() { |
string16 select_title = |
l10n_util::GetStringUTF16(IDS_EXTENSION_LOAD_FROM_DIRECTORY); |
- const ui::SelectFileDialog::Type kSelectType = |
- ui::SelectFileDialog::SELECT_FOLDER; |
- const FilePath& last_unpacked_directory = |
- DeveloperPrivateAPI::Get(profile())->getLastUnpackedDirectory(); |
SetResult(Value::CreateBooleanValue(true)); |
- return ShowPicker(kSelectType, last_unpacked_directory, select_title); |
+ int result = |
+ ShowPicker( |
+ ui::SelectFileDialog::SELECT_FOLDER, |
+ DeveloperPrivateAPI::Get(profile())->GetLastUnpackedDirectory(), |
+ select_title, |
+ ui::SelectFileDialog::FileTypeInfo(), |
+ 0); |
+ return result; |
+} |
+ |
+void DeveloperPrivateLoadUnpackedFunction::FileSelected(const FilePath& path) { |
+ |
+ DeveloperPrivateAPI::Get(profile())->LoadUnpacked(path); |
+ SendResponse(true); |
} |
-bool DeveloperPrivateChooseEntryFunction::ShowPicker( |
+void DeveloperPrivateLoadUnpackedFunction::FileSelectionCanceled() { |
+ SendResponse(false); |
+} |
+ |
+bool DeveloperPrivateChooseEntryFunction::ShowPicker( |
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( |
@@ -611,7 +626,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; |
} |
@@ -619,18 +634,142 @@ bool DeveloperPrivateChooseEntryFunction::RunImpl() { return false; } |
DeveloperPrivateChooseEntryFunction::~DeveloperPrivateChooseEntryFunction() {} |
-void DeveloperPrivateChooseEntryFunction::FileSelected(const FilePath& path) { |
+void DeveloperPrivatePackDirectoryFunction::OnPackSuccess( |
+ const FilePath& crx_file, |
+ const FilePath& pem_file) { |
+ developer::PackDirectoryResponse response; |
+ response.message = |
+ UTF16ToUTF8(extensions::PackExtensionJob::StandardSuccessMessage( |
+ crx_file, pem_file)); |
+ response.status = developer::DEVELOPER_PRIVATE_PACK_STATUS_SUCCESS; |
+ results_ = developer::PackDirectory::Results::Create(response); |
+ SendResponse(true); |
+ Release(); |
+} |
- DeveloperPrivateAPI::Get(profile())->LoadUnpacked(path); |
+void DeveloperPrivatePackDirectoryFunction::OnPackFailure( |
+ const std::string& error, |
+ extensions::ExtensionCreator::ErrorType error_type) { |
+ developer::PackDirectoryResponse 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::PackDirectory::Results::Create(response); |
SendResponse(true); |
+ Release(); |
} |
-void DeveloperPrivateChooseEntryFunction::FileSelectionCanceled() { |
- SendResponse(false); |
+bool DeveloperPrivatePackDirectoryFunction::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::PackDirectoryResponse 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( |
+ IDS_EXTENSION_PACK_DIALOG_ERROR_ROOT_INVALID); |
+ |
+ response.status = developer::DEVELOPER_PRIVATE_PACK_STATUS_ERROR; |
+ results_ = developer::PackDirectory::Results::Create(response); |
+ SendResponse(true); |
+ return true; |
+ } |
+ |
+ if (!key_path_str_.empty() && key_file.empty()) { |
+ response.message = l10n_util::GetStringUTF8( |
+ IDS_EXTENSION_PACK_DIALOG_ERROR_KEY_INVALID); |
+ response.status = developer::DEVELOPER_PRIVATE_PACK_STATUS_ERROR; |
+ results_ = developer::PackDirectory::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; |
} |
+DeveloperPrivatePackDirectoryFunction::DeveloperPrivatePackDirectoryFunction() |
+{} |
+ |
+DeveloperPrivatePackDirectoryFunction::~DeveloperPrivatePackDirectoryFunction() |
+{} |
+ |
DeveloperPrivateLoadUnpackedFunction::~DeveloperPrivateLoadUnpackedFunction() {} |
+bool DeveloperPrivateChoosePathFunction::RunImpl() { |
+ |
+ scoped_ptr<developer::ChoosePath::Params> params( |
+ developer::ChoosePath::Params::Create(*args_)); |
+ EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
+ |
+ ui::SelectFileDialog::Type type = ui::SelectFileDialog::SELECT_FOLDER; |
+ ui::SelectFileDialog::FileTypeInfo info; |
+ if (params->select_type == developer::DEVELOPER_PRIVATE_SELECT_TYPE_FILE) { |
+ type = ui::SelectFileDialog::SELECT_OPEN_FILE; |
+ } |
+ string16 select_title; |
+ |
+ int file_type_index = 0; |
+ if (params->file_type == developer::DEVELOPER_PRIVATE_FILE_TYPE_LOAD) |
+ select_title = l10n_util::GetStringUTF16(IDS_EXTENSION_LOAD_FROM_DIRECTORY); |
+ else if (params->file_type== developer::DEVELOPER_PRIVATE_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(); |
+ } |
+ |
+ int result = |
+ ShowPicker( |
+ type, |
+ DeveloperPrivateAPI::Get(profile())->GetLastUnpackedDirectory(), |
+ select_title, |
+ info, |
+ file_type_index); |
+ return result; |
+} |
+ |
+void DeveloperPrivateChoosePathFunction::FileSelected(const FilePath& path) { |
+ SetResult(base::Value::CreateStringValue( |
+ UTF16ToUTF8(path.LossyDisplayName()))); |
+ SendResponse(true); |
+} |
+ |
+void DeveloperPrivateChoosePathFunction::FileSelectionCanceled() { |
+ SendResponse(false); |
+} |
+ |
+DeveloperPrivateChoosePathFunction::~DeveloperPrivateChoosePathFunction() {} |
+ |
bool DeveloperPrivateGetStringsFunction::RunImpl() { |
DictionaryValue* dict = new DictionaryValue(); |
SetResult(dict); |