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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 #if defined(ENABLE_SUPERVISED_USERS) | 201 #if defined(ENABLE_SUPERVISED_USERS) |
202 Profile* profile = browser_view_->browser()->profile(); | 202 Profile* profile = browser_view_->browser()->profile(); |
203 if (profile->IsSupervised() && !supervised_user_avatar_label_) { | 203 if (profile->IsSupervised() && !supervised_user_avatar_label_) { |
204 supervised_user_avatar_label_ = | 204 supervised_user_avatar_label_ = |
205 new SupervisedUserAvatarLabel(browser_view_); | 205 new SupervisedUserAvatarLabel(browser_view_); |
206 supervised_user_avatar_label_->set_id( | 206 supervised_user_avatar_label_->set_id( |
207 VIEW_ID_SUPERVISED_USER_AVATAR_LABEL); | 207 VIEW_ID_SUPERVISED_USER_AVATAR_LABEL); |
208 AddChildView(supervised_user_avatar_label_); | 208 AddChildView(supervised_user_avatar_label_); |
209 } | 209 } |
210 #endif | 210 #endif |
211 avatar_button_ = new AvatarMenuButton( | 211 avatar_button_ = new AvatarMenuButton(browser_view_); |
212 browser_view_->browser(), !browser_view_->IsRegularOrGuestSession()); | |
213 avatar_button_->set_id(VIEW_ID_AVATAR_BUTTON); | 212 avatar_button_->set_id(VIEW_ID_AVATAR_BUTTON); |
214 AddChildView(avatar_button_); | 213 AddChildView(avatar_button_); |
215 // Invalidate here because adding a child does not invalidate the layout. | 214 // Invalidate here because adding a child does not invalidate the layout. |
216 InvalidateLayout(); | 215 InvalidateLayout(); |
217 frame_->GetRootView()->Layout(); | 216 frame_->GetRootView()->Layout(); |
218 } | 217 } |
219 } else if (avatar_button_) { | 218 } else if (avatar_button_) { |
220 #if defined(ENABLE_SUPERVISED_USERS) | 219 #if defined(ENABLE_SUPERVISED_USERS) |
221 // The avatar label can just be there if there is also an avatar button. | 220 // The avatar label can just be there if there is also an avatar button. |
222 if (supervised_user_avatar_label_) { | 221 if (supervised_user_avatar_label_) { |
223 RemoveChildView(supervised_user_avatar_label_); | 222 RemoveChildView(supervised_user_avatar_label_); |
224 delete supervised_user_avatar_label_; | 223 delete supervised_user_avatar_label_; |
225 supervised_user_avatar_label_ = nullptr; | 224 supervised_user_avatar_label_ = nullptr; |
226 } | 225 } |
227 #endif | 226 #endif |
228 RemoveChildView(avatar_button_); | 227 RemoveChildView(avatar_button_); |
229 delete avatar_button_; | 228 delete avatar_button_; |
230 avatar_button_ = nullptr; | 229 avatar_button_ = nullptr; |
231 frame_->GetRootView()->Layout(); | 230 frame_->GetRootView()->Layout(); |
232 } | 231 } |
233 | 232 |
234 gfx::Image avatar; | 233 gfx::Image avatar; |
235 gfx::Image taskbar_badge_avatar; | 234 gfx::Image taskbar_badge_avatar; |
236 bool is_rectangle = false; | 235 bool is_rectangle = false; |
237 | 236 |
238 // Update the avatar button in the window frame and the taskbar overlay. | 237 // Update the avatar button in the window frame and the taskbar overlay. |
239 bool should_show_avatar_menu = | 238 bool should_show_avatar_menu = |
240 avatar_button_ || AvatarMenu::ShouldShowAvatarMenu(); | 239 avatar_button_ || AvatarMenu::ShouldShowAvatarMenu(); |
241 | 240 |
242 if (!AvatarMenuButton::GetAvatarImages( | 241 if (!AvatarMenuButton::GetAvatarImages(browser_view_, should_show_avatar_menu, |
243 browser_view_->browser()->profile(), should_show_avatar_menu, &avatar, | 242 &avatar, &taskbar_badge_avatar, |
244 &taskbar_badge_avatar, &is_rectangle)) { | 243 &is_rectangle)) { |
245 return; | 244 return; |
246 } | 245 } |
247 | 246 |
248 // Disable the menu when we should not show the menu. | 247 // Disable the menu when we should not show the menu. |
249 if (avatar_button_ && !AvatarMenu::ShouldShowAvatarMenu()) | 248 if (avatar_button_ && !AvatarMenu::ShouldShowAvatarMenu()) |
250 avatar_button_->SetEnabled(false); | 249 avatar_button_->SetEnabled(false); |
251 if (avatar_button_) | 250 if (avatar_button_) |
252 avatar_button_->SetAvatarIcon(avatar, is_rectangle); | 251 avatar_button_->SetAvatarIcon(avatar, is_rectangle); |
253 } | 252 } |
254 | 253 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 } | 299 } |
301 | 300 |
302 void BrowserNonClientFrameView::UpdateTaskbarDecoration() { | 301 void BrowserNonClientFrameView::UpdateTaskbarDecoration() { |
303 gfx::Image avatar; | 302 gfx::Image avatar; |
304 gfx::Image taskbar_badge_avatar; | 303 gfx::Image taskbar_badge_avatar; |
305 bool is_rectangle; | 304 bool is_rectangle; |
306 // Only need to update the taskbar overlay here. If GetAvatarImages() | 305 // Only need to update the taskbar overlay here. If GetAvatarImages() |
307 // returns false, don't bother trying to update the taskbar decoration since | 306 // returns false, don't bother trying to update the taskbar decoration since |
308 // the returned images are not initialized. This can happen if the user | 307 // the returned images are not initialized. This can happen if the user |
309 // deletes the current profile. | 308 // deletes the current profile. |
310 if (AvatarMenuButton::GetAvatarImages(browser_view_->browser()->profile(), | 309 if (AvatarMenuButton::GetAvatarImages( |
311 AvatarMenu::ShouldShowAvatarMenu(), | 310 browser_view_, AvatarMenu::ShouldShowAvatarMenu(), &avatar, |
312 &avatar, &taskbar_badge_avatar, | 311 &taskbar_badge_avatar, &is_rectangle)) { |
313 &is_rectangle)) { | |
314 // For popups and panels which don't have the avatar button, we still | 312 // For popups and panels which don't have the avatar button, we still |
315 // need to draw the taskbar decoration. Even though we have an icon on the | 313 // need to draw the taskbar decoration. Even though we have an icon on the |
316 // window's relaunch details, we draw over it because the user may have | 314 // window's relaunch details, we draw over it because the user may have |
317 // pinned the badge-less Chrome shortcut which will cause windows to ignore | 315 // pinned the badge-less Chrome shortcut which will cause windows to ignore |
318 // the relaunch details. | 316 // the relaunch details. |
319 // TODO(calamity): ideally this should not be necessary but due to issues | 317 // TODO(calamity): ideally this should not be necessary but due to issues |
320 // with the default shortcut being pinned, we add the runtime badge for | 318 // with the default shortcut being pinned, we add the runtime badge for |
321 // safety. See crbug.com/313800. | 319 // safety. See crbug.com/313800. |
322 bool show_decoration = AvatarMenu::ShouldShowAvatarMenu() && | 320 bool show_decoration = AvatarMenu::ShouldShowAvatarMenu() && |
323 !browser_view_->browser()->profile()->IsGuestSession(); | 321 !browser_view_->browser()->profile()->IsGuestSession(); |
324 // In tests, make sure that the browser process and profile manager are | 322 // In tests, make sure that the browser process and profile manager are |
325 // valid before using. | 323 // valid before using. |
326 if (g_browser_process && g_browser_process->profile_manager()) { | 324 if (g_browser_process && g_browser_process->profile_manager()) { |
327 const ProfileInfoCache& cache = | 325 const ProfileInfoCache& cache = |
328 g_browser_process->profile_manager()->GetProfileInfoCache(); | 326 g_browser_process->profile_manager()->GetProfileInfoCache(); |
329 show_decoration = show_decoration && cache.GetNumberOfProfiles() > 1; | 327 show_decoration = show_decoration && cache.GetNumberOfProfiles() > 1; |
330 } | 328 } |
331 chrome::DrawTaskbarDecoration(frame_->GetNativeWindow(), | 329 chrome::DrawTaskbarDecoration(frame_->GetNativeWindow(), |
332 show_decoration | 330 show_decoration |
333 ? (taskbar_badge_avatar.IsEmpty() ? &avatar : &taskbar_badge_avatar) | 331 ? (taskbar_badge_avatar.IsEmpty() ? &avatar : &taskbar_badge_avatar) |
334 : nullptr); | 332 : nullptr); |
335 } | 333 } |
336 } | 334 } |
OLD | NEW |