| 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 #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/memory/linked_ptr.h" | 13 #include "base/memory/linked_ptr.h" |
| 14 #include "base/time.h" | 14 #include "base/time.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/extensions/api/content_settings/content_settings_store.
h" | 16 #include "chrome/browser/extensions/api/content_settings/content_settings_store.
h" |
| 17 #include "chrome/browser/extensions/extension_menu_manager.h" | 17 #include "chrome/browser/extensions/extension_menu_manager.h" |
| 18 #include "chrome/browser/extensions/extension_prefs_scope.h" | 18 #include "chrome/browser/extensions/extension_prefs_scope.h" |
| 19 #include "chrome/browser/extensions/extension_scoped_prefs.h" | 19 #include "chrome/browser/extensions/extension_scoped_prefs.h" |
| 20 #include "chrome/browser/extensions/management_policy.h" |
| 20 #include "chrome/common/extensions/extension.h" | 21 #include "chrome/common/extensions/extension.h" |
| 21 #include "chrome/common/string_ordinal.h" | 22 #include "chrome/common/string_ordinal.h" |
| 22 | 23 |
| 23 class ExtensionPrefValueMap; | 24 class ExtensionPrefValueMap; |
| 24 class ExtensionSorting; | 25 class ExtensionSorting; |
| 25 class PrefService; | 26 class PrefService; |
| 26 class URLPatternSet; | 27 class URLPatternSet; |
| 27 | 28 |
| 28 namespace extensions { | 29 namespace extensions { |
| 29 struct AlarmPref; | 30 struct AlarmPref; |
| 30 struct ExtensionOmniboxSuggestion; | 31 struct ExtensionOmniboxSuggestion; |
| 31 } | 32 } |
| 32 | 33 |
| 33 // Class for managing global and per-extension preferences. | 34 // Class for managing global and per-extension preferences. |
| 34 // | 35 // |
| 35 // This class distinguishes the following kinds of preferences: | 36 // This class distinguishes the following kinds of preferences: |
| 36 // - global preferences: | 37 // - global preferences: |
| 37 // internal state for the extension system in general, not associated | 38 // internal state for the extension system in general, not associated |
| 38 // with an individual extension, such as lastUpdateTime. | 39 // with an individual extension, such as lastUpdateTime. |
| 39 // - per-extension preferences: | 40 // - per-extension preferences: |
| 40 // meta-preferences describing properties of the extension like | 41 // meta-preferences describing properties of the extension like |
| 41 // installation time, whether the extension is enabled, etc. | 42 // installation time, whether the extension is enabled, etc. |
| 42 // - extension controlled preferences: | 43 // - extension controlled preferences: |
| 43 // browser preferences that an extension controls. For example, an | 44 // browser preferences that an extension controls. For example, an |
| 44 // extension could use the proxy API to specify the browser's proxy | 45 // extension could use the proxy API to specify the browser's proxy |
| 45 // preference. Extension-controlled preferences are stored in | 46 // preference. Extension-controlled preferences are stored in |
| 46 // PrefValueStore::extension_prefs(), which this class populates and | 47 // PrefValueStore::extension_prefs(), which this class populates and |
| 47 // maintains as the underlying extensions change. | 48 // maintains as the underlying extensions change. |
| 48 class ExtensionPrefs : public extensions::ContentSettingsStore::Observer, | 49 class ExtensionPrefs : public extensions::ContentSettingsStore::Observer, |
| 50 public extensions::ManagementPolicy::Provider, |
| 49 public ExtensionScopedPrefs { | 51 public ExtensionScopedPrefs { |
| 50 public: | 52 public: |
| 51 // Key name for a preference that keeps track of per-extension settings. This | 53 // Key name for a preference that keeps track of per-extension settings. This |
| 52 // is a dictionary object read from the Preferences file, keyed off of | 54 // is a dictionary object read from the Preferences file, keyed off of |
| 53 // extension ids. | 55 // extension ids. |
| 54 static const char kExtensionsPref[]; | 56 static const char kExtensionsPref[]; |
| 55 | 57 |
| 56 typedef std::vector<linked_ptr<extensions::ExtensionInfo> > ExtensionsInfo; | 58 typedef std::vector<linked_ptr<extensions::ExtensionInfo> > ExtensionsInfo; |
| 57 | 59 |
| 58 // Vector containing identifiers for preferences. | 60 // Vector containing identifiers for preferences. |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 | 202 |
| 201 // The oauth client id used for app notification setup, if any. | 203 // The oauth client id used for app notification setup, if any. |
| 202 std::string GetAppNotificationClientId(const std::string& extension_id) const; | 204 std::string GetAppNotificationClientId(const std::string& extension_id) const; |
| 203 void SetAppNotificationClientId(const std::string& extension_id, | 205 void SetAppNotificationClientId(const std::string& extension_id, |
| 204 const std::string& oauth_client_id); | 206 const std::string& oauth_client_id); |
| 205 | 207 |
| 206 // Whether app notifications are disabled for the given app. | 208 // Whether app notifications are disabled for the given app. |
| 207 bool IsAppNotificationDisabled(const std::string& extension_id) const; | 209 bool IsAppNotificationDisabled(const std::string& extension_id) const; |
| 208 void SetAppNotificationDisabled(const std::string& extension_id, bool value); | 210 void SetAppNotificationDisabled(const std::string& extension_id, bool value); |
| 209 | 211 |
| 210 // Is the extension with |extension_id| allowed by policy (checking both | 212 // ManagementPolicy::Provider |
| 211 // whitelist and blacklist). | 213 virtual std::string GetPolicyProviderName() const OVERRIDE; |
| 212 bool IsExtensionAllowedByPolicy(const std::string& extension_id, | 214 // Returns true if the extension is allowed by admin policy white- and |
| 213 extensions::Extension::Location location) const; | 215 // blacklists. |
| 216 virtual bool UserMayLoad(const extensions::Extension* extension, |
| 217 string16* error) const OVERRIDE; |
| 218 // Returns false if the extension is required to remain running, as determined |
| 219 // by Extension::IsRequired(). In practice this enforces the admin policy |
| 220 // forcelist. |
| 221 virtual bool UserMayModifySettings(const extensions::Extension* extension, |
| 222 string16* error) const OVERRIDE; |
| 223 // Returns true if the extension is required to remain running, as determined |
| 224 // by Extension::IsRequired(). In practice this enforces the admin policy |
| 225 // forcelist. |
| 226 virtual bool MustRemainEnabled(const extensions::Extension* extension, |
| 227 string16* error) const OVERRIDE; |
| 214 | 228 |
| 215 // Checks if extensions are blacklisted by default, by policy. When true, this | 229 // Checks if extensions are blacklisted by default, by policy. When true, this |
| 216 // means that even extensions without an ID should be blacklisted (e.g. | 230 // means that even extensions without an ID should be blacklisted (e.g. |
| 217 // from the command line, or when loaded as an unpacked extension). | 231 // from the command line, or when loaded as an unpacked extension). |
| 218 // IsExtensionAllowedByPolicy() also takes this into account, and should be | 232 // IsExtensionAllowedByPolicy() also takes this into account, and should be |
| 219 // used instead when the extension ID is known. | 233 // used instead when the extension ID is known. |
| 220 bool ExtensionsBlacklistedByDefault() const; | 234 bool ExtensionsBlacklistedByDefault() const; |
| 221 | 235 |
| 222 // Returns the last value set via SetLastPingDay. If there isn't such a | 236 // Returns the last value set via SetLastPingDay. If there isn't such a |
| 223 // pref, the returned Time will return true for is_null(). | 237 // pref, the returned Time will return true for is_null(). |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 // exist. | 521 // exist. |
| 508 const base::DictionaryValue* GetExtensionPref(const std::string& id) const; | 522 const base::DictionaryValue* GetExtensionPref(const std::string& id) const; |
| 509 | 523 |
| 510 // Returns the dictionary of preferences controlled by the specified extension | 524 // Returns the dictionary of preferences controlled by the specified extension |
| 511 // or creates a new one. All entries in the dictionary contain non-expanded | 525 // or creates a new one. All entries in the dictionary contain non-expanded |
| 512 // paths. | 526 // paths. |
| 513 const base::DictionaryValue* GetExtensionControlledPrefs( | 527 const base::DictionaryValue* GetExtensionControlledPrefs( |
| 514 const std::string& id, | 528 const std::string& id, |
| 515 bool incognito) const; | 529 bool incognito) const; |
| 516 | 530 |
| 531 // Internal implementation for certain ManagementPolicy::Delegate methods. |
| 532 // Returns |modifiable_value| if the extension can be modified. |
| 533 bool ManagementPolicyImpl(const extensions::Extension* extension, |
| 534 string16* error, |
| 535 bool modifiable_value) const; |
| 536 |
| 517 // Checks if kPrefBlacklist is set to true in the DictionaryValue. | 537 // Checks if kPrefBlacklist is set to true in the DictionaryValue. |
| 518 // Return false if the value is false or kPrefBlacklist does not exist. | 538 // Return false if the value is false or kPrefBlacklist does not exist. |
| 519 // This is used to decide if an extension is blacklisted. | 539 // This is used to decide if an extension is blacklisted. |
| 520 static bool IsBlacklistBitSet(base::DictionaryValue* ext); | 540 static bool IsBlacklistBitSet(base::DictionaryValue* ext); |
| 521 | 541 |
| 522 // Fix missing preference entries in the extensions that are were introduced | 542 // Fix missing preference entries in the extensions that are were introduced |
| 523 // in a later Chrome version. | 543 // in a later Chrome version. |
| 524 void FixMissingPrefs(const ExtensionIdSet& extension_ids); | 544 void FixMissingPrefs(const ExtensionIdSet& extension_ids); |
| 525 | 545 |
| 526 // Installs the persistent extension preferences into |prefs_|'s extension | 546 // Installs the persistent extension preferences into |prefs_|'s extension |
| (...skipping 20 matching lines...) Expand all Loading... |
| 547 // Contains all the logic for handling the order for various extension | 567 // Contains all the logic for handling the order for various extension |
| 548 // properties. | 568 // properties. |
| 549 scoped_ptr<ExtensionSorting> extension_sorting_; | 569 scoped_ptr<ExtensionSorting> extension_sorting_; |
| 550 | 570 |
| 551 scoped_refptr<extensions::ContentSettingsStore> content_settings_store_; | 571 scoped_refptr<extensions::ContentSettingsStore> content_settings_store_; |
| 552 | 572 |
| 553 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs); | 573 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs); |
| 554 }; | 574 }; |
| 555 | 575 |
| 556 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ | 576 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ |
| OLD | NEW |