summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/views
diff options
context:
space:
mode:
authorbauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-27 18:27:14 +0000
committerbauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-27 18:27:14 +0000
commit623294c447e00b7485092cdf68d50874a9f0646e (patch)
tree53135e482180a848d3ab9b0a3643407f63c5b9cc /chrome/browser/ui/views
parent61b4efcd2a24ed3862775093626247ebddc3f5f0 (diff)
downloadchromium_src-623294c447e00b7485092cdf68d50874a9f0646e.zip
chromium_src-623294c447e00b7485092cdf68d50874a9f0646e.tar.gz
chromium_src-623294c447e00b7485092cdf68d50874a9f0646e.tar.bz2
Add a button to exit managed mode in place of the profile avatar.
BUG=116060 TEST=none Review URL: http://codereview.chromium.org/9500003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@134308 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui/views')
-rw-r--r--chrome/browser/ui/views/avatar_menu_button.cc30
-rw-r--r--chrome/browser/ui/views/avatar_menu_button.h10
-rw-r--r--chrome/browser/ui/views/frame/browser_non_client_frame_view.cc72
-rw-r--r--chrome/browser/ui/views/frame/browser_view.cc29
-rw-r--r--chrome/browser/ui/views/frame/browser_view.h3
5 files changed, 75 insertions, 69 deletions
diff --git a/chrome/browser/ui/views/avatar_menu_button.cc b/chrome/browser/ui/views/avatar_menu_button.cc
index 6ef2401..532f795 100644
--- a/chrome/browser/ui/views/avatar_menu_button.cc
+++ b/chrome/browser/ui/views/avatar_menu_button.cc
@@ -4,12 +4,20 @@
#include "chrome/browser/ui/views/avatar_menu_button.h"
+#include "chrome/app/chrome_command_ids.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/command_updater.h"
+#include "chrome/browser/managed_mode.h"
+#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/avatar_menu_model.h"
#include "chrome/browser/profiles/profile_info_util.h"
#include "chrome/browser/profiles/profile_metrics.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/views/avatar_menu_bubble_view.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
+#include "chrome/common/chrome_notification_types.h"
+#include "chrome/common/pref_names.h"
+#include "content/public/browser/notification_service.h"
#include "ui/gfx/canvas.h"
#include "ui/views/widget/widget.h"
@@ -36,10 +44,7 @@ void DrawTaskBarDecoration(gfx::NativeWindow window, const gfx::Image* image) {
#if defined(OS_WIN) && !defined(USE_AURA)
if (base::win::GetVersion() < base::win::VERSION_WIN7)
return;
- // Don't badge the task bar in the single profile case to match the behavior
- // of the title bar.
- if (!AvatarMenuModel::ShouldShowAvatarMenu())
- return;
+
// SetOverlayIcon does nothing if the window is not visible so testing
// here avoids all the wasted effort of the image resizing.
if (!::IsWindowVisible(window))
@@ -83,10 +88,10 @@ void DrawTaskBarDecoration(gfx::NativeWindow window, const gfx::Image* image) {
#endif
}
-AvatarMenuButton::AvatarMenuButton(Browser* browser, bool has_menu)
+AvatarMenuButton::AvatarMenuButton(Browser* browser, bool incognito)
: MenuButton(NULL, string16(), this, false),
browser_(browser),
- has_menu_(has_menu),
+ incognito_(incognito),
is_gaia_picture_(false),
old_height_(0) {
// In RTL mode, the avatar icon should be looking the opposite direction.
@@ -128,7 +133,7 @@ void AvatarMenuButton::OnPaint(gfx::Canvas* canvas) {
}
bool AvatarMenuButton::HitTest(const gfx::Point& point) const {
- if (!has_menu_)
+ if (incognito_)
return false;
return views::MenuButton::HitTest(point);
}
@@ -144,12 +149,17 @@ void AvatarMenuButton::SetAvatarIcon(const gfx::Image& icon,
// views::MenuButtonListener implementation
void AvatarMenuButton::OnMenuButtonClicked(views::View* source,
const gfx::Point& point) {
- ShowAvatarBubble();
+ if (incognito_)
+ return;
+
+ if (ManagedMode::IsInManagedMode())
+ ManagedMode::LeaveManagedMode();
+ else
+ ShowAvatarBubble();
}
void AvatarMenuButton::ShowAvatarBubble() {
- if (!has_menu_)
- return;
+ DCHECK(browser_->command_updater()->IsCommandEnabled(IDC_SHOW_AVATAR_MENU));
gfx::Point origin;
views::View::ConvertPointToScreen(this, &origin);
diff --git a/chrome/browser/ui/views/avatar_menu_button.h b/chrome/browser/ui/views/avatar_menu_button.h
index 6edc79a..dbd8ffe 100644
--- a/chrome/browser/ui/views/avatar_menu_button.h
+++ b/chrome/browser/ui/views/avatar_menu_button.h
@@ -32,9 +32,9 @@ void DrawTaskBarDecoration(gfx::NativeWindow window, const gfx::Image* image);
class AvatarMenuButton : public views::MenuButton,
public views::MenuButtonListener {
public:
- // Creates a new button. If |has_menu| is true then clicking on the button
- // will cause the profile menu to be displayed.
- AvatarMenuButton(Browser* browser, bool has_menu);
+ // Creates a new button. If |incognito| is true and we're not in managed mode,
+ // clicking on the button will cause the profile menu to be displayed.
+ AvatarMenuButton(Browser* browser, bool incognito);
virtual ~AvatarMenuButton();
@@ -52,8 +52,10 @@ class AvatarMenuButton : public views::MenuButton,
virtual void OnMenuButtonClicked(views::View* source,
const gfx::Point& point) OVERRIDE;
+ void ButtonClicked();
+
Browser* browser_;
- bool has_menu_;
+ bool incognito_;
scoped_ptr<ui::MenuModel> menu_model_;
// Use a scoped ptr because gfx::Image doesn't have a default constructor.
diff --git a/chrome/browser/ui/views/frame/browser_non_client_frame_view.cc b/chrome/browser/ui/views/frame/browser_non_client_frame_view.cc
index bc52d45..2942426 100644
--- a/chrome/browser/ui/views/frame/browser_non_client_frame_view.cc
+++ b/chrome/browser/ui/views/frame/browser_non_client_frame_view.cc
@@ -1,15 +1,19 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/frame/browser_non_client_frame_view.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/managed_mode.h"
+#include "chrome/browser/profiles/avatar_menu_model.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_info_cache.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/views/avatar_menu_button.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
+#include "grit/theme_resources.h"
+#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/image/image.h"
BrowserNonClientFrameView::BrowserNonClientFrameView(BrowserFrame* frame,
@@ -24,8 +28,9 @@ BrowserNonClientFrameView::~BrowserNonClientFrameView() {
void BrowserNonClientFrameView::UpdateAvatarInfo() {
if (browser_view_->ShouldShowAvatar()) {
if (!avatar_button_.get()) {
- avatar_button_.reset(new AvatarMenuButton(
- browser_view_->browser(), !browser_view_->IsOffTheRecord()));
+ avatar_button_.reset(
+ new AvatarMenuButton(browser_view_->browser(),
+ browser_view_->IsOffTheRecord()));
AddChildView(avatar_button_.get());
frame_->GetRootView()->Layout();
}
@@ -35,39 +40,46 @@ void BrowserNonClientFrameView::UpdateAvatarInfo() {
frame_->GetRootView()->Layout();
}
- // For popups and panels which don't have the avatar button, we still
- // need to draw the taskbar decoration.
- if (browser_view_->IsBrowserTypeNormal()) {
- if (!avatar_button_.get())
- return;
- }
-
+ ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
+ gfx::Image avatar;
+ string16 text;
+ bool is_gaia_picture = false;
if (browser_view_->IsGuestSession()) {
- const gfx::Image avatar(new SkBitmap(browser_view_->GetGuestAvatarIcon()));
- if (avatar_button_.get())
- avatar_button_->SetAvatarIcon(avatar, false);
- DrawTaskBarDecoration(frame_->GetNativeWindow(), &avatar);
+#if defined(OS_CHROMEOS)
+ avatar = rb.GetImageNamed(IDR_GUEST_ICON);
+#else
+ NOTREACHED();
+#endif
} else if (browser_view_->IsOffTheRecord()) {
- const gfx::Image avatar(new SkBitmap(browser_view_->GetOTRAvatarIcon()));
- if (avatar_button_.get())
- avatar_button_->SetAvatarIcon(avatar, false);
- DrawTaskBarDecoration(frame_->GetNativeWindow(), &avatar);
- } else {
+ avatar = rb.GetImageNamed(IDR_OTR_ICON);
+ } else if (ManagedMode::IsInManagedMode()) {
+ avatar = rb.GetImageNamed(IDR_MANAGED_MODE_AVATAR);
+ } else if (AvatarMenuModel::ShouldShowAvatarMenu()) {
ProfileInfoCache& cache =
g_browser_process->profile_manager()->GetProfileInfoCache();
Profile* profile = browser_view_->browser()->profile();
size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath());
- if (index != std::string::npos) {
- bool is_gaia_picture =
- cache.IsUsingGAIAPictureOfProfileAtIndex(index) &&
- cache.GetGAIAPictureOfProfileAtIndex(index);
- const gfx::Image& avatar = cache.GetAvatarIconOfProfileAtIndex(index);
- if (avatar_button_.get()) {
- avatar_button_->SetAvatarIcon(avatar, is_gaia_picture);
- avatar_button_->SetText(cache.GetNameOfProfileAtIndex(index));
- }
- DrawTaskBarDecoration(frame_->GetNativeWindow(), &avatar);
- }
+ if (index == std::string::npos)
+ return;
+ is_gaia_picture =
+ cache.IsUsingGAIAPictureOfProfileAtIndex(index) &&
+ cache.GetGAIAPictureOfProfileAtIndex(index);
+ avatar = cache.GetAvatarIconOfProfileAtIndex(index);
+ text = cache.GetNameOfProfileAtIndex(index);
+ }
+ if (avatar_button_.get()) {
+ avatar_button_->SetAvatarIcon(avatar, is_gaia_picture);
+ if (!text.empty())
+ avatar_button_->SetText(text);
+ }
+
+ // For popups and panels which don't have the avatar button, we still
+ // need to draw the taskbar decoration.
+ if (AvatarMenuModel::ShouldShowAvatarMenu() ||
+ ManagedMode::IsInManagedMode()) {
+ DrawTaskBarDecoration(frame_->GetNativeWindow(), &avatar);
+ } else {
+ DrawTaskBarDecoration(frame_->GetNativeWindow(), NULL);
}
}
diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc
index 16cda18..5bbca22 100644
--- a/chrome/browser/ui/views/frame/browser_view.cc
+++ b/chrome/browser/ui/views/frame/browser_view.cc
@@ -24,6 +24,7 @@
#include "chrome/browser/instant/instant_controller.h"
#include "chrome/browser/native_window_notification_source.h"
#include "chrome/browser/ntp_background_util.h"
+#include "chrome/browser/managed_mode.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/avatar_menu_model.h"
#include "chrome/browser/profiles/profile.h"
@@ -467,6 +468,8 @@ bool BrowserView::ShouldShowAvatar() const {
return false;
if (IsOffTheRecord())
return true;
+ if (ManagedMode::IsInManagedMode())
+ return true;
ProfileInfoCache& cache =
g_browser_process->profile_manager()->GetProfileInfoCache();
@@ -549,28 +552,10 @@ TabContentsWrapper* BrowserView::GetSelectedTabContentsWrapper() const {
}
SkBitmap BrowserView::GetOTRAvatarIcon() const {
- static SkBitmap* otr_avatar_ = new SkBitmap();
-
- if (otr_avatar_->isNull()) {
- ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
- *otr_avatar_ = *rb.GetBitmapNamed(IDR_OTR_ICON);
- }
- return *otr_avatar_;
-}
-
-SkBitmap BrowserView::GetGuestAvatarIcon() const {
-#if defined(OS_CHROMEOS)
- static SkBitmap* guest_avatar_ = new SkBitmap();
-
- if (guest_avatar_->isNull()) {
- ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
- *guest_avatar_ = *rb.GetBitmapNamed(IDR_GUEST_ICON);
- }
- return *guest_avatar_;
-#else
- NOTREACHED();
- return SkBitmap();
-#endif
+ ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
+ const SkBitmap* otr_avatar =
+ rb.GetNativeImageNamed(IDR_OTR_ICON).ToSkBitmap();
+ return *otr_avatar;
}
// static
diff --git a/chrome/browser/ui/views/frame/browser_view.h b/chrome/browser/ui/views/frame/browser_view.h
index a8b574a..e634c89 100644
--- a/chrome/browser/ui/views/frame/browser_view.h
+++ b/chrome/browser/ui/views/frame/browser_view.h
@@ -182,9 +182,6 @@ class BrowserView : public BrowserWindow,
// Retrieves the icon to use in the frame to indicate an OTR window.
SkBitmap GetOTRAvatarIcon() const;
- // Retrieves the icon to use in the frame to indicate guest session.
- SkBitmap GetGuestAvatarIcon() const;
-
// Returns true if the Browser object associated with this BrowserView is a
// tabbed-type window (i.e. a browser window, not an app or popup).
bool IsBrowserTypeNormal() const {