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

Unified Diff: chrome/browser/extensions/extension_service.cc

Issue 9694038: OBSOLETE REVIEW. See http://codereview.chromium.org/10382149/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_service.cc
===================================================================
--- chrome/browser/extensions/extension_service.cc (revision 136836)
+++ chrome/browser/extensions/extension_service.cc (working copy)
@@ -17,7 +17,6 @@
#include "base/metrics/histogram.h"
#include "base/path_service.h"
#include "base/stl_util.h"
-#include "base/string16.h"
#include "base/string_number_conversions.h"
#include "base/string_util.h"
#include "base/stringprintf.h"
@@ -106,9 +105,11 @@
#include "content/public/browser/render_process_host.h"
#include "content/public/common/pepper_plugin_info.h"
#include "googleurl/src/gurl.h"
+#include "grit/generated_resources.h"
#include "net/base/registry_controlled_domain.h"
#include "webkit/database/database_tracker.h"
#include "webkit/database/database_util.h"
+#include "ui/base/l10n/l10n_util.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/cros/cros_library.h"
@@ -365,7 +366,7 @@
// The following call to UninstallExtension will not allow an uninstall of a
// policy-controlled extension.
- std::string error;
+ string16 error;
if (!extensions_service->UninstallExtension(extension_id, false, &error)) {
LOG(WARNING) << "Cannot uninstall extension with id " << extension_id
<< ": " << error;
@@ -410,6 +411,12 @@
extensions_enabled_ = false;
}
+ extension_management_policy_.RegisterDelegate(this);
+
+ // Normally each delegate should register itself, but the ExtensionPrefs are
+ // created before the ExtensionService.
+ extension_management_policy_.RegisterDelegate(extension_prefs_);
+
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
content::NotificationService::AllBrowserContextsAndSources());
registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED,
@@ -489,6 +496,10 @@
return &pending_extension_manager_;
}
+ExtensionManagementPolicy* ExtensionService::extension_management_policy() {
+ return &extension_management_policy_;
+}
+
ExtensionService::~ExtensionService() {
// No need to unload extensions here because they are profile-scoped, and the
// profile is in the process of being deleted.
@@ -749,7 +760,7 @@
bool ExtensionService::UninstallExtension(
std::string extension_id,
bool external_uninstall,
- std::string* error) {
+ string16* error) {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
scoped_refptr<const Extension> extension(GetInstalledExtension(extension_id));
@@ -760,15 +771,13 @@
// Policy change which triggers an uninstall will always set
// |external_uninstall| to true so this is the only way to uninstall
// managed extensions.
- if (!Extension::UserMayDisable(extension->location()) &&
- !external_uninstall) {
+ if (!external_uninstall &&
+ !extension_management_policy_.
+ UserMayModifyStatus(extension.get(), error)) {
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED,
content::Source<Profile>(profile_),
content::Details<const Extension>(extension));
- if (error != NULL) {
- *error = errors::kCannotUninstallManagedExtension;
- }
return false;
}
@@ -879,6 +888,38 @@
return extension_prefs_->IsExternalExtensionUninstalled(extension_id);
}
+bool ExtensionService::UserMayModifyStatus(const Extension* extension,
+ string16* error) const {
+ return ExtensionManagementPolicyImpl(extension, error, true);
+}
+
+bool ExtensionService::UserMayModifyUsage(const Extension* extension,
+ string16* error) const {
+ return ExtensionManagementPolicyImpl(extension, error, true);
+}
+
+bool ExtensionService::MustRemainEnabled(const Extension* extension,
+ string16* error) const {
+ return ExtensionManagementPolicyImpl(extension, error, false);
+}
+
+bool ExtensionService::ExtensionManagementPolicyImpl(const Extension* extension,
+ string16* error, bool modifiable_value) const {
+ // An extension that is required (by admin policy, for example) cannot be
+ // modified.
+ bool modifiable = !Extension::IsRequired(extension->location());
+ if (modifiable)
+ return modifiable_value;
+
+ if (error) {
+ *error = l10n_util::GetStringFUTF16(
+ IDS_EXTENSION_CANT_MODIFY_POLICY_REQUIRED,
+ UTF8ToUTF16(extension->name()),
+ UTF8ToUTF16(extension->id()));
+ }
+ return !modifiable_value;
+}
+
void ExtensionService::EnableExtension(const std::string& extension_id) {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
@@ -919,8 +960,10 @@
const Extension* extension = GetInstalledExtension(extension_id);
// |extension| can be NULL if sync disables an extension that is not
// installed yet.
- if (extension && !Extension::UserMayDisable(extension->location()))
+ if (extension &&
+ !extension_management_policy_.UserMayModifyStatus(extension, NULL)) {
return;
+ }
extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED);
extension_prefs_->SetDisableReason(extension_id, disable_reason);
@@ -1240,8 +1283,10 @@
for (ExtensionSet::const_iterator iter = extensions_.begin();
iter != extensions_.end(); ++iter) {
const Extension* extension = (*iter);
- if (!extension_prefs_->IsExtensionAllowedByPolicy(extension->id(),
- extension->location())) {
+ if (!extension_management_policy_.UserMayInstall(extension->id(),
+ extension->location(),
+ std::string(),
+ NULL)) {
to_be_removed.push_back(extension->id());
}
}
@@ -2192,7 +2237,7 @@
// installation disabled the extension, make sure it is now enabled.
bool initial_enable =
!extension_prefs_->IsExtensionDisabled(id) ||
- !Extension::UserMayDisable(extension->location());
+ extension_management_policy_.MustRemainEnabled(extension, NULL);
PendingExtensionInfo pending_extension_info;
if (pending_extension_manager()->GetById(id, &pending_extension_info)) {
pending_extension_manager()->Remove(id);

Powered by Google App Engine
This is Rietveld 408576698