OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/webui/extensions/install_extension_handler.h" | 5 #include "chrome/browser/ui/webui/extensions/install_extension_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/extensions/crx_installer.h" | 10 #include "chrome/browser/extensions/crx_installer.h" |
11 #include "chrome/browser/extensions/extension_install_prompt.h" | 11 #include "chrome/browser/extensions/extension_install_prompt.h" |
12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
13 #include "chrome/browser/extensions/unpacked_installer.h" | 13 #include "chrome/browser/extensions/unpacked_installer.h" |
| 14 #include "chrome/browser/extensions/zipfile_installer.h" |
14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
15 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
16 #include "content/public/browser/web_ui.h" | 17 #include "content/public/browser/web_ui.h" |
17 #include "content/public/browser/web_ui_data_source.h" | 18 #include "content/public/browser/web_ui_data_source.h" |
18 #include "content/public/common/drop_data.h" | 19 #include "content/public/common/drop_data.h" |
19 #include "extensions/browser/extension_system.h" | 20 #include "extensions/browser/extension_system.h" |
20 #include "extensions/common/feature_switch.h" | 21 #include "extensions/common/feature_switch.h" |
21 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" |
22 #include "net/base/filename_util.h" | 23 #include "net/base/filename_util.h" |
23 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 | 93 |
93 void InstallExtensionHandler::HandleInstallMessage( | 94 void InstallExtensionHandler::HandleInstallMessage( |
94 const base::ListValue* args) { | 95 const base::ListValue* args) { |
95 if (file_to_install_.empty()) { | 96 if (file_to_install_.empty()) { |
96 LOG(ERROR) << "No file captured to install."; | 97 LOG(ERROR) << "No file captured to install."; |
97 return; | 98 return; |
98 } | 99 } |
99 | 100 |
100 Profile* profile = Profile::FromBrowserContext( | 101 Profile* profile = Profile::FromBrowserContext( |
101 web_ui()->GetWebContents()->GetBrowserContext()); | 102 web_ui()->GetWebContents()->GetBrowserContext()); |
102 scoped_ptr<ExtensionInstallPrompt> prompt( | |
103 new ExtensionInstallPrompt(web_ui()->GetWebContents())); | |
104 scoped_refptr<CrxInstaller> crx_installer(CrxInstaller::Create( | |
105 ExtensionSystem::Get(profile)->extension_service(), | |
106 prompt.Pass())); | |
107 crx_installer->set_error_on_unsupported_requirements(true); | |
108 crx_installer->set_off_store_install_allow_reason( | |
109 CrxInstaller::OffStoreInstallAllowedFromSettingsPage); | |
110 crx_installer->set_install_immediately(true); | |
111 | 103 |
112 const bool kCaseSensitive = false; | 104 const bool kCaseSensitive = false; |
113 | 105 |
114 if (EndsWith(file_display_name_, | 106 if (EndsWith( |
115 base::ASCIIToUTF16(".user.js"), | 107 file_display_name_, base::ASCIIToUTF16(".zip"), kCaseSensitive)) { |
116 kCaseSensitive)) { | 108 ZipFileInstaller::Create(ExtensionSystem::Get(profile)->extension_service()) |
117 crx_installer->InstallUserScript( | 109 ->LoadFromZipFile(file_to_install_); |
118 file_to_install_, | |
119 net::FilePathToFileURL(file_to_install_)); | |
120 } else if (EndsWith(file_display_name_, | |
121 base::ASCIIToUTF16(".crx"), | |
122 kCaseSensitive)) { | |
123 crx_installer->InstallCrx(file_to_install_); | |
124 } else { | 110 } else { |
125 CHECK(false); | 111 scoped_ptr<ExtensionInstallPrompt> prompt( |
| 112 new ExtensionInstallPrompt(web_ui()->GetWebContents())); |
| 113 scoped_refptr<CrxInstaller> crx_installer(CrxInstaller::Create( |
| 114 ExtensionSystem::Get(profile)->extension_service(), prompt.Pass())); |
| 115 crx_installer->set_error_on_unsupported_requirements(true); |
| 116 crx_installer->set_off_store_install_allow_reason( |
| 117 CrxInstaller::OffStoreInstallAllowedFromSettingsPage); |
| 118 crx_installer->set_install_immediately(true); |
| 119 |
| 120 if (EndsWith(file_display_name_, |
| 121 base::ASCIIToUTF16(".user.js"), |
| 122 kCaseSensitive)) { |
| 123 crx_installer->InstallUserScript( |
| 124 file_to_install_, net::FilePathToFileURL(file_to_install_)); |
| 125 } else if (EndsWith(file_display_name_, |
| 126 base::ASCIIToUTF16(".crx"), |
| 127 kCaseSensitive)) { |
| 128 crx_installer->InstallCrx(file_to_install_); |
| 129 } else { |
| 130 CHECK(false); |
| 131 } |
126 } | 132 } |
127 | 133 |
128 file_to_install_.clear(); | 134 file_to_install_.clear(); |
129 file_display_name_.clear(); | 135 file_display_name_.clear(); |
130 } | 136 } |
131 | 137 |
132 void InstallExtensionHandler::HandleInstallDirectoryMessage( | 138 void InstallExtensionHandler::HandleInstallDirectoryMessage( |
133 const base::ListValue* args) { | 139 const base::ListValue* args) { |
134 Profile* profile = Profile::FromBrowserContext( | 140 Profile* profile = Profile::FromBrowserContext( |
135 web_ui()->GetWebContents()->GetBrowserContext()); | 141 web_ui()->GetWebContents()->GetBrowserContext()); |
136 UnpackedInstaller::Create( | 142 UnpackedInstaller::Create( |
137 ExtensionSystem::Get(profile)-> | 143 ExtensionSystem::Get(profile)-> |
138 extension_service())->Load(file_to_install_); | 144 extension_service())->Load(file_to_install_); |
139 } | 145 } |
140 | 146 |
141 } // namespace extensions | 147 } // namespace extensions |
OLD | NEW |