Commit 8f75871b authored by treib@chromium.org's avatar treib@chromium.org

New avatar menu: Don't show "Go incognito" if incognito is disabled by policy

BUG=400094

Review URL: https://codereview.chromium.org/422443008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287543 0039d316-1c4b-4281-b951-d872f2087c98
parent eba66a19
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/lifetime/application_lifetime.h" #include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/prefs/incognito_mode_prefs.h"
#include "chrome/browser/profiles/avatar_menu.h" #include "chrome/browser/profiles/avatar_menu.h"
#include "chrome/browser/profiles/avatar_menu_observer.h" #include "chrome/browser/profiles/avatar_menu_observer.h"
#include "chrome/browser/profiles/profile_avatar_icon_util.h" #include "chrome/browser/profiles/profile_avatar_icon_util.h"
...@@ -775,6 +776,8 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, ...@@ -775,6 +776,8 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver,
title:(const std::string&)title title:(const std::string&)title
tag:(int)tag tag:(int)tag
reauthRequired:(BOOL)reauthRequired; reauthRequired:(BOOL)reauthRequired;
- (bool)shouldShowGoIncognito;
@end @end
@implementation ProfileChooserController @implementation ProfileChooserController
...@@ -801,7 +804,7 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, ...@@ -801,7 +804,7 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver,
} }
- (IBAction)goIncognito:(id)sender { - (IBAction)goIncognito:(id)sender {
DCHECK(!browser_->profile()->IsGuestSession()); DCHECK([self shouldShowGoIncognito]);
chrome::NewIncognitoWindow(browser_); chrome::NewIncognitoWindow(browser_);
} }
...@@ -1521,7 +1524,7 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, ...@@ -1521,7 +1524,7 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver,
viewRect.origin.y = NSMaxY([separator frame]); viewRect.origin.y = NSMaxY([separator frame]);
} }
if (!isGuestSession_) { if ([self shouldShowGoIncognito]) {
// TODO(noms): Use the correct incognito icon when it's available. // TODO(noms): Use the correct incognito icon when it's available.
NSButton* goIncognitoButton = NSButton* goIncognitoButton =
[self hoverButtonWithRect:viewRect [self hoverButtonWithRect:viewRect
...@@ -1938,4 +1941,11 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, ...@@ -1938,4 +1941,11 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver,
serviceType_ = signin::GAIA_SERVICE_TYPE_NONE; serviceType_ = signin::GAIA_SERVICE_TYPE_NONE;
} }
- (bool)shouldShowGoIncognito {
bool incognitoAvailable =
IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) !=
IncognitoModePrefs::DISABLED;
return incognitoAvailable && !browser_->profile()->IsGuestSession();
}
@end @end
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/lifetime/application_lifetime.h" #include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/prefs/incognito_mode_prefs.h"
#include "chrome/browser/profiles/profile_avatar_icon_util.h" #include "chrome/browser/profiles/profile_avatar_icon_util.h"
#include "chrome/browser/profiles/profile_info_cache.h" #include "chrome/browser/profiles/profile_info_cache.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
...@@ -661,7 +662,7 @@ void ProfileChooserView::ButtonPressed(views::Button* sender, ...@@ -661,7 +662,7 @@ void ProfileChooserView::ButtonPressed(views::Button* sender,
if (browser_->profile()->IsGuestSession()) if (browser_->profile()->IsGuestSession())
profiles::CloseGuestProfileWindows(); profiles::CloseGuestProfileWindows();
} else if (sender == go_incognito_button_) { } else if (sender == go_incognito_button_) {
DCHECK(!browser_->profile()->IsGuestSession()); DCHECK(ShouldShowGoIncognito());
chrome::NewIncognitoWindow(browser_); chrome::NewIncognitoWindow(browser_);
} else if (sender == lock_button_) { } else if (sender == lock_button_) {
profiles::LockProfile(browser_->profile()); profiles::LockProfile(browser_->profile());
...@@ -825,12 +826,6 @@ bool ProfileChooserView::HandleKeyEvent(views::Textfield* sender, ...@@ -825,12 +826,6 @@ bool ProfileChooserView::HandleKeyEvent(views::Textfield* sender,
return false; return false;
} }
void ProfileChooserView::PostActionPerformed(
ProfileMetrics::ProfileDesktopMenu action_performed) {
ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_);
gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE;
}
views::View* ProfileChooserView::CreateProfileChooserView( views::View* ProfileChooserView::CreateProfileChooserView(
AvatarMenu* avatar_menu, AvatarMenu* avatar_menu,
profiles::TutorialMode last_tutorial_mode) { profiles::TutorialMode last_tutorial_mode) {
...@@ -1242,7 +1237,7 @@ views::View* ProfileChooserView::CreateOptionsView(bool enable_lock) { ...@@ -1242,7 +1237,7 @@ views::View* ProfileChooserView::CreateOptionsView(bool enable_lock) {
layout->StartRow(1, 0); layout->StartRow(1, 0);
layout->AddView(users_button_); layout->AddView(users_button_);
if (!browser_->profile()->IsGuestSession()) { if (ShouldShowGoIncognito()) {
layout->StartRow(1, 0); layout->StartRow(1, 0);
layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); layout->AddView(new views::Separator(views::Separator::HORIZONTAL));
...@@ -1533,3 +1528,16 @@ views::View* ProfileChooserView::CreateEndPreviewView() { ...@@ -1533,3 +1528,16 @@ views::View* ProfileChooserView::CreateEndPreviewView() {
return TitleCard::AddPaddedTitleCard( return TitleCard::AddPaddedTitleCard(
view, title_card, kFixedAccountRemovalViewWidth); view, title_card, kFixedAccountRemovalViewWidth);
} }
bool ProfileChooserView::ShouldShowGoIncognito() const {
bool incognito_available =
IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) !=
IncognitoModePrefs::DISABLED;
return incognito_available && !browser_->profile()->IsGuestSession();
}
void ProfileChooserView::PostActionPerformed(
ProfileMetrics::ProfileDesktopMenu action_performed) {
ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_);
gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE;
}
...@@ -183,6 +183,8 @@ class ProfileChooserView : public views::BubbleDelegateView, ...@@ -183,6 +183,8 @@ class ProfileChooserView : public views::BubbleDelegateView,
views::View* CreateEndPreviewView(); views::View* CreateEndPreviewView();
bool ShouldShowGoIncognito() const;
// Clean-up done after an action was performed in the ProfileChooser. // Clean-up done after an action was performed in the ProfileChooser.
void PostActionPerformed(ProfileMetrics::ProfileDesktopMenu action_performed); void PostActionPerformed(ProfileMetrics::ProfileDesktopMenu action_performed);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment