Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: chrome/browser/extensions/extension_prefs.cc

Issue 7649006: more changes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix another typo Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 return true; 423 return true;
424 } 424 }
425 425
426 void ExtensionPrefs::SetExtensionPrefURLPatternSet( 426 void ExtensionPrefs::SetExtensionPrefURLPatternSet(
427 const std::string& extension_id, 427 const std::string& extension_id,
428 const std::string& pref_key, 428 const std::string& pref_key,
429 const URLPatternSet& new_value) { 429 const URLPatternSet& new_value) {
430 ListValue* value = new ListValue(); 430 ListValue* value = new ListValue();
431 for (URLPatternSet::const_iterator i = new_value.begin(); 431 for (URLPatternSet::const_iterator i = new_value.begin();
432 i != new_value.end(); ++i) 432 i != new_value.end(); ++i)
433 value->AppendIfNotPresent(Value::CreateStringValue(i->GetAsString())); 433 value->AppendIfNotPresent(base::StringValue::New(i->GetAsString()));
434 434
435 UpdateExtensionPref(extension_id, pref_key, value); 435 UpdateExtensionPref(extension_id, pref_key, value);
436 } 436 }
437 437
438 ExtensionPermissionSet* ExtensionPrefs::ReadExtensionPrefPermissionSet( 438 ExtensionPermissionSet* ExtensionPrefs::ReadExtensionPrefPermissionSet(
439 const std::string& extension_id, 439 const std::string& extension_id,
440 const std::string& pref_key) { 440 const std::string& pref_key) {
441 if (!GetExtensionPref(extension_id)) 441 if (!GetExtensionPref(extension_id))
442 return NULL; 442 return NULL;
443 443
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 const ExtensionPermissionSet* new_value) { 478 const ExtensionPermissionSet* new_value) {
479 // Set the API permissions. 479 // Set the API permissions.
480 ListValue* api_values = new ListValue(); 480 ListValue* api_values = new ListValue();
481 ExtensionAPIPermissionSet apis = new_value->apis(); 481 ExtensionAPIPermissionSet apis = new_value->apis();
482 ExtensionPermissionsInfo* info = ExtensionPermissionsInfo::GetInstance(); 482 ExtensionPermissionsInfo* info = ExtensionPermissionsInfo::GetInstance();
483 std::string api_pref = JoinPrefs(pref_key, kPrefAPIs); 483 std::string api_pref = JoinPrefs(pref_key, kPrefAPIs);
484 for (ExtensionAPIPermissionSet::const_iterator i = apis.begin(); 484 for (ExtensionAPIPermissionSet::const_iterator i = apis.begin();
485 i != apis.end(); ++i) { 485 i != apis.end(); ++i) {
486 ExtensionAPIPermission* perm = info->GetByID(*i); 486 ExtensionAPIPermission* perm = info->GetByID(*i);
487 if (perm) 487 if (perm)
488 api_values->Append(Value::CreateStringValue(perm->name())); 488 api_values->Append(base::StringValue::New(perm->name()));
489 } 489 }
490 UpdateExtensionPref(extension_id, api_pref, api_values); 490 UpdateExtensionPref(extension_id, api_pref, api_values);
491 491
492 // Set the explicit host permissions. 492 // Set the explicit host permissions.
493 if (!new_value->explicit_hosts().is_empty()) { 493 if (!new_value->explicit_hosts().is_empty()) {
494 SetExtensionPrefURLPatternSet(extension_id, 494 SetExtensionPrefURLPatternSet(extension_id,
495 JoinPrefs(pref_key, kPrefExplicitHosts), 495 JoinPrefs(pref_key, kPrefExplicitHosts),
496 new_value->explicit_hosts()); 496 new_value->explicit_hosts());
497 } 497 }
498 498
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 559
560 bool ExtensionPrefs::DidExtensionEscalatePermissions( 560 bool ExtensionPrefs::DidExtensionEscalatePermissions(
561 const std::string& extension_id) { 561 const std::string& extension_id) {
562 return ReadExtensionPrefBoolean(extension_id, 562 return ReadExtensionPrefBoolean(extension_id,
563 kExtensionDidEscalatePermissions); 563 kExtensionDidEscalatePermissions);
564 } 564 }
565 565
566 void ExtensionPrefs::SetDidExtensionEscalatePermissions( 566 void ExtensionPrefs::SetDidExtensionEscalatePermissions(
567 const Extension* extension, bool did_escalate) { 567 const Extension* extension, bool did_escalate) {
568 UpdateExtensionPref(extension->id(), kExtensionDidEscalatePermissions, 568 UpdateExtensionPref(extension->id(), kExtensionDidEscalatePermissions,
569 Value::CreateBooleanValue(did_escalate)); 569 base::BooleanValue::New(did_escalate));
570 } 570 }
571 571
572 void ExtensionPrefs::UpdateBlacklist( 572 void ExtensionPrefs::UpdateBlacklist(
573 const std::set<std::string>& blacklist_set) { 573 const std::set<std::string>& blacklist_set) {
574 std::vector<std::string> remove_pref_ids; 574 std::vector<std::string> remove_pref_ids;
575 std::set<std::string> used_id_set; 575 std::set<std::string> used_id_set;
576 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); 576 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref);
577 577
578 if (extensions) { 578 if (extensions) {
579 for (DictionaryValue::key_iterator extension_id = extensions->begin_keys(); 579 for (DictionaryValue::key_iterator extension_id = extensions->begin_keys();
(...skipping 26 matching lines...) Expand all
606 // Keep the record if this extension is already processed. 606 // Keep the record if this extension is already processed.
607 used_id_set.insert(id); 607 used_id_set.insert(id);
608 } 608 }
609 } 609 }
610 } 610 }
611 611
612 // Iterate the leftovers to set blacklist in pref 612 // Iterate the leftovers to set blacklist in pref
613 std::set<std::string>::const_iterator set_itr = blacklist_set.begin(); 613 std::set<std::string>::const_iterator set_itr = blacklist_set.begin();
614 for (; set_itr != blacklist_set.end(); ++set_itr) { 614 for (; set_itr != blacklist_set.end(); ++set_itr) {
615 if (used_id_set.find(*set_itr) == used_id_set.end()) { 615 if (used_id_set.find(*set_itr) == used_id_set.end()) {
616 UpdateExtensionPref(*set_itr, kPrefBlacklist, 616 UpdateExtensionPref(*set_itr, kPrefBlacklist, base::TrueValue());
617 Value::CreateBooleanValue(true));
618 } 617 }
619 } 618 }
620 for (unsigned int i = 0; i < remove_pref_ids.size(); ++i) { 619 for (unsigned int i = 0; i < remove_pref_ids.size(); ++i) {
621 DeleteExtensionPrefs(remove_pref_ids[i]); 620 DeleteExtensionPrefs(remove_pref_ids[i]);
622 } 621 }
623 } 622 }
624 623
625 namespace { 624 namespace {
626 625
627 // Serializes |time| as a string value mapped to |key| in |dictionary|. 626 // Serializes |time| as a string value mapped to |key| in |dictionary|.
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 const DictionaryValue* dictionary = GetExtensionPref(extension_id); 686 const DictionaryValue* dictionary = GetExtensionPref(extension_id);
688 bool result = false; 687 bool result = false;
689 if (dictionary && dictionary->GetBoolean(kActiveBit, &result)) 688 if (dictionary && dictionary->GetBoolean(kActiveBit, &result))
690 return result; 689 return result;
691 return false; 690 return false;
692 } 691 }
693 692
694 void ExtensionPrefs::SetActiveBit(const std::string& extension_id, 693 void ExtensionPrefs::SetActiveBit(const std::string& extension_id,
695 bool active) { 694 bool active) {
696 UpdateExtensionPref(extension_id, kActiveBit, 695 UpdateExtensionPref(extension_id, kActiveBit,
697 Value::CreateBooleanValue(active)); 696 base::BooleanValue::New(active));
698 } 697 }
699 698
700 void ExtensionPrefs::MigratePermissions(const ExtensionIdSet& extension_ids) { 699 void ExtensionPrefs::MigratePermissions(const ExtensionIdSet& extension_ids) {
701 ExtensionPermissionsInfo* info = ExtensionPermissionsInfo::GetInstance(); 700 ExtensionPermissionsInfo* info = ExtensionPermissionsInfo::GetInstance();
702 for (ExtensionIdSet::const_iterator ext_id = extension_ids.begin(); 701 for (ExtensionIdSet::const_iterator ext_id = extension_ids.begin();
703 ext_id != extension_ids.end(); ++ext_id) { 702 ext_id != extension_ids.end(); ++ext_id) {
704 703
705 // An extension's granted permissions need to be migrated if the 704 // An extension's granted permissions need to be migrated if the
706 // full_access bit is present. This bit was always present in the previous 705 // full_access bit is present. This bit was always present in the previous
707 // scheme and is never present now. 706 // scheme and is never present now.
(...skipping 13 matching lines...) Expand all
721 720
722 std::string granted_apis = 721 std::string granted_apis =
723 JoinPrefs(kPrefGrantedPermissions, kPrefAPIs); 722 JoinPrefs(kPrefGrantedPermissions, kPrefAPIs);
724 if (ext->GetList(kPrefOldGrantedAPIs, &apis)) 723 if (ext->GetList(kPrefOldGrantedAPIs, &apis))
725 new_apis = apis->DeepCopy(); 724 new_apis = apis->DeepCopy();
726 else 725 else
727 new_apis = new ListValue(); 726 new_apis = new ListValue();
728 727
729 std::string plugin_name = info->GetByID( 728 std::string plugin_name = info->GetByID(
730 ExtensionAPIPermission::kPlugin)->name(); 729 ExtensionAPIPermission::kPlugin)->name();
731 new_apis->Append(Value::CreateStringValue(plugin_name)); 730 new_apis->Append(base::StringValue::New(plugin_name));
732 UpdateExtensionPref(*ext_id, granted_apis, new_apis); 731 UpdateExtensionPref(*ext_id, granted_apis, new_apis);
733 } 732 }
734 733
735 // The granted permissions originally only held the effective hosts, 734 // The granted permissions originally only held the effective hosts,
736 // which are a combination of host and user script host permissions. 735 // which are a combination of host and user script host permissions.
737 // We now maintain these lists separately. For migration purposes, it 736 // We now maintain these lists separately. For migration purposes, it
738 // does not matter how we treat the old effective hosts as long as the 737 // does not matter how we treat the old effective hosts as long as the
739 // new effective hosts will be the same, so we move them to explicit 738 // new effective hosts will be the same, so we move them to explicit
740 // host permissions. 739 // host permissions.
741 ListValue* hosts; 740 ListValue* hosts;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 extension_id, kPrefActivePermissions, permissions); 787 extension_id, kPrefActivePermissions, permissions);
789 } 788 }
790 789
791 bool ExtensionPrefs::IsIncognitoEnabled(const std::string& extension_id) { 790 bool ExtensionPrefs::IsIncognitoEnabled(const std::string& extension_id) {
792 return ReadExtensionPrefBoolean(extension_id, kPrefIncognitoEnabled); 791 return ReadExtensionPrefBoolean(extension_id, kPrefIncognitoEnabled);
793 } 792 }
794 793
795 void ExtensionPrefs::SetIsIncognitoEnabled(const std::string& extension_id, 794 void ExtensionPrefs::SetIsIncognitoEnabled(const std::string& extension_id,
796 bool enabled) { 795 bool enabled) {
797 UpdateExtensionPref(extension_id, kPrefIncognitoEnabled, 796 UpdateExtensionPref(extension_id, kPrefIncognitoEnabled,
798 Value::CreateBooleanValue(enabled)); 797 base::BooleanValue::New(enabled));
799 } 798 }
800 799
801 bool ExtensionPrefs::AllowFileAccess(const std::string& extension_id) { 800 bool ExtensionPrefs::AllowFileAccess(const std::string& extension_id) {
802 return ReadExtensionPrefBoolean(extension_id, kPrefAllowFileAccess); 801 return ReadExtensionPrefBoolean(extension_id, kPrefAllowFileAccess);
803 } 802 }
804 803
805 void ExtensionPrefs::SetAllowFileAccess(const std::string& extension_id, 804 void ExtensionPrefs::SetAllowFileAccess(const std::string& extension_id,
806 bool allow) { 805 bool allow) {
807 UpdateExtensionPref(extension_id, kPrefAllowFileAccess, 806 UpdateExtensionPref(extension_id, kPrefAllowFileAccess,
808 Value::CreateBooleanValue(allow)); 807 base::BooleanValue::New(allow));
809 } 808 }
810 809
811 bool ExtensionPrefs::HasAllowFileAccessSetting( 810 bool ExtensionPrefs::HasAllowFileAccessSetting(
812 const std::string& extension_id) const { 811 const std::string& extension_id) const {
813 const DictionaryValue* ext = GetExtensionPref(extension_id); 812 const DictionaryValue* ext = GetExtensionPref(extension_id);
814 return ext && ext->HasKey(kPrefAllowFileAccess); 813 return ext && ext->HasKey(kPrefAllowFileAccess);
815 } 814 }
816 815
817 ExtensionPrefs::LaunchType ExtensionPrefs::GetLaunchType( 816 ExtensionPrefs::LaunchType ExtensionPrefs::GetLaunchType(
818 const std::string& extension_id, 817 const std::string& extension_id,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 DLOG(FATAL) << "Failed to set a launch container."; 885 DLOG(FATAL) << "Failed to set a launch container.";
887 result = extension_misc::LAUNCH_TAB; 886 result = extension_misc::LAUNCH_TAB;
888 } 887 }
889 888
890 return result; 889 return result;
891 } 890 }
892 891
893 void ExtensionPrefs::SetLaunchType(const std::string& extension_id, 892 void ExtensionPrefs::SetLaunchType(const std::string& extension_id,
894 LaunchType launch_type) { 893 LaunchType launch_type) {
895 UpdateExtensionPref(extension_id, kPrefLaunchType, 894 UpdateExtensionPref(extension_id, kPrefLaunchType,
896 Value::CreateIntegerValue(static_cast<int>(launch_type))); 895 base::NumberValue::New(static_cast<int>(launch_type)));
897 } 896 }
898 897
899 bool ExtensionPrefs::DoesExtensionHaveState( 898 bool ExtensionPrefs::DoesExtensionHaveState(
900 const std::string& id, Extension::State check_state) const { 899 const std::string& id, Extension::State check_state) const {
901 const DictionaryValue* extension = GetExtensionPref(id); 900 const DictionaryValue* extension = GetExtensionPref(id);
902 int state = -1; 901 int state = -1;
903 if (!extension || !extension->GetInteger(kPrefState, &state)) 902 if (!extension || !extension->GetInteger(kPrefState, &state))
904 return false; 903 return false;
905 904
906 if (state < 0 || state >= Extension::NUM_STATES) { 905 if (state < 0 || state >= Extension::NUM_STATES) {
(...skipping 27 matching lines...) Expand all
934 return extension_ids; 933 return extension_ids;
935 } 934 }
936 935
937 void ExtensionPrefs::SetToolbarOrder( 936 void ExtensionPrefs::SetToolbarOrder(
938 const std::vector<std::string>& extension_ids) { 937 const std::vector<std::string>& extension_ids) {
939 ListPrefUpdate update(prefs_, kExtensionToolbar); 938 ListPrefUpdate update(prefs_, kExtensionToolbar);
940 ListValue* toolbar_order = update.Get(); 939 ListValue* toolbar_order = update.Get();
941 toolbar_order->Clear(); 940 toolbar_order->Clear();
942 for (std::vector<std::string>::const_iterator iter = extension_ids.begin(); 941 for (std::vector<std::string>::const_iterator iter = extension_ids.begin();
943 iter != extension_ids.end(); ++iter) { 942 iter != extension_ids.end(); ++iter) {
944 toolbar_order->Append(new StringValue(*iter)); 943 toolbar_order->Append(base::StringValue::New(*iter));
945 } 944 }
946 SavePrefs(); 945 SavePrefs();
947 } 946 }
948 947
949 void ExtensionPrefs::OnExtensionInstalled( 948 void ExtensionPrefs::OnExtensionInstalled(
950 const Extension* extension, 949 const Extension* extension,
951 Extension::State initial_state, 950 Extension::State initial_state,
952 bool from_webstore) { 951 bool from_webstore) {
953 const std::string& id = extension->id(); 952 const std::string& id = extension->id();
954 CHECK(Extension::IdIsValid(id)); 953 CHECK(Extension::IdIsValid(id));
955 ScopedExtensionPrefUpdate update(prefs_, id); 954 ScopedExtensionPrefUpdate update(prefs_, id);
956 DictionaryValue* extension_dict = update.Get(); 955 DictionaryValue* extension_dict = update.Get();
957 const base::Time install_time = GetCurrentTime(); 956 const base::Time install_time = GetCurrentTime();
958 extension_dict->Set(kPrefState, Value::CreateIntegerValue(initial_state)); 957 extension_dict->Set(kPrefState, base::NumberValue::New(initial_state));
959 extension_dict->Set(kPrefLocation, 958 extension_dict->Set(kPrefLocation,
960 Value::CreateIntegerValue(extension->location())); 959 base::NumberValue::New(extension->location()));
961 extension_dict->Set(kPrefFromWebStore, 960 extension_dict->Set(kPrefFromWebStore,
962 Value::CreateBooleanValue(from_webstore)); 961 base::BooleanValue::New(from_webstore));
963 extension_dict->Set(kPrefFromBookmark, 962 extension_dict->Set(kPrefFromBookmark,
964 Value::CreateBooleanValue(extension->from_bookmark())); 963 base::BooleanValue::New(extension->from_bookmark()));
965 extension_dict->Set(kPrefInstallTime, 964 extension_dict->Set(kPrefInstallTime,
966 Value::CreateStringValue( 965 base::StringValue::New(
967 base::Int64ToString(install_time.ToInternalValue()))); 966 base::Int64ToString(install_time.ToInternalValue())));
968 extension_dict->Set(kPrefPreferences, new DictionaryValue()); 967 extension_dict->Set(kPrefPreferences, new DictionaryValue());
969 extension_dict->Set(kPrefIncognitoPreferences, new DictionaryValue()); 968 extension_dict->Set(kPrefIncognitoPreferences, new DictionaryValue());
970 extension_dict->Set(kPrefContentSettings, new ListValue()); 969 extension_dict->Set(kPrefContentSettings, new ListValue());
971 extension_dict->Set(kPrefIncognitoContentSettings, new ListValue()); 970 extension_dict->Set(kPrefIncognitoContentSettings, new ListValue());
972 971
973 FilePath::StringType path = MakePathRelative(install_directory_, 972 FilePath::StringType path = MakePathRelative(install_directory_,
974 extension->path()); 973 extension->path());
975 extension_dict->Set(kPrefPath, Value::CreateStringValue(path)); 974 extension_dict->Set(kPrefPath, base::StringValue::New(path));
976 // We store prefs about LOAD extensions, but don't cache their manifest 975 // We store prefs about LOAD extensions, but don't cache their manifest
977 // since it may change on disk. 976 // since it may change on disk.
978 if (extension->location() != Extension::LOAD) { 977 if (extension->location() != Extension::LOAD) {
979 extension_dict->Set(kPrefManifest, 978 extension_dict->Set(kPrefManifest,
980 extension->manifest_value()->DeepCopy()); 979 extension->manifest_value()->DeepCopy());
981 } 980 }
982 extension_dict->Set(kPrefAppLaunchIndex, 981 extension_dict->Set(kPrefAppLaunchIndex,
983 Value::CreateIntegerValue(GetNextAppLaunchIndex())); 982 base::NumberValue::New(GetNextAppLaunchIndex()));
984 extension_pref_value_map_->RegisterExtension( 983 extension_pref_value_map_->RegisterExtension(
985 id, install_time, initial_state == Extension::ENABLED); 984 id, install_time, initial_state == Extension::ENABLED);
986 content_settings_store_->RegisterExtension( 985 content_settings_store_->RegisterExtension(
987 id, install_time, initial_state == Extension::ENABLED); 986 id, install_time, initial_state == Extension::ENABLED);
988 } 987 }
989 988
990 void ExtensionPrefs::OnExtensionUninstalled(const std::string& extension_id, 989 void ExtensionPrefs::OnExtensionUninstalled(const std::string& extension_id,
991 const Extension::Location& location, 990 const Extension::Location& location,
992 bool external_uninstall) { 991 bool external_uninstall) {
993 // For external extensions, we save a preference reminding ourself not to try 992 // For external extensions, we save a preference reminding ourself not to try
994 // and install the extension anymore (except when |external_uninstall| is 993 // and install the extension anymore (except when |external_uninstall| is
995 // true, which signifies that the registry key was deleted or the pref file 994 // true, which signifies that the registry key was deleted or the pref file
996 // no longer lists the extension). 995 // no longer lists the extension).
997 if (!external_uninstall && Extension::IsExternalLocation(location)) { 996 if (!external_uninstall && Extension::IsExternalLocation(location)) {
998 UpdateExtensionPref(extension_id, kPrefState, 997 UpdateExtensionPref(extension_id, kPrefState,
999 Value::CreateIntegerValue( 998 base::NumberValue::New(
1000 Extension::EXTERNAL_EXTENSION_UNINSTALLED)); 999 Extension::EXTERNAL_EXTENSION_UNINSTALLED));
1001 extension_pref_value_map_->SetExtensionState(extension_id, false); 1000 extension_pref_value_map_->SetExtensionState(extension_id, false);
1002 content_settings_store_->SetExtensionState(extension_id, false); 1001 content_settings_store_->SetExtensionState(extension_id, false);
1003 } else { 1002 } else {
1004 DeleteExtensionPrefs(extension_id); 1003 DeleteExtensionPrefs(extension_id);
1005 } 1004 }
1006 } 1005 }
1007 1006
1008 void ExtensionPrefs::SetExtensionState(const std::string& extension_id, 1007 void ExtensionPrefs::SetExtensionState(const std::string& extension_id,
1009 Extension::State state) { 1008 Extension::State state) {
1010 UpdateExtensionPref(extension_id, kPrefState, 1009 UpdateExtensionPref(extension_id, kPrefState,
1011 Value::CreateIntegerValue(state)); 1010 base::NumberValue::New(state));
1012 bool enabled = (state == Extension::ENABLED); 1011 bool enabled = (state == Extension::ENABLED);
1013 extension_pref_value_map_->SetExtensionState(extension_id, enabled); 1012 extension_pref_value_map_->SetExtensionState(extension_id, enabled);
1014 content_settings_store_->SetExtensionState(extension_id, enabled); 1013 content_settings_store_->SetExtensionState(extension_id, enabled);
1015 } 1014 }
1016 1015
1017 bool ExtensionPrefs::GetBrowserActionVisibility(const Extension* extension) { 1016 bool ExtensionPrefs::GetBrowserActionVisibility(const Extension* extension) {
1018 const DictionaryValue* extension_prefs = GetExtensionPref(extension->id()); 1017 const DictionaryValue* extension_prefs = GetExtensionPref(extension->id());
1019 if (!extension_prefs) 1018 if (!extension_prefs)
1020 return true; 1019 return true;
1021 bool visible = false; 1020 bool visible = false;
1022 if (!extension_prefs->GetBoolean(kBrowserActionVisible, &visible) || visible) 1021 if (!extension_prefs->GetBoolean(kBrowserActionVisible, &visible) || visible)
1023 return true; 1022 return true;
1024 1023
1025 return false; 1024 return false;
1026 } 1025 }
1027 1026
1028 void ExtensionPrefs::SetBrowserActionVisibility(const Extension* extension, 1027 void ExtensionPrefs::SetBrowserActionVisibility(const Extension* extension,
1029 bool visible) { 1028 bool visible) {
1030 if (GetBrowserActionVisibility(extension) == visible) 1029 if (GetBrowserActionVisibility(extension) == visible)
1031 return; 1030 return;
1032 1031
1033 UpdateExtensionPref(extension->id(), kBrowserActionVisible, 1032 UpdateExtensionPref(extension->id(), kBrowserActionVisible,
1034 Value::CreateBooleanValue(visible)); 1033 base::BooleanValue::New(visible));
1035 NotificationService::current()->Notify( 1034 NotificationService::current()->Notify(
1036 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, 1035 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED,
1037 Source<ExtensionPrefs>(this), 1036 Source<ExtensionPrefs>(this),
1038 Details<const Extension>(extension)); 1037 Details<const Extension>(extension));
1039 } 1038 }
1040 1039
1041 std::string ExtensionPrefs::GetVersionString(const std::string& extension_id) { 1040 std::string ExtensionPrefs::GetVersionString(const std::string& extension_id) {
1042 const DictionaryValue* extension = GetExtensionPref(extension_id); 1041 const DictionaryValue* extension = GetExtensionPref(extension_id);
1043 if (!extension) 1042 if (!extension)
1044 return std::string(); 1043 return std::string();
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1314 if (ReadExtensionPrefInteger(extension_id, kPrefAppLaunchIndex, &value)) 1313 if (ReadExtensionPrefInteger(extension_id, kPrefAppLaunchIndex, &value))
1315 return value; 1314 return value;
1316 1315
1317 return -1; 1316 return -1;
1318 } 1317 }
1319 1318
1320 void ExtensionPrefs::SetAppLaunchIndex(const std::string& extension_id, 1319 void ExtensionPrefs::SetAppLaunchIndex(const std::string& extension_id,
1321 int index) { 1320 int index) {
1322 DCHECK_GE(index, 0); 1321 DCHECK_GE(index, 0);
1323 UpdateExtensionPref(extension_id, kPrefAppLaunchIndex, 1322 UpdateExtensionPref(extension_id, kPrefAppLaunchIndex,
1324 Value::CreateIntegerValue(index)); 1323 base::NumberValue::New(index));
1325 } 1324 }
1326 1325
1327 int ExtensionPrefs::GetNextAppLaunchIndex() { 1326 int ExtensionPrefs::GetNextAppLaunchIndex() {
1328 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); 1327 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref);
1329 if (!extensions) 1328 if (!extensions)
1330 return 0; 1329 return 0;
1331 1330
1332 int max_value = -1; 1331 int max_value = -1;
1333 for (DictionaryValue::key_iterator extension_id = extensions->begin_keys(); 1332 for (DictionaryValue::key_iterator extension_id = extensions->begin_keys();
1334 extension_id != extensions->end_keys(); ++extension_id) { 1333 extension_id != extensions->end_keys(); ++extension_id) {
(...skipping 17 matching lines...) Expand all
1352 1351
1353 int ExtensionPrefs::GetPageIndex(const std::string& extension_id) { 1352 int ExtensionPrefs::GetPageIndex(const std::string& extension_id) {
1354 int value = -1; 1353 int value = -1;
1355 ReadExtensionPrefInteger(extension_id, kPrefPageIndex, &value); 1354 ReadExtensionPrefInteger(extension_id, kPrefPageIndex, &value);
1356 return value; 1355 return value;
1357 } 1356 }
1358 1357
1359 void ExtensionPrefs::SetPageIndex(const std::string& extension_id, int index) { 1358 void ExtensionPrefs::SetPageIndex(const std::string& extension_id, int index) {
1360 CHECK_GE(index, 0); 1359 CHECK_GE(index, 0);
1361 UpdateExtensionPref(extension_id, kPrefPageIndex, 1360 UpdateExtensionPref(extension_id, kPrefPageIndex,
1362 Value::CreateIntegerValue(index)); 1361 base::NumberValue::New(index));
1363 } 1362 }
1364 1363
1365 bool ExtensionPrefs::WasAppDraggedByUser(const std::string& extension_id) { 1364 bool ExtensionPrefs::WasAppDraggedByUser(const std::string& extension_id) {
1366 return ReadExtensionPrefBoolean(extension_id, kPrefUserDraggedApp); 1365 return ReadExtensionPrefBoolean(extension_id, kPrefUserDraggedApp);
1367 } 1366 }
1368 1367
1369 void ExtensionPrefs::SetAppDraggedByUser(const std::string& extension_id) { 1368 void ExtensionPrefs::SetAppDraggedByUser(const std::string& extension_id) {
1370 UpdateExtensionPref(extension_id, kPrefUserDraggedApp, 1369 UpdateExtensionPref(extension_id, kPrefUserDraggedApp, base::TrueValue());
1371 Value::CreateBooleanValue(true));
1372 } 1370 }
1373 1371
1374 void ExtensionPrefs::SetUpdateUrlData(const std::string& extension_id, 1372 void ExtensionPrefs::SetUpdateUrlData(const std::string& extension_id,
1375 const std::string& data) { 1373 const std::string& data) {
1376 UpdateExtensionPref(extension_id, kUpdateUrlData, 1374 UpdateExtensionPref(extension_id, kUpdateUrlData,
1377 Value::CreateStringValue(data)); 1375 base::StringValue::New(data));
1378 } 1376 }
1379 1377
1380 std::string ExtensionPrefs::GetUpdateUrlData(const std::string& extension_id) { 1378 std::string ExtensionPrefs::GetUpdateUrlData(const std::string& extension_id) {
1381 const DictionaryValue* dictionary = GetExtensionPref(extension_id); 1379 const DictionaryValue* dictionary = GetExtensionPref(extension_id);
1382 if (!dictionary) 1380 if (!dictionary)
1383 return std::string(); 1381 return std::string();
1384 1382
1385 std::string data; 1383 std::string data;
1386 dictionary->GetString(kUpdateUrlData, &data); 1384 dictionary->GetString(kUpdateUrlData, &data);
1387 return data; 1385 return data;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1456 // Fix old entries that did not get an installation time entry when they 1454 // Fix old entries that did not get an installation time entry when they
1457 // were installed or don't have a preferences field. 1455 // were installed or don't have a preferences field.
1458 for (ExtensionIdSet::const_iterator ext_id = extension_ids.begin(); 1456 for (ExtensionIdSet::const_iterator ext_id = extension_ids.begin();
1459 ext_id != extension_ids.end(); ++ext_id) { 1457 ext_id != extension_ids.end(); ++ext_id) {
1460 if (GetInstallTime(*ext_id) == base::Time()) { 1458 if (GetInstallTime(*ext_id) == base::Time()) {
1461 LOG(INFO) << "Could not parse installation time of extension " 1459 LOG(INFO) << "Could not parse installation time of extension "
1462 << *ext_id << ". It was probably installed before setting " 1460 << *ext_id << ". It was probably installed before setting "
1463 << kPrefInstallTime << " was introduced. Updating " 1461 << kPrefInstallTime << " was introduced. Updating "
1464 << kPrefInstallTime << " to the current time."; 1462 << kPrefInstallTime << " to the current time.";
1465 const base::Time install_time = GetCurrentTime(); 1463 const base::Time install_time = GetCurrentTime();
1466 UpdateExtensionPref(*ext_id, kPrefInstallTime, Value::CreateStringValue( 1464 UpdateExtensionPref(*ext_id, kPrefInstallTime, base::StringValue::New(
1467 base::Int64ToString(install_time.ToInternalValue()))); 1465 base::Int64ToString(install_time.ToInternalValue())));
1468 } 1466 }
1469 } 1467 }
1470 } 1468 }
1471 1469
1472 const DictionaryValue* ExtensionPrefs::GetExtensionControlledPrefs( 1470 const DictionaryValue* ExtensionPrefs::GetExtensionControlledPrefs(
1473 const std::string& extension_id, 1471 const std::string& extension_id,
1474 bool incognito) const { 1472 bool incognito) const {
1475 std::string key = extension_id + std::string(".") + 1473 std::string key = extension_id + std::string(".") +
1476 (incognito ? kPrefIncognitoPreferences : kPrefPreferences); 1474 (incognito ? kPrefIncognitoPreferences : kPrefPreferences);
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
1669 prefs->RegisterListPref(prefs::kExtensionInstallAllowList, 1667 prefs->RegisterListPref(prefs::kExtensionInstallAllowList,
1670 PrefService::UNSYNCABLE_PREF); 1668 PrefService::UNSYNCABLE_PREF);
1671 prefs->RegisterListPref(prefs::kExtensionInstallDenyList, 1669 prefs->RegisterListPref(prefs::kExtensionInstallDenyList,
1672 PrefService::UNSYNCABLE_PREF); 1670 PrefService::UNSYNCABLE_PREF);
1673 prefs->RegisterListPref(prefs::kExtensionInstallForceList, 1671 prefs->RegisterListPref(prefs::kExtensionInstallForceList,
1674 PrefService::UNSYNCABLE_PREF); 1672 PrefService::UNSYNCABLE_PREF);
1675 prefs->RegisterStringPref(kWebStoreLogin, 1673 prefs->RegisterStringPref(kWebStoreLogin,
1676 std::string() /* default_value */, 1674 std::string() /* default_value */,
1677 PrefService::UNSYNCABLE_PREF); 1675 PrefService::UNSYNCABLE_PREF);
1678 } 1676 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_preference_api.cc ('k') | chrome/browser/extensions/extension_prefs_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698