diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-17 01:13:37 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-17 01:13:37 +0000 |
commit | fee8f0222a5f2a377ba5d7f2d3383481c02eafac (patch) | |
tree | 0542f26a1076b07d0857298b7a9fc694a61422cb /chrome/browser/extensions | |
parent | 8fa18a33d2dee21f748139ef503d08ebb4b706af (diff) | |
download | chromium_src-fee8f0222a5f2a377ba5d7f2d3383481c02eafac.zip chromium_src-fee8f0222a5f2a377ba5d7f2d3383481c02eafac.tar.gz chromium_src-fee8f0222a5f2a377ba5d7f2d3383481c02eafac.tar.bz2 |
Add a pref for the number of showing icons in the browser actions toolbar.
Also fix some issues on GTK concerning the proper behavior when adding/removing browser actions (container sizing + chevron visibility).
Windows uses a different pref (kBrowserActionContainerWidth), which is measured in pixels; it should be migrated to the new pref.
Also, register extension prefs during startup.
BUG=32101
TEST=manual
Review URL: http://codereview.chromium.org/841007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41800 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r-- | chrome/browser/extensions/extension_prefs.cc | 15 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_prefs.h | 2 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_toolbar_model.cc | 13 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_toolbar_model.h | 15 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service_unittest.cc | 2 |
5 files changed, 37 insertions, 10 deletions
diff --git a/chrome/browser/extensions/extension_prefs.cc b/chrome/browser/extensions/extension_prefs.cc index d4879ac..c9f391f 100644 --- a/chrome/browser/extensions/extension_prefs.cc +++ b/chrome/browser/extensions/extension_prefs.cc @@ -5,6 +5,7 @@ #include "base/string_util.h" #include "chrome/browser/extensions/extension_prefs.h" #include "chrome/common/extensions/extension.h" +#include "chrome/common/pref_names.h" using base::Time; @@ -60,12 +61,6 @@ const wchar_t kPrefIncognitoEnabled[] = L"incognito"; ExtensionPrefs::ExtensionPrefs(PrefService* prefs, const FilePath& root_dir) : prefs_(prefs), install_directory_(root_dir) { - if (!prefs_->FindPreference(kExtensionsPref)) - prefs_->RegisterDictionaryPref(kExtensionsPref); - if (!prefs->FindPreference(kExtensionShelf)) - prefs->RegisterListPref(kExtensionShelf); - if (!prefs->FindPreference(kExtensionToolbar)) - prefs->RegisterListPref(kExtensionToolbar); MakePathsRelative(); } @@ -580,3 +575,11 @@ ExtensionPrefs::ExtensionsInfo* ExtensionPrefs::CollectExtensionsInfo( return extensions_info; } + +// static +void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) { + prefs->RegisterDictionaryPref(kExtensionsPref); + prefs->RegisterListPref(kExtensionShelf); + prefs->RegisterListPref(kExtensionToolbar); + prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, -1); +} diff --git a/chrome/browser/extensions/extension_prefs.h b/chrome/browser/extensions/extension_prefs.h index 1d16631..4b026c2 100644 --- a/chrome/browser/extensions/extension_prefs.h +++ b/chrome/browser/extensions/extension_prefs.h @@ -105,6 +105,8 @@ class ExtensionPrefs { // Caller takes ownership of returned structure. static ExtensionsInfo* CollectExtensionsInfo(ExtensionPrefs* extension_prefs); + static void RegisterUserPrefs(PrefService* prefs); + private: // Converts absolute paths in the pref to paths relative to the diff --git a/chrome/browser/extensions/extension_toolbar_model.cc b/chrome/browser/extensions/extension_toolbar_model.cc index ab16d5b..0d8472e 100644 --- a/chrome/browser/extensions/extension_toolbar_model.cc +++ b/chrome/browser/extensions/extension_toolbar_model.cc @@ -6,11 +6,15 @@ #include "chrome/browser/extensions/extension_prefs.h" #include "chrome/browser/extensions/extensions_service.h" +#include "chrome/browser/pref_service.h" +#include "chrome/browser/profile.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/notification_service.h" +#include "chrome/common/pref_names.h" ExtensionToolbarModel::ExtensionToolbarModel(ExtensionsService* service) - : service_(service) { + : service_(service), + prefs_(service->profile()->GetPrefs()) { DCHECK(service_); registrar_.Add(this, NotificationType::EXTENSION_LOADED, @@ -21,6 +25,8 @@ ExtensionToolbarModel::ExtensionToolbarModel(ExtensionsService* service) Source<Profile>(service_->profile())); registrar_.Add(this, NotificationType::EXTENSIONS_READY, Source<Profile>(service_->profile())); + + visible_icon_count_ = prefs_->GetInteger(prefs::kExtensionToolbarSize); } ExtensionToolbarModel::~ExtensionToolbarModel() { @@ -65,6 +71,11 @@ void ExtensionToolbarModel::MoveBrowserAction(Extension* extension, UpdatePrefs(); } +void ExtensionToolbarModel::SetVisibleIconCount(int count) { + visible_icon_count_ = count == static_cast<int>(size()) ? -1 : count; + prefs_->SetInteger(prefs::kExtensionToolbarSize, visible_icon_count_); +} + void ExtensionToolbarModel::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { diff --git a/chrome/browser/extensions/extension_toolbar_model.h b/chrome/browser/extensions/extension_toolbar_model.h index 2341493b5..44f7950 100644 --- a/chrome/browser/extensions/extension_toolbar_model.h +++ b/chrome/browser/extensions/extension_toolbar_model.h @@ -11,6 +11,7 @@ #include "chrome/common/notification_registrar.h" class ExtensionsService; +class PrefService; // Model for the browser actions toolbar. class ExtensionToolbarModel : public NotificationObserver { @@ -37,9 +38,11 @@ class ExtensionToolbarModel : public NotificationObserver { void AddObserver(Observer* observer); void RemoveObserver(Observer* observer); void MoveBrowserAction(Extension* extension, int index); - // TODO(estade): implement these. - void SetVisibleIconCount(int count) {} - int GetVisibleIconCount() { return -1; } + // If count == size(), this will set the visible icon count to -1, meaning + // "show all actions". + void SetVisibleIconCount(int count); + // As above, a return value of -1 represents "show all actions". + int GetVisibleIconCount() { return visible_icon_count_; } size_t size() const { return toolitems_.size(); @@ -83,6 +86,8 @@ class ExtensionToolbarModel : public NotificationObserver { // Our ExtensionsService, guaranteed to outlive us. ExtensionsService* service_; + PrefService* prefs_; + // Ordered list of browser action buttons. ExtensionList toolitems_; @@ -92,6 +97,10 @@ class ExtensionToolbarModel : public NotificationObserver { // Keeps track of where the last extension to get disabled was in the list. size_t last_extension_removed_index_; + // The number of icons visible (the rest should be hidden in the overflow + // chevron). + int visible_icon_count_; + NotificationRegistrar registrar_; }; diff --git a/chrome/browser/extensions/extensions_service_unittest.cc b/chrome/browser/extensions/extensions_service_unittest.cc index e5cf7b4..5de4f3e 100644 --- a/chrome/browser/extensions/extensions_service_unittest.cc +++ b/chrome/browser/extensions/extensions_service_unittest.cc @@ -236,6 +236,8 @@ void ExtensionsServiceTestBase::InitializeExtensionsService( const FilePath& pref_file, const FilePath& extensions_install_dir) { ExtensionTestingProfile* profile = new ExtensionTestingProfile(); prefs_.reset(new PrefService(pref_file)); + Profile::RegisterUserPrefs(prefs_.get()); + browser::RegisterUserPrefs(prefs_.get()); profile_.reset(profile); CommandLine::ForCurrentProcess()->AppendSwitch( |