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" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 ExtensionService* AsyncExtensionManagementFunction::service() { | 51 ExtensionService* AsyncExtensionManagementFunction::service() { |
| 52 return profile()->GetExtensionService(); | 52 return profile()->GetExtensionService(); |
| 53 } | 53 } |
| 54 | 54 |
| 55 static DictionaryValue* CreateExtensionInfo(const Extension& extension, | 55 static DictionaryValue* CreateExtensionInfo(const Extension& extension, |
| 56 ExtensionService* service) { | 56 ExtensionService* service) { |
| 57 DictionaryValue* info = new DictionaryValue(); | 57 DictionaryValue* info = new DictionaryValue(); |
| 58 bool enabled = service->IsExtensionEnabled(extension.id()); | 58 bool enabled = service->IsExtensionEnabled(extension.id()); |
| 59 extension.GetBasicInfo(enabled, info); | 59 extension.GetBasicInfo(enabled, info); |
| 60 | 60 |
| 61 info->SetBoolean(keys::kMayDisableKey, service-> | |
|
Aaron Boodman
2012/05/17 22:41:06
What's the need for this?
Aaron Boodman
2012/05/17 22:41:06
Wrapping: param lines should all start at same col
Pam (message me for reviews)
2012/05/18 20:15:15
It's part of the ExtensionInfo returned by the API
| |
| 62 extension_management_policy()->UserMayModifyStatus(&extension, NULL)); | |
| 63 | |
| 61 info->SetBoolean(keys::kIsAppKey, extension.is_app()); | 64 info->SetBoolean(keys::kIsAppKey, extension.is_app()); |
| 62 | 65 |
| 63 if (!enabled) { | 66 if (!enabled) { |
| 64 bool permissions_escalated = service->extension_prefs()-> | 67 bool permissions_escalated = service->extension_prefs()-> |
| 65 DidExtensionEscalatePermissions(extension.id()); | 68 DidExtensionEscalatePermissions(extension.id()); |
| 66 const char* reason = permissions_escalated ? | 69 const char* reason = permissions_escalated ? |
| 67 keys::kDisabledReasonPermissionsIncrease : keys::kDisabledReasonUnknown; | 70 keys::kDisabledReasonPermissionsIncrease : keys::kDisabledReasonUnknown; |
| 68 info->SetString(keys::kDisabledReasonKey, reason); | 71 info->SetString(keys::kDisabledReasonKey, reason); |
| 69 } | 72 } |
| 70 | 73 |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 358 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id_)); | 361 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id_)); |
| 359 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &enable)); | 362 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &enable)); |
| 360 | 363 |
| 361 const Extension* extension = service()->GetExtensionById(extension_id_, true); | 364 const Extension* extension = service()->GetExtensionById(extension_id_, true); |
| 362 if (!extension) { | 365 if (!extension) { |
| 363 error_ = ExtensionErrorUtils::FormatErrorMessage( | 366 error_ = ExtensionErrorUtils::FormatErrorMessage( |
| 364 keys::kNoExtensionError, extension_id_); | 367 keys::kNoExtensionError, extension_id_); |
| 365 return false; | 368 return false; |
| 366 } | 369 } |
| 367 | 370 |
| 368 if (!Extension::UserMayDisable(extension->location())) { | 371 if (!service()->extension_management_policy()-> |
| 369 error_ = ExtensionErrorUtils::FormatErrorMessage( | 372 UserMayModifyStatus(extension, NULL)) { |
| 370 keys::kUserCantDisableError, extension_id_); | 373 if (enable) { |
| 374 error_ = ExtensionErrorUtils::FormatErrorMessage( | |
| 375 keys::kUserCantModifyError, extension_id_); | |
|
Aaron Boodman
2012/05/17 22:41:06
Can we just have a generic kUserCantDoAnything err
Pam (message me for reviews)
2012/05/18 20:15:15
Excellent, I'd love to consolidate them.
| |
| 376 } else { | |
| 377 error_ = ExtensionErrorUtils::FormatErrorMessage( | |
| 378 keys::kUserCantDisableError, extension_id_); | |
| 379 } | |
| 371 return false; | 380 return false; |
| 372 } | 381 } |
| 373 | 382 |
| 374 bool currently_enabled = service()->IsExtensionEnabled(extension_id_); | 383 bool currently_enabled = service()->IsExtensionEnabled(extension_id_); |
| 375 | 384 |
| 376 if (!currently_enabled && enable) { | 385 if (!currently_enabled && enable) { |
| 377 ExtensionPrefs* prefs = service()->extension_prefs(); | 386 ExtensionPrefs* prefs = service()->extension_prefs(); |
| 378 if (prefs->DidExtensionEscalatePermissions(extension_id_)) { | 387 if (prefs->DidExtensionEscalatePermissions(extension_id_)) { |
| 379 if (!user_gesture()) { | 388 if (!user_gesture()) { |
| 380 error_ = keys::kGestureNeededForEscalationError; | 389 error_ = keys::kGestureNeededForEscalationError; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 413 bool UninstallFunction::RunImpl() { | 422 bool UninstallFunction::RunImpl() { |
| 414 std::string extension_id; | 423 std::string extension_id; |
| 415 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id)); | 424 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id)); |
| 416 | 425 |
| 417 if (!service()->GetExtensionById(extension_id, true)) { | 426 if (!service()->GetExtensionById(extension_id, true)) { |
| 418 error_ = ExtensionErrorUtils::FormatErrorMessage( | 427 error_ = ExtensionErrorUtils::FormatErrorMessage( |
| 419 keys::kNoExtensionError, extension_id); | 428 keys::kNoExtensionError, extension_id); |
| 420 return false; | 429 return false; |
| 421 } | 430 } |
| 422 | 431 |
| 423 ExtensionPrefs* prefs = service()->extension_prefs(); | 432 const Extension* extension = service()->GetExtensionById(extension_id, true); |
| 424 | 433 if (!service()->extension_management_policy()-> |
| 425 if (!Extension::UserMayDisable( | 434 UserMayModifyStatus(extension, NULL)) { |
|
Aaron Boodman
2012/05/17 22:41:06
Wrap at open paren. You should also change extensi
| |
| 426 prefs->GetInstalledExtensionInfo(extension_id)->extension_location)) { | |
| 427 error_ = ExtensionErrorUtils::FormatErrorMessage( | 435 error_ = ExtensionErrorUtils::FormatErrorMessage( |
| 428 keys::kUserCantDisableError, extension_id); | 436 keys::kUserCantDisableError, extension_id); |
| 429 return false; | 437 return false; |
| 430 } | 438 } |
| 431 | 439 |
| 432 service()->UninstallExtension(extension_id, false /* external_uninstall */, | 440 service()->UninstallExtension(extension_id, false /* external_uninstall */, |
| 433 NULL); | 441 NULL); |
| 434 return true; | 442 return true; |
| 435 } | 443 } |
| 436 | 444 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 497 ExtensionService* service = profile->GetExtensionService(); | 505 ExtensionService* service = profile->GetExtensionService(); |
| 498 args.Append(CreateExtensionInfo(*extension, service)); | 506 args.Append(CreateExtensionInfo(*extension, service)); |
| 499 } | 507 } |
| 500 | 508 |
| 501 std::string args_json; | 509 std::string args_json; |
| 502 base::JSONWriter::Write(&args, &args_json); | 510 base::JSONWriter::Write(&args, &args_json); |
| 503 | 511 |
| 504 profile->GetExtensionEventRouter()->DispatchEventToRenderers( | 512 profile->GetExtensionEventRouter()->DispatchEventToRenderers( |
| 505 event_name, args_json, NULL, GURL()); | 513 event_name, args_json, NULL, GURL()); |
| 506 } | 514 } |
| OLD | NEW |