Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: chrome/browser/ui/views/frame/browser_non_client_frame_view.cc

Issue 678553002: Badge icons in windows task bar with avatar icon. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests with no profile manager Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/views/frame/browser_non_client_frame_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 }
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 // The profile manager may by NULL in tests.
83 if (g_browser_process->profile_manager()) {
84 ProfileInfoCache& cache =
85 g_browser_process->profile_manager()->GetProfileInfoCache();
86 cache.AddObserver(this);
87 }
40 } 88 }
41 89
42 BrowserNonClientFrameView::~BrowserNonClientFrameView() { 90 BrowserNonClientFrameView::~BrowserNonClientFrameView() {
91 // The profile manager may by NULL in tests.
92 if (g_browser_process->profile_manager()) {
93 ProfileInfoCache& cache =
94 g_browser_process->profile_manager()->GetProfileInfoCache();
95 cache.RemoveObserver(this);
96 }
43 } 97 }
44 98
45 void BrowserNonClientFrameView::VisibilityChanged(views::View* starting_from, 99 void BrowserNonClientFrameView::VisibilityChanged(views::View* starting_from,
46 bool is_visible) { 100 bool is_visible) {
47 if (!is_visible) 101 if (!is_visible)
48 return; 102 return;
103
49 // The first time UpdateAvatarInfo() is called the window is not visible so 104 // The first time UpdateAvatarInfo() is called the window is not visible so
50 // DrawTaskBarDecoration() has no effect. Therefore we need to call it again 105 // DrawTaskBarDecoration() has no effect. Therefore we need to call it again
51 // once the window is visible. 106 // once the window is visible.
52 if (!browser_view_->IsRegularOrGuestSession() || 107 if (!browser_view_->IsRegularOrGuestSession() ||
53 !switches::IsNewAvatarMenu()) 108 !switches::IsNewAvatarMenu()) {
54 UpdateAvatarInfo(); 109 UpdateAvatarInfo();
110 }
111
112 // Make sure the task bar icon is correctly updated call
noms (inactive) 2014/10/24 18:44:57 nit: two spaces between updated and call :(
113 // |OnProfileAvatarChanged()| in this case, but only for non guest profiles.
114 if (!browser_view_->IsGuestSession() || !switches::IsNewAvatarMenu())
115 OnProfileAvatarChanged(base::FilePath());
55 } 116 }
56 117
57 #if defined(ENABLE_MANAGED_USERS) 118 #if defined(ENABLE_MANAGED_USERS)
58 void BrowserNonClientFrameView::OnThemeChanged() { 119 void BrowserNonClientFrameView::OnThemeChanged() {
59 if (supervised_user_avatar_label_) 120 if (supervised_user_avatar_label_)
60 supervised_user_avatar_label_->UpdateLabelStyle(); 121 supervised_user_avatar_label_->UpdateLabelStyle();
61 } 122 }
62 #endif 123 #endif
63 124
64 void BrowserNonClientFrameView::UpdateAvatarInfo() { 125 void BrowserNonClientFrameView::UpdateAvatarInfo() {
(...skipping 25 matching lines...) Expand all
90 delete supervised_user_avatar_label_; 151 delete supervised_user_avatar_label_;
91 supervised_user_avatar_label_ = NULL; 152 supervised_user_avatar_label_ = NULL;
92 } 153 }
93 #endif 154 #endif
94 RemoveChildView(avatar_button_); 155 RemoveChildView(avatar_button_);
95 delete avatar_button_; 156 delete avatar_button_;
96 avatar_button_ = NULL; 157 avatar_button_ = NULL;
97 frame_->GetRootView()->Layout(); 158 frame_->GetRootView()->Layout();
98 } 159 }
99 160
100 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
101 gfx::Image avatar; 161 gfx::Image avatar;
102 gfx::Image taskbar_badge_avatar; 162 gfx::Image taskbar_badge_avatar;
103 base::string16 text;
104 bool is_rectangle = false; 163 bool is_rectangle = false;
105 if (browser_view_->IsGuestSession()) { 164 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 165
128 AvatarMenu::GetImageForMenuButton(browser_view_->browser()->profile(), 166 // Disable the menu when we should not show the menu.
129 &avatar, 167 if (avatar_button_ && !AvatarMenu::ShouldShowAvatarMenu())
130 &is_rectangle); 168 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_) 169 if (avatar_button_)
136 avatar_button_->SetAvatarIcon(avatar, is_rectangle); 170 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 } 171 }
152 172
153 void BrowserNonClientFrameView::UpdateNewStyleAvatarInfo( 173 void BrowserNonClientFrameView::UpdateNewStyleAvatarInfo(
154 views::ButtonListener* listener, 174 views::ButtonListener* listener,
155 const NewAvatarButton::AvatarButtonStyle style) { 175 const NewAvatarButton::AvatarButtonStyle style) {
156 DCHECK(switches::IsNewAvatarMenu()); 176 DCHECK(switches::IsNewAvatarMenu());
157 // This should never be called in incognito mode. 177 // This should never be called in incognito mode.
158 DCHECK(browser_view_->IsRegularOrGuestSession()); 178 DCHECK(browser_view_->IsRegularOrGuestSession());
159 179
160 if (browser_view_->ShouldShowAvatar()) { 180 if (browser_view_->ShouldShowAvatar()) {
161 if (!new_avatar_button_) { 181 if (!new_avatar_button_) {
162 new_avatar_button_ = 182 new_avatar_button_ =
163 new NewAvatarButton(listener, style, browser_view_->browser()); 183 new NewAvatarButton(listener, style, browser_view_->browser());
164 new_avatar_button_->set_id(VIEW_ID_NEW_AVATAR_BUTTON); 184 new_avatar_button_->set_id(VIEW_ID_NEW_AVATAR_BUTTON);
165 AddChildView(new_avatar_button_); 185 AddChildView(new_avatar_button_);
166 frame_->GetRootView()->Layout(); 186 frame_->GetRootView()->Layout();
167 } 187 }
168 } else if (new_avatar_button_) { 188 } else if (new_avatar_button_) {
169 delete new_avatar_button_; 189 delete new_avatar_button_;
170 new_avatar_button_ = NULL; 190 new_avatar_button_ = NULL;
171 frame_->GetRootView()->Layout(); 191 frame_->GetRootView()->Layout();
172 } 192 }
173 } 193 }
194
195 void BrowserNonClientFrameView::DrawTaskbarDecoration(
196 const gfx::Image& avatar,
197 const gfx::Image& taskbar_badge_avatar) {
198 // For popups and panels which don't have the avatar button, we still
199 // need to draw the taskbar decoration. Even though we have an icon on the
200 // window's relaunch details, we draw over it because the user may have pinned
201 // the badge-less Chrome shortcut which will cause windows to ignore the
202 // relaunch details.
203 // TODO(calamity): ideally this should not be necessary but due to issues with
204 // the default shortcut being pinned, we add the runtime badge for safety.
205 // See crbug.com/313800.
206 chrome::DrawTaskbarDecoration(frame_->GetNativeWindow(),
207 AvatarMenu::ShouldShowAvatarMenu()
208 ? (taskbar_badge_avatar.IsEmpty() ? &avatar : &taskbar_badge_avatar)
209 : NULL);
210 }
211
212 void BrowserNonClientFrameView::OnProfileAvatarChanged(
213 const base::FilePath& profile_path) {
214 gfx::Image avatar;
215 gfx::Image taskbar_badge_avatar;
216 bool is_rectangle;
217 GetAvatarImage(browser_view_, &avatar, &taskbar_badge_avatar, &is_rectangle);
218 DrawTaskbarDecoration(avatar, taskbar_badge_avatar);
219 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/frame/browser_non_client_frame_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698