OLD | NEW |
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 | 6 |
7 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" | 7 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" |
8 | 8 |
9 #include "base/mac/bundle_locations.h" | 9 #include "base/mac/bundle_locations.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
855 // Creates a generic link button with |title| and an |action| positioned at | 855 // Creates a generic link button with |title| and an |action| positioned at |
856 // |frameOrigin|. | 856 // |frameOrigin|. |
857 - (NSButton*)linkButtonWithTitle:(NSString*)title | 857 - (NSButton*)linkButtonWithTitle:(NSString*)title |
858 frameOrigin:(NSPoint)frameOrigin | 858 frameOrigin:(NSPoint)frameOrigin |
859 action:(SEL)action; | 859 action:(SEL)action; |
860 | 860 |
861 // Creates an email account button with |title| and a remove icon. If | 861 // Creates an email account button with |title| and a remove icon. If |
862 // |reauthRequired| is true, the button also displays a warning icon. |tag| | 862 // |reauthRequired| is true, the button also displays a warning icon. |tag| |
863 // indicates which account the button refers to. | 863 // indicates which account the button refers to. |
864 - (NSButton*)accountButtonWithRect:(NSRect)rect | 864 - (NSButton*)accountButtonWithRect:(NSRect)rect |
865 title:(const std::string&)title | 865 accountId:(const std::string&)accountId |
866 tag:(int)tag | 866 tag:(int)tag |
867 reauthRequired:(BOOL)reauthRequired; | 867 reauthRequired:(BOOL)reauthRequired; |
868 | 868 |
869 - (bool)shouldShowGoIncognito; | 869 - (bool)shouldShowGoIncognito; |
870 @end | 870 @end |
871 | 871 |
872 @implementation ProfileChooserController | 872 @implementation ProfileChooserController |
873 - (profiles::BubbleViewMode) viewMode { | 873 - (profiles::BubbleViewMode) viewMode { |
874 return viewMode_; | 874 return viewMode_; |
875 } | 875 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
920 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN]; | 920 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN]; |
921 } | 921 } |
922 | 922 |
923 - (IBAction)addAccount:(id)sender { | 923 - (IBAction)addAccount:(id)sender { |
924 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT]; | 924 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT]; |
925 [self postActionPerformed:ProfileMetrics::PROFILE_DESKTOP_MENU_ADD_ACCT]; | 925 [self postActionPerformed:ProfileMetrics::PROFILE_DESKTOP_MENU_ADD_ACCT]; |
926 } | 926 } |
927 | 927 |
928 - (IBAction)navigateBackFromSigninPage:(id)sender { | 928 - (IBAction)navigateBackFromSigninPage:(id)sender { |
929 std::string primaryAccount = SigninManagerFactory::GetForProfile( | 929 std::string primaryAccount = SigninManagerFactory::GetForProfile( |
930 browser_->profile())->GetAuthenticatedUsername(); | 930 browser_->profile())->GetAuthenticatedAccountId(); |
931 bool hasAccountManagement = !primaryAccount.empty() && | 931 bool hasAccountManagement = !primaryAccount.empty() && |
932 switches::IsEnableAccountConsistency(); | 932 switches::IsEnableAccountConsistency(); |
933 [self initMenuContentsWithView:hasAccountManagement ? | 933 [self initMenuContentsWithView:hasAccountManagement ? |
934 profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT : | 934 profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT : |
935 profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER]; | 935 profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER]; |
936 } | 936 } |
937 | 937 |
938 - (IBAction)showAccountRemovalView:(id)sender { | 938 - (IBAction)showAccountRemovalView:(id)sender { |
939 DCHECK(!isGuestSession_); | 939 DCHECK(!isGuestSession_); |
940 | 940 |
941 // Tag is either |kPrimaryProfileTag| for the primary account, or equal to the | 941 // Tag is either |kPrimaryProfileTag| for the primary account, or equal to the |
942 // index in |currentProfileAccounts_| for a secondary account. | 942 // index in |currentProfileAccounts_| for a secondary account. |
943 int tag = [sender tag]; | 943 int tag = [sender tag]; |
944 if (tag == kPrimaryProfileTag) { | 944 if (tag == kPrimaryProfileTag) { |
945 accountIdToRemove_ = SigninManagerFactory::GetForProfile( | 945 accountIdToRemove_ = SigninManagerFactory::GetForProfile( |
946 browser_->profile())->GetAuthenticatedUsername(); | 946 browser_->profile())->GetAuthenticatedAccountId(); |
947 } else { | 947 } else { |
948 DCHECK(ContainsKey(currentProfileAccounts_, tag)); | 948 DCHECK(ContainsKey(currentProfileAccounts_, tag)); |
949 accountIdToRemove_ = currentProfileAccounts_[tag]; | 949 accountIdToRemove_ = currentProfileAccounts_[tag]; |
950 } | 950 } |
951 | 951 |
952 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL]; | 952 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL]; |
953 } | 953 } |
954 | 954 |
955 - (IBAction)showAccountReauthenticationView:(id)sender { | 955 - (IBAction)showAccountReauthenticationView:(id)sender { |
956 DCHECK(!isGuestSession_); | 956 DCHECK(!isGuestSession_); |
(...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1785 NSMaxY([accountEmails frame]))]; | 1785 NSMaxY([accountEmails frame]))]; |
1786 return container.autorelease(); | 1786 return container.autorelease(); |
1787 } | 1787 } |
1788 | 1788 |
1789 - (NSView*)createAccountsListWithRect:(NSRect)rect { | 1789 - (NSView*)createAccountsListWithRect:(NSRect)rect { |
1790 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]); | 1790 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]); |
1791 currentProfileAccounts_.clear(); | 1791 currentProfileAccounts_.clear(); |
1792 | 1792 |
1793 Profile* profile = browser_->profile(); | 1793 Profile* profile = browser_->profile(); |
1794 std::string primaryAccount = | 1794 std::string primaryAccount = |
1795 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedUsername(); | 1795 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedAccountId(); |
1796 DCHECK(!primaryAccount.empty()); | 1796 DCHECK(!primaryAccount.empty()); |
1797 std::vector<std::string>accounts = | 1797 std::vector<std::string>accounts = |
1798 profiles::GetSecondaryAccountsForProfile(profile, primaryAccount); | 1798 profiles::GetSecondaryAccountsForProfile(profile, primaryAccount); |
1799 | 1799 |
1800 // If there is an account with an authentication error, it needs to be | 1800 // If there is an account with an authentication error, it needs to be |
1801 // badged with a warning icon. | 1801 // badged with a warning icon. |
1802 const SigninErrorController* errorController = | 1802 const SigninErrorController* errorController = |
1803 profiles::GetSigninErrorController(profile); | 1803 profiles::GetSigninErrorController(profile); |
1804 std::string errorAccountId = | 1804 std::string errorAccountId = |
1805 errorController ? errorController->error_account_id() : std::string(); | 1805 errorController ? errorController->error_account_id() : std::string(); |
1806 | 1806 |
1807 rect.origin.y = 0; | 1807 rect.origin.y = 0; |
1808 for (size_t i = 0; i < accounts.size(); ++i) { | 1808 for (size_t i = 0; i < accounts.size(); ++i) { |
1809 // Save the original email address, as the button text could be elided. | 1809 // Save the original email address, as the button text could be elided. |
1810 currentProfileAccounts_[i] = accounts[i]; | 1810 currentProfileAccounts_[i] = accounts[i]; |
1811 NSButton* accountButton = | 1811 NSButton* accountButton = |
1812 [self accountButtonWithRect:rect | 1812 [self accountButtonWithRect:rect |
1813 title:accounts[i] | 1813 accountId:accounts[i] |
1814 tag:i | 1814 tag:i |
1815 reauthRequired:errorAccountId == accounts[i]]; | 1815 reauthRequired:errorAccountId == accounts[i]]; |
1816 [container addSubview:accountButton]; | 1816 [container addSubview:accountButton]; |
1817 rect.origin.y = NSMaxY([accountButton frame]); | 1817 rect.origin.y = NSMaxY([accountButton frame]); |
1818 } | 1818 } |
1819 | 1819 |
1820 // The primary account should always be listed first. | 1820 // The primary account should always be listed first. |
1821 NSButton* accountButton = | 1821 NSButton* accountButton = |
1822 [self accountButtonWithRect:rect | 1822 [self accountButtonWithRect:rect |
1823 title:primaryAccount | 1823 accountId:primaryAccount |
1824 tag:kPrimaryProfileTag | 1824 tag:kPrimaryProfileTag |
1825 reauthRequired:errorAccountId == primaryAccount]; | 1825 reauthRequired:errorAccountId == primaryAccount]; |
1826 [container addSubview:accountButton]; | 1826 [container addSubview:accountButton]; |
1827 [container setFrameSize:NSMakeSize(NSWidth([container frame]), | 1827 [container setFrameSize:NSMakeSize(NSWidth([container frame]), |
1828 NSMaxY([accountButton frame]))]; | 1828 NSMaxY([accountButton frame]))]; |
1829 return container.autorelease(); | 1829 return container.autorelease(); |
1830 } | 1830 } |
1831 | 1831 |
1832 - (NSView*)buildGaiaEmbeddedView { | 1832 - (NSView*)buildGaiaEmbeddedView { |
1833 base::scoped_nsobject<NSView> container( | 1833 base::scoped_nsobject<NSView> container( |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1895 - (NSView*)buildAccountRemovalView { | 1895 - (NSView*)buildAccountRemovalView { |
1896 DCHECK(!accountIdToRemove_.empty()); | 1896 DCHECK(!accountIdToRemove_.empty()); |
1897 | 1897 |
1898 base::scoped_nsobject<NSView> container( | 1898 base::scoped_nsobject<NSView> container( |
1899 [[NSView alloc] initWithFrame:NSZeroRect]); | 1899 [[NSView alloc] initWithFrame:NSZeroRect]); |
1900 CGFloat availableWidth = | 1900 CGFloat availableWidth = |
1901 kFixedAccountRemovalViewWidth - 2 * kHorizontalSpacing; | 1901 kFixedAccountRemovalViewWidth - 2 * kHorizontalSpacing; |
1902 CGFloat yOffset = kVerticalSpacing; | 1902 CGFloat yOffset = kVerticalSpacing; |
1903 | 1903 |
1904 const std::string& primaryAccount = SigninManagerFactory::GetForProfile( | 1904 const std::string& primaryAccount = SigninManagerFactory::GetForProfile( |
1905 browser_->profile())->GetAuthenticatedUsername(); | 1905 browser_->profile())->GetAuthenticatedAccountId(); |
1906 bool isPrimaryAccount = primaryAccount == accountIdToRemove_; | 1906 bool isPrimaryAccount = primaryAccount == accountIdToRemove_; |
1907 | 1907 |
1908 // Adds "remove account" button at the bottom if needed. | 1908 // Adds "remove account" button at the bottom if needed. |
1909 if (!isPrimaryAccount) { | 1909 if (!isPrimaryAccount) { |
1910 base::scoped_nsobject<NSButton> removeAccountButton( | 1910 base::scoped_nsobject<NSButton> removeAccountButton( |
1911 [[BlueLabelButton alloc] initWithFrame:NSZeroRect]); | 1911 [[BlueLabelButton alloc] initWithFrame:NSZeroRect]); |
1912 [removeAccountButton setTitle:l10n_util::GetNSString( | 1912 [removeAccountButton setTitle:l10n_util::GetNSString( |
1913 IDS_PROFILES_ACCOUNT_REMOVAL_BUTTON)]; | 1913 IDS_PROFILES_ACCOUNT_REMOVAL_BUTTON)]; |
1914 [removeAccountButton setTarget:self]; | 1914 [removeAccountButton setTarget:self]; |
1915 [removeAccountButton setAction:@selector(removeAccount:)]; | 1915 [removeAccountButton setAction:@selector(removeAccount:)]; |
1916 [removeAccountButton sizeToFit]; | 1916 [removeAccountButton sizeToFit]; |
1917 [removeAccountButton setAlignment:NSCenterTextAlignment]; | 1917 [removeAccountButton setAlignment:NSCenterTextAlignment]; |
1918 CGFloat xOffset = (kFixedAccountRemovalViewWidth - | 1918 CGFloat xOffset = (kFixedAccountRemovalViewWidth - |
1919 NSWidth([removeAccountButton frame])) / 2; | 1919 NSWidth([removeAccountButton frame])) / 2; |
1920 [removeAccountButton setFrameOrigin:NSMakePoint(xOffset, yOffset)]; | 1920 [removeAccountButton setFrameOrigin:NSMakePoint(xOffset, yOffset)]; |
1921 [container addSubview:removeAccountButton]; | 1921 [container addSubview:removeAccountButton]; |
1922 | 1922 |
1923 yOffset = NSMaxY([removeAccountButton frame]) + kVerticalSpacing; | 1923 yOffset = NSMaxY([removeAccountButton frame]) + kVerticalSpacing; |
1924 } | 1924 } |
1925 | 1925 |
1926 NSView* contentView; | 1926 NSView* contentView; |
1927 NSPoint contentFrameOrigin = NSMakePoint(kHorizontalSpacing, yOffset); | 1927 NSPoint contentFrameOrigin = NSMakePoint(kHorizontalSpacing, yOffset); |
1928 if (isPrimaryAccount) { | 1928 if (isPrimaryAccount) { |
| 1929 std::string email = signin_ui_util::GetDisplayEmail(browser_->profile(), |
| 1930 accountIdToRemove_); |
1929 std::vector<size_t> offsets; | 1931 std::vector<size_t> offsets; |
1930 NSString* contentStr = l10n_util::GetNSStringF( | 1932 NSString* contentStr = l10n_util::GetNSStringF( |
1931 IDS_PROFILES_PRIMARY_ACCOUNT_REMOVAL_TEXT, | 1933 IDS_PROFILES_PRIMARY_ACCOUNT_REMOVAL_TEXT, |
1932 base::UTF8ToUTF16(accountIdToRemove_), base::string16(), &offsets); | 1934 base::UTF8ToUTF16(email), base::string16(), &offsets); |
1933 NSString* linkStr = l10n_util::GetNSString(IDS_PROFILES_SETTINGS_LINK); | 1935 NSString* linkStr = l10n_util::GetNSString(IDS_PROFILES_SETTINGS_LINK); |
1934 contentView = BuildFixedWidthTextViewWithLink(self, contentStr, linkStr, | 1936 contentView = BuildFixedWidthTextViewWithLink(self, contentStr, linkStr, |
1935 offsets[1], contentFrameOrigin, availableWidth); | 1937 offsets[1], contentFrameOrigin, availableWidth); |
1936 } else { | 1938 } else { |
1937 NSString* contentStr = | 1939 NSString* contentStr = |
1938 l10n_util::GetNSString(IDS_PROFILES_ACCOUNT_REMOVAL_TEXT); | 1940 l10n_util::GetNSString(IDS_PROFILES_ACCOUNT_REMOVAL_TEXT); |
1939 NSTextField* contentLabel = BuildLabel(contentStr, contentFrameOrigin, nil); | 1941 NSTextField* contentLabel = BuildLabel(contentStr, contentFrameOrigin, nil); |
1940 [contentLabel setFrameSize:NSMakeSize(availableWidth, 0)]; | 1942 [contentLabel setFrameSize:NSMakeSize(availableWidth, 0)]; |
1941 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:contentLabel]; | 1943 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:contentLabel]; |
1942 contentView = contentLabel; | 1944 contentView = contentLabel; |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2085 [link setFont:[NSFont labelFontOfSize:kTextFontSize]]; | 2087 [link setFont:[NSFont labelFontOfSize:kTextFontSize]]; |
2086 [link setTarget:self]; | 2088 [link setTarget:self]; |
2087 [link setAction:action]; | 2089 [link setAction:action]; |
2088 [link setFrameOrigin:frameOrigin]; | 2090 [link setFrameOrigin:frameOrigin]; |
2089 [link sizeToFit]; | 2091 [link sizeToFit]; |
2090 | 2092 |
2091 return link.autorelease(); | 2093 return link.autorelease(); |
2092 } | 2094 } |
2093 | 2095 |
2094 - (NSButton*)accountButtonWithRect:(NSRect)rect | 2096 - (NSButton*)accountButtonWithRect:(NSRect)rect |
2095 title:(const std::string&)title | 2097 accountId:(const std::string&)accountId |
2096 tag:(int)tag | 2098 tag:(int)tag |
2097 reauthRequired:(BOOL)reauthRequired { | 2099 reauthRequired:(BOOL)reauthRequired { |
| 2100 // Get display email address for account. |
| 2101 std::string email = signin_ui_util::GetDisplayEmail(browser_->profile(), |
| 2102 accountId); |
| 2103 |
2098 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 2104 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
2099 NSImage* deleteImage = rb->GetNativeImageNamed(IDR_CLOSE_1).ToNSImage(); | 2105 NSImage* deleteImage = rb->GetNativeImageNamed(IDR_CLOSE_1).ToNSImage(); |
2100 CGFloat deleteImageWidth = [deleteImage size].width; | 2106 CGFloat deleteImageWidth = [deleteImage size].width; |
2101 NSImage* warningImage = reauthRequired ? rb->GetNativeImageNamed( | 2107 NSImage* warningImage = reauthRequired ? rb->GetNativeImageNamed( |
2102 IDR_ICON_PROFILES_ACCOUNT_BUTTON_ERROR).ToNSImage() : nil; | 2108 IDR_ICON_PROFILES_ACCOUNT_BUTTON_ERROR).ToNSImage() : nil; |
2103 CGFloat warningImageWidth = [warningImage size].width; | 2109 CGFloat warningImageWidth = [warningImage size].width; |
2104 | 2110 |
2105 CGFloat availableTextWidth = rect.size.width - kHorizontalSpacing - | 2111 CGFloat availableTextWidth = rect.size.width - kHorizontalSpacing - |
2106 warningImageWidth - deleteImageWidth; | 2112 warningImageWidth - deleteImageWidth; |
2107 if (warningImage) | 2113 if (warningImage) |
2108 availableTextWidth -= kHorizontalSpacing; | 2114 availableTextWidth -= kHorizontalSpacing; |
2109 | 2115 |
2110 NSColor* backgroundColor = gfx::SkColorToCalibratedNSColor( | 2116 NSColor* backgroundColor = gfx::SkColorToCalibratedNSColor( |
2111 profiles::kAvatarBubbleAccountsBackgroundColor); | 2117 profiles::kAvatarBubbleAccountsBackgroundColor); |
2112 base::scoped_nsobject<BackgroundColorHoverButton> button( | 2118 base::scoped_nsobject<BackgroundColorHoverButton> button( |
2113 [[BackgroundColorHoverButton alloc] initWithFrame:rect | 2119 [[BackgroundColorHoverButton alloc] initWithFrame:rect |
2114 imageTitleSpacing:0 | 2120 imageTitleSpacing:0 |
2115 backgroundColor:backgroundColor]); | 2121 backgroundColor:backgroundColor]); |
2116 [button setTitle:ElideEmail(title, availableTextWidth)]; | 2122 [button setTitle:ElideEmail(email, availableTextWidth)]; |
2117 [button setAlignment:NSLeftTextAlignment]; | 2123 [button setAlignment:NSLeftTextAlignment]; |
2118 [button setBordered:NO]; | 2124 [button setBordered:NO]; |
2119 if (reauthRequired) { | 2125 if (reauthRequired) { |
2120 [button setDefaultImage:warningImage]; | 2126 [button setDefaultImage:warningImage]; |
2121 [button setImagePosition:NSImageLeft]; | 2127 [button setImagePosition:NSImageLeft]; |
2122 [button setTarget:self]; | 2128 [button setTarget:self]; |
2123 [button setAction:@selector(showAccountReauthenticationView:)]; | 2129 [button setAction:@selector(showAccountReauthenticationView:)]; |
2124 [button setTag:tag]; | 2130 [button setTag:tag]; |
2125 } | 2131 } |
2126 | 2132 |
(...skipping 28 matching lines...) Expand all Loading... |
2155 } | 2161 } |
2156 | 2162 |
2157 - (bool)shouldShowGoIncognito { | 2163 - (bool)shouldShowGoIncognito { |
2158 bool incognitoAvailable = | 2164 bool incognitoAvailable = |
2159 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != | 2165 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != |
2160 IncognitoModePrefs::DISABLED; | 2166 IncognitoModePrefs::DISABLED; |
2161 return incognitoAvailable && !browser_->profile()->IsGuestSession(); | 2167 return incognitoAvailable && !browser_->profile()->IsGuestSession(); |
2162 } | 2168 } |
2163 | 2169 |
2164 @end | 2170 @end |
OLD | NEW |