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

Unified Diff: chrome/browser/ui/cocoa/browser/avatar_button_controller.mm

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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/browser/avatar_button_controller.mm
diff --git a/chrome/browser/ui/cocoa/browser/avatar_button_controller.mm b/chrome/browser/ui/cocoa/browser/avatar_button_controller.mm
index 18ff3f15ef6ec70b4995f3e33e3dd7dbfe70756c..0ff25755137efa13398be54f14132320430d1314 100644
--- a/chrome/browser/ui/cocoa/browser/avatar_button_controller.mm
+++ b/chrome/browser/ui/cocoa/browser/avatar_button_controller.mm
@@ -6,6 +6,7 @@
#include "base/sys_string_conversions.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/managed_mode.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_info_cache.h"
#include "chrome/browser/profiles/profile_info_util.h"
@@ -28,7 +29,7 @@
#include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
@interface AvatarButtonController (Private)
-- (void)setOpenMenuOnClick:(BOOL)flag;
+- (void)setButtonEnabled:(BOOL)flag;
- (IBAction)buttonClicked:(id)sender;
- (void)bubbleWillClose:(NSNotification*)notif;
- (NSImage*)compositeImageWithShadow:(NSImage*)image;
@@ -46,9 +47,9 @@ class Observer : public content::NotificationObserver {
}
// NotificationObserver:
- void Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) OVERRIDE {
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE {
switch (type) {
case chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED:
[button_ updateAvatar];
@@ -125,10 +126,10 @@ const CGFloat kMenuYOffsetAdjust = 1.0;
if (browser_->profile()->IsOffTheRecord()) {
[self setImage:[self compositeImageWithShadow:
gfx::GetCachedImageWithName(@"otr_icon.pdf")]];
- [self setOpenMenuOnClick:NO];
+ [self setButtonEnabled:NO];
} else {
+ [self setButtonEnabled:YES];
observer_.reset(new AvatarButtonControllerInternal::Observer(self));
- [self setOpenMenuOnClick:YES];
[self updateAvatar];
}
}
@@ -183,13 +184,18 @@ const CGFloat kMenuYOffsetAdjust = 1.0;
// Private /////////////////////////////////////////////////////////////////////
-- (void)setOpenMenuOnClick:(BOOL)flag {
+- (void)setButtonEnabled:(BOOL)flag {
[self.buttonView setEnabled:flag];
}
- (IBAction)buttonClicked:(id)sender {
DCHECK_EQ(self.buttonView, sender);
- [self showAvatarBubble];
+ if (ManagedMode::IsInManagedMode()) {
+ ManagedMode::LeaveManagedMode();
+ } else {
+ DCHECK(!browser_->profile()->IsOffTheRecord());
+ [self showAvatarBubble];
+ }
}
- (void)bubbleWillClose:(NSNotification*)notif {
@@ -234,26 +240,33 @@ const CGFloat kMenuYOffsetAdjust = 1.0;
// Updates the avatar information from the profile cache.
- (void)updateAvatar {
+ if (ManagedMode::IsInManagedMode()) {
+ gfx::Image icon =
+ ResourceBundle::GetSharedInstance().GetNativeImageNamed(
+ IDR_MANAGED_MODE_AVATAR);
+ [self setImage:icon.ToNSImage()];
+ return;
+ }
ProfileInfoCache& cache =
g_browser_process->profile_manager()->GetProfileInfoCache();
size_t index =
cache.GetIndexOfProfileWithPath(browser_->profile()->GetPath());
- if (index != std::string::npos) {
- BOOL is_gaia_picture =
- cache.IsUsingGAIAPictureOfProfileAtIndex(index) &&
- cache.GetGAIAPictureOfProfileAtIndex(index);
- gfx::Image icon = profiles::GetAvatarIconForTitleBar(
- cache.GetAvatarIconOfProfileAtIndex(index), is_gaia_picture,
- profiles::kAvatarIconWidth, profiles::kAvatarIconHeight);
- [self setImage:icon.ToNSImage()];
-
- const string16& name = cache.GetNameOfProfileAtIndex(index);
- NSString* nsName = base::SysUTF16ToNSString(name);
- [self.view setToolTip:nsName];
- [[self.buttonView cell]
- accessibilitySetOverrideValue:nsName
- forAttribute:NSAccessibilityValueAttribute];
- }
+ if (index == std::string::npos)
+ return;
+ BOOL is_gaia_picture =
+ cache.IsUsingGAIAPictureOfProfileAtIndex(index) &&
+ cache.GetGAIAPictureOfProfileAtIndex(index);
+ gfx::Image icon = profiles::GetAvatarIconForTitleBar(
+ cache.GetAvatarIconOfProfileAtIndex(index), is_gaia_picture,
+ profiles::kAvatarIconWidth, profiles::kAvatarIconHeight);
+ [self setImage:icon.ToNSImage()];
+
+ const string16& name = cache.GetNameOfProfileAtIndex(index);
+ NSString* nsName = base::SysUTF16ToNSString(name);
+ [self.view setToolTip:nsName];
+ [[self.buttonView cell]
+ accessibilitySetOverrideValue:nsName
+ forAttribute:NSAccessibilityValueAttribute];
}
// If the second-to-last profile was removed or a second profile was added,

Powered by Google App Engine
This is Rietveld 408576698