| OLD | NEW |
| 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/singleton.h" |
| 12 #include "base/task.h" | 13 #include "base/task.h" |
| 13 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 14 #include "base/version.h" | 15 #include "base/version.h" |
| 15 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/chrome_thread.h" | 17 #include "chrome/browser/chrome_thread.h" |
| 17 #include "chrome/browser/extensions/convert_user_script.h" | 18 #include "chrome/browser/extensions/convert_user_script.h" |
| 18 #include "chrome/browser/extensions/extensions_service.h" | 19 #include "chrome/browser/extensions/extensions_service.h" |
| 19 #include "chrome/browser/extensions/extension_error_reporter.h" | 20 #include "chrome/browser/extensions/extension_error_reporter.h" |
| 20 #include "chrome/browser/profile.h" | 21 #include "chrome/browser/profile.h" |
| 21 #include "chrome/browser/shell_integration.h" | 22 #include "chrome/browser/shell_integration.h" |
| 22 #include "chrome/browser/web_applications/web_app.h" | 23 #include "chrome/browser/web_applications/web_app.h" |
| 23 #include "chrome/common/chrome_paths.h" | 24 #include "chrome/common/chrome_paths.h" |
| 24 #include "chrome/common/extensions/extension_file_util.h" | 25 #include "chrome/common/extensions/extension_file_util.h" |
| 25 #include "chrome/common/extensions/extension_constants.h" | 26 #include "chrome/common/extensions/extension_constants.h" |
| 26 #include "chrome/common/notification_service.h" | 27 #include "chrome/common/notification_service.h" |
| 27 #include "chrome/common/notification_type.h" | 28 #include "chrome/common/notification_type.h" |
| 28 #include "grit/chromium_strings.h" | 29 #include "grit/chromium_strings.h" |
| 29 #include "grit/generated_resources.h" | 30 #include "grit/generated_resources.h" |
| 30 #include "grit/theme_resources.h" | 31 #include "grit/theme_resources.h" |
| 31 #include "third_party/skia/include/core/SkBitmap.h" | 32 #include "third_party/skia/include/core/SkBitmap.h" |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 // Helper function to delete files. This is used to avoid ugly casts which | 35 |
| 35 // would be necessary with PostMessage since file_util::Delete is overloaded. | 36 // Helper function to delete files. This is used to avoid ugly casts which |
| 36 static void DeleteFileHelper(const FilePath& path, bool recursive) { | 37 // would be necessary with PostMessage since file_util::Delete is overloaded. |
| 37 file_util::Delete(path, recursive); | 38 static void DeleteFileHelper(const FilePath& path, bool recursive) { |
| 39 file_util::Delete(path, recursive); |
| 40 } |
| 41 |
| 42 struct WhitelistedInstallData { |
| 43 WhitelistedInstallData() {} |
| 44 std::list<std::string> ids; |
| 45 }; |
| 46 |
| 47 } |
| 48 |
| 49 // static |
| 50 void CrxInstaller::SetWhitelistedInstallId(const std::string& id) { |
| 51 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 52 Singleton<WhitelistedInstallData>::get()->ids.push_back(id); |
| 53 } |
| 54 |
| 55 // static |
| 56 bool CrxInstaller::ClearWhitelistedInstallId(const std::string& id) { |
| 57 std::list<std::string>& ids = Singleton<WhitelistedInstallData>::get()->ids; |
| 58 std::list<std::string>::iterator iter = ids.begin(); |
| 59 for (; iter != ids.end(); ++iter) { |
| 60 if (*iter == id) { |
| 61 break; |
| 62 } |
| 38 } | 63 } |
| 64 |
| 65 if (iter != ids.end()) { |
| 66 ids.erase(iter); |
| 67 return true; |
| 68 } |
| 69 |
| 70 return false; |
| 39 } | 71 } |
| 40 | 72 |
| 41 CrxInstaller::CrxInstaller(const FilePath& install_directory, | 73 CrxInstaller::CrxInstaller(const FilePath& install_directory, |
| 42 ExtensionsService* frontend, | 74 ExtensionsService* frontend, |
| 43 ExtensionInstallUI* client) | 75 ExtensionInstallUI* client) |
| 44 : install_directory_(install_directory), | 76 : install_directory_(install_directory), |
| 45 install_source_(Extension::INTERNAL), | 77 install_source_(Extension::INTERNAL), |
| 46 delete_source_(false), | 78 delete_source_(false), |
| 47 allow_privilege_increase_(false), | 79 allow_privilege_increase_(false), |
| 48 limit_web_extent_to_download_host_(false), | 80 limit_web_extent_to_download_host_(false), |
| 49 create_app_shortcut_(false), | 81 create_app_shortcut_(false), |
| 50 frontend_(frontend), | 82 frontend_(frontend), |
| 51 client_(client), | 83 client_(client), |
| 52 apps_require_extension_mime_type_(false) { | 84 apps_require_extension_mime_type_(false), |
| 85 allow_silent_install_(false) { |
| 53 extensions_enabled_ = frontend_->extensions_enabled(); | 86 extensions_enabled_ = frontend_->extensions_enabled(); |
| 54 } | 87 } |
| 55 | 88 |
| 56 CrxInstaller::~CrxInstaller() { | 89 CrxInstaller::~CrxInstaller() { |
| 57 // Delete the temp directory and crx file as necessary. Note that the | 90 // Delete the temp directory and crx file as necessary. Note that the |
| 58 // destructor might be called on any thread, so we post a task to the file | 91 // destructor might be called on any thread, so we post a task to the file |
| 59 // thread to make sure the delete happens there. | 92 // thread to make sure the delete happens there. |
| 60 if (!temp_dir_.value().empty()) { | 93 if (!temp_dir_.value().empty()) { |
| 61 ChromeThread::PostTask( | 94 ChromeThread::PostTask( |
| 62 ChromeThread::FILE, FROM_HERE, | 95 ChromeThread::FILE, FROM_HERE, |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 if (overlapping_extension) { | 247 if (overlapping_extension) { |
| 215 ReportFailureFromUIThread(l10n_util::GetStringFUTF8( | 248 ReportFailureFromUIThread(l10n_util::GetStringFUTF8( |
| 216 IDS_EXTENSION_OVERLAPPING_WEB_EXTENT, | 249 IDS_EXTENSION_OVERLAPPING_WEB_EXTENT, |
| 217 UTF8ToUTF16(overlapping_extension->name()))); | 250 UTF8ToUTF16(overlapping_extension->name()))); |
| 218 return; | 251 return; |
| 219 } | 252 } |
| 220 | 253 |
| 221 current_version_ = | 254 current_version_ = |
| 222 frontend_->extension_prefs()->GetVersionString(extension_->id()); | 255 frontend_->extension_prefs()->GetVersionString(extension_->id()); |
| 223 | 256 |
| 224 if (client_) { | 257 if (client_ && |
| 258 (!allow_silent_install_ || |
| 259 !ClearWhitelistedInstallId(extension_->id()))) { |
| 225 AddRef(); // Balanced in Proceed() and Abort(). | 260 AddRef(); // Balanced in Proceed() and Abort(). |
| 226 client_->ConfirmInstall(this, extension_.get()); | 261 client_->ConfirmInstall(this, extension_.get()); |
| 227 } else { | 262 } else { |
| 228 ChromeThread::PostTask( | 263 ChromeThread::PostTask( |
| 229 ChromeThread::FILE, FROM_HERE, | 264 ChromeThread::FILE, FROM_HERE, |
| 230 NewRunnableMethod(this, &CrxInstaller::CompleteInstall)); | 265 NewRunnableMethod(this, &CrxInstaller::CompleteInstall)); |
| 231 } | 266 } |
| 232 return; | 267 return; |
| 233 } | 268 } |
| 234 | 269 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 client_->OnInstallSuccess(extension_.get()); | 390 client_->OnInstallSuccess(extension_.get()); |
| 356 | 391 |
| 357 // Tell the frontend about the installation and hand off ownership of | 392 // Tell the frontend about the installation and hand off ownership of |
| 358 // extension_ to it. | 393 // extension_ to it. |
| 359 frontend_->OnExtensionInstalled(extension_.release(), | 394 frontend_->OnExtensionInstalled(extension_.release(), |
| 360 allow_privilege_increase_); | 395 allow_privilege_increase_); |
| 361 | 396 |
| 362 // We're done. We don't post any more tasks to ourselves so we are deleted | 397 // We're done. We don't post any more tasks to ourselves so we are deleted |
| 363 // soon. | 398 // soon. |
| 364 } | 399 } |
| OLD | NEW |