Chromium Code Reviews| 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..5f4e9fd5f9f8618086b8b536ee0261edf3ede8a9 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); |
| + } |
| + } |
| +} |
|
Roger Tawa OOO till Jul 10th
2014/10/24 17:51:32
I made this an anonymous function in this file sin
|
| + |
| +} // namespace |
| + |
| + |
| BrowserNonClientFrameView::BrowserNonClientFrameView(BrowserFrame* frame, |
| BrowserView* browser_view) |
| : frame_(frame), |
| @@ -37,9 +79,15 @@ BrowserNonClientFrameView::BrowserNonClientFrameView(BrowserFrame* frame, |
| supervised_user_avatar_label_(NULL), |
| #endif |
| new_avatar_button_(NULL) { |
| + ProfileInfoCache& cache = |
| + g_browser_process->profile_manager()->GetProfileInfoCache(); |
| + cache.AddObserver(this); |
| } |
| BrowserNonClientFrameView::~BrowserNonClientFrameView() { |
| + ProfileInfoCache& cache = |
| + g_browser_process->profile_manager()->GetProfileInfoCache(); |
| + cache.RemoveObserver(this); |
| } |
| void BrowserNonClientFrameView::VisibilityChanged(views::View* starting_from, |
| @@ -49,9 +97,23 @@ void BrowserNonClientFrameView::VisibilityChanged(views::View* starting_from, |
| // 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()) |
| + |
| + // UpdateAvatarInfo() only supports the old style avatars. So call it |
| + // when |IsNewAvatarMenu()| returns false. However, incognito mode in the |
| + // new style avatar still uses the old avatar button, so call |
| + // UpdateAvatarInfo() in this case too. Because guest mode also reports |
| + // itself as "incognito", make sure to check this is not a guest mode profile |
| + // when |IsOffTheRecord()| returns true. |
| + // |
| + // To make sure the task bar icon is correctly updated in the new avatar |
| + // style, call |OnProfileAvatarChanged()| in this case, but only for non |
| + // guest profiles. |
| + if ((browser_view_->IsOffTheRecord() && !browser_view_->IsGuestSession()) || |
|
noms (inactive)
2014/10/24 17:59:19
I think that's still just !IsRegularOrGuestSession
Roger Tawa OOO till Jul 10th
2014/10/24 18:36:07
Doh! Yes it is. Done.
|
| + !switches::IsNewAvatarMenu()) { |
| UpdateAvatarInfo(); |
| + } else if (!browser_view_->IsGuestSession()) { |
| + OnProfileAvatarChanged(base::FilePath()); |
| + } |
| } |
| #if defined(ENABLE_MANAGED_USERS) |
| @@ -97,57 +159,18 @@ 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); |
| + DrawTaskbarDecoration(avatar, taskbar_badge_avatar); |
|
noms (inactive)
2014/10/24 17:59:19
Should this also be in UpdateNewStyleAvatarInfo()?
Roger Tawa OOO till Jul 10th
2014/10/24 18:36:07
Done.
|
| } |
| void BrowserNonClientFrameView::UpdateNewStyleAvatarInfo( |
| @@ -171,3 +194,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); |
| +} |