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 9eefa6812ad919b4381c087f908f87a311f2cfe2..d1c0d056223c42734a9a4bd7496a6890d0c0181e 100644 |
| --- a/chrome/browser/extensions/api/developer_private/developer_private_api.cc |
| +++ b/chrome/browser/extensions/api/developer_private/developer_private_api.cc |
| @@ -110,11 +110,11 @@ bool DeveloperPrivateAutoUpdateFunction::RunImpl() { |
| DeveloperPrivateAutoUpdateFunction::~DeveloperPrivateAutoUpdateFunction() {} |
| -scoped_ptr<developer::ItemInfo> |
| - DeveloperPrivateGetItemsInfoFunction::CreateItemInfo( |
| - const Extension& item, |
| - ExtensionSystem* system, |
| - bool item_is_enabled) { |
| +scoped_ptr<developer::ItemInfo> DeveloperPrivateGetItemsInfoFunction:: |
| + CreateItemInfo( |
| + const Extension& item, |
| + ExtensionSystem* system, |
| + bool item_is_enabled) { |
| scoped_ptr<developer::ItemInfo> info(new developer::ItemInfo()); |
| ExtensionService* service = profile()->GetExtensionService(); |
| @@ -248,13 +248,12 @@ void DeveloperPrivateGetItemsInfoFunction:: |
| process->GetBrowserContext()->IsOffTheRecord())); |
| } |
| } |
| - |
| -linked_ptr<developer::ItemInspectView> |
| - DeveloperPrivateGetItemsInfoFunction::constructInspectView( |
| - const GURL& url, |
| - int render_process_id, |
| - int render_view_id, |
| - bool incognito) { |
| +linked_ptr<developer::ItemInspectView> DeveloperPrivateGetItemsInfoFunction:: |
| + constructInspectView( |
| + const GURL& url, |
| + int render_process_id, |
| + int render_view_id, |
| + bool incognito) { |
| linked_ptr<developer::ItemInspectView> view(new developer::ItemInspectView()); |
| if (url.scheme() == extensions::kExtensionScheme) { |
| @@ -463,7 +462,6 @@ void DeveloperPrivateEnableFunction::OnRequirementsChecked( |
| UTF8ToUTF16(JoinString(requirements_errors, ' ')), |
| true /* be noisy */); |
| } |
| - |
| Release(); |
| } |
| @@ -515,21 +513,39 @@ 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)); |
| // Balanced in FileSelected / FileSelectionCanceled. |
| AddRef(); |
| - bool result = ShowPicker(kSelectType, last_unpacked_directory, select_title); |
| + int result = |
| + ShowPicker( |
|
asargent_no_longer_on_chrome
2013/02/09 00:38:45
style nit: collapse the first 2 lines here:
int r
Gaurav
2013/02/11 20:01:55
Done.
|
| + ui::SelectFileDialog::SELECT_FOLDER, |
| + DeveloperPrivateAPI::Get(profile())->GetLastUnpackedDirectory(), |
| + select_title, |
| + ui::SelectFileDialog::FileTypeInfo(), |
| + 0); |
| return result; |
| } |
| +void DeveloperPrivateLoadUnpackedFunction::FileSelected(const FilePath& path) { |
| + |
|
asargent_no_longer_on_chrome
2013/02/09 00:38:45
style nit: no empty space at beginning of function
Gaurav
2013/02/11 20:01:55
Done.
|
| + ExtensionService* service = profile()->GetExtensionService(); |
| + extensions::UnpackedInstaller::Create(service)->Load(path); |
| + DeveloperPrivateAPI::Get(profile())->SetLastUnpackedDirectory(path); |
| + SendResponse(true); |
| + Release(); |
| +} |
| + |
| +void DeveloperPrivateLoadUnpackedFunction::FileSelectionCanceled() { |
| + SendResponse(false); |
| + Release(); |
| +} |
| + |
| 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( |
| @@ -543,7 +559,7 @@ bool DeveloperPrivateChooseEntryFunction::ShowPicker( |
| // selected a file or cancelled the picker. At that point, the picker will |
| // delete itself. |
| new EntryPicker(this, shell_window->web_contents(), picker_type, |
| - last_directory, select_title); |
| + last_directory, select_title, info, file_type_index); |
| return true; |
| } |
| @@ -551,21 +567,145 @@ bool DeveloperPrivateChooseEntryFunction::RunImpl() { return false; } |
| DeveloperPrivateChooseEntryFunction::~DeveloperPrivateChooseEntryFunction() {} |
| -void DeveloperPrivateLoadUnpackedFunction::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::PACK_STATUS_SUCCESS; |
| + results_ = developer::PackDirectory::Results::Create(response); |
| + SendResponse(true); |
| + Release(); |
| +} |
| - ExtensionService* service = profile()->GetExtensionService(); |
| - extensions::UnpackedInstaller::Create(service)->Load(path); |
| - DeveloperPrivateAPI::Get(profile())->SetLastUnpackedDirectory(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::PACK_STATUS_WARNING; |
| + } else { |
| + response.status = developer::PACK_STATUS_ERROR; |
| + } |
| + results_ = developer::PackDirectory::Results::Create(response); |
| SendResponse(true); |
| Release(); |
| } |
| -void DeveloperPrivateLoadUnpackedFunction::FileSelectionCanceled() { |
| +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::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::PACK_STATUS_ERROR; |
| + results_ = developer::PackDirectory::Results::Create(response); |
| + SendResponse(true); |
| + return true; |
| + } |
| + |
| + // Pack job will release the function instance. |
|
asargent_no_longer_on_chrome
2013/02/09 00:38:45
nit: this comment is slightly misleading - better
Gaurav
2013/02/11 20:01:55
Done.
Gaurav
2013/02/11 20:01:55
Done.
|
| + 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::SELECT_TYPE_FILE) { |
| + type = ui::SelectFileDialog::SELECT_OPEN_FILE; |
| + } |
| + string16 select_title; |
| + |
| + int file_type_index = 0; |
| + if (params->file_type == developer::FILE_TYPE_LOAD) |
| + select_title = l10n_util::GetStringUTF16(IDS_EXTENSION_LOAD_FROM_DIRECTORY); |
| + else if (params->file_type== developer::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(); |
| + } |
| + |
| + // Balanced by FileSelected / FileSelectionCanceled. |
| + AddRef(); |
| + int result = |
| + ShowPicker( |
|
asargent_no_longer_on_chrome
2013/02/09 00:38:45
nit: collapse first 2 lines, e.g.
int result = Sh
Gaurav
2013/02/11 20:01:55
Done.
|
| + 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); |
| + Release(); |
| +} |
| + |
| +void DeveloperPrivateChoosePathFunction::FileSelectionCanceled() { |
| SendResponse(false); |
| Release(); |
| } |
| -DeveloperPrivateLoadUnpackedFunction::~DeveloperPrivateLoadUnpackedFunction() {} |
| +DeveloperPrivateChoosePathFunction::~DeveloperPrivateChoosePathFunction() {} |
| bool DeveloperPrivateGetStringsFunction::RunImpl() { |
| DictionaryValue* dict = new DictionaryValue(); |