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

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: review 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"
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 gfx::Image avatar;
44 string16 text;
45 bool is_gaia_picture = false;
46 if (browser_view_->IsGuestSession()) {
47 #if defined(OS_CHROMEOS)
48 avatar = rb.GetImageNamed(IDR_GUEST_ICON);
49 #else
50 NOTREACHED();
51 #endif
52 } else if (browser_view_->IsOffTheRecord()) {
53 avatar = rb.GetImageNamed(IDR_OTR_ICON);
54 } else if (ManagedMode::IsInManagedMode()) {
55 avatar = rb.GetImageNamed(IDR_MANAGED_MODE_AVATAR);
56 } else if (AvatarMenuModel::ShouldShowAvatarMenu()) {
57 ProfileInfoCache& cache =
58 g_browser_process->profile_manager()->GetProfileInfoCache();
59 Profile* profile = browser_view_->browser()->profile();
60 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath());
61 if (index == std::string::npos)
62 return;
63 is_gaia_picture =
64 cache.IsUsingGAIAPictureOfProfileAtIndex(index) &&
65 cache.GetGAIAPictureOfProfileAtIndex(index);
66 avatar = cache.GetAvatarIconOfProfileAtIndex(index);
67 text = cache.GetNameOfProfileAtIndex(index);
68 }
69 if (avatar_button_.get()) {
70 avatar_button_->SetAvatarIcon(avatar, is_gaia_picture);
71 if (!text.empty())
72 avatar_button_->SetText(text);
73 }
74
38 // For popups and panels which don't have the avatar button, we still 75 // For popups and panels which don't have the avatar button, we still
39 // need to draw the taskbar decoration. 76 // need to draw the taskbar decoration.
40 if (browser_view_->IsBrowserTypeNormal()) { 77 if (AvatarMenuModel::ShouldShowAvatarMenu() ||
41 if (!avatar_button_.get()) 78 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); 79 DrawTaskBarDecoration(frame_->GetNativeWindow(), &avatar);
55 } else { 80 } else {
56 ProfileInfoCache& cache = 81 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 } 82 }
72 } 83 }
73 84
74 void BrowserNonClientFrameView::VisibilityChanged(views::View* starting_from, 85 void BrowserNonClientFrameView::VisibilityChanged(views::View* starting_from,
75 bool is_visible) { 86 bool is_visible) {
76 if (!is_visible) 87 if (!is_visible)
77 return; 88 return;
78 // The first time UpdateAvatarInfo() is called the window is not visible so 89 // The first time UpdateAvatarInfo() is called the window is not visible so
79 // DrawTaskBarDecoration() has no effect. Therefore we need to call it again 90 // DrawTaskBarDecoration() has no effect. Therefore we need to call it again
80 // once the window is visible. 91 // once the window is visible.
81 UpdateAvatarInfo(); 92 UpdateAvatarInfo();
82 } 93 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698