summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions
diff options
context:
space:
mode:
authorrafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-08 01:18:02 +0000
committerrafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-08 01:18:02 +0000
commit13555c122fbc9ec2a6c1a4cbace288ec7892be6e (patch)
treeb78bb0337bf633e7ecff2adc004c4a93542bdba9 /chrome/browser/extensions
parent2c8311e9badbe99ba50d6429a2c13bb8be89ff80 (diff)
downloadchromium_src-13555c122fbc9ec2a6c1a4cbace288ec7892be6e.zip
chromium_src-13555c122fbc9ec2a6c1a4cbace288ec7892be6e.tar.gz
chromium_src-13555c122fbc9ec2a6c1a4cbace288ec7892be6e.tar.bz2
Reland: HTML Pack Extension Dialog / Linux & Mac Packaging Support.
original issue: http://codereview.chromium.org/207062 The issue had to do with a symbol collison with the nss libraries (which are currently out-of-date) on the build bots. HTML Pack Extension Dialog. This removes the views implementation of the ExtensionPackDialog, and implements the dialog in html in the extensions_ui DOMUI. Additionally, support is added for packaging extensions via ---pack-extension on linux and mac BUG=20668, 20669 TBR=aa,wtc Review URL: http://codereview.chromium.org/265032 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28365 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r--chrome/browser/extensions/extensions_service_unittest.cc2
-rw-r--r--chrome/browser/extensions/extensions_ui.cc138
-rw-r--r--chrome/browser/extensions/extensions_ui.h23
-rw-r--r--chrome/browser/extensions/pack_extension_job.h8
4 files changed, 152 insertions, 19 deletions
diff --git a/chrome/browser/extensions/extensions_service_unittest.cc b/chrome/browser/extensions/extensions_service_unittest.cc
index 578bde2..d5d629f 100644
--- a/chrome/browser/extensions/extensions_service_unittest.cc
+++ b/chrome/browser/extensions/extensions_service_unittest.cc
@@ -721,7 +721,6 @@ TEST_F(ExtensionsServiceTest, InstallExtension) {
// TODO(erikkay): add tests for upgrade cases.
}
-#if defined(OS_WIN) // TODO(port)
// Test Packaging and installing an extension.
// TODO(rafaelw): add more tests for failure cases.
TEST_F(ExtensionsServiceTest, PackExtension) {
@@ -785,7 +784,6 @@ TEST_F(ExtensionsServiceTest, PackExtensionOpenSSLKey) {
file_util::Delete(crx_path, false);
}
-#endif // defined(OS_WIN)
TEST_F(ExtensionsServiceTest, InstallTheme) {
InitializeEmptyExtensionsService();
diff --git a/chrome/browser/extensions/extensions_ui.cc b/chrome/browser/extensions/extensions_ui.cc
index 7313f50..ff2505f 100644
--- a/chrome/browser/extensions/extensions_ui.cc
+++ b/chrome/browser/extensions/extensions_ui.cc
@@ -9,6 +9,7 @@
#include "base/string_util.h"
#include "base/thread.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/debugger/devtools_manager.h"
#include "chrome/browser/extensions/extension_message_service.h"
#include "chrome/browser/extensions/extensions_service.h"
@@ -47,6 +48,14 @@ void ExtensionsUIHTMLSource::StartDataRequest(const std::string& path,
DictionaryValue localized_strings;
localized_strings.SetString(L"title",
l10n_util::GetString(IDS_EXTENSIONS_TITLE));
+ localized_strings.SetString(L"packDialogHeading",
+ l10n_util::GetString(IDS_EXTENSION_PACK_DIALOG_HEADING));
+ localized_strings.SetString(L"rootDirectoryLabel",
+ l10n_util::GetString(IDS_EXTENSION_PACK_DIALOG_ROOT_DIRECTORY_LABEL));
+ localized_strings.SetString(L"packDialogBrowse",
+ l10n_util::GetString(IDS_EXTENSION_PACK_DIALOG_BROWSE));
+ localized_strings.SetString(L"privateKeyLabel",
+ l10n_util::GetString(IDS_EXTENSION_PACK_DIALOG_PRIVATE_KEY_LABEL));
static const base::StringPiece extensions_html(
ResourceBundle::GetSharedInstance().GetRawDataResource(
@@ -91,6 +100,8 @@ void ExtensionsDOMHandler::RegisterMessages() {
NewCallback(this, &ExtensionsDOMHandler::HandlePackMessage));
dom_ui_->RegisterMessageCallback("autoupdate",
NewCallback(this, &ExtensionsDOMHandler::HandleAutoUpdateMessage));
+ dom_ui_->RegisterMessageCallback("selectFilePath",
+ NewCallback(this, &ExtensionsDOMHandler::HandleSelectFilePathMessage));
}
void ExtensionsDOMHandler::HandleRequestExtensionsData(const Value* value) {
@@ -187,18 +198,77 @@ void ExtensionsDOMHandler::HandleUninstallMessage(const Value* value) {
}
void ExtensionsDOMHandler::HandleLoadMessage(const Value* value) {
- load_extension_dialog_ = SelectFileDialog::Create(this);
- load_extension_dialog_->SelectFile(
- SelectFileDialog::SELECT_FOLDER,
- l10n_util::GetStringUTF16(IDS_EXTENSION_LOAD_FROM_DIRECTORY),
- FilePath(), NULL, 0, FILE_PATH_LITERAL(""),
- dom_ui_->tab_contents()->view()->GetTopLevelNativeWindow(), NULL);
+ std::string string_path;
+ CHECK(value->IsType(Value::TYPE_LIST));
+ const ListValue* list = static_cast<const ListValue*>(value);
+ CHECK(list->GetSize() == 1) << list->GetSize();
+ CHECK(list->GetString(0, &string_path));
+ FilePath file_path = FilePath::FromWStringHack(ASCIIToWide(string_path));
+ extensions_service_->LoadExtension(file_path);
+}
+
+void ExtensionsDOMHandler::ShowAlert(const std::string& message) {
+ ListValue arguments;
+ arguments.Append(Value::CreateStringValue(message));
+ dom_ui_->CallJavascriptFunction(L"alert", arguments);
}
void ExtensionsDOMHandler::HandlePackMessage(const Value* value) {
-#if defined(OS_WIN)
- ShowPackDialog();
-#endif
+ std::string extension_path;
+ std::string private_key_path;
+ CHECK(value->IsType(Value::TYPE_LIST));
+ const ListValue* list = static_cast<const ListValue*>(value);
+ CHECK(list->GetSize() == 2);
+ CHECK(list->GetString(0, &extension_path));
+ CHECK(list->GetString(1, &private_key_path));
+
+ FilePath root_directory = FilePath::FromWStringHack(ASCIIToWide(
+ extension_path));
+ FilePath key_file = FilePath::FromWStringHack(ASCIIToWide(private_key_path));
+
+ if (root_directory.empty()) {
+ if (extension_path.empty()) {
+ ShowAlert(l10n_util::GetStringUTF8(
+ IDS_EXTENSION_PACK_DIALOG_ERROR_ROOT_REQUIRED));
+ } else {
+ ShowAlert(l10n_util::GetStringUTF8(
+ IDS_EXTENSION_PACK_DIALOG_ERROR_ROOT_INVALID));
+ }
+
+ return;
+ }
+
+ if (!private_key_path.empty() && key_file.empty()) {
+ ShowAlert(l10n_util::GetStringUTF8(
+ IDS_EXTENSION_PACK_DIALOG_ERROR_KEY_INVALID));
+ return;
+ }
+
+ pack_job_ = new PackExtensionJob(this, root_directory, key_file,
+ ChromeThread::GetMessageLoop(ChromeThread::FILE));
+}
+
+void ExtensionsDOMHandler::OnPackSuccess(const FilePath& crx_file,
+ const FilePath& pem_file) {
+ std::string message;
+ if (!pem_file.empty()) {
+ message = WideToASCII(l10n_util::GetStringF(
+ IDS_EXTENSION_PACK_DIALOG_SUCCESS_BODY_NEW,
+ crx_file.ToWStringHack(),
+ pem_file.ToWStringHack()));
+ } else {
+ message = WideToASCII(l10n_util::GetStringF(
+ IDS_EXTENSION_PACK_DIALOG_SUCCESS_BODY_UPDATE,
+ crx_file.ToWStringHack()));
+ }
+ ShowAlert(message);
+
+ ListValue results;
+ dom_ui_->CallJavascriptFunction(L"hidePackDialog", results);
+}
+
+void ExtensionsDOMHandler::OnPackFailure(const std::wstring& error) {
+ ShowAlert(WideToASCII(error));
}
void ExtensionsDOMHandler::HandleAutoUpdateMessage(const Value* value) {
@@ -208,9 +278,55 @@ void ExtensionsDOMHandler::HandleAutoUpdateMessage(const Value* value) {
}
}
+void ExtensionsDOMHandler::HandleSelectFilePathMessage(const Value* value) {
+ std::string select_type;
+ std::string operation;
+ CHECK(value->IsType(Value::TYPE_LIST));
+ const ListValue* list = static_cast<const ListValue*>(value);
+ CHECK(list->GetSize() == 2);
+ CHECK(list->GetString(0, &select_type));
+ CHECK(list->GetString(1, &operation));
+
+ SelectFileDialog::Type type = SelectFileDialog::SELECT_FOLDER;
+ static SelectFileDialog::FileTypeInfo info;
+ int file_type_index = 0;
+ if (select_type == "file")
+ type = SelectFileDialog::SELECT_OPEN_FILE;
+
+ string16 select_title;
+ if (operation == "load")
+ select_title = l10n_util::GetStringUTF16(IDS_EXTENSION_LOAD_FROM_DIRECTORY);
+ else if (operation == "packRoot")
+ select_title = l10n_util::GetStringUTF16(
+ IDS_EXTENSION_PACK_DIALOG_SELECT_ROOT);
+ else if (operation == "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(WideToUTF16(
+ l10n_util::GetString(
+ IDS_EXTENSION_PACK_DIALOG_KEY_FILE_TYPE_DESCRIPTION)));
+ info.include_all_files = true;
+ file_type_index = 1;
+ } else {
+ NOTREACHED();
+ return;
+ }
+
+ load_extension_dialog_ = SelectFileDialog::Create(this);
+ load_extension_dialog_->SelectFile(type, select_title, FilePath(), &info,
+ file_type_index, FILE_PATH_LITERAL(""),
+ dom_ui_->tab_contents()->view()->GetTopLevelNativeWindow(), NULL);
+}
+
+
void ExtensionsDOMHandler::FileSelected(const FilePath& path, int index,
void* params) {
- extensions_service_->LoadExtension(path);
+ // Add the extensions to the results structure.
+ ListValue results;
+ results.Append(Value::CreateStringValue(path.value()));
+ dom_ui_->CallJavascriptFunction(L"window.handleFilePathSelected", results);
}
void ExtensionsDOMHandler::Observe(NotificationType type,
@@ -339,6 +455,8 @@ std::vector<ExtensionPage> ExtensionsDOMHandler::GetActivePagesForExtension(
}
ExtensionsDOMHandler::~ExtensionsDOMHandler() {
+ if (pack_job_.get())
+ pack_job_->ClearClient();
}
// ExtensionsDOMHandler, public: -----------------------------------------------
diff --git a/chrome/browser/extensions/extensions_ui.h b/chrome/browser/extensions/extensions_ui.h
index 80ddf4d..908c9f3 100644
--- a/chrome/browser/extensions/extensions_ui.h
+++ b/chrome/browser/extensions/extensions_ui.h
@@ -10,6 +10,7 @@
#include "chrome/browser/dom_ui/chrome_url_data_manager.h"
#include "chrome/browser/dom_ui/dom_ui.h"
+#include "chrome/browser/extensions/pack_extension_job.h"
#include "chrome/browser/shell_dialogs.h"
#include "chrome/common/notification_observer.h"
#include "chrome/common/notification_registrar.h"
@@ -52,6 +53,7 @@ class ExtensionsUIHTMLSource : public ChromeURLDataManager::DataSource {
class ExtensionsDOMHandler
: public DOMMessageHandler,
public NotificationObserver,
+ public PackExtensionJob::Client,
public SelectFileDialog::Listener {
public:
explicit ExtensionsDOMHandler(ExtensionsService* extension_service);
@@ -71,13 +73,13 @@ class ExtensionsDOMHandler
const UserScript& script,
const FilePath& extension_path);
- private:
-#if defined(OS_WIN)
- // The implementation of this method is platform-specific and defined
- // elsewhere.
- static void ShowPackDialog();
-#endif
+ // ExtensionPackJob::Client
+ virtual void OnPackSuccess(const FilePath& crx_file,
+ const FilePath& key_file);
+
+ virtual void OnPackFailure(const std::wstring& message);
+ private:
// Callback for "requestExtensionsData" message.
void HandleRequestExtensionsData(const Value* value);
@@ -102,6 +104,12 @@ class ExtensionsDOMHandler
// Callback for "autoupdate" message.
void HandleAutoUpdateMessage(const Value* value);
+ // Utility for calling javascript window.alert in the page.
+ void ShowAlert(const std::string& message);
+
+ // Callback for "selectFilePath" message.
+ void HandleSelectFilePathMessage(const Value* value);
+
// SelectFileDialog::Listener
virtual void FileSelected(const FilePath& path,
int index, void* params);
@@ -126,6 +134,9 @@ class ExtensionsDOMHandler
// Used to pick the directory when loading an extension.
scoped_refptr<SelectFileDialog> load_extension_dialog_;
+ // Used to package the extension.
+ scoped_refptr<PackExtensionJob> pack_job_;
+
// We monitor changes to the extension system so that we can reload when
// necessary.
NotificationRegistrar registrar_;
diff --git a/chrome/browser/extensions/pack_extension_job.h b/chrome/browser/extensions/pack_extension_job.h
index ec00f21..8c3cf26 100644
--- a/chrome/browser/extensions/pack_extension_job.h
+++ b/chrome/browser/extensions/pack_extension_job.h
@@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#ifndef CHROME_BROWSER_EXTENSIONS_PACK_EXTENSION_JOB_UI_H_
+#define CHROME_BROWSER_EXTENSIONS_PACK_EXTENSION_JOB_UI_H_
+
#include <string>
#include "base/file_path.h"
@@ -11,7 +14,7 @@ class MessageLoop;
// Manages packing an extension on the file thread and reporting the result
// back to the UI.
-class PackExtensionJob : public base::RefCounted<PackExtensionJob> {
+class PackExtensionJob : public base::RefCountedThreadSafe<PackExtensionJob> {
public:
// Interface for people who want to use PackExtensionJob to implement.
@@ -46,3 +49,6 @@ class PackExtensionJob : public base::RefCounted<PackExtensionJob> {
DISALLOW_COPY_AND_ASSIGN(PackExtensionJob);
};
+
+#endif // CHROME_BROWSER_EXTENSIONS_PACK_EXTENSION_JOB_UI_H_
+