Chromium Code Reviews| 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/extension_management_api.h" | 5 #include "chrome/browser/extensions/extension_management_api.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
| 15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 16 #include "chrome/browser/extensions/extension_event_names.h" | 16 #include "chrome/browser/extensions/extension_event_names.h" |
| 17 #include "chrome/browser/extensions/extension_event_router.h" | 17 #include "chrome/browser/extensions/extension_event_router.h" |
| 18 #include "chrome/browser/extensions/extension_management_api_constants.h" | 18 #include "chrome/browser/extensions/extension_management_api_constants.h" |
| 19 #include "chrome/browser/extensions/extension_service.h" | 19 #include "chrome/browser/extensions/extension_service.h" |
| 20 #include "chrome/browser/extensions/extension_system.h" | |
| 20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
| 22 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | 23 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
| 23 #include "chrome/common/chrome_notification_types.h" | 24 #include "chrome/common/chrome_notification_types.h" |
| 24 #include "chrome/common/chrome_utility_messages.h" | 25 #include "chrome/common/chrome_utility_messages.h" |
| 25 #include "chrome/common/extensions/extension.h" | 26 #include "chrome/common/extensions/extension.h" |
| 26 #include "chrome/common/extensions/extension_constants.h" | 27 #include "chrome/common/extensions/extension_constants.h" |
| 27 #include "chrome/common/extensions/extension_error_utils.h" | 28 #include "chrome/common/extensions/extension_error_utils.h" |
| 28 #include "chrome/common/extensions/extension_icon_set.h" | 29 #include "chrome/common/extensions/extension_icon_set.h" |
| 29 #include "chrome/common/extensions/url_pattern.h" | 30 #include "chrome/common/extensions/url_pattern.h" |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 52 ExtensionService* AsyncExtensionManagementFunction::service() { | 53 ExtensionService* AsyncExtensionManagementFunction::service() { |
| 53 return profile()->GetExtensionService(); | 54 return profile()->GetExtensionService(); |
| 54 } | 55 } |
| 55 | 56 |
| 56 static DictionaryValue* CreateExtensionInfo(const Extension& extension, | 57 static DictionaryValue* CreateExtensionInfo(const Extension& extension, |
| 57 ExtensionService* service) { | 58 ExtensionService* service) { |
| 58 DictionaryValue* info = new DictionaryValue(); | 59 DictionaryValue* info = new DictionaryValue(); |
| 59 bool enabled = service->IsExtensionEnabled(extension.id()); | 60 bool enabled = service->IsExtensionEnabled(extension.id()); |
| 60 extension.GetBasicInfo(enabled, info); | 61 extension.GetBasicInfo(enabled, info); |
| 61 | 62 |
| 63 info->SetBoolean(keys::kMayDisableKey, | |
|
Pam (message me for reviews)
2012/05/22 12:51:07
It's part of the ExtensionInfo returned by the API
Aaron Boodman
2012/05/22 15:56:11
No what I meant was: is there a client that needs
Pam (message me for reviews)
2012/05/23 15:00:58
Sorry, I could have been clearer. It's a documente
| |
| 64 ExtensionSystem::Get(service->profile())->management_policy() | |
| 65 ->UserMayModifyStatus(&extension, NULL)); | |
| 66 | |
| 62 info->SetBoolean(keys::kIsAppKey, extension.is_app()); | 67 info->SetBoolean(keys::kIsAppKey, extension.is_app()); |
| 63 | 68 |
| 64 if (!enabled) { | 69 if (!enabled) { |
| 65 bool permissions_escalated = service->extension_prefs()-> | 70 bool permissions_escalated = service->extension_prefs()-> |
| 66 DidExtensionEscalatePermissions(extension.id()); | 71 DidExtensionEscalatePermissions(extension.id()); |
| 67 const char* reason = permissions_escalated ? | 72 const char* reason = permissions_escalated ? |
| 68 keys::kDisabledReasonPermissionsIncrease : keys::kDisabledReasonUnknown; | 73 keys::kDisabledReasonPermissionsIncrease : keys::kDisabledReasonUnknown; |
| 69 info->SetString(keys::kDisabledReasonKey, reason); | 74 info->SetString(keys::kDisabledReasonKey, reason); |
| 70 } | 75 } |
| 71 | 76 |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 359 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id_)); | 364 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id_)); |
| 360 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &enable)); | 365 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &enable)); |
| 361 | 366 |
| 362 const Extension* extension = service()->GetExtensionById(extension_id_, true); | 367 const Extension* extension = service()->GetExtensionById(extension_id_, true); |
| 363 if (!extension) { | 368 if (!extension) { |
| 364 error_ = ExtensionErrorUtils::FormatErrorMessage( | 369 error_ = ExtensionErrorUtils::FormatErrorMessage( |
| 365 keys::kNoExtensionError, extension_id_); | 370 keys::kNoExtensionError, extension_id_); |
| 366 return false; | 371 return false; |
| 367 } | 372 } |
| 368 | 373 |
| 369 if (!Extension::UserMayDisable(extension->location())) { | 374 if (!ExtensionSystem::Get(profile())->management_policy() |
| 375 ->UserMayModifyStatus(extension, NULL)) { | |
| 370 error_ = ExtensionErrorUtils::FormatErrorMessage( | 376 error_ = ExtensionErrorUtils::FormatErrorMessage( |
| 371 keys::kUserCantDisableError, extension_id_); | 377 keys::kUserCantModifyError, extension_id_); |
|
Pam (message me for reviews)
2012/05/22 12:51:07
Excellent, I'd love to consolidate them.
| |
| 372 return false; | 378 return false; |
| 373 } | 379 } |
| 374 | 380 |
| 375 bool currently_enabled = service()->IsExtensionEnabled(extension_id_); | 381 bool currently_enabled = service()->IsExtensionEnabled(extension_id_); |
| 376 | 382 |
| 377 if (!currently_enabled && enable) { | 383 if (!currently_enabled && enable) { |
| 378 ExtensionPrefs* prefs = service()->extension_prefs(); | 384 ExtensionPrefs* prefs = service()->extension_prefs(); |
| 379 if (prefs->DidExtensionEscalatePermissions(extension_id_)) { | 385 if (prefs->DidExtensionEscalatePermissions(extension_id_)) { |
| 380 if (!user_gesture()) { | 386 if (!user_gesture()) { |
| 381 error_ = keys::kGestureNeededForEscalationError; | 387 error_ = keys::kGestureNeededForEscalationError; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 414 bool UninstallFunction::RunImpl() { | 420 bool UninstallFunction::RunImpl() { |
| 415 std::string extension_id; | 421 std::string extension_id; |
| 416 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id)); | 422 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id)); |
| 417 | 423 |
| 418 if (!service()->GetExtensionById(extension_id, true)) { | 424 if (!service()->GetExtensionById(extension_id, true)) { |
| 419 error_ = ExtensionErrorUtils::FormatErrorMessage( | 425 error_ = ExtensionErrorUtils::FormatErrorMessage( |
| 420 keys::kNoExtensionError, extension_id); | 426 keys::kNoExtensionError, extension_id); |
| 421 return false; | 427 return false; |
| 422 } | 428 } |
| 423 | 429 |
| 424 ExtensionPrefs* prefs = service()->extension_prefs(); | 430 const Extension* extension = service()->GetExtensionById(extension_id, true); |
| 425 | 431 if (!ExtensionSystem::Get(profile())->management_policy() |
| 426 if (!Extension::UserMayDisable( | 432 ->UserMayModifyStatus(extension, NULL)) { |
|
Pam (message me for reviews)
2012/05/22 12:51:07
On 2012/05/17 22:41:06, Aaron Boodman wrote:
> Wra
| |
| 427 prefs->GetInstalledExtensionInfo(extension_id)->extension_location)) { | |
| 428 error_ = ExtensionErrorUtils::FormatErrorMessage( | 433 error_ = ExtensionErrorUtils::FormatErrorMessage( |
| 429 keys::kUserCantDisableError, extension_id); | 434 keys::kUserCantModifyError, extension_id); |
| 430 return false; | 435 return false; |
| 431 } | 436 } |
| 432 | 437 |
| 433 service()->UninstallExtension(extension_id, false /* external_uninstall */, | 438 service()->UninstallExtension(extension_id, false /* external_uninstall */, |
| 434 NULL); | 439 NULL); |
| 435 return true; | 440 return true; |
| 436 } | 441 } |
| 437 | 442 |
| 438 ExtensionManagementEventRouter::ExtensionManagementEventRouter(Profile* profile) | 443 ExtensionManagementEventRouter::ExtensionManagementEventRouter(Profile* profile) |
| 439 : profile_(profile) {} | 444 : profile_(profile) {} |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 499 ExtensionService* service = profile->GetExtensionService(); | 504 ExtensionService* service = profile->GetExtensionService(); |
| 500 args.Append(CreateExtensionInfo(*extension, service)); | 505 args.Append(CreateExtensionInfo(*extension, service)); |
| 501 } | 506 } |
| 502 | 507 |
| 503 std::string args_json; | 508 std::string args_json; |
| 504 base::JSONWriter::Write(&args, &args_json); | 509 base::JSONWriter::Write(&args, &args_json); |
| 505 | 510 |
| 506 profile->GetExtensionEventRouter()->DispatchEventToRenderers( | 511 profile->GetExtensionEventRouter()->DispatchEventToRenderers( |
| 507 event_name, args_json, NULL, GURL()); | 512 event_name, args_json, NULL, GURL()); |
| 508 } | 513 } |
| OLD | NEW |