| 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_prefs.h" | 5 #include "chrome/browser/extensions/extension_prefs.h" |
| 6 | 6 |
| 7 #include "base/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/extensions/api/alarms/alarm_manager.h" | 10 #include "chrome/browser/extensions/api/alarms/alarm_manager.h" |
| 11 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" | 11 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" |
| 12 #include "chrome/browser/extensions/extension_pref_store.h" | 12 #include "chrome/browser/extensions/extension_pref_store.h" |
| 13 #include "chrome/browser/extensions/extension_sorting.h" | 13 #include "chrome/browser/extensions/extension_sorting.h" |
| 14 #include "chrome/browser/prefs/pref_notifier.h" | 14 #include "chrome/browser/prefs/pref_notifier.h" |
| 15 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
| 16 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 16 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 17 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
| 18 #include "chrome/common/extensions/extension_switch_utils.h" | 18 #include "chrome/common/extensions/extension_switch_utils.h" |
| 19 #include "chrome/common/extensions/manifest.h" | 19 #include "chrome/common/extensions/manifest.h" |
| 20 #include "chrome/common/extensions/url_pattern.h" | 20 #include "chrome/common/extensions/url_pattern.h" |
| 21 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
| 22 #include "chrome/common/url_constants.h" | 22 #include "chrome/common/url_constants.h" |
| 23 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
| 24 #include "grit/generated_resources.h" |
| 25 #include "ui/base/l10n/l10n_util.h" |
| 24 | 26 |
| 25 using extensions::Extension; | 27 using extensions::Extension; |
| 26 using extensions::ExtensionInfo; | 28 using extensions::ExtensionInfo; |
| 27 | 29 |
| 28 namespace { | 30 namespace { |
| 29 | 31 |
| 30 // Additional preferences keys | 32 // Additional preferences keys |
| 31 | 33 |
| 32 // Where an extension was installed from. (see Extension::Location) | 34 // Where an extension was installed from. (see Extension::Location) |
| 33 const char kPrefLocation[] = "location"; | 35 const char kPrefLocation[] = "location"; |
| (...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 ListValue* scope_values = new ListValue(); | 563 ListValue* scope_values = new ListValue(); |
| 562 for (ExtensionOAuth2Scopes::iterator i = scopes.begin(); | 564 for (ExtensionOAuth2Scopes::iterator i = scopes.begin(); |
| 563 i != scopes.end(); ++i) { | 565 i != scopes.end(); ++i) { |
| 564 scope_values->Append(Value::CreateStringValue(*i)); | 566 scope_values->Append(Value::CreateStringValue(*i)); |
| 565 } | 567 } |
| 566 std::string scope_pref = JoinPrefs(pref_key, kPrefScopes); | 568 std::string scope_pref = JoinPrefs(pref_key, kPrefScopes); |
| 567 UpdateExtensionPref(extension_id, scope_pref, scope_values); | 569 UpdateExtensionPref(extension_id, scope_pref, scope_values); |
| 568 } | 570 } |
| 569 } | 571 } |
| 570 | 572 |
| 573 bool ExtensionPrefs::ManagementPolicyImpl(const Extension* extension, |
| 574 string16* error, |
| 575 bool modifiable_value) const { |
| 576 // An extension that is required (by admin policy, for example) cannot be |
| 577 // modified. |
| 578 bool modifiable = !Extension::IsRequired(extension->location()); |
| 579 // Some callers equate "no restriction" to true, others to false. |
| 580 if (modifiable) |
| 581 return modifiable_value; |
| 582 |
| 583 if (error) { |
| 584 *error = l10n_util::GetStringFUTF16( |
| 585 IDS_EXTENSION_CANT_MODIFY_POLICY_REQUIRED, |
| 586 UTF8ToUTF16(extension->name())); |
| 587 } |
| 588 return !modifiable_value; |
| 589 } |
| 590 |
| 571 // static | 591 // static |
| 572 bool ExtensionPrefs::IsBlacklistBitSet(DictionaryValue* ext) { | 592 bool ExtensionPrefs::IsBlacklistBitSet(DictionaryValue* ext) { |
| 573 return ReadBooleanFromPref(ext, kPrefBlacklist); | 593 return ReadBooleanFromPref(ext, kPrefBlacklist); |
| 574 } | 594 } |
| 575 | 595 |
| 576 bool ExtensionPrefs::IsExtensionBlacklisted(const std::string& extension_id) { | 596 bool ExtensionPrefs::IsExtensionBlacklisted(const std::string& extension_id) { |
| 577 return ReadExtensionPrefBoolean(extension_id, kPrefBlacklist); | 597 return ReadExtensionPrefBoolean(extension_id, kPrefBlacklist); |
| 578 } | 598 } |
| 579 | 599 |
| 580 bool ExtensionPrefs::IsExtensionOrphaned(const std::string& extension_id) { | 600 bool ExtensionPrefs::IsExtensionOrphaned(const std::string& extension_id) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 return ReadExtensionPrefBoolean(extension_id, kPrefAppNotificationDisbaled); | 672 return ReadExtensionPrefBoolean(extension_id, kPrefAppNotificationDisbaled); |
| 653 } | 673 } |
| 654 | 674 |
| 655 void ExtensionPrefs::SetAppNotificationDisabled( | 675 void ExtensionPrefs::SetAppNotificationDisabled( |
| 656 const std::string& extension_id, bool value) { | 676 const std::string& extension_id, bool value) { |
| 657 DCHECK(Extension::IdIsValid(extension_id)); | 677 DCHECK(Extension::IdIsValid(extension_id)); |
| 658 UpdateExtensionPref(extension_id, kPrefAppNotificationDisbaled, | 678 UpdateExtensionPref(extension_id, kPrefAppNotificationDisbaled, |
| 659 Value::CreateBooleanValue(value)); | 679 Value::CreateBooleanValue(value)); |
| 660 } | 680 } |
| 661 | 681 |
| 662 bool ExtensionPrefs::IsExtensionAllowedByPolicy( | 682 std::string ExtensionPrefs::GetPolicyProviderName() const { |
| 663 const std::string& extension_id, | 683 return "admin policy black/whitelist, via the ExtensionPrefs"; |
| 664 Extension::Location location) const { | 684 } |
| 665 base::StringValue id_value(extension_id); | |
| 666 | 685 |
| 667 if (location == Extension::COMPONENT || | 686 bool ExtensionPrefs::UserMayLoad(const extensions::Extension* extension, |
| 668 location == Extension::EXTERNAL_POLICY_DOWNLOAD) { | 687 string16* error) const { |
| 688 base::StringValue id_value(extension->id()); |
| 689 |
| 690 if (extensions::Extension::IsRequired(extension->location())) |
| 669 return true; | 691 return true; |
| 670 } | |
| 671 | 692 |
| 672 const base::ListValue* blacklist = | 693 const base::ListValue* blacklist = |
| 673 prefs_->GetList(prefs::kExtensionInstallDenyList); | 694 prefs_->GetList(prefs::kExtensionInstallDenyList); |
| 674 if (!blacklist || blacklist->empty()) | 695 if (!blacklist || blacklist->empty()) |
| 675 return true; | 696 return true; |
| 676 | 697 |
| 677 // Check the whitelist first. | 698 // Check the whitelist first. |
| 678 const base::ListValue* whitelist = | 699 const base::ListValue* whitelist = |
| 679 prefs_->GetList(prefs::kExtensionInstallAllowList); | 700 prefs_->GetList(prefs::kExtensionInstallAllowList); |
| 680 if (whitelist && whitelist->Find(id_value) != whitelist->end()) | 701 if (whitelist && whitelist->Find(id_value) != whitelist->end()) |
| 681 return true; | 702 return true; |
| 682 | 703 |
| 683 // Then check the blacklist (the admin blacklist, not the Google blacklist). | 704 // Then check the blacklist (the admin blacklist, not the Google blacklist). |
| 684 return blacklist->Find(id_value) == blacklist->end() && | 705 bool result = blacklist->Find(id_value) == blacklist->end() && |
| 685 !ExtensionsBlacklistedByDefault(); | 706 !ExtensionsBlacklistedByDefault(); |
| 707 if (error && !result) { |
| 708 *error = l10n_util::GetStringFUTF16( |
| 709 IDS_EXTENSION_CANT_INSTALL_POLICY_BLACKLIST, |
| 710 UTF8ToUTF16(extension->name()), |
| 711 UTF8ToUTF16(extension->id())); |
| 712 } |
| 713 return result; |
| 714 } |
| 715 |
| 716 bool ExtensionPrefs::UserMayModifySettings(const Extension* extension, |
| 717 string16* error) const { |
| 718 return ManagementPolicyImpl(extension, error, true); |
| 719 } |
| 720 |
| 721 bool ExtensionPrefs::MustRemainEnabled(const Extension* extension, |
| 722 string16* error) const { |
| 723 return ManagementPolicyImpl(extension, error, false); |
| 686 } | 724 } |
| 687 | 725 |
| 688 bool ExtensionPrefs::ExtensionsBlacklistedByDefault() const { | 726 bool ExtensionPrefs::ExtensionsBlacklistedByDefault() const { |
| 689 const base::ListValue* blacklist = | 727 const base::ListValue* blacklist = |
| 690 prefs_->GetList(prefs::kExtensionInstallDenyList); | 728 prefs_->GetList(prefs::kExtensionInstallDenyList); |
| 691 base::StringValue wildcard("*"); | 729 base::StringValue wildcard("*"); |
| 692 return blacklist && blacklist->Find(wildcard) != blacklist->end(); | 730 return blacklist && blacklist->Find(wildcard) != blacklist->end(); |
| 693 } | 731 } |
| 694 | 732 |
| 695 bool ExtensionPrefs::DidExtensionEscalatePermissions( | 733 bool ExtensionPrefs::DidExtensionEscalatePermissions( |
| (...skipping 1216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1912 prefs->RegisterStringPref(prefs::kExtensionBlacklistUpdateVersion, | 1950 prefs->RegisterStringPref(prefs::kExtensionBlacklistUpdateVersion, |
| 1913 "0", // default value | 1951 "0", // default value |
| 1914 PrefService::UNSYNCABLE_PREF); | 1952 PrefService::UNSYNCABLE_PREF); |
| 1915 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, | 1953 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, |
| 1916 0, // default value | 1954 0, // default value |
| 1917 PrefService::UNSYNCABLE_PREF); | 1955 PrefService::UNSYNCABLE_PREF); |
| 1918 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, | 1956 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, |
| 1919 0, // default value | 1957 0, // default value |
| 1920 PrefService::UNSYNCABLE_PREF); | 1958 PrefService::UNSYNCABLE_PREF); |
| 1921 } | 1959 } |
| OLD | NEW |