[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame^] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ |
| 6 | #define CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ |
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 8 | |
| 9 | #include <set> |
| 10 | #include <string> |
| 11 | #include <vector> |
| 12 | |
[email protected] | 696044b | 2009-12-17 18:30:53 | [diff] [blame] | 13 | #include "base/linked_ptr.h" |
[email protected] | 5ef47ec | 2010-01-28 05:58:05 | [diff] [blame] | 14 | #include "base/time.h" |
[email protected] | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 15 | #include "chrome/browser/prefs/pref_service.h" |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 16 | #include "chrome/common/extensions/extension.h" |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 17 | #include "googleurl/src/gurl.h" |
| 18 | |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame^] | 19 | class ExtensionPrefValueMap; |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 20 | |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 21 | // Class for managing global and per-extension preferences. |
[email protected] | 73c4793 | 2010-12-06 18:13:43 | [diff] [blame] | 22 | // |
| 23 | // This class distinguishes the following kinds of preferences: |
| 24 | // - global preferences: |
| 25 | // internal state for the extension system in general, not associated |
| 26 | // with an individual extension, such as lastUpdateTime. |
| 27 | // - per-extension preferences: |
| 28 | // meta-preferences describing properties of the extension like |
| 29 | // installation time, whether the extension is enabled, etc. |
| 30 | // - extension controlled preferences: |
| 31 | // browser preferences that an extension controls. For example, an |
| 32 | // extension could use the proxy API to specify the browser's proxy |
| 33 | // preference. Extension-controlled preferences are stored in |
| 34 | // PrefValueStore::extension_prefs(), which this class populates and |
| 35 | // maintains as the underlying extensions change. |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 36 | class ExtensionPrefs { |
| 37 | public: |
[email protected] | 10abd19 | 2010-09-30 02:03:49 | [diff] [blame] | 38 | // Key name for a preference that keeps track of per-extension settings. This |
| 39 | // is a dictionary object read from the Preferences file, keyed off of |
| 40 | // extension ids. |
| 41 | static const char kExtensionsPref[]; |
| 42 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 43 | typedef std::vector<linked_ptr<ExtensionInfo> > ExtensionsInfo; |
| 44 | |
[email protected] | 73c4793 | 2010-12-06 18:13:43 | [diff] [blame] | 45 | // Vector containing identifiers for preferences. |
| 46 | typedef std::set<std::string> PrefKeySet; |
| 47 | |
| 48 | // Vector containing identifiers for extensions. |
| 49 | typedef std::vector<std::string> ExtensionIdSet; |
| 50 | |
[email protected] | 10abd19 | 2010-09-30 02:03:49 | [diff] [blame] | 51 | // This enum is used for the launch type the user wants to use for an |
| 52 | // application. |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 53 | // Do not remove items or re-order this enum as it is used in preferences |
| 54 | // and histograms. |
[email protected] | 10abd19 | 2010-09-30 02:03:49 | [diff] [blame] | 55 | enum LaunchType { |
| 56 | LAUNCH_PINNED, |
| 57 | LAUNCH_REGULAR, |
[email protected] | fa6a910 | 2010-11-22 15:38:50 | [diff] [blame] | 58 | LAUNCH_FULLSCREEN, |
| 59 | LAUNCH_WINDOW |
[email protected] | 10abd19 | 2010-09-30 02:03:49 | [diff] [blame] | 60 | }; |
| 61 | |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame^] | 62 | // Does not assume ownership of |prefs| and |incognito_prefs|. |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 63 | explicit ExtensionPrefs(PrefService* prefs, |
| 64 | const FilePath& root_dir, |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame^] | 65 | ExtensionPrefValueMap* extension_pref_value_map); |
[email protected] | 2858bbf | 2010-10-05 23:46:02 | [diff] [blame] | 66 | ~ExtensionPrefs(); |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 67 | |
| 68 | // Returns a copy of the Extensions prefs. |
| 69 | // TODO(erikkay) Remove this so that external consumers don't need to be |
| 70 | // aware of the internal structure of the preferences. |
| 71 | DictionaryValue* CopyCurrentExtensions(); |
| 72 | |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 73 | // Returns true if the specified extension has an entry in prefs |
| 74 | // and its killbit is on. |
| 75 | bool IsExtensionKilled(const std::string& id); |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 76 | |
| 77 | // Get the order that toolstrip URLs appear in the shelf. |
| 78 | typedef std::vector<GURL> URLList; |
| 79 | URLList GetShelfToolstripOrder(); |
| 80 | |
[email protected] | e81dba3 | 2009-06-19 20:19:13 | [diff] [blame] | 81 | // Sets the order that toolstrip URLs appear in the shelf. |
| 82 | void SetShelfToolstripOrder(const URLList& urls); |
| 83 | |
[email protected] | 216e0bc0 | 2009-12-14 20:51:29 | [diff] [blame] | 84 | // Get the order that the browser actions appear in the toolbar. |
| 85 | std::vector<std::string> GetToolbarOrder(); |
| 86 | |
| 87 | // Set the order that the browser actions appear in the toolbar. |
| 88 | void SetToolbarOrder(const std::vector<std::string>& extension_ids); |
| 89 | |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 90 | // Called when an extension is installed, so that prefs get created. |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 91 | void OnExtensionInstalled(const Extension* extension, |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 92 | Extension::State initial_state, |
| 93 | bool initial_incognito_enabled); |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 94 | |
| 95 | // Called when an extension is uninstalled, so that prefs get cleaned up. |
[email protected] | 831aa21 | 2010-03-26 13:55:19 | [diff] [blame] | 96 | void OnExtensionUninstalled(const std::string& extension_id, |
| 97 | const Extension::Location& location, |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 98 | bool external_uninstall); |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 99 | |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 100 | // Returns the state (enabled/disabled) of the given extension. |
[email protected] | 73c4793 | 2010-12-06 18:13:43 | [diff] [blame] | 101 | Extension::State GetExtensionState(const std::string& extension_id) const; |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 102 | |
| 103 | // Called to change the extension's state when it is enabled/disabled. |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 104 | void SetExtensionState(const Extension* extension, Extension::State); |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 105 | |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame^] | 106 | // Returns all installed extensions |
| 107 | void GetExtensions(ExtensionIdSet* out) const; |
[email protected] | 73c4793 | 2010-12-06 18:13:43 | [diff] [blame] | 108 | |
[email protected] | f681c78 | 2010-11-19 11:19:39 | [diff] [blame] | 109 | // Getter and setter for browser action visibility. |
| 110 | bool GetBrowserActionVisibility(const Extension* extension); |
| 111 | void SetBrowserActionVisibility(const Extension* extension, bool visible); |
| 112 | |
[email protected] | e6090e4 | 2010-03-23 22:44:08 | [diff] [blame] | 113 | // Did the extension ask to escalate its permission during an upgrade? |
| 114 | bool DidExtensionEscalatePermissions(const std::string& id); |
| 115 | |
| 116 | // If |did_escalate| is true, the preferences for |extension| will be set to |
[email protected] | 7d84586 | 2010-01-04 21:28:57 | [diff] [blame] | 117 | // require the install warning when the user tries to enable. |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 118 | void SetDidExtensionEscalatePermissions(const Extension* extension, |
[email protected] | e6090e4 | 2010-03-23 22:44:08 | [diff] [blame] | 119 | bool did_escalate); |
[email protected] | 7d84586 | 2010-01-04 21:28:57 | [diff] [blame] | 120 | |
[email protected] | b6ab96d | 2009-08-20 18:58:19 | [diff] [blame] | 121 | // Returns the version string for the currently installed extension, or |
| 122 | // the empty string if not found. |
| 123 | std::string GetVersionString(const std::string& extension_id); |
| 124 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 125 | // Re-writes the extension manifest into the prefs. |
| 126 | // Called to change the extension's manifest when it's re-localized. |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 127 | void UpdateManifest(const Extension* extension); |
[email protected] | b6ab96d | 2009-08-20 18:58:19 | [diff] [blame] | 128 | |
[email protected] | 371ed7a | 2009-08-25 15:22:46 | [diff] [blame] | 129 | // Returns extension path based on extension ID, or empty FilePath on error. |
| 130 | FilePath GetExtensionPath(const std::string& extension_id); |
| 131 | |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 132 | // Returns base extensions install directory. |
| 133 | const FilePath& install_directory() const { return install_directory_; } |
| 134 | |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 135 | // Updates the prefs based on the blacklist. |
| 136 | void UpdateBlacklist(const std::set<std::string>& blacklist_set); |
| 137 | |
| 138 | // Based on extension id, checks prefs to see if it is blacklisted. |
| 139 | bool IsExtensionBlacklisted(const std::string& id); |
| 140 | |
[email protected] | 306a2bd | 2010-08-11 14:56:36 | [diff] [blame] | 141 | // Is the extension with |extension_id| allowed by policy (checking both |
| 142 | // whitelist and blacklist). |
| 143 | bool IsExtensionAllowedByPolicy(const std::string& extension_id); |
| 144 | |
[email protected] | 5ef47ec | 2010-01-28 05:58:05 | [diff] [blame] | 145 | // Returns the last value set via SetLastPingDay. If there isn't such a |
| 146 | // pref, the returned Time will return true for is_null(). |
[email protected] | c5804aa1 | 2010-03-30 23:44:06 | [diff] [blame] | 147 | base::Time LastPingDay(const std::string& extension_id) const; |
[email protected] | 5ef47ec | 2010-01-28 05:58:05 | [diff] [blame] | 148 | |
| 149 | // The time stored is based on the server's perspective of day start time, not |
| 150 | // the client's. |
| 151 | void SetLastPingDay(const std::string& extension_id, const base::Time& time); |
| 152 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 153 | // Gets the permissions (|api_permissions|, |host_extent| and |full_access|) |
| 154 | // granted to the extension with |extension_id|. |full_access| will be true |
| 155 | // if the extension has all effective permissions (like from an NPAPI plugin). |
| 156 | // Returns false if the granted permissions haven't been initialized yet. |
| 157 | // TODO(jstritar): Refractor the permissions into a class that encapsulates |
| 158 | // all granted permissions, can be initialized from preferences or |
| 159 | // a manifest file, and can be compared to each other. |
| 160 | bool GetGrantedPermissions(const std::string& extension_id, |
| 161 | bool* full_access, |
| 162 | std::set<std::string>* api_permissions, |
| 163 | ExtensionExtent* host_extent); |
| 164 | |
| 165 | // Adds the specified |api_permissions|, |host_extent| and |full_access| |
| 166 | // to the granted permissions for extension with |extension_id|. |
| 167 | // |full_access| should be set to true if the extension effectively has all |
| 168 | // permissions (such as by having an NPAPI plugin). |
| 169 | void AddGrantedPermissions(const std::string& extension_id, |
| 170 | const bool full_access, |
| 171 | const std::set<std::string>& api_permissions, |
| 172 | const ExtensionExtent& host_extent); |
| 173 | |
[email protected] | aca840c | 2010-04-06 23:33:04 | [diff] [blame] | 174 | // Similar to the 2 above, but for the extensions blacklist. |
| 175 | base::Time BlacklistLastPingDay() const; |
| 176 | void SetBlacklistLastPingDay(const base::Time& time); |
| 177 | |
[email protected] | 55a3569 | 2010-02-11 23:25:21 | [diff] [blame] | 178 | // Returns true if the user enabled this extension to be loaded in incognito |
| 179 | // mode. |
| 180 | bool IsIncognitoEnabled(const std::string& extension_id); |
| 181 | void SetIsIncognitoEnabled(const std::string& extension_id, bool enabled); |
[email protected] | 5ef47ec | 2010-01-28 05:58:05 | [diff] [blame] | 182 | |
[email protected] | 05c8218 | 2010-06-24 17:49:08 | [diff] [blame] | 183 | // Returns true if the user has chosen to allow this extension to inject |
| 184 | // scripts into pages with file URLs. |
| 185 | bool AllowFileAccess(const std::string& extension_id); |
| 186 | void SetAllowFileAccess(const std::string& extension_id, bool allow); |
| 187 | |
[email protected] | a3b734b | 2010-11-30 03:17:11 | [diff] [blame] | 188 | // Get the launch type preference. If no preference is set, return |
| 189 | // |default_pref_value|. |
| 190 | LaunchType GetLaunchType(const std::string& extension_id, |
| 191 | LaunchType default_pref_value); |
| 192 | |
[email protected] | 10abd19 | 2010-09-30 02:03:49 | [diff] [blame] | 193 | void SetLaunchType(const std::string& extension_id, LaunchType launch_type); |
| 194 | |
[email protected] | a3b734b | 2010-11-30 03:17:11 | [diff] [blame] | 195 | // Find the right launch container based on the launch type. |
| 196 | // If |extension|'s prefs do not have a launch type set, then |
| 197 | // use |default_pref_value|. |
| 198 | extension_misc::LaunchContainer GetLaunchContainer( |
| 199 | const Extension* extension, |
| 200 | LaunchType default_pref_value); |
| 201 | |
| 202 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 203 | // Saves ExtensionInfo for each installed extension with the path to the |
| 204 | // version directory and the location. Blacklisted extensions won't be saved |
| 205 | // and neither will external extensions the user has explicitly uninstalled. |
| 206 | // Caller takes ownership of returned structure. |
[email protected] | e6090e4 | 2010-03-23 22:44:08 | [diff] [blame] | 207 | ExtensionsInfo* GetInstalledExtensionsInfo(); |
| 208 | |
| 209 | // Returns the ExtensionInfo from the prefs for the given extension. If the |
| 210 | // extension is not present, NULL is returned. |
| 211 | ExtensionInfo* GetInstalledExtensionInfo(const std::string& extension_id); |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 212 | |
[email protected] | 63c64d1 | 2010-04-27 21:21:34 | [diff] [blame] | 213 | // We've downloaded an updated .crx file for the extension, but are waiting |
| 214 | // for idle time to install it. |
| 215 | void SetIdleInstallInfo(const std::string& extension_id, |
| 216 | const FilePath& crx_path, |
| 217 | const std::string& version, |
| 218 | const base::Time& fetch_time); |
| 219 | |
| 220 | // Removes any idle install information we have for the given |extension_id|. |
| 221 | // Returns true if there was info to remove; false otherwise. |
| 222 | bool RemoveIdleInstallInfo(const std::string& extension_id); |
| 223 | |
| 224 | // If we have idle install information for |extension_id|, this puts it into |
| 225 | // the out parameters and returns true. Otherwise returns false. |
| 226 | bool GetIdleInstallInfo(const std::string& extension_id, |
| 227 | FilePath* crx_path, |
| 228 | std::string* version, |
| 229 | base::Time* fetch_time); |
| 230 | |
| 231 | // Returns the extension id's that have idle install information. |
| 232 | std::set<std::string> GetIdleInstallInfoIds(); |
| 233 | |
[email protected] | 63cda0c | 2010-09-01 04:41:23 | [diff] [blame] | 234 | // We allow the web store to set a string containing login information when a |
| 235 | // purchase is made, so that when a user logs into sync with a different |
| 236 | // account we can recognize the situation. The Get function returns true if |
| 237 | // there was previously stored data (placing it in |result|), or false |
| 238 | // otherwise. The Set will overwrite any previous login. |
| 239 | bool GetWebStoreLogin(std::string* result); |
| 240 | void SetWebStoreLogin(const std::string& login); |
| 241 | |
[email protected] | ebfd4b9 | 2010-10-10 09:17:08 | [diff] [blame] | 242 | // Get the application launch index for an extension with |extension_id|. This |
| 243 | // determines the order of which the applications appear on the New Tab Page. |
| 244 | // A value of 0 generally indicates top left. If the extension has no launch |
| 245 | // index a -1 value is returned. |
| 246 | int GetAppLaunchIndex(const std::string& extension_id); |
| 247 | |
| 248 | // Sets a specific launch index for an extension with |extension_id|. |
| 249 | void SetAppLaunchIndex(const std::string& extension_id, int index); |
| 250 | |
| 251 | // Gets the next available application launch index. This is 1 higher than the |
| 252 | // highest current application launch index found. |
| 253 | int GetNextAppLaunchIndex(); |
| 254 | |
[email protected] | 4828164 | 2011-01-24 03:41:02 | [diff] [blame] | 255 | // Sets the order the apps should be displayed in the app launcher. |
| 256 | void SetAppLauncherOrder(const std::vector<std::string>& extension_ids); |
| 257 | |
[email protected] | a65882c | 2010-11-12 15:15:09 | [diff] [blame] | 258 | // The extension's update URL data. If not empty, the ExtensionUpdater |
| 259 | // will append a ap= parameter to the URL when checking if a new version |
| 260 | // of the extension is available. |
| 261 | void SetUpdateUrlData(const std::string& extension_id, |
| 262 | const std::string& data); |
| 263 | std::string GetUpdateUrlData(const std::string& extension_id); |
| 264 | |
[email protected] | 73c4793 | 2010-12-06 18:13:43 | [diff] [blame] | 265 | // Sets a preference value that is controlled by the extension. In other |
| 266 | // words, this is not a pref value *about* the extension but something |
| 267 | // global the extension wants to override. |
| 268 | void SetExtensionControlledPref(const std::string& extension_id, |
| 269 | const std::string& pref_key, |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame^] | 270 | bool incognito, |
[email protected] | 73c4793 | 2010-12-06 18:13:43 | [diff] [blame] | 271 | Value* value); |
| 272 | |
[email protected] | fee8f022 | 2010-03-17 01:13:37 | [diff] [blame] | 273 | static void RegisterUserPrefs(PrefService* prefs); |
| 274 | |
[email protected] | ba39967 | 2010-04-06 15:42:39 | [diff] [blame] | 275 | // The underlying PrefService. |
| 276 | PrefService* pref_service() const { return prefs_; } |
| 277 | |
[email protected] | 73c4793 | 2010-12-06 18:13:43 | [diff] [blame] | 278 | protected: |
| 279 | // For unit testing. Enables injecting an artificial clock that is used |
| 280 | // to query the current time, when an extension is installed. |
| 281 | virtual base::Time GetCurrentTime() const; |
| 282 | |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 283 | private: |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 284 | // Converts absolute paths in the pref to paths relative to the |
| 285 | // install_directory_. |
| 286 | void MakePathsRelative(); |
| 287 | |
| 288 | // Converts internal relative paths to be absolute. Used for export to |
| 289 | // consumers who expect full paths. |
| 290 | void MakePathsAbsolute(DictionaryValue* dict); |
| 291 | |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 292 | // Sets the pref |key| for extension |id| to |value|. |
[email protected] | 4dad9ad8 | 2009-11-25 20:47:52 | [diff] [blame] | 293 | void UpdateExtensionPref(const std::string& id, |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 294 | const std::string& key, |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 295 | Value* value); |
| 296 | |
| 297 | // Deletes the pref dictionary for extension |id|. |
| 298 | void DeleteExtensionPrefs(const std::string& id); |
| 299 | |
[email protected] | 7d84586 | 2010-01-04 21:28:57 | [diff] [blame] | 300 | // Reads a boolean pref from |ext| with key |pref_key|. |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 301 | // Return false if the value is false or |pref_key| does not exist. |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 302 | bool ReadBooleanFromPref(DictionaryValue* ext, const std::string& pref_key); |
[email protected] | 7d84586 | 2010-01-04 21:28:57 | [diff] [blame] | 303 | |
| 304 | // Reads a boolean pref |pref_key| from extension with id |extension_id|. |
| 305 | bool ReadExtensionPrefBoolean(const std::string& extension_id, |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 306 | const std::string& pref_key); |
[email protected] | 7d84586 | 2010-01-04 21:28:57 | [diff] [blame] | 307 | |
[email protected] | 10abd19 | 2010-09-30 02:03:49 | [diff] [blame] | 308 | // Reads an integer pref from |ext| with key |pref_key|. |
| 309 | // Return false if the value does not exist. |
| 310 | bool ReadIntegerFromPref(DictionaryValue* ext, const std::string& pref_key, |
| 311 | int* out_value); |
| 312 | |
| 313 | // Reads an integer pref |pref_key| from extension with id |extension_id|. |
| 314 | bool ReadExtensionPrefInteger(const std::string& extension_id, |
| 315 | const std::string& pref_key, |
| 316 | int* out_value); |
| 317 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 318 | // Reads a list pref |pref_key| from extension with id | extension_id|. |
| 319 | bool ReadExtensionPrefList(const std::string& extension_id, |
| 320 | const std::string& pref_key, |
| 321 | ListValue** out_value); |
| 322 | |
| 323 | // Reads a list pref |pref_key| as a string set from the extension with |
| 324 | // id |extension_id|. |
| 325 | bool ReadExtensionPrefStringSet(const std::string& extension_id, |
| 326 | const std::string& pref_key, |
| 327 | std::set<std::string>* result); |
| 328 | |
| 329 | // Adds the |added_values| to the value of |pref_key| for the extension |
| 330 | // with id |extension_id| (the new value will be the union of the existing |
| 331 | // value and |added_values|). |
| 332 | void AddToExtensionPrefStringSet(const std::string& extension_id, |
| 333 | const std::string& pref_key, |
| 334 | const std::set<std::string>& added_values); |
| 335 | |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 336 | // Ensures and returns a mutable dictionary for extension |id|'s prefs. |
| 337 | DictionaryValue* GetOrCreateExtensionPref(const std::string& id); |
| 338 | |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 339 | // Same as above, but returns NULL if it doesn't exist. |
[email protected] | c5804aa1 | 2010-03-30 23:44:06 | [diff] [blame] | 340 | DictionaryValue* GetExtensionPref(const std::string& id) const; |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 341 | |
[email protected] | 73c4793 | 2010-12-06 18:13:43 | [diff] [blame] | 342 | // Returns the dictionary of preferences controlled by the specified extension |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame^] | 343 | // or creates a new one. All entries in the dictionary contain non-expanded |
[email protected] | 73c4793 | 2010-12-06 18:13:43 | [diff] [blame] | 344 | // paths. |
| 345 | DictionaryValue* GetExtensionControlledPrefs(const std::string& id) const; |
| 346 | |
[email protected] | 10abd19 | 2010-09-30 02:03:49 | [diff] [blame] | 347 | // Serializes the data and schedules a persistent save via the |PrefService|. |
| 348 | // Additionally fires a PREF_CHANGED notification with the top-level |
| 349 | // |kExtensionsPref| path set. |
| 350 | // TODO(andybons): Switch this to EXTENSION_PREF_CHANGED to be more granular. |
| 351 | // TODO(andybons): Use a ScopedPrefUpdate to update observers on changes to |
| 352 | // the mutable extension dictionary. |
| 353 | void SavePrefsAndNotify(); |
| 354 | |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 355 | // Checks if kPrefBlacklist is set to true in the DictionaryValue. |
| 356 | // Return false if the value is false or kPrefBlacklist does not exist. |
| 357 | // This is used to decide if an extension is blacklisted. |
| 358 | bool IsBlacklistBitSet(DictionaryValue* ext); |
| 359 | |
[email protected] | aca840c | 2010-04-06 23:33:04 | [diff] [blame] | 360 | // Helper methods for the public last ping day functions. |
| 361 | base::Time LastPingDayImpl(const DictionaryValue* dictionary) const; |
| 362 | void SetLastPingDayImpl(const base::Time& time, DictionaryValue* dictionary); |
| 363 | |
[email protected] | 73c4793 | 2010-12-06 18:13:43 | [diff] [blame] | 364 | // Helper method to acquire the installation time of an extension. |
[email protected] | eb29cc02 | 2011-01-10 17:23:07 | [diff] [blame] | 365 | // Returns base::Time() if the installation time could not be parsed or |
| 366 | // found. |
[email protected] | 73c4793 | 2010-12-06 18:13:43 | [diff] [blame] | 367 | base::Time GetInstallTime(const std::string& extension_id) const; |
| 368 | |
| 369 | // Fix missing preference entries in the extensions that are were introduced |
| 370 | // in a later Chrome version. |
| 371 | void FixMissingPrefs(const ExtensionIdSet& extension_ids); |
| 372 | |
| 373 | // Installs the persistent extension preferences into |prefs_|'s extension |
| 374 | // pref store. |
| 375 | void InitPrefStore(); |
| 376 | |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame^] | 377 | // The pref service specific to this set of extension prefs. Owned by profile. |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 378 | PrefService* prefs_; |
| 379 | |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 380 | // Base extensions install directory. |
| 381 | FilePath install_directory_; |
| 382 | |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame^] | 383 | // Weak pointer, owned by Profile. |
| 384 | ExtensionPrefValueMap* extension_pref_value_map_; |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 385 | |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 386 | // The URLs of all of the toolstrips. |
| 387 | URLList shelf_order_; |
| 388 | |
| 389 | DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs); |
| 390 | }; |
| 391 | |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 392 | #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ |