| 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 931 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 942 for (std::vector<std::string>::const_iterator iter = extension_ids.begin(); | 942 for (std::vector<std::string>::const_iterator iter = extension_ids.begin(); |
| 943 iter != extension_ids.end(); ++iter) { | 943 iter != extension_ids.end(); ++iter) { |
| 944 toolbar_order->Append(new StringValue(*iter)); | 944 toolbar_order->Append(new StringValue(*iter)); |
| 945 } | 945 } |
| 946 SavePrefs(); | 946 SavePrefs(); |
| 947 } | 947 } |
| 948 | 948 |
| 949 void ExtensionPrefs::OnExtensionInstalled( | 949 void ExtensionPrefs::OnExtensionInstalled( |
| 950 const Extension* extension, | 950 const Extension* extension, |
| 951 Extension::State initial_state, | 951 Extension::State initial_state, |
| 952 bool from_webstore) { | 952 bool from_webstore, |
| 953 int page_index) { |
| 953 const std::string& id = extension->id(); | 954 const std::string& id = extension->id(); |
| 954 CHECK(Extension::IdIsValid(id)); | 955 CHECK(Extension::IdIsValid(id)); |
| 955 ScopedExtensionPrefUpdate update(prefs_, id); | 956 ScopedExtensionPrefUpdate update(prefs_, id); |
| 956 DictionaryValue* extension_dict = update.Get(); | 957 DictionaryValue* extension_dict = update.Get(); |
| 957 const base::Time install_time = GetCurrentTime(); | 958 const base::Time install_time = GetCurrentTime(); |
| 958 extension_dict->Set(kPrefState, Value::CreateIntegerValue(initial_state)); | 959 extension_dict->Set(kPrefState, Value::CreateIntegerValue(initial_state)); |
| 959 extension_dict->Set(kPrefLocation, | 960 extension_dict->Set(kPrefLocation, |
| 960 Value::CreateIntegerValue(extension->location())); | 961 Value::CreateIntegerValue(extension->location())); |
| 961 extension_dict->Set(kPrefFromWebStore, | 962 extension_dict->Set(kPrefFromWebStore, |
| 962 Value::CreateBooleanValue(from_webstore)); | 963 Value::CreateBooleanValue(from_webstore)); |
| 963 extension_dict->Set(kPrefFromBookmark, | 964 extension_dict->Set(kPrefFromBookmark, |
| 964 Value::CreateBooleanValue(extension->from_bookmark())); | 965 Value::CreateBooleanValue(extension->from_bookmark())); |
| 965 extension_dict->Set(kPrefInstallTime, | 966 extension_dict->Set(kPrefInstallTime, |
| 966 Value::CreateStringValue( | 967 Value::CreateStringValue( |
| 967 base::Int64ToString(install_time.ToInternalValue()))); | 968 base::Int64ToString(install_time.ToInternalValue()))); |
| 968 extension_dict->Set(kPrefPreferences, new DictionaryValue()); | 969 extension_dict->Set(kPrefPreferences, new DictionaryValue()); |
| 969 extension_dict->Set(kPrefIncognitoPreferences, new DictionaryValue()); | 970 extension_dict->Set(kPrefIncognitoPreferences, new DictionaryValue()); |
| 970 extension_dict->Set(kPrefContentSettings, new ListValue()); | 971 extension_dict->Set(kPrefContentSettings, new ListValue()); |
| 971 extension_dict->Set(kPrefIncognitoContentSettings, new ListValue()); | 972 extension_dict->Set(kPrefIncognitoContentSettings, new ListValue()); |
| 972 | 973 |
| 973 FilePath::StringType path = MakePathRelative(install_directory_, | 974 FilePath::StringType path = MakePathRelative(install_directory_, |
| 974 extension->path()); | 975 extension->path()); |
| 975 extension_dict->Set(kPrefPath, Value::CreateStringValue(path)); | 976 extension_dict->Set(kPrefPath, Value::CreateStringValue(path)); |
| 976 // We store prefs about LOAD extensions, but don't cache their manifest | 977 // We store prefs about LOAD extensions, but don't cache their manifest |
| 977 // since it may change on disk. | 978 // since it may change on disk. |
| 978 if (extension->location() != Extension::LOAD) { | 979 if (extension->location() != Extension::LOAD) { |
| 979 extension_dict->Set(kPrefManifest, | 980 extension_dict->Set(kPrefManifest, |
| 980 extension->manifest_value()->DeepCopy()); | 981 extension->manifest_value()->DeepCopy()); |
| 981 } | 982 } |
| 983 extension_dict->Set(kPrefPageIndex, |
| 984 Value::CreateIntegerValue(page_index)); |
| 982 extension_dict->Set(kPrefAppLaunchIndex, | 985 extension_dict->Set(kPrefAppLaunchIndex, |
| 983 Value::CreateIntegerValue(GetNextAppLaunchIndex())); | 986 Value::CreateIntegerValue(GetNextAppLaunchIndex(page_index))); |
| 984 extension_pref_value_map_->RegisterExtension( | 987 extension_pref_value_map_->RegisterExtension( |
| 985 id, install_time, initial_state == Extension::ENABLED); | 988 id, install_time, initial_state == Extension::ENABLED); |
| 986 content_settings_store_->RegisterExtension( | 989 content_settings_store_->RegisterExtension( |
| 987 id, install_time, initial_state == Extension::ENABLED); | 990 id, install_time, initial_state == Extension::ENABLED); |
| 988 } | 991 } |
| 989 | 992 |
| 990 void ExtensionPrefs::OnExtensionUninstalled(const std::string& extension_id, | 993 void ExtensionPrefs::OnExtensionUninstalled(const std::string& extension_id, |
| 991 const Extension::Location& location, | 994 const Extension::Location& location, |
| 992 bool external_uninstall) { | 995 bool external_uninstall) { |
| 993 // For external extensions, we save a preference reminding ourself not to try | 996 // For external extensions, we save a preference reminding ourself not to try |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1317 return -1; | 1320 return -1; |
| 1318 } | 1321 } |
| 1319 | 1322 |
| 1320 void ExtensionPrefs::SetAppLaunchIndex(const std::string& extension_id, | 1323 void ExtensionPrefs::SetAppLaunchIndex(const std::string& extension_id, |
| 1321 int index) { | 1324 int index) { |
| 1322 DCHECK_GE(index, 0); | 1325 DCHECK_GE(index, 0); |
| 1323 UpdateExtensionPref(extension_id, kPrefAppLaunchIndex, | 1326 UpdateExtensionPref(extension_id, kPrefAppLaunchIndex, |
| 1324 Value::CreateIntegerValue(index)); | 1327 Value::CreateIntegerValue(index)); |
| 1325 } | 1328 } |
| 1326 | 1329 |
| 1327 int ExtensionPrefs::GetNextAppLaunchIndex() { | 1330 int ExtensionPrefs::GetNextAppLaunchIndex(int on_page) { |
| 1328 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); | 1331 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); |
| 1329 if (!extensions) | 1332 if (!extensions) |
| 1330 return 0; | 1333 return 0; |
| 1331 | 1334 |
| 1332 int max_value = -1; | 1335 int max_value = -1; |
| 1333 for (DictionaryValue::key_iterator extension_id = extensions->begin_keys(); | 1336 for (DictionaryValue::key_iterator extension_id = extensions->begin_keys(); |
| 1334 extension_id != extensions->end_keys(); ++extension_id) { | 1337 extension_id != extensions->end_keys(); ++extension_id) { |
| 1335 int value = GetAppLaunchIndex(*extension_id); | 1338 int value = GetAppLaunchIndex(*extension_id); |
| 1336 if (value > max_value) | 1339 int page = GetPageIndex(*extension_id); |
| 1340 if (page == on_page && value > max_value) |
| 1337 max_value = value; | 1341 max_value = value; |
| 1338 } | 1342 } |
| 1339 return max_value + 1; | 1343 return max_value + 1; |
| 1340 } | 1344 } |
| 1341 | 1345 |
| 1342 void ExtensionPrefs::SetAppLauncherOrder( | 1346 void ExtensionPrefs::SetAppLauncherOrder( |
| 1343 const std::vector<std::string>& extension_ids) { | 1347 const std::vector<std::string>& extension_ids) { |
| 1344 for (size_t i = 0; i < extension_ids.size(); ++i) | 1348 for (size_t i = 0; i < extension_ids.size(); ++i) |
| 1345 SetAppLaunchIndex(extension_ids.at(i), i); | 1349 SetAppLaunchIndex(extension_ids.at(i), i); |
| 1346 | 1350 |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1669 prefs->RegisterListPref(prefs::kExtensionInstallAllowList, | 1673 prefs->RegisterListPref(prefs::kExtensionInstallAllowList, |
| 1670 PrefService::UNSYNCABLE_PREF); | 1674 PrefService::UNSYNCABLE_PREF); |
| 1671 prefs->RegisterListPref(prefs::kExtensionInstallDenyList, | 1675 prefs->RegisterListPref(prefs::kExtensionInstallDenyList, |
| 1672 PrefService::UNSYNCABLE_PREF); | 1676 PrefService::UNSYNCABLE_PREF); |
| 1673 prefs->RegisterListPref(prefs::kExtensionInstallForceList, | 1677 prefs->RegisterListPref(prefs::kExtensionInstallForceList, |
| 1674 PrefService::UNSYNCABLE_PREF); | 1678 PrefService::UNSYNCABLE_PREF); |
| 1675 prefs->RegisterStringPref(kWebStoreLogin, | 1679 prefs->RegisterStringPref(kWebStoreLogin, |
| 1676 std::string() /* default_value */, | 1680 std::string() /* default_value */, |
| 1677 PrefService::UNSYNCABLE_PREF); | 1681 PrefService::UNSYNCABLE_PREF); |
| 1678 } | 1682 } |
| OLD | NEW |