| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/ui/views/frame/browser_non_client_frame_view.h" | 5 #include "chrome/browser/ui/views/frame/browser_non_client_frame_view.h" |
| 6 | 6 |
| 7 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
| 8 #include "chrome/browser/profiles/avatar_menu.h" | 8 #include "chrome/browser/profiles/avatar_menu.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 10 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 BrowserNonClientFrameView::BrowserNonClientFrameView(BrowserFrame* frame, | 31 BrowserNonClientFrameView::BrowserNonClientFrameView(BrowserFrame* frame, |
| 32 BrowserView* browser_view) | 32 BrowserView* browser_view) |
| 33 : frame_(frame), | 33 : frame_(frame), |
| 34 browser_view_(browser_view), | 34 browser_view_(browser_view), |
| 35 avatar_button_(NULL), | 35 avatar_button_(NULL), |
| 36 #if defined(ENABLE_MANAGED_USERS) | 36 #if defined(ENABLE_MANAGED_USERS) |
| 37 supervised_user_avatar_label_(NULL), | 37 supervised_user_avatar_label_(NULL), |
| 38 #endif | 38 #endif |
| 39 new_avatar_button_(NULL) { | 39 new_avatar_button_(NULL) { |
| 40 // The profile manager may by NULL in tests. |
| 41 if (g_browser_process->profile_manager()) { |
| 42 ProfileInfoCache& cache = |
| 43 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 44 cache.AddObserver(this); |
| 45 } |
| 40 } | 46 } |
| 41 | 47 |
| 42 BrowserNonClientFrameView::~BrowserNonClientFrameView() { | 48 BrowserNonClientFrameView::~BrowserNonClientFrameView() { |
| 49 // The profile manager may by NULL in tests. |
| 50 if (g_browser_process->profile_manager()) { |
| 51 ProfileInfoCache& cache = |
| 52 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 53 cache.RemoveObserver(this); |
| 54 } |
| 43 } | 55 } |
| 44 | 56 |
| 45 void BrowserNonClientFrameView::VisibilityChanged(views::View* starting_from, | 57 void BrowserNonClientFrameView::VisibilityChanged(views::View* starting_from, |
| 46 bool is_visible) { | 58 bool is_visible) { |
| 47 if (!is_visible) | 59 if (!is_visible) |
| 48 return; | 60 return; |
| 61 |
| 49 // The first time UpdateAvatarInfo() is called the window is not visible so | 62 // The first time UpdateAvatarInfo() is called the window is not visible so |
| 50 // DrawTaskBarDecoration() has no effect. Therefore we need to call it again | 63 // DrawTaskBarDecoration() has no effect. Therefore we need to call it again |
| 51 // once the window is visible. | 64 // once the window is visible. |
| 52 if (!browser_view_->IsRegularOrGuestSession() || | 65 if (!browser_view_->IsRegularOrGuestSession() || |
| 53 !switches::IsNewAvatarMenu()) | 66 !switches::IsNewAvatarMenu()) { |
| 54 UpdateAvatarInfo(); | 67 UpdateAvatarInfo(); |
| 68 } |
| 69 |
| 70 // Make sure the task bar icon is correctly updated call |
| 71 // |OnProfileAvatarChanged()| in this case, but only for non guest profiles. |
| 72 if (!browser_view_->IsGuestSession() || !switches::IsNewAvatarMenu()) |
| 73 OnProfileAvatarChanged(base::FilePath()); |
| 55 } | 74 } |
| 56 | 75 |
| 57 #if defined(ENABLE_MANAGED_USERS) | 76 #if defined(ENABLE_MANAGED_USERS) |
| 58 void BrowserNonClientFrameView::OnThemeChanged() { | 77 void BrowserNonClientFrameView::OnThemeChanged() { |
| 59 if (supervised_user_avatar_label_) | 78 if (supervised_user_avatar_label_) |
| 60 supervised_user_avatar_label_->UpdateLabelStyle(); | 79 supervised_user_avatar_label_->UpdateLabelStyle(); |
| 61 } | 80 } |
| 62 #endif | 81 #endif |
| 63 | 82 |
| 64 void BrowserNonClientFrameView::UpdateAvatarInfo() { | 83 void BrowserNonClientFrameView::UpdateAvatarInfo() { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 90 delete supervised_user_avatar_label_; | 109 delete supervised_user_avatar_label_; |
| 91 supervised_user_avatar_label_ = NULL; | 110 supervised_user_avatar_label_ = NULL; |
| 92 } | 111 } |
| 93 #endif | 112 #endif |
| 94 RemoveChildView(avatar_button_); | 113 RemoveChildView(avatar_button_); |
| 95 delete avatar_button_; | 114 delete avatar_button_; |
| 96 avatar_button_ = NULL; | 115 avatar_button_ = NULL; |
| 97 frame_->GetRootView()->Layout(); | 116 frame_->GetRootView()->Layout(); |
| 98 } | 117 } |
| 99 | 118 |
| 100 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 101 gfx::Image avatar; | 119 gfx::Image avatar; |
| 102 gfx::Image taskbar_badge_avatar; | 120 gfx::Image taskbar_badge_avatar; |
| 103 base::string16 text; | |
| 104 bool is_rectangle = false; | 121 bool is_rectangle = false; |
| 105 if (browser_view_->IsGuestSession()) { | 122 AvatarMenuButton::GetAvatarImages(browser_view_->browser()->profile(), |
| 106 avatar = rb. | 123 &avatar, &taskbar_badge_avatar, |
| 107 GetImageNamed(profiles::GetPlaceholderAvatarIconResourceID()); | 124 &is_rectangle); |
| 108 } else if (browser_view_->IsOffTheRecord()) { | |
| 109 avatar = rb.GetImageNamed(IDR_OTR_ICON); | |
| 110 // TODO(nkostylev): Allow this on ChromeOS once the ChromeOS test | |
| 111 // environment handles profile directories correctly. | |
| 112 #if !defined(OS_CHROMEOS) | |
| 113 bool is_badge_rectangle = false; | |
| 114 // The taskbar badge should be the profile avatar, not the OTR avatar. | |
| 115 AvatarMenu::GetImageForMenuButton(browser_view_->browser()->profile(), | |
| 116 &taskbar_badge_avatar, | |
| 117 &is_badge_rectangle); | |
| 118 #endif | |
| 119 } else if (avatar_button_ || AvatarMenu::ShouldShowAvatarMenu()) { | |
| 120 ProfileInfoCache& cache = | |
| 121 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
| 122 Profile* profile = browser_view_->browser()->profile(); | |
| 123 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | |
| 124 if (index == std::string::npos) | |
| 125 return; | |
| 126 text = cache.GetNameOfProfileAtIndex(index); | |
| 127 | 125 |
| 128 AvatarMenu::GetImageForMenuButton(browser_view_->browser()->profile(), | 126 // Disable the menu when we should not show the menu. |
| 129 &avatar, | 127 if (avatar_button_ && !AvatarMenu::ShouldShowAvatarMenu()) |
| 130 &is_rectangle); | 128 avatar_button_->SetEnabled(false); |
| 131 // Disable the menu when we should not show the menu. | |
| 132 if (avatar_button_ && !AvatarMenu::ShouldShowAvatarMenu()) | |
| 133 avatar_button_->SetEnabled(false); | |
| 134 } | |
| 135 if (avatar_button_) | 129 if (avatar_button_) |
| 136 avatar_button_->SetAvatarIcon(avatar, is_rectangle); | 130 avatar_button_->SetAvatarIcon(avatar, is_rectangle); |
| 137 | |
| 138 // For popups and panels which don't have the avatar button, we still | |
| 139 // need to draw the taskbar decoration. Even though we have an icon on the | |
| 140 // window's relaunch details, we draw over it because the user may have pinned | |
| 141 // the badge-less Chrome shortcut which will cause windows to ignore the | |
| 142 // relaunch details. | |
| 143 // TODO(calamity): ideally this should not be necessary but due to issues with | |
| 144 // the default shortcut being pinned, we add the runtime badge for safety. | |
| 145 // See crbug.com/313800. | |
| 146 chrome::DrawTaskbarDecoration( | |
| 147 frame_->GetNativeWindow(), | |
| 148 AvatarMenu::ShouldShowAvatarMenu() | |
| 149 ? (taskbar_badge_avatar.IsEmpty() ? &avatar : &taskbar_badge_avatar) | |
| 150 : NULL); | |
| 151 } | 131 } |
| 152 | 132 |
| 153 void BrowserNonClientFrameView::UpdateNewStyleAvatarInfo( | 133 void BrowserNonClientFrameView::UpdateNewStyleAvatarInfo( |
| 154 views::ButtonListener* listener, | 134 views::ButtonListener* listener, |
| 155 const NewAvatarButton::AvatarButtonStyle style) { | 135 const NewAvatarButton::AvatarButtonStyle style) { |
| 156 DCHECK(switches::IsNewAvatarMenu()); | 136 DCHECK(switches::IsNewAvatarMenu()); |
| 157 // This should never be called in incognito mode. | 137 // This should never be called in incognito mode. |
| 158 DCHECK(browser_view_->IsRegularOrGuestSession()); | 138 DCHECK(browser_view_->IsRegularOrGuestSession()); |
| 159 | 139 |
| 160 if (browser_view_->ShouldShowAvatar()) { | 140 if (browser_view_->ShouldShowAvatar()) { |
| 161 if (!new_avatar_button_) { | 141 if (!new_avatar_button_) { |
| 162 new_avatar_button_ = | 142 new_avatar_button_ = |
| 163 new NewAvatarButton(listener, style, browser_view_->browser()); | 143 new NewAvatarButton(listener, style, browser_view_->browser()); |
| 164 new_avatar_button_->set_id(VIEW_ID_NEW_AVATAR_BUTTON); | 144 new_avatar_button_->set_id(VIEW_ID_NEW_AVATAR_BUTTON); |
| 165 AddChildView(new_avatar_button_); | 145 AddChildView(new_avatar_button_); |
| 166 frame_->GetRootView()->Layout(); | 146 frame_->GetRootView()->Layout(); |
| 167 } | 147 } |
| 168 } else if (new_avatar_button_) { | 148 } else if (new_avatar_button_) { |
| 169 delete new_avatar_button_; | 149 delete new_avatar_button_; |
| 170 new_avatar_button_ = NULL; | 150 new_avatar_button_ = NULL; |
| 171 frame_->GetRootView()->Layout(); | 151 frame_->GetRootView()->Layout(); |
| 172 } | 152 } |
| 173 } | 153 } |
| 154 |
| 155 void BrowserNonClientFrameView::DrawTaskbarDecoration( |
| 156 const gfx::Image& avatar, |
| 157 const gfx::Image& taskbar_badge_avatar) { |
| 158 // For popups and panels which don't have the avatar button, we still |
| 159 // need to draw the taskbar decoration. Even though we have an icon on the |
| 160 // window's relaunch details, we draw over it because the user may have pinned |
| 161 // the badge-less Chrome shortcut which will cause windows to ignore the |
| 162 // relaunch details. |
| 163 // TODO(calamity): ideally this should not be necessary but due to issues with |
| 164 // the default shortcut being pinned, we add the runtime badge for safety. |
| 165 // See crbug.com/313800. |
| 166 chrome::DrawTaskbarDecoration(frame_->GetNativeWindow(), |
| 167 AvatarMenu::ShouldShowAvatarMenu() |
| 168 ? (taskbar_badge_avatar.IsEmpty() ? &avatar : &taskbar_badge_avatar) |
| 169 : NULL); |
| 170 } |
| 171 |
| 172 void BrowserNonClientFrameView::OnProfileAvatarChanged( |
| 173 const base::FilePath& profile_path) { |
| 174 gfx::Image avatar; |
| 175 gfx::Image taskbar_badge_avatar; |
| 176 bool is_rectangle; |
| 177 AvatarMenuButton::GetAvatarImages(browser_view_->browser()->profile(), |
| 178 &avatar, &taskbar_badge_avatar, |
| 179 &is_rectangle); |
| 180 DrawTaskbarDecoration(avatar, taskbar_badge_avatar); |
| 181 } |
| OLD | NEW |