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

Side by Side Diff: chrome/browser/extensions/crx_installer.cc

Issue 1521039: Allow extension overinstall (Closed)
Patch Set: blargh Created 10 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/extensions/crx_installer.h" 5 #include "chrome/browser/extensions/crx_installer.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/scoped_temp_dir.h" 11 #include "base/scoped_temp_dir.h"
12 #include "base/task.h" 12 #include "base/task.h"
13 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
14 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/chrome_thread.h" 15 #include "chrome/browser/chrome_thread.h"
16 #include "chrome/browser/extensions/convert_user_script.h" 16 #include "chrome/browser/extensions/convert_user_script.h"
17 #include "chrome/browser/extensions/extension_error_reporter.h" 17 #include "chrome/browser/extensions/extension_error_reporter.h"
18 #include "chrome/browser/profile.h" 18 #include "chrome/browser/profile.h"
19 #include "chrome/browser/shell_integration.h" 19 #include "chrome/browser/shell_integration.h"
20 #include "chrome/browser/web_applications/web_app.h" 20 #include "chrome/browser/web_applications/web_app.h"
21 #include "chrome/common/chrome_paths.h" 21 #include "chrome/common/chrome_paths.h"
22 #include "chrome/common/extensions/extension_file_util.h" 22 #include "chrome/common/extensions/extension_file_util.h"
23 #include "chrome/common/notification_service.h" 23 #include "chrome/common/notification_service.h"
24 #include "chrome/common/notification_type.h" 24 #include "chrome/common/notification_type.h"
25 #include "grit/browser_resources.h" 25 #include "grit/browser_resources.h"
26 #include "grit/chromium_strings.h" 26 #include "grit/chromium_strings.h"
27 #include "grit/generated_resources.h"
27 #include "third_party/skia/include/core/SkBitmap.h" 28 #include "third_party/skia/include/core/SkBitmap.h"
28 29
29 namespace { 30 namespace {
30 // Helper function to delete files. This is used to avoid ugly casts which 31 // Helper function to delete files. This is used to avoid ugly casts which
31 // would be necessary with PostMessage since file_util::Delete is overloaded. 32 // would be necessary with PostMessage since file_util::Delete is overloaded.
32 static void DeleteFileHelper(const FilePath& path, bool recursive) { 33 static void DeleteFileHelper(const FilePath& path, bool recursive) {
33 file_util::Delete(path, recursive); 34 file_util::Delete(path, recursive);
34 } 35 }
35 } 36 }
36 37
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 NotificationService::NoDetails()); 207 NotificationService::NoDetails());
207 Release(); // balanced in ConfirmInstall(). 208 Release(); // balanced in ConfirmInstall().
208 209
209 // We're done. Since we don't post any more tasks to ourself, our ref count 210 // We're done. Since we don't post any more tasks to ourself, our ref count
210 // should go to zero and we die. The destructor will clean up the temp dir. 211 // should go to zero and we die. The destructor will clean up the temp dir.
211 } 212 }
212 213
213 void CrxInstaller::CompleteInstall() { 214 void CrxInstaller::CompleteInstall() {
214 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); 215 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE));
215 216
216 FilePath version_dir; 217 if (!current_version_.empty()) {
217 Extension::InstallType install_type = 218 scoped_ptr<Version> current_version(
218 extension_file_util::CompareToInstalledVersion( 219 Version::GetVersionFromString(current_version_));
219 install_directory_, extension_->id(), current_version_, 220 if (current_version->CompareTo(*(extension_->version())) > 0) {
220 extension_->VersionString(), &version_dir); 221 ReportFailureFromFileThread("Attempted to downgrade extension.");
222 return;
223 }
224 }
221 225
222 if (install_type == Extension::DOWNGRADE) { 226 FilePath version_dir = extension_file_util::InstallExtension(
223 ReportFailureFromFileThread("Attempted to downgrade extension."); 227 unpacked_extension_root_,
228 extension_->id(),
229 extension_->VersionString(),
230 install_directory_);
231 if (version_dir.empty()) {
232 ReportFailureFromFileThread(
233 l10n_util::GetStringUTF8(
234 IDS_EXTENSION_MOVE_DIRECTORY_TO_PROFILE_FAILED));
224 return; 235 return;
225 } 236 }
226 237
227 if (install_type == Extension::REINSTALL) {
228 // We use this as a signal to switch themes.
229 ReportOverinstallFromFileThread();
230 return;
231 }
232
233 std::string error_msg;
234 if (!extension_file_util::InstallExtension(unpacked_extension_root_,
235 version_dir, &error_msg)) {
236 ReportFailureFromFileThread(error_msg);
237 return;
238 }
239
240 if (create_app_shortcut_) { 238 if (create_app_shortcut_) {
241 SkBitmap icon = install_icon_.get() ? *install_icon_ : 239 SkBitmap icon = install_icon_.get() ? *install_icon_ :
242 *ResourceBundle::GetSharedInstance().GetBitmapNamed( 240 *ResourceBundle::GetSharedInstance().GetBitmapNamed(
243 IDR_EXTENSION_DEFAULT_ICON); 241 IDR_EXTENSION_DEFAULT_ICON);
244 242
245 ShellIntegration::ShortcutInfo shortcut_info; 243 ShellIntegration::ShortcutInfo shortcut_info;
246 shortcut_info.url = extension_->GetFullLaunchURL(); 244 shortcut_info.url = extension_->GetFullLaunchURL();
247 shortcut_info.extension_id = UTF8ToUTF16(extension_->id()); 245 shortcut_info.extension_id = UTF8ToUTF16(extension_->id());
248 shortcut_info.title = UTF8ToUTF16(extension_->name()); 246 shortcut_info.title = UTF8ToUTF16(extension_->name());
249 shortcut_info.description = UTF8ToUTF16(extension_->description()); 247 shortcut_info.description = UTF8ToUTF16(extension_->description());
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 // see errors get reported via this interface. 287 // see errors get reported via this interface.
290 // 288 //
291 // TODO(aa): Need to go through unit tests and clean them up too, probably get 289 // TODO(aa): Need to go through unit tests and clean them up too, probably get
292 // rid of this line. 290 // rid of this line.
293 ExtensionErrorReporter::GetInstance()->ReportError(error, false); // quiet 291 ExtensionErrorReporter::GetInstance()->ReportError(error, false); // quiet
294 292
295 if (client_) 293 if (client_)
296 client_->OnInstallFailure(error); 294 client_->OnInstallFailure(error);
297 } 295 }
298 296
299 void CrxInstaller::ReportOverinstallFromFileThread() {
300 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE));
301 ChromeThread::PostTask(
302 ChromeThread::UI, FROM_HERE,
303 NewRunnableMethod(this, &CrxInstaller::ReportOverinstallFromUIThread));
304 }
305
306 void CrxInstaller::ReportOverinstallFromUIThread() {
307 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
308
309 NotificationService* service = NotificationService::current();
310 service->Notify(NotificationType::EXTENSION_OVERINSTALL_ERROR,
311 Source<CrxInstaller>(this),
312 Details<const FilePath>(&extension_->path()));
313
314 if (client_)
315 client_->OnOverinstallAttempted(extension_.get());
316
317 frontend_->OnExtensionOverinstallAttempted(extension_->id());
318 }
319
320 void CrxInstaller::ReportSuccessFromFileThread() { 297 void CrxInstaller::ReportSuccessFromFileThread() {
321 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); 298 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE));
322 ChromeThread::PostTask( 299 ChromeThread::PostTask(
323 ChromeThread::UI, FROM_HERE, 300 ChromeThread::UI, FROM_HERE,
324 NewRunnableMethod(this, &CrxInstaller::ReportSuccessFromUIThread)); 301 NewRunnableMethod(this, &CrxInstaller::ReportSuccessFromUIThread));
325 } 302 }
326 303
327 void CrxInstaller::ReportSuccessFromUIThread() { 304 void CrxInstaller::ReportSuccessFromUIThread() {
328 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); 305 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
329 306
330 // If there is a client, tell the client about installation. 307 // If there is a client, tell the client about installation.
331 if (client_) 308 if (client_)
332 client_->OnInstallSuccess(extension_.get()); 309 client_->OnInstallSuccess(extension_.get());
333 310
334 // Tell the frontend about the installation and hand off ownership of 311 // Tell the frontend about the installation and hand off ownership of
335 // extension_ to it. 312 // extension_ to it.
336 frontend_->OnExtensionInstalled(extension_.release(), 313 frontend_->OnExtensionInstalled(extension_.release(),
337 allow_privilege_increase_); 314 allow_privilege_increase_);
338 315
339 // We're done. We don't post any more tasks to ourselves so we are deleted 316 // We're done. We don't post any more tasks to ourselves so we are deleted
340 // soon. 317 // soon.
341 } 318 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/crx_installer.h ('k') | chrome/browser/extensions/extension_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698