Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/extensions/extension_content_settings_store.h" | 15 #include "chrome/browser/extensions/extension_content_settings_store.h" |
| 16 #include "chrome/browser/extensions/extension_prefs_scope.h" | 16 #include "chrome/browser/extensions/extension_prefs_scope.h" |
| 17 #include "chrome/browser/prefs/pref_service.h" | 17 #include "chrome/browser/prefs/pref_service.h" |
| 18 #include "chrome/common/extensions/extension.h" | 18 #include "chrome/common/extensions/extension.h" |
| 19 #include "chrome/common/string_ordinal.h" | |
| 19 #include "googleurl/src/gurl.h" | 20 #include "googleurl/src/gurl.h" |
| 20 | 21 |
| 21 class ExtensionPrefValueMap; | 22 class ExtensionPrefValueMap; |
| 22 class URLPatternSet; | 23 class URLPatternSet; |
| 23 | 24 |
| 24 // Class for managing global and per-extension preferences. | 25 // Class for managing global and per-extension preferences. |
| 25 // | 26 // |
| 26 // This class distinguishes the following kinds of preferences: | 27 // This class distinguishes the following kinds of preferences: |
| 27 // - global preferences: | 28 // - global preferences: |
| 28 // internal state for the extension system in general, not associated | 29 // internal state for the extension system in general, not associated |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 // ExtensionService::IsExtensionEnabled instead. | 93 // ExtensionService::IsExtensionEnabled instead. |
| 93 bool IsExtensionDisabled(const std::string& id) const; | 94 bool IsExtensionDisabled(const std::string& id) const; |
| 94 | 95 |
| 95 // Get the order that the browser actions appear in the toolbar. | 96 // Get the order that the browser actions appear in the toolbar. |
| 96 std::vector<std::string> GetToolbarOrder(); | 97 std::vector<std::string> GetToolbarOrder(); |
| 97 | 98 |
| 98 // Set the order that the browser actions appear in the toolbar. | 99 // Set the order that the browser actions appear in the toolbar. |
| 99 void SetToolbarOrder(const std::vector<std::string>& extension_ids); | 100 void SetToolbarOrder(const std::vector<std::string>& extension_ids); |
| 100 | 101 |
| 101 // Called when an extension is installed, so that prefs get created. | 102 // Called when an extension is installed, so that prefs get created. |
| 102 // If |page_index| is -1, and the then a page will be found for the App. | 103 // If |page_ordinal| is an invalid ordinal, then a page will be found |
| 104 // for the App. | |
| 103 void OnExtensionInstalled(const Extension* extension, | 105 void OnExtensionInstalled(const Extension* extension, |
| 104 Extension::State initial_state, | 106 Extension::State initial_state, |
| 105 bool from_webstore, | 107 bool from_webstore, |
| 106 int page_index); | 108 const StringOrdinal& page_ordinal); |
| 107 | 109 |
| 108 // Called when an extension is uninstalled, so that prefs get cleaned up. | 110 // Called when an extension is uninstalled, so that prefs get cleaned up. |
| 109 void OnExtensionUninstalled(const std::string& extension_id, | 111 void OnExtensionUninstalled(const std::string& extension_id, |
| 110 const Extension::Location& location, | 112 const Extension::Location& location, |
| 111 bool external_uninstall); | 113 bool external_uninstall); |
| 112 | 114 |
| 115 // Updates the app launcher value for the moved extension so that it is now | |
| 116 // located after the given predecessor and before the successor. | |
| 117 // Empty strings are used to indicate no successor or predecessor. | |
| 118 void OnExtensionMoved( | |
| 119 const std::string& moved_extension_id, | |
| 120 const std::string& predecessor_extension_id, | |
| 121 const std::string& successor_extension_id); | |
| 122 | |
| 113 // Called to change the extension's state when it is enabled/disabled. | 123 // Called to change the extension's state when it is enabled/disabled. |
| 114 void SetExtensionState(const std::string& extension_id, Extension::State); | 124 void SetExtensionState(const std::string& extension_id, Extension::State); |
| 115 | 125 |
| 116 // Returns all installed extensions | 126 // Returns all installed extensions |
| 117 void GetExtensions(ExtensionIdSet* out); | 127 void GetExtensions(ExtensionIdSet* out); |
| 118 | 128 |
| 119 // Getter and setter for browser action visibility. | 129 // Getter and setter for browser action visibility. |
| 120 bool GetBrowserActionVisibility(const Extension* extension); | 130 bool GetBrowserActionVisibility(const Extension* extension); |
| 121 void SetBrowserActionVisibility(const Extension* extension, bool visible); | 131 void SetBrowserActionVisibility(const Extension* extension, bool visible); |
| 122 | 132 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 std::set<std::string> GetIdleInstallInfoIds(); | 307 std::set<std::string> GetIdleInstallInfoIds(); |
| 298 | 308 |
| 299 // We allow the web store to set a string containing login information when a | 309 // We allow the web store to set a string containing login information when a |
| 300 // purchase is made, so that when a user logs into sync with a different | 310 // purchase is made, so that when a user logs into sync with a different |
| 301 // account we can recognize the situation. The Get function returns true if | 311 // account we can recognize the situation. The Get function returns true if |
| 302 // there was previously stored data (placing it in |result|), or false | 312 // there was previously stored data (placing it in |result|), or false |
| 303 // otherwise. The Set will overwrite any previous login. | 313 // otherwise. The Set will overwrite any previous login. |
| 304 bool GetWebStoreLogin(std::string* result); | 314 bool GetWebStoreLogin(std::string* result); |
| 305 void SetWebStoreLogin(const std::string& login); | 315 void SetWebStoreLogin(const std::string& login); |
| 306 | 316 |
| 307 // Get the application launch index for an extension with |extension_id|. This | 317 // Get the application launch ordinal for an extension with |extension_id|. |
| 308 // determines the order of which the applications appear on the New Tab Page. | 318 // This determines the order of which the applications appear on the page it |
|
akalin
2011/12/02 19:48:23
First sentence should change extension -> app
Rew
csharp
2011/12/05 15:30:24
Done.
| |
| 309 // A value of 0 generally indicates top left. If the extension has no launch | 319 // is specified to appear on in the New Tab Page. A string value close to |
| 310 // index a -1 value is returned. | 320 // |a*| generally indicates top left. If the extension has no launch ordinal, |
| 311 int GetAppLaunchIndex(const std::string& extension_id); | 321 // an invalid StringOrdinal is returned. |
| 322 StringOrdinal GetAppLaunchOrdinal(const std::string& extension_id) const; | |
| 312 | 323 |
| 313 // Sets a specific launch index for an extension with |extension_id|. | 324 // Sets a specific launch ordinal for an extension with |extension_id|. |
|
akalin
2011/12/02 19:48:23
extension -> app
csharp
2011/12/05 15:30:24
Done.
| |
| 314 void SetAppLaunchIndex(const std::string& extension_id, int index); | 325 void SetAppLaunchOrdinal(const std::string& extension_id, |
| 326 const StringOrdinal& ordinal); | |
| 315 | 327 |
| 316 // Gets the next available application launch index. This is 1 higher than the | 328 // Create a StringOrdinal which will be the first element for the given page. |
|
akalin
2011/12/02 19:48:23
// Returns a StringOrdinal that is lower than any
csharp
2011/12/05 15:30:24
Done.
| |
| 317 // highest current application launch index found for the page |on_page|. | 329 StringOrdinal CreateFirstAppLaunchOrdinal(const StringOrdinal& page_ordinal) |
| 318 int GetNextAppLaunchIndex(int on_page); | 330 const; |
| 319 | 331 |
| 320 // Gets the page a new app should install to. Starts on page 0, and if there | 332 // Creates a ordinal value that is higher than the highest current |
|
akalin
2011/12/02 19:48:23
// Returns a StringOrdinal that is higher than any
csharp
2011/12/05 15:30:24
Done.
| |
| 321 // are N or more apps on it, tries to install on the next page. | 333 // application launch ordinal found for the page |page_ordinal|. |
| 322 int GetNaturalAppPageIndex(); | 334 StringOrdinal CreateNextAppLaunchOrdinal(const StringOrdinal& page_ordinal) |
| 335 const; | |
| 323 | 336 |
| 324 // Sets the order the apps should be displayed in the app launcher. | 337 // Create a StringOrdinal that will be the first page. |
|
akalin
2011/12/02 19:48:23
// Returns a StringOrdinal that is lower than any
csharp
2011/12/05 15:30:24
Done.
| |
| 325 void SetAppLauncherOrder(const std::vector<std::string>& extension_ids); | 338 StringOrdinal CreateFirstAppPage() const; |
|
akalin
2011/12/02 19:48:23
maybe rename to CreateFirstAppPageOrdinal() to be
csharp
2011/12/05 15:30:24
Done.
| |
| 326 | 339 |
| 327 // Get the application page index for an extension with |extension_id|. This | 340 // Gets the page a new app should install to. Starts on the first page, and if |
| 328 // determines which page an app will appear on in page-based NTPs. If | 341 // there are N or more apps on it, tries to install on the next page. |
|
akalin
2011/12/02 19:48:23
// Gets the page a new app should install to, whic
csharp
2011/12/05 15:30:24
Done.
| |
| 329 // the app has no page specified, -1 is returned. | 342 StringOrdinal GetNaturalAppPageOrdinal() const; |
| 330 int GetPageIndex(const std::string& extension_id); | |
| 331 | 343 |
| 332 // Sets a specific page index for an extension with |extension_id|. | 344 // Get the application page ordinal for an extension with |extension_id|. |
|
akalin
2011/12/02 19:48:23
application page -> page, extension -> app
csharp
2011/12/05 15:30:24
Done.
| |
| 333 void SetPageIndex(const std::string& extension_id, int index); | 345 // This determines which page an app will appear on in page-based NTPs. If |
| 346 // the app has no page specified, an invalid StringOrdinal is returned. | |
| 347 StringOrdinal GetPageOrdinal(const std::string& extension_id) const; | |
| 334 | 348 |
| 335 // Removes the page index for an extension. | 349 // Sets a specific page ordinal for an extension with |extension_id|. |
|
akalin
2011/12/02 19:48:23
extension -> app
csharp
2011/12/05 15:30:24
Done.
| |
| 336 void ClearPageIndex(const std::string& extension_id); | 350 void SetPageOrdinal(const std::string& extension_id, |
| 351 const StringOrdinal& ordinal); | |
| 352 | |
| 353 // Removes the page ordinal for an extension. | |
|
akalin
2011/12/02 19:48:23
extension -> app
csharp
2011/12/05 15:30:24
Done.
| |
| 354 void ClearPageOrdinal(const std::string& extension_id); | |
| 355 | |
| 356 // Convert the page StringOrdinal value to its integer equivalent. This takes | |
| 357 // O(# of apps) worst-case. | |
| 358 int PageStringOrdinalAsInteger(const StringOrdinal& page_ordinal) const; | |
| 359 | |
| 360 // Converts the page index integer to its StringOrdinal equivalent. This takes | |
| 361 // O(# of apps) worst-case. | |
| 362 StringOrdinal PageIntegerAsStringOrdinal(size_t page_index) const; | |
| 337 | 363 |
| 338 // Returns true if the user repositioned the app on the app launcher via drag | 364 // Returns true if the user repositioned the app on the app launcher via drag |
| 339 // and drop. | 365 // and drop. |
| 340 bool WasAppDraggedByUser(const std::string& extension_id); | 366 bool WasAppDraggedByUser(const std::string& extension_id); |
| 341 | 367 |
| 342 // Sets a flag indicating that the user repositioned the app on the app | 368 // Sets a flag indicating that the user repositioned the app on the app |
| 343 // launcher by drag and dropping it. | 369 // launcher by drag and dropping it. |
| 344 void SetAppDraggedByUser(const std::string& extension_id); | 370 void SetAppDraggedByUser(const std::string& extension_id); |
| 345 | 371 |
| 346 // The extension's update URL data. If not empty, the ExtensionUpdater | 372 // The extension's update URL data. If not empty, the ExtensionUpdater |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 402 | 428 |
| 403 // The underlying PrefService. | 429 // The underlying PrefService. |
| 404 PrefService* pref_service() const { return prefs_; } | 430 PrefService* pref_service() const { return prefs_; } |
| 405 | 431 |
| 406 protected: | 432 protected: |
| 407 // For unit testing. Enables injecting an artificial clock that is used | 433 // For unit testing. Enables injecting an artificial clock that is used |
| 408 // to query the current time, when an extension is installed. | 434 // to query the current time, when an extension is installed. |
| 409 virtual base::Time GetCurrentTime() const; | 435 virtual base::Time GetCurrentTime() const; |
| 410 | 436 |
| 411 private: | 437 private: |
| 438 friend class ExtensionPrefsGetMinAndMaxLaunchOrdinalsOnPage; // Unit test. | |
| 439 friend class ExtensionPrefsMigrateAppIndex; // Unit test. | |
| 412 friend class ExtensionPrefsUninstallExtension; // Unit test. | 440 friend class ExtensionPrefsUninstallExtension; // Unit test. |
| 413 | 441 |
| 414 // ExtensionContentSettingsStore::Observer methods: | 442 // ExtensionContentSettingsStore::Observer methods: |
| 415 virtual void OnContentSettingChanged( | 443 virtual void OnContentSettingChanged( |
| 416 const std::string& extension_id, | 444 const std::string& extension_id, |
| 417 bool incognito) OVERRIDE; | 445 bool incognito) OVERRIDE; |
| 418 | 446 |
| 419 // Converts absolute paths in the pref to paths relative to the | 447 // Converts absolute paths in the pref to paths relative to the |
| 420 // install_directory_. | 448 // install_directory_. |
| 421 void MakePathsRelative(); | 449 void MakePathsRelative(); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 450 // Reads an integer pref |pref_key| from extension with id |extension_id|. | 478 // Reads an integer pref |pref_key| from extension with id |extension_id|. |
| 451 bool ReadExtensionPrefInteger(const std::string& extension_id, | 479 bool ReadExtensionPrefInteger(const std::string& extension_id, |
| 452 const std::string& pref_key, | 480 const std::string& pref_key, |
| 453 int* out_value); | 481 int* out_value); |
| 454 | 482 |
| 455 // Reads a list pref |pref_key| from extension with id |extension_id|. | 483 // Reads a list pref |pref_key| from extension with id |extension_id|. |
| 456 bool ReadExtensionPrefList(const std::string& extension_id, | 484 bool ReadExtensionPrefList(const std::string& extension_id, |
| 457 const std::string& pref_key, | 485 const std::string& pref_key, |
| 458 const base::ListValue** out_value); | 486 const base::ListValue** out_value); |
| 459 | 487 |
| 488 // Reads a string pref |pref_key| from extension with id |extension_id|. | |
| 489 bool ReadExtensionPrefString(const std::string& extension_id, | |
| 490 const std::string& pref_key, | |
| 491 std::string* out_value) const; | |
| 492 | |
| 460 // Interprets the list pref, |pref_key| in |extension_id|'s preferences, as a | 493 // Interprets the list pref, |pref_key| in |extension_id|'s preferences, as a |
| 461 // URLPatternSet. The |valid_schemes| specify how to parse the URLPatterns. | 494 // URLPatternSet. The |valid_schemes| specify how to parse the URLPatterns. |
| 462 bool ReadExtensionPrefURLPatternSet(const std::string& extension_id, | 495 bool ReadExtensionPrefURLPatternSet(const std::string& extension_id, |
| 463 const std::string& pref_key, | 496 const std::string& pref_key, |
| 464 URLPatternSet* result, | 497 URLPatternSet* result, |
| 465 int valid_schemes); | 498 int valid_schemes); |
| 466 | 499 |
| 467 // Converts |new_value| to a list of strings and sets the |pref_key| pref | 500 // Converts |new_value| to a list of strings and sets the |pref_key| pref |
| 468 // belonging to |extension_id|. | 501 // belonging to |extension_id|. |
| 469 void SetExtensionPrefURLPatternSet(const std::string& extension_id, | 502 void SetExtensionPrefURLPatternSet(const std::string& extension_id, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 507 // in a later Chrome version. | 540 // in a later Chrome version. |
| 508 void FixMissingPrefs(const ExtensionIdSet& extension_ids); | 541 void FixMissingPrefs(const ExtensionIdSet& extension_ids); |
| 509 | 542 |
| 510 // Installs the persistent extension preferences into |prefs_|'s extension | 543 // Installs the persistent extension preferences into |prefs_|'s extension |
| 511 // pref store. Does nothing if |extensions_disabled| is true. | 544 // pref store. Does nothing if |extensions_disabled| is true. |
| 512 void InitPrefStore(bool extensions_disabled); | 545 void InitPrefStore(bool extensions_disabled); |
| 513 | 546 |
| 514 // Migrates the permissions data in the pref store. | 547 // Migrates the permissions data in the pref store. |
| 515 void MigratePermissions(const ExtensionIdSet& extension_ids); | 548 void MigratePermissions(const ExtensionIdSet& extension_ids); |
| 516 | 549 |
| 550 // Migrates the app launcher and page index values. | |
| 551 void MigrateAppIndex(const ExtensionIdSet& extension_ids); | |
| 552 | |
| 517 // Checks whether there is a state pref for the extension and if so, whether | 553 // Checks whether there is a state pref for the extension and if so, whether |
| 518 // it matches |check_state|. | 554 // it matches |check_state|. |
| 519 bool DoesExtensionHaveState(const std::string& id, | 555 bool DoesExtensionHaveState(const std::string& id, |
| 520 Extension::State check_state) const; | 556 Extension::State check_state) const; |
| 521 | 557 |
| 558 // This function sets |min_app_launch_value| to contain the lowest | |
| 559 // ordinal on |page_ordinal| and |max_app_launch_value| to contain the | |
| 560 // largest ordinal on |page_ordinal|. If there are no apps on the page then | |
| 561 // |min_app_launch_value| and |max_app_launch_value| are unchanged. It is an | |
| 562 // error to call this function with an invalid |page_ordinal| or | |
| 563 // NULL values for |min_app_launch_value| or |max_app_launch_value|. | |
| 564 void GetMinAndMaxAppLaunchOrdinalsOnPage( | |
| 565 const StringOrdinal& page_ordinal, | |
| 566 StringOrdinal* min_app_launch_value, | |
| 567 StringOrdinal* max_app_launch_value) const; | |
| 568 | |
| 569 // Initialize the |page_ordinal_map_| with the page ordinals used by the | |
| 570 // given extensions. | |
| 571 void InitializePageOrdinalMap(const ExtensionIdSet& extension_ids); | |
| 572 | |
| 573 // Called when an application changes the value of its page ordinal so that | |
| 574 // |page_ordinal_map_| is aware that |old_value| page ordinal has been | |
| 575 // replace by the |new_value| page ordinal and adjusts its mapping | |
| 576 // accordingly. This works with valid and invalid StringOrdinals. | |
| 577 void UpdatePageOrdinalMap(const StringOrdinal& old_value, | |
| 578 const StringOrdinal& new_value); | |
| 579 | |
| 522 // The pref service specific to this set of extension prefs. Owned by profile. | 580 // The pref service specific to this set of extension prefs. Owned by profile. |
| 523 PrefService* prefs_; | 581 PrefService* prefs_; |
| 524 | 582 |
| 525 // Base extensions install directory. | 583 // Base extensions install directory. |
| 526 FilePath install_directory_; | 584 FilePath install_directory_; |
| 527 | 585 |
| 586 // A map of all the StringOrdinal page indices mapping to how often they are | |
| 587 // used, this is used for mapping the StringOrdinals to their integer | |
| 588 // equivalent as well as quick lookup of the sorted StringOrdinals. | |
| 589 std::map<StringOrdinal, int, StringOrdinalLessThan> page_ordinal_map_; | |
|
akalin
2011/12/02 19:48:23
actually, i think it's better to have a two-layer
csharp
2011/12/05 15:30:24
Done.
| |
| 590 | |
| 528 // Weak pointer, owned by Profile. | 591 // Weak pointer, owned by Profile. |
| 529 ExtensionPrefValueMap* extension_pref_value_map_; | 592 ExtensionPrefValueMap* extension_pref_value_map_; |
| 530 | 593 |
| 531 scoped_refptr<ExtensionContentSettingsStore> content_settings_store_; | 594 scoped_refptr<ExtensionContentSettingsStore> content_settings_store_; |
| 532 | 595 |
| 533 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs); | 596 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs); |
| 534 }; | 597 }; |
| 535 | 598 |
| 536 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ | 599 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ |
| OLD | NEW |