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

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

Issue 9500003: Add a button to exit managed mode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update Created 8 years, 8 months 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 | Annotate | Revision Log
OLDNEW
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"
13 #include "ui/gfx/image/image.h" 15 #include "ui/gfx/image/image.h"
14 16
15 BrowserNonClientFrameView::BrowserNonClientFrameView(BrowserFrame* frame, 17 BrowserNonClientFrameView::BrowserNonClientFrameView(BrowserFrame* frame,
16 BrowserView* browser_view) 18 BrowserView* browser_view)
17 : frame_(frame), 19 : frame_(frame),
18 browser_view_(browser_view) { 20 browser_view_(browser_view) {
19 } 21 }
20 22
21 BrowserNonClientFrameView::~BrowserNonClientFrameView() { 23 BrowserNonClientFrameView::~BrowserNonClientFrameView() {
22 } 24 }
23 25
24 void BrowserNonClientFrameView::UpdateAvatarInfo() { 26 void BrowserNonClientFrameView::UpdateAvatarInfo() {
25 if (browser_view_->ShouldShowAvatar()) { 27 if (browser_view_->ShouldShowAvatar()) {
26 if (!avatar_button_.get()) { 28 if (!avatar_button_.get()) {
27 avatar_button_.reset(new AvatarMenuButton( 29 avatar_button_.reset(
28 browser_view_->browser(), !browser_view_->IsOffTheRecord())); 30 new AvatarMenuButton(browser_view_->browser(),
31 browser_view_->IsOffTheRecord()));
29 AddChildView(avatar_button_.get()); 32 AddChildView(avatar_button_.get());
30 frame_->GetRootView()->Layout(); 33 frame_->GetRootView()->Layout();
31 } 34 }
32 } else if (avatar_button_.get()) { 35 } else if (avatar_button_.get()) {
33 RemoveChildView(avatar_button_.get()); 36 RemoveChildView(avatar_button_.get());
34 avatar_button_.reset(); 37 avatar_button_.reset();
35 frame_->GetRootView()->Layout(); 38 frame_->GetRootView()->Layout();
36 } 39 }
37 40
41 gfx::Image avatar;
sky 2012/04/25 17:12:26 Is there some place else this code could exist? It
Bernhard Bauer 2012/04/25 17:57:30 I'm not sure I follow. Where would you suggest to
sky 2012/04/25 19:44:33 It felt like this code isn't really specific to wh
42 string16 text;
43 bool is_gaia_picture = false;
44 if (browser_view_->IsGuestSession()) {
45 avatar = gfx::Image(browser_view_->GetGuestAvatarIcon());
46 } else if (browser_view_->IsOffTheRecord()) {
47 avatar = gfx::Image(browser_view_->GetOTRAvatarIcon());
48 } else if (ManagedMode::IsInManagedMode()) {
49 avatar = gfx::Image(browser_view_->GetManagedModeAvatarIcon());
50 } else if (AvatarMenuModel::ShouldShowAvatarMenu()) {
51 ProfileInfoCache& cache =
52 g_browser_process->profile_manager()->GetProfileInfoCache();
53 Profile* profile = browser_view_->browser()->profile();
54 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath());
55 if (index == std::string::npos)
56 return;
57 is_gaia_picture =
58 cache.IsUsingGAIAPictureOfProfileAtIndex(index) &&
59 cache.GetGAIAPictureOfProfileAtIndex(index);
60 avatar = cache.GetAvatarIconOfProfileAtIndex(index);
61 text = cache.GetNameOfProfileAtIndex(index);
62 }
63 if (avatar_button_.get()) {
64 avatar_button_->SetAvatarIcon(avatar, is_gaia_picture);
65 if (!text.empty())
66 avatar_button_->SetText(text);
67 }
68
38 // For popups and panels which don't have the avatar button, we still 69 // For popups and panels which don't have the avatar button, we still
39 // need to draw the taskbar decoration. 70 // need to draw the taskbar decoration.
40 if (browser_view_->IsBrowserTypeNormal()) { 71 if (AvatarMenuModel::ShouldShowAvatarMenu() ||
41 if (!avatar_button_.get()) 72 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); 73 DrawTaskBarDecoration(frame_->GetNativeWindow(), &avatar);
55 } else { 74 } else {
56 ProfileInfoCache& cache = 75 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 } 76 }
72 } 77 }
73 78
74 void BrowserNonClientFrameView::VisibilityChanged(views::View* starting_from, 79 void BrowserNonClientFrameView::VisibilityChanged(views::View* starting_from,
75 bool is_visible) { 80 bool is_visible) {
76 if (!is_visible) 81 if (!is_visible)
77 return; 82 return;
78 // The first time UpdateAvatarInfo() is called the window is not visible so 83 // The first time UpdateAvatarInfo() is called the window is not visible so
79 // DrawTaskBarDecoration() has no effect. Therefore we need to call it again 84 // DrawTaskBarDecoration() has no effect. Therefore we need to call it again
80 // once the window is visible. 85 // once the window is visible.
81 UpdateAvatarInfo(); 86 UpdateAvatarInfo();
82 } 87 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698