| 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 #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 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 LAUNCH_DEFAULT = LAUNCH_REGULAR | 78 LAUNCH_DEFAULT = LAUNCH_REGULAR |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 // Does not assume ownership of |prefs| and |extension_pref_value_map|. | 81 // Does not assume ownership of |prefs| and |extension_pref_value_map|. |
| 82 // Note that you must call Init() to finalize construction. | 82 // Note that you must call Init() to finalize construction. |
| 83 ExtensionPrefs(PrefService* prefs, | 83 ExtensionPrefs(PrefService* prefs, |
| 84 const FilePath& root_dir, | 84 const FilePath& root_dir, |
| 85 ExtensionPrefValueMap* extension_pref_value_map); | 85 ExtensionPrefValueMap* extension_pref_value_map); |
| 86 virtual ~ExtensionPrefs(); | 86 virtual ~ExtensionPrefs(); |
| 87 | 87 |
| 88 // Returns all installed extensions from extension preferences provided by |
| 89 // |pref_service|. This is exposed for ProtectedPrefsWatcher because it needs |
| 90 // access to the extension ID list before the ExtensionService is initialized. |
| 91 static ExtensionIds GetExtensionsFrom(const PrefService* pref_service); |
| 92 |
| 88 // If |extensions_disabled| is true, extension controlled preferences and | 93 // If |extensions_disabled| is true, extension controlled preferences and |
| 89 // content settings do not become effective. | 94 // content settings do not become effective. |
| 90 void Init(bool extensions_disabled); | 95 void Init(bool extensions_disabled); |
| 91 | 96 |
| 92 // Returns a copy of the Extensions prefs. | 97 // Returns a copy of the Extensions prefs. |
| 93 // TODO(erikkay) Remove this so that external consumers don't need to be | 98 // TODO(erikkay) Remove this so that external consumers don't need to be |
| 94 // aware of the internal structure of the preferences. | 99 // aware of the internal structure of the preferences. |
| 95 base::DictionaryValue* CopyCurrentExtensions(); | 100 base::DictionaryValue* CopyCurrentExtensions(); |
| 96 | 101 |
| 97 // Returns true if the specified external extension was uninstalled by the | 102 // Returns true if the specified external extension was uninstalled by the |
| (...skipping 25 matching lines...) Expand all Loading... |
| 123 void OnExtensionUninstalled(const std::string& extension_id, | 128 void OnExtensionUninstalled(const std::string& extension_id, |
| 124 const Extension::Location& location, | 129 const Extension::Location& location, |
| 125 bool external_uninstall); | 130 bool external_uninstall); |
| 126 | 131 |
| 127 // Called to change the extension's state when it is enabled/disabled. | 132 // Called to change the extension's state when it is enabled/disabled. |
| 128 void SetExtensionState(const std::string& extension_id, Extension::State); | 133 void SetExtensionState(const std::string& extension_id, Extension::State); |
| 129 | 134 |
| 130 // Returns all installed extensions | 135 // Returns all installed extensions |
| 131 void GetExtensions(ExtensionIds* out); | 136 void GetExtensions(ExtensionIds* out); |
| 132 | 137 |
| 133 // Returns all installed extensions from |extension_prefs|. This is exposed | |
| 134 // for ProtectedPrefsWatcher because it needs access to the extension ID list | |
| 135 // before the ExtensionService is initialized. | |
| 136 static ExtensionIds GetExtensionsFrom( | |
| 137 const base::DictionaryValue* extension_prefs); | |
| 138 | |
| 139 // Getter and setter for browser action visibility. | 138 // Getter and setter for browser action visibility. |
| 140 bool GetBrowserActionVisibility(const Extension* extension); | 139 bool GetBrowserActionVisibility(const Extension* extension); |
| 141 void SetBrowserActionVisibility(const Extension* extension, | 140 void SetBrowserActionVisibility(const Extension* extension, |
| 142 bool visible); | 141 bool visible); |
| 143 | 142 |
| 144 // Did the extension ask to escalate its permission during an upgrade? | 143 // Did the extension ask to escalate its permission during an upgrade? |
| 145 bool DidExtensionEscalatePermissions(const std::string& id); | 144 bool DidExtensionEscalatePermissions(const std::string& id); |
| 146 | 145 |
| 147 // If |did_escalate| is true, the preferences for |extension| will be set to | 146 // If |did_escalate| is true, the preferences for |extension| will be set to |
| 148 // require the install warning when the user tries to enable. | 147 // require the install warning when the user tries to enable. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 168 | 167 |
| 169 // Returns extension path based on extension ID, or empty FilePath on error. | 168 // Returns extension path based on extension ID, or empty FilePath on error. |
| 170 FilePath GetExtensionPath(const std::string& extension_id); | 169 FilePath GetExtensionPath(const std::string& extension_id); |
| 171 | 170 |
| 172 // Returns base extensions install directory. | 171 // Returns base extensions install directory. |
| 173 const FilePath& install_directory() const { return install_directory_; } | 172 const FilePath& install_directory() const { return install_directory_; } |
| 174 | 173 |
| 175 // Updates the prefs based on the blacklist. | 174 // Updates the prefs based on the blacklist. |
| 176 void UpdateBlacklist(const std::set<std::string>& blacklist_set); | 175 void UpdateBlacklist(const std::set<std::string>& blacklist_set); |
| 177 | 176 |
| 178 // Based on extension id, checks prefs to see if it is blacklisted. | |
| 179 bool IsExtensionBlacklisted(const std::string& id); | |
| 180 | |
| 181 // Based on extension id, checks prefs to see if it is orphaned. | 177 // Based on extension id, checks prefs to see if it is orphaned. |
| 182 bool IsExtensionOrphaned(const std::string& id); | 178 bool IsExtensionOrphaned(const std::string& id); |
| 183 | 179 |
| 184 // Whether the user has acknowledged an external extension. | 180 // Whether the user has acknowledged an external extension. |
| 185 bool IsExternalExtensionAcknowledged(const std::string& extension_id); | 181 bool IsExternalExtensionAcknowledged(const std::string& extension_id); |
| 186 void AcknowledgeExternalExtension(const std::string& extension_id); | 182 void AcknowledgeExternalExtension(const std::string& extension_id); |
| 187 | 183 |
| 188 // Whether the user has acknowledged a blacklisted extension. | 184 // Whether the user has acknowledged a blacklisted extension. |
| 189 bool IsBlacklistedExtensionAcknowledged(const std::string& extension_id); | 185 bool IsBlacklistedExtensionAcknowledged(const std::string& extension_id); |
| 190 void AcknowledgeBlacklistedExtension(const std::string& extension_id); | 186 void AcknowledgeBlacklistedExtension(const std::string& extension_id); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 void UnsetMediaGalleryPermission(const std::string& extension_id, | 329 void UnsetMediaGalleryPermission(const std::string& extension_id, |
| 334 chrome::MediaGalleryPrefId gallery); | 330 chrome::MediaGalleryPrefId gallery); |
| 335 std::vector<chrome::MediaGalleryPermission> GetMediaGalleryPermissions( | 331 std::vector<chrome::MediaGalleryPermission> GetMediaGalleryPermissions( |
| 336 const std::string& extension_id); | 332 const std::string& extension_id); |
| 337 void RemoveMediaGalleryPermissions(chrome::MediaGalleryPrefId gallery_id); | 333 void RemoveMediaGalleryPermissions(chrome::MediaGalleryPrefId gallery_id); |
| 338 | 334 |
| 339 // Saves ExtensionInfo for each installed extension with the path to the | 335 // Saves ExtensionInfo for each installed extension with the path to the |
| 340 // version directory and the location. Blacklisted extensions won't be saved | 336 // version directory and the location. Blacklisted extensions won't be saved |
| 341 // and neither will external extensions the user has explicitly uninstalled. | 337 // and neither will external extensions the user has explicitly uninstalled. |
| 342 // Caller takes ownership of returned structure. | 338 // Caller takes ownership of returned structure. |
| 343 ExtensionsInfo* GetInstalledExtensionsInfo(); | 339 ExtensionsInfo* GetInstalledExtensionsInfo() const; |
| 344 | 340 |
| 345 // Returns the ExtensionInfo from the prefs for the given extension. If the | 341 // Returns the ExtensionInfo from the prefs for the given extension. If the |
| 346 // extension is not present, NULL is returned. | 342 // extension is not present, NULL is returned. |
| 347 ExtensionInfo* GetInstalledExtensionInfo(const std::string& extension_id); | 343 ExtensionInfo* GetInstalledExtensionInfo( |
| 344 const std::string& extension_id) const; |
| 348 | 345 |
| 349 // We've downloaded an updated .crx file for the extension, but are waiting | 346 // We've downloaded an updated .crx file for the extension, but are waiting |
| 350 // for idle time to install it. | 347 // for idle time to install it. |
| 351 void SetIdleInstallInfo(const std::string& extension_id, | 348 void SetIdleInstallInfo(const std::string& extension_id, |
| 352 const FilePath& crx_path, | 349 const FilePath& crx_path, |
| 353 const std::string& version, | 350 const std::string& version, |
| 354 const base::Time& fetch_time); | 351 const base::Time& fetch_time); |
| 355 | 352 |
| 356 // Removes any idle install information we have for the given |extension_id|. | 353 // Removes any idle install information we have for the given |extension_id|. |
| 357 // Returns true if there was info to remove; false otherwise. | 354 // Returns true if there was info to remove; false otherwise. |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 std::string* out_value) const OVERRIDE; | 484 std::string* out_value) const OVERRIDE; |
| 488 | 485 |
| 489 // Converts absolute paths in the pref to paths relative to the | 486 // Converts absolute paths in the pref to paths relative to the |
| 490 // install_directory_. | 487 // install_directory_. |
| 491 void MakePathsRelative(); | 488 void MakePathsRelative(); |
| 492 | 489 |
| 493 // Converts internal relative paths to be absolute. Used for export to | 490 // Converts internal relative paths to be absolute. Used for export to |
| 494 // consumers who expect full paths. | 491 // consumers who expect full paths. |
| 495 void MakePathsAbsolute(base::DictionaryValue* dict); | 492 void MakePathsAbsolute(base::DictionaryValue* dict); |
| 496 | 493 |
| 497 // Reads a boolean pref from |ext| with key |pref_key|. | |
| 498 // Return false if the value is false or |pref_key| does not exist. | |
| 499 static bool ReadBooleanFromPref(const base::DictionaryValue* ext, | |
| 500 const std::string& pref_key); | |
| 501 | |
| 502 // Reads an integer pref from |ext| with key |pref_key|. | |
| 503 // Return false if the value does not exist. | |
| 504 static bool ReadIntegerFromPref(const base::DictionaryValue* ext, | |
| 505 const std::string& pref_key, | |
| 506 int* out_value); | |
| 507 | |
| 508 // Interprets the list pref, |pref_key| in |extension_id|'s preferences, as a | 494 // Interprets the list pref, |pref_key| in |extension_id|'s preferences, as a |
| 509 // URLPatternSet. The |valid_schemes| specify how to parse the URLPatterns. | 495 // URLPatternSet. The |valid_schemes| specify how to parse the URLPatterns. |
| 510 bool ReadExtensionPrefURLPatternSet(const std::string& extension_id, | 496 bool ReadExtensionPrefURLPatternSet(const std::string& extension_id, |
| 511 const std::string& pref_key, | 497 const std::string& pref_key, |
| 512 URLPatternSet* result, | 498 URLPatternSet* result, |
| 513 int valid_schemes); | 499 int valid_schemes); |
| 514 | 500 |
| 515 // Converts |new_value| to a list of strings and sets the |pref_key| pref | 501 // Converts |new_value| to a list of strings and sets the |pref_key| pref |
| 516 // belonging to |extension_id|. | 502 // belonging to |extension_id|. |
| 517 void SetExtensionPrefURLPatternSet(const std::string& extension_id, | 503 void SetExtensionPrefURLPatternSet(const std::string& extension_id, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 531 | 517 |
| 532 // Returns a dictionary for extension |id|'s prefs or NULL if it doesn't | 518 // Returns a dictionary for extension |id|'s prefs or NULL if it doesn't |
| 533 // exist. | 519 // exist. |
| 534 const base::DictionaryValue* GetExtensionPref(const std::string& id) const; | 520 const base::DictionaryValue* GetExtensionPref(const std::string& id) const; |
| 535 | 521 |
| 536 // Loads the preferences controlled by the specified extension from their | 522 // Loads the preferences controlled by the specified extension from their |
| 537 // dictionary and sets them in the |pref_value_map_|. | 523 // dictionary and sets them in the |pref_value_map_|. |
| 538 void LoadExtensionControlledPrefs(const std::string& id, | 524 void LoadExtensionControlledPrefs(const std::string& id, |
| 539 ExtensionPrefsScope scope); | 525 ExtensionPrefsScope scope); |
| 540 | 526 |
| 541 // Checks if kPrefBlacklist is set to true in the DictionaryValue. | |
| 542 // Return false if the value is false or kPrefBlacklist does not exist. | |
| 543 // This is used to decide if an extension is blacklisted. | |
| 544 static bool IsBlacklistBitSet(const base::DictionaryValue* ext); | |
| 545 | |
| 546 // Fix missing preference entries in the extensions that are were introduced | 527 // Fix missing preference entries in the extensions that are were introduced |
| 547 // in a later Chrome version. | 528 // in a later Chrome version. |
| 548 void FixMissingPrefs(const ExtensionIds& extension_ids); | 529 void FixMissingPrefs(const ExtensionIds& extension_ids); |
| 549 | 530 |
| 550 // Installs the persistent extension preferences into |prefs_|'s extension | 531 // Installs the persistent extension preferences into |prefs_|'s extension |
| 551 // pref store. Does nothing if |extensions_disabled| is true. | 532 // pref store. Does nothing if |extensions_disabled| is true. |
| 552 void InitPrefStore(bool extensions_disabled); | 533 void InitPrefStore(bool extensions_disabled); |
| 553 | 534 |
| 554 // Migrates the permissions data in the pref store. | 535 // Migrates the permissions data in the pref store. |
| 555 void MigratePermissions(const ExtensionIds& extension_ids); | 536 void MigratePermissions(const ExtensionIds& extension_ids); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 581 scoped_ptr<ExtensionSorting> extension_sorting_; | 562 scoped_ptr<ExtensionSorting> extension_sorting_; |
| 582 | 563 |
| 583 scoped_refptr<ContentSettingsStore> content_settings_store_; | 564 scoped_refptr<ContentSettingsStore> content_settings_store_; |
| 584 | 565 |
| 585 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs); | 566 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs); |
| 586 }; | 567 }; |
| 587 | 568 |
| 588 } // namespace extensions | 569 } // namespace extensions |
| 589 | 570 |
| 590 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ | 571 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ |
| OLD | NEW |