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 24 matching lines...) Expand all Loading... | |
35 #include "chrome/browser/ui/chrome_style.h" | 35 #include "chrome/browser/ui/chrome_style.h" |
36 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 36 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
37 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 37 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
38 #import "chrome/browser/ui/cocoa/hyperlink_text_view.h" | 38 #import "chrome/browser/ui/cocoa/hyperlink_text_view.h" |
39 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 39 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
40 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 40 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
41 #import "chrome/browser/ui/cocoa/profiles/user_manager_mac.h" | 41 #import "chrome/browser/ui/cocoa/profiles/user_manager_mac.h" |
42 #include "chrome/browser/ui/singleton_tabs.h" | 42 #include "chrome/browser/ui/singleton_tabs.h" |
43 #include "chrome/common/pref_names.h" | 43 #include "chrome/common/pref_names.h" |
44 #include "chrome/common/url_constants.h" | 44 #include "chrome/common/url_constants.h" |
45 #include "components/signin/core/common/profile_management_switches.h" | |
46 #include "components/signin/core/browser/mutable_profile_oauth2_token_service.h" | 45 #include "components/signin/core/browser/mutable_profile_oauth2_token_service.h" |
47 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 46 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
48 #include "components/signin/core/browser/signin_manager.h" | 47 #include "components/signin/core/browser/signin_manager.h" |
48 #include "components/signin/core/common/profile_management_switches.h" | |
49 #include "content/public/browser/notification_service.h" | 49 #include "content/public/browser/notification_service.h" |
50 #include "content/public/browser/web_contents.h" | 50 #include "content/public/browser/web_contents.h" |
51 #include "google_apis/gaia/oauth2_token_service.h" | 51 #include "google_apis/gaia/oauth2_token_service.h" |
52 #include "grit/chromium_strings.h" | 52 #include "grit/chromium_strings.h" |
53 #include "grit/generated_resources.h" | 53 #include "grit/generated_resources.h" |
54 #include "grit/theme_resources.h" | 54 #include "grit/theme_resources.h" |
55 #include "skia/ext/skia_utils_mac.h" | 55 #include "skia/ext/skia_utils_mac.h" |
56 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw eaker.h" | 56 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw eaker.h" |
57 #import "ui/base/cocoa/cocoa_base_utils.h" | 57 #import "ui/base/cocoa/cocoa_base_utils.h" |
58 #import "ui/base/cocoa/controls/blue_label_button.h" | 58 #import "ui/base/cocoa/controls/blue_label_button.h" |
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
854 // Creates a generic link button with |title| and an |action| positioned at | 854 // Creates a generic link button with |title| and an |action| positioned at |
855 // |frameOrigin|. | 855 // |frameOrigin|. |
856 - (NSButton*)linkButtonWithTitle:(NSString*)title | 856 - (NSButton*)linkButtonWithTitle:(NSString*)title |
857 frameOrigin:(NSPoint)frameOrigin | 857 frameOrigin:(NSPoint)frameOrigin |
858 action:(SEL)action; | 858 action:(SEL)action; |
859 | 859 |
860 // Creates an email account button with |title| and a remove icon. If | 860 // Creates an email account button with |title| and a remove icon. If |
861 // |reauthRequired| is true, the button also displays a warning icon. |tag| | 861 // |reauthRequired| is true, the button also displays a warning icon. |tag| |
862 // indicates which account the button refers to. | 862 // indicates which account the button refers to. |
863 - (NSButton*)accountButtonWithRect:(NSRect)rect | 863 - (NSButton*)accountButtonWithRect:(NSRect)rect |
864 title:(const std::string&)title | 864 account_id:(const std::string&)account_id |
865 tag:(int)tag | 865 tag:(int)tag |
866 reauthRequired:(BOOL)reauthRequired; | 866 reauthRequired:(BOOL)reauthRequired; |
867 | 867 |
868 - (bool)shouldShowGoIncognito; | 868 - (bool)shouldShowGoIncognito; |
869 @end | 869 @end |
870 | 870 |
871 @implementation ProfileChooserController | 871 @implementation ProfileChooserController |
872 - (profiles::BubbleViewMode) viewMode { | 872 - (profiles::BubbleViewMode) viewMode { |
873 return viewMode_; | 873 return viewMode_; |
874 } | 874 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
935 } | 935 } |
936 | 936 |
937 - (IBAction)showAccountRemovalView:(id)sender { | 937 - (IBAction)showAccountRemovalView:(id)sender { |
938 DCHECK(!isGuestSession_); | 938 DCHECK(!isGuestSession_); |
939 | 939 |
940 // Tag is either |kPrimaryProfileTag| for the primary account, or equal to the | 940 // Tag is either |kPrimaryProfileTag| for the primary account, or equal to the |
941 // index in |currentProfileAccounts_| for a secondary account. | 941 // index in |currentProfileAccounts_| for a secondary account. |
942 int tag = [sender tag]; | 942 int tag = [sender tag]; |
943 if (tag == kPrimaryProfileTag) { | 943 if (tag == kPrimaryProfileTag) { |
944 accountIdToRemove_ = SigninManagerFactory::GetForProfile( | 944 accountIdToRemove_ = SigninManagerFactory::GetForProfile( |
945 browser_->profile())->GetAuthenticatedUsername(); | 945 browser_->profile())->GetAuthenticatedUsername(); |
guohui
2014/08/21 19:01:53
here it should be changed to GetAuthenticatedAccou
Roger Tawa OOO till Jul 10th
2014/08/21 20:39:25
I was planning to do a cleanup of all places in a
| |
946 } else { | 946 } else { |
947 DCHECK(ContainsKey(currentProfileAccounts_, tag)); | 947 DCHECK(ContainsKey(currentProfileAccounts_, tag)); |
948 accountIdToRemove_ = currentProfileAccounts_[tag]; | 948 accountIdToRemove_ = currentProfileAccounts_[tag]; |
949 } | 949 } |
950 | 950 |
951 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL]; | 951 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL]; |
952 } | 952 } |
953 | 953 |
954 - (IBAction)showAccountReauthenticationView:(id)sender { | 954 - (IBAction)showAccountReauthenticationView:(id)sender { |
955 DCHECK(!isGuestSession_); | 955 DCHECK(!isGuestSession_); |
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1800 profiles::GetSigninErrorController(profile); | 1800 profiles::GetSigninErrorController(profile); |
1801 std::string errorAccountId = | 1801 std::string errorAccountId = |
1802 errorController ? errorController->error_account_id() : std::string(); | 1802 errorController ? errorController->error_account_id() : std::string(); |
1803 | 1803 |
1804 rect.origin.y = 0; | 1804 rect.origin.y = 0; |
1805 for (size_t i = 0; i < accounts.size(); ++i) { | 1805 for (size_t i = 0; i < accounts.size(); ++i) { |
1806 // Save the original email address, as the button text could be elided. | 1806 // Save the original email address, as the button text could be elided. |
1807 currentProfileAccounts_[i] = accounts[i]; | 1807 currentProfileAccounts_[i] = accounts[i]; |
1808 NSButton* accountButton = | 1808 NSButton* accountButton = |
1809 [self accountButtonWithRect:rect | 1809 [self accountButtonWithRect:rect |
1810 title:accounts[i] | 1810 account_id:accounts[i] |
1811 tag:i | 1811 tag:i |
1812 reauthRequired:errorAccountId == accounts[i]]; | 1812 reauthRequired:errorAccountId == accounts[i]]; |
1813 [container addSubview:accountButton]; | 1813 [container addSubview:accountButton]; |
1814 rect.origin.y = NSMaxY([accountButton frame]); | 1814 rect.origin.y = NSMaxY([accountButton frame]); |
1815 } | 1815 } |
1816 | 1816 |
1817 // The primary account should always be listed first. | 1817 // The primary account should always be listed first. |
1818 NSButton* accountButton = | 1818 NSButton* accountButton = |
1819 [self accountButtonWithRect:rect | 1819 [self accountButtonWithRect:rect |
1820 title:primaryAccount | 1820 account_id:primaryAccount |
guohui
2014/08/21 19:01:52
primaryAccount is filled with the authenticated us
Roger Tawa OOO till Jul 10th
2014/08/21 20:39:25
Done.
| |
1821 tag:kPrimaryProfileTag | 1821 tag:kPrimaryProfileTag |
1822 reauthRequired:errorAccountId == primaryAccount]; | 1822 reauthRequired:errorAccountId == primaryAccount]; |
1823 [container addSubview:accountButton]; | 1823 [container addSubview:accountButton]; |
1824 [container setFrameSize:NSMakeSize(NSWidth([container frame]), | 1824 [container setFrameSize:NSMakeSize(NSWidth([container frame]), |
1825 NSMaxY([accountButton frame]))]; | 1825 NSMaxY([accountButton frame]))]; |
1826 return container.autorelease(); | 1826 return container.autorelease(); |
1827 } | 1827 } |
1828 | 1828 |
1829 - (NSView*)buildGaiaEmbeddedView { | 1829 - (NSView*)buildGaiaEmbeddedView { |
1830 base::scoped_nsobject<NSView> container( | 1830 base::scoped_nsobject<NSView> container( |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1892 - (NSView*)buildAccountRemovalView { | 1892 - (NSView*)buildAccountRemovalView { |
1893 DCHECK(!accountIdToRemove_.empty()); | 1893 DCHECK(!accountIdToRemove_.empty()); |
1894 | 1894 |
1895 base::scoped_nsobject<NSView> container( | 1895 base::scoped_nsobject<NSView> container( |
1896 [[NSView alloc] initWithFrame:NSZeroRect]); | 1896 [[NSView alloc] initWithFrame:NSZeroRect]); |
1897 CGFloat availableWidth = | 1897 CGFloat availableWidth = |
1898 kFixedAccountRemovalViewWidth - 2 * kHorizontalSpacing; | 1898 kFixedAccountRemovalViewWidth - 2 * kHorizontalSpacing; |
1899 CGFloat yOffset = kVerticalSpacing; | 1899 CGFloat yOffset = kVerticalSpacing; |
1900 | 1900 |
1901 const std::string& primaryAccount = SigninManagerFactory::GetForProfile( | 1901 const std::string& primaryAccount = SigninManagerFactory::GetForProfile( |
1902 browser_->profile())->GetAuthenticatedUsername(); | 1902 browser_->profile())->GetAuthenticatedUsername(); |
guohui
2014/08/21 19:01:52
here it should be getauthenticatedaccountid.
Roger Tawa OOO till Jul 10th
2014/08/21 20:39:25
Done.
| |
1903 bool isPrimaryAccount = primaryAccount == accountIdToRemove_; | 1903 bool isPrimaryAccount = primaryAccount == accountIdToRemove_; |
1904 | 1904 |
1905 // Adds "remove account" button at the bottom if needed. | 1905 // Adds "remove account" button at the bottom if needed. |
1906 if (!isPrimaryAccount) { | 1906 if (!isPrimaryAccount) { |
1907 base::scoped_nsobject<NSButton> removeAccountButton( | 1907 base::scoped_nsobject<NSButton> removeAccountButton( |
1908 [[BlueLabelButton alloc] initWithFrame:NSZeroRect]); | 1908 [[BlueLabelButton alloc] initWithFrame:NSZeroRect]); |
1909 [removeAccountButton setTitle:l10n_util::GetNSString( | 1909 [removeAccountButton setTitle:l10n_util::GetNSString( |
1910 IDS_PROFILES_ACCOUNT_REMOVAL_BUTTON)]; | 1910 IDS_PROFILES_ACCOUNT_REMOVAL_BUTTON)]; |
1911 [removeAccountButton setTarget:self]; | 1911 [removeAccountButton setTarget:self]; |
1912 [removeAccountButton setAction:@selector(removeAccount:)]; | 1912 [removeAccountButton setAction:@selector(removeAccount:)]; |
1913 [removeAccountButton sizeToFit]; | 1913 [removeAccountButton sizeToFit]; |
1914 [removeAccountButton setAlignment:NSCenterTextAlignment]; | 1914 [removeAccountButton setAlignment:NSCenterTextAlignment]; |
1915 CGFloat xOffset = (kFixedAccountRemovalViewWidth - | 1915 CGFloat xOffset = (kFixedAccountRemovalViewWidth - |
1916 NSWidth([removeAccountButton frame])) / 2; | 1916 NSWidth([removeAccountButton frame])) / 2; |
1917 [removeAccountButton setFrameOrigin:NSMakePoint(xOffset, yOffset)]; | 1917 [removeAccountButton setFrameOrigin:NSMakePoint(xOffset, yOffset)]; |
1918 [container addSubview:removeAccountButton]; | 1918 [container addSubview:removeAccountButton]; |
1919 | 1919 |
1920 yOffset = NSMaxY([removeAccountButton frame]) + kVerticalSpacing; | 1920 yOffset = NSMaxY([removeAccountButton frame]) + kVerticalSpacing; |
1921 } | 1921 } |
1922 | 1922 |
1923 NSView* contentView; | 1923 NSView* contentView; |
1924 NSPoint contentFrameOrigin = NSMakePoint(kHorizontalSpacing, yOffset); | 1924 NSPoint contentFrameOrigin = NSMakePoint(kHorizontalSpacing, yOffset); |
1925 if (isPrimaryAccount) { | 1925 if (isPrimaryAccount) { |
1926 std::vector<size_t> offsets; | 1926 std::vector<size_t> offsets; |
1927 NSString* contentStr = l10n_util::GetNSStringF( | 1927 NSString* contentStr = l10n_util::GetNSStringF( |
1928 IDS_PROFILES_PRIMARY_ACCOUNT_REMOVAL_TEXT, | 1928 IDS_PROFILES_PRIMARY_ACCOUNT_REMOVAL_TEXT, |
1929 base::UTF8ToUTF16(accountIdToRemove_), base::string16(), &offsets); | 1929 base::UTF8ToUTF16(accountIdToRemove_), base::string16(), &offsets); |
guohui
2014/08/21 19:01:52
need to convert id to display email.
Roger Tawa OOO till Jul 10th
2014/08/21 20:39:24
Good catch. Done.
| |
1930 NSString* linkStr = l10n_util::GetNSString(IDS_PROFILES_SETTINGS_LINK); | 1930 NSString* linkStr = l10n_util::GetNSString(IDS_PROFILES_SETTINGS_LINK); |
1931 contentView = BuildFixedWidthTextViewWithLink(self, contentStr, linkStr, | 1931 contentView = BuildFixedWidthTextViewWithLink(self, contentStr, linkStr, |
1932 offsets[1], contentFrameOrigin, availableWidth); | 1932 offsets[1], contentFrameOrigin, availableWidth); |
1933 } else { | 1933 } else { |
1934 NSString* contentStr = | 1934 NSString* contentStr = |
1935 l10n_util::GetNSString(IDS_PROFILES_ACCOUNT_REMOVAL_TEXT); | 1935 l10n_util::GetNSString(IDS_PROFILES_ACCOUNT_REMOVAL_TEXT); |
1936 NSTextField* contentLabel = BuildLabel(contentStr, contentFrameOrigin, nil); | 1936 NSTextField* contentLabel = BuildLabel(contentStr, contentFrameOrigin, nil); |
1937 [contentLabel setFrameSize:NSMakeSize(availableWidth, 0)]; | 1937 [contentLabel setFrameSize:NSMakeSize(availableWidth, 0)]; |
1938 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:contentLabel]; | 1938 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:contentLabel]; |
1939 contentView = contentLabel; | 1939 contentView = contentLabel; |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2082 [link setFont:[NSFont labelFontOfSize:kTextFontSize]]; | 2082 [link setFont:[NSFont labelFontOfSize:kTextFontSize]]; |
2083 [link setTarget:self]; | 2083 [link setTarget:self]; |
2084 [link setAction:action]; | 2084 [link setAction:action]; |
2085 [link setFrameOrigin:frameOrigin]; | 2085 [link setFrameOrigin:frameOrigin]; |
2086 [link sizeToFit]; | 2086 [link sizeToFit]; |
2087 | 2087 |
2088 return link.autorelease(); | 2088 return link.autorelease(); |
2089 } | 2089 } |
2090 | 2090 |
2091 - (NSButton*)accountButtonWithRect:(NSRect)rect | 2091 - (NSButton*)accountButtonWithRect:(NSRect)rect |
2092 title:(const std::string&)title | 2092 account_id:(const std::string&)account_id |
2093 tag:(int)tag | 2093 tag:(int)tag |
2094 reauthRequired:(BOOL)reauthRequired { | 2094 reauthRequired:(BOOL)reauthRequired { |
2095 // Get display email address for account. | |
2096 std::string email = signin_ui_util::GetDisplayEmail(browser_->profile(), | |
2097 account_id); | |
2098 | |
2095 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 2099 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
2096 NSImage* deleteImage = rb->GetNativeImageNamed(IDR_CLOSE_1).ToNSImage(); | 2100 NSImage* deleteImage = rb->GetNativeImageNamed(IDR_CLOSE_1).ToNSImage(); |
2097 CGFloat deleteImageWidth = [deleteImage size].width; | 2101 CGFloat deleteImageWidth = [deleteImage size].width; |
2098 NSImage* warningImage = reauthRequired ? rb->GetNativeImageNamed( | 2102 NSImage* warningImage = reauthRequired ? rb->GetNativeImageNamed( |
2099 IDR_ICON_PROFILES_ACCOUNT_BUTTON_ERROR).ToNSImage() : nil; | 2103 IDR_ICON_PROFILES_ACCOUNT_BUTTON_ERROR).ToNSImage() : nil; |
2100 CGFloat warningImageWidth = [warningImage size].width; | 2104 CGFloat warningImageWidth = [warningImage size].width; |
2101 | 2105 |
2102 CGFloat availableTextWidth = rect.size.width - kHorizontalSpacing - | 2106 CGFloat availableTextWidth = rect.size.width - kHorizontalSpacing - |
2103 warningImageWidth - deleteImageWidth; | 2107 warningImageWidth - deleteImageWidth; |
2104 if (warningImage) | 2108 if (warningImage) |
2105 availableTextWidth -= kHorizontalSpacing; | 2109 availableTextWidth -= kHorizontalSpacing; |
2106 | 2110 |
2107 NSColor* backgroundColor = gfx::SkColorToCalibratedNSColor( | 2111 NSColor* backgroundColor = gfx::SkColorToCalibratedNSColor( |
2108 profiles::kAvatarBubbleAccountsBackgroundColor); | 2112 profiles::kAvatarBubbleAccountsBackgroundColor); |
2109 base::scoped_nsobject<BackgroundColorHoverButton> button( | 2113 base::scoped_nsobject<BackgroundColorHoverButton> button( |
2110 [[BackgroundColorHoverButton alloc] initWithFrame:rect | 2114 [[BackgroundColorHoverButton alloc] initWithFrame:rect |
2111 imageTitleSpacing:0 | 2115 imageTitleSpacing:0 |
2112 backgroundColor:backgroundColor]); | 2116 backgroundColor:backgroundColor]); |
2113 [button setTitle:ElideEmail(title, availableTextWidth)]; | 2117 [button setTitle:ElideEmail(email, availableTextWidth)]; |
2114 [button setAlignment:NSLeftTextAlignment]; | 2118 [button setAlignment:NSLeftTextAlignment]; |
2115 [button setBordered:NO]; | 2119 [button setBordered:NO]; |
2116 if (reauthRequired) { | 2120 if (reauthRequired) { |
2117 [button setDefaultImage:warningImage]; | 2121 [button setDefaultImage:warningImage]; |
2118 [button setImagePosition:NSImageLeft]; | 2122 [button setImagePosition:NSImageLeft]; |
2119 [button setTarget:self]; | 2123 [button setTarget:self]; |
2120 [button setAction:@selector(showAccountReauthenticationView:)]; | 2124 [button setAction:@selector(showAccountReauthenticationView:)]; |
2121 [button setTag:tag]; | 2125 [button setTag:tag]; |
2122 } | 2126 } |
2123 | 2127 |
(...skipping 28 matching lines...) Expand all Loading... | |
2152 } | 2156 } |
2153 | 2157 |
2154 - (bool)shouldShowGoIncognito { | 2158 - (bool)shouldShowGoIncognito { |
2155 bool incognitoAvailable = | 2159 bool incognitoAvailable = |
2156 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != | 2160 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != |
2157 IncognitoModePrefs::DISABLED; | 2161 IncognitoModePrefs::DISABLED; |
2158 return incognitoAvailable && !browser_->profile()->IsGuestSession(); | 2162 return incognitoAvailable && !browser_->profile()->IsGuestSession(); |
2159 } | 2163 } |
2160 | 2164 |
2161 @end | 2165 @end |
OLD | NEW |