OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/managed_mode.h" |
| 9 #include "chrome/browser/profiles/avatar_menu_model.h" |
8 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/profiles/profile_info_cache.h" | 11 #include "chrome/browser/profiles/profile_info_cache.h" |
10 #include "chrome/browser/profiles/profile_manager.h" | 12 #include "chrome/browser/profiles/profile_manager.h" |
11 #include "chrome/browser/ui/views/avatar_menu_button.h" | 13 #include "chrome/browser/ui/views/avatar_menu_button.h" |
12 #include "chrome/browser/ui/views/frame/browser_view.h" | 14 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 15 #include "grit/theme_resources.h" |
| 16 #include "ui/base/resource/resource_bundle.h" |
13 #include "ui/gfx/image/image.h" | 17 #include "ui/gfx/image/image.h" |
14 | 18 |
15 BrowserNonClientFrameView::BrowserNonClientFrameView(BrowserFrame* frame, | 19 BrowserNonClientFrameView::BrowserNonClientFrameView(BrowserFrame* frame, |
16 BrowserView* browser_view) | 20 BrowserView* browser_view) |
17 : frame_(frame), | 21 : frame_(frame), |
18 browser_view_(browser_view) { | 22 browser_view_(browser_view) { |
19 } | 23 } |
20 | 24 |
21 BrowserNonClientFrameView::~BrowserNonClientFrameView() { | 25 BrowserNonClientFrameView::~BrowserNonClientFrameView() { |
22 } | 26 } |
23 | 27 |
24 void BrowserNonClientFrameView::UpdateAvatarInfo() { | 28 void BrowserNonClientFrameView::UpdateAvatarInfo() { |
25 if (browser_view_->ShouldShowAvatar()) { | 29 if (browser_view_->ShouldShowAvatar()) { |
26 if (!avatar_button_.get()) { | 30 if (!avatar_button_.get()) { |
27 avatar_button_.reset(new AvatarMenuButton( | 31 avatar_button_.reset( |
28 browser_view_->browser(), !browser_view_->IsOffTheRecord())); | 32 new AvatarMenuButton(browser_view_->browser(), |
| 33 browser_view_->IsOffTheRecord())); |
29 AddChildView(avatar_button_.get()); | 34 AddChildView(avatar_button_.get()); |
30 frame_->GetRootView()->Layout(); | 35 frame_->GetRootView()->Layout(); |
31 } | 36 } |
32 } else if (avatar_button_.get()) { | 37 } else if (avatar_button_.get()) { |
33 RemoveChildView(avatar_button_.get()); | 38 RemoveChildView(avatar_button_.get()); |
34 avatar_button_.reset(); | 39 avatar_button_.reset(); |
35 frame_->GetRootView()->Layout(); | 40 frame_->GetRootView()->Layout(); |
36 } | 41 } |
37 | 42 |
| 43 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 44 gfx::Image avatar; |
| 45 string16 text; |
| 46 bool is_gaia_picture = false; |
| 47 if (browser_view_->IsGuestSession()) { |
| 48 #if defined(OS_CHROMEOS) |
| 49 avatar = rb.GetImageNamed(IDR_GUEST_ICON); |
| 50 #else |
| 51 NOTREACHED(); |
| 52 #endif |
| 53 } else if (browser_view_->IsOffTheRecord()) { |
| 54 avatar = rb.GetImageNamed(IDR_OTR_ICON); |
| 55 } else if (ManagedMode::IsInManagedMode()) { |
| 56 avatar = rb.GetImageNamed(IDR_MANAGED_MODE_AVATAR); |
| 57 } else if (AvatarMenuModel::ShouldShowAvatarMenu()) { |
| 58 ProfileInfoCache& cache = |
| 59 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 60 Profile* profile = browser_view_->browser()->profile(); |
| 61 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath()); |
| 62 if (index == std::string::npos) |
| 63 return; |
| 64 is_gaia_picture = |
| 65 cache.IsUsingGAIAPictureOfProfileAtIndex(index) && |
| 66 cache.GetGAIAPictureOfProfileAtIndex(index); |
| 67 avatar = cache.GetAvatarIconOfProfileAtIndex(index); |
| 68 text = cache.GetNameOfProfileAtIndex(index); |
| 69 } |
| 70 if (avatar_button_.get()) { |
| 71 avatar_button_->SetAvatarIcon(avatar, is_gaia_picture); |
| 72 if (!text.empty()) |
| 73 avatar_button_->SetText(text); |
| 74 } |
| 75 |
38 // For popups and panels which don't have the avatar button, we still | 76 // For popups and panels which don't have the avatar button, we still |
39 // need to draw the taskbar decoration. | 77 // need to draw the taskbar decoration. |
40 if (browser_view_->IsBrowserTypeNormal()) { | 78 if (AvatarMenuModel::ShouldShowAvatarMenu() || |
41 if (!avatar_button_.get()) | 79 ManagedMode::IsInManagedMode()) { |
42 return; | |
43 } | |
44 | |
45 if (browser_view_->IsGuestSession()) { | |
46 const gfx::Image avatar(new SkBitmap(browser_view_->GetGuestAvatarIcon())); | |
47 if (avatar_button_.get()) | |
48 avatar_button_->SetAvatarIcon(avatar, false); | |
49 DrawTaskBarDecoration(frame_->GetNativeWindow(), &avatar); | |
50 } else if (browser_view_->IsOffTheRecord()) { | |
51 const gfx::Image avatar(new SkBitmap(browser_view_->GetOTRAvatarIcon())); | |
52 if (avatar_button_.get()) | |
53 avatar_button_->SetAvatarIcon(avatar, false); | |
54 DrawTaskBarDecoration(frame_->GetNativeWindow(), &avatar); | 80 DrawTaskBarDecoration(frame_->GetNativeWindow(), &avatar); |
55 } else { | 81 } else { |
56 ProfileInfoCache& cache = | 82 DrawTaskBarDecoration(frame_->GetNativeWindow(), NULL); |
57 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
58 Profile* profile = browser_view_->browser()->profile(); | |
59 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | |
60 if (index != std::string::npos) { | |
61 bool is_gaia_picture = | |
62 cache.IsUsingGAIAPictureOfProfileAtIndex(index) && | |
63 cache.GetGAIAPictureOfProfileAtIndex(index); | |
64 const gfx::Image& avatar = cache.GetAvatarIconOfProfileAtIndex(index); | |
65 if (avatar_button_.get()) { | |
66 avatar_button_->SetAvatarIcon(avatar, is_gaia_picture); | |
67 avatar_button_->SetText(cache.GetNameOfProfileAtIndex(index)); | |
68 } | |
69 DrawTaskBarDecoration(frame_->GetNativeWindow(), &avatar); | |
70 } | |
71 } | 83 } |
72 } | 84 } |
73 | 85 |
74 void BrowserNonClientFrameView::VisibilityChanged(views::View* starting_from, | 86 void BrowserNonClientFrameView::VisibilityChanged(views::View* starting_from, |
75 bool is_visible) { | 87 bool is_visible) { |
76 if (!is_visible) | 88 if (!is_visible) |
77 return; | 89 return; |
78 // The first time UpdateAvatarInfo() is called the window is not visible so | 90 // The first time UpdateAvatarInfo() is called the window is not visible so |
79 // DrawTaskBarDecoration() has no effect. Therefore we need to call it again | 91 // DrawTaskBarDecoration() has no effect. Therefore we need to call it again |
80 // once the window is visible. | 92 // once the window is visible. |
81 UpdateAvatarInfo(); | 93 UpdateAvatarInfo(); |
82 } | 94 } |
OLD | NEW |