| OLD | NEW |
| 1 // Copyright (c) 2011 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/permissions_updater.h" |
| 29 #include "chrome/browser/shell_integration.h" | 30 #include "chrome/browser/shell_integration.h" |
| 30 #include "chrome/browser/web_applications/web_app.h" | 31 #include "chrome/browser/web_applications/web_app.h" |
| 31 #include "chrome/common/chrome_notification_types.h" | 32 #include "chrome/common/chrome_notification_types.h" |
| 32 #include "chrome/common/chrome_paths.h" | 33 #include "chrome/common/chrome_paths.h" |
| 33 #include "chrome/common/extensions/extension_constants.h" | 34 #include "chrome/common/extensions/extension_constants.h" |
| 34 #include "chrome/common/extensions/extension_file_util.h" | 35 #include "chrome/common/extensions/extension_file_util.h" |
| 35 #include "content/public/browser/browser_thread.h" | 36 #include "content/public/browser/browser_thread.h" |
| 36 #include "content/public/browser/notification_service.h" | 37 #include "content/public/browser/notification_service.h" |
| 37 #include "content/public/browser/user_metrics.h" | 38 #include "content/public/browser/user_metrics.h" |
| 38 #include "grit/chromium_strings.h" | 39 #include "grit/chromium_strings.h" |
| 39 #include "grit/generated_resources.h" | 40 #include "grit/generated_resources.h" |
| 40 #include "grit/theme_resources.h" | 41 #include "grit/theme_resources.h" |
| 41 #include "third_party/skia/include/core/SkBitmap.h" | 42 #include "third_party/skia/include/core/SkBitmap.h" |
| 42 #include "ui/base/l10n/l10n_util.h" | 43 #include "ui/base/l10n/l10n_util.h" |
| 43 #include "ui/base/resource/resource_bundle.h" | 44 #include "ui/base/resource/resource_bundle.h" |
| 44 | 45 |
| 45 using content::BrowserThread; | 46 using content::BrowserThread; |
| 46 using content::UserMetricsAction; | 47 using content::UserMetricsAction; |
| 48 using extensions::PermissionsUpdater; |
| 47 | 49 |
| 48 namespace { | 50 namespace { |
| 49 | 51 |
| 50 struct Whitelist { | 52 struct Whitelist { |
| 51 Whitelist() {} | 53 Whitelist() {} |
| 52 std::set<std::string> ids; | 54 std::set<std::string> ids; |
| 53 std::map<std::string, linked_ptr<CrxInstaller::WhitelistEntry> > entries; | 55 std::map<std::string, linked_ptr<CrxInstaller::WhitelistEntry> > entries; |
| 54 }; | 56 }; |
| 55 | 57 |
| 56 static base::LazyInstance<Whitelist> | 58 static base::LazyInstance<Whitelist> |
| (...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 return; | 577 return; |
| 576 | 578 |
| 577 // If there is a client, tell the client about installation. | 579 // If there is a client, tell the client about installation. |
| 578 if (client_) | 580 if (client_) |
| 579 client_->OnInstallSuccess(extension_.get(), install_icon_.get()); | 581 client_->OnInstallSuccess(extension_.get(), install_icon_.get()); |
| 580 | 582 |
| 581 // We update the extension's granted permissions if the user already approved | 583 // We update the extension's granted permissions if the user already approved |
| 582 // the install (client_ is non NULL), or we are allowed to install this | 584 // the install (client_ is non NULL), or we are allowed to install this |
| 583 // silently. We only track granted permissions for INTERNAL extensions. | 585 // silently. We only track granted permissions for INTERNAL extensions. |
| 584 if ((client_ || allow_silent_install_) && | 586 if ((client_ || allow_silent_install_) && |
| 585 extension_->location() == Extension::INTERNAL) | 587 extension_->location() == Extension::INTERNAL) { |
| 586 frontend_weak_->GrantPermissions(extension_); | 588 PermissionsUpdater perms_updater(profile()); |
| 589 perms_updater.GrantActivePermissions(extension_); |
| 590 } |
| 587 | 591 |
| 588 // Tell the frontend about the installation and hand off ownership of | 592 // Tell the frontend about the installation and hand off ownership of |
| 589 // extension_ to it. | 593 // extension_ to it. |
| 590 frontend_weak_->OnExtensionInstalled(extension_, is_gallery_install(), | 594 frontend_weak_->OnExtensionInstalled(extension_, is_gallery_install(), |
| 591 page_ordinal_); | 595 page_ordinal_); |
| 592 | 596 |
| 593 NotifyCrxInstallComplete(extension_.get()); | 597 NotifyCrxInstallComplete(extension_.get()); |
| 594 | 598 |
| 595 extension_ = NULL; | 599 extension_ = NULL; |
| 596 | 600 |
| 597 // We're done. We don't post any more tasks to ourselves so we are deleted | 601 // We're done. We don't post any more tasks to ourselves so we are deleted |
| 598 // soon. | 602 // soon. |
| 599 } | 603 } |
| 600 | 604 |
| 601 void CrxInstaller::NotifyCrxInstallComplete(const Extension* extension) { | 605 void CrxInstaller::NotifyCrxInstallComplete(const Extension* extension) { |
| 602 // Some users (such as the download shelf) need to know when a | 606 // Some users (such as the download shelf) need to know when a |
| 603 // CRXInstaller is done. Listening for the EXTENSION_* events | 607 // CRXInstaller is done. Listening for the EXTENSION_* events |
| 604 // is problematic because they don't know anything about the | 608 // is problematic because they don't know anything about the |
| 605 // extension before it is unpacked, so they cannot filter based | 609 // extension before it is unpacked, so they cannot filter based |
| 606 // on the extension. | 610 // on the extension. |
| 607 content::NotificationService::current()->Notify( | 611 content::NotificationService::current()->Notify( |
| 608 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 612 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 609 content::Source<CrxInstaller>(this), | 613 content::Source<CrxInstaller>(this), |
| 610 content::Details<const Extension>(extension)); | 614 content::Details<const Extension>(extension)); |
| 611 } | 615 } |
| OLD | NEW |