| 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/extensions/crx_installer.h" | 5 #include "chrome/browser/extensions/crx_installer.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/metrics/field_trial.h" | 13 #include "base/metrics/field_trial.h" |
| 14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
| 16 #include "base/scoped_temp_dir.h" | 16 #include "base/scoped_temp_dir.h" |
| 17 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
| 18 #include "base/stringprintf.h" | 18 #include "base/stringprintf.h" |
| 19 #include "base/threading/thread_restrictions.h" | 19 #include "base/threading/thread_restrictions.h" |
| 20 #include "base/time.h" | 20 #include "base/time.h" |
| 21 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
| 22 #include "base/version.h" | 22 #include "base/version.h" |
| 23 #include "chrome/browser/browser_process.h" | 23 #include "chrome/browser/browser_process.h" |
| 24 #include "chrome/browser/extensions/convert_user_script.h" | 24 #include "chrome/browser/extensions/convert_user_script.h" |
| 25 #include "chrome/browser/extensions/convert_web_app.h" | 25 #include "chrome/browser/extensions/convert_web_app.h" |
| 26 #include "chrome/browser/extensions/default_apps_trial.h" | 26 #include "chrome/browser/extensions/default_apps_trial.h" |
| 27 #include "chrome/browser/extensions/extension_error_reporter.h" | 27 #include "chrome/browser/extensions/extension_error_reporter.h" |
| 28 #include "chrome/browser/extensions/extension_service.h" | 28 #include "chrome/browser/extensions/extension_service.h" |
| 29 #include "chrome/browser/extensions/extension_system.h" |
| 29 #include "chrome/browser/extensions/permissions_updater.h" | 30 #include "chrome/browser/extensions/permissions_updater.h" |
| 30 #include "chrome/browser/extensions/webstore_installer.h" | 31 #include "chrome/browser/extensions/webstore_installer.h" |
| 31 #include "chrome/browser/profiles/profile.h" | 32 #include "chrome/browser/profiles/profile.h" |
| 32 #include "chrome/browser/shell_integration.h" | 33 #include "chrome/browser/shell_integration.h" |
| 33 #include "chrome/browser/web_applications/web_app.h" | 34 #include "chrome/browser/web_applications/web_app.h" |
| 34 #include "chrome/common/chrome_notification_types.h" | 35 #include "chrome/common/chrome_notification_types.h" |
| 35 #include "chrome/common/chrome_paths.h" | 36 #include "chrome/common/chrome_paths.h" |
| 36 #include "chrome/common/extensions/extension_constants.h" | 37 #include "chrome/common/extensions/extension_constants.h" |
| 37 #include "chrome/common/extensions/extension_file_util.h" | 38 #include "chrome/common/extensions/extension_file_util.h" |
| 38 #include "chrome/common/extensions/extension_icon_set.h" | 39 #include "chrome/common/extensions/extension_icon_set.h" |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 | 220 |
| 220 // Make sure the manifests match if we want to bypass the prompt. | 221 // Make sure the manifests match if we want to bypass the prompt. |
| 221 if (approved_ && | 222 if (approved_ && |
| 222 (!expected_manifest_.get() || | 223 (!expected_manifest_.get() || |
| 223 !expected_manifest_->Equals(original_manifest_.get()))) { | 224 !expected_manifest_->Equals(original_manifest_.get()))) { |
| 224 *error = l10n_util::GetStringUTF16(IDS_EXTENSION_MANIFEST_INVALID); | 225 *error = l10n_util::GetStringUTF16(IDS_EXTENSION_MANIFEST_INVALID); |
| 225 return false; | 226 return false; |
| 226 } | 227 } |
| 227 | 228 |
| 228 // The checks below are skipped for themes and external installs. | 229 // The checks below are skipped for themes and external installs. |
| 230 // TODO(pamg): After ManagementPolicy refactoring is complete, remove this |
| 231 // and other uses of install_source_ that are no longer needed now that the |
| 232 // SandboxedExtensionUnpacker sets extension->location. |
| 229 if (extension->is_theme() || Extension::IsExternalLocation(install_source_)) | 233 if (extension->is_theme() || Extension::IsExternalLocation(install_source_)) |
| 230 return true; | 234 return true; |
| 231 | 235 |
| 232 if (!extensions_enabled_) { | 236 if (!extensions_enabled_) { |
| 233 *error = l10n_util::GetStringUTF16(IDS_EXTENSION_INSTALL_NOT_ENABLED); | 237 *error = l10n_util::GetStringUTF16(IDS_EXTENSION_INSTALL_NOT_ENABLED); |
| 234 return false; | 238 return false; |
| 235 } | 239 } |
| 236 | 240 |
| 237 if (extension_->is_app()) { | 241 if (extension_->is_app()) { |
| 238 // If the app was downloaded, apps_require_extension_mime_type_ | 242 // If the app was downloaded, apps_require_extension_mime_type_ |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 | 353 |
| 350 if (frontend_weak_->extension_prefs() | 354 if (frontend_weak_->extension_prefs() |
| 351 ->IsExtensionBlacklisted(extension_->id())) { | 355 ->IsExtensionBlacklisted(extension_->id())) { |
| 352 VLOG(1) << "This extension: " << extension_->id() | 356 VLOG(1) << "This extension: " << extension_->id() |
| 353 << " is blacklisted. Install failed."; | 357 << " is blacklisted. Install failed."; |
| 354 ReportFailureFromUIThread( | 358 ReportFailureFromUIThread( |
| 355 l10n_util::GetStringUTF16(IDS_EXTENSION_CANT_INSTALL_BLACKLISTED)); | 359 l10n_util::GetStringUTF16(IDS_EXTENSION_CANT_INSTALL_BLACKLISTED)); |
| 356 return; | 360 return; |
| 357 } | 361 } |
| 358 | 362 |
| 359 if (!frontend_weak_->extension_prefs()->IsExtensionAllowedByPolicy( | 363 string16 error; |
| 360 extension_->id(), install_source_)) { | 364 if (!ExtensionSystem::Get(profile_)->management_policy()->UserMayLoad( |
| 361 ReportFailureFromUIThread(l10n_util::GetStringFUTF16( | 365 extension_, &error)) { |
| 362 IDS_EXTENSION_CANT_INSTALL_POLICY_BLACKLIST, | 366 ReportFailureFromUIThread(error); |
| 363 UTF8ToUTF16(extension_->name()), | |
| 364 UTF8ToUTF16(extension_->id()))); | |
| 365 return; | 367 return; |
| 366 } | 368 } |
| 367 | 369 |
| 368 GURL overlapping_url; | 370 GURL overlapping_url; |
| 369 const Extension* overlapping_extension = | 371 const Extension* overlapping_extension = |
| 370 frontend_weak_->extensions()-> | 372 frontend_weak_->extensions()-> |
| 371 GetHostedAppByOverlappingWebExtent(extension_->web_extent()); | 373 GetHostedAppByOverlappingWebExtent(extension_->web_extent()); |
| 372 if (overlapping_extension && | 374 if (overlapping_extension && |
| 373 overlapping_extension->id() != extension_->id()) { | 375 overlapping_extension->id() != extension_->id()) { |
| 374 ReportFailureFromUIThread(l10n_util::GetStringFUTF16( | 376 ReportFailureFromUIThread(l10n_util::GetStringFUTF16( |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 // Some users (such as the download shelf) need to know when a | 562 // Some users (such as the download shelf) need to know when a |
| 561 // CRXInstaller is done. Listening for the EXTENSION_* events | 563 // CRXInstaller is done. Listening for the EXTENSION_* events |
| 562 // is problematic because they don't know anything about the | 564 // is problematic because they don't know anything about the |
| 563 // extension before it is unpacked, so they cannot filter based | 565 // extension before it is unpacked, so they cannot filter based |
| 564 // on the extension. | 566 // on the extension. |
| 565 content::NotificationService::current()->Notify( | 567 content::NotificationService::current()->Notify( |
| 566 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 568 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 567 content::Source<CrxInstaller>(this), | 569 content::Source<CrxInstaller>(this), |
| 568 content::Details<const Extension>(extension)); | 570 content::Details<const Extension>(extension)); |
| 569 } | 571 } |
| OLD | NEW |