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