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

Side by Side Diff: chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm

Issue 1094103005: Profile chooser on mac was passing wrong value to signin error controller. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 5 years, 7 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #import <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 #import <Carbon/Carbon.h> // kVK_Return. 6 #import <Carbon/Carbon.h> // kVK_Return.
7 7
8 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" 8 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h"
9 9
10 #include "base/mac/bundle_locations.h" 10 #include "base/mac/bundle_locations.h"
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "base/strings/sys_string_conversions.h" 13 #include "base/strings/sys_string_conversions.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "chrome/app/chrome_command_ids.h" 15 #include "chrome/app/chrome_command_ids.h"
16 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/chrome_notification_types.h" 17 #include "chrome/browser/chrome_notification_types.h"
18 #include "chrome/browser/lifetime/application_lifetime.h" 18 #include "chrome/browser/lifetime/application_lifetime.h"
19 #include "chrome/browser/prefs/incognito_mode_prefs.h" 19 #include "chrome/browser/prefs/incognito_mode_prefs.h"
20 #include "chrome/browser/profiles/avatar_menu.h" 20 #include "chrome/browser/profiles/avatar_menu.h"
21 #include "chrome/browser/profiles/avatar_menu_observer.h" 21 #include "chrome/browser/profiles/avatar_menu_observer.h"
22 #include "chrome/browser/profiles/profile_avatar_icon_util.h" 22 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
23 #include "chrome/browser/profiles/profile_info_cache.h" 23 #include "chrome/browser/profiles/profile_info_cache.h"
24 #include "chrome/browser/profiles/profile_manager.h" 24 #include "chrome/browser/profiles/profile_manager.h"
25 #include "chrome/browser/profiles/profile_metrics.h" 25 #include "chrome/browser/profiles/profile_metrics.h"
26 #include "chrome/browser/profiles/profile_window.h" 26 #include "chrome/browser/profiles/profile_window.h"
27 #include "chrome/browser/profiles/profiles_state.h" 27 #include "chrome/browser/profiles/profiles_state.h"
28 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 28 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
29 #include "chrome/browser/signin/signin_error_controller_factory.h"
29 #include "chrome/browser/signin/signin_header_helper.h" 30 #include "chrome/browser/signin/signin_header_helper.h"
30 #include "chrome/browser/signin/signin_manager_factory.h" 31 #include "chrome/browser/signin/signin_manager_factory.h"
31 #include "chrome/browser/signin/signin_promo.h" 32 #include "chrome/browser/signin/signin_promo.h"
32 #include "chrome/browser/signin/signin_ui_util.h" 33 #include "chrome/browser/signin/signin_ui_util.h"
33 #include "chrome/browser/ui/browser.h" 34 #include "chrome/browser/ui/browser.h"
34 #include "chrome/browser/ui/browser_commands.h" 35 #include "chrome/browser/ui/browser_commands.h"
35 #include "chrome/browser/ui/browser_window.h" 36 #include "chrome/browser/ui/browser_window.h"
36 #include "chrome/browser/ui/chrome_pages.h" 37 #include "chrome/browser/ui/chrome_pages.h"
37 #include "chrome/browser/ui/chrome_style.h" 38 #include "chrome/browser/ui/chrome_style.h"
38 #import "chrome/browser/ui/cocoa/browser_window_utils.h" 39 #import "chrome/browser/ui/cocoa/browser_window_utils.h"
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 [container addSubview:title_label]; 241 [container addSubview:title_label];
241 CGFloat height = std::max(NSMaxY([title_label frame]), 242 CGFloat height = std::max(NSMaxY([title_label frame]),
242 NSMaxY([button frame])) + kVerticalSpacing; 243 NSMaxY([button frame])) + kVerticalSpacing;
243 [container setFrameSize:NSMakeSize(NSWidth([container frame]), height)]; 244 [container setFrameSize:NSMakeSize(NSWidth([container frame]), height)];
244 245
245 return container.autorelease(); 246 return container.autorelease();
246 } 247 }
247 248
248 bool HasAuthError(Profile* profile) { 249 bool HasAuthError(Profile* profile) {
249 const SigninErrorController* error_controller = 250 const SigninErrorController* error_controller =
250 profiles::GetSigninErrorController(profile); 251 SigninErrorControllerFactory::GetForProfile(profile);
251 return error_controller && error_controller->HasError(); 252 return error_controller && error_controller->HasError();
252 } 253 }
253 254
255 std::string GetAuthErrorAccountId(Profile* profile) {
256 const SigninErrorController* error_controller =
257 SigninErrorControllerFactory::GetForProfile(profile);
258 if (!error_controller)
259 return std::string();
260
261 return error_controller->error_account_id();
262 }
263
254 } // namespace 264 } // namespace
255 265
256 // Custom WebContentsDelegate that allows handling of hotkeys and suppresses 266 // Custom WebContentsDelegate that allows handling of hotkeys and suppresses
257 // the context menu. 267 // the context menu.
258 class GaiaWebContentsDelegate : public content::WebContentsDelegate { 268 class GaiaWebContentsDelegate : public content::WebContentsDelegate {
259 public: 269 public:
260 GaiaWebContentsDelegate() {} 270 GaiaWebContentsDelegate() {}
261 ~GaiaWebContentsDelegate() override {} 271 ~GaiaWebContentsDelegate() override {}
262 272
263 private: 273 private:
(...skipping 1671 matching lines...) Expand 10 before | Expand all | Expand 10 after
1935 1945
1936 Profile* profile = browser_->profile(); 1946 Profile* profile = browser_->profile();
1937 std::string primaryAccount = 1947 std::string primaryAccount =
1938 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedAccountId(); 1948 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedAccountId();
1939 DCHECK(!primaryAccount.empty()); 1949 DCHECK(!primaryAccount.empty());
1940 std::vector<std::string>accounts = 1950 std::vector<std::string>accounts =
1941 profiles::GetSecondaryAccountsForProfile(profile, primaryAccount); 1951 profiles::GetSecondaryAccountsForProfile(profile, primaryAccount);
1942 1952
1943 // If there is an account with an authentication error, it needs to be 1953 // If there is an account with an authentication error, it needs to be
1944 // badged with a warning icon. 1954 // badged with a warning icon.
1945 const SigninErrorController* errorController = 1955 std::string errorAccountId = GetAuthErrorAccountId(profile);
1946 profiles::GetSigninErrorController(profile);
1947 std::string errorAccountId =
1948 errorController ? errorController->error_account_id() : std::string();
1949 1956
1950 rect.origin.y = 0; 1957 rect.origin.y = 0;
1951 for (size_t i = 0; i < accounts.size(); ++i) { 1958 for (size_t i = 0; i < accounts.size(); ++i) {
1952 // Save the original email address, as the button text could be elided. 1959 // Save the original email address, as the button text could be elided.
1953 currentProfileAccounts_[i] = accounts[i]; 1960 currentProfileAccounts_[i] = accounts[i];
1954 NSButton* accountButton = 1961 NSButton* accountButton =
1955 [self accountButtonWithRect:rect 1962 [self accountButtonWithRect:rect
1956 accountId:accounts[i] 1963 accountId:accounts[i]
1957 tag:i 1964 tag:i
1958 reauthRequired:errorAccountId == accounts[i]]; 1965 reauthRequired:errorAccountId == accounts[i]];
(...skipping 13 matching lines...) Expand all
1972 return container.autorelease(); 1979 return container.autorelease();
1973 } 1980 }
1974 1981
1975 - (NSView*)buildGaiaEmbeddedView { 1982 - (NSView*)buildGaiaEmbeddedView {
1976 base::scoped_nsobject<NSView> container( 1983 base::scoped_nsobject<NSView> container(
1977 [[NSView alloc] initWithFrame:NSZeroRect]); 1984 [[NSView alloc] initWithFrame:NSZeroRect]);
1978 CGFloat yOffset = 0; 1985 CGFloat yOffset = 0;
1979 1986
1980 GURL url; 1987 GURL url;
1981 int messageId = -1; 1988 int messageId = -1;
1982 SigninErrorController* errorController = NULL;
1983 switch (viewMode_) { 1989 switch (viewMode_) {
1984 case profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN: 1990 case profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN:
1985 url = signin::GetPromoURL(signin_metrics::SOURCE_AVATAR_BUBBLE_SIGN_IN, 1991 url = signin::GetPromoURL(signin_metrics::SOURCE_AVATAR_BUBBLE_SIGN_IN,
1986 false /* auto_close */, 1992 false /* auto_close */,
1987 true /* is_constrained */); 1993 true /* is_constrained */);
1988 messageId = IDS_PROFILES_GAIA_SIGNIN_TITLE; 1994 messageId = IDS_PROFILES_GAIA_SIGNIN_TITLE;
1989 break; 1995 break;
1990 case profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT: 1996 case profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT:
1991 url = signin::GetPromoURL( 1997 url = signin::GetPromoURL(
1992 signin_metrics::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT, 1998 signin_metrics::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT,
1993 false /* auto_close */, 1999 false /* auto_close */,
1994 true /* is_constrained */); 2000 true /* is_constrained */);
1995 messageId = IDS_PROFILES_GAIA_ADD_ACCOUNT_TITLE; 2001 messageId = IDS_PROFILES_GAIA_ADD_ACCOUNT_TITLE;
1996 break; 2002 break;
1997 case profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH: 2003 case profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH:
1998 DCHECK(HasAuthError(browser_->profile())); 2004 DCHECK(HasAuthError(browser_->profile()));
1999 errorController = profiles::GetSigninErrorController(browser_->profile());
2000 url = signin::GetReauthURL( 2005 url = signin::GetReauthURL(
2001 browser_->profile(), 2006 browser_->profile(), GetAuthErrorAccountId(browser_->profile()));
2002 errorController ? errorController->error_username() : std::string());
2003 messageId = IDS_PROFILES_GAIA_REAUTH_TITLE; 2007 messageId = IDS_PROFILES_GAIA_REAUTH_TITLE;
2004 break; 2008 break;
2005 default: 2009 default:
2006 NOTREACHED() << "Called with invalid mode=" << viewMode_; 2010 NOTREACHED() << "Called with invalid mode=" << viewMode_;
2007 break; 2011 break;
2008 } 2012 }
2009 2013
2010 webContents_.reset(content::WebContents::Create( 2014 webContents_.reset(content::WebContents::Create(
2011 content::WebContents::CreateParams(browser_->profile()))); 2015 content::WebContents::CreateParams(browser_->profile())));
2012 2016
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
2311 } 2315 }
2312 2316
2313 - (bool)shouldShowGoIncognito { 2317 - (bool)shouldShowGoIncognito {
2314 bool incognitoAvailable = 2318 bool incognitoAvailable =
2315 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != 2319 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) !=
2316 IncognitoModePrefs::DISABLED; 2320 IncognitoModePrefs::DISABLED;
2317 return incognitoAvailable && !browser_->profile()->IsGuestSession(); 2321 return incognitoAvailable && !browser_->profile()->IsGuestSession();
2318 } 2322 }
2319 2323
2320 @end 2324 @end
OLDNEW
« no previous file with comments | « chrome/browser/sync/sync_ui_util_unittest.cc ('k') | chrome/browser/ui/views/profiles/profile_chooser_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698