| 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/api/alarms/alarm_manager.h" | 10 #include "chrome/browser/extensions/api/alarms/alarm_manager.h" |
| 11 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" |
| 11 #include "chrome/browser/extensions/extension_pref_store.h" | 12 #include "chrome/browser/extensions/extension_pref_store.h" |
| 12 #include "chrome/browser/extensions/extension_sorting.h" | 13 #include "chrome/browser/extensions/extension_sorting.h" |
| 13 #include "chrome/browser/prefs/pref_notifier.h" | 14 #include "chrome/browser/prefs/pref_notifier.h" |
| 14 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
| 15 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 16 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 16 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
| 17 #include "chrome/common/extensions/manifest.h" | 18 #include "chrome/common/extensions/manifest.h" |
| 18 #include "chrome/common/extensions/url_pattern.h" | 19 #include "chrome/common/extensions/url_pattern.h" |
| 19 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 20 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 const char kPrefIncognitoContentSettings[] = "incognito_content_settings"; | 156 const char kPrefIncognitoContentSettings[] = "incognito_content_settings"; |
| 156 | 157 |
| 157 // A list of event names that this extension has registered from its lazy | 158 // A list of event names that this extension has registered from its lazy |
| 158 // background page. | 159 // background page. |
| 159 const char kRegisteredEvents[] = "events"; | 160 const char kRegisteredEvents[] = "events"; |
| 160 | 161 |
| 161 // A list of alarms that this extension has set. | 162 // A list of alarms that this extension has set. |
| 162 const char kRegisteredAlarms[] = "alarms"; | 163 const char kRegisteredAlarms[] = "alarms"; |
| 163 const char kAlarmScheduledRunTime[] = "scheduled_run_time"; | 164 const char kAlarmScheduledRunTime[] = "scheduled_run_time"; |
| 164 | 165 |
| 166 // Persisted value for omnibox.setDefaultSuggestion. |
| 167 const char kOmniboxDefaultSuggestion[] = "omnibox_default_suggestion"; |
| 168 |
| 165 // Provider of write access to a dictionary storing extension prefs. | 169 // Provider of write access to a dictionary storing extension prefs. |
| 166 class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate { | 170 class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate { |
| 167 public: | 171 public: |
| 168 ScopedExtensionPrefUpdate(PrefService* service, | 172 ScopedExtensionPrefUpdate(PrefService* service, |
| 169 const std::string& extension_id) : | 173 const std::string& extension_id) : |
| 170 DictionaryPrefUpdate(service, ExtensionPrefs::kExtensionsPref), | 174 DictionaryPrefUpdate(service, ExtensionPrefs::kExtensionsPref), |
| 171 extension_id_(extension_id) {} | 175 extension_id_(extension_id) {} |
| 172 | 176 |
| 173 virtual ~ScopedExtensionPrefUpdate() { | 177 virtual ~ScopedExtensionPrefUpdate() { |
| 174 } | 178 } |
| (...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 994 const std::vector<extensions::AlarmPref>& alarms) { | 998 const std::vector<extensions::AlarmPref>& alarms) { |
| 995 base::ListValue* list = new ListValue(); | 999 base::ListValue* list = new ListValue(); |
| 996 for (size_t i = 0; i < alarms.size(); ++i) { | 1000 for (size_t i = 0; i < alarms.size(); ++i) { |
| 997 scoped_ptr<base::DictionaryValue> alarm = alarms[i].alarm->ToValue().Pass(); | 1001 scoped_ptr<base::DictionaryValue> alarm = alarms[i].alarm->ToValue().Pass(); |
| 998 SaveTime(alarm.get(), kAlarmScheduledRunTime, alarms[i].scheduled_run_time); | 1002 SaveTime(alarm.get(), kAlarmScheduledRunTime, alarms[i].scheduled_run_time); |
| 999 list->Append(alarm.release()); | 1003 list->Append(alarm.release()); |
| 1000 } | 1004 } |
| 1001 UpdateExtensionPref(extension_id, kRegisteredAlarms, list); | 1005 UpdateExtensionPref(extension_id, kRegisteredAlarms, list); |
| 1002 } | 1006 } |
| 1003 | 1007 |
| 1008 extensions::ExtensionOmniboxSuggestion |
| 1009 ExtensionPrefs::GetOmniboxDefaultSuggestion(const std::string& extension_id) { |
| 1010 extensions::ExtensionOmniboxSuggestion suggestion; |
| 1011 |
| 1012 const base::DictionaryValue* extension = GetExtensionPref(extension_id); |
| 1013 base::DictionaryValue* dict = NULL; |
| 1014 if (extension && extension->GetDictionary(kOmniboxDefaultSuggestion, &dict)) |
| 1015 suggestion.Populate(*dict, false); |
| 1016 |
| 1017 return suggestion; |
| 1018 } |
| 1019 |
| 1020 void ExtensionPrefs::SetOmniboxDefaultSuggestion( |
| 1021 const std::string& extension_id, |
| 1022 const extensions::ExtensionOmniboxSuggestion& suggestion) { |
| 1023 scoped_ptr<base::DictionaryValue> dict = suggestion.ToValue().Pass(); |
| 1024 UpdateExtensionPref(extension_id, kOmniboxDefaultSuggestion, dict.release()); |
| 1025 } |
| 1026 |
| 1004 bool ExtensionPrefs::IsIncognitoEnabled(const std::string& extension_id) { | 1027 bool ExtensionPrefs::IsIncognitoEnabled(const std::string& extension_id) { |
| 1005 return ReadExtensionPrefBoolean(extension_id, kPrefIncognitoEnabled); | 1028 return ReadExtensionPrefBoolean(extension_id, kPrefIncognitoEnabled); |
| 1006 } | 1029 } |
| 1007 | 1030 |
| 1008 void ExtensionPrefs::SetIsIncognitoEnabled(const std::string& extension_id, | 1031 void ExtensionPrefs::SetIsIncognitoEnabled(const std::string& extension_id, |
| 1009 bool enabled) { | 1032 bool enabled) { |
| 1010 UpdateExtensionPref(extension_id, kPrefIncognitoEnabled, | 1033 UpdateExtensionPref(extension_id, kPrefIncognitoEnabled, |
| 1011 Value::CreateBooleanValue(enabled)); | 1034 Value::CreateBooleanValue(enabled)); |
| 1012 } | 1035 } |
| 1013 | 1036 |
| (...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1871 prefs->RegisterStringPref(prefs::kExtensionBlacklistUpdateVersion, | 1894 prefs->RegisterStringPref(prefs::kExtensionBlacklistUpdateVersion, |
| 1872 "0", // default value | 1895 "0", // default value |
| 1873 PrefService::UNSYNCABLE_PREF); | 1896 PrefService::UNSYNCABLE_PREF); |
| 1874 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, | 1897 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, |
| 1875 0, // default value | 1898 0, // default value |
| 1876 PrefService::UNSYNCABLE_PREF); | 1899 PrefService::UNSYNCABLE_PREF); |
| 1877 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, | 1900 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, |
| 1878 0, // default value | 1901 0, // default value |
| 1879 PrefService::UNSYNCABLE_PREF); | 1902 PrefService::UNSYNCABLE_PREF); |
| 1880 } | 1903 } |
| OLD | NEW |