OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/webui/options/pack_extension_handler.h" |
| 6 |
| 7 #include "base/utf_string_conversions.h" |
| 8 #include "grit/generated_resources.h" |
| 9 #include "ui/base/l10n/l10n_util.h" |
| 10 |
| 11 PackExtensionHandler::PackExtensionHandler() { |
| 12 } |
| 13 |
| 14 PackExtensionHandler::~PackExtensionHandler() { |
| 15 if (pack_job_.get()) |
| 16 pack_job_->ClearClient(); |
| 17 } |
| 18 |
| 19 void PackExtensionHandler::Initialize() { |
| 20 } |
| 21 |
| 22 void PackExtensionHandler::GetLocalizedValues( |
| 23 DictionaryValue* localized_strings) { |
| 24 DCHECK(localized_strings); |
| 25 RegisterTitle(localized_strings, "clearBrowserDataOverlay", |
| 26 IDS_CLEAR_BROWSING_DATA_TITLE); |
| 27 |
| 28 localized_strings->SetString("packExtensionOverlay", |
| 29 l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_DIALOG_TITLE)); |
| 30 localized_strings->SetString("packExtensionHeading", |
| 31 l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_DIALOG_HEADING)); |
| 32 localized_strings->SetString("packExtensionCommit", |
| 33 l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_BUTTON)); |
| 34 localized_strings->SetString("packExtensionRootDir", |
| 35 l10n_util::GetStringUTF16( |
| 36 IDS_EXTENSION_PACK_DIALOG_ROOT_DIRECTORY_LABEL)); |
| 37 localized_strings->SetString("packExtensionPrivateKey", |
| 38 l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_DIALOG_PRIVATE_KEY_LABEL)); |
| 39 localized_strings->SetString("packExtensionBrowseButton", |
| 40 l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_DIALOG_BROWSE)); |
| 41 } |
| 42 |
| 43 void PackExtensionHandler::RegisterMessages() { |
| 44 // Setup handlers specific to this panel. |
| 45 web_ui_->RegisterMessageCallback("pack", |
| 46 NewCallback(this, &PackExtensionHandler::HandlePackMessage)); |
| 47 } |
| 48 |
| 49 void PackExtensionHandler::OnPackSuccess(const FilePath& crx_file, |
| 50 const FilePath& pem_file) { |
| 51 ListValue results; |
| 52 web_ui_->CallJavascriptFunction("OptionsPage.closeOverlay", results); |
| 53 |
| 54 ShowAlert(UTF16ToUTF8(PackExtensionJob::StandardSuccessMessage(crx_file, |
| 55 pem_file))); |
| 56 } |
| 57 |
| 58 void PackExtensionHandler::OnPackFailure(const std::string& error) { |
| 59 ShowAlert(error); |
| 60 } |
| 61 |
| 62 void PackExtensionHandler::HandlePackMessage(const ListValue* args) { |
| 63 std::string extension_path; |
| 64 std::string private_key_path; |
| 65 CHECK_EQ(2U, args->GetSize()); |
| 66 CHECK(args->GetString(0, &extension_path)); |
| 67 CHECK(args->GetString(1, &private_key_path)); |
| 68 |
| 69 FilePath root_directory = |
| 70 FilePath::FromWStringHack(UTF8ToWide(extension_path)); |
| 71 FilePath key_file = FilePath::FromWStringHack(UTF8ToWide(private_key_path)); |
| 72 |
| 73 if (root_directory.empty()) { |
| 74 if (extension_path.empty()) { |
| 75 ShowAlert(l10n_util::GetStringUTF8( |
| 76 IDS_EXTENSION_PACK_DIALOG_ERROR_ROOT_REQUIRED)); |
| 77 } else { |
| 78 ShowAlert(l10n_util::GetStringUTF8( |
| 79 IDS_EXTENSION_PACK_DIALOG_ERROR_ROOT_INVALID)); |
| 80 } |
| 81 |
| 82 return; |
| 83 } |
| 84 |
| 85 if (!private_key_path.empty() && key_file.empty()) { |
| 86 ShowAlert(l10n_util::GetStringUTF8( |
| 87 IDS_EXTENSION_PACK_DIALOG_ERROR_KEY_INVALID)); |
| 88 return; |
| 89 } |
| 90 |
| 91 pack_job_ = new PackExtensionJob(this, root_directory, key_file); |
| 92 pack_job_->Start(); |
| 93 } |
| 94 |
| 95 void PackExtensionHandler::ShowAlert(const std::string& message) { |
| 96 ListValue arguments; |
| 97 arguments.Append(Value::CreateStringValue(message)); |
| 98 web_ui_->CallJavascriptFunction("alert", arguments); |
| 99 } |
OLD | NEW |