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

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

Issue 8520035: Revert 110264 - Fix for management API related to escalated permissions disabled extensions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 1 month 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_management_api.cc
===================================================================
--- chrome/browser/extensions/extension_management_api.cc (revision 110267)
+++ chrome/browser/extensions/extension_management_api.cc (working copy)
@@ -7,15 +7,14 @@
#include <map>
#include <string>
-#include "base/basictypes.h"
#include "base/bind.h"
+#include "base/basictypes.h"
#include "base/json/json_writer.h"
#include "base/metrics/histogram.h"
#include "base/string_number_conversions.h"
#include "base/string_util.h"
#include "chrome/browser/extensions/extension_event_names.h"
#include "chrome/browser/extensions/extension_event_router.h"
-#include "chrome/browser/extensions/extension_management_api_constants.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_updater.h"
#include "chrome/browser/profiles/profile.h"
@@ -33,45 +32,61 @@
using base::IntToString;
using content::BrowserThread;
-
namespace events = extension_event_names;
-namespace keys = extension_management_api_constants;
-ExtensionService* ExtensionManagementFunction::service() {
- return profile()->GetExtensionService();
+namespace {
+
+const char kAppLaunchUrlKey[] = "appLaunchUrl";
+const char kDescriptionKey[] = "description";
+const char kEnabledKey[] = "enabled";
+const char kHomepageUrlKey[] = "homepageUrl";
+const char kIconsKey[] = "icons";
+const char kIdKey[] = "id";
+const char kIsAppKey[] = "isApp";
+const char kNameKey[] = "name";
+const char kOfflineEnabledKey[] = "offlineEnabled";
+const char kOptionsUrlKey[] = "optionsUrl";
+const char kPermissionsKey[] = "permissions";
+const char kMayDisableKey[] = "mayDisable";
+const char kSizeKey[] = "size";
+const char kUpdateUrlKey[] = "updateUrl";
+const char kUrlKey[] = "url";
+const char kVersionKey[] = "version";
+
+const char kExtensionCreateError[] =
+ "Failed to create extension from manifest.";
+const char kManifestParseError[] = "Failed to parse manifest.";
+const char kNoExtensionError[] = "Failed to find extension with id *";
+const char kNotAnAppError[] = "Extension * is not an App";
+const char kUserCantDisableError[] = "Extension * can not be disabled by user";
}
-ExtensionService* AsyncExtensionManagementFunction::service() {
+ExtensionService* ExtensionManagementFunction::service() {
return profile()->GetExtensionService();
}
static DictionaryValue* CreateExtensionInfo(const Extension& extension,
- bool enabled,
- bool permissions_escalated) {
+ bool enabled) {
DictionaryValue* info = new DictionaryValue();
- info->SetString(keys::kIdKey, extension.id());
- info->SetBoolean(keys::kIsAppKey, extension.is_app());
- info->SetString(keys::kNameKey, extension.name());
- info->SetBoolean(keys::kEnabledKey, enabled);
- if (!enabled) {
- const char* reason = permissions_escalated ?
- keys::kDisabledReasonPermissionsIncrease : keys::kDisabledReasonUnknown;
- info->SetString(keys::kDisabledReasonKey, reason);
- }
- info->SetBoolean(keys::kMayDisableKey,
+ info->SetString(kIdKey, extension.id());
+ info->SetBoolean(kIsAppKey, extension.is_app());
+ info->SetString(kNameKey, extension.name());
+ info->SetBoolean(kEnabledKey, enabled);
+ info->SetBoolean(kMayDisableKey,
Extension::UserMayDisable(extension.location()));
- info->SetBoolean(keys::kOfflineEnabledKey, extension.offline_enabled());
- info->SetString(keys::kVersionKey, extension.VersionString());
- info->SetString(keys::kDescriptionKey, extension.description());
- info->SetString(keys::kOptionsUrlKey,
+ info->SetBoolean(kOfflineEnabledKey, extension.offline_enabled());
+ info->SetString(kVersionKey, extension.VersionString());
+ info->SetString(kDescriptionKey, extension.description());
+ info->SetString(kOptionsUrlKey,
extension.options_url().possibly_invalid_spec());
- info->SetString(keys::kHomepageUrlKey,
+ info->SetString(kHomepageUrlKey,
extension.GetHomepageURL().possibly_invalid_spec());
- if (!extension.update_url().is_empty())
- info->SetString(keys::kUpdateUrlKey,
+ if (!extension.update_url().is_empty()) {
+ info->SetString(kUpdateUrlKey,
extension.update_url().possibly_invalid_spec());
+ }
if (extension.is_app())
- info->SetString(keys::kAppLaunchUrlKey,
+ info->SetString(kAppLaunchUrlKey,
extension.GetFullLaunchURL().possibly_invalid_spec());
const ExtensionIconSet::IconMap& icons = extension.icons().map();
@@ -83,8 +98,8 @@
Extension::Icons size = static_cast<Extension::Icons>(icon_iter->first);
GURL url = ExtensionIconSource::GetIconURL(
&extension, size, ExtensionIconSet::MATCH_EXACTLY, false, NULL);
- icon_info->SetInteger(keys::kSizeKey, icon_iter->first);
- icon_info->SetString(keys::kUrlKey, url.spec());
+ icon_info->SetInteger(kSizeKey, icon_iter->first);
+ icon_info->SetString(kUrlKey, url.spec());
icon_list->Append(icon_info);
}
info->Set("icons", icon_list);
@@ -124,8 +139,7 @@
static void AddExtensionInfo(ListValue* list,
const ExtensionList& extensions,
- bool enabled,
- ExtensionPrefs* prefs) {
+ bool enabled) {
for (ExtensionList::const_iterator i = extensions.begin();
i != extensions.end(); ++i) {
const Extension& extension = **i;
@@ -133,9 +147,7 @@
if (extension.location() == Extension::COMPONENT)
continue; // Skip built-in extensions.
- bool escalated =
- prefs->DidExtensionEscalatePermissions(extension.id());
- list->Append(CreateExtensionInfo(extension, enabled, escalated));
+ list->Append(CreateExtensionInfo(extension, enabled));
}
}
@@ -143,10 +155,8 @@
ListValue* result = new ListValue();
result_.reset(result);
- ExtensionPrefs* prefs = service()->extension_prefs();
- AddExtensionInfo(result, *service()->extensions(), true, prefs);
- AddExtensionInfo(
- result, *service()->disabled_extensions(), false, prefs);
+ AddExtensionInfo(result, *service()->extensions(), true);
+ AddExtensionInfo(result, *service()->disabled_extensions(), false);
return true;
}
@@ -156,14 +166,12 @@
EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id));
const Extension* extension = service()->GetExtensionById(extension_id, true);
if (!extension) {
- error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kNoExtensionError,
+ error_ = ExtensionErrorUtils::FormatErrorMessage(kNoExtensionError,
extension_id);
return false;
}
bool enabled = service()->IsExtensionEnabled(extension_id);
- ExtensionPrefs* prefs = service()->extension_prefs();
- bool escalated = prefs->DidExtensionEscalatePermissions(extension_id);
- DictionaryValue* result = CreateExtensionInfo(*extension, enabled, escalated);
+ DictionaryValue* result = CreateExtensionInfo(*extension, enabled);
result_.reset(result);
return true;
@@ -175,7 +183,7 @@
const Extension* extension = service()->GetExtensionById(ext_id, true);
if (!extension) {
- error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kNoExtensionError,
+ error_ = ExtensionErrorUtils::FormatErrorMessage(kNoExtensionError,
ext_id);
return false;
}
@@ -234,7 +242,7 @@
if (value->IsType(Value::TYPE_DICTIONARY))
parsed_manifest_.reset(static_cast<DictionaryValue*>(value)->DeepCopy());
else
- error_ = keys::kManifestParseError;
+ error_ = kManifestParseError;
utility_host_ = NULL; // has already deleted itself
BrowserThread::PostTask(
@@ -302,7 +310,7 @@
FilePath(), Extension::INVALID, *parsed_manifest,
Extension::STRICT_ERROR_CHECKS, &error_);
if (!extension.get()) {
- OnParseFailure(keys::kExtensionCreateError);
+ OnParseFailure(kExtensionCreateError);
return;
}
@@ -332,12 +340,12 @@
EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id));
const Extension* extension = service()->GetExtensionById(extension_id, true);
if (!extension) {
- error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kNoExtensionError,
+ error_ = ExtensionErrorUtils::FormatErrorMessage(kNoExtensionError,
extension_id);
return false;
}
if (!extension->is_app()) {
- error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kNotAnAppError,
+ error_ = ExtensionErrorUtils::FormatErrorMessage(kNotAnAppError,
extension_id);
return false;
}
@@ -357,74 +365,40 @@
return true;
}
-SetEnabledFunction::SetEnabledFunction() {}
-
-SetEnabledFunction::~SetEnabledFunction() {}
-
bool SetEnabledFunction::RunImpl() {
+ std::string extension_id;
bool enable;
- EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id_));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id));
EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &enable));
- const Extension* extension = service()->GetExtensionById(extension_id_, true);
+ const Extension* extension = service()->GetExtensionById(extension_id, true);
if (!extension) {
error_ = ExtensionErrorUtils::FormatErrorMessage(
- keys::kNoExtensionError, extension_id_);
+ kNoExtensionError, extension_id);
return false;
}
if (!Extension::UserMayDisable(extension->location())) {
error_ = ExtensionErrorUtils::FormatErrorMessage(
- keys::kUserCantDisableError, extension_id_);
+ kUserCantDisableError, extension_id);
return false;
}
- bool currently_enabled = service()->IsExtensionEnabled(extension_id_);
+ if (!service()->IsExtensionEnabled(extension_id) && enable)
+ service()->EnableExtension(extension_id);
+ else if (service()->IsExtensionEnabled(extension_id) && !enable)
+ service()->DisableExtension(extension_id);
- if (!currently_enabled && enable) {
- ExtensionPrefs* prefs = service()->extension_prefs();
- if (prefs->DidExtensionEscalatePermissions(extension_id_)) {
- if (!user_gesture()) {
- error_ = keys::kGestureNeededForEscalationError;
- return false;
- }
- AddRef(); // Matched in InstallUIProceed/InstallUIAbort
- install_ui_.reset(new ExtensionInstallUI(profile_));
- install_ui_->ConfirmReEnable(this, extension);
- return true;
- }
- service()->EnableExtension(extension_id_);
- } else if (currently_enabled && !enable) {
- service()->DisableExtension(extension_id_);
- }
-
- BrowserThread::PostTask(
- BrowserThread::UI,
- FROM_HERE,
- base::Bind(&SetEnabledFunction::SendResponse, this, true));
-
return true;
}
-void SetEnabledFunction::InstallUIProceed() {
- service()->EnableExtension(extension_id_);
- SendResponse(true);
- Release();
-}
-
-void SetEnabledFunction::InstallUIAbort(bool user_initiated) {
- error_ = keys::kUserDidNotReEnableError;
- SendResponse(false);
- Release();
-}
-
bool UninstallFunction::RunImpl() {
std::string extension_id;
EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id));
if (!service()->GetExtensionById(extension_id, true)) {
error_ = ExtensionErrorUtils::FormatErrorMessage(
- keys::kNoExtensionError, extension_id);
+ kNoExtensionError, extension_id);
return false;
}
@@ -433,7 +407,7 @@
if (!Extension::UserMayDisable(
prefs->GetInstalledExtensionInfo(extension_id)->extension_location)) {
error_ = ExtensionErrorUtils::FormatErrorMessage(
- keys::kUserCantDisableError, extension_id);
+ kUserCantDisableError, extension_id);
return false;
}
@@ -503,10 +477,8 @@
}
CHECK(extension);
ExtensionService* service = profile->GetExtensionService();
- ExtensionPrefs* prefs = service->extension_prefs();
bool enabled = service->GetExtensionById(extension->id(), false) != NULL;
- bool escalated = prefs ->DidExtensionEscalatePermissions(extension->id());
- args.Append(CreateExtensionInfo(*extension, enabled, escalated));
+ args.Append(CreateExtensionInfo(*extension, enabled));
}
std::string args_json;

Powered by Google App Engine
This is Rietveld 408576698