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 10 matching lines...) Expand all Loading... | |
21 #include "third_party/skia/include/core/SkColor.h" | 21 #include "third_party/skia/include/core/SkColor.h" |
22 #include "ui/base/resource/resource_bundle.h" | 22 #include "ui/base/resource/resource_bundle.h" |
23 #include "ui/base/theme_provider.h" | 23 #include "ui/base/theme_provider.h" |
24 #include "ui/gfx/image/image.h" | 24 #include "ui/gfx/image/image.h" |
25 #include "ui/views/background.h" | 25 #include "ui/views/background.h" |
26 | 26 |
27 #if defined(ENABLE_MANAGED_USERS) | 27 #if defined(ENABLE_MANAGED_USERS) |
28 #include "chrome/browser/ui/views/profiles/supervised_user_avatar_label.h" | 28 #include "chrome/browser/ui/views/profiles/supervised_user_avatar_label.h" |
29 #endif | 29 #endif |
30 | 30 |
31 namespace { | |
32 | |
33 void GetAvatarImage(BrowserView* browser_view, | |
34 gfx::Image* avatar, | |
35 gfx::Image* taskbar_badge_avatar, | |
36 bool *is_rectangle) { | |
37 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
38 if (browser_view->IsGuestSession()) { | |
39 *avatar = rb. | |
40 GetImageNamed(profiles::GetPlaceholderAvatarIconResourceID()); | |
41 } else if (browser_view->IsOffTheRecord()) { | |
42 *avatar = rb.GetImageNamed(IDR_OTR_ICON); | |
43 // TODO(nkostylev): Allow this on ChromeOS once the ChromeOS test | |
44 // environment handles profile directories correctly. | |
45 #if !defined(OS_CHROMEOS) | |
46 bool is_badge_rectangle = false; | |
47 // The taskbar badge should be the profile avatar, not the OTR avatar. | |
48 AvatarMenu::GetImageForMenuButton(browser_view->browser()->profile(), | |
49 taskbar_badge_avatar, | |
50 &is_badge_rectangle); | |
51 #endif | |
52 } else if (AvatarMenu::ShouldShowAvatarMenu()) { | |
53 ProfileInfoCache& cache = | |
54 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
55 Profile* profile = browser_view->browser()->profile(); | |
56 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | |
57 if (index == std::string::npos) | |
58 return; | |
59 | |
60 if (switches::IsNewAvatarMenu()) { | |
61 *avatar = cache.GetAvatarIconOfProfileAtIndex(index); | |
62 } else { | |
63 AvatarMenu::GetImageForMenuButton(browser_view->browser()->profile(), | |
64 avatar, | |
65 is_rectangle); | |
66 } | |
67 } | |
68 } | |
Roger Tawa OOO till Jul 10th
2014/10/24 17:51:32
I made this an anonymous function in this file sin
| |
69 | |
70 } // namespace | |
71 | |
72 | |
31 BrowserNonClientFrameView::BrowserNonClientFrameView(BrowserFrame* frame, | 73 BrowserNonClientFrameView::BrowserNonClientFrameView(BrowserFrame* frame, |
32 BrowserView* browser_view) | 74 BrowserView* browser_view) |
33 : frame_(frame), | 75 : frame_(frame), |
34 browser_view_(browser_view), | 76 browser_view_(browser_view), |
35 avatar_button_(NULL), | 77 avatar_button_(NULL), |
36 #if defined(ENABLE_MANAGED_USERS) | 78 #if defined(ENABLE_MANAGED_USERS) |
37 supervised_user_avatar_label_(NULL), | 79 supervised_user_avatar_label_(NULL), |
38 #endif | 80 #endif |
39 new_avatar_button_(NULL) { | 81 new_avatar_button_(NULL) { |
82 ProfileInfoCache& cache = | |
83 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
84 cache.AddObserver(this); | |
40 } | 85 } |
41 | 86 |
42 BrowserNonClientFrameView::~BrowserNonClientFrameView() { | 87 BrowserNonClientFrameView::~BrowserNonClientFrameView() { |
88 ProfileInfoCache& cache = | |
89 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
90 cache.RemoveObserver(this); | |
43 } | 91 } |
44 | 92 |
45 void BrowserNonClientFrameView::VisibilityChanged(views::View* starting_from, | 93 void BrowserNonClientFrameView::VisibilityChanged(views::View* starting_from, |
46 bool is_visible) { | 94 bool is_visible) { |
47 if (!is_visible) | 95 if (!is_visible) |
48 return; | 96 return; |
49 // The first time UpdateAvatarInfo() is called the window is not visible so | 97 // The first time UpdateAvatarInfo() is called the window is not visible so |
50 // DrawTaskBarDecoration() has no effect. Therefore we need to call it again | 98 // DrawTaskBarDecoration() has no effect. Therefore we need to call it again |
51 // once the window is visible. | 99 // once the window is visible. |
52 if (!browser_view_->IsRegularOrGuestSession() || | 100 |
53 !switches::IsNewAvatarMenu()) | 101 // UpdateAvatarInfo() only supports the old style avatars. So call it |
102 // when |IsNewAvatarMenu()| returns false. However, incognito mode in the | |
103 // new style avatar still uses the old avatar button, so call | |
104 // UpdateAvatarInfo() in this case too. Because guest mode also reports | |
105 // itself as "incognito", make sure to check this is not a guest mode profile | |
106 // when |IsOffTheRecord()| returns true. | |
107 // | |
108 // To make sure the task bar icon is correctly updated in the new avatar | |
109 // style, call |OnProfileAvatarChanged()| in this case, but only for non | |
110 // guest profiles. | |
111 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.
| |
112 !switches::IsNewAvatarMenu()) { | |
54 UpdateAvatarInfo(); | 113 UpdateAvatarInfo(); |
114 } else if (!browser_view_->IsGuestSession()) { | |
115 OnProfileAvatarChanged(base::FilePath()); | |
116 } | |
55 } | 117 } |
56 | 118 |
57 #if defined(ENABLE_MANAGED_USERS) | 119 #if defined(ENABLE_MANAGED_USERS) |
58 void BrowserNonClientFrameView::OnThemeChanged() { | 120 void BrowserNonClientFrameView::OnThemeChanged() { |
59 if (supervised_user_avatar_label_) | 121 if (supervised_user_avatar_label_) |
60 supervised_user_avatar_label_->UpdateLabelStyle(); | 122 supervised_user_avatar_label_->UpdateLabelStyle(); |
61 } | 123 } |
62 #endif | 124 #endif |
63 | 125 |
64 void BrowserNonClientFrameView::UpdateAvatarInfo() { | 126 void BrowserNonClientFrameView::UpdateAvatarInfo() { |
(...skipping 25 matching lines...) Expand all Loading... | |
90 delete supervised_user_avatar_label_; | 152 delete supervised_user_avatar_label_; |
91 supervised_user_avatar_label_ = NULL; | 153 supervised_user_avatar_label_ = NULL; |
92 } | 154 } |
93 #endif | 155 #endif |
94 RemoveChildView(avatar_button_); | 156 RemoveChildView(avatar_button_); |
95 delete avatar_button_; | 157 delete avatar_button_; |
96 avatar_button_ = NULL; | 158 avatar_button_ = NULL; |
97 frame_->GetRootView()->Layout(); | 159 frame_->GetRootView()->Layout(); |
98 } | 160 } |
99 | 161 |
100 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
101 gfx::Image avatar; | 162 gfx::Image avatar; |
102 gfx::Image taskbar_badge_avatar; | 163 gfx::Image taskbar_badge_avatar; |
103 base::string16 text; | |
104 bool is_rectangle = false; | 164 bool is_rectangle = false; |
105 if (browser_view_->IsGuestSession()) { | 165 GetAvatarImage(browser_view_, &avatar, &taskbar_badge_avatar, &is_rectangle); |
106 avatar = rb. | |
107 GetImageNamed(profiles::GetPlaceholderAvatarIconResourceID()); | |
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 | 166 |
128 AvatarMenu::GetImageForMenuButton(browser_view_->browser()->profile(), | 167 // Disable the menu when we should not show the menu. |
129 &avatar, | 168 if (avatar_button_ && !AvatarMenu::ShouldShowAvatarMenu()) |
130 &is_rectangle); | 169 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_) | 170 if (avatar_button_) |
136 avatar_button_->SetAvatarIcon(avatar, is_rectangle); | 171 avatar_button_->SetAvatarIcon(avatar, is_rectangle); |
137 | 172 |
138 // For popups and panels which don't have the avatar button, we still | 173 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.
| |
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 } | 174 } |
152 | 175 |
153 void BrowserNonClientFrameView::UpdateNewStyleAvatarInfo( | 176 void BrowserNonClientFrameView::UpdateNewStyleAvatarInfo( |
154 views::ButtonListener* listener, | 177 views::ButtonListener* listener, |
155 const NewAvatarButton::AvatarButtonStyle style) { | 178 const NewAvatarButton::AvatarButtonStyle style) { |
156 DCHECK(switches::IsNewAvatarMenu()); | 179 DCHECK(switches::IsNewAvatarMenu()); |
157 // This should never be called in incognito mode. | 180 // This should never be called in incognito mode. |
158 DCHECK(browser_view_->IsRegularOrGuestSession()); | 181 DCHECK(browser_view_->IsRegularOrGuestSession()); |
159 | 182 |
160 if (browser_view_->ShouldShowAvatar()) { | 183 if (browser_view_->ShouldShowAvatar()) { |
161 if (!new_avatar_button_) { | 184 if (!new_avatar_button_) { |
162 new_avatar_button_ = | 185 new_avatar_button_ = |
163 new NewAvatarButton(listener, style, browser_view_->browser()); | 186 new NewAvatarButton(listener, style, browser_view_->browser()); |
164 new_avatar_button_->set_id(VIEW_ID_NEW_AVATAR_BUTTON); | 187 new_avatar_button_->set_id(VIEW_ID_NEW_AVATAR_BUTTON); |
165 AddChildView(new_avatar_button_); | 188 AddChildView(new_avatar_button_); |
166 frame_->GetRootView()->Layout(); | 189 frame_->GetRootView()->Layout(); |
167 } | 190 } |
168 } else if (new_avatar_button_) { | 191 } else if (new_avatar_button_) { |
169 delete new_avatar_button_; | 192 delete new_avatar_button_; |
170 new_avatar_button_ = NULL; | 193 new_avatar_button_ = NULL; |
171 frame_->GetRootView()->Layout(); | 194 frame_->GetRootView()->Layout(); |
172 } | 195 } |
173 } | 196 } |
197 | |
198 void BrowserNonClientFrameView::DrawTaskbarDecoration( | |
199 const gfx::Image& avatar, | |
200 const gfx::Image& taskbar_badge_avatar) { | |
201 // For popups and panels which don't have the avatar button, we still | |
202 // need to draw the taskbar decoration. Even though we have an icon on the | |
203 // window's relaunch details, we draw over it because the user may have pinned | |
204 // the badge-less Chrome shortcut which will cause windows to ignore the | |
205 // relaunch details. | |
206 // TODO(calamity): ideally this should not be necessary but due to issues with | |
207 // the default shortcut being pinned, we add the runtime badge for safety. | |
208 // See crbug.com/313800. | |
209 chrome::DrawTaskbarDecoration(frame_->GetNativeWindow(), | |
210 AvatarMenu::ShouldShowAvatarMenu() | |
211 ? (taskbar_badge_avatar.IsEmpty() ? &avatar : &taskbar_badge_avatar) | |
212 : NULL); | |
213 } | |
214 | |
215 void BrowserNonClientFrameView::OnProfileAvatarChanged( | |
216 const base::FilePath& profile_path) { | |
217 gfx::Image avatar; | |
218 gfx::Image taskbar_badge_avatar; | |
219 bool is_rectangle; | |
220 GetAvatarImage(browser_view_, &avatar, &taskbar_badge_avatar, &is_rectangle); | |
221 DrawTaskbarDecoration(avatar, taskbar_badge_avatar); | |
222 } | |
OLD | NEW |