1 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef EXTENSIONS_BROWSER_EXTENSION_PREFS_H_ 6 #define EXTENSIONS_BROWSER_EXTENSION_PREFS_H_ 7 8 #include <set> 9 #include <string> 10 #include <vector> 11 12 #include "base/basictypes.h" 13 #include "base/memory/linked_ptr.h" 14 #include "base/memory/scoped_ptr.h" 15 #include "base/observer_list.h" 16 #include "base/prefs/scoped_user_pref_update.h" 17 #include "base/time/time.h" 18 #include "base/values.h" 19 #include "components/keyed_service/core/keyed_service.h" 20 #include "extensions/browser/app_sorting.h" 21 #include "extensions/browser/blacklist_state.h" 22 #include "extensions/browser/extension_scoped_prefs.h" 23 #include "extensions/browser/install_flag.h" 24 #include "extensions/common/constants.h" 25 #include "extensions/common/extension.h" 26 #include "extensions/common/url_pattern_set.h" 27 #include "sync/api/string_ordinal.h" 28 29 class ExtensionPrefValueMap; 30 class PrefService; 31 32 namespace content { 33 class BrowserContext; 34 } 35 36 namespace user_prefs { 37 class PrefRegistrySyncable; 38 } 39 40 namespace extensions { 41 42 class AppSorting; 43 class ExtensionPrefsObserver; 44 class ExtensionPrefsUninstallExtension; 45 class URLPatternSet; 46 47 // Class for managing global and per-extension preferences. 48 // 49 // This class distinguishes the following kinds of preferences: 50 // - global preferences: 51 // internal state for the extension system in general, not associated 52 // with an individual extension, such as lastUpdateTime. 53 // - per-extension preferences: 54 // meta-preferences describing properties of the extension like 55 // installation time, whether the extension is enabled, etc. 56 // - extension controlled preferences: 57 // browser preferences that an extension controls. For example, an 58 // extension could use the proxy API to specify the browser's proxy 59 // preference. Extension-controlled preferences are stored in 60 // PrefValueStore::extension_prefs(), which this class populates and 61 // maintains as the underlying extensions change. 62 class ExtensionPrefs : public ExtensionScopedPrefs, public KeyedService { 63 public: 64 typedef std::vector<linked_ptr<ExtensionInfo> > ExtensionsInfo; 65 66 // Vector containing identifiers for preferences. 67 typedef std::set<std::string> PrefKeySet; 68 69 // This enum is used to store the reason an extension's install has been 70 // delayed. Do not remove items or re-order this enum as it is used in 71 // preferences. 72 enum DelayReason { 73 DELAY_REASON_NONE = 0, 74 DELAY_REASON_GC = 1, 75 DELAY_REASON_WAIT_FOR_IDLE = 2, 76 DELAY_REASON_WAIT_FOR_IMPORTS = 3, 77 }; 78 79 80 // Creates base::Time classes. The default implementation is just to return 81 // the current time, but tests can inject alternative implementations. 82 class TimeProvider { 83 public: 84 TimeProvider(); 85 86 virtual ~TimeProvider(); 87 88 // By default, returns the current time (base::Time::Now()). 89 virtual base::Time GetCurrentTime() const; 90 91 private: 92 DISALLOW_COPY_AND_ASSIGN(TimeProvider); 93 }; 94 95 // A wrapper around a ScopedUserPrefUpdate, which allows us to access the 96 // entry of a particular key for an extension. Use this if you need a mutable 97 // record of a dictionary or list in the current settings. Otherwise, prefer 98 // ReadPrefAsT() and UpdateExtensionPref() methods. 99 template <typename T, base::Value::Type type_enum_value> 100 class ScopedUpdate { 101 public: 102 ScopedUpdate(ExtensionPrefs* prefs, 103 const std::string& extension_id, 104 const std::string& key); 105 virtual ~ScopedUpdate(); 106 107 // Returns a mutable value for the key (ownership remains with the prefs), 108 // if one exists. Otherwise, returns NULL. 109 virtual T* Get(); 110 111 // Creates and returns a mutable value for the key (the prefs own the new 112 // value), if one does not already exist. Otherwise, returns the current 113 // value. 114 virtual T* Create(); 115 116 private: 117 DictionaryPrefUpdate update_; 118 const std::string extension_id_; 119 const std::string key_; 120 121 DISALLOW_COPY_AND_ASSIGN(ScopedUpdate); 122 }; 123 typedef ScopedUpdate<base::DictionaryValue, base::Value::TYPE_DICTIONARY> 124 ScopedDictionaryUpdate; 125 typedef ScopedUpdate<base::ListValue, base::Value::TYPE_LIST> 126 ScopedListUpdate; 127 128 // Creates an ExtensionPrefs object. 129 // Does not take ownership of |prefs| or |extension_pref_value_map|. 130 // If |extensions_disabled| is true, extension controlled preferences and 131 // content settings do not become effective. ExtensionPrefsObservers should be 132 // included in |early_observers| if they need to observe events which occur 133 // during initialization of the ExtensionPrefs object. 134 static ExtensionPrefs* Create( 135 PrefService* prefs, 136 const base::FilePath& root_dir, 137 ExtensionPrefValueMap* extension_pref_value_map, 138 scoped_ptr<AppSorting> app_sorting, 139 bool extensions_disabled, 140 const std::vector<ExtensionPrefsObserver*>& early_observers); 141 142 // A version of Create which allows injection of a custom base::Time provider. 143 // Use this as needed for testing. 144 static ExtensionPrefs* Create( 145 PrefService* prefs, 146 const base::FilePath& root_dir, 147 ExtensionPrefValueMap* extension_pref_value_map, 148 scoped_ptr<AppSorting> app_sorting, 149 bool extensions_disabled, 150 const std::vector<ExtensionPrefsObserver*>& early_observers, 151 scoped_ptr<TimeProvider> time_provider); 152 153 virtual ~ExtensionPrefs(); 154 155 // Convenience function to get the ExtensionPrefs for a BrowserContext. 156 static ExtensionPrefs* Get(content::BrowserContext* context); 157 158 // Returns all installed extensions from extension preferences provided by 159 // |pref_service|. This is exposed for ProtectedPrefsWatcher because it needs 160 // access to the extension ID list before the ExtensionService is initialized. 161 static ExtensionIdList GetExtensionsFrom(const PrefService* pref_service); 162 163 // Add or remove an observer from the ExtensionPrefs. 164 void AddObserver(ExtensionPrefsObserver* observer); 165 void RemoveObserver(ExtensionPrefsObserver* observer); 166 167 // Returns true if the specified external extension was uninstalled by the 168 // user. 169 bool IsExternalExtensionUninstalled(const std::string& id) const; 170 171 // Checks whether |extension_id| is disabled. If there's no state pref for 172 // the extension, this will return false. Generally you should use 173 // ExtensionService::IsExtensionEnabled instead. 174 bool IsExtensionDisabled(const std::string& id) const; 175 176 // Get/Set the order that the browser actions appear in the toolbar. 177 ExtensionIdList GetToolbarOrder(); 178 void SetToolbarOrder(const ExtensionIdList& extension_ids); 179 180 // Gets the set of known disabled extension IDs into |id_set_out|. Returns 181 // false iff the set of known disabled extension IDs hasn't been set yet. 182 bool GetKnownDisabled(ExtensionIdSet* id_set_out); 183 184 // Sets the set of known disabled extension IDs. 185 void SetKnownDisabled(const ExtensionIdSet& extension_ids); 186 187 // Called when an extension is installed, so that prefs get created. 188 // If |page_ordinal| is invalid then a page will be found for the App. 189 // |install_flags| are a bitmask of extension::InstallFlags. 190 void OnExtensionInstalled(const Extension* extension, 191 Extension::State initial_state, 192 const syncer::StringOrdinal& page_ordinal, 193 int install_flags, 194 const std::string& install_parameter); 195 // OnExtensionInstalled with no install flags. OnExtensionInstalled(const Extension * extension,Extension::State initial_state,const syncer::StringOrdinal & page_ordinal,const std::string & install_parameter)196 void OnExtensionInstalled(const Extension* extension, 197 Extension::State initial_state, 198 const syncer::StringOrdinal& page_ordinal, 199 const std::string& install_parameter) { 200 OnExtensionInstalled(extension, 201 initial_state, 202 page_ordinal, 203 kInstallFlagNone, 204 install_parameter); 205 } 206 207 // Called when an extension is uninstalled, so that prefs get cleaned up. 208 void OnExtensionUninstalled(const std::string& extension_id, 209 const Manifest::Location& location, 210 bool external_uninstall); 211 212 // Called to change the extension's state when it is enabled/disabled. 213 void SetExtensionState(const std::string& extension_id, Extension::State); 214 215 // Called to change the extension's BlacklistState. Currently only used for 216 // non-malicious extensions. 217 // TODO(oleg): replace SetExtensionBlacklisted by this function. 218 void SetExtensionBlacklistState(const std::string& extension_id, 219 BlacklistState state); 220 221 // Checks whether |extension_id| is marked as greylisted. 222 // TODO(oleg): Replace IsExtensionBlacklisted by this method. 223 BlacklistState GetExtensionBlacklistState(const std::string& extension_id); 224 225 // Populates |out| with the ids of all installed extensions. 226 void GetExtensions(ExtensionIdList* out); 227 228 // ExtensionScopedPrefs methods: 229 virtual void UpdateExtensionPref(const std::string& id, 230 const std::string& key, 231 base::Value* value) OVERRIDE; 232 233 virtual void DeleteExtensionPrefs(const std::string& id) OVERRIDE; 234 235 virtual bool ReadPrefAsBoolean(const std::string& extension_id, 236 const std::string& pref_key, 237 bool* out_value) const OVERRIDE; 238 239 virtual bool ReadPrefAsInteger(const std::string& extension_id, 240 const std::string& pref_key, 241 int* out_value) const OVERRIDE; 242 243 virtual bool ReadPrefAsString(const std::string& extension_id, 244 const std::string& pref_key, 245 std::string* out_value) const OVERRIDE; 246 247 virtual bool ReadPrefAsList(const std::string& extension_id, 248 const std::string& pref_key, 249 const base::ListValue** out_value) const OVERRIDE; 250 251 virtual bool ReadPrefAsDictionary( 252 const std::string& extension_id, 253 const std::string& pref_key, 254 const base::DictionaryValue** out_value) const OVERRIDE; 255 256 virtual bool HasPrefForExtension(const std::string& extension_id) const 257 OVERRIDE; 258 259 // Did the extension ask to escalate its permission during an upgrade? 260 bool DidExtensionEscalatePermissions(const std::string& id); 261 262 // If |did_escalate| is true, the preferences for |extension| will be set to 263 // require the install warning when the user tries to enable. 264 void SetDidExtensionEscalatePermissions( 265 const Extension* extension, 266 bool did_escalate); 267 268 // Getters and setters for disabled reason. 269 int GetDisableReasons(const std::string& extension_id) const; 270 bool HasDisableReason(const std::string& extension_id, 271 Extension::DisableReason disable_reason) const; 272 void AddDisableReason(const std::string& extension_id, 273 Extension::DisableReason disable_reason); 274 void RemoveDisableReason(const std::string& extension_id, 275 Extension::DisableReason disable_reason); 276 void ClearDisableReasons(const std::string& extension_id); 277 278 // Gets the set of extensions that have been blacklisted in prefs. This will 279 // return only the blocked extensions, not the "greylist" extensions. 280 // TODO(oleg): Make method names consistent here, in extension service and in 281 // blacklist. 282 std::set<std::string> GetBlacklistedExtensions(); 283 284 // Sets whether the extension with |id| is blacklisted. 285 void SetExtensionBlacklisted(const std::string& extension_id, 286 bool is_blacklisted); 287 288 // Returns the version string for the currently installed extension, or 289 // the empty string if not found. 290 std::string GetVersionString(const std::string& extension_id); 291 292 // Re-writes the extension manifest into the prefs. 293 // Called to change the extension's manifest when it's re-localized. 294 void UpdateManifest(const Extension* extension); 295 296 // Returns base extensions install directory. install_directory()297 const base::FilePath& install_directory() const { return install_directory_; } 298 299 // Returns whether the extension with |id| has its blacklist bit set. 300 // 301 // WARNING: this only checks the extension's entry in prefs, so by definition 302 // can only check extensions that prefs knows about. There may be other 303 // sources of blacklist information, such as safebrowsing. You probably want 304 // to use Blacklist::GetBlacklistedIDs rather than this method. 305 bool IsExtensionBlacklisted(const std::string& id) const; 306 307 // Increment the count of how many times we prompted the user to acknowledge 308 // the given extension, and return the new count. 309 int IncrementAcknowledgePromptCount(const std::string& extension_id); 310 311 // Whether the user has acknowledged an external extension. 312 bool IsExternalExtensionAcknowledged(const std::string& extension_id); 313 void AcknowledgeExternalExtension(const std::string& extension_id); 314 315 // Whether the user has acknowledged a blacklisted extension. 316 bool IsBlacklistedExtensionAcknowledged(const std::string& extension_id); 317 void AcknowledgeBlacklistedExtension(const std::string& extension_id); 318 319 // Whether the external extension was installed during the first run 320 // of this profile. 321 bool IsExternalInstallFirstRun(const std::string& extension_id); 322 void SetExternalInstallFirstRun(const std::string& extension_id); 323 324 // Whether the user has been notified about extension with |extension_id| 325 // being wiped out. 326 bool HasWipeoutBeenAcknowledged(const std::string& extension_id); 327 void SetWipeoutAcknowledged(const std::string& extension_id, bool value); 328 329 // Whether the user has been notified about extension with |extension_id| 330 // taking over some aspect of the user's settings (homepage, startup pages, 331 // or search engine). 332 bool HasSettingsApiBubbleBeenAcknowledged(const std::string& extension_id); 333 void SetSettingsApiBubbleBeenAcknowledged(const std::string& extension_id, 334 bool value); 335 336 // Whether the user has been notified about extension with |extension_id| 337 // overriding the new tab page. 338 bool HasNtpOverriddenBubbleBeenAcknowledged(const std::string& extension_id); 339 void SetNtpOverriddenBubbleBeenAcknowledged(const std::string& extension_id, 340 bool value); 341 342 // Whether the user has been notified about extension with |extension_id| 343 // overriding the proxy. 344 bool HasProxyOverriddenBubbleBeenAcknowledged( 345 const std::string& extension_id); 346 void SetProxyOverriddenBubbleBeenAcknowledged(const std::string& extension_id, 347 bool value); 348 349 // Returns true if the extension notification code has already run for the 350 // first time for this profile. Currently we use this flag to mean that any 351 // extensions that would trigger notifications should get silently 352 // acknowledged. This is a fuse. Calling it the first time returns false. 353 // Subsequent calls return true. It's not possible through an API to ever 354 // reset it. Don't call it unless you mean it! 355 bool SetAlertSystemFirstRun(); 356 357 // Checks if extensions are blacklisted by default, by policy. 358 // The ManagementPolicy::Provider methods also take this into account, and 359 // should be used instead when the extension ID is known. 360 bool ExtensionsBlacklistedByDefault() const; 361 362 // Returns the last value set via SetLastPingDay. If there isn't such a 363 // pref, the returned Time will return true for is_null(). 364 base::Time LastPingDay(const std::string& extension_id) const; 365 366 // The time stored is based on the server's perspective of day start time, not 367 // the client's. 368 void SetLastPingDay(const std::string& extension_id, const base::Time& time); 369 370 // Similar to the 2 above, but for the extensions blacklist. 371 base::Time BlacklistLastPingDay() const; 372 void SetBlacklistLastPingDay(const base::Time& time); 373 374 // Similar to LastPingDay/SetLastPingDay, but for sending "days since active" 375 // ping. 376 base::Time LastActivePingDay(const std::string& extension_id); 377 void SetLastActivePingDay(const std::string& extension_id, 378 const base::Time& time); 379 380 // A bit we use for determining if we should send the "days since active" 381 // ping. A value of true means the item has been active (launched) since the 382 // last update check. 383 bool GetActiveBit(const std::string& extension_id); 384 void SetActiveBit(const std::string& extension_id, bool active); 385 386 // Returns the granted permission set for the extension with |extension_id|, 387 // and NULL if no preferences were found for |extension_id|. 388 // This passes ownership of the returned set to the caller. 389 PermissionSet* GetGrantedPermissions(const std::string& extension_id); 390 391 // Adds |permissions| to the granted permissions set for the extension with 392 // |extension_id|. The new granted permissions set will be the union of 393 // |permissions| and the already granted permissions. 394 void AddGrantedPermissions(const std::string& extension_id, 395 const PermissionSet* permissions); 396 397 // As above, but subtracts the given |permissions| from the granted set. 398 void RemoveGrantedPermissions(const std::string& extension_id, 399 const PermissionSet* permissions); 400 401 // Gets the active permission set for the specified extension. This may 402 // differ from the permissions in the manifest due to the optional 403 // permissions API. This passes ownership of the set to the caller. 404 PermissionSet* GetActivePermissions(const std::string& extension_id); 405 406 // Sets the active |permissions| for the extension with |extension_id|. 407 void SetActivePermissions(const std::string& extension_id, 408 const PermissionSet* permissions); 409 410 // Records whether or not this extension is currently running. 411 void SetExtensionRunning(const std::string& extension_id, bool is_running); 412 413 // Returns whether or not this extension is marked as running. This is used to 414 // restart apps across browser restarts. 415 bool IsExtensionRunning(const std::string& extension_id); 416 417 // Set/Get whether or not the app is active. Used to force a launch of apps 418 // that don't handle onRestarted() on a restart. We can only safely do that if 419 // the app was active when it was last running. 420 void SetIsActive(const std::string& extension_id, bool is_active); 421 bool IsActive(const std::string& extension_id); 422 423 // Returns true if the user enabled this extension to be loaded in incognito 424 // mode. 425 // 426 // IMPORTANT: you probably want to use extensions::util::IsIncognitoEnabled 427 // instead of this method. 428 bool IsIncognitoEnabled(const std::string& extension_id) const; 429 void SetIsIncognitoEnabled(const std::string& extension_id, bool enabled); 430 431 // Returns true if the user has chosen to allow this extension to inject 432 // scripts into pages with file URLs. 433 // 434 // IMPORTANT: you probably want to use extensions::util::AllowFileAccess 435 // instead of this method. 436 bool AllowFileAccess(const std::string& extension_id) const; 437 void SetAllowFileAccess(const std::string& extension_id, bool allow); 438 bool HasAllowFileAccessSetting(const std::string& extension_id) const; 439 440 // Saves ExtensionInfo for each installed extension with the path to the 441 // version directory and the location. Blacklisted extensions won't be saved 442 // and neither will external extensions the user has explicitly uninstalled. 443 // Caller takes ownership of returned structure. 444 scoped_ptr<ExtensionsInfo> GetInstalledExtensionsInfo() const; 445 446 // Same as above, but only includes external extensions the user has 447 // explicitly uninstalled. 448 scoped_ptr<ExtensionsInfo> GetUninstalledExtensionsInfo() const; 449 450 // Returns the ExtensionInfo from the prefs for the given extension. If the 451 // extension is not present, NULL is returned. 452 scoped_ptr<ExtensionInfo> GetInstalledExtensionInfo( 453 const std::string& extension_id) const; 454 455 // We've downloaded an updated .crx file for the extension, but are waiting 456 // to install it. 457 // 458 // |install_flags| are a bitmask of extension::InstallFlags. 459 void SetDelayedInstallInfo(const Extension* extension, 460 Extension::State initial_state, 461 int install_flags, 462 DelayReason delay_reason, 463 const syncer::StringOrdinal& page_ordinal, 464 const std::string& install_parameter); 465 466 // Removes any delayed install information we have for the given 467 // |extension_id|. Returns true if there was info to remove; false otherwise. 468 bool RemoveDelayedInstallInfo(const std::string& extension_id); 469 470 // Update the prefs to finish the update for an extension. 471 bool FinishDelayedInstallInfo(const std::string& extension_id); 472 473 // Returns the ExtensionInfo from the prefs for delayed install information 474 // for |extension_id|, if we have any. Otherwise returns NULL. 475 scoped_ptr<ExtensionInfo> GetDelayedInstallInfo( 476 const std::string& extension_id) const; 477 478 DelayReason GetDelayedInstallReason(const std::string& extension_id) const; 479 480 // Returns information about all the extensions that have delayed install 481 // information. 482 scoped_ptr<ExtensionsInfo> GetAllDelayedInstallInfo() const; 483 484 // Returns true if the extension is an ephemeral app. 485 bool IsEphemeralApp(const std::string& extension_id) const; 486 487 // Promotes an ephemeral app to a regular installed app. 488 void OnEphemeralAppPromoted(const std::string& extension_id); 489 490 // Returns true if the user repositioned the app on the app launcher via drag 491 // and drop. 492 bool WasAppDraggedByUser(const std::string& extension_id); 493 494 // Sets a flag indicating that the user repositioned the app on the app 495 // launcher by drag and dropping it. 496 void SetAppDraggedByUser(const std::string& extension_id); 497 498 // Returns true if there is an extension which controls the preference value 499 // for |pref_key| *and* it is specific to incognito mode. 500 bool HasIncognitoPrefValue(const std::string& pref_key); 501 502 // Returns the creation flags mask for the extension. 503 int GetCreationFlags(const std::string& extension_id) const; 504 505 // Returns the creation flags mask for a delayed install extension. 506 int GetDelayedInstallCreationFlags(const std::string& extension_id) const; 507 508 // Returns true if the extension was installed from the Chrome Web Store. 509 bool IsFromWebStore(const std::string& extension_id) const; 510 511 // Returns true if the extension was installed from an App generated from a 512 // bookmark. 513 bool IsFromBookmark(const std::string& extension_id) const; 514 515 // Returns true if the extension was installed as a default app. 516 bool WasInstalledByDefault(const std::string& extension_id) const; 517 518 // Returns true if the extension was installed as an oem app. 519 bool WasInstalledByOem(const std::string& extension_id) const; 520 521 // Helper method to acquire the installation time of an extension. 522 // Returns base::Time() if the installation time could not be parsed or 523 // found. 524 base::Time GetInstallTime(const std::string& extension_id) const; 525 526 // Returns true if the extension should not be synced. 527 bool DoNotSync(const std::string& extension_id) const; 528 529 // Gets/sets the last launch time of an extension. 530 base::Time GetLastLaunchTime(const std::string& extension_id) const; 531 void SetLastLaunchTime(const std::string& extension_id, 532 const base::Time& time); 533 534 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 535 extensions_disabled()536 bool extensions_disabled() const { return extensions_disabled_; } 537 538 // The underlying PrefService. pref_service()539 PrefService* pref_service() const { return prefs_; } 540 541 // The underlying AppSorting. app_sorting()542 AppSorting* app_sorting() const { return app_sorting_.get(); } 543 544 // Describes the URLs that are able to install extensions. See 545 // pref_names::kAllowedInstallSites for more information. 546 URLPatternSet GetAllowedInstallSites(); 547 548 // Schedules garbage collection of an extension's on-disk data on the next 549 // start of this ExtensionService. Applies only to extensions with isolated 550 // storage. 551 void SetNeedsStorageGarbageCollection(bool value); 552 bool NeedsStorageGarbageCollection(); 553 554 // Used by AppWindowGeometryCache to persist its cache. These methods 555 // should not be called directly. 556 const base::DictionaryValue* GetGeometryCache( 557 const std::string& extension_id) const; 558 void SetGeometryCache(const std::string& extension_id, 559 scoped_ptr<base::DictionaryValue> cache); 560 561 // Used for verification of installed extension ids. For the Set method, pass 562 // null to remove the preference. 563 const base::DictionaryValue* GetInstallSignature(); 564 void SetInstallSignature(const base::DictionaryValue* signature); 565 566 // The installation parameter associated with the extension. 567 std::string GetInstallParam(const std::string& extension_id) const; 568 void SetInstallParam(const std::string& extension_id, 569 const std::string& install_parameter); 570 571 private: 572 friend class ExtensionPrefsBlacklistedExtensions; // Unit test. 573 friend class ExtensionPrefsUninstallExtension; // Unit test. 574 575 enum DisableReasonChange { 576 DISABLE_REASON_ADD, 577 DISABLE_REASON_REMOVE, 578 DISABLE_REASON_CLEAR 579 }; 580 581 // See the Create methods. 582 ExtensionPrefs(PrefService* prefs, 583 const base::FilePath& root_dir, 584 ExtensionPrefValueMap* extension_pref_value_map, 585 scoped_ptr<AppSorting> app_sorting, 586 scoped_ptr<TimeProvider> time_provider, 587 bool extensions_disabled, 588 const std::vector<ExtensionPrefsObserver*>& early_observers); 589 590 // Converts absolute paths in the pref to paths relative to the 591 // install_directory_. 592 void MakePathsRelative(); 593 594 // Converts internal relative paths to be absolute. Used for export to 595 // consumers who expect full paths. 596 void MakePathsAbsolute(base::DictionaryValue* dict); 597 598 // Helper function used by GetInstalledExtensionInfo() and 599 // GetDelayedInstallInfo() to construct an ExtensionInfo from the provided 600 // |extension| dictionary. 601 scoped_ptr<ExtensionInfo> GetInstalledInfoHelper( 602 const std::string& extension_id, 603 const base::DictionaryValue* extension) const; 604 605 // Interprets the list pref, |pref_key| in |extension_id|'s preferences, as a 606 // URLPatternSet. The |valid_schemes| specify how to parse the URLPatterns. 607 bool ReadPrefAsURLPatternSet(const std::string& extension_id, 608 const std::string& pref_key, 609 URLPatternSet* result, 610 int valid_schemes); 611 612 // Converts |new_value| to a list of strings and sets the |pref_key| pref 613 // belonging to |extension_id|. 614 void SetExtensionPrefURLPatternSet(const std::string& extension_id, 615 const std::string& pref_key, 616 const URLPatternSet& new_value); 617 618 // Read the boolean preference entry and return true if the preference exists 619 // and the preference's value is true; false otherwise. 620 bool ReadPrefAsBooleanAndReturn(const std::string& extension_id, 621 const std::string& key) const; 622 623 // Interprets |pref_key| in |extension_id|'s preferences as an 624 // PermissionSet, and passes ownership of the set to the caller. 625 PermissionSet* ReadPrefAsPermissionSet(const std::string& extension_id, 626 const std::string& pref_key); 627 628 // Converts the |new_value| to its value and sets the |pref_key| pref 629 // belonging to |extension_id|. 630 void SetExtensionPrefPermissionSet(const std::string& extension_id, 631 const std::string& pref_key, 632 const PermissionSet* new_value); 633 634 // Returns an immutable dictionary for extension |id|'s prefs, or NULL if it 635 // doesn't exist. 636 const base::DictionaryValue* GetExtensionPref(const std::string& id) const; 637 638 // Modifies the extensions disable reasons to add a new reason, remove an 639 // existing reason, or clear all reasons. Notifies observers if the set of 640 // DisableReasons has changed. 641 // If |change| is DISABLE_REASON_CLEAR, then |reason| is ignored. 642 void ModifyDisableReason(const std::string& extension_id, 643 Extension::DisableReason reason, 644 DisableReasonChange change); 645 646 // Fix missing preference entries in the extensions that are were introduced 647 // in a later Chrome version. 648 void FixMissingPrefs(const ExtensionIdList& extension_ids); 649 650 // Installs the persistent extension preferences into |prefs_|'s extension 651 // pref store. Does nothing if extensions_disabled_ is true. 652 void InitPrefStore(); 653 654 // Migrates the permissions data in the pref store. 655 void MigratePermissions(const ExtensionIdList& extension_ids); 656 657 // Migrates the disable reasons from a single enum to a bit mask. 658 void MigrateDisableReasons(const ExtensionIdList& extension_ids); 659 660 // Checks whether there is a state pref for the extension and if so, whether 661 // it matches |check_state|. 662 bool DoesExtensionHaveState(const std::string& id, 663 Extension::State check_state) const; 664 665 // Reads the list of strings for |pref| from user prefs into 666 // |id_container_out|. Returns false if the pref wasn't found in the user 667 // pref store. 668 template <class ExtensionIdContainer> 669 bool GetUserExtensionPrefIntoContainer( 670 const char* pref, 671 ExtensionIdContainer* id_container_out); 672 673 // Writes the list of strings contained in |strings| to |pref| in prefs. 674 template <class ExtensionIdContainer> 675 void SetExtensionPrefFromContainer(const char* pref, 676 const ExtensionIdContainer& strings); 677 678 // Helper function to populate |extension_dict| with the values needed 679 // by a newly installed extension. Work is broken up between this 680 // function and FinishExtensionInfoPrefs() to accomodate delayed 681 // installations. 682 // 683 // |install_flags| are a bitmask of extension::InstallFlags. 684 void PopulateExtensionInfoPrefs(const Extension* extension, 685 const base::Time install_time, 686 Extension::State initial_state, 687 int install_flags, 688 const std::string& install_parameter, 689 base::DictionaryValue* extension_dict); 690 691 void InitExtensionControlledPrefs(ExtensionPrefValueMap* value_map); 692 693 // Helper function to complete initialization of the values in 694 // |extension_dict| for an extension install. Also see 695 // PopulateExtensionInfoPrefs(). 696 void FinishExtensionInfoPrefs( 697 const std::string& extension_id, 698 const base::Time install_time, 699 bool needs_sort_ordinal, 700 const syncer::StringOrdinal& suggested_page_ordinal, 701 base::DictionaryValue* extension_dict); 702 703 // The pref service specific to this set of extension prefs. Owned by the 704 // BrowserContext. 705 PrefService* prefs_; 706 707 // Base extensions install directory. 708 base::FilePath install_directory_; 709 710 // Weak pointer, owned by BrowserContext. 711 ExtensionPrefValueMap* extension_pref_value_map_; 712 713 // Contains all the logic for handling the order for various extension 714 // properties. 715 scoped_ptr<AppSorting> app_sorting_; 716 717 scoped_ptr<TimeProvider> time_provider_; 718 719 bool extensions_disabled_; 720 721 ObserverList<ExtensionPrefsObserver> observer_list_; 722 723 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs); 724 }; 725 726 } // namespace extensions 727 728 #endif // EXTENSIONS_BROWSER_EXTENSION_PREFS_H_ 729