Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5096)

Unified Diff: chrome/browser/ui/webui/extensions/install_extension_handler.cc

Issue 10270031: Add a first-class off-store install UI to chrome://extensions/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: AppEngine, you suck Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/extensions/install_extension_handler.cc
diff --git a/chrome/browser/ui/webui/extensions/install_extension_handler.cc b/chrome/browser/ui/webui/extensions/install_extension_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a5a648b3e7a4bc982e785c1e8e638c3de48bab8b
--- /dev/null
+++ b/chrome/browser/ui/webui/extensions/install_extension_handler.cc
@@ -0,0 +1,87 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/webui/extensions/install_extension_handler.h"
+
+#include "base/bind.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/extensions/crx_installer.h"
+#include "chrome/browser/extensions/extension_install_ui.h"
+#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/extensions/switch_utils.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/browser/web_contents_view.h"
+#include "content/public/browser/web_ui.h"
+#include "grit/generated_resources.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "webkit/glue/webdropdata.h"
+
+InstallExtensionHandler::InstallExtensionHandler() {
+}
+
+InstallExtensionHandler::~InstallExtensionHandler() {
+}
+
+void InstallExtensionHandler::GetLocalizedValues(
+ DictionaryValue* localized_strings) {
+ DCHECK(localized_strings);
+ localized_strings->SetString("extensionSettingsInstallDropTarget",
James Hawkins 2012/05/01 23:13:36 nit: The start of parameter rows must all begin on
Aaron Boodman 2012/05/02 00:41:36 Done.
+ l10n_util::GetStringUTF16(IDS_EXTENSIONS_INSTALL_DROP_TARGET));
+ localized_strings->SetBoolean(
+ "offstoreinstallenabled",
Evan Stade 2012/05/01 23:43:07 camel case
Aaron Boodman 2012/05/02 00:41:36 HTML attributes are forced to lowercase, so this d
+ extensions::switch_utils::IsOffStoreInstallEnabled());
+}
+
+void InstallExtensionHandler::RegisterMessages() {
+ web_ui()->RegisterMessageCallback(
+ "startDrag",
+ base::Bind(&InstallExtensionHandler::HandleStartDragMessage,
+ base::Unretained(this)));
+ web_ui()->RegisterMessageCallback(
+ "stopDrag",
+ base::Bind(&InstallExtensionHandler::HandleStopDragMessage,
+ base::Unretained(this)));
+ web_ui()->RegisterMessageCallback(
+ "installDroppedFile",
+ base::Bind(&InstallExtensionHandler::HandleInstallMessage,
+ base::Unretained(this)));
+}
+
+void InstallExtensionHandler::HandleStartDragMessage(const ListValue* args) {
Evan Stade 2012/05/01 23:43:07 is this necessary because by the time you get to h
Aaron Boodman 2012/05/02 00:41:36 Yep. Added comment.
+ WebDropData* drop_data = web_ui()->GetWebContents()->GetView()->GetDropData();
+ if (!drop_data) {
+ LOG(ERROR) << "No current drop data.";
James Hawkins 2012/05/01 23:13:36 Remove log spam?
Aaron Boodman 2012/05/02 00:41:36 Disagree that it is log spam. This will only occur
+ return;
+ }
+
+ if (drop_data->filenames.empty()) {
+ LOG(ERROR) << "Current drop data contains no files.";
+ return;
+ }
+
+ file_to_install_ = FilePath::FromWStringHack(
James Hawkins 2012/05/01 23:13:36 What is one supposed to do here to avoid using the
Aaron Boodman 2012/05/02 00:41:36 You're not supposed to have a string16 in the firs
+ UTF16ToWide(drop_data->filenames.front()));
+}
+
+void InstallExtensionHandler::HandleStopDragMessage(const ListValue* args) {
+ file_to_install_.clear();
+}
+
+void InstallExtensionHandler::HandleInstallMessage(const ListValue* args) {
+ if (file_to_install_.empty()) {
+ LOG(ERROR) << "No file captured to install.";
+ return;
+ }
+
+ Profile* profile = Profile::FromWebUI(web_ui());
+ scoped_refptr<CrxInstaller> crx_installer(
+ CrxInstaller::Create(
+ ExtensionSystem::Get(profile)->extension_service(),
+ new ExtensionInstallUI(profile)));
+ crx_installer->InstallCrx(file_to_install_);
+
+ file_to_install_.clear();
+}

Powered by Google App Engine
This is Rietveld 408576698