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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 | 60 |
| 61 // Path for settings specific to blacklist update. | 61 // Path for settings specific to blacklist update. |
| 62 const char kExtensionsBlacklistUpdate[] = "extensions.blacklistupdate"; | 62 const char kExtensionsBlacklistUpdate[] = "extensions.blacklistupdate"; |
| 63 | 63 |
| 64 // Path and sub-keys for the idle install info dictionary preference. | 64 // Path and sub-keys for the idle install info dictionary preference. |
| 65 const char kIdleInstallInfo[] = "idle_install_info"; | 65 const char kIdleInstallInfo[] = "idle_install_info"; |
| 66 const char kIdleInstallInfoCrxPath[] = "crx_path"; | 66 const char kIdleInstallInfoCrxPath[] = "crx_path"; |
| 67 const char kIdleInstallInfoVersion[] = "version"; | 67 const char kIdleInstallInfoVersion[] = "version"; |
| 68 const char kIdleInstallInfoFetchTime[] = "fetch_time"; | 68 const char kIdleInstallInfoFetchTime[] = "fetch_time"; |
| 69 | 69 |
| 70 | |
| 71 // A preference that, if true, will allow this extension to run in incognito | 70 // A preference that, if true, will allow this extension to run in incognito |
| 72 // mode. | 71 // mode. |
| 73 const char kPrefIncognitoEnabled[] = "incognito"; | 72 const char kPrefIncognitoEnabled[] = "incognito"; |
| 74 | 73 |
| 75 // A preference to control whether an extension is allowed to inject script in | 74 // A preference to control whether an extension is allowed to inject script in |
| 76 // pages with file URLs. | 75 // pages with file URLs. |
| 77 const char kPrefAllowFileAccess[] = "allowFileAccess"; | 76 const char kPrefAllowFileAccess[] = "allowFileAccess"; |
| 78 | 77 |
| 79 // A preference set by the web store to indicate login information for | 78 // A preference set by the web store to indicate login information for |
| 80 // purchased apps. | 79 // purchased apps. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 93 // A preference specifying if the user dragged the app on the NTP. | 92 // A preference specifying if the user dragged the app on the NTP. |
| 94 const char kPrefUserDraggedApp[] = "user_dragged_app_ntp"; | 93 const char kPrefUserDraggedApp[] = "user_dragged_app_ntp"; |
| 95 | 94 |
| 96 // A preference for storing extra data sent in update checks for an extension. | 95 // A preference for storing extra data sent in update checks for an extension. |
| 97 const char kUpdateUrlData[] = "update_url_data"; | 96 const char kUpdateUrlData[] = "update_url_data"; |
| 98 | 97 |
| 99 // Whether the browser action is visible in the toolbar. | 98 // Whether the browser action is visible in the toolbar. |
| 100 const char kBrowserActionVisible[] = "browser_action_visible"; | 99 const char kBrowserActionVisible[] = "browser_action_visible"; |
| 101 | 100 |
| 102 // Preferences that hold which permissions the user has granted the extension. | 101 // Preferences that hold which permissions the user has granted the extension. |
| 103 // We explicitly keep track of these so that extensions can contain unknown | 102 // We explicity keep track of these so that extensions can contain unknown |
|
Matt Perry
2011/06/21 00:43:10
typo
jstritar
2011/06/21 23:12:16
Done.
| |
| 104 // permissions, for backwards compatibility reasons, and we can still prompt | 103 // permissions, for backwards compatibility reasons, and we can still prompt |
| 105 // the user to accept them once recognized. | 104 // the user to accept them once recognized. |
| 106 const char kPrefGrantedPermissionsAPI[] = "granted_permissions.api"; | 105 const char kPrefGrantedAPIs[] = "granted_permissions.api"; |
| 107 const char kPrefGrantedPermissionsHost[] = "granted_permissions.host"; | 106 const char kPrefGrantedExplicitHosts[] = "granted_permissions.explicit_host"; |
| 108 const char kPrefGrantedPermissionsAll[] = "granted_permissions.full"; | 107 const char kPrefGrantedScriptableHosts[] = |
| 108 "granted_permissions.scriptable_host"; | |
| 109 | |
| 110 // The preference names for the old granted permissions scheme. | |
| 111 const char kPrefOldGrantedFullAccess[] = "granted_permissions.full"; | |
| 112 const char kPrefOldGrantedHosts[] = "granted_permissions.host"; | |
| 113 const char kPrefOldGrantedAPIs[] = "granted_permissions.api"; | |
| 109 | 114 |
| 110 // A preference that indicates when an extension was installed. | 115 // A preference that indicates when an extension was installed. |
| 111 const char kPrefInstallTime[] = "install_time"; | 116 const char kPrefInstallTime[] = "install_time"; |
| 112 | 117 |
| 113 // A preference that contains any extension-controlled preferences. | 118 // A preference that contains any extension-controlled preferences. |
| 114 const char kPrefPreferences[] = "preferences"; | 119 const char kPrefPreferences[] = "preferences"; |
| 115 | 120 |
| 116 // A preference that contains any extension-controlled incognito preferences. | 121 // A preference that contains any extension-controlled incognito preferences. |
| 117 const char kPrefIncognitoPreferences[] = "incognito_preferences"; | 122 const char kPrefIncognitoPreferences[] = "incognito_preferences"; |
| 118 | 123 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 Value* extension_prefs = NULL; | 254 Value* extension_prefs = NULL; |
| 250 CHECK(update_dictionary->RemoveWithoutPathExpansion( | 255 CHECK(update_dictionary->RemoveWithoutPathExpansion( |
| 251 i->first, &extension_prefs)); | 256 i->first, &extension_prefs)); |
| 252 update_dictionary->SetWithoutPathExpansion(i->second, extension_prefs); | 257 update_dictionary->SetWithoutPathExpansion(i->second, extension_prefs); |
| 253 } | 258 } |
| 254 | 259 |
| 255 prefs->ScheduleSavePersistentPrefs(); | 260 prefs->ScheduleSavePersistentPrefs(); |
| 256 } | 261 } |
| 257 } | 262 } |
| 258 | 263 |
| 259 static void ExtentToStringSet(const URLPatternSet& host_extent, | |
| 260 std::set<std::string>* result) { | |
| 261 URLPatternList patterns = host_extent.patterns(); | |
| 262 URLPatternList::const_iterator i; | |
| 263 | |
| 264 for (i = patterns.begin(); i != patterns.end(); ++i) | |
| 265 result->insert(i->GetAsString()); | |
| 266 } | |
| 267 | |
| 268 } // namespace | 264 } // namespace |
| 269 | 265 |
| 270 ExtensionPrefs::ExtensionPrefs( | 266 ExtensionPrefs::ExtensionPrefs( |
| 271 PrefService* prefs, | 267 PrefService* prefs, |
| 272 const FilePath& root_dir, | 268 const FilePath& root_dir, |
| 273 ExtensionPrefValueMap* extension_pref_value_map) | 269 ExtensionPrefValueMap* extension_pref_value_map) |
| 274 : prefs_(prefs), | 270 : prefs_(prefs), |
| 275 install_directory_(root_dir), | 271 install_directory_(root_dir), |
| 276 extension_pref_value_map_(extension_pref_value_map), | 272 extension_pref_value_map_(extension_pref_value_map), |
| 277 content_settings_store_(new ExtensionContentSettingsStore()) { | 273 content_settings_store_(new ExtensionContentSettingsStore()) { |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 430 const ListValue** out_value) { | 426 const ListValue** out_value) { |
| 431 const DictionaryValue* ext = GetExtensionPref(extension_id); | 427 const DictionaryValue* ext = GetExtensionPref(extension_id); |
| 432 ListValue* out = NULL; | 428 ListValue* out = NULL; |
| 433 if (!ext || !ext->GetList(pref_key, &out)) | 429 if (!ext || !ext->GetList(pref_key, &out)) |
| 434 return false; | 430 return false; |
| 435 *out_value = out; | 431 *out_value = out; |
| 436 | 432 |
| 437 return out_value != NULL; | 433 return out_value != NULL; |
| 438 } | 434 } |
| 439 | 435 |
| 440 bool ExtensionPrefs::ReadExtensionPrefStringSet( | 436 bool ExtensionPrefs::ReadExtensionPrefURLPatternSet( |
| 441 const std::string& extension_id, | 437 const std::string& extension_id, |
| 442 const std::string& pref_key, | 438 const std::string& pref_key, |
| 443 std::set<std::string>* result) { | 439 URLPatternSet* result, |
| 440 int valid_schemes) { | |
| 444 const ListValue* value = NULL; | 441 const ListValue* value = NULL; |
| 445 if (!ReadExtensionPrefList(extension_id, pref_key, &value)) | 442 if (!ReadExtensionPrefList(extension_id, pref_key, &value)) |
| 446 return false; | 443 return false; |
| 447 | 444 |
| 448 result->clear(); | 445 bool allow_file_access = AllowFileAccess(extension_id); |
|
Matt Perry
2011/06/21 00:43:10
should you clear result to be consistent with the
jstritar
2011/06/21 23:12:16
Yes, thanks. Done.
| |
| 449 | 446 |
| 450 for (size_t i = 0; i < value->GetSize(); ++i) { | 447 for (size_t i = 0; i < value->GetSize(); ++i) { |
| 451 std::string item; | 448 std::string item; |
| 452 if (!value->GetString(i, &item)) | 449 if (!value->GetString(i, &item)) |
| 453 return false; | 450 return false; |
| 454 result->insert(item); | 451 URLPattern pattern(valid_schemes); |
| 452 if (pattern.Parse(item, URLPattern::PARSE_LENIENT) != | |
| 453 URLPattern::PARSE_SUCCESS) { | |
| 454 NOTREACHED(); | |
| 455 return false; | |
| 456 } | |
| 457 if (!allow_file_access && pattern.MatchesScheme(chrome::kFileScheme)) { | |
| 458 pattern.set_valid_schemes( | |
| 459 pattern.valid_schemes() & ~URLPattern::SCHEME_FILE); | |
|
Matt Perry
2011/06/21 00:43:10
indent +2
jstritar
2011/06/21 23:12:16
Done.
| |
| 460 } | |
| 461 result->AddPattern(pattern); | |
| 455 } | 462 } |
| 456 | 463 |
| 457 return true; | 464 return true; |
| 458 } | 465 } |
| 459 | 466 |
| 460 void ExtensionPrefs::AddToExtensionPrefStringSet( | 467 void ExtensionPrefs::SetExtensionPrefURLPatternSet( |
| 461 const std::string& extension_id, | 468 const std::string& extension_id, |
| 462 const std::string& pref_key, | 469 const std::string& pref_key, |
| 463 const std::set<std::string>& added_value) { | 470 const URLPatternSet& 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(); | 471 ListValue* value = new ListValue(); |
| 473 for (std::set<std::string>::const_iterator iter = new_value.begin(); | 472 for (URLPatternList::const_iterator i = new_value.patterns().begin(); |
| 474 iter != new_value.end(); ++iter) | 473 i != new_value.patterns().end(); ++i) |
| 475 value->Append(Value::CreateStringValue(*iter)); | 474 value->Append(Value::CreateStringValue(i->GetAsString())); |
| 476 | 475 |
| 477 UpdateExtensionPref(extension_id, pref_key, value); | 476 UpdateExtensionPref(extension_id, pref_key, value); |
| 478 } | 477 } |
| 479 | 478 |
| 480 void ExtensionPrefs::SavePrefs() { | 479 void ExtensionPrefs::SavePrefs() { |
| 481 prefs_->ScheduleSavePersistentPrefs(); | 480 prefs_->ScheduleSavePersistentPrefs(); |
| 482 } | 481 } |
| 483 | 482 |
| 484 // static | 483 // static |
| 485 bool ExtensionPrefs::IsBlacklistBitSet(DictionaryValue* ext) { | 484 bool ExtensionPrefs::IsBlacklistBitSet(DictionaryValue* ext) { |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 663 return result; | 662 return result; |
| 664 return false; | 663 return false; |
| 665 } | 664 } |
| 666 | 665 |
| 667 void ExtensionPrefs::SetActiveBit(const std::string& extension_id, | 666 void ExtensionPrefs::SetActiveBit(const std::string& extension_id, |
| 668 bool active) { | 667 bool active) { |
| 669 UpdateExtensionPref(extension_id, kActiveBit, | 668 UpdateExtensionPref(extension_id, kActiveBit, |
| 670 Value::CreateBooleanValue(active)); | 669 Value::CreateBooleanValue(active)); |
| 671 } | 670 } |
| 672 | 671 |
| 673 bool ExtensionPrefs::GetGrantedPermissions( | 672 void ExtensionPrefs::MigratePermissions(const ExtensionIdSet& extension_ids) { |
| 674 const std::string& extension_id, | 673 for (ExtensionIdSet::const_iterator ext_id = extension_ids.begin(); |
| 675 bool* full_access, | 674 ext_id != extension_ids.end(); ++ext_id) { |
| 676 std::set<std::string>* api_permissions, | 675 |
| 677 URLPatternSet* host_extent) { | 676 // An extension's granted permissions need to be migrated if the |
| 677 // full_access bit is present. This bit was always present in the previous | |
| 678 // scheme and is never present now. | |
| 679 bool full_access; | |
| 680 const DictionaryValue* ext = GetExtensionPref(*ext_id); | |
| 681 if (!ext || !ext->GetBoolean(kPrefOldGrantedFullAccess, &full_access)) | |
| 682 continue; | |
| 683 | |
| 684 // Remove the full access bit (empty list will get trimmed). | |
| 685 UpdateExtensionPref( | |
| 686 *ext_id, kPrefOldGrantedFullAccess, new ListValue()); | |
| 687 | |
| 688 // Migrate the API permission list to use the enumeration values rather | |
|
Matt Perry
2011/06/21 00:43:10
I think this is dangerous. It requires us to commi
jstritar
2011/06/21 23:12:16
Good point. We're already committed to preserving
| |
| 689 // than string names. Also, add the plugin permission if the full | |
| 690 // access bit had been set. | |
| 691 ListValue* new_apis = new ListValue(); | |
| 692 if (full_access) | |
| 693 new_apis->Append(Value::CreateIntegerValue( | |
| 694 ExtensionAPIPermission::kPlugin)); | |
| 695 | |
| 696 ListValue* apis = NULL; | |
| 697 if (ext->GetList(kPrefGrantedAPIs, &apis)) { | |
| 698 for (size_t i = 0; i < apis->GetSize(); ++i) { | |
| 699 std::string api; | |
| 700 if (apis->GetString(i, &api)) { | |
| 701 ExtensionAPIPermission* perm = | |
| 702 ExtensionPermissionsInfo::GetByName(api); | |
| 703 if (perm) | |
| 704 new_apis->Append(Value::CreateIntegerValue(perm->id())); | |
| 705 } | |
| 706 } | |
| 707 } | |
| 708 UpdateExtensionPref(*ext_id, kPrefGrantedAPIs, new_apis); | |
| 709 | |
| 710 | |
| 711 // The granted permissions originally only held the effective hosts, | |
| 712 // which are a combination of host and user script host permissions. | |
| 713 // We now maintain these lists separately. For migration purposes, it | |
| 714 // does not matter how we treat the old effective hosts as long as the | |
| 715 // new effective hosts will be the same, so we move them to explicit | |
| 716 // host permissions. | |
| 717 ListValue* hosts; | |
| 718 if (ext->GetList(kPrefOldGrantedHosts, &hosts)) { | |
| 719 UpdateExtensionPref( | |
| 720 *ext_id, kPrefGrantedExplicitHosts, hosts->DeepCopy()); | |
| 721 | |
| 722 // We can get rid of the old one by setting it to an empty list. | |
| 723 UpdateExtensionPref(*ext_id, kPrefOldGrantedHosts, new ListValue()); | |
| 724 } | |
| 725 } | |
| 726 SavePrefs(); | |
| 727 } | |
| 728 | |
| 729 ExtensionPermissionSet* ExtensionPrefs::GetGrantedPermissions( | |
| 730 const std::string& extension_id) { | |
| 678 CHECK(Extension::IdIsValid(extension_id)); | 731 CHECK(Extension::IdIsValid(extension_id)); |
| 679 | 732 |
| 680 const DictionaryValue* ext = GetExtensionPref(extension_id); | 733 const DictionaryValue* ext = GetExtensionPref(extension_id); |
| 681 if (!ext || !ext->GetBoolean(kPrefGrantedPermissionsAll, full_access)) | 734 if (!ext) |
| 682 return false; | 735 return NULL; |
| 683 | 736 |
| 684 ReadExtensionPrefStringSet( | 737 // Retrieve the API permissions. |
| 685 extension_id, kPrefGrantedPermissionsAPI, api_permissions); | 738 ExtensionAPIPermissionSet apis; |
| 686 | 739 const ListValue* api_values = NULL; |
| 687 std::set<std::string> host_permissions; | 740 if (ReadExtensionPrefList(extension_id, kPrefGrantedAPIs, &api_values)) { |
| 688 ReadExtensionPrefStringSet( | 741 for (size_t i = 0; i < api_values->GetSize(); ++i) { |
| 689 extension_id, kPrefGrantedPermissionsHost, &host_permissions); | 742 int api_id; |
| 690 bool allow_file_access = AllowFileAccess(extension_id); | 743 if (api_values->GetInteger(i, &api_id)) |
| 691 | 744 apis.insert(static_cast<ExtensionAPIPermission::Id>(api_id)); |
| 692 // The granted host permissions contain hosts from the manifest's | |
| 693 // "permissions" array and from the content script "matches" arrays, | |
| 694 // so the URLPattern needs to accept valid schemes from both types. | |
| 695 for (std::set<std::string>::iterator i = host_permissions.begin(); | |
| 696 i != host_permissions.end(); ++i) { | |
| 697 URLPattern pattern( | |
| 698 Extension::kValidHostPermissionSchemes | | |
| 699 UserScript::kValidUserScriptSchemes); | |
| 700 | |
| 701 // Parse without strict checks, so that new strict checks do not | |
| 702 // fail on a pattern in an installed extension. | |
| 703 if (URLPattern::PARSE_SUCCESS != pattern.Parse( | |
| 704 *i, URLPattern::PARSE_LENIENT)) { | |
| 705 NOTREACHED(); // Corrupt prefs? Hand editing? | |
| 706 } else { | |
| 707 if (!allow_file_access && pattern.MatchesScheme(chrome::kFileScheme)) { | |
| 708 pattern.set_valid_schemes( | |
| 709 pattern.valid_schemes() & ~URLPattern::SCHEME_FILE); | |
| 710 } | |
| 711 host_extent->AddPattern(pattern); | |
| 712 } | 745 } |
| 713 } | 746 } |
| 714 | 747 |
| 715 return true; | 748 // Retrieve the explicit host permissions. |
| 749 URLPatternSet explicit_hosts; | |
| 750 ReadExtensionPrefURLPatternSet( | |
| 751 extension_id, kPrefGrantedExplicitHosts, | |
| 752 &explicit_hosts, Extension::kValidHostPermissionSchemes); | |
| 753 | |
| 754 // Retrieve the scriptable host permissions. | |
| 755 URLPatternSet scriptable_hosts; | |
| 756 ReadExtensionPrefURLPatternSet( | |
| 757 extension_id, kPrefGrantedScriptableHosts, | |
| 758 &scriptable_hosts, UserScript::kValidUserScriptSchemes); | |
| 759 | |
| 760 return new ExtensionPermissionSet(apis, explicit_hosts, scriptable_hosts); | |
| 716 } | 761 } |
| 717 | 762 |
| 718 void ExtensionPrefs::AddGrantedPermissions( | 763 void ExtensionPrefs::AddGrantedPermissions( |
| 719 const std::string& extension_id, | 764 const std::string& extension_id, |
| 720 const bool full_access, | 765 const ExtensionPermissionSet* permissions) { |
| 721 const std::set<std::string>& api_permissions, | |
| 722 const URLPatternSet& host_extent) { | |
| 723 CHECK(Extension::IdIsValid(extension_id)); | 766 CHECK(Extension::IdIsValid(extension_id)); |
| 724 | 767 |
| 725 UpdateExtensionPref(extension_id, kPrefGrantedPermissionsAll, | 768 scoped_ptr<ExtensionPermissionSet> granted_permissions( |
| 726 Value::CreateBooleanValue(full_access)); | 769 GetGrantedPermissions(extension_id)); |
| 727 | 770 |
| 728 if (!api_permissions.empty()) { | 771 // The new granted permissions are the union of the already granted |
| 729 AddToExtensionPrefStringSet( | 772 // permissions and the newly granted permissions. |
| 730 extension_id, kPrefGrantedPermissionsAPI, api_permissions); | 773 scoped_ptr<ExtensionPermissionSet> new_perms( |
| 774 ExtensionPermissionSet::CreateUnion( | |
| 775 permissions, granted_permissions.get())); | |
| 776 | |
| 777 // Set the API permissions. | |
| 778 ListValue* api_values = new ListValue(); | |
| 779 ExtensionAPIPermissionSet apis = new_perms->apis(); | |
| 780 for (ExtensionAPIPermissionSet::const_iterator i = apis.begin(); | |
| 781 i != apis.end(); ++i) { | |
| 782 api_values->Append(Value::CreateIntegerValue(*i)); | |
| 783 } | |
| 784 UpdateExtensionPref(extension_id, kPrefGrantedAPIs, api_values); | |
| 785 | |
| 786 // Set the explicit host permissions. | |
| 787 if (!new_perms->explicit_hosts().is_empty()) { | |
| 788 SetExtensionPrefURLPatternSet(extension_id, | |
| 789 kPrefGrantedExplicitHosts, | |
| 790 new_perms->explicit_hosts()); | |
| 731 } | 791 } |
| 732 | 792 |
| 733 if (!host_extent.is_empty()) { | 793 // Set the scriptable host permissions. |
| 734 std::set<std::string> host_permissions; | 794 if (!new_perms->scriptable_hosts().is_empty()) { |
| 735 ExtentToStringSet(host_extent, &host_permissions); | 795 SetExtensionPrefURLPatternSet(extension_id, |
| 736 | 796 kPrefGrantedScriptableHosts, |
| 737 AddToExtensionPrefStringSet( | 797 new_perms->scriptable_hosts()); |
| 738 extension_id, kPrefGrantedPermissionsHost, host_permissions); | |
| 739 } | 798 } |
| 740 } | 799 } |
| 741 | 800 |
| 742 bool ExtensionPrefs::IsIncognitoEnabled(const std::string& extension_id) { | 801 bool ExtensionPrefs::IsIncognitoEnabled(const std::string& extension_id) { |
| 743 return ReadExtensionPrefBoolean(extension_id, kPrefIncognitoEnabled); | 802 return ReadExtensionPrefBoolean(extension_id, kPrefIncognitoEnabled); |
| 744 } | 803 } |
| 745 | 804 |
| 746 void ExtensionPrefs::SetIsIncognitoEnabled(const std::string& extension_id, | 805 void ExtensionPrefs::SetIsIncognitoEnabled(const std::string& extension_id, |
| 747 bool enabled) { | 806 bool enabled) { |
| 748 UpdateExtensionPref(extension_id, kPrefIncognitoEnabled, | 807 UpdateExtensionPref(extension_id, kPrefIncognitoEnabled, |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 902 | 961 |
| 903 FilePath::StringType path = MakePathRelative(install_directory_, | 962 FilePath::StringType path = MakePathRelative(install_directory_, |
| 904 extension->path()); | 963 extension->path()); |
| 905 extension_dict->Set(kPrefPath, Value::CreateStringValue(path)); | 964 extension_dict->Set(kPrefPath, Value::CreateStringValue(path)); |
| 906 // We store prefs about LOAD extensions, but don't cache their manifest | 965 // We store prefs about LOAD extensions, but don't cache their manifest |
| 907 // since it may change on disk. | 966 // since it may change on disk. |
| 908 if (extension->location() != Extension::LOAD) { | 967 if (extension->location() != Extension::LOAD) { |
| 909 extension_dict->Set(kPrefManifest, | 968 extension_dict->Set(kPrefManifest, |
| 910 extension->manifest_value()->DeepCopy()); | 969 extension->manifest_value()->DeepCopy()); |
| 911 } | 970 } |
| 971 if (extension->location() == Extension::INTERNAL) { | |
| 972 AddGrantedPermissions(extension->id(), | |
| 973 extension->permission_set()); | |
| 974 } | |
| 912 extension_dict->Set(kPrefAppLaunchIndex, | 975 extension_dict->Set(kPrefAppLaunchIndex, |
| 913 Value::CreateIntegerValue(GetNextAppLaunchIndex())); | 976 Value::CreateIntegerValue(GetNextAppLaunchIndex())); |
| 914 extension_pref_value_map_->RegisterExtension( | 977 extension_pref_value_map_->RegisterExtension( |
| 915 id, install_time, initial_state == Extension::ENABLED); | 978 id, install_time, initial_state == Extension::ENABLED); |
| 916 content_settings_store_->RegisterExtension( | 979 content_settings_store_->RegisterExtension( |
| 917 id, install_time, initial_state == Extension::ENABLED); | 980 id, install_time, initial_state == Extension::ENABLED); |
| 918 } | 981 } |
| 919 | 982 |
| 920 void ExtensionPrefs::OnExtensionUninstalled(const std::string& extension_id, | 983 void ExtensionPrefs::OnExtensionUninstalled(const std::string& extension_id, |
| 921 const Extension::Location& location, | 984 const Extension::Location& location, |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1421 // Create empty preferences dictionary for each extension (these dictionaries | 1484 // Create empty preferences dictionary for each extension (these dictionaries |
| 1422 // are pruned when persisting the preferences to disk). | 1485 // are pruned when persisting the preferences to disk). |
| 1423 for (ExtensionIdSet::iterator ext_id = extension_ids.begin(); | 1486 for (ExtensionIdSet::iterator ext_id = extension_ids.begin(); |
| 1424 ext_id != extension_ids.end(); ++ext_id) { | 1487 ext_id != extension_ids.end(); ++ext_id) { |
| 1425 ScopedExtensionPrefUpdate update(prefs_, *ext_id); | 1488 ScopedExtensionPrefUpdate update(prefs_, *ext_id); |
| 1426 // This creates an empty dictionary if none is stored. | 1489 // This creates an empty dictionary if none is stored. |
| 1427 update.Get(); | 1490 update.Get(); |
| 1428 } | 1491 } |
| 1429 | 1492 |
| 1430 FixMissingPrefs(extension_ids); | 1493 FixMissingPrefs(extension_ids); |
| 1494 MigratePermissions(extension_ids); | |
| 1495 | |
| 1431 // Store extension controlled preference values in the | 1496 // Store extension controlled preference values in the |
| 1432 // |extension_pref_value_map_|, which then informs the subscribers | 1497 // |extension_pref_value_map_|, which then informs the subscribers |
| 1433 // (ExtensionPrefStores) about the winning values. | 1498 // (ExtensionPrefStores) about the winning values. |
| 1434 for (ExtensionIdSet::iterator ext_id = extension_ids.begin(); | 1499 for (ExtensionIdSet::iterator ext_id = extension_ids.begin(); |
| 1435 ext_id != extension_ids.end(); ++ext_id) { | 1500 ext_id != extension_ids.end(); ++ext_id) { |
| 1436 extension_pref_value_map_->RegisterExtension( | 1501 extension_pref_value_map_->RegisterExtension( |
| 1437 *ext_id, | 1502 *ext_id, |
| 1438 GetInstallTime(*ext_id), | 1503 GetInstallTime(*ext_id), |
| 1439 GetExtensionState(*ext_id) == Extension::ENABLED); | 1504 GetExtensionState(*ext_id) == Extension::ENABLED); |
| 1440 content_settings_store_->RegisterExtension( | 1505 content_settings_store_->RegisterExtension( |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1478 &content_settings)) { | 1543 &content_settings)) { |
| 1479 content_settings_store_->SetExtensionContentSettingsFromList( | 1544 content_settings_store_->SetExtensionContentSettingsFromList( |
| 1480 *ext_id, content_settings, | 1545 *ext_id, content_settings, |
| 1481 kExtensionPrefsScopeIncognitoPersistent); | 1546 kExtensionPrefsScopeIncognitoPersistent); |
| 1482 } | 1547 } |
| 1483 } | 1548 } |
| 1484 | 1549 |
| 1485 extension_pref_value_map_->NotifyInitializationCompleted(); | 1550 extension_pref_value_map_->NotifyInitializationCompleted(); |
| 1486 } | 1551 } |
| 1487 | 1552 |
| 1488 | |
| 1489 void ExtensionPrefs::SetExtensionControlledPref( | 1553 void ExtensionPrefs::SetExtensionControlledPref( |
| 1490 const std::string& extension_id, | 1554 const std::string& extension_id, |
| 1491 const std::string& pref_key, | 1555 const std::string& pref_key, |
| 1492 ExtensionPrefsScope scope, | 1556 ExtensionPrefsScope scope, |
| 1493 Value* value) { | 1557 Value* value) { |
| 1494 #ifndef NDEBUG | 1558 #ifndef NDEBUG |
| 1495 const PrefService::Preference* pref = | 1559 const PrefService::Preference* pref = |
| 1496 pref_service()->FindPreference(pref_key.c_str()); | 1560 pref_service()->FindPreference(pref_key.c_str()); |
| 1497 DCHECK(pref) << "Extension controlled preference key " << pref_key | 1561 DCHECK(pref) << "Extension controlled preference key " << pref_key |
| 1498 << " not registered."; | 1562 << " not registered."; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1595 prefs->RegisterListPref(prefs::kExtensionInstallAllowList, | 1659 prefs->RegisterListPref(prefs::kExtensionInstallAllowList, |
| 1596 PrefService::UNSYNCABLE_PREF); | 1660 PrefService::UNSYNCABLE_PREF); |
| 1597 prefs->RegisterListPref(prefs::kExtensionInstallDenyList, | 1661 prefs->RegisterListPref(prefs::kExtensionInstallDenyList, |
| 1598 PrefService::UNSYNCABLE_PREF); | 1662 PrefService::UNSYNCABLE_PREF); |
| 1599 prefs->RegisterListPref(prefs::kExtensionInstallForceList, | 1663 prefs->RegisterListPref(prefs::kExtensionInstallForceList, |
| 1600 PrefService::UNSYNCABLE_PREF); | 1664 PrefService::UNSYNCABLE_PREF); |
| 1601 prefs->RegisterStringPref(kWebStoreLogin, | 1665 prefs->RegisterStringPref(kWebStoreLogin, |
| 1602 std::string() /* default_value */, | 1666 std::string() /* default_value */, |
| 1603 PrefService::UNSYNCABLE_PREF); | 1667 PrefService::UNSYNCABLE_PREF); |
| 1604 } | 1668 } |
| OLD | NEW |