| 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 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 for (size_t i = 0; i < value->GetSize(); ++i) { | 450 for (size_t i = 0; i < value->GetSize(); ++i) { |
| 451 std::string item; | 451 std::string item; |
| 452 if (!value->GetString(i, &item)) | 452 if (!value->GetString(i, &item)) |
| 453 return false; | 453 return false; |
| 454 result->insert(item); | 454 result->insert(item); |
| 455 } | 455 } |
| 456 | 456 |
| 457 return true; | 457 return true; |
| 458 } | 458 } |
| 459 | 459 |
| 460 void ExtensionPrefs::AddToExtensionPrefStringSet( | 460 void ExtensionPrefs::SetExtensionPrefStringSet( |
| 461 const std::string& extension_id, | 461 const std::string& extension_id, |
| 462 const std::string& pref_key, | 462 const std::string& pref_key, |
| 463 const std::set<std::string>& added_value) { | 463 const std::set<std::string>& new_value) { |
| 464 std::set<std::string> old_value; | |
| 465 std::set<std::string> new_value; | |
| 466 ReadExtensionPrefStringSet(extension_id, pref_key, &old_value); | |
| 467 | |
| 468 std::set_union(old_value.begin(), old_value.end(), | |
| 469 added_value.begin(), added_value.end(), | |
| 470 std::inserter(new_value, new_value.begin())); | |
| 471 | |
| 472 ListValue* value = new ListValue(); | 464 ListValue* value = new ListValue(); |
| 473 for (std::set<std::string>::const_iterator iter = new_value.begin(); | 465 for (std::set<std::string>::const_iterator iter = new_value.begin(); |
| 474 iter != new_value.end(); ++iter) | 466 iter != new_value.end(); ++iter) |
| 475 value->Append(Value::CreateStringValue(*iter)); | 467 value->Append(Value::CreateStringValue(*iter)); |
| 476 | 468 |
| 477 UpdateExtensionPref(extension_id, pref_key, value); | 469 UpdateExtensionPref(extension_id, pref_key, value); |
| 478 } | 470 } |
| 479 | 471 |
| 480 void ExtensionPrefs::SavePrefs() { | 472 void ExtensionPrefs::SavePrefs() { |
| 481 prefs_->ScheduleSavePersistentPrefs(); | 473 prefs_->ScheduleSavePersistentPrefs(); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 return result; | 655 return result; |
| 664 return false; | 656 return false; |
| 665 } | 657 } |
| 666 | 658 |
| 667 void ExtensionPrefs::SetActiveBit(const std::string& extension_id, | 659 void ExtensionPrefs::SetActiveBit(const std::string& extension_id, |
| 668 bool active) { | 660 bool active) { |
| 669 UpdateExtensionPref(extension_id, kActiveBit, | 661 UpdateExtensionPref(extension_id, kActiveBit, |
| 670 Value::CreateBooleanValue(active)); | 662 Value::CreateBooleanValue(active)); |
| 671 } | 663 } |
| 672 | 664 |
| 673 bool ExtensionPrefs::GetGrantedPermissions( | 665 ExtensionPermissionSet* ExtensionPrefs::GetGrantedPermissions( |
| 674 const std::string& extension_id, | 666 const std::string& extension_id, bool* initialized) { |
| 675 bool* full_access, | |
| 676 std::set<std::string>* api_permissions, | |
| 677 URLPatternSet* host_extent) { | |
| 678 CHECK(Extension::IdIsValid(extension_id)); | 667 CHECK(Extension::IdIsValid(extension_id)); |
| 679 | 668 |
| 669 bool full_access; |
| 680 const DictionaryValue* ext = GetExtensionPref(extension_id); | 670 const DictionaryValue* ext = GetExtensionPref(extension_id); |
| 681 if (!ext || !ext->GetBoolean(kPrefGrantedPermissionsAll, full_access)) | 671 if (!ext || !ext->GetBoolean(kPrefGrantedPermissionsAll, &full_access)) { |
| 682 return false; | 672 if (initialized != NULL) |
| 673 *initialized = false; |
| 674 return new ExtensionPermissionSet(); |
| 675 } |
| 683 | 676 |
| 677 if (initialized != NULL) |
| 678 *initialized = true; |
| 679 |
| 680 std::set<std::string> api_permissions_str; |
| 684 ReadExtensionPrefStringSet( | 681 ReadExtensionPrefStringSet( |
| 685 extension_id, kPrefGrantedPermissionsAPI, api_permissions); | 682 extension_id, kPrefGrantedPermissionsAPI, &api_permissions_str); |
| 683 std::set<ExtensionAPIPermission> api_permissions = |
| 684 ExtensionAPIPermission::GetAllByName(api_permissions_str); |
| 686 | 685 |
| 687 std::set<std::string> host_permissions; | 686 std::set<std::string> host_permissions_str; |
| 687 URLPatternSet host_extent; |
| 688 ReadExtensionPrefStringSet( | 688 ReadExtensionPrefStringSet( |
| 689 extension_id, kPrefGrantedPermissionsHost, &host_permissions); | 689 extension_id, kPrefGrantedPermissionsHost, &host_permissions_str); |
| 690 bool allow_file_access = AllowFileAccess(extension_id); | 690 bool allow_file_access = AllowFileAccess(extension_id); |
| 691 | 691 |
| 692 // The granted host permissions contain hosts from the manifest's | 692 // The granted host permissions contain hosts from the manifest's |
| 693 // "permissions" array and from the content script "matches" arrays, | 693 // "permissions" array and from the content script "matches" arrays, |
| 694 // so the URLPattern needs to accept valid schemes from both types. | 694 // so the URLPattern needs to accept valid schemes from both types. |
| 695 for (std::set<std::string>::iterator i = host_permissions.begin(); | 695 for (std::set<std::string>::iterator i = host_permissions_str.begin(); |
| 696 i != host_permissions.end(); ++i) { | 696 i != host_permissions_str.end(); ++i) { |
| 697 URLPattern pattern( | 697 URLPattern pattern( |
| 698 Extension::kValidHostPermissionSchemes | | 698 Extension::kValidHostPermissionSchemes | |
| 699 UserScript::kValidUserScriptSchemes); | 699 UserScript::kValidUserScriptSchemes); |
| 700 | 700 |
| 701 // Parse without strict checks, so that new strict checks do not | 701 // Parse without strict checks, so that new strict checks do not |
| 702 // fail on a pattern in an installed extension. | 702 // fail on a pattern in an installed extension. |
| 703 if (URLPattern::PARSE_SUCCESS != pattern.Parse( | 703 if (URLPattern::PARSE_SUCCESS != pattern.Parse( |
| 704 *i, URLPattern::PARSE_LENIENT)) { | 704 *i, URLPattern::PARSE_LENIENT)) { |
| 705 NOTREACHED(); // Corrupt prefs? Hand editing? | 705 NOTREACHED(); // Corrupt prefs? Hand editing? |
| 706 } else { | 706 } else { |
| 707 if (!allow_file_access && pattern.MatchesScheme(chrome::kFileScheme)) { | 707 if (!allow_file_access && pattern.MatchesScheme(chrome::kFileScheme)) { |
| 708 pattern.set_valid_schemes( | 708 pattern.set_valid_schemes( |
| 709 pattern.valid_schemes() & ~URLPattern::SCHEME_FILE); | 709 pattern.valid_schemes() & ~URLPattern::SCHEME_FILE); |
| 710 } | 710 } |
| 711 host_extent->AddPattern(pattern); | 711 host_extent.AddPattern(pattern); |
| 712 } | 712 } |
| 713 } | 713 } |
| 714 | 714 |
| 715 return true; | 715 return new ExtensionPermissionSet(full_access, api_permissions, host_extent); |
| 716 } | 716 } |
| 717 | 717 |
| 718 void ExtensionPrefs::AddGrantedPermissions( | 718 void ExtensionPrefs::AddGrantedPermissions( |
| 719 const std::string& extension_id, | 719 const std::string& extension_id, |
| 720 const bool full_access, | 720 const ExtensionPermissionSet& permissions) { |
| 721 const std::set<std::string>& api_permissions, | |
| 722 const URLPatternSet& host_extent) { | |
| 723 CHECK(Extension::IdIsValid(extension_id)); | 721 CHECK(Extension::IdIsValid(extension_id)); |
| 724 | 722 |
| 723 scoped_ptr<ExtensionPermissionSet> granted_permissions( |
| 724 GetGrantedPermissions(extension_id, NULL)); |
| 725 |
| 726 // The granted permissions are now the union of the already granted |
| 727 // permissions and the newly granted permissions. |
| 728 scoped_ptr<ExtensionPermissionSet> new_perms( |
| 729 ExtensionPermissionSet::CreateUnion(permissions, *granted_permissions)); |
| 730 |
| 731 // Set the full access (native code) bit. |
| 725 UpdateExtensionPref(extension_id, kPrefGrantedPermissionsAll, | 732 UpdateExtensionPref(extension_id, kPrefGrantedPermissionsAll, |
| 726 Value::CreateBooleanValue(full_access)); | 733 Value::CreateBooleanValue(new_perms->native_code())); |
| 727 | 734 |
| 728 if (!api_permissions.empty()) { | 735 // Set the api permissions. |
| 729 AddToExtensionPrefStringSet( | 736 if (!new_perms->apis().empty()) |
| 730 extension_id, kPrefGrantedPermissionsAPI, api_permissions); | 737 SetExtensionPrefStringSet(extension_id, kPrefGrantedPermissionsAPI, |
| 731 } | 738 new_perms->GetAPIsAsStrings()); |
| 732 | 739 |
| 733 if (!host_extent.is_empty()) { | 740 // Set the host permissions. |
| 734 std::set<std::string> host_permissions; | 741 if (!new_perms->effective_hosts().is_empty()) { |
| 735 ExtentToStringSet(host_extent, &host_permissions); | 742 std::set<std::string> hosts; |
| 736 | 743 ExtentToStringSet(new_perms->effective_hosts(), &hosts); |
| 737 AddToExtensionPrefStringSet( | 744 SetExtensionPrefStringSet(extension_id, kPrefGrantedPermissionsHost, hosts); |
| 738 extension_id, kPrefGrantedPermissionsHost, host_permissions); | |
| 739 } | 745 } |
| 740 } | 746 } |
| 741 | 747 |
| 742 bool ExtensionPrefs::IsIncognitoEnabled(const std::string& extension_id) { | 748 bool ExtensionPrefs::IsIncognitoEnabled(const std::string& extension_id) { |
| 743 return ReadExtensionPrefBoolean(extension_id, kPrefIncognitoEnabled); | 749 return ReadExtensionPrefBoolean(extension_id, kPrefIncognitoEnabled); |
| 744 } | 750 } |
| 745 | 751 |
| 746 void ExtensionPrefs::SetIsIncognitoEnabled(const std::string& extension_id, | 752 void ExtensionPrefs::SetIsIncognitoEnabled(const std::string& extension_id, |
| 747 bool enabled) { | 753 bool enabled) { |
| 748 UpdateExtensionPref(extension_id, kPrefIncognitoEnabled, | 754 UpdateExtensionPref(extension_id, kPrefIncognitoEnabled, |
| (...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1595 prefs->RegisterListPref(prefs::kExtensionInstallAllowList, | 1601 prefs->RegisterListPref(prefs::kExtensionInstallAllowList, |
| 1596 PrefService::UNSYNCABLE_PREF); | 1602 PrefService::UNSYNCABLE_PREF); |
| 1597 prefs->RegisterListPref(prefs::kExtensionInstallDenyList, | 1603 prefs->RegisterListPref(prefs::kExtensionInstallDenyList, |
| 1598 PrefService::UNSYNCABLE_PREF); | 1604 PrefService::UNSYNCABLE_PREF); |
| 1599 prefs->RegisterListPref(prefs::kExtensionInstallForceList, | 1605 prefs->RegisterListPref(prefs::kExtensionInstallForceList, |
| 1600 PrefService::UNSYNCABLE_PREF); | 1606 PrefService::UNSYNCABLE_PREF); |
| 1601 prefs->RegisterStringPref(kWebStoreLogin, | 1607 prefs->RegisterStringPref(kWebStoreLogin, |
| 1602 std::string() /* default_value */, | 1608 std::string() /* default_value */, |
| 1603 PrefService::UNSYNCABLE_PREF); | 1609 PrefService::UNSYNCABLE_PREF); |
| 1604 } | 1610 } |
| OLD | NEW |