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 } |
| 16 |
| 17 void PackExtensionHandler::Initialize() { |
| 18 } |
| 19 |
| 20 void PackExtensionHandler::GetLocalizedValues( |
| 21 DictionaryValue* localized_strings) { |
| 22 DCHECK(localized_strings); |
| 23 RegisterTitle(localized_strings, "clearBrowserDataOverlay", |
| 24 IDS_CLEAR_BROWSING_DATA_TITLE); |
| 25 |
| 26 localized_strings->SetString("packExtensionOverlay", |
| 27 l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_DIALOG_TITLE)); |
| 28 localized_strings->SetString("packExtensionHeading", |
| 29 l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_DIALOG_HEADING)); |
| 30 localized_strings->SetString("packExtensionCommit", |
| 31 l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_BUTTON)); |
| 32 localized_strings->SetString("packExtensionRootDir", |
| 33 l10n_util::GetStringUTF16( |
| 34 IDS_EXTENSION_PACK_DIALOG_ROOT_DIRECTORY_LABEL)); |
| 35 localized_strings->SetString("packExtensionPrivateKey", |
| 36 l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_DIALOG_PRIVATE_KEY_LABEL)); |
| 37 localized_strings->SetString("packExtensionBrowseButton", |
| 38 l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_DIALOG_BROWSE)); |
| 39 } |
| 40 |
| 41 void PackExtensionHandler::RegisterMessages() { |
| 42 // Setup handlers specific to this panel. |
| 43 web_ui_->RegisterMessageCallback("pack", |
| 44 NewCallback(this, &PackExtensionHandler::HandlePackMessage)); |
| 45 } |
| 46 |
| 47 void PackExtensionHandler::OnPackSuccess(const FilePath& crx_file, |
| 48 const FilePath& pem_file) { |
| 49 ListValue results; |
| 50 web_ui_->CallJavascriptFunction("OptionsPage.closeOverlay", results); |
| 51 |
| 52 ShowAlert(UTF16ToUTF8(PackExtensionJob::StandardSuccessMessage(crx_file, |
| 53 pem_file))); |
| 54 } |
| 55 |
| 56 void PackExtensionHandler::OnPackFailure(const std::string& error) { |
| 57 ShowAlert(error); |
| 58 } |
| 59 |
| 60 void PackExtensionHandler::HandlePackMessage(const ListValue* args) { |
| 61 std::string extension_path; |
| 62 std::string private_key_path; |
| 63 CHECK_EQ(2U, args->GetSize()); |
| 64 CHECK(args->GetString(0, &extension_path)); |
| 65 CHECK(args->GetString(1, &private_key_path)); |
| 66 |
| 67 FilePath root_directory = |
| 68 FilePath::FromWStringHack(UTF8ToWide(extension_path)); |
| 69 FilePath key_file = FilePath::FromWStringHack(UTF8ToWide(private_key_path)); |
| 70 |
| 71 if (root_directory.empty()) { |
| 72 if (extension_path.empty()) { |
| 73 ShowAlert(l10n_util::GetStringUTF8( |
| 74 IDS_EXTENSION_PACK_DIALOG_ERROR_ROOT_REQUIRED)); |
| 75 } else { |
| 76 ShowAlert(l10n_util::GetStringUTF8( |
| 77 IDS_EXTENSION_PACK_DIALOG_ERROR_ROOT_INVALID)); |
| 78 } |
| 79 |
| 80 return; |
| 81 } |
| 82 |
| 83 if (!private_key_path.empty() && key_file.empty()) { |
| 84 ShowAlert(l10n_util::GetStringUTF8( |
| 85 IDS_EXTENSION_PACK_DIALOG_ERROR_KEY_INVALID)); |
| 86 return; |
| 87 } |
| 88 |
| 89 pack_job_ = new PackExtensionJob(this, root_directory, key_file); |
| 90 pack_job_->Start(); |
| 91 } |
| 92 |
| 93 void PackExtensionHandler::ShowAlert(const std::string& message) { |
| 94 ListValue arguments; |
| 95 arguments.Append(Value::CreateStringValue(message)); |
| 96 web_ui_->CallJavascriptFunction("alert", arguments); |
| 97 } |
OLD | NEW |