Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(560)

Side by Side Diff: chrome/browser/extensions/extension_prefs.cc

Issue 10689097: Enforce the 'requirements' field in manifests. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/admin_policy.h" 10 #include "chrome/browser/extensions/admin_policy.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 const char kPrefAppNotificationDisbaled[] = "app_notif_disabled"; 56 const char kPrefAppNotificationDisbaled[] = "app_notif_disabled";
57 57
58 // Indicates whether the user has acknowledged various types of extensions. 58 // Indicates whether the user has acknowledged various types of extensions.
59 const char kPrefExternalAcknowledged[] = "ack_external"; 59 const char kPrefExternalAcknowledged[] = "ack_external";
60 const char kPrefBlacklistAcknowledged[] = "ack_blacklist"; 60 const char kPrefBlacklistAcknowledged[] = "ack_blacklist";
61 const char kPrefOrphanAcknowledged[] = "ack_orphan"; 61 const char kPrefOrphanAcknowledged[] = "ack_orphan";
62 62
63 // Indicates whether to show an install warning when the user enables. 63 // Indicates whether to show an install warning when the user enables.
64 const char kExtensionDidEscalatePermissions[] = "install_warning_on_enable"; 64 const char kExtensionDidEscalatePermissions[] = "install_warning_on_enable";
65 65
66 // Any errors that arose from unmet unmet requirements.
Aaron Boodman 2012/08/01 03:58:54 duplicate 'unmet'
eaugusti 2012/08/03 01:06:26 Done.
67 const char kUnsupportedRequirements[] = "unsupported_requirements";
68
66 // Indicates whether the extension was updated while it was disabled. 69 // Indicates whether the extension was updated while it was disabled.
67 const char kPrefDisableReason[] = "disable_reason"; 70 const char kPrefDisableReason[] = "disable_reason";
68 71
69 // A preference that tracks browser action toolbar configuration. This is a list 72 // A preference that tracks browser action toolbar configuration. This is a list
70 // object stored in the Preferences file. The extensions are stored by ID. 73 // object stored in the Preferences file. The extensions are stored by ID.
71 const char kExtensionToolbar[] = "extensions.toolbar"; 74 const char kExtensionToolbar[] = "extensions.toolbar";
72 75
73 // The key for a serialized Time value indicating the start of the day (from the 76 // The key for a serialized Time value indicating the start of the day (from the
74 // server's perspective) an extension last included a "ping" parameter during 77 // server's perspective) an extension last included a "ping" parameter during
75 // its update check. 78 // its update check.
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 UpdateExtensionPref(extension_id, kPrefAppNotificationClientId, 620 UpdateExtensionPref(extension_id, kPrefAppNotificationClientId,
618 Value::CreateStringValue(oauth_client_id)); 621 Value::CreateStringValue(oauth_client_id));
619 } 622 }
620 623
621 bool ExtensionPrefs::IsAppNotificationDisabled( 624 bool ExtensionPrefs::IsAppNotificationDisabled(
622 const std::string& extension_id) const { 625 const std::string& extension_id) const {
623 return ReadExtensionPrefBoolean(extension_id, kPrefAppNotificationDisbaled); 626 return ReadExtensionPrefBoolean(extension_id, kPrefAppNotificationDisbaled);
624 } 627 }
625 628
626 void ExtensionPrefs::SetAppNotificationDisabled( 629 void ExtensionPrefs::SetAppNotificationDisabled(
627 const std::string& extension_id, bool value) { 630 const std::string& extension_id, bool value) {
628 DCHECK(Extension::IdIsValid(extension_id)); 631 DCHECK(Extension::IdIsValid(extension_id));
629 UpdateExtensionPref(extension_id, kPrefAppNotificationDisbaled, 632 UpdateExtensionPref(extension_id, kPrefAppNotificationDisbaled,
630 Value::CreateBooleanValue(value)); 633 Value::CreateBooleanValue(value));
631 } 634 }
632 635
633 std::string ExtensionPrefs::GetDebugPolicyProviderName() const { 636 std::string ExtensionPrefs::GetDebugPolicyProviderName() const {
634 #ifdef NDEBUG 637 #ifdef NDEBUG
635 NOTREACHED(); 638 NOTREACHED();
636 return std::string(); 639 return std::string();
637 #else 640 #else
638 return "admin policy black/white/forcelist, via the ExtensionPrefs"; 641 return "admin policy black/white/forcelist, via the ExtensionPrefs";
639 #endif 642 #endif
640 } 643 }
641 644
642 bool ExtensionPrefs::UserMayLoad(const Extension* extension, 645 bool ExtensionPrefs::UserMayLoad(const Extension* extension,
643 string16* error) const { 646 string16* error) const {
644
Aaron Boodman 2012/08/01 03:58:54 stray edit
eaugusti 2012/08/03 01:06:26 Done.
645 const base::ListValue* blacklist = 647 const base::ListValue* blacklist =
646 prefs_->GetList(prefs::kExtensionInstallDenyList); 648 prefs_->GetList(prefs::kExtensionInstallDenyList);
647 const base::ListValue* whitelist = 649 const base::ListValue* whitelist =
648 prefs_->GetList(prefs::kExtensionInstallAllowList); 650 prefs_->GetList(prefs::kExtensionInstallAllowList);
649 return admin_policy::UserMayLoad(blacklist, whitelist, extension, 651 return admin_policy::UserMayLoad(blacklist, whitelist, extension,
650 error); 652 error);
651 } 653 }
652 654
653 bool ExtensionPrefs::UserMayModifySettings(const Extension* extension, 655 bool ExtensionPrefs::UserMayModifySettings(const Extension* extension,
654 string16* error) const { 656 string16* error) const {
(...skipping 15 matching lines...) Expand all
670 return ReadExtensionPrefBoolean(extension_id, 672 return ReadExtensionPrefBoolean(extension_id,
671 kExtensionDidEscalatePermissions); 673 kExtensionDidEscalatePermissions);
672 } 674 }
673 675
674 void ExtensionPrefs::SetDidExtensionEscalatePermissions( 676 void ExtensionPrefs::SetDidExtensionEscalatePermissions(
675 const Extension* extension, bool did_escalate) { 677 const Extension* extension, bool did_escalate) {
676 UpdateExtensionPref(extension->id(), kExtensionDidEscalatePermissions, 678 UpdateExtensionPref(extension->id(), kExtensionDidEscalatePermissions,
677 Value::CreateBooleanValue(did_escalate)); 679 Value::CreateBooleanValue(did_escalate));
678 } 680 }
679 681
682 bool ExtensionPrefs::HasUnsupportedRequirements(
683 const std::string& extension_id) {
684 const ListValue* requirement_errors = NULL;
685 return ReadExtensionPrefList(extension_id,
686 kUnsupportedRequirements,
687 &requirement_errors);
688 }
689
690 void ExtensionPrefs::ClearUnsupportedRequirements(
691 const std::string& extension_id) {
692 UpdateExtensionPref(extension_id, kUnsupportedRequirements, NULL);
693 }
694
695 void ExtensionPrefs::SetUnsupportedRequirements(
696 const std::string& extension_id,
697 std::vector<std::string> requirement_errors) {
698 ListValue* errors_list = new ListValue();
Aaron Boodman 2012/08/01 03:58:54 Are there other functions in this class doing the
eaugusti 2012/08/03 01:06:26 No one uses this exact functionality, but I can st
699 std::vector<std::string>::iterator it;
700 for (it = requirement_errors.begin(); it != requirement_errors.end(); ++it)
701 errors_list->Append(Value::CreateStringValue(*it));
702 UpdateExtensionPref(extension_id, kUnsupportedRequirements, errors_list);
703 }
704
705 std::vector<std::string> ExtensionPrefs::GetUnsupportedRequirements(
706 const std::string& extension_id) {
707 std::vector<std::string> requirement_errors;
708 const ListValue* errors = NULL;
709 if (ReadExtensionPrefList(extension_id, kUnsupportedRequirements,
Aaron Boodman 2012/08/01 03:58:54 Same comment about potentially pulling out duplica
eaugusti 2012/08/03 01:06:26 Done.
710 &errors)) {
711 for (size_t i = 0; i < errors->GetSize(); ++i) {
712 std::string requirement_error;
713 if (errors->GetString(i, &requirement_error))
714 requirement_errors.push_back(requirement_error);
715 }
716 }
717 return requirement_errors;
718 }
719
680 Extension::DisableReason ExtensionPrefs::GetDisableReason( 720 Extension::DisableReason ExtensionPrefs::GetDisableReason(
681 const std::string& extension_id) { 721 const std::string& extension_id) {
682 int value = -1; 722 int value = -1;
683 if (ReadExtensionPrefInteger(extension_id, kPrefDisableReason, &value) && 723 if (ReadExtensionPrefInteger(extension_id, kPrefDisableReason, &value) &&
684 value >= 0 && value < Extension::DISABLE_LAST) { 724 value >= 0 && value < Extension::DISABLE_LAST) {
685 return static_cast<Extension::DisableReason>(value); 725 return static_cast<Extension::DisableReason>(value);
686 } 726 }
687 return Extension::DISABLE_UNKNOWN; 727 return Extension::DISABLE_UNKNOWN;
688 } 728 }
689 729
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 void ExtensionPrefs::SetActiveBit(const std::string& extension_id, 866 void ExtensionPrefs::SetActiveBit(const std::string& extension_id,
827 bool active) { 867 bool active) {
828 UpdateExtensionPref(extension_id, kActiveBit, 868 UpdateExtensionPref(extension_id, kActiveBit,
829 Value::CreateBooleanValue(active)); 869 Value::CreateBooleanValue(active));
830 } 870 }
831 871
832 void ExtensionPrefs::MigratePermissions(const ExtensionIdSet& extension_ids) { 872 void ExtensionPrefs::MigratePermissions(const ExtensionIdSet& extension_ids) {
833 PermissionsInfo* info = PermissionsInfo::GetInstance(); 873 PermissionsInfo* info = PermissionsInfo::GetInstance();
834 for (ExtensionIdSet::const_iterator ext_id = 874 for (ExtensionIdSet::const_iterator ext_id =
835 extension_ids.begin(); ext_id != extension_ids.end(); ++ext_id) { 875 extension_ids.begin(); ext_id != extension_ids.end(); ++ext_id) {
836
837 // An extension's granted permissions need to be migrated if the 876 // An extension's granted permissions need to be migrated if the
Aaron Boodman 2012/08/01 03:58:54 stray edit
eaugusti 2012/08/03 01:06:26 Done.
838 // full_access bit is present. This bit was always present in the previous 877 // full_access bit is present. This bit was always present in the previous
839 // scheme and is never present now. 878 // scheme and is never present now.
840 bool full_access; 879 bool full_access;
841 const DictionaryValue* ext = GetExtensionPref(*ext_id); 880 const DictionaryValue* ext = GetExtensionPref(*ext_id);
842 if (!ext || !ext->GetBoolean(kPrefOldGrantedFullAccess, &full_access)) 881 if (!ext || !ext->GetBoolean(kPrefOldGrantedFullAccess, &full_access))
843 continue; 882 continue;
844 883
845 // Remove the full access bit (empty list will get trimmed). 884 // Remove the full access bit (empty list will get trimmed).
846 UpdateExtensionPref( 885 UpdateExtensionPref(
847 *ext_id, kPrefOldGrantedFullAccess, new ListValue()); 886 *ext_id, kPrefOldGrantedFullAccess, new ListValue());
(...skipping 1086 matching lines...) Expand 10 before | Expand all | Expand 10 after
1934 0, // default value 1973 0, // default value
1935 PrefService::UNSYNCABLE_PREF); 1974 PrefService::UNSYNCABLE_PREF);
1936 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, 1975 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck,
1937 0, // default value 1976 0, // default value
1938 PrefService::UNSYNCABLE_PREF); 1977 PrefService::UNSYNCABLE_PREF);
1939 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites, 1978 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites,
1940 PrefService::UNSYNCABLE_PREF); 1979 PrefService::UNSYNCABLE_PREF);
1941 } 1980 }
1942 1981
1943 } // namespace extensions 1982 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698