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