diff options
author | atwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-22 20:53:44 +0000 |
---|---|---|
committer | atwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-22 20:53:44 +0000 |
commit | b569c11767085b8e4b440d51b3bb84740a91f204 (patch) | |
tree | 2249778ad3d12ccbfdcebc89ff8f52f3a699a5b6 /chrome/browser/ui | |
parent | ca6c990f200c470f2f026ccafac39e29a23c26f2 (diff) | |
download | chromium_src-b569c11767085b8e4b440d51b3bb84740a91f204.zip chromium_src-b569c11767085b8e4b440d51b3bb84740a91f204.tar.gz chromium_src-b569c11767085b8e4b440d51b3bb84740a91f204.tar.bz2 |
Display badge when new background page is installed.
Added BackgroundPageTracker which tracks which extensions/apps contain
background pages.
Added code to wrench menu/toolbar to display a badge when there is a new
background page added to the system.
BUG=59980
TEST=BackgroundPageTrackerTest
Review URL: http://codereview.chromium.org/5207002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66997 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui')
-rw-r--r-- | chrome/browser/ui/browser.cc | 7 | ||||
-rw-r--r-- | chrome/browser/ui/views/toolbar_view.cc | 45 | ||||
-rw-r--r-- | chrome/browser/ui/views/toolbar_view.h | 7 |
3 files changed, 49 insertions, 10 deletions
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index b566eb7..c21f7eb 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -2211,7 +2211,8 @@ void Browser::ExecuteCommandWithDisposition( case IDC_DEV_TOOLS_INSPECT: ToggleDevToolsWindow( DEVTOOLS_TOGGLE_ACTION_INSPECT); break; - case IDC_TASK_MANAGER: OpenTaskManager(); break; + case IDC_TASK_MANAGER: // fall through to OpenTaskManager(). + case IDC_VIEW_BACKGROUND_PAGES: OpenTaskManager(); break; case IDC_REPORT_BUG: OpenBugReportDialog(); break; case IDC_SHOW_BOOKMARK_BAR: ToggleBookmarkBar(); break; @@ -3527,6 +3528,10 @@ void Browser::InitCommandState() { command_updater_.UpdateCommandEnabled(IDC_UPGRADE_DIALOG, true); command_updater_.UpdateCommandEnabled(IDC_VIEW_INCOMPATIBILITIES, true); + // View Background Pages entry is always enabled, but is hidden if there are + // no background pages. + command_updater_.UpdateCommandEnabled(IDC_VIEW_BACKGROUND_PAGES, true); + // Initialize other commands whose state changes based on fullscreen mode. UpdateCommandsForFullscreenMode(false); diff --git a/chrome/browser/ui/views/toolbar_view.cc b/chrome/browser/ui/views/toolbar_view.cc index 34261fe..3b3b052 100644 --- a/chrome/browser/ui/views/toolbar_view.cc +++ b/chrome/browser/ui/views/toolbar_view.cc @@ -8,6 +8,7 @@ #include "app/resource_bundle.h" #include "chrome/app/chrome_command_ids.h" #include "chrome/browser/accessibility/browser_accessibility_state.h" +#include "chrome/browser/background_page_tracker.h" #include "chrome/browser/browser_window.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profile.h" @@ -108,6 +109,9 @@ ToolbarView::ToolbarView(Browser* browser) } registrar_.Add(this, NotificationType::MODULE_INCOMPATIBILITY_DETECTED, NotificationService::AllSources()); + registrar_.Add(this, + NotificationType::BACKGROUND_PAGE_TRACKER_CHANGED, + NotificationService::AllSources()); } ToolbarView::~ToolbarView() { @@ -180,10 +184,11 @@ void ToolbarView::Init(Profile* profile) { l10n_util::GetString(IDS_PRODUCT_NAME))); app_menu_->SetID(VIEW_ID_APP_MENU); - // Catch the case where the window is created after we detect a new version. - if (IsUpgradeRecommended() || ShouldShowIncompatibilityWarning()) + // Add any necessary badges to the menu item based on the system state. + if (IsUpgradeRecommended() || ShouldShowIncompatibilityWarning() || + ShouldShowBackgroundPageBadge()) { UpdateAppMenuBadge(); - + } LoadImages(); // Always add children in order from left to right, for accessibility. @@ -322,6 +327,9 @@ cleanup: if (destroyed_flag) return; destroyed_flag_ = NULL; + + // Stop showing the background app badge also. + BackgroundPageTracker::GetSingleton()->AcknowledgeBackgroundPages(); } //////////////////////////////////////////////////////////////////////////////// @@ -399,6 +407,10 @@ void ToolbarView::Observe(NotificationType type, bool confirmed_bad = *Details<bool>(details).ptr(); if (confirmed_bad) UpdateAppMenuBadge(); + } else if (type == + NotificationType::BACKGROUND_PAGE_TRACKER_CHANGED) { + // Force a repaint to add/remove the badge. + UpdateAppMenuBadge(); } } @@ -577,6 +589,11 @@ bool ToolbarView::IsUpgradeRecommended() { #endif } +bool ToolbarView::ShouldShowBackgroundPageBadge() { + return BackgroundPageTracker::GetSingleton()-> + GetUnacknowledgedBackgroundPageCount() > 0; +} + bool ToolbarView::ShouldShowIncompatibilityWarning() { #if defined(OS_WIN) EnumerateModulesModel* loaded_modules = EnumerateModulesModel::GetSingleton(); @@ -654,7 +671,9 @@ SkBitmap ToolbarView::GetAppMenuIcon(views::CustomButton::ButtonState state) { } SkBitmap icon = *tp->GetBitmapNamed(id); - bool add_badge = IsUpgradeRecommended() || ShouldShowIncompatibilityWarning(); + bool add_badge = IsUpgradeRecommended() || + ShouldShowIncompatibilityWarning() || + ShouldShowBackgroundPageBadge(); if (!add_badge) return icon; @@ -663,14 +682,16 @@ SkBitmap ToolbarView::GetAppMenuIcon(views::CustomButton::ButtonState state) { new gfx::CanvasSkia(icon.width(), icon.height(), false)); canvas->DrawBitmapInt(icon, 0, 0); - SkBitmap* badge = NULL; + SkBitmap badge; // Only one badge can be active at any given time. The Upgrade notification // is deemed most important, then the DLL conflict badge. if (IsUpgradeRecommended()) { - badge = tp->GetBitmapNamed(IDR_UPDATE_BADGE); + badge = *tp->GetBitmapNamed(IDR_UPDATE_BADGE); + } else if (ShouldShowBackgroundPageBadge()) { + badge = GetBackgroundPageBadge(); } else if (ShouldShowIncompatibilityWarning()) { #if defined(OS_WIN) - badge = tp->GetBitmapNamed(IDR_CONFLICT_BADGE); + badge = *tp->GetBitmapNamed(IDR_CONFLICT_BADGE); #else NOTREACHED(); #endif @@ -680,9 +701,15 @@ SkBitmap ToolbarView::GetAppMenuIcon(views::CustomButton::ButtonState state) { static const int kBadgeRightMargin = 2; static const int kBadgeTopMargin = 2; - canvas->DrawBitmapInt(*badge, - icon.width() - badge->width() - kBadgeRightMargin, + canvas->DrawBitmapInt(badge, + icon.width() - badge.width() - kBadgeRightMargin, kBadgeTopMargin); return canvas->ExtractBitmap(); } + +SkBitmap ToolbarView::GetBackgroundPageBadge() { + ThemeProvider* tp = GetThemeProvider(); + // TODO(atwilson): Add code to display current number of pages in badge. + return *tp->GetBitmapNamed(IDR_BACKGROUND_BADGE); +} diff --git a/chrome/browser/ui/views/toolbar_view.h b/chrome/browser/ui/views/toolbar_view.h index bea00f3..fb4d8ff 100644 --- a/chrome/browser/ui/views/toolbar_view.h +++ b/chrome/browser/ui/views/toolbar_view.h @@ -138,6 +138,9 @@ class ToolbarView : public AccessiblePaneView, // Returns true if we should show the upgrade recommended dot. bool IsUpgradeRecommended(); + // Returns true if we should show the background page badge. + bool ShouldShowBackgroundPageBadge(); + // Returns true if we should show the warning for incompatible software. bool ShouldShowIncompatibilityWarning(); @@ -164,6 +167,10 @@ class ToolbarView : public AccessiblePaneView, // badge. SkBitmap GetAppMenuIcon(views::CustomButton::ButtonState state); + // Gets a badge for the wrench icon corresponding to the number of + // unacknowledged background pages in the system. + SkBitmap GetBackgroundPageBadge(); + scoped_ptr<BackForwardMenuModel> back_menu_model_; scoped_ptr<BackForwardMenuModel> forward_menu_model_; |