| 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/admin_policy.h" | 10 #include "chrome/browser/extensions/admin_policy.h" |
| 11 #include "chrome/browser/extensions/api/alarms/alarm_manager.h" | |
| 12 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" | 11 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" |
| 13 #include "chrome/browser/extensions/extension_menu_manager.h" | 12 #include "chrome/browser/extensions/extension_menu_manager.h" |
| 14 #include "chrome/browser/extensions/extension_pref_store.h" | 13 #include "chrome/browser/extensions/extension_pref_store.h" |
| 15 #include "chrome/browser/extensions/extension_sorting.h" | 14 #include "chrome/browser/extensions/extension_sorting.h" |
| 16 #include "chrome/browser/prefs/pref_notifier.h" | 15 #include "chrome/browser/prefs/pref_notifier.h" |
| 17 #include "chrome/browser/prefs/pref_service.h" | 16 #include "chrome/browser/prefs/pref_service.h" |
| 18 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 17 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 19 #include "chrome/common/chrome_notification_types.h" | 18 #include "chrome/common/chrome_notification_types.h" |
| 20 #include "chrome/common/extensions/extension_switch_utils.h" | 19 #include "chrome/common/extensions/extension_switch_utils.h" |
| 21 #include "chrome/common/extensions/manifest.h" | 20 #include "chrome/common/extensions/manifest.h" |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 // A preference that contains extension-set content settings. | 163 // A preference that contains extension-set content settings. |
| 165 const char kPrefContentSettings[] = "content_settings"; | 164 const char kPrefContentSettings[] = "content_settings"; |
| 166 | 165 |
| 167 // A preference that contains extension-set content settings. | 166 // A preference that contains extension-set content settings. |
| 168 const char kPrefIncognitoContentSettings[] = "incognito_content_settings"; | 167 const char kPrefIncognitoContentSettings[] = "incognito_content_settings"; |
| 169 | 168 |
| 170 // A list of event names that this extension has registered from its lazy | 169 // A list of event names that this extension has registered from its lazy |
| 171 // background page. | 170 // background page. |
| 172 const char kRegisteredEvents[] = "events"; | 171 const char kRegisteredEvents[] = "events"; |
| 173 | 172 |
| 174 // A list of alarms that this extension has set. | |
| 175 const char kRegisteredAlarms[] = "alarms"; | |
| 176 const char kAlarmScheduledRunTime[] = "scheduled_run_time"; | |
| 177 | |
| 178 // Persisted value for omnibox.setDefaultSuggestion. | 173 // Persisted value for omnibox.setDefaultSuggestion. |
| 179 const char kOmniboxDefaultSuggestion[] = "omnibox_default_suggestion"; | 174 const char kOmniboxDefaultSuggestion[] = "omnibox_default_suggestion"; |
| 180 | 175 |
| 181 // A preference containing context menu items, persisted for event pages. | 176 // A preference containing context menu items, persisted for event pages. |
| 182 const char kPrefContextMenus[] = "context_menus"; | 177 const char kPrefContextMenus[] = "context_menus"; |
| 183 | 178 |
| 184 // Provider of write access to a dictionary storing extension prefs. | 179 // Provider of write access to a dictionary storing extension prefs. |
| 185 class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate { | 180 class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate { |
| 186 public: | 181 public: |
| 187 ScopedExtensionPrefUpdate(PrefService* service, | 182 ScopedExtensionPrefUpdate(PrefService* service, |
| (...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 950 void ExtensionPrefs::SetRegisteredEvents( | 945 void ExtensionPrefs::SetRegisteredEvents( |
| 951 const std::string& extension_id, const std::set<std::string>& events) { | 946 const std::string& extension_id, const std::set<std::string>& events) { |
| 952 ListValue* value = new ListValue(); | 947 ListValue* value = new ListValue(); |
| 953 for (std::set<std::string>::const_iterator it = events.begin(); | 948 for (std::set<std::string>::const_iterator it = events.begin(); |
| 954 it != events.end(); ++it) { | 949 it != events.end(); ++it) { |
| 955 value->Append(new StringValue(*it)); | 950 value->Append(new StringValue(*it)); |
| 956 } | 951 } |
| 957 UpdateExtensionPref(extension_id, kRegisteredEvents, value); | 952 UpdateExtensionPref(extension_id, kRegisteredEvents, value); |
| 958 } | 953 } |
| 959 | 954 |
| 960 std::vector<extensions::AlarmPref> ExtensionPrefs::GetRegisteredAlarms( | |
| 961 const std::string& extension_id) { | |
| 962 std::vector<extensions::AlarmPref> alarms; | |
| 963 const base::DictionaryValue* extension = GetExtensionPref(extension_id); | |
| 964 if (!extension) | |
| 965 return alarms; | |
| 966 | |
| 967 base::ListValue* list = NULL; | |
| 968 if (!extension->GetList(kRegisteredAlarms, &list)) | |
| 969 return alarms; | |
| 970 | |
| 971 typedef extensions::AlarmManager::Alarm Alarm; | |
| 972 for (size_t i = 0; i < list->GetSize(); ++i) { | |
| 973 base::DictionaryValue* alarm_dict = NULL; | |
| 974 extensions::AlarmPref alarm; | |
| 975 alarm.alarm.reset(new Alarm()); | |
| 976 if (list->GetDictionary(i, &alarm_dict) && | |
| 977 Alarm::Populate(*alarm_dict, alarm.alarm.get())) { | |
| 978 alarm.scheduled_run_time = ReadTime(alarm_dict, kAlarmScheduledRunTime); | |
| 979 alarms.push_back(alarm); | |
| 980 } | |
| 981 } | |
| 982 return alarms; | |
| 983 } | |
| 984 | |
| 985 void ExtensionPrefs::SetRegisteredAlarms( | |
| 986 const std::string& extension_id, | |
| 987 const std::vector<extensions::AlarmPref>& alarms) { | |
| 988 base::ListValue* list = new ListValue(); | |
| 989 for (size_t i = 0; i < alarms.size(); ++i) { | |
| 990 scoped_ptr<base::DictionaryValue> alarm = alarms[i].alarm->ToValue().Pass(); | |
| 991 SaveTime(alarm.get(), kAlarmScheduledRunTime, alarms[i].scheduled_run_time); | |
| 992 list->Append(alarm.release()); | |
| 993 } | |
| 994 UpdateExtensionPref(extension_id, kRegisteredAlarms, list); | |
| 995 } | |
| 996 | |
| 997 extensions::ExtensionOmniboxSuggestion | 955 extensions::ExtensionOmniboxSuggestion |
| 998 ExtensionPrefs::GetOmniboxDefaultSuggestion(const std::string& extension_id) { | 956 ExtensionPrefs::GetOmniboxDefaultSuggestion(const std::string& extension_id) { |
| 999 extensions::ExtensionOmniboxSuggestion suggestion; | 957 extensions::ExtensionOmniboxSuggestion suggestion; |
| 1000 | 958 |
| 1001 const base::DictionaryValue* extension = GetExtensionPref(extension_id); | 959 const base::DictionaryValue* extension = GetExtensionPref(extension_id); |
| 1002 base::DictionaryValue* dict = NULL; | 960 base::DictionaryValue* dict = NULL; |
| 1003 if (extension && extension->GetDictionary(kOmniboxDefaultSuggestion, &dict)) | 961 if (extension && extension->GetDictionary(kOmniboxDefaultSuggestion, &dict)) |
| 1004 suggestion.Populate(*dict, false); | 962 suggestion.Populate(*dict, false); |
| 1005 | 963 |
| 1006 return suggestion; | 964 return suggestion; |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1234 extension_dict->Set(kPrefPath, Value::CreateStringValue(path)); | 1192 extension_dict->Set(kPrefPath, Value::CreateStringValue(path)); |
| 1235 // We store prefs about LOAD extensions, but don't cache their manifest | 1193 // We store prefs about LOAD extensions, but don't cache their manifest |
| 1236 // since it may change on disk. | 1194 // since it may change on disk. |
| 1237 if (extension->location() != Extension::LOAD) { | 1195 if (extension->location() != Extension::LOAD) { |
| 1238 extension_dict->Set(kPrefManifest, | 1196 extension_dict->Set(kPrefManifest, |
| 1239 extension->manifest()->value()->DeepCopy()); | 1197 extension->manifest()->value()->DeepCopy()); |
| 1240 } | 1198 } |
| 1241 | 1199 |
| 1242 // Clear state that may be registered from a previous install. | 1200 // Clear state that may be registered from a previous install. |
| 1243 extension_dict->Remove(kRegisteredEvents, NULL); | 1201 extension_dict->Remove(kRegisteredEvents, NULL); |
| 1244 extension_dict->Remove(kRegisteredAlarms, NULL); | |
| 1245 extension_dict->Remove(kPrefContextMenus, NULL); | 1202 extension_dict->Remove(kPrefContextMenus, NULL); |
| 1246 | 1203 |
| 1247 if (extension->is_app()) { | 1204 if (extension->is_app()) { |
| 1248 StringOrdinal new_page_ordinal = page_ordinal.IsValid() ? | 1205 StringOrdinal new_page_ordinal = page_ordinal.IsValid() ? |
| 1249 page_ordinal : extension_sorting_->GetNaturalAppPageOrdinal(); | 1206 page_ordinal : extension_sorting_->GetNaturalAppPageOrdinal(); |
| 1250 if (!extension_sorting_->GetPageOrdinal(id).IsValid()) | 1207 if (!extension_sorting_->GetPageOrdinal(id).IsValid()) |
| 1251 extension_sorting_->SetPageOrdinal(id, new_page_ordinal); | 1208 extension_sorting_->SetPageOrdinal(id, new_page_ordinal); |
| 1252 if (!extension_sorting_->GetAppLaunchOrdinal(id).IsValid()) | 1209 if (!extension_sorting_->GetAppLaunchOrdinal(id).IsValid()) |
| 1253 extension_sorting_->SetAppLaunchOrdinal( | 1210 extension_sorting_->SetAppLaunchOrdinal( |
| 1254 id, extension_sorting_->CreateNextAppLaunchOrdinal(new_page_ordinal)); | 1211 id, extension_sorting_->CreateNextAppLaunchOrdinal(new_page_ordinal)); |
| (...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1948 PrefService::UNSYNCABLE_PREF); | 1905 PrefService::UNSYNCABLE_PREF); |
| 1949 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, | 1906 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, |
| 1950 0, // default value | 1907 0, // default value |
| 1951 PrefService::UNSYNCABLE_PREF); | 1908 PrefService::UNSYNCABLE_PREF); |
| 1952 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, | 1909 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, |
| 1953 0, // default value | 1910 0, // default value |
| 1954 PrefService::UNSYNCABLE_PREF); | 1911 PrefService::UNSYNCABLE_PREF); |
| 1955 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites, | 1912 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites, |
| 1956 PrefService::UNSYNCABLE_PREF); | 1913 PrefService::UNSYNCABLE_PREF); |
| 1957 } | 1914 } |
| OLD | NEW |