Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1123)

Unified Diff: chrome/browser/ui/views/frame/browser_non_client_frame_view.cc

Issue 678553002: Badge icons in windows task bar with avatar icon. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests with no profile manager Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/views/frame/browser_non_client_frame_view.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/frame/browser_non_client_frame_view.cc
diff --git a/chrome/browser/ui/views/frame/browser_non_client_frame_view.cc b/chrome/browser/ui/views/frame/browser_non_client_frame_view.cc
index 5ba04c24d5d0a606f9227b16787de56e5dcdcdcf..2373d9299b4cda20ea3e48faa2513613a68c4ce1 100644
--- a/chrome/browser/ui/views/frame/browser_non_client_frame_view.cc
+++ b/chrome/browser/ui/views/frame/browser_non_client_frame_view.cc
@@ -28,6 +28,48 @@
#include "chrome/browser/ui/views/profiles/supervised_user_avatar_label.h"
#endif
+namespace {
+
+void GetAvatarImage(BrowserView* browser_view,
+ gfx::Image* avatar,
+ gfx::Image* taskbar_badge_avatar,
+ bool *is_rectangle) {
+ ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
+ if (browser_view->IsGuestSession()) {
+ *avatar = rb.
+ GetImageNamed(profiles::GetPlaceholderAvatarIconResourceID());
+ } else if (browser_view->IsOffTheRecord()) {
+ *avatar = rb.GetImageNamed(IDR_OTR_ICON);
+ // TODO(nkostylev): Allow this on ChromeOS once the ChromeOS test
+ // environment handles profile directories correctly.
+#if !defined(OS_CHROMEOS)
+ bool is_badge_rectangle = false;
+ // The taskbar badge should be the profile avatar, not the OTR avatar.
+ AvatarMenu::GetImageForMenuButton(browser_view->browser()->profile(),
+ taskbar_badge_avatar,
+ &is_badge_rectangle);
+#endif
+ } else if (AvatarMenu::ShouldShowAvatarMenu()) {
+ ProfileInfoCache& cache =
+ g_browser_process->profile_manager()->GetProfileInfoCache();
+ Profile* profile = browser_view->browser()->profile();
+ size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath());
+ if (index == std::string::npos)
+ return;
+
+ if (switches::IsNewAvatarMenu()) {
+ *avatar = cache.GetAvatarIconOfProfileAtIndex(index);
+ } else {
+ AvatarMenu::GetImageForMenuButton(browser_view->browser()->profile(),
+ avatar,
+ is_rectangle);
+ }
+ }
+}
+
+} // namespace
+
+
BrowserNonClientFrameView::BrowserNonClientFrameView(BrowserFrame* frame,
BrowserView* browser_view)
: frame_(frame),
@@ -37,21 +79,40 @@ BrowserNonClientFrameView::BrowserNonClientFrameView(BrowserFrame* frame,
supervised_user_avatar_label_(NULL),
#endif
new_avatar_button_(NULL) {
+ // The profile manager may by NULL in tests.
+ if (g_browser_process->profile_manager()) {
+ ProfileInfoCache& cache =
+ g_browser_process->profile_manager()->GetProfileInfoCache();
+ cache.AddObserver(this);
+ }
}
BrowserNonClientFrameView::~BrowserNonClientFrameView() {
+ // The profile manager may by NULL in tests.
+ if (g_browser_process->profile_manager()) {
+ ProfileInfoCache& cache =
+ g_browser_process->profile_manager()->GetProfileInfoCache();
+ cache.RemoveObserver(this);
+ }
}
void BrowserNonClientFrameView::VisibilityChanged(views::View* starting_from,
bool is_visible) {
if (!is_visible)
return;
+
// The first time UpdateAvatarInfo() is called the window is not visible so
// DrawTaskBarDecoration() has no effect. Therefore we need to call it again
// once the window is visible.
if (!browser_view_->IsRegularOrGuestSession() ||
- !switches::IsNewAvatarMenu())
+ !switches::IsNewAvatarMenu()) {
UpdateAvatarInfo();
+ }
+
+ // Make sure the task bar icon is correctly updated call
noms (inactive) 2014/10/24 18:44:57 nit: two spaces between updated and call :(
+ // |OnProfileAvatarChanged()| in this case, but only for non guest profiles.
+ if (!browser_view_->IsGuestSession() || !switches::IsNewAvatarMenu())
+ OnProfileAvatarChanged(base::FilePath());
}
#if defined(ENABLE_MANAGED_USERS)
@@ -97,57 +158,16 @@ void BrowserNonClientFrameView::UpdateAvatarInfo() {
frame_->GetRootView()->Layout();
}
- ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
gfx::Image avatar;
gfx::Image taskbar_badge_avatar;
- base::string16 text;
bool is_rectangle = false;
- if (browser_view_->IsGuestSession()) {
- avatar = rb.
- GetImageNamed(profiles::GetPlaceholderAvatarIconResourceID());
- } else if (browser_view_->IsOffTheRecord()) {
- avatar = rb.GetImageNamed(IDR_OTR_ICON);
- // TODO(nkostylev): Allow this on ChromeOS once the ChromeOS test
- // environment handles profile directories correctly.
-#if !defined(OS_CHROMEOS)
- bool is_badge_rectangle = false;
- // The taskbar badge should be the profile avatar, not the OTR avatar.
- AvatarMenu::GetImageForMenuButton(browser_view_->browser()->profile(),
- &taskbar_badge_avatar,
- &is_badge_rectangle);
-#endif
- } else if (avatar_button_ || AvatarMenu::ShouldShowAvatarMenu()) {
- ProfileInfoCache& cache =
- g_browser_process->profile_manager()->GetProfileInfoCache();
- Profile* profile = browser_view_->browser()->profile();
- size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath());
- if (index == std::string::npos)
- return;
- text = cache.GetNameOfProfileAtIndex(index);
-
- AvatarMenu::GetImageForMenuButton(browser_view_->browser()->profile(),
- &avatar,
- &is_rectangle);
- // Disable the menu when we should not show the menu.
- if (avatar_button_ && !AvatarMenu::ShouldShowAvatarMenu())
- avatar_button_->SetEnabled(false);
- }
+ GetAvatarImage(browser_view_, &avatar, &taskbar_badge_avatar, &is_rectangle);
+
+ // Disable the menu when we should not show the menu.
+ if (avatar_button_ && !AvatarMenu::ShouldShowAvatarMenu())
+ avatar_button_->SetEnabled(false);
if (avatar_button_)
avatar_button_->SetAvatarIcon(avatar, is_rectangle);
-
- // For popups and panels which don't have the avatar button, we still
- // need to draw the taskbar decoration. Even though we have an icon on the
- // window's relaunch details, we draw over it because the user may have pinned
- // the badge-less Chrome shortcut which will cause windows to ignore the
- // relaunch details.
- // TODO(calamity): ideally this should not be necessary but due to issues with
- // the default shortcut being pinned, we add the runtime badge for safety.
- // See crbug.com/313800.
- chrome::DrawTaskbarDecoration(
- frame_->GetNativeWindow(),
- AvatarMenu::ShouldShowAvatarMenu()
- ? (taskbar_badge_avatar.IsEmpty() ? &avatar : &taskbar_badge_avatar)
- : NULL);
}
void BrowserNonClientFrameView::UpdateNewStyleAvatarInfo(
@@ -171,3 +191,29 @@ void BrowserNonClientFrameView::UpdateNewStyleAvatarInfo(
frame_->GetRootView()->Layout();
}
}
+
+void BrowserNonClientFrameView::DrawTaskbarDecoration(
+ const gfx::Image& avatar,
+ const gfx::Image& taskbar_badge_avatar) {
+ // For popups and panels which don't have the avatar button, we still
+ // need to draw the taskbar decoration. Even though we have an icon on the
+ // window's relaunch details, we draw over it because the user may have pinned
+ // the badge-less Chrome shortcut which will cause windows to ignore the
+ // relaunch details.
+ // TODO(calamity): ideally this should not be necessary but due to issues with
+ // the default shortcut being pinned, we add the runtime badge for safety.
+ // See crbug.com/313800.
+ chrome::DrawTaskbarDecoration(frame_->GetNativeWindow(),
+ AvatarMenu::ShouldShowAvatarMenu()
+ ? (taskbar_badge_avatar.IsEmpty() ? &avatar : &taskbar_badge_avatar)
+ : NULL);
+}
+
+void BrowserNonClientFrameView::OnProfileAvatarChanged(
+ const base::FilePath& profile_path) {
+ gfx::Image avatar;
+ gfx::Image taskbar_badge_avatar;
+ bool is_rectangle;
+ GetAvatarImage(browser_view_, &avatar, &taskbar_badge_avatar, &is_rectangle);
+ DrawTaskbarDecoration(avatar, taskbar_badge_avatar);
+}
« no previous file with comments | « chrome/browser/ui/views/frame/browser_non_client_frame_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698