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_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 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 652 return ReadExtensionPrefBoolean(extension_id, kPrefAppNotificationDisbaled); | 654 return ReadExtensionPrefBoolean(extension_id, kPrefAppNotificationDisbaled); |
| 653 } | 655 } |
| 654 | 656 |
| 655 void ExtensionPrefs::SetAppNotificationDisabled( | 657 void ExtensionPrefs::SetAppNotificationDisabled( |
| 656 const std::string& extension_id, bool value) { | 658 const std::string& extension_id, bool value) { |
| 657 DCHECK(Extension::IdIsValid(extension_id)); | 659 DCHECK(Extension::IdIsValid(extension_id)); |
| 658 UpdateExtensionPref(extension_id, kPrefAppNotificationDisbaled, | 660 UpdateExtensionPref(extension_id, kPrefAppNotificationDisbaled, |
| 659 Value::CreateBooleanValue(value)); | 661 Value::CreateBooleanValue(value)); |
| 660 } | 662 } |
| 661 | 663 |
| 662 bool ExtensionPrefs::IsExtensionAllowedByPolicy( | 664 std::string ExtensionPrefs::PolicyProviderName() const { |
|
Aaron Boodman
2012/05/22 15:56:11
Methods should typically be verb phrases, so GetPo
| |
| 663 const std::string& extension_id, | 665 return "admin policy black/whitelist, via the ExtensionPrefs"; |
| 664 Extension::Location location) const { | 666 } |
| 665 base::StringValue id_value(extension_id); | |
| 666 | 667 |
| 667 if (location == Extension::COMPONENT || | 668 bool ExtensionPrefs::UserMayLoad(const extensions::Extension* extension, |
| 668 location == Extension::EXTERNAL_POLICY_DOWNLOAD) { | 669 extensions::Extension::Location location, |
| 670 string16* error) const { | |
| 671 base::StringValue id_value(extension->id()); | |
| 672 | |
| 673 if (extensions::Extension::IsRequired(location)) | |
|
Pam (message me for reviews)
2012/05/22 12:51:07
It's a rename (and direction flip) of Extension::U
Aaron Boodman
2012/05/22 15:56:11
Ah. Can that bit be moved into extensions::Managem
Pam (message me for reviews)
2012/05/23 15:00:58
On 2012/05/22 15:56:11, Aaron Boodman wrote:
Can
Aaron Boodman
2012/05/24 08:11:23
OK, I see.
| |
| 669 return true; | 674 return true; |
| 670 } | |
| 671 | 675 |
| 672 const base::ListValue* blacklist = | 676 const base::ListValue* blacklist = |
| 673 prefs_->GetList(prefs::kExtensionInstallDenyList); | 677 prefs_->GetList(prefs::kExtensionInstallDenyList); |
| 674 if (!blacklist || blacklist->empty()) | 678 if (!blacklist || blacklist->empty()) |
| 675 return true; | 679 return true; |
| 676 | 680 |
| 677 // Check the whitelist first. | 681 // Check the whitelist first. |
| 678 const base::ListValue* whitelist = | 682 const base::ListValue* whitelist = |
| 679 prefs_->GetList(prefs::kExtensionInstallAllowList); | 683 prefs_->GetList(prefs::kExtensionInstallAllowList); |
| 680 if (whitelist && whitelist->Find(id_value) != whitelist->end()) | 684 if (whitelist && whitelist->Find(id_value) != whitelist->end()) |
| 681 return true; | 685 return true; |
| 682 | 686 |
| 683 // Then check the blacklist (the admin blacklist, not the Google blacklist). | 687 // Then check the blacklist (the admin blacklist, not the Google blacklist). |
| 684 return blacklist->Find(id_value) == blacklist->end() && | 688 bool result = blacklist->Find(id_value) == blacklist->end() && |
| 685 !ExtensionsBlacklistedByDefault(); | 689 !ExtensionsBlacklistedByDefault(); |
| 690 if (error && !result) { | |
| 691 *error = l10n_util::GetStringFUTF16( | |
| 692 IDS_EXTENSION_CANT_INSTALL_POLICY_BLACKLIST, | |
| 693 UTF8ToUTF16(extension->name()), | |
| 694 UTF8ToUTF16(extension->id())); | |
| 695 } | |
| 696 return result; | |
| 686 } | 697 } |
| 687 | 698 |
| 688 bool ExtensionPrefs::ExtensionsBlacklistedByDefault() const { | 699 bool ExtensionPrefs::ExtensionsBlacklistedByDefault() const { |
| 689 const base::ListValue* blacklist = | 700 const base::ListValue* blacklist = |
| 690 prefs_->GetList(prefs::kExtensionInstallDenyList); | 701 prefs_->GetList(prefs::kExtensionInstallDenyList); |
| 691 base::StringValue wildcard("*"); | 702 base::StringValue wildcard("*"); |
| 692 return blacklist && blacklist->Find(wildcard) != blacklist->end(); | 703 return blacklist && blacklist->Find(wildcard) != blacklist->end(); |
| 693 } | 704 } |
| 694 | 705 |
| 695 bool ExtensionPrefs::DidExtensionEscalatePermissions( | 706 bool ExtensionPrefs::DidExtensionEscalatePermissions( |
| (...skipping 1216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1912 prefs->RegisterStringPref(prefs::kExtensionBlacklistUpdateVersion, | 1923 prefs->RegisterStringPref(prefs::kExtensionBlacklistUpdateVersion, |
| 1913 "0", // default value | 1924 "0", // default value |
| 1914 PrefService::UNSYNCABLE_PREF); | 1925 PrefService::UNSYNCABLE_PREF); |
| 1915 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, | 1926 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, |
| 1916 0, // default value | 1927 0, // default value |
| 1917 PrefService::UNSYNCABLE_PREF); | 1928 PrefService::UNSYNCABLE_PREF); |
| 1918 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, | 1929 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, |
| 1919 0, // default value | 1930 0, // default value |
| 1920 PrefService::UNSYNCABLE_PREF); | 1931 PrefService::UNSYNCABLE_PREF); |
| 1921 } | 1932 } |
| OLD | NEW |