OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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/extensions/install_extension_handler.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/extensions/crx_installer.h" |
| 10 #include "chrome/browser/extensions/extension_install_ui.h" |
| 11 #include "chrome/browser/extensions/extension_service.h" |
| 12 #include "chrome/browser/extensions/extension_system.h" |
| 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/common/extensions/extension_switch_utils.h" |
| 15 #include "content/public/browser/web_contents.h" |
| 16 #include "content/public/browser/web_contents_view.h" |
| 17 #include "content/public/browser/web_ui.h" |
| 18 #include "grit/generated_resources.h" |
| 19 #include "ui/base/l10n/l10n_util.h" |
| 20 #include "webkit/glue/webdropdata.h" |
| 21 |
| 22 InstallExtensionHandler::InstallExtensionHandler() { |
| 23 } |
| 24 |
| 25 InstallExtensionHandler::~InstallExtensionHandler() { |
| 26 } |
| 27 |
| 28 void InstallExtensionHandler::GetLocalizedValues( |
| 29 DictionaryValue* localized_strings) { |
| 30 DCHECK(localized_strings); |
| 31 localized_strings->SetString( |
| 32 "extensionSettingsInstallDropTarget", |
| 33 l10n_util::GetStringUTF16(IDS_EXTENSIONS_INSTALL_DROP_TARGET)); |
| 34 localized_strings->SetBoolean( |
| 35 "offStoreInstallEnabled", |
| 36 extensions::switch_utils::IsOffStoreInstallEnabled()); |
| 37 } |
| 38 |
| 39 void InstallExtensionHandler::RegisterMessages() { |
| 40 web_ui()->RegisterMessageCallback( |
| 41 "startDrag", |
| 42 base::Bind(&InstallExtensionHandler::HandleStartDragMessage, |
| 43 base::Unretained(this))); |
| 44 web_ui()->RegisterMessageCallback( |
| 45 "stopDrag", |
| 46 base::Bind(&InstallExtensionHandler::HandleStopDragMessage, |
| 47 base::Unretained(this))); |
| 48 web_ui()->RegisterMessageCallback( |
| 49 "installDroppedFile", |
| 50 base::Bind(&InstallExtensionHandler::HandleInstallMessage, |
| 51 base::Unretained(this))); |
| 52 } |
| 53 |
| 54 void InstallExtensionHandler::HandleStartDragMessage(const ListValue* args) { |
| 55 WebDropData* drop_data = web_ui()->GetWebContents()->GetView()->GetDropData(); |
| 56 if (!drop_data) { |
| 57 DLOG(ERROR) << "No current drop data."; |
| 58 return; |
| 59 } |
| 60 |
| 61 if (drop_data->filenames.empty()) { |
| 62 DLOG(ERROR) << "Current drop data contains no files."; |
| 63 return; |
| 64 } |
| 65 |
| 66 file_to_install_ = FilePath::FromWStringHack( |
| 67 UTF16ToWide(drop_data->filenames.front())); |
| 68 } |
| 69 |
| 70 void InstallExtensionHandler::HandleStopDragMessage(const ListValue* args) { |
| 71 file_to_install_.clear(); |
| 72 } |
| 73 |
| 74 void InstallExtensionHandler::HandleInstallMessage(const ListValue* args) { |
| 75 if (file_to_install_.empty()) { |
| 76 LOG(ERROR) << "No file captured to install."; |
| 77 return; |
| 78 } |
| 79 |
| 80 Profile* profile = Profile::FromWebUI(web_ui()); |
| 81 scoped_refptr<CrxInstaller> crx_installer( |
| 82 CrxInstaller::Create( |
| 83 ExtensionSystem::Get(profile)->extension_service(), |
| 84 new ExtensionInstallUI(profile))); |
| 85 crx_installer->InstallCrx(file_to_install_); |
| 86 |
| 87 file_to_install_.clear(); |
| 88 } |
OLD | NEW |