| 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_menu_manager.h" | 12 #include "chrome/browser/extensions/extension_menu_manager.h" |
| 13 #include "chrome/browser/extensions/extension_pref_store.h" | 13 #include "chrome/browser/extensions/extension_pref_store.h" |
| 14 #include "chrome/browser/extensions/extension_sorting.h" | 14 #include "chrome/browser/extensions/extension_sorting.h" |
| 15 #include "chrome/browser/prefs/pref_notifier.h" | 15 #include "chrome/browser/prefs/pref_notifier.h" |
| 16 #include "chrome/browser/prefs/pref_service.h" | 16 #include "chrome/browser/prefs/pref_service.h" |
| 17 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 17 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 18 #include "chrome/common/chrome_notification_types.h" | 18 #include "chrome/common/chrome_notification_types.h" |
| 19 #include "chrome/common/extensions/extension_switch_utils.h" | 19 #include "chrome/common/extensions/extension_switch_utils.h" |
| 20 #include "chrome/common/extensions/manifest.h" | 20 #include "chrome/common/extensions/manifest.h" |
| 21 #include "chrome/common/extensions/url_pattern.h" | 21 #include "chrome/common/extensions/url_pattern.h" |
| 22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 23 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
| 24 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
| 25 #include "grit/generated_resources.h" |
| 26 #include "ui/base/l10n/l10n_util.h" |
| 25 | 27 |
| 26 using extensions::Extension; | 28 using extensions::Extension; |
| 27 using extensions::ExtensionInfo; | 29 using extensions::ExtensionInfo; |
| 28 | 30 |
| 29 namespace { | 31 namespace { |
| 30 | 32 |
| 31 // Additional preferences keys | 33 // Additional preferences keys |
| 32 | 34 |
| 33 // Where an extension was installed from. (see Extension::Location) | 35 // Where an extension was installed from. (see Extension::Location) |
| 34 const char kPrefLocation[] = "location"; | 36 const char kPrefLocation[] = "location"; |
| (...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 ListValue* scope_values = new ListValue(); | 544 ListValue* scope_values = new ListValue(); |
| 543 for (ExtensionOAuth2Scopes::iterator i = scopes.begin(); | 545 for (ExtensionOAuth2Scopes::iterator i = scopes.begin(); |
| 544 i != scopes.end(); ++i) { | 546 i != scopes.end(); ++i) { |
| 545 scope_values->Append(Value::CreateStringValue(*i)); | 547 scope_values->Append(Value::CreateStringValue(*i)); |
| 546 } | 548 } |
| 547 std::string scope_pref = JoinPrefs(pref_key, kPrefScopes); | 549 std::string scope_pref = JoinPrefs(pref_key, kPrefScopes); |
| 548 UpdateExtensionPref(extension_id, scope_pref, scope_values); | 550 UpdateExtensionPref(extension_id, scope_pref, scope_values); |
| 549 } | 551 } |
| 550 } | 552 } |
| 551 | 553 |
| 554 bool ExtensionPrefs::ManagementPolicyImpl(const Extension* extension, |
| 555 string16* error, |
| 556 bool modifiable_value) const { |
| 557 // An extension that is required (by admin policy, for example) cannot be |
| 558 // modified. |
| 559 bool modifiable = !Extension::IsRequired(extension->location()); |
| 560 // Some callers equate "no restriction" to true, others to false. |
| 561 if (modifiable) |
| 562 return modifiable_value; |
| 563 |
| 564 if (error) { |
| 565 *error = l10n_util::GetStringFUTF16( |
| 566 IDS_EXTENSION_CANT_MODIFY_POLICY_REQUIRED, |
| 567 UTF8ToUTF16(extension->name())); |
| 568 } |
| 569 return !modifiable_value; |
| 570 } |
| 571 |
| 552 // static | 572 // static |
| 553 bool ExtensionPrefs::IsBlacklistBitSet(DictionaryValue* ext) { | 573 bool ExtensionPrefs::IsBlacklistBitSet(DictionaryValue* ext) { |
| 554 return ReadBooleanFromPref(ext, kPrefBlacklist); | 574 return ReadBooleanFromPref(ext, kPrefBlacklist); |
| 555 } | 575 } |
| 556 | 576 |
| 557 bool ExtensionPrefs::IsExtensionBlacklisted(const std::string& extension_id) { | 577 bool ExtensionPrefs::IsExtensionBlacklisted(const std::string& extension_id) { |
| 558 return ReadExtensionPrefBoolean(extension_id, kPrefBlacklist); | 578 return ReadExtensionPrefBoolean(extension_id, kPrefBlacklist); |
| 559 } | 579 } |
| 560 | 580 |
| 561 bool ExtensionPrefs::IsExtensionOrphaned(const std::string& extension_id) { | 581 bool ExtensionPrefs::IsExtensionOrphaned(const std::string& extension_id) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 return ReadExtensionPrefBoolean(extension_id, kPrefAppNotificationDisbaled); | 653 return ReadExtensionPrefBoolean(extension_id, kPrefAppNotificationDisbaled); |
| 634 } | 654 } |
| 635 | 655 |
| 636 void ExtensionPrefs::SetAppNotificationDisabled( | 656 void ExtensionPrefs::SetAppNotificationDisabled( |
| 637 const std::string& extension_id, bool value) { | 657 const std::string& extension_id, bool value) { |
| 638 DCHECK(Extension::IdIsValid(extension_id)); | 658 DCHECK(Extension::IdIsValid(extension_id)); |
| 639 UpdateExtensionPref(extension_id, kPrefAppNotificationDisbaled, | 659 UpdateExtensionPref(extension_id, kPrefAppNotificationDisbaled, |
| 640 Value::CreateBooleanValue(value)); | 660 Value::CreateBooleanValue(value)); |
| 641 } | 661 } |
| 642 | 662 |
| 643 bool ExtensionPrefs::IsExtensionAllowedByPolicy( | 663 std::string ExtensionPrefs::GetPolicyProviderName() const { |
| 644 const std::string& extension_id, | 664 return "admin policy black/whitelist, via the ExtensionPrefs"; |
| 645 Extension::Location location) const { | 665 } |
| 646 base::StringValue id_value(extension_id); | |
| 647 | 666 |
| 648 if (location == Extension::COMPONENT || | 667 bool ExtensionPrefs::UserMayLoad(const extensions::Extension* extension, |
| 649 location == Extension::EXTERNAL_POLICY_DOWNLOAD) { | 668 string16* error) const { |
| 669 base::StringValue id_value(extension->id()); |
| 670 |
| 671 if (extensions::Extension::IsRequired(extension->location())) |
| 650 return true; | 672 return true; |
| 651 } | |
| 652 | 673 |
| 653 const base::ListValue* blacklist = | 674 const base::ListValue* blacklist = |
| 654 prefs_->GetList(prefs::kExtensionInstallDenyList); | 675 prefs_->GetList(prefs::kExtensionInstallDenyList); |
| 655 if (!blacklist || blacklist->empty()) | 676 if (!blacklist || blacklist->empty()) |
| 656 return true; | 677 return true; |
| 657 | 678 |
| 658 // Check the whitelist first. | 679 // Check the whitelist first. |
| 659 const base::ListValue* whitelist = | 680 const base::ListValue* whitelist = |
| 660 prefs_->GetList(prefs::kExtensionInstallAllowList); | 681 prefs_->GetList(prefs::kExtensionInstallAllowList); |
| 661 if (whitelist && whitelist->Find(id_value) != whitelist->end()) | 682 if (whitelist && whitelist->Find(id_value) != whitelist->end()) |
| 662 return true; | 683 return true; |
| 663 | 684 |
| 664 // Then check the blacklist (the admin blacklist, not the Google blacklist). | 685 // Then check the blacklist (the admin blacklist, not the Google blacklist). |
| 665 return blacklist->Find(id_value) == blacklist->end() && | 686 bool result = blacklist->Find(id_value) == blacklist->end() && |
| 666 !ExtensionsBlacklistedByDefault(); | 687 !ExtensionsBlacklistedByDefault(); |
| 688 if (error && !result) { |
| 689 *error = l10n_util::GetStringFUTF16( |
| 690 IDS_EXTENSION_CANT_INSTALL_POLICY_BLACKLIST, |
| 691 UTF8ToUTF16(extension->name()), |
| 692 UTF8ToUTF16(extension->id())); |
| 693 } |
| 694 return result; |
| 695 } |
| 696 |
| 697 bool ExtensionPrefs::UserMayModifySettings(const Extension* extension, |
| 698 string16* error) const { |
| 699 return ManagementPolicyImpl(extension, error, true); |
| 700 } |
| 701 |
| 702 bool ExtensionPrefs::MustRemainEnabled(const Extension* extension, |
| 703 string16* error) const { |
| 704 return ManagementPolicyImpl(extension, error, false); |
| 667 } | 705 } |
| 668 | 706 |
| 669 bool ExtensionPrefs::ExtensionsBlacklistedByDefault() const { | 707 bool ExtensionPrefs::ExtensionsBlacklistedByDefault() const { |
| 670 const base::ListValue* blacklist = | 708 const base::ListValue* blacklist = |
| 671 prefs_->GetList(prefs::kExtensionInstallDenyList); | 709 prefs_->GetList(prefs::kExtensionInstallDenyList); |
| 672 base::StringValue wildcard("*"); | 710 base::StringValue wildcard("*"); |
| 673 return blacklist && blacklist->Find(wildcard) != blacklist->end(); | 711 return blacklist && blacklist->Find(wildcard) != blacklist->end(); |
| 674 } | 712 } |
| 675 | 713 |
| 676 bool ExtensionPrefs::DidExtensionEscalatePermissions( | 714 bool ExtensionPrefs::DidExtensionEscalatePermissions( |
| (...skipping 1248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1925 prefs->RegisterStringPref(prefs::kExtensionBlacklistUpdateVersion, | 1963 prefs->RegisterStringPref(prefs::kExtensionBlacklistUpdateVersion, |
| 1926 "0", // default value | 1964 "0", // default value |
| 1927 PrefService::UNSYNCABLE_PREF); | 1965 PrefService::UNSYNCABLE_PREF); |
| 1928 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, | 1966 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, |
| 1929 0, // default value | 1967 0, // default value |
| 1930 PrefService::UNSYNCABLE_PREF); | 1968 PrefService::UNSYNCABLE_PREF); |
| 1931 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, | 1969 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, |
| 1932 0, // default value | 1970 0, // default value |
| 1933 PrefService::UNSYNCABLE_PREF); | 1971 PrefService::UNSYNCABLE_PREF); |
| 1934 } | 1972 } |
| OLD | NEW |