| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 OnProfileAvatarChanged(base::FilePath()); | 80 OnProfileAvatarChanged(base::FilePath()); |
| 81 } | 81 } |
| 82 | 82 |
| 83 #if defined(ENABLE_SUPERVISED_USERS) | 83 #if defined(ENABLE_SUPERVISED_USERS) |
| 84 void BrowserNonClientFrameView::OnThemeChanged() { | 84 void BrowserNonClientFrameView::OnThemeChanged() { |
| 85 if (supervised_user_avatar_label_) | 85 if (supervised_user_avatar_label_) |
| 86 supervised_user_avatar_label_->UpdateLabelStyle(); | 86 supervised_user_avatar_label_->UpdateLabelStyle(); |
| 87 } | 87 } |
| 88 #endif | 88 #endif |
| 89 | 89 |
| 90 void BrowserNonClientFrameView::UpdateAvatar() { |
| 91 if (browser_view()->IsRegularOrGuestSession() && switches::IsNewAvatarMenu()) |
| 92 UpdateNewStyleAvatar(); |
| 93 else |
| 94 UpdateAvatarInfo(); |
| 95 } |
| 96 |
| 90 void BrowserNonClientFrameView::UpdateAvatarInfo() { | 97 void BrowserNonClientFrameView::UpdateAvatarInfo() { |
| 91 if (browser_view_->ShouldShowAvatar()) { | 98 if (browser_view_->ShouldShowAvatar()) { |
| 92 if (!avatar_button_) { | 99 if (!avatar_button_) { |
| 93 #if defined(ENABLE_SUPERVISED_USERS) | 100 #if defined(ENABLE_SUPERVISED_USERS) |
| 94 Profile* profile = browser_view_->browser()->profile(); | 101 Profile* profile = browser_view_->browser()->profile(); |
| 95 if (profile->IsSupervised() && !supervised_user_avatar_label_) { | 102 if (profile->IsSupervised() && !supervised_user_avatar_label_) { |
| 96 supervised_user_avatar_label_ = | 103 supervised_user_avatar_label_ = |
| 97 new SupervisedUserAvatarLabel(browser_view_); | 104 new SupervisedUserAvatarLabel(browser_view_); |
| 98 supervised_user_avatar_label_->set_id( | 105 supervised_user_avatar_label_->set_id( |
| 99 VIEW_ID_SUPERVISED_USER_AVATAR_LABEL); | 106 VIEW_ID_SUPERVISED_USER_AVATAR_LABEL); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 AddChildView(new_avatar_button_); | 166 AddChildView(new_avatar_button_); |
| 160 frame_->GetRootView()->Layout(); | 167 frame_->GetRootView()->Layout(); |
| 161 } | 168 } |
| 162 } else if (new_avatar_button_) { | 169 } else if (new_avatar_button_) { |
| 163 delete new_avatar_button_; | 170 delete new_avatar_button_; |
| 164 new_avatar_button_ = nullptr; | 171 new_avatar_button_ = nullptr; |
| 165 frame_->GetRootView()->Layout(); | 172 frame_->GetRootView()->Layout(); |
| 166 } | 173 } |
| 167 } | 174 } |
| 168 | 175 |
| 169 void BrowserNonClientFrameView::DrawTaskbarDecoration( | |
| 170 const gfx::Image& avatar, | |
| 171 const gfx::Image& taskbar_badge_avatar) { | |
| 172 // For popups and panels which don't have the avatar button, we still | |
| 173 // need to draw the taskbar decoration. Even though we have an icon on the | |
| 174 // window's relaunch details, we draw over it because the user may have pinned | |
| 175 // the badge-less Chrome shortcut which will cause windows to ignore the | |
| 176 // relaunch details. | |
| 177 // TODO(calamity): ideally this should not be necessary but due to issues with | |
| 178 // the default shortcut being pinned, we add the runtime badge for safety. | |
| 179 // See crbug.com/313800. | |
| 180 bool show_decoration = AvatarMenu::ShouldShowAvatarMenu() && | |
| 181 !browser_view_->browser()->profile()->IsGuestSession(); | |
| 182 // In tests, make sure that the browser process and profile manager are valid | |
| 183 // before using. | |
| 184 if (g_browser_process && g_browser_process->profile_manager()) { | |
| 185 const ProfileInfoCache& cache = | |
| 186 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
| 187 show_decoration = show_decoration && cache.GetNumberOfProfiles() > 1; | |
| 188 } | |
| 189 chrome::DrawTaskbarDecoration(frame_->GetNativeWindow(), | |
| 190 show_decoration | |
| 191 ? (taskbar_badge_avatar.IsEmpty() ? &avatar : &taskbar_badge_avatar) | |
| 192 : nullptr); | |
| 193 } | |
| 194 | |
| 195 void BrowserNonClientFrameView::OnProfileAdded( | 176 void BrowserNonClientFrameView::OnProfileAdded( |
| 196 const base::FilePath& profile_path) { | 177 const base::FilePath& profile_path) { |
| 197 OnProfileAvatarChanged(profile_path); | 178 UpdateTaskbarDecoration(); |
| 179 UpdateAvatar(); |
| 198 } | 180 } |
| 199 | 181 |
| 200 void BrowserNonClientFrameView::OnProfileWasRemoved( | 182 void BrowserNonClientFrameView::OnProfileWasRemoved( |
| 201 const base::FilePath& profile_path, | 183 const base::FilePath& profile_path, |
| 202 const base::string16& profile_name) { | 184 const base::string16& profile_name) { |
| 203 OnProfileAvatarChanged(profile_path); | 185 UpdateTaskbarDecoration(); |
| 186 UpdateAvatar(); |
| 204 } | 187 } |
| 205 | 188 |
| 206 void BrowserNonClientFrameView::OnProfileAvatarChanged( | 189 void BrowserNonClientFrameView::OnProfileAvatarChanged( |
| 207 const base::FilePath& profile_path) { | 190 const base::FilePath& profile_path) { |
| 191 UpdateTaskbarDecoration(); |
| 192 // Profile avatars are only displayed in the old UI or incognito. |
| 193 if (browser_view()->IsOffTheRecord() || !switches::IsNewAvatarMenu()) |
| 194 UpdateAvatarInfo(); |
| 195 } |
| 196 |
| 197 void BrowserNonClientFrameView::OnProfileNameChanged( |
| 198 const base::FilePath& profile_path, |
| 199 const base::string16& old_profile_name) { |
| 200 UpdateAvatar(); |
| 201 } |
| 202 |
| 203 void BrowserNonClientFrameView::UpdateTaskbarDecoration() { |
| 208 gfx::Image avatar; | 204 gfx::Image avatar; |
| 209 gfx::Image taskbar_badge_avatar; | 205 gfx::Image taskbar_badge_avatar; |
| 210 bool is_rectangle; | 206 bool is_rectangle; |
| 211 // Only need to update the taskbar overlay here. If GetAvatarImages() | 207 // Only need to update the taskbar overlay here. If GetAvatarImages() |
| 212 // returns false, don't bother trying to update the taskbar decoration since | 208 // returns false, don't bother trying to update the taskbar decoration since |
| 213 // the returned images are not initialized. This can happen if the user | 209 // the returned images are not initialized. This can happen if the user |
| 214 // deletes the current profile. | 210 // deletes the current profile. |
| 215 if (AvatarMenuButton::GetAvatarImages(browser_view_->browser()->profile(), | 211 if (AvatarMenuButton::GetAvatarImages(browser_view_->browser()->profile(), |
| 216 AvatarMenu::ShouldShowAvatarMenu(), | 212 AvatarMenu::ShouldShowAvatarMenu(), |
| 217 &avatar, &taskbar_badge_avatar, | 213 &avatar, &taskbar_badge_avatar, |
| 218 &is_rectangle)) { | 214 &is_rectangle)) { |
| 219 DrawTaskbarDecoration(avatar, taskbar_badge_avatar); | 215 // For popups and panels which don't have the avatar button, we still |
| 216 // need to draw the taskbar decoration. Even though we have an icon on the |
| 217 // window's relaunch details, we draw over it because the user may have |
| 218 // pinned the badge-less Chrome shortcut which will cause windows to ignore |
| 219 // the relaunch details. |
| 220 // TODO(calamity): ideally this should not be necessary but due to issues |
| 221 // with the default shortcut being pinned, we add the runtime badge for |
| 222 // safety. See crbug.com/313800. |
| 223 bool show_decoration = AvatarMenu::ShouldShowAvatarMenu() && |
| 224 !browser_view_->browser()->profile()->IsGuestSession(); |
| 225 // In tests, make sure that the browser process and profile manager are |
| 226 // valid before using. |
| 227 if (g_browser_process && g_browser_process->profile_manager()) { |
| 228 const ProfileInfoCache& cache = |
| 229 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 230 show_decoration = show_decoration && cache.GetNumberOfProfiles() > 1; |
| 231 } |
| 232 chrome::DrawTaskbarDecoration(frame_->GetNativeWindow(), |
| 233 show_decoration |
| 234 ? (taskbar_badge_avatar.IsEmpty() ? &avatar : &taskbar_badge_avatar) |
| 235 : nullptr); |
| 220 } | 236 } |
| 221 } | 237 } |
| OLD | NEW |