| 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/extensions/extension_uninstall_dialog.h" | 21 #include "chrome/browser/extensions/extension_uninstall_dialog.h" |
| 22 #include "chrome/browser/extensions/management_policy.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/ui/extensions/application_launch.h" | 24 #include "chrome/browser/ui/extensions/application_launch.h" |
| 23 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | 25 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
| 24 #include "chrome/common/chrome_notification_types.h" | 26 #include "chrome/common/chrome_notification_types.h" |
| 25 #include "chrome/common/chrome_utility_messages.h" | 27 #include "chrome/common/chrome_utility_messages.h" |
| 26 #include "chrome/common/extensions/extension.h" | 28 #include "chrome/common/extensions/extension.h" |
| 27 #include "chrome/common/extensions/extension_constants.h" | 29 #include "chrome/common/extensions/extension_constants.h" |
| 28 #include "chrome/common/extensions/extension_error_utils.h" | 30 #include "chrome/common/extensions/extension_error_utils.h" |
| 29 #include "chrome/common/extensions/extension_icon_set.h" | 31 #include "chrome/common/extensions/extension_icon_set.h" |
| 30 #include "chrome/common/extensions/url_pattern.h" | 32 #include "chrome/common/extensions/url_pattern.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 ExtensionService* AsyncExtensionManagementFunction::service() { | 67 ExtensionService* AsyncExtensionManagementFunction::service() { |
| 66 return profile()->GetExtensionService(); | 68 return profile()->GetExtensionService(); |
| 67 } | 69 } |
| 68 | 70 |
| 69 static DictionaryValue* CreateExtensionInfo(const Extension& extension, | 71 static DictionaryValue* CreateExtensionInfo(const Extension& extension, |
| 70 ExtensionService* service) { | 72 ExtensionService* service) { |
| 71 DictionaryValue* info = new DictionaryValue(); | 73 DictionaryValue* info = new DictionaryValue(); |
| 72 bool enabled = service->IsExtensionEnabled(extension.id()); | 74 bool enabled = service->IsExtensionEnabled(extension.id()); |
| 73 extension.GetBasicInfo(enabled, info); | 75 extension.GetBasicInfo(enabled, info); |
| 74 | 76 |
| 77 const extensions::ManagementPolicy* policy = ExtensionSystem::Get( |
| 78 service->profile())->management_policy(); |
| 79 info->SetBoolean(keys::kMayDisableKey, |
| 80 policy->UserMayModifySettings(&extension, NULL)); |
| 81 |
| 75 info->SetBoolean(keys::kIsAppKey, extension.is_app()); | 82 info->SetBoolean(keys::kIsAppKey, extension.is_app()); |
| 76 | 83 |
| 77 if (!enabled) { | 84 if (!enabled) { |
| 78 bool permissions_escalated = service->extension_prefs()-> | 85 ExtensionPrefs* prefs = service->extension_prefs(); |
| 79 DidExtensionEscalatePermissions(extension.id()); | 86 bool permissions_escalated = |
| 87 prefs->DidExtensionEscalatePermissions(extension.id()); |
| 80 const char* reason = permissions_escalated ? | 88 const char* reason = permissions_escalated ? |
| 81 keys::kDisabledReasonPermissionsIncrease : keys::kDisabledReasonUnknown; | 89 keys::kDisabledReasonPermissionsIncrease : keys::kDisabledReasonUnknown; |
| 82 info->SetString(keys::kDisabledReasonKey, reason); | 90 info->SetString(keys::kDisabledReasonKey, reason); |
| 83 } | 91 } |
| 84 | 92 |
| 85 if (!extension.update_url().is_empty()) | 93 if (!extension.update_url().is_empty()) |
| 86 info->SetString(keys::kUpdateUrlKey, | 94 info->SetString(keys::kUpdateUrlKey, |
| 87 extension.update_url().possibly_invalid_spec()); | 95 extension.update_url().possibly_invalid_spec()); |
| 88 if (extension.is_app()) | 96 if (extension.is_app()) |
| 89 info->SetString(keys::kAppLaunchUrlKey, | 97 info->SetString(keys::kAppLaunchUrlKey, |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 return true; | 184 return true; |
| 177 } | 185 } |
| 178 | 186 |
| 179 bool GetPermissionWarningsByIdFunction::RunImpl() { | 187 bool GetPermissionWarningsByIdFunction::RunImpl() { |
| 180 std::string ext_id; | 188 std::string ext_id; |
| 181 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &ext_id)); | 189 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &ext_id)); |
| 182 | 190 |
| 183 const Extension* extension = service()->GetExtensionById(ext_id, true); | 191 const Extension* extension = service()->GetExtensionById(ext_id, true); |
| 184 if (!extension) { | 192 if (!extension) { |
| 185 error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kNoExtensionError, | 193 error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kNoExtensionError, |
| 186 ext_id); | 194 ext_id); |
| 187 return false; | 195 return false; |
| 188 } | 196 } |
| 189 | 197 |
| 190 ExtensionPermissionMessages warnings = extension->GetPermissionMessages(); | 198 ExtensionPermissionMessages warnings = extension->GetPermissionMessages(); |
| 191 ListValue* result = new ListValue(); | 199 ListValue* result = new ListValue(); |
| 192 for (ExtensionPermissionMessages::const_iterator i = warnings.begin(); | 200 for (ExtensionPermissionMessages::const_iterator i = warnings.begin(); |
| 193 i < warnings.end(); ++i) | 201 i < warnings.end(); ++i) |
| 194 result->Append(Value::CreateStringValue(i->message())); | 202 result->Append(Value::CreateStringValue(i->message())); |
| 195 result_.reset(result); | 203 result_.reset(result); |
| 196 return true; | 204 return true; |
| 197 } | 205 } |
| 198 | 206 |
| 199 namespace { | 207 namespace { |
| 200 | 208 |
| 201 // This class helps GetPermissionWarningsByManifestFunction manage | 209 // This class helps GetPermissionWarningsByManifestFunction manage |
| 202 // sending manifest JSON strings to the utility process for parsing. | 210 // sending manifest JSON strings to the utility process for parsing. |
| 203 class SafeManifestJSONParser : public UtilityProcessHostClient { | 211 class SafeManifestJSONParser : public UtilityProcessHostClient { |
| 204 public: | 212 public: |
| 205 SafeManifestJSONParser(GetPermissionWarningsByManifestFunction* client, | 213 SafeManifestJSONParser(GetPermissionWarningsByManifestFunction* client, |
| 206 const std::string& manifest) | 214 const std::string& manifest) |
| 207 : client_(client), | 215 : client_(client), |
| 208 manifest_(manifest) {} | 216 manifest_(manifest) {} |
| 209 | 217 |
| 210 void Start() { | 218 void Start() { |
| 211 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 219 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 212 BrowserThread::PostTask( | 220 BrowserThread::PostTask( |
| 213 BrowserThread::IO, | 221 BrowserThread::IO, |
| 214 FROM_HERE, | 222 FROM_HERE, |
| 215 base::Bind(&SafeManifestJSONParser::StartWorkOnIOThread, this)); | 223 base::Bind(&SafeManifestJSONParser::StartWorkOnIOThread, this)); |
| 216 } | 224 } |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id_)); | 382 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id_)); |
| 375 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &enable)); | 383 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &enable)); |
| 376 | 384 |
| 377 const Extension* extension = service()->GetExtensionById(extension_id_, true); | 385 const Extension* extension = service()->GetExtensionById(extension_id_, true); |
| 378 if (!extension) { | 386 if (!extension) { |
| 379 error_ = ExtensionErrorUtils::FormatErrorMessage( | 387 error_ = ExtensionErrorUtils::FormatErrorMessage( |
| 380 keys::kNoExtensionError, extension_id_); | 388 keys::kNoExtensionError, extension_id_); |
| 381 return false; | 389 return false; |
| 382 } | 390 } |
| 383 | 391 |
| 384 if (!Extension::UserMayDisable(extension->location())) { | 392 const extensions::ManagementPolicy* policy = ExtensionSystem::Get( |
| 393 profile())->management_policy(); |
| 394 if (!policy->UserMayModifySettings(extension, NULL)) { |
| 385 error_ = ExtensionErrorUtils::FormatErrorMessage( | 395 error_ = ExtensionErrorUtils::FormatErrorMessage( |
| 386 keys::kUserCantDisableError, extension_id_); | 396 keys::kUserCantModifyError, extension_id_); |
| 387 return false; | 397 return false; |
| 388 } | 398 } |
| 389 | 399 |
| 390 bool currently_enabled = service()->IsExtensionEnabled(extension_id_); | 400 bool currently_enabled = service()->IsExtensionEnabled(extension_id_); |
| 391 | 401 |
| 392 if (!currently_enabled && enable) { | 402 if (!currently_enabled && enable) { |
| 393 ExtensionPrefs* prefs = service()->extension_prefs(); | 403 ExtensionPrefs* prefs = service()->extension_prefs(); |
| 394 if (prefs->DidExtensionEscalatePermissions(extension_id_)) { | 404 if (prefs->DidExtensionEscalatePermissions(extension_id_)) { |
| 395 if (!user_gesture()) { | 405 if (!user_gesture()) { |
| 396 error_ = keys::kGestureNeededForEscalationError; | 406 error_ = keys::kGestureNeededForEscalationError; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 } | 457 } |
| 448 } | 458 } |
| 449 | 459 |
| 450 const Extension* extension = service()->GetExtensionById(extension_id_, true); | 460 const Extension* extension = service()->GetExtensionById(extension_id_, true); |
| 451 if (!extension) { | 461 if (!extension) { |
| 452 error_ = ExtensionErrorUtils::FormatErrorMessage( | 462 error_ = ExtensionErrorUtils::FormatErrorMessage( |
| 453 keys::kNoExtensionError, extension_id_); | 463 keys::kNoExtensionError, extension_id_); |
| 454 return false; | 464 return false; |
| 455 } | 465 } |
| 456 | 466 |
| 457 ExtensionPrefs* prefs = service()->extension_prefs(); | 467 if (!ExtensionSystem::Get( |
| 458 | 468 profile())->management_policy()->UserMayModifySettings(extension, NULL)) { |
| 459 if (!Extension::UserMayDisable( | |
| 460 prefs->GetInstalledExtensionInfo(extension_id_)->extension_location)) { | |
| 461 error_ = ExtensionErrorUtils::FormatErrorMessage( | 469 error_ = ExtensionErrorUtils::FormatErrorMessage( |
| 462 keys::kUserCantDisableError, extension_id_); | 470 keys::kUserCantModifyError, extension_id_); |
| 463 return false; | 471 return false; |
| 464 } | 472 } |
| 465 | 473 |
| 466 if (auto_confirm_for_test == DO_NOT_SKIP) { | 474 if (auto_confirm_for_test == DO_NOT_SKIP) { |
| 467 if (show_confirm_dialog) { | 475 if (show_confirm_dialog) { |
| 468 AddRef(); // Balanced in ExtensionUninstallAccepted/Canceled | 476 AddRef(); // Balanced in ExtensionUninstallAccepted/Canceled |
| 469 extension_uninstall_dialog_.reset(ExtensionUninstallDialog::Create( | 477 extension_uninstall_dialog_.reset(ExtensionUninstallDialog::Create( |
| 470 profile_, this)); | 478 profile_, this)); |
| 471 extension_uninstall_dialog_->ConfirmUninstall(extension); | 479 extension_uninstall_dialog_->ConfirmUninstall(extension); |
| 472 } else { | 480 } else { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 ExtensionService* service = profile->GetExtensionService(); | 583 ExtensionService* service = profile->GetExtensionService(); |
| 576 args.Append(CreateExtensionInfo(*extension, service)); | 584 args.Append(CreateExtensionInfo(*extension, service)); |
| 577 } | 585 } |
| 578 | 586 |
| 579 std::string args_json; | 587 std::string args_json; |
| 580 base::JSONWriter::Write(&args, &args_json); | 588 base::JSONWriter::Write(&args, &args_json); |
| 581 | 589 |
| 582 profile->GetExtensionEventRouter()->DispatchEventToRenderers( | 590 profile->GetExtensionEventRouter()->DispatchEventToRenderers( |
| 583 event_name, args_json, NULL, GURL()); | 591 event_name, args_json, NULL, GURL()); |
| 584 } | 592 } |
| OLD | NEW |