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/manifest.h" | 18 #include "chrome/common/extensions/manifest.h" |
| 19 #include "chrome/common/extensions/url_pattern.h" | 19 #include "chrome/common/extensions/url_pattern.h" |
| 20 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 21 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
| 22 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
| 23 #include "grit/generated_resources.h" | |
| 24 #include "ui/base/l10n/l10n_util.h" | |
| 23 | 25 |
| 24 namespace { | 26 namespace { |
| 25 | 27 |
| 26 // Additional preferences keys | 28 // Additional preferences keys |
| 27 | 29 |
| 28 // Where an extension was installed from. (see Extension::Location) | 30 // Where an extension was installed from. (see Extension::Location) |
| 29 const char kPrefLocation[] = "location"; | 31 const char kPrefLocation[] = "location"; |
| 30 | 32 |
| 31 // Enabled, disabled, killed, etc. (see Extension::State) | 33 // Enabled, disabled, killed, etc. (see Extension::State) |
| 32 const char kPrefState[] = "state"; | 34 const char kPrefState[] = "state"; |
| (...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 644 return ReadExtensionPrefBoolean(extension_id, kPrefAppNotificationDisbaled); | 646 return ReadExtensionPrefBoolean(extension_id, kPrefAppNotificationDisbaled); |
| 645 } | 647 } |
| 646 | 648 |
| 647 void ExtensionPrefs::SetAppNotificationDisabled( | 649 void ExtensionPrefs::SetAppNotificationDisabled( |
| 648 const std::string& extension_id, bool value) { | 650 const std::string& extension_id, bool value) { |
| 649 DCHECK(Extension::IdIsValid(extension_id)); | 651 DCHECK(Extension::IdIsValid(extension_id)); |
| 650 UpdateExtensionPref(extension_id, kPrefAppNotificationDisbaled, | 652 UpdateExtensionPref(extension_id, kPrefAppNotificationDisbaled, |
| 651 Value::CreateBooleanValue(value)); | 653 Value::CreateBooleanValue(value)); |
| 652 } | 654 } |
| 653 | 655 |
| 654 bool ExtensionPrefs::IsExtensionAllowedByPolicy( | 656 bool ExtensionPrefs::UserMayInstall(const std::string& extension_id, |
| 655 const std::string& extension_id, | 657 Extension::Location location, |
| 656 Extension::Location location) const { | 658 const std::string& extension_name, |
| 659 string16* error) const { | |
| 657 base::StringValue id_value(extension_id); | 660 base::StringValue id_value(extension_id); |
| 658 | 661 |
| 659 if (location == Extension::COMPONENT || | 662 if (Extension::IsRequired(location)) |
|
Aaron Boodman
2012/05/17 22:41:06
I don't see any Extension::IsRequired. What's this
Pam (message me for reviews)
2012/05/18 20:15:15
It's a rename (and direction flip) of Extension::U
| |
| 660 location == Extension::EXTERNAL_POLICY_DOWNLOAD) { | |
| 661 return true; | 663 return true; |
| 662 } | |
| 663 | 664 |
| 664 const base::ListValue* blacklist = | 665 const base::ListValue* blacklist = |
| 665 prefs_->GetList(prefs::kExtensionInstallDenyList); | 666 prefs_->GetList(prefs::kExtensionInstallDenyList); |
| 666 if (!blacklist || blacklist->empty()) | 667 if (!blacklist || blacklist->empty()) |
| 667 return true; | 668 return true; |
| 668 | 669 |
| 669 // Check the whitelist first. | 670 // Check the whitelist first. |
| 670 const base::ListValue* whitelist = | 671 const base::ListValue* whitelist = |
| 671 prefs_->GetList(prefs::kExtensionInstallAllowList); | 672 prefs_->GetList(prefs::kExtensionInstallAllowList); |
| 672 if (whitelist && whitelist->Find(id_value) != whitelist->end()) | 673 if (whitelist && whitelist->Find(id_value) != whitelist->end()) |
| 673 return true; | 674 return true; |
| 674 | 675 |
| 675 // Then check the blacklist (the admin blacklist, not the Google blacklist). | 676 // Then check the blacklist (the admin blacklist, not the Google blacklist). |
| 676 return blacklist->Find(id_value) == blacklist->end() && | 677 bool result = blacklist->Find(id_value) == blacklist->end() && |
| 677 !ExtensionsBlacklistedByDefault(); | 678 !ExtensionsBlacklistedByDefault(); |
| 679 if (error && !result) { | |
| 680 *error = l10n_util::GetStringFUTF16( | |
| 681 IDS_EXTENSION_CANT_INSTALL_POLICY_BLACKLIST, | |
| 682 UTF8ToUTF16(extension_name), | |
| 683 UTF8ToUTF16(extension_id)); | |
| 684 } | |
| 685 return result; | |
| 678 } | 686 } |
| 679 | 687 |
| 680 bool ExtensionPrefs::ExtensionsBlacklistedByDefault() const { | 688 bool ExtensionPrefs::ExtensionsBlacklistedByDefault() const { |
| 681 const base::ListValue* blacklist = | 689 const base::ListValue* blacklist = |
| 682 prefs_->GetList(prefs::kExtensionInstallDenyList); | 690 prefs_->GetList(prefs::kExtensionInstallDenyList); |
| 683 base::StringValue wildcard("*"); | 691 base::StringValue wildcard("*"); |
| 684 return blacklist && blacklist->Find(wildcard) != blacklist->end(); | 692 return blacklist && blacklist->Find(wildcard) != blacklist->end(); |
| 685 } | 693 } |
| 686 | 694 |
| 687 bool ExtensionPrefs::DidExtensionEscalatePermissions( | 695 bool ExtensionPrefs::DidExtensionEscalatePermissions( |
| (...skipping 1206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1894 prefs->RegisterStringPref(prefs::kExtensionBlacklistUpdateVersion, | 1902 prefs->RegisterStringPref(prefs::kExtensionBlacklistUpdateVersion, |
| 1895 "0", // default value | 1903 "0", // default value |
| 1896 PrefService::UNSYNCABLE_PREF); | 1904 PrefService::UNSYNCABLE_PREF); |
| 1897 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, | 1905 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, |
| 1898 0, // default value | 1906 0, // default value |
| 1899 PrefService::UNSYNCABLE_PREF); | 1907 PrefService::UNSYNCABLE_PREF); |
| 1900 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, | 1908 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, |
| 1901 0, // default value | 1909 0, // default value |
| 1902 PrefService::UNSYNCABLE_PREF); | 1910 PrefService::UNSYNCABLE_PREF); |
| 1903 } | 1911 } |
| OLD | NEW |