| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/linked_ptr.h" | 13 #include "base/linked_ptr.h" |
| 14 #include "base/time.h" | 14 #include "base/time.h" |
| 15 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
| 16 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
| 17 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 18 | 18 |
| 19 // Class for managing global and per-extension preferences. | 19 // Class for managing global and per-extension preferences. |
| 20 // This class is instantiated by ExtensionsService, so it should be accessed | 20 // This class is instantiated by ExtensionsService, so it should be accessed |
| 21 // from there. | 21 // from there. |
| 22 class ExtensionPrefs { | 22 class ExtensionPrefs { |
| 23 public: | 23 public: |
| 24 // Key name for a preference that keeps track of per-extension settings. This |
| 25 // is a dictionary object read from the Preferences file, keyed off of |
| 26 // extension ids. |
| 27 static const char kExtensionsPref[]; |
| 28 |
| 24 typedef std::vector<linked_ptr<ExtensionInfo> > ExtensionsInfo; | 29 typedef std::vector<linked_ptr<ExtensionInfo> > ExtensionsInfo; |
| 25 | 30 |
| 31 // This enum is used for the launch type the user wants to use for an |
| 32 // application. |
| 33 enum LaunchType { |
| 34 LAUNCH_PINNED, |
| 35 LAUNCH_REGULAR, |
| 36 LAUNCH_FULLSCREEN |
| 37 }; |
| 38 |
| 26 explicit ExtensionPrefs(PrefService* prefs, const FilePath& root_dir_); | 39 explicit ExtensionPrefs(PrefService* prefs, const FilePath& root_dir_); |
| 27 | 40 |
| 28 // Returns a copy of the Extensions prefs. | 41 // Returns a copy of the Extensions prefs. |
| 29 // TODO(erikkay) Remove this so that external consumers don't need to be | 42 // TODO(erikkay) Remove this so that external consumers don't need to be |
| 30 // aware of the internal structure of the preferences. | 43 // aware of the internal structure of the preferences. |
| 31 DictionaryValue* CopyCurrentExtensions(); | 44 DictionaryValue* CopyCurrentExtensions(); |
| 32 | 45 |
| 33 // Populate |killed_ids| with extension ids that have been killed. | 46 // Populate |killed_ids| with extension ids that have been killed. |
| 34 void GetKilledExtensionIds(std::set<std::string>* killed_ids); | 47 void GetKilledExtensionIds(std::set<std::string>* killed_ids); |
| 35 | 48 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 // Returns true if the user enabled this extension to be loaded in incognito | 122 // Returns true if the user enabled this extension to be loaded in incognito |
| 110 // mode. | 123 // mode. |
| 111 bool IsIncognitoEnabled(const std::string& extension_id); | 124 bool IsIncognitoEnabled(const std::string& extension_id); |
| 112 void SetIsIncognitoEnabled(const std::string& extension_id, bool enabled); | 125 void SetIsIncognitoEnabled(const std::string& extension_id, bool enabled); |
| 113 | 126 |
| 114 // Returns true if the user has chosen to allow this extension to inject | 127 // Returns true if the user has chosen to allow this extension to inject |
| 115 // scripts into pages with file URLs. | 128 // scripts into pages with file URLs. |
| 116 bool AllowFileAccess(const std::string& extension_id); | 129 bool AllowFileAccess(const std::string& extension_id); |
| 117 void SetAllowFileAccess(const std::string& extension_id, bool allow); | 130 void SetAllowFileAccess(const std::string& extension_id, bool allow); |
| 118 | 131 |
| 132 ExtensionPrefs::LaunchType GetLaunchType(const std::string& extension_id); |
| 133 void SetLaunchType(const std::string& extension_id, LaunchType launch_type); |
| 134 |
| 119 // Saves ExtensionInfo for each installed extension with the path to the | 135 // Saves ExtensionInfo for each installed extension with the path to the |
| 120 // version directory and the location. Blacklisted extensions won't be saved | 136 // version directory and the location. Blacklisted extensions won't be saved |
| 121 // and neither will external extensions the user has explicitly uninstalled. | 137 // and neither will external extensions the user has explicitly uninstalled. |
| 122 // Caller takes ownership of returned structure. | 138 // Caller takes ownership of returned structure. |
| 123 ExtensionsInfo* GetInstalledExtensionsInfo(); | 139 ExtensionsInfo* GetInstalledExtensionsInfo(); |
| 124 | 140 |
| 125 // Returns the ExtensionInfo from the prefs for the given extension. If the | 141 // Returns the ExtensionInfo from the prefs for the given extension. If the |
| 126 // extension is not present, NULL is returned. | 142 // extension is not present, NULL is returned. |
| 127 ExtensionInfo* GetInstalledExtensionInfo(const std::string& extension_id); | 143 ExtensionInfo* GetInstalledExtensionInfo(const std::string& extension_id); |
| 128 | 144 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 void DeleteExtensionPrefs(const std::string& id); | 194 void DeleteExtensionPrefs(const std::string& id); |
| 179 | 195 |
| 180 // Reads a boolean pref from |ext| with key |pref_key|. | 196 // Reads a boolean pref from |ext| with key |pref_key|. |
| 181 // Return false if the value is false or kPrefBlacklist does not exist. | 197 // Return false if the value is false or kPrefBlacklist does not exist. |
| 182 bool ReadBooleanFromPref(DictionaryValue* ext, const std::string& pref_key); | 198 bool ReadBooleanFromPref(DictionaryValue* ext, const std::string& pref_key); |
| 183 | 199 |
| 184 // Reads a boolean pref |pref_key| from extension with id |extension_id|. | 200 // Reads a boolean pref |pref_key| from extension with id |extension_id|. |
| 185 bool ReadExtensionPrefBoolean(const std::string& extension_id, | 201 bool ReadExtensionPrefBoolean(const std::string& extension_id, |
| 186 const std::string& pref_key); | 202 const std::string& pref_key); |
| 187 | 203 |
| 204 // Reads an integer pref from |ext| with key |pref_key|. |
| 205 // Return false if the value does not exist. |
| 206 bool ReadIntegerFromPref(DictionaryValue* ext, const std::string& pref_key, |
| 207 int* out_value); |
| 208 |
| 209 // Reads an integer pref |pref_key| from extension with id |extension_id|. |
| 210 bool ReadExtensionPrefInteger(const std::string& extension_id, |
| 211 const std::string& pref_key, |
| 212 int* out_value); |
| 213 |
| 188 // Ensures and returns a mutable dictionary for extension |id|'s prefs. | 214 // Ensures and returns a mutable dictionary for extension |id|'s prefs. |
| 189 DictionaryValue* GetOrCreateExtensionPref(const std::string& id); | 215 DictionaryValue* GetOrCreateExtensionPref(const std::string& id); |
| 190 | 216 |
| 191 // Same as above, but returns NULL if it doesn't exist. | 217 // Same as above, but returns NULL if it doesn't exist. |
| 192 DictionaryValue* GetExtensionPref(const std::string& id) const; | 218 DictionaryValue* GetExtensionPref(const std::string& id) const; |
| 193 | 219 |
| 220 // Serializes the data and schedules a persistent save via the |PrefService|. |
| 221 // Additionally fires a PREF_CHANGED notification with the top-level |
| 222 // |kExtensionsPref| path set. |
| 223 // TODO(andybons): Switch this to EXTENSION_PREF_CHANGED to be more granular. |
| 224 // TODO(andybons): Use a ScopedPrefUpdate to update observers on changes to |
| 225 // the mutable extension dictionary. |
| 226 void SavePrefsAndNotify(); |
| 227 |
| 194 // Checks if kPrefBlacklist is set to true in the DictionaryValue. | 228 // Checks if kPrefBlacklist is set to true in the DictionaryValue. |
| 195 // Return false if the value is false or kPrefBlacklist does not exist. | 229 // Return false if the value is false or kPrefBlacklist does not exist. |
| 196 // This is used to decide if an extension is blacklisted. | 230 // This is used to decide if an extension is blacklisted. |
| 197 bool IsBlacklistBitSet(DictionaryValue* ext); | 231 bool IsBlacklistBitSet(DictionaryValue* ext); |
| 198 | 232 |
| 199 // Helper methods for the public last ping day functions. | 233 // Helper methods for the public last ping day functions. |
| 200 base::Time LastPingDayImpl(const DictionaryValue* dictionary) const; | 234 base::Time LastPingDayImpl(const DictionaryValue* dictionary) const; |
| 201 void SetLastPingDayImpl(const base::Time& time, DictionaryValue* dictionary); | 235 void SetLastPingDayImpl(const base::Time& time, DictionaryValue* dictionary); |
| 202 | 236 |
| 203 // The pref service specific to this set of extension prefs. | 237 // The pref service specific to this set of extension prefs. |
| 204 PrefService* prefs_; | 238 PrefService* prefs_; |
| 205 | 239 |
| 206 // Base extensions install directory. | 240 // Base extensions install directory. |
| 207 FilePath install_directory_; | 241 FilePath install_directory_; |
| 208 | 242 |
| 209 // The URLs of all of the toolstrips. | 243 // The URLs of all of the toolstrips. |
| 210 URLList shelf_order_; | 244 URLList shelf_order_; |
| 211 | 245 |
| 212 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs); | 246 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs); |
| 213 }; | 247 }; |
| 214 | 248 |
| 215 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ | 249 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ |
| OLD | NEW |