Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extension_pref_store.h" | 10 #include "chrome/browser/extensions/extension_pref_store.h" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 const char kPrefGrantedAPIs[] = "granted_permissions.api"; | 106 const char kPrefGrantedAPIs[] = "granted_permissions.api"; |
| 107 const char kPrefGrantedExplicitHosts[] = "granted_permissions.explicit_host"; | 107 const char kPrefGrantedExplicitHosts[] = "granted_permissions.explicit_host"; |
| 108 const char kPrefGrantedScriptableHosts[] = | 108 const char kPrefGrantedScriptableHosts[] = |
| 109 "granted_permissions.scriptable_host"; | 109 "granted_permissions.scriptable_host"; |
| 110 | 110 |
| 111 // The preference names for the old granted permissions scheme. | 111 // The preference names for the old granted permissions scheme. |
| 112 const char kPrefOldGrantedFullAccess[] = "granted_permissions.full"; | 112 const char kPrefOldGrantedFullAccess[] = "granted_permissions.full"; |
| 113 const char kPrefOldGrantedHosts[] = "granted_permissions.host"; | 113 const char kPrefOldGrantedHosts[] = "granted_permissions.host"; |
| 114 const char kPrefOldGrantedAPIs[] = "granted_permissions.api"; | 114 const char kPrefOldGrantedAPIs[] = "granted_permissions.api"; |
| 115 | 115 |
| 116 const char kPrefActiveAPIs[] = "active_permissions.api"; | |
| 117 const char kPrefActiveExplicitHosts[] = "active_permissions.explicit_host"; | |
| 118 const char kPrefActiveScriptableHosts[] = | |
| 119 "active_permissions.scriptable_host"; | |
| 120 | |
| 116 // A preference that indicates when an extension was installed. | 121 // A preference that indicates when an extension was installed. |
| 117 const char kPrefInstallTime[] = "install_time"; | 122 const char kPrefInstallTime[] = "install_time"; |
| 118 | 123 |
| 119 // A preference that indicates whether the extension was installed from the | 124 // A preference that indicates whether the extension was installed from the |
| 120 // Chrome Web Store. | 125 // Chrome Web Store. |
| 121 const char kPrefFromWebStore[] = "from_webstore"; | 126 const char kPrefFromWebStore[] = "from_webstore"; |
| 122 | 127 |
| 123 // A preference that contains any extension-controlled preferences. | 128 // A preference that contains any extension-controlled preferences. |
| 124 const char kPrefPreferences[] = "preferences"; | 129 const char kPrefPreferences[] = "preferences"; |
| 125 | 130 |
| (...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 734 } | 739 } |
| 735 | 740 |
| 736 // Set the scriptable host permissions. | 741 // Set the scriptable host permissions. |
| 737 if (!new_perms->scriptable_hosts().is_empty()) { | 742 if (!new_perms->scriptable_hosts().is_empty()) { |
| 738 SetExtensionPrefURLPatternSet(extension_id, | 743 SetExtensionPrefURLPatternSet(extension_id, |
| 739 kPrefGrantedScriptableHosts, | 744 kPrefGrantedScriptableHosts, |
| 740 new_perms->scriptable_hosts()); | 745 new_perms->scriptable_hosts()); |
| 741 } | 746 } |
| 742 } | 747 } |
| 743 | 748 |
| 749 ExtensionPermissionSet* ExtensionPrefs::GetActivePermissions( | |
|
Mihai Parparita -not on Chrome
2011/07/20 22:03:43
This seems pretty similar to the granted permissio
jstritar
2011/07/22 19:21:55
I factored these out into {Set,Read}ExtensionPrefP
| |
| 750 const std::string& extension_id) { | |
| 751 CHECK(Extension::IdIsValid(extension_id)); | |
| 752 | |
| 753 const DictionaryValue* ext = GetExtensionPref(extension_id); | |
| 754 if (!ext) | |
| 755 return NULL; | |
| 756 | |
| 757 // Retrieve the API permissions. | |
| 758 ExtensionAPIPermissionSet apis; | |
| 759 const ListValue* api_values = NULL; | |
| 760 if (ReadExtensionPrefList(extension_id, kPrefActiveAPIs, &api_values)) { | |
| 761 ExtensionPermissionsInfo* info = ExtensionPermissionsInfo::GetInstance(); | |
| 762 for (size_t i = 0; i < api_values->GetSize(); ++i) { | |
| 763 std::string permission_name; | |
| 764 if (api_values->GetString(i, &permission_name)) { | |
| 765 ExtensionAPIPermission *permission = info->GetByName(permission_name); | |
| 766 if (permission) | |
| 767 apis.insert(permission->id()); | |
| 768 } | |
| 769 } | |
| 770 } | |
| 771 | |
| 772 // Retrieve the explicit host permissions. | |
| 773 URLPatternSet explicit_hosts; | |
| 774 ReadExtensionPrefURLPatternSet( | |
| 775 extension_id, kPrefActiveExplicitHosts, | |
| 776 &explicit_hosts, Extension::kValidHostPermissionSchemes); | |
| 777 | |
| 778 // Retrieve the scriptable host permissions. | |
| 779 URLPatternSet scriptable_hosts; | |
| 780 ReadExtensionPrefURLPatternSet( | |
| 781 extension_id, kPrefActiveScriptableHosts, | |
| 782 &scriptable_hosts, UserScript::kValidUserScriptSchemes); | |
| 783 | |
| 784 return new ExtensionPermissionSet(apis, explicit_hosts, scriptable_hosts); | |
| 785 } | |
| 786 | |
| 787 void ExtensionPrefs::SetActivePermissions( | |
| 788 const std::string& extension_id, | |
| 789 const ExtensionPermissionSet* permissions) { | |
| 790 // Set the API permissions. | |
| 791 ListValue* api_values = new ListValue(); | |
| 792 ExtensionAPIPermissionSet apis = permissions->apis(); | |
| 793 ExtensionPermissionsInfo* info = ExtensionPermissionsInfo::GetInstance(); | |
| 794 for (ExtensionAPIPermissionSet::const_iterator i = apis.begin(); | |
| 795 i != apis.end(); ++i) { | |
| 796 ExtensionAPIPermission* perm = info->GetByID(*i); | |
| 797 if (perm) | |
| 798 api_values->Append(Value::CreateStringValue(perm->name())); | |
| 799 } | |
| 800 UpdateExtensionPref(extension_id, kPrefActiveAPIs, api_values); | |
| 801 | |
| 802 // Set the explicit host permissions. | |
| 803 if (!permissions->explicit_hosts().is_empty()) { | |
| 804 SetExtensionPrefURLPatternSet(extension_id, | |
| 805 kPrefActiveExplicitHosts, | |
| 806 permissions->explicit_hosts()); | |
| 807 } | |
| 808 | |
| 809 // Set the scriptable host permissions. | |
| 810 if (!permissions->scriptable_hosts().is_empty()) { | |
| 811 SetExtensionPrefURLPatternSet(extension_id, | |
| 812 kPrefActiveScriptableHosts, | |
| 813 permissions->scriptable_hosts()); | |
| 814 } | |
| 815 } | |
| 816 | |
| 744 bool ExtensionPrefs::IsIncognitoEnabled(const std::string& extension_id) { | 817 bool ExtensionPrefs::IsIncognitoEnabled(const std::string& extension_id) { |
| 745 return ReadExtensionPrefBoolean(extension_id, kPrefIncognitoEnabled); | 818 return ReadExtensionPrefBoolean(extension_id, kPrefIncognitoEnabled); |
| 746 } | 819 } |
| 747 | 820 |
| 748 void ExtensionPrefs::SetIsIncognitoEnabled(const std::string& extension_id, | 821 void ExtensionPrefs::SetIsIncognitoEnabled(const std::string& extension_id, |
| 749 bool enabled) { | 822 bool enabled) { |
| 750 UpdateExtensionPref(extension_id, kPrefIncognitoEnabled, | 823 UpdateExtensionPref(extension_id, kPrefIncognitoEnabled, |
| 751 Value::CreateBooleanValue(enabled)); | 824 Value::CreateBooleanValue(enabled)); |
| 752 } | 825 } |
| 753 | 826 |
| (...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1610 prefs->RegisterListPref(prefs::kExtensionInstallAllowList, | 1683 prefs->RegisterListPref(prefs::kExtensionInstallAllowList, |
| 1611 PrefService::UNSYNCABLE_PREF); | 1684 PrefService::UNSYNCABLE_PREF); |
| 1612 prefs->RegisterListPref(prefs::kExtensionInstallDenyList, | 1685 prefs->RegisterListPref(prefs::kExtensionInstallDenyList, |
| 1613 PrefService::UNSYNCABLE_PREF); | 1686 PrefService::UNSYNCABLE_PREF); |
| 1614 prefs->RegisterListPref(prefs::kExtensionInstallForceList, | 1687 prefs->RegisterListPref(prefs::kExtensionInstallForceList, |
| 1615 PrefService::UNSYNCABLE_PREF); | 1688 PrefService::UNSYNCABLE_PREF); |
| 1616 prefs->RegisterStringPref(kWebStoreLogin, | 1689 prefs->RegisterStringPref(kWebStoreLogin, |
| 1617 std::string() /* default_value */, | 1690 std::string() /* default_value */, |
| 1618 PrefService::UNSYNCABLE_PREF); | 1691 PrefService::UNSYNCABLE_PREF); |
| 1619 } | 1692 } |
| OLD | NEW |