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 // | |
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 // global preferences that an individual extension wants to set; | |
32 // these are arbitrary preferences that are controlled by other | |
33 // sub-systems. | |
22 class ExtensionPrefs { | 34 class ExtensionPrefs { |
23 public: | 35 public: |
24 // Key name for a preference that keeps track of per-extension settings. This | 36 // 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 | 37 // is a dictionary object read from the Preferences file, keyed off of |
26 // extension ids. | 38 // extension ids. |
27 static const char kExtensionsPref[]; | 39 static const char kExtensionsPref[]; |
28 | 40 |
29 typedef std::vector<linked_ptr<ExtensionInfo> > ExtensionsInfo; | 41 typedef std::vector<linked_ptr<ExtensionInfo> > ExtensionsInfo; |
30 | 42 |
43 // Vector containing identifiers for preferences. | |
44 typedef std::vector<std::string> PrefKeySet; | |
45 | |
46 // Vector containing identifiers for extensions. | |
47 typedef std::vector<std::string> ExtensionIdSet; | |
48 | |
31 // This enum is used for the launch type the user wants to use for an | 49 // This enum is used for the launch type the user wants to use for an |
32 // application. | 50 // application. |
33 // Do not remove items or re-order this enum as it is used in preferences | 51 // Do not remove items or re-order this enum as it is used in preferences |
34 // and histograms. | 52 // and histograms. |
35 enum LaunchType { | 53 enum LaunchType { |
36 LAUNCH_PINNED, | 54 LAUNCH_PINNED, |
37 LAUNCH_REGULAR, | 55 LAUNCH_REGULAR, |
38 LAUNCH_FULLSCREEN, | 56 LAUNCH_FULLSCREEN, |
39 LAUNCH_WINDOW | 57 LAUNCH_WINDOW |
40 }; | 58 }; |
41 | 59 |
42 explicit ExtensionPrefs(PrefService* prefs, const FilePath& root_dir_); | 60 explicit ExtensionPrefs(Profile* profile, |
61 PrefService* prefs, | |
62 const FilePath& root_dir); | |
Mattias Nissler (ping if slow)
2010/12/01 10:36:36
Can we guarantee that the ExtensionPrefStore outli
battre (please use the other)
2010/12/01 17:44:38
Done. Moved PrefService in ProfileImpl accordingly
| |
43 ~ExtensionPrefs(); | 63 ~ExtensionPrefs(); |
44 | 64 |
45 // Returns a copy of the Extensions prefs. | 65 // Returns a copy of the Extensions prefs. |
46 // TODO(erikkay) Remove this so that external consumers don't need to be | 66 // TODO(erikkay) Remove this so that external consumers don't need to be |
47 // aware of the internal structure of the preferences. | 67 // aware of the internal structure of the preferences. |
48 DictionaryValue* CopyCurrentExtensions(); | 68 DictionaryValue* CopyCurrentExtensions(); |
49 | 69 |
50 // Populate |killed_ids| with extension ids that have been killed. | 70 // Populate |killed_ids| with extension ids that have been killed. |
51 void GetKilledExtensionIds(std::set<std::string>* killed_ids); | 71 void GetKilledExtensionIds(std::set<std::string>* killed_ids); |
52 | 72 |
(...skipping 14 matching lines...) Expand all Loading... | |
67 void OnExtensionInstalled(const Extension* extension, | 87 void OnExtensionInstalled(const Extension* extension, |
68 Extension::State initial_state, | 88 Extension::State initial_state, |
69 bool initial_incognito_enabled); | 89 bool initial_incognito_enabled); |
70 | 90 |
71 // Called when an extension is uninstalled, so that prefs get cleaned up. | 91 // Called when an extension is uninstalled, so that prefs get cleaned up. |
72 void OnExtensionUninstalled(const std::string& extension_id, | 92 void OnExtensionUninstalled(const std::string& extension_id, |
73 const Extension::Location& location, | 93 const Extension::Location& location, |
74 bool external_uninstall); | 94 bool external_uninstall); |
75 | 95 |
76 // Returns the state (enabled/disabled) of the given extension. | 96 // Returns the state (enabled/disabled) of the given extension. |
77 Extension::State GetExtensionState(const std::string& extension_id); | 97 Extension::State GetExtensionState(const std::string& extension_id) const; |
78 | 98 |
79 // Called to change the extension's state when it is enabled/disabled. | 99 // Called to change the extension's state when it is enabled/disabled. |
80 void SetExtensionState(const Extension* extension, Extension::State); | 100 void SetExtensionState(const Extension* extension, Extension::State); |
81 | 101 |
102 // Returns all installed and enabled extensions | |
103 void GetEnabledExtensions(ExtensionIdSet* out) const; | |
104 | |
82 // Getter and setter for browser action visibility. | 105 // Getter and setter for browser action visibility. |
83 bool GetBrowserActionVisibility(const Extension* extension); | 106 bool GetBrowserActionVisibility(const Extension* extension); |
84 void SetBrowserActionVisibility(const Extension* extension, bool visible); | 107 void SetBrowserActionVisibility(const Extension* extension, bool visible); |
85 | 108 |
86 // Did the extension ask to escalate its permission during an upgrade? | 109 // Did the extension ask to escalate its permission during an upgrade? |
87 bool DidExtensionEscalatePermissions(const std::string& id); | 110 bool DidExtensionEscalatePermissions(const std::string& id); |
88 | 111 |
89 // If |did_escalate| is true, the preferences for |extension| will be set to | 112 // If |did_escalate| is true, the preferences for |extension| will be set to |
90 // require the install warning when the user tries to enable. | 113 // require the install warning when the user tries to enable. |
91 void SetDidExtensionEscalatePermissions(const Extension* extension, | 114 void SetDidExtensionEscalatePermissions(const Extension* extension, |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
225 // highest current application launch index found. | 248 // highest current application launch index found. |
226 int GetNextAppLaunchIndex(); | 249 int GetNextAppLaunchIndex(); |
227 | 250 |
228 // The extension's update URL data. If not empty, the ExtensionUpdater | 251 // The extension's update URL data. If not empty, the ExtensionUpdater |
229 // will append a ap= parameter to the URL when checking if a new version | 252 // will append a ap= parameter to the URL when checking if a new version |
230 // of the extension is available. | 253 // of the extension is available. |
231 void SetUpdateUrlData(const std::string& extension_id, | 254 void SetUpdateUrlData(const std::string& extension_id, |
232 const std::string& data); | 255 const std::string& data); |
233 std::string GetUpdateUrlData(const std::string& extension_id); | 256 std::string GetUpdateUrlData(const std::string& extension_id); |
234 | 257 |
258 // Sets a preference value that is controlled by the extension. In other | |
259 // words, this is not a pref value *about* the extension but something | |
260 // global the extension wants to override. | |
261 void SetExtensionControlledPref(const std::string& extension_id, | |
262 const std::string& pref_key, | |
263 Value* value); | |
264 | |
235 static void RegisterUserPrefs(PrefService* prefs); | 265 static void RegisterUserPrefs(PrefService* prefs); |
236 | 266 |
237 // The underlying PrefService. | 267 // The underlying PrefService. |
238 PrefService* pref_service() const { return prefs_; } | 268 PrefService* pref_service() const { return prefs_; } |
239 | 269 |
270 protected: | |
271 // For unit testing. Enables injecting an artificial clock that is used | |
272 // to query the current time, when an extension is installed. | |
273 virtual base::Time GetCurrentTime() const; | |
274 | |
240 private: | 275 private: |
241 // Converts absolute paths in the pref to paths relative to the | 276 // Converts absolute paths in the pref to paths relative to the |
242 // install_directory_. | 277 // install_directory_. |
243 void MakePathsRelative(); | 278 void MakePathsRelative(); |
244 | 279 |
245 // Converts internal relative paths to be absolute. Used for export to | 280 // Converts internal relative paths to be absolute. Used for export to |
246 // consumers who expect full paths. | 281 // consumers who expect full paths. |
247 void MakePathsAbsolute(DictionaryValue* dict); | 282 void MakePathsAbsolute(DictionaryValue* dict); |
248 | 283 |
249 // Sets the pref |key| for extension |id| to |value|. | 284 // Sets the pref |key| for extension |id| to |value|. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
289 void AddToExtensionPrefStringSet(const std::string& extension_id, | 324 void AddToExtensionPrefStringSet(const std::string& extension_id, |
290 const std::string& pref_key, | 325 const std::string& pref_key, |
291 const std::set<std::string>& added_values); | 326 const std::set<std::string>& added_values); |
292 | 327 |
293 // Ensures and returns a mutable dictionary for extension |id|'s prefs. | 328 // Ensures and returns a mutable dictionary for extension |id|'s prefs. |
294 DictionaryValue* GetOrCreateExtensionPref(const std::string& id); | 329 DictionaryValue* GetOrCreateExtensionPref(const std::string& id); |
295 | 330 |
296 // Same as above, but returns NULL if it doesn't exist. | 331 // Same as above, but returns NULL if it doesn't exist. |
297 DictionaryValue* GetExtensionPref(const std::string& id) const; | 332 DictionaryValue* GetExtensionPref(const std::string& id) const; |
298 | 333 |
334 // Returns the dictionary of preferences controlled by the specified extension | |
335 // or NULL if unknown. All entries in the dictionary contain non-expanded | |
336 // paths. | |
337 DictionaryValue* GetExtensionControlledPrefs(const std::string& id) const; | |
338 | |
299 // Serializes the data and schedules a persistent save via the |PrefService|. | 339 // Serializes the data and schedules a persistent save via the |PrefService|. |
300 // Additionally fires a PREF_CHANGED notification with the top-level | 340 // Additionally fires a PREF_CHANGED notification with the top-level |
301 // |kExtensionsPref| path set. | 341 // |kExtensionsPref| path set. |
302 // TODO(andybons): Switch this to EXTENSION_PREF_CHANGED to be more granular. | 342 // TODO(andybons): Switch this to EXTENSION_PREF_CHANGED to be more granular. |
303 // TODO(andybons): Use a ScopedPrefUpdate to update observers on changes to | 343 // TODO(andybons): Use a ScopedPrefUpdate to update observers on changes to |
304 // the mutable extension dictionary. | 344 // the mutable extension dictionary. |
305 void SavePrefsAndNotify(); | 345 void SavePrefsAndNotify(); |
306 | 346 |
307 // Checks if kPrefBlacklist is set to true in the DictionaryValue. | 347 // Checks if kPrefBlacklist is set to true in the DictionaryValue. |
308 // Return false if the value is false or kPrefBlacklist does not exist. | 348 // Return false if the value is false or kPrefBlacklist does not exist. |
309 // This is used to decide if an extension is blacklisted. | 349 // This is used to decide if an extension is blacklisted. |
310 bool IsBlacklistBitSet(DictionaryValue* ext); | 350 bool IsBlacklistBitSet(DictionaryValue* ext); |
311 | 351 |
312 // Helper methods for the public last ping day functions. | 352 // Helper methods for the public last ping day functions. |
313 base::Time LastPingDayImpl(const DictionaryValue* dictionary) const; | 353 base::Time LastPingDayImpl(const DictionaryValue* dictionary) const; |
314 void SetLastPingDayImpl(const base::Time& time, DictionaryValue* dictionary); | 354 void SetLastPingDayImpl(const base::Time& time, DictionaryValue* dictionary); |
315 | 355 |
356 // Helper method to acquire the installation time of an extension | |
Mattias Nissler (ping if slow)
2010/12/01 10:36:36
Missing period.
battre (please use the other)
2010/12/01 17:44:38
Done.
| |
357 base::Time GetInstallTime(const std::string& extension_id) const; | |
358 | |
359 // Fix missing preference entries in the extensions that are were introduced | |
360 // in a later Chrome version. | |
361 void FixMissingPrefs(const ExtensionIdSet& extension_ids); | |
362 | |
363 // Installs the persistent extension preferences into |prefs_|'s extension | |
364 // pref store. | |
365 void InstallPersistedExtensionControlledPrefs(); | |
366 | |
367 // Returns the extension controlled preference value of the extension that was | |
368 // installed most recently. | |
369 const Value* WinningExtensionControlledPrefValue(const std::string& key) | |
370 const; | |
Mattias Nissler (ping if slow)
2010/12/01 10:36:36
"If your function is const, the const keyword shou
battre (please use the other)
2010/12/01 17:44:38
Done.
| |
371 | |
372 // Find the most recently installed extension that defines a preference | |
373 // for |pref_key|, then store its value in the PrefValueStore's extension pref | |
374 // store and send notifications to observers in case the value changed. | |
375 void UpdateWinningPref(const std::string& pref_key, | |
376 bool suppressNotification); | |
377 | |
378 // Retrieves a list of preference keys that the specified extension | |
379 // intents to manage. | |
380 void GetExtensionControlledPrefKeys(const std::string& extension_id, | |
381 PrefKeySet *out) const; | |
382 | |
383 Profile* profile_; | |
384 | |
316 // The pref service specific to this set of extension prefs. | 385 // The pref service specific to this set of extension prefs. |
317 PrefService* prefs_; | 386 PrefService* prefs_; |
318 | 387 |
319 // Base extensions install directory. | 388 // Base extensions install directory. |
320 FilePath install_directory_; | 389 FilePath install_directory_; |
321 | 390 |
322 // The URLs of all of the toolstrips. | 391 // The URLs of all of the toolstrips. |
323 URLList shelf_order_; | 392 URLList shelf_order_; |
324 | 393 |
325 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs); | 394 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs); |
326 }; | 395 }; |
327 | 396 |
328 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ | 397 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ |
OLD | NEW |