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" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 // permissions, for backwards compatibility reasons, and we can still prompt | 117 // permissions, for backwards compatibility reasons, and we can still prompt |
118 // the user to accept them once recognized. We store the active permission | 118 // the user to accept them once recognized. We store the active permission |
119 // permissions because they may differ from those defined in the manifest. | 119 // permissions because they may differ from those defined in the manifest. |
120 const char kPrefActivePermissions[] = "active_permissions"; | 120 const char kPrefActivePermissions[] = "active_permissions"; |
121 const char kPrefGrantedPermissions[] = "granted_permissions"; | 121 const char kPrefGrantedPermissions[] = "granted_permissions"; |
122 | 122 |
123 // The preference names for ExtensionPermissionSet values. | 123 // The preference names for ExtensionPermissionSet values. |
124 const char kPrefAPIs[] = "api"; | 124 const char kPrefAPIs[] = "api"; |
125 const char kPrefExplicitHosts[] = "explicit_host"; | 125 const char kPrefExplicitHosts[] = "explicit_host"; |
126 const char kPrefScriptableHosts[] = "scriptable_host"; | 126 const char kPrefScriptableHosts[] = "scriptable_host"; |
127 const char kPrefScopes[] = "scopes"; | |
Yoyo Zhou
2012/04/24 23:16:36
The ones just above this aren't plural, so conside
jstritar
2012/04/24 23:33:34
Yeah, this is weird.... I don't remember why we ma
| |
127 | 128 |
128 // The preference names for the old granted permissions scheme. | 129 // The preference names for the old granted permissions scheme. |
129 const char kPrefOldGrantedFullAccess[] = "granted_permissions.full"; | 130 const char kPrefOldGrantedFullAccess[] = "granted_permissions.full"; |
130 const char kPrefOldGrantedHosts[] = "granted_permissions.host"; | 131 const char kPrefOldGrantedHosts[] = "granted_permissions.host"; |
131 const char kPrefOldGrantedAPIs[] = "granted_permissions.api"; | 132 const char kPrefOldGrantedAPIs[] = "granted_permissions.api"; |
132 | 133 |
133 // A preference that indicates when an extension was installed. | 134 // A preference that indicates when an extension was installed. |
134 const char kPrefInstallTime[] = "install_time"; | 135 const char kPrefInstallTime[] = "install_time"; |
135 | 136 |
136 // A preference that indicates whether the extension was installed from the | 137 // A preference that indicates whether the extension was installed from the |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
488 ReadExtensionPrefURLPatternSet( | 489 ReadExtensionPrefURLPatternSet( |
489 extension_id, JoinPrefs(pref_key, kPrefExplicitHosts), | 490 extension_id, JoinPrefs(pref_key, kPrefExplicitHosts), |
490 &explicit_hosts, Extension::kValidHostPermissionSchemes); | 491 &explicit_hosts, Extension::kValidHostPermissionSchemes); |
491 | 492 |
492 // Retrieve the scriptable host permissions. | 493 // Retrieve the scriptable host permissions. |
493 URLPatternSet scriptable_hosts; | 494 URLPatternSet scriptable_hosts; |
494 ReadExtensionPrefURLPatternSet( | 495 ReadExtensionPrefURLPatternSet( |
495 extension_id, JoinPrefs(pref_key, kPrefScriptableHosts), | 496 extension_id, JoinPrefs(pref_key, kPrefScriptableHosts), |
496 &scriptable_hosts, UserScript::kValidUserScriptSchemes); | 497 &scriptable_hosts, UserScript::kValidUserScriptSchemes); |
497 | 498 |
498 return new ExtensionPermissionSet(apis, explicit_hosts, scriptable_hosts); | 499 // Retrieve the oauth2 scopes. |
500 ExtensionOAuth2Scopes scopes; | |
501 const ListValue* scope_values = NULL; | |
502 std::string scope_pref = JoinPrefs(pref_key, kPrefScopes); | |
503 if (ReadExtensionPrefList(extension_id, scope_pref, &scope_values)) { | |
504 for (size_t i = 0; i < scope_values->GetSize(); ++i) { | |
505 std::string scope; | |
506 if (scope_values->GetString(i, &scope)) | |
507 scopes.insert(scope); | |
508 } | |
509 } | |
510 | |
511 return new ExtensionPermissionSet( | |
512 apis, explicit_hosts, scriptable_hosts, scopes); | |
499 } | 513 } |
500 | 514 |
501 void ExtensionPrefs::SetExtensionPrefPermissionSet( | 515 void ExtensionPrefs::SetExtensionPrefPermissionSet( |
502 const std::string& extension_id, | 516 const std::string& extension_id, |
503 const std::string& pref_key, | 517 const std::string& pref_key, |
504 const ExtensionPermissionSet* new_value) { | 518 const ExtensionPermissionSet* new_value) { |
505 // Set the API permissions. | 519 // Set the API permissions. |
506 ListValue* api_values = new ListValue(); | 520 ListValue* api_values = new ListValue(); |
507 ExtensionAPIPermissionSet apis = new_value->apis(); | 521 ExtensionAPIPermissionSet apis = new_value->apis(); |
508 ExtensionPermissionsInfo* info = ExtensionPermissionsInfo::GetInstance(); | 522 ExtensionPermissionsInfo* info = ExtensionPermissionsInfo::GetInstance(); |
(...skipping 12 matching lines...) Expand all Loading... | |
521 JoinPrefs(pref_key, kPrefExplicitHosts), | 535 JoinPrefs(pref_key, kPrefExplicitHosts), |
522 new_value->explicit_hosts()); | 536 new_value->explicit_hosts()); |
523 } | 537 } |
524 | 538 |
525 // Set the scriptable host permissions. | 539 // Set the scriptable host permissions. |
526 if (!new_value->scriptable_hosts().is_empty()) { | 540 if (!new_value->scriptable_hosts().is_empty()) { |
527 SetExtensionPrefURLPatternSet(extension_id, | 541 SetExtensionPrefURLPatternSet(extension_id, |
528 JoinPrefs(pref_key, kPrefScriptableHosts), | 542 JoinPrefs(pref_key, kPrefScriptableHosts), |
529 new_value->scriptable_hosts()); | 543 new_value->scriptable_hosts()); |
530 } | 544 } |
545 | |
546 // Set the oauth2 scopes. | |
547 ExtensionOAuth2Scopes scopes = new_value->scopes(); | |
548 if (!scopes.empty()) { | |
549 ListValue* scope_values = new ListValue(); | |
550 for (ExtensionOAuth2Scopes::iterator i = scopes.begin(); | |
551 i != scopes.end(); ++i) { | |
552 scope_values->Append(Value::CreateStringValue(*i)); | |
553 } | |
554 std::string scope_pref = JoinPrefs(pref_key, kPrefScopes); | |
555 UpdateExtensionPref(extension_id, scope_pref, scope_values); | |
556 } | |
531 } | 557 } |
532 | 558 |
533 // static | 559 // static |
534 bool ExtensionPrefs::IsBlacklistBitSet(DictionaryValue* ext) { | 560 bool ExtensionPrefs::IsBlacklistBitSet(DictionaryValue* ext) { |
535 return ReadBooleanFromPref(ext, kPrefBlacklist); | 561 return ReadBooleanFromPref(ext, kPrefBlacklist); |
536 } | 562 } |
537 | 563 |
538 bool ExtensionPrefs::IsExtensionBlacklisted(const std::string& extension_id) { | 564 bool ExtensionPrefs::IsExtensionBlacklisted(const std::string& extension_id) { |
539 return ReadExtensionPrefBoolean(extension_id, kPrefBlacklist); | 565 return ReadExtensionPrefBoolean(extension_id, kPrefBlacklist); |
540 } | 566 } |
(...skipping 1304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1845 prefs->RegisterStringPref(prefs::kExtensionBlacklistUpdateVersion, | 1871 prefs->RegisterStringPref(prefs::kExtensionBlacklistUpdateVersion, |
1846 "0", // default value | 1872 "0", // default value |
1847 PrefService::UNSYNCABLE_PREF); | 1873 PrefService::UNSYNCABLE_PREF); |
1848 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, | 1874 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, |
1849 0, // default value | 1875 0, // default value |
1850 PrefService::UNSYNCABLE_PREF); | 1876 PrefService::UNSYNCABLE_PREF); |
1851 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, | 1877 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, |
1852 0, // default value | 1878 0, // default value |
1853 PrefService::UNSYNCABLE_PREF); | 1879 PrefService::UNSYNCABLE_PREF); |
1854 } | 1880 } |
OLD | NEW |