| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/extension_prefs.h" | 5 #include "extensions/browser/extension_prefs.h" |
| 6 | 6 |
| 7 #include <iterator> | 7 #include <iterator> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 } | 532 } |
| 533 | 533 |
| 534 bool ExtensionPrefs::HasPrefForExtension( | 534 bool ExtensionPrefs::HasPrefForExtension( |
| 535 const std::string& extension_id) const { | 535 const std::string& extension_id) const { |
| 536 return GetExtensionPref(extension_id) != NULL; | 536 return GetExtensionPref(extension_id) != NULL; |
| 537 } | 537 } |
| 538 | 538 |
| 539 bool ExtensionPrefs::ReadPrefAsURLPatternSet(const std::string& extension_id, | 539 bool ExtensionPrefs::ReadPrefAsURLPatternSet(const std::string& extension_id, |
| 540 const std::string& pref_key, | 540 const std::string& pref_key, |
| 541 URLPatternSet* result, | 541 URLPatternSet* result, |
| 542 int valid_schemes) { | 542 int valid_schemes) const { |
| 543 const base::ListValue* value = NULL; | 543 const base::ListValue* value = NULL; |
| 544 if (!ReadPrefAsList(extension_id, pref_key, &value)) | 544 if (!ReadPrefAsList(extension_id, pref_key, &value)) |
| 545 return false; | 545 return false; |
| 546 const base::DictionaryValue* extension = GetExtensionPref(extension_id); | 546 const base::DictionaryValue* extension = GetExtensionPref(extension_id); |
| 547 if (!extension) | 547 if (!extension) |
| 548 return false; | 548 return false; |
| 549 int location; | 549 int location; |
| 550 if (extension->GetInteger(kPrefLocation, &location) && | 550 if (extension->GetInteger(kPrefLocation, &location) && |
| 551 static_cast<Manifest::Location>(location) == Manifest::COMPONENT) { | 551 static_cast<Manifest::Location>(location) == Manifest::COMPONENT) { |
| 552 valid_schemes |= URLPattern::SCHEME_CHROMEUI; | 552 valid_schemes |= URLPattern::SCHEME_CHROMEUI; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 565 | 565 |
| 566 bool ExtensionPrefs::ReadPrefAsBooleanAndReturn( | 566 bool ExtensionPrefs::ReadPrefAsBooleanAndReturn( |
| 567 const std::string& extension_id, | 567 const std::string& extension_id, |
| 568 const std::string& pref_key) const { | 568 const std::string& pref_key) const { |
| 569 bool out_value = false; | 569 bool out_value = false; |
| 570 return ReadPrefAsBoolean(extension_id, pref_key, &out_value) && out_value; | 570 return ReadPrefAsBoolean(extension_id, pref_key, &out_value) && out_value; |
| 571 } | 571 } |
| 572 | 572 |
| 573 PermissionSet* ExtensionPrefs::ReadPrefAsPermissionSet( | 573 PermissionSet* ExtensionPrefs::ReadPrefAsPermissionSet( |
| 574 const std::string& extension_id, | 574 const std::string& extension_id, |
| 575 const std::string& pref_key) { | 575 const std::string& pref_key) const { |
| 576 if (!GetExtensionPref(extension_id)) | 576 if (!GetExtensionPref(extension_id)) |
| 577 return NULL; | 577 return NULL; |
| 578 | 578 |
| 579 // Retrieve the API permissions. Please refer SetExtensionPrefPermissionSet() | 579 // Retrieve the API permissions. Please refer SetExtensionPrefPermissionSet() |
| 580 // for api_values format. | 580 // for api_values format. |
| 581 APIPermissionSet apis; | 581 APIPermissionSet apis; |
| 582 const base::ListValue* api_values = NULL; | 582 const base::ListValue* api_values = NULL; |
| 583 std::string api_pref = JoinPrefs(pref_key, kPrefAPIs); | 583 std::string api_pref = JoinPrefs(pref_key, kPrefAPIs); |
| 584 if (ReadPrefAsList(extension_id, api_pref, &api_values)) { | 584 if (ReadPrefAsList(extension_id, api_pref, &api_values)) { |
| 585 APIPermissionSet::ParseFromJSON(api_values, | 585 APIPermissionSet::ParseFromJSON(api_values, |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 const std::string& extension_id) { | 675 const std::string& extension_id) { |
| 676 int count = 0; | 676 int count = 0; |
| 677 ReadPrefAsInteger(extension_id, kPrefAcknowledgePromptCount, &count); | 677 ReadPrefAsInteger(extension_id, kPrefAcknowledgePromptCount, &count); |
| 678 ++count; | 678 ++count; |
| 679 UpdateExtensionPref(extension_id, kPrefAcknowledgePromptCount, | 679 UpdateExtensionPref(extension_id, kPrefAcknowledgePromptCount, |
| 680 new base::FundamentalValue(count)); | 680 new base::FundamentalValue(count)); |
| 681 return count; | 681 return count; |
| 682 } | 682 } |
| 683 | 683 |
| 684 bool ExtensionPrefs::IsExternalExtensionAcknowledged( | 684 bool ExtensionPrefs::IsExternalExtensionAcknowledged( |
| 685 const std::string& extension_id) { | 685 const std::string& extension_id) const { |
| 686 return ReadPrefAsBooleanAndReturn(extension_id, kPrefExternalAcknowledged); | 686 return ReadPrefAsBooleanAndReturn(extension_id, kPrefExternalAcknowledged); |
| 687 } | 687 } |
| 688 | 688 |
| 689 void ExtensionPrefs::AcknowledgeExternalExtension( | 689 void ExtensionPrefs::AcknowledgeExternalExtension( |
| 690 const std::string& extension_id) { | 690 const std::string& extension_id) { |
| 691 DCHECK(crx_file::id_util::IdIsValid(extension_id)); | 691 DCHECK(crx_file::id_util::IdIsValid(extension_id)); |
| 692 UpdateExtensionPref(extension_id, kPrefExternalAcknowledged, | 692 UpdateExtensionPref(extension_id, kPrefExternalAcknowledged, |
| 693 new base::FundamentalValue(true)); | 693 new base::FundamentalValue(true)); |
| 694 UpdateExtensionPref(extension_id, kPrefAcknowledgePromptCount, NULL); | 694 UpdateExtensionPref(extension_id, kPrefAcknowledgePromptCount, NULL); |
| 695 } | 695 } |
| 696 | 696 |
| 697 bool ExtensionPrefs::IsBlacklistedExtensionAcknowledged( | 697 bool ExtensionPrefs::IsBlacklistedExtensionAcknowledged( |
| 698 const std::string& extension_id) { | 698 const std::string& extension_id) const { |
| 699 return ReadPrefAsBooleanAndReturn(extension_id, kPrefBlacklistAcknowledged); | 699 return ReadPrefAsBooleanAndReturn(extension_id, kPrefBlacklistAcknowledged); |
| 700 } | 700 } |
| 701 | 701 |
| 702 void ExtensionPrefs::AcknowledgeBlacklistedExtension( | 702 void ExtensionPrefs::AcknowledgeBlacklistedExtension( |
| 703 const std::string& extension_id) { | 703 const std::string& extension_id) { |
| 704 DCHECK(crx_file::id_util::IdIsValid(extension_id)); | 704 DCHECK(crx_file::id_util::IdIsValid(extension_id)); |
| 705 UpdateExtensionPref(extension_id, kPrefBlacklistAcknowledged, | 705 UpdateExtensionPref(extension_id, kPrefBlacklistAcknowledged, |
| 706 new base::FundamentalValue(true)); | 706 new base::FundamentalValue(true)); |
| 707 UpdateExtensionPref(extension_id, kPrefAcknowledgePromptCount, NULL); | 707 UpdateExtensionPref(extension_id, kPrefAcknowledgePromptCount, NULL); |
| 708 } | 708 } |
| 709 | 709 |
| 710 bool ExtensionPrefs::IsExternalInstallFirstRun( | 710 bool ExtensionPrefs::IsExternalInstallFirstRun( |
| 711 const std::string& extension_id) { | 711 const std::string& extension_id) const { |
| 712 return ReadPrefAsBooleanAndReturn(extension_id, kPrefExternalInstallFirstRun); | 712 return ReadPrefAsBooleanAndReturn(extension_id, kPrefExternalInstallFirstRun); |
| 713 } | 713 } |
| 714 | 714 |
| 715 void ExtensionPrefs::SetExternalInstallFirstRun( | 715 void ExtensionPrefs::SetExternalInstallFirstRun( |
| 716 const std::string& extension_id) { | 716 const std::string& extension_id) { |
| 717 DCHECK(crx_file::id_util::IdIsValid(extension_id)); | 717 DCHECK(crx_file::id_util::IdIsValid(extension_id)); |
| 718 UpdateExtensionPref(extension_id, kPrefExternalInstallFirstRun, | 718 UpdateExtensionPref(extension_id, kPrefExternalInstallFirstRun, |
| 719 new base::FundamentalValue(true)); | 719 new base::FundamentalValue(true)); |
| 720 } | 720 } |
| 721 | 721 |
| 722 bool ExtensionPrefs::SetAlertSystemFirstRun() { | 722 bool ExtensionPrefs::SetAlertSystemFirstRun() { |
| 723 if (prefs_->GetBoolean(pref_names::kAlertsInitialized)) { | 723 if (prefs_->GetBoolean(pref_names::kAlertsInitialized)) { |
| 724 return true; | 724 return true; |
| 725 } | 725 } |
| 726 prefs_->SetBoolean(pref_names::kAlertsInitialized, true); | 726 prefs_->SetBoolean(pref_names::kAlertsInitialized, true); |
| 727 return false; | 727 return false; |
| 728 } | 728 } |
| 729 | 729 |
| 730 bool ExtensionPrefs::DidExtensionEscalatePermissions( | 730 bool ExtensionPrefs::DidExtensionEscalatePermissions( |
| 731 const std::string& extension_id) { | 731 const std::string& extension_id) const { |
| 732 return ReadPrefAsBooleanAndReturn(extension_id, | 732 return ReadPrefAsBooleanAndReturn(extension_id, |
| 733 kExtensionDidEscalatePermissions); | 733 kExtensionDidEscalatePermissions); |
| 734 } | 734 } |
| 735 | 735 |
| 736 void ExtensionPrefs::SetDidExtensionEscalatePermissions( | 736 void ExtensionPrefs::SetDidExtensionEscalatePermissions( |
| 737 const Extension* extension, bool did_escalate) { | 737 const Extension* extension, bool did_escalate) { |
| 738 UpdateExtensionPref(extension->id(), kExtensionDidEscalatePermissions, | 738 UpdateExtensionPref(extension->id(), kExtensionDidEscalatePermissions, |
| 739 new base::FundamentalValue(did_escalate)); | 739 new base::FundamentalValue(did_escalate)); |
| 740 } | 740 } |
| 741 | 741 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 UpdateExtensionPref(extension_id, | 796 UpdateExtensionPref(extension_id, |
| 797 kPrefDisableReasons, | 797 kPrefDisableReasons, |
| 798 new base::FundamentalValue(new_value)); | 798 new base::FundamentalValue(new_value)); |
| 799 } | 799 } |
| 800 | 800 |
| 801 FOR_EACH_OBSERVER(ExtensionPrefsObserver, | 801 FOR_EACH_OBSERVER(ExtensionPrefsObserver, |
| 802 observer_list_, | 802 observer_list_, |
| 803 OnExtensionDisableReasonsChanged(extension_id, new_value)); | 803 OnExtensionDisableReasonsChanged(extension_id, new_value)); |
| 804 } | 804 } |
| 805 | 805 |
| 806 std::set<std::string> ExtensionPrefs::GetBlacklistedExtensions() { | 806 std::set<std::string> ExtensionPrefs::GetBlacklistedExtensions() const { |
| 807 std::set<std::string> ids; | 807 std::set<std::string> ids; |
| 808 | 808 |
| 809 const base::DictionaryValue* extensions = | 809 const base::DictionaryValue* extensions = |
| 810 prefs_->GetDictionary(pref_names::kExtensions); | 810 prefs_->GetDictionary(pref_names::kExtensions); |
| 811 if (!extensions) | 811 if (!extensions) |
| 812 return ids; | 812 return ids; |
| 813 | 813 |
| 814 for (base::DictionaryValue::Iterator it(*extensions); | 814 for (base::DictionaryValue::Iterator it(*extensions); |
| 815 !it.IsAtEnd(); it.Advance()) { | 815 !it.IsAtEnd(); it.Advance()) { |
| 816 if (!it.value().IsType(base::Value::TYPE_DICTIONARY)) { | 816 if (!it.value().IsType(base::Value::TYPE_DICTIONARY)) { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 base::Time ExtensionPrefs::BlacklistLastPingDay() const { | 914 base::Time ExtensionPrefs::BlacklistLastPingDay() const { |
| 915 return ReadTime(prefs_->GetDictionary(kExtensionsBlacklistUpdate), | 915 return ReadTime(prefs_->GetDictionary(kExtensionsBlacklistUpdate), |
| 916 kLastPingDay); | 916 kLastPingDay); |
| 917 } | 917 } |
| 918 | 918 |
| 919 void ExtensionPrefs::SetBlacklistLastPingDay(const base::Time& time) { | 919 void ExtensionPrefs::SetBlacklistLastPingDay(const base::Time& time) { |
| 920 DictionaryPrefUpdate update(prefs_, kExtensionsBlacklistUpdate); | 920 DictionaryPrefUpdate update(prefs_, kExtensionsBlacklistUpdate); |
| 921 SaveTime(update.Get(), kLastPingDay, time); | 921 SaveTime(update.Get(), kLastPingDay, time); |
| 922 } | 922 } |
| 923 | 923 |
| 924 base::Time ExtensionPrefs::LastActivePingDay(const std::string& extension_id) { | 924 base::Time ExtensionPrefs::LastActivePingDay( |
| 925 const std::string& extension_id) const { |
| 925 DCHECK(crx_file::id_util::IdIsValid(extension_id)); | 926 DCHECK(crx_file::id_util::IdIsValid(extension_id)); |
| 926 return ReadTime(GetExtensionPref(extension_id), kLastActivePingDay); | 927 return ReadTime(GetExtensionPref(extension_id), kLastActivePingDay); |
| 927 } | 928 } |
| 928 | 929 |
| 929 void ExtensionPrefs::SetLastActivePingDay(const std::string& extension_id, | 930 void ExtensionPrefs::SetLastActivePingDay(const std::string& extension_id, |
| 930 const base::Time& time) { | 931 const base::Time& time) { |
| 931 DCHECK(crx_file::id_util::IdIsValid(extension_id)); | 932 DCHECK(crx_file::id_util::IdIsValid(extension_id)); |
| 932 ScopedExtensionPrefUpdate update(prefs_, extension_id); | 933 ScopedExtensionPrefUpdate update(prefs_, extension_id); |
| 933 SaveTime(update.Get(), kLastActivePingDay, time); | 934 SaveTime(update.Get(), kLastActivePingDay, time); |
| 934 } | 935 } |
| 935 | 936 |
| 936 bool ExtensionPrefs::GetActiveBit(const std::string& extension_id) { | 937 bool ExtensionPrefs::GetActiveBit(const std::string& extension_id) const { |
| 937 const base::DictionaryValue* dictionary = GetExtensionPref(extension_id); | 938 const base::DictionaryValue* dictionary = GetExtensionPref(extension_id); |
| 938 bool result = false; | 939 bool result = false; |
| 939 if (dictionary && dictionary->GetBoolean(kActiveBit, &result)) | 940 if (dictionary && dictionary->GetBoolean(kActiveBit, &result)) |
| 940 return result; | 941 return result; |
| 941 return false; | 942 return false; |
| 942 } | 943 } |
| 943 | 944 |
| 944 void ExtensionPrefs::SetActiveBit(const std::string& extension_id, | 945 void ExtensionPrefs::SetActiveBit(const std::string& extension_id, |
| 945 bool active) { | 946 bool active) { |
| 946 UpdateExtensionPref(extension_id, kActiveBit, | 947 UpdateExtensionPref(extension_id, kActiveBit, |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1019 | 1020 |
| 1020 UpdateExtensionPref(*ext_id, kPrefDisableReasons, | 1021 UpdateExtensionPref(*ext_id, kPrefDisableReasons, |
| 1021 new base::FundamentalValue(new_value)); | 1022 new base::FundamentalValue(new_value)); |
| 1022 // Remove the old disable reason. | 1023 // Remove the old disable reason. |
| 1023 UpdateExtensionPref(*ext_id, kDeprecatedPrefDisableReason, NULL); | 1024 UpdateExtensionPref(*ext_id, kDeprecatedPrefDisableReason, NULL); |
| 1024 } | 1025 } |
| 1025 } | 1026 } |
| 1026 } | 1027 } |
| 1027 | 1028 |
| 1028 PermissionSet* ExtensionPrefs::GetGrantedPermissions( | 1029 PermissionSet* ExtensionPrefs::GetGrantedPermissions( |
| 1029 const std::string& extension_id) { | 1030 const std::string& extension_id) const { |
| 1030 CHECK(crx_file::id_util::IdIsValid(extension_id)); | 1031 CHECK(crx_file::id_util::IdIsValid(extension_id)); |
| 1031 return ReadPrefAsPermissionSet(extension_id, kPrefGrantedPermissions); | 1032 return ReadPrefAsPermissionSet(extension_id, kPrefGrantedPermissions); |
| 1032 } | 1033 } |
| 1033 | 1034 |
| 1034 void ExtensionPrefs::AddGrantedPermissions( | 1035 void ExtensionPrefs::AddGrantedPermissions( |
| 1035 const std::string& extension_id, | 1036 const std::string& extension_id, |
| 1036 const PermissionSet* permissions) { | 1037 const PermissionSet* permissions) { |
| 1037 CHECK(crx_file::id_util::IdIsValid(extension_id)); | 1038 CHECK(crx_file::id_util::IdIsValid(extension_id)); |
| 1038 | 1039 |
| 1039 scoped_refptr<PermissionSet> granted_permissions( | 1040 scoped_refptr<PermissionSet> granted_permissions( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1061 // permissions and the newly ungranted permissions. | 1062 // permissions and the newly ungranted permissions. |
| 1062 scoped_refptr<PermissionSet> new_perms( | 1063 scoped_refptr<PermissionSet> new_perms( |
| 1063 PermissionSet::CreateDifference( | 1064 PermissionSet::CreateDifference( |
| 1064 granted_permissions.get(), permissions)); | 1065 granted_permissions.get(), permissions)); |
| 1065 | 1066 |
| 1066 SetExtensionPrefPermissionSet( | 1067 SetExtensionPrefPermissionSet( |
| 1067 extension_id, kPrefGrantedPermissions, new_perms.get()); | 1068 extension_id, kPrefGrantedPermissions, new_perms.get()); |
| 1068 } | 1069 } |
| 1069 | 1070 |
| 1070 PermissionSet* ExtensionPrefs::GetActivePermissions( | 1071 PermissionSet* ExtensionPrefs::GetActivePermissions( |
| 1071 const std::string& extension_id) { | 1072 const std::string& extension_id) const { |
| 1072 CHECK(crx_file::id_util::IdIsValid(extension_id)); | 1073 CHECK(crx_file::id_util::IdIsValid(extension_id)); |
| 1073 return ReadPrefAsPermissionSet(extension_id, kPrefActivePermissions); | 1074 return ReadPrefAsPermissionSet(extension_id, kPrefActivePermissions); |
| 1074 } | 1075 } |
| 1075 | 1076 |
| 1076 void ExtensionPrefs::SetActivePermissions( | 1077 void ExtensionPrefs::SetActivePermissions( |
| 1077 const std::string& extension_id, | 1078 const std::string& extension_id, |
| 1078 const PermissionSet* permissions) { | 1079 const PermissionSet* permissions) { |
| 1079 SetExtensionPrefPermissionSet( | 1080 SetExtensionPrefPermissionSet( |
| 1080 extension_id, kPrefActivePermissions, permissions); | 1081 extension_id, kPrefActivePermissions, permissions); |
| 1081 } | 1082 } |
| 1082 | 1083 |
| 1083 void ExtensionPrefs::SetExtensionRunning(const std::string& extension_id, | 1084 void ExtensionPrefs::SetExtensionRunning(const std::string& extension_id, |
| 1084 bool is_running) { | 1085 bool is_running) { |
| 1085 base::Value* value = new base::FundamentalValue(is_running); | 1086 base::Value* value = new base::FundamentalValue(is_running); |
| 1086 UpdateExtensionPref(extension_id, kPrefRunning, value); | 1087 UpdateExtensionPref(extension_id, kPrefRunning, value); |
| 1087 } | 1088 } |
| 1088 | 1089 |
| 1089 bool ExtensionPrefs::IsExtensionRunning(const std::string& extension_id) { | 1090 bool ExtensionPrefs::IsExtensionRunning(const std::string& extension_id) const { |
| 1090 const base::DictionaryValue* extension = GetExtensionPref(extension_id); | 1091 const base::DictionaryValue* extension = GetExtensionPref(extension_id); |
| 1091 if (!extension) | 1092 if (!extension) |
| 1092 return false; | 1093 return false; |
| 1093 bool running = false; | 1094 bool running = false; |
| 1094 extension->GetBoolean(kPrefRunning, &running); | 1095 extension->GetBoolean(kPrefRunning, &running); |
| 1095 return running; | 1096 return running; |
| 1096 } | 1097 } |
| 1097 | 1098 |
| 1098 void ExtensionPrefs::SetIsActive(const std::string& extension_id, | 1099 void ExtensionPrefs::SetIsActive(const std::string& extension_id, |
| 1099 bool is_active) { | 1100 bool is_active) { |
| 1100 base::Value* value = new base::FundamentalValue(is_active); | 1101 base::Value* value = new base::FundamentalValue(is_active); |
| 1101 UpdateExtensionPref(extension_id, kIsActive, value); | 1102 UpdateExtensionPref(extension_id, kIsActive, value); |
| 1102 } | 1103 } |
| 1103 | 1104 |
| 1104 bool ExtensionPrefs::IsActive(const std::string& extension_id) { | 1105 bool ExtensionPrefs::IsActive(const std::string& extension_id) const { |
| 1105 const base::DictionaryValue* extension = GetExtensionPref(extension_id); | 1106 const base::DictionaryValue* extension = GetExtensionPref(extension_id); |
| 1106 if (!extension) | 1107 if (!extension) |
| 1107 return false; | 1108 return false; |
| 1108 bool is_active = false; | 1109 bool is_active = false; |
| 1109 extension->GetBoolean(kIsActive, &is_active); | 1110 extension->GetBoolean(kIsActive, &is_active); |
| 1110 return is_active; | 1111 return is_active; |
| 1111 } | 1112 } |
| 1112 | 1113 |
| 1113 bool ExtensionPrefs::IsIncognitoEnabled(const std::string& extension_id) const { | 1114 bool ExtensionPrefs::IsIncognitoEnabled(const std::string& extension_id) const { |
| 1114 return ReadPrefAsBooleanAndReturn(extension_id, kPrefIncognitoEnabled); | 1115 return ReadPrefAsBooleanAndReturn(extension_id, kPrefIncognitoEnabled); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1155 bool ExtensionPrefs::IsExternalExtensionUninstalled( | 1156 bool ExtensionPrefs::IsExternalExtensionUninstalled( |
| 1156 const std::string& id) const { | 1157 const std::string& id) const { |
| 1157 return DoesExtensionHaveState(id, Extension::EXTERNAL_EXTENSION_UNINSTALLED); | 1158 return DoesExtensionHaveState(id, Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
| 1158 } | 1159 } |
| 1159 | 1160 |
| 1160 bool ExtensionPrefs::IsExtensionDisabled( | 1161 bool ExtensionPrefs::IsExtensionDisabled( |
| 1161 const std::string& id) const { | 1162 const std::string& id) const { |
| 1162 return DoesExtensionHaveState(id, Extension::DISABLED); | 1163 return DoesExtensionHaveState(id, Extension::DISABLED); |
| 1163 } | 1164 } |
| 1164 | 1165 |
| 1165 ExtensionIdList ExtensionPrefs::GetToolbarOrder() { | 1166 ExtensionIdList ExtensionPrefs::GetToolbarOrder() const { |
| 1166 ExtensionIdList id_list_out; | 1167 ExtensionIdList id_list_out; |
| 1167 GetUserExtensionPrefIntoContainer(pref_names::kToolbar, &id_list_out); | 1168 GetUserExtensionPrefIntoContainer(pref_names::kToolbar, &id_list_out); |
| 1168 return id_list_out; | 1169 return id_list_out; |
| 1169 } | 1170 } |
| 1170 | 1171 |
| 1171 void ExtensionPrefs::SetToolbarOrder(const ExtensionIdList& extension_ids) { | 1172 void ExtensionPrefs::SetToolbarOrder(const ExtensionIdList& extension_ids) { |
| 1172 SetExtensionPrefFromContainer(pref_names::kToolbar, extension_ids); | 1173 SetExtensionPrefFromContainer(pref_names::kToolbar, extension_ids); |
| 1173 } | 1174 } |
| 1174 | 1175 |
| 1175 void ExtensionPrefs::OnExtensionInstalled( | 1176 void ExtensionPrefs::OnExtensionInstalled( |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1231 } | 1232 } |
| 1232 | 1233 |
| 1233 void ExtensionPrefs::SetExtensionBlacklistState(const std::string& extension_id, | 1234 void ExtensionPrefs::SetExtensionBlacklistState(const std::string& extension_id, |
| 1234 BlacklistState state) { | 1235 BlacklistState state) { |
| 1235 SetExtensionBlacklisted(extension_id, state == BLACKLISTED_MALWARE); | 1236 SetExtensionBlacklisted(extension_id, state == BLACKLISTED_MALWARE); |
| 1236 UpdateExtensionPref(extension_id, kPrefBlacklistState, | 1237 UpdateExtensionPref(extension_id, kPrefBlacklistState, |
| 1237 new base::FundamentalValue(state)); | 1238 new base::FundamentalValue(state)); |
| 1238 } | 1239 } |
| 1239 | 1240 |
| 1240 BlacklistState ExtensionPrefs::GetExtensionBlacklistState( | 1241 BlacklistState ExtensionPrefs::GetExtensionBlacklistState( |
| 1241 const std::string& extension_id) { | 1242 const std::string& extension_id) const { |
| 1242 if (IsExtensionBlacklisted(extension_id)) | 1243 if (IsExtensionBlacklisted(extension_id)) |
| 1243 return BLACKLISTED_MALWARE; | 1244 return BLACKLISTED_MALWARE; |
| 1244 const base::DictionaryValue* ext_prefs = GetExtensionPref(extension_id); | 1245 const base::DictionaryValue* ext_prefs = GetExtensionPref(extension_id); |
| 1245 int int_value = 0; | 1246 int int_value = 0; |
| 1246 if (ext_prefs && ext_prefs->GetInteger(kPrefBlacklistState, &int_value)) | 1247 if (ext_prefs && ext_prefs->GetInteger(kPrefBlacklistState, &int_value)) |
| 1247 return static_cast<BlacklistState>(int_value); | 1248 return static_cast<BlacklistState>(int_value); |
| 1248 | 1249 |
| 1249 return NOT_BLACKLISTED; | 1250 return NOT_BLACKLISTED; |
| 1250 } | 1251 } |
| 1251 | 1252 |
| 1252 std::string ExtensionPrefs::GetVersionString(const std::string& extension_id) { | 1253 std::string ExtensionPrefs::GetVersionString( |
| 1254 const std::string& extension_id) const { |
| 1253 const base::DictionaryValue* extension = GetExtensionPref(extension_id); | 1255 const base::DictionaryValue* extension = GetExtensionPref(extension_id); |
| 1254 if (!extension) | 1256 if (!extension) |
| 1255 return std::string(); | 1257 return std::string(); |
| 1256 | 1258 |
| 1257 std::string version; | 1259 std::string version; |
| 1258 extension->GetString(kPrefVersion, &version); | 1260 extension->GetString(kPrefVersion, &version); |
| 1259 | 1261 |
| 1260 return version; | 1262 return version; |
| 1261 } | 1263 } |
| 1262 | 1264 |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1539 if (ReadPrefAsInteger(extension_id, kPrefCreationFlags, &creation_flags)) { | 1541 if (ReadPrefAsInteger(extension_id, kPrefCreationFlags, &creation_flags)) { |
| 1540 if (creation_flags & Extension::IS_EPHEMERAL) { | 1542 if (creation_flags & Extension::IS_EPHEMERAL) { |
| 1541 creation_flags &= ~static_cast<int>(Extension::IS_EPHEMERAL); | 1543 creation_flags &= ~static_cast<int>(Extension::IS_EPHEMERAL); |
| 1542 UpdateExtensionPref(extension_id, | 1544 UpdateExtensionPref(extension_id, |
| 1543 kPrefCreationFlags, | 1545 kPrefCreationFlags, |
| 1544 new base::FundamentalValue(creation_flags)); | 1546 new base::FundamentalValue(creation_flags)); |
| 1545 } | 1547 } |
| 1546 } | 1548 } |
| 1547 } | 1549 } |
| 1548 | 1550 |
| 1549 bool ExtensionPrefs::WasAppDraggedByUser(const std::string& extension_id) { | 1551 bool ExtensionPrefs::WasAppDraggedByUser( |
| 1552 const std::string& extension_id) const { |
| 1550 return ReadPrefAsBooleanAndReturn(extension_id, kPrefUserDraggedApp); | 1553 return ReadPrefAsBooleanAndReturn(extension_id, kPrefUserDraggedApp); |
| 1551 } | 1554 } |
| 1552 | 1555 |
| 1553 void ExtensionPrefs::SetAppDraggedByUser(const std::string& extension_id) { | 1556 void ExtensionPrefs::SetAppDraggedByUser(const std::string& extension_id) { |
| 1554 UpdateExtensionPref(extension_id, kPrefUserDraggedApp, | 1557 UpdateExtensionPref(extension_id, kPrefUserDraggedApp, |
| 1555 new base::FundamentalValue(true)); | 1558 new base::FundamentalValue(true)); |
| 1556 } | 1559 } |
| 1557 | 1560 |
| 1558 bool ExtensionPrefs::IsFromWebStore( | 1561 bool ExtensionPrefs::IsFromWebStore( |
| 1559 const std::string& extension_id) const { | 1562 const std::string& extension_id) const { |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1677 i.Advance()) { | 1680 i.Advance()) { |
| 1678 base::DictionaryValue* extension_dict = NULL; | 1681 base::DictionaryValue* extension_dict = NULL; |
| 1679 if (!update_dict->GetDictionary(i.key(), &extension_dict)) | 1682 if (!update_dict->GetDictionary(i.key(), &extension_dict)) |
| 1680 continue; | 1683 continue; |
| 1681 | 1684 |
| 1682 if (extension_dict->HasKey(kPrefLastLaunchTime)) | 1685 if (extension_dict->HasKey(kPrefLastLaunchTime)) |
| 1683 extension_dict->Remove(kPrefLastLaunchTime, NULL); | 1686 extension_dict->Remove(kPrefLastLaunchTime, NULL); |
| 1684 } | 1687 } |
| 1685 } | 1688 } |
| 1686 | 1689 |
| 1687 void ExtensionPrefs::GetExtensions(ExtensionIdList* out) { | 1690 void ExtensionPrefs::GetExtensions(ExtensionIdList* out) const { |
| 1688 CHECK(out); | 1691 CHECK(out); |
| 1689 | 1692 |
| 1690 scoped_ptr<ExtensionsInfo> extensions_info(GetInstalledExtensionsInfo()); | 1693 scoped_ptr<ExtensionsInfo> extensions_info(GetInstalledExtensionsInfo()); |
| 1691 | 1694 |
| 1692 for (size_t i = 0; i < extensions_info->size(); ++i) { | 1695 for (size_t i = 0; i < extensions_info->size(); ++i) { |
| 1693 ExtensionInfo* info = extensions_info->at(i).get(); | 1696 ExtensionInfo* info = extensions_info->at(i).get(); |
| 1694 out->push_back(info->extension_id); | 1697 out->push_back(info->extension_id); |
| 1695 } | 1698 } |
| 1696 } | 1699 } |
| 1697 | 1700 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1776 FixMissingPrefs(extension_ids); | 1779 FixMissingPrefs(extension_ids); |
| 1777 MigratePermissions(extension_ids); | 1780 MigratePermissions(extension_ids); |
| 1778 MigrateDisableReasons(extension_ids); | 1781 MigrateDisableReasons(extension_ids); |
| 1779 app_sorting_->Initialize(extension_ids); | 1782 app_sorting_->Initialize(extension_ids); |
| 1780 | 1783 |
| 1781 InitExtensionControlledPrefs(extension_pref_value_map_); | 1784 InitExtensionControlledPrefs(extension_pref_value_map_); |
| 1782 | 1785 |
| 1783 extension_pref_value_map_->NotifyInitializationCompleted(); | 1786 extension_pref_value_map_->NotifyInitializationCompleted(); |
| 1784 } | 1787 } |
| 1785 | 1788 |
| 1786 bool ExtensionPrefs::HasIncognitoPrefValue(const std::string& pref_key) { | 1789 bool ExtensionPrefs::HasIncognitoPrefValue(const std::string& pref_key) const { |
| 1787 bool has_incognito_pref_value = false; | 1790 bool has_incognito_pref_value = false; |
| 1788 extension_pref_value_map_->GetEffectivePrefValue(pref_key, | 1791 extension_pref_value_map_->GetEffectivePrefValue(pref_key, |
| 1789 true, | 1792 true, |
| 1790 &has_incognito_pref_value); | 1793 &has_incognito_pref_value); |
| 1791 return has_incognito_pref_value; | 1794 return has_incognito_pref_value; |
| 1792 } | 1795 } |
| 1793 | 1796 |
| 1794 const base::DictionaryValue* ExtensionPrefs::GetGeometryCache( | 1797 const base::DictionaryValue* ExtensionPrefs::GetGeometryCache( |
| 1795 const std::string& extension_id) const { | 1798 const std::string& extension_id) const { |
| 1796 const base::DictionaryValue* extension_prefs = GetExtensionPref(extension_id); | 1799 const base::DictionaryValue* extension_prefs = GetExtensionPref(extension_id); |
| 1797 if (!extension_prefs) | 1800 if (!extension_prefs) |
| 1798 return NULL; | 1801 return NULL; |
| 1799 | 1802 |
| 1800 const base::DictionaryValue* ext = NULL; | 1803 const base::DictionaryValue* ext = NULL; |
| 1801 if (!extension_prefs->GetDictionary(kPrefGeometryCache, &ext)) | 1804 if (!extension_prefs->GetDictionary(kPrefGeometryCache, &ext)) |
| 1802 return NULL; | 1805 return NULL; |
| 1803 | 1806 |
| 1804 return ext; | 1807 return ext; |
| 1805 } | 1808 } |
| 1806 | 1809 |
| 1807 void ExtensionPrefs::SetGeometryCache( | 1810 void ExtensionPrefs::SetGeometryCache( |
| 1808 const std::string& extension_id, | 1811 const std::string& extension_id, |
| 1809 scoped_ptr<base::DictionaryValue> cache) { | 1812 scoped_ptr<base::DictionaryValue> cache) { |
| 1810 UpdateExtensionPref(extension_id, kPrefGeometryCache, cache.release()); | 1813 UpdateExtensionPref(extension_id, kPrefGeometryCache, cache.release()); |
| 1811 } | 1814 } |
| 1812 | 1815 |
| 1813 const base::DictionaryValue* ExtensionPrefs::GetInstallSignature() { | 1816 const base::DictionaryValue* ExtensionPrefs::GetInstallSignature() const { |
| 1814 return prefs_->GetDictionary(kInstallSignature); | 1817 return prefs_->GetDictionary(kInstallSignature); |
| 1815 } | 1818 } |
| 1816 | 1819 |
| 1817 void ExtensionPrefs::SetInstallSignature( | 1820 void ExtensionPrefs::SetInstallSignature( |
| 1818 const base::DictionaryValue* signature) { | 1821 const base::DictionaryValue* signature) { |
| 1819 if (signature) { | 1822 if (signature) { |
| 1820 prefs_->Set(kInstallSignature, *signature); | 1823 prefs_->Set(kInstallSignature, *signature); |
| 1821 DVLOG(1) << "SetInstallSignature - saving"; | 1824 DVLOG(1) << "SetInstallSignature - saving"; |
| 1822 } else { | 1825 } else { |
| 1823 DVLOG(1) << "SetInstallSignature - clearing"; | 1826 DVLOG(1) << "SetInstallSignature - clearing"; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1836 return install_parameter; | 1839 return install_parameter; |
| 1837 } | 1840 } |
| 1838 | 1841 |
| 1839 void ExtensionPrefs::SetInstallParam(const std::string& extension_id, | 1842 void ExtensionPrefs::SetInstallParam(const std::string& extension_id, |
| 1840 const std::string& install_parameter) { | 1843 const std::string& install_parameter) { |
| 1841 UpdateExtensionPref(extension_id, | 1844 UpdateExtensionPref(extension_id, |
| 1842 kPrefInstallParam, | 1845 kPrefInstallParam, |
| 1843 new base::StringValue(install_parameter)); | 1846 new base::StringValue(install_parameter)); |
| 1844 } | 1847 } |
| 1845 | 1848 |
| 1846 int ExtensionPrefs::GetCorruptedDisableCount() { | 1849 int ExtensionPrefs::GetCorruptedDisableCount() const { |
| 1847 return prefs_->GetInteger(kCorruptedDisableCount); | 1850 return prefs_->GetInteger(kCorruptedDisableCount); |
| 1848 } | 1851 } |
| 1849 | 1852 |
| 1850 void ExtensionPrefs::IncrementCorruptedDisableCount() { | 1853 void ExtensionPrefs::IncrementCorruptedDisableCount() { |
| 1851 int count = prefs_->GetInteger(kCorruptedDisableCount); | 1854 int count = prefs_->GetInteger(kCorruptedDisableCount); |
| 1852 prefs_->SetInteger(kCorruptedDisableCount, count + 1); | 1855 prefs_->SetInteger(kCorruptedDisableCount, count + 1); |
| 1853 } | 1856 } |
| 1854 | 1857 |
| 1855 ExtensionPrefs::ExtensionPrefs( | 1858 ExtensionPrefs::ExtensionPrefs( |
| 1856 PrefService* prefs, | 1859 PrefService* prefs, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1881 AddObserver(*iter); | 1884 AddObserver(*iter); |
| 1882 } | 1885 } |
| 1883 | 1886 |
| 1884 InitPrefStore(); | 1887 InitPrefStore(); |
| 1885 } | 1888 } |
| 1886 | 1889 |
| 1887 void ExtensionPrefs::SetNeedsStorageGarbageCollection(bool value) { | 1890 void ExtensionPrefs::SetNeedsStorageGarbageCollection(bool value) { |
| 1888 prefs_->SetBoolean(pref_names::kStorageGarbageCollect, value); | 1891 prefs_->SetBoolean(pref_names::kStorageGarbageCollect, value); |
| 1889 } | 1892 } |
| 1890 | 1893 |
| 1891 bool ExtensionPrefs::NeedsStorageGarbageCollection() { | 1894 bool ExtensionPrefs::NeedsStorageGarbageCollection() const { |
| 1892 return prefs_->GetBoolean(pref_names::kStorageGarbageCollect); | 1895 return prefs_->GetBoolean(pref_names::kStorageGarbageCollect); |
| 1893 } | 1896 } |
| 1894 | 1897 |
| 1895 // static | 1898 // static |
| 1896 void ExtensionPrefs::RegisterProfilePrefs( | 1899 void ExtensionPrefs::RegisterProfilePrefs( |
| 1897 user_prefs::PrefRegistrySyncable* registry) { | 1900 user_prefs::PrefRegistrySyncable* registry) { |
| 1898 registry->RegisterDictionaryPref(pref_names::kExtensions); | 1901 registry->RegisterDictionaryPref(pref_names::kExtensions); |
| 1899 registry->RegisterListPref(pref_names::kToolbar, | 1902 registry->RegisterListPref(pref_names::kToolbar, |
| 1900 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 1903 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
| 1901 registry->RegisterIntegerPref(pref_names::kToolbarSize, -1); | 1904 registry->RegisterIntegerPref(pref_names::kToolbarSize, -1); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1918 registry->RegisterIntegerPref(kCorruptedDisableCount, 0); | 1921 registry->RegisterIntegerPref(kCorruptedDisableCount, 0); |
| 1919 | 1922 |
| 1920 #if !defined(OS_MACOSX) | 1923 #if !defined(OS_MACOSX) |
| 1921 registry->RegisterBooleanPref(pref_names::kAppFullscreenAllowed, true); | 1924 registry->RegisterBooleanPref(pref_names::kAppFullscreenAllowed, true); |
| 1922 #endif | 1925 #endif |
| 1923 } | 1926 } |
| 1924 | 1927 |
| 1925 template <class ExtensionIdContainer> | 1928 template <class ExtensionIdContainer> |
| 1926 bool ExtensionPrefs::GetUserExtensionPrefIntoContainer( | 1929 bool ExtensionPrefs::GetUserExtensionPrefIntoContainer( |
| 1927 const char* pref, | 1930 const char* pref, |
| 1928 ExtensionIdContainer* id_container_out) { | 1931 ExtensionIdContainer* id_container_out) const { |
| 1929 DCHECK(id_container_out->empty()); | 1932 DCHECK(id_container_out->empty()); |
| 1930 | 1933 |
| 1931 const base::Value* user_pref_value = prefs_->GetUserPrefValue(pref); | 1934 const base::Value* user_pref_value = prefs_->GetUserPrefValue(pref); |
| 1932 const base::ListValue* user_pref_as_list; | 1935 const base::ListValue* user_pref_as_list; |
| 1933 if (!user_pref_value || !user_pref_value->GetAsList(&user_pref_as_list)) | 1936 if (!user_pref_value || !user_pref_value->GetAsList(&user_pref_as_list)) |
| 1934 return false; | 1937 return false; |
| 1935 | 1938 |
| 1936 std::insert_iterator<ExtensionIdContainer> insert_iterator( | 1939 std::insert_iterator<ExtensionIdContainer> insert_iterator( |
| 1937 *id_container_out, id_container_out->end()); | 1940 *id_container_out, id_container_out->end()); |
| 1938 std::string extension_id; | 1941 std::string extension_id; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1959 list_of_values->Append(new base::StringValue(*iter)); | 1962 list_of_values->Append(new base::StringValue(*iter)); |
| 1960 } | 1963 } |
| 1961 } | 1964 } |
| 1962 | 1965 |
| 1963 void ExtensionPrefs::PopulateExtensionInfoPrefs( | 1966 void ExtensionPrefs::PopulateExtensionInfoPrefs( |
| 1964 const Extension* extension, | 1967 const Extension* extension, |
| 1965 const base::Time install_time, | 1968 const base::Time install_time, |
| 1966 Extension::State initial_state, | 1969 Extension::State initial_state, |
| 1967 int install_flags, | 1970 int install_flags, |
| 1968 const std::string& install_parameter, | 1971 const std::string& install_parameter, |
| 1969 base::DictionaryValue* extension_dict) { | 1972 base::DictionaryValue* extension_dict) const { |
| 1970 extension_dict->Set(kPrefState, new base::FundamentalValue(initial_state)); | 1973 extension_dict->Set(kPrefState, new base::FundamentalValue(initial_state)); |
| 1971 extension_dict->Set(kPrefLocation, | 1974 extension_dict->Set(kPrefLocation, |
| 1972 new base::FundamentalValue(extension->location())); | 1975 new base::FundamentalValue(extension->location())); |
| 1973 extension_dict->Set(kPrefCreationFlags, | 1976 extension_dict->Set(kPrefCreationFlags, |
| 1974 new base::FundamentalValue(extension->creation_flags())); | 1977 new base::FundamentalValue(extension->creation_flags())); |
| 1975 extension_dict->Set(kPrefFromWebStore, | 1978 extension_dict->Set(kPrefFromWebStore, |
| 1976 new base::FundamentalValue(extension->from_webstore())); | 1979 new base::FundamentalValue(extension->from_webstore())); |
| 1977 extension_dict->Set(kPrefFromBookmark, | 1980 extension_dict->Set(kPrefFromBookmark, |
| 1978 new base::FundamentalValue(extension->from_bookmark())); | 1981 new base::FundamentalValue(extension->from_bookmark())); |
| 1979 extension_dict->Set( | 1982 extension_dict->Set( |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2109 extension_pref_value_map_->RegisterExtension( | 2112 extension_pref_value_map_->RegisterExtension( |
| 2110 extension_id, install_time, is_enabled, is_incognito_enabled); | 2113 extension_id, install_time, is_enabled, is_incognito_enabled); |
| 2111 | 2114 |
| 2112 FOR_EACH_OBSERVER( | 2115 FOR_EACH_OBSERVER( |
| 2113 ExtensionPrefsObserver, | 2116 ExtensionPrefsObserver, |
| 2114 observer_list_, | 2117 observer_list_, |
| 2115 OnExtensionRegistered(extension_id, install_time, is_enabled)); | 2118 OnExtensionRegistered(extension_id, install_time, is_enabled)); |
| 2116 } | 2119 } |
| 2117 | 2120 |
| 2118 } // namespace extensions | 2121 } // namespace extensions |
| OLD | NEW |