| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/ui/cocoa/one_click_signin_view_controller.h" | 5 #import "chrome/browser/ui/cocoa/one_click_signin_view_controller.h" |
| 6 | 6 |
| 7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/mac/bundle_locations.h" | 9 #include "base/mac/bundle_locations.h" |
| 10 #import "chrome/browser/ui/chrome_style.h" | 10 #import "chrome/browser/ui/chrome_style.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 } // namespace | 31 } // namespace |
| 32 | 32 |
| 33 @interface OneClickSigninViewController () | 33 @interface OneClickSigninViewController () |
| 34 - (CGFloat)initializeInformativeTextView; | 34 - (CGFloat)initializeInformativeTextView; |
| 35 - (void)close; | 35 - (void)close; |
| 36 @end | 36 @end |
| 37 | 37 |
| 38 @implementation OneClickSigninViewController | 38 @implementation OneClickSigninViewController |
| 39 | 39 |
| 40 |
| 40 - (id)initWithNibName:(NSString*)nibName | 41 - (id)initWithNibName:(NSString*)nibName |
| 41 webContents:(content::WebContents*)webContents | 42 webContents:(content::WebContents*)webContents |
| 42 syncCallback:(const BrowserWindow::StartSyncCallback&)syncCallback | 43 syncCallback:(const BrowserWindow::StartSyncCallback&)syncCallback |
| 43 closeCallback:(const base::Closure&)closeCallback | 44 closeCallback:(const base::Closure&)closeCallback |
| 44 isModalDialog:(BOOL)isModalDialog { | 45 isSyncDialog:(BOOL)isSyncDialog |
| 46 errorMessage:(NSString*)errorMessage { |
| 45 if ((self = [super initWithNibName:nibName | 47 if ((self = [super initWithNibName:nibName |
| 46 bundle:base::mac::FrameworkBundle()])) { | 48 bundle:base::mac::FrameworkBundle()])) { |
| 47 webContents_ = webContents; | 49 webContents_ = webContents; |
| 48 startSyncCallback_ = syncCallback; | 50 startSyncCallback_ = syncCallback; |
| 49 closeCallback_ = closeCallback; | 51 closeCallback_ = closeCallback; |
| 50 isModalDialog_ = isModalDialog; | 52 isSyncDialog_ = isSyncDialog; |
| 51 clickedLearnMore_ = NO; | 53 clickedLearnMore_ = NO; |
| 52 DCHECK(!startSyncCallback_.is_null()); | 54 errorMessage_.reset([errorMessage retain]); |
| 55 if (isSyncDialog_) |
| 56 DCHECK(!startSyncCallback_.is_null()); |
| 53 } | 57 } |
| 54 return self; | 58 return self; |
| 55 } | 59 } |
| 56 | 60 |
| 57 - (void)viewWillClose { | 61 - (void)viewWillClose { |
| 58 if (!startSyncCallback_.is_null()) { | 62 // This is usually called after a click handler has initiated sync |
| 63 // and has reset the callback. However, in the case that we are closing |
| 64 // the window and nothing else has initiated the sync, we must do so here |
| 65 if (isSyncDialog_ && !startSyncCallback_.is_null()) { |
| 59 base::ResetAndReturn(&startSyncCallback_).Run( | 66 base::ResetAndReturn(&startSyncCallback_).Run( |
| 60 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); | 67 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); |
| 61 } | 68 } |
| 62 } | 69 } |
| 63 | 70 |
| 64 - (IBAction)ok:(id)sender { | 71 - (IBAction)ok:(id)sender { |
| 65 base::ResetAndReturn(&startSyncCallback_).Run( | 72 if (isSyncDialog_) { |
| 66 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); | |
| 67 | |
| 68 if (isModalDialog_) { | |
| 69 OneClickSigninHelper::LogConfirmHistogramValue( | 73 OneClickSigninHelper::LogConfirmHistogramValue( |
| 70 clickedLearnMore_ ? | 74 clickedLearnMore_ ? |
| 71 one_click_signin::HISTOGRAM_CONFIRM_LEARN_MORE_OK : | 75 one_click_signin::HISTOGRAM_CONFIRM_LEARN_MORE_OK : |
| 72 one_click_signin::HISTOGRAM_CONFIRM_OK); | 76 one_click_signin::HISTOGRAM_CONFIRM_OK); |
| 77 |
| 78 base::ResetAndReturn(&startSyncCallback_).Run( |
| 79 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); |
| 73 } | 80 } |
| 74 | |
| 75 [self close]; | 81 [self close]; |
| 76 } | 82 } |
| 77 | 83 |
| 78 - (IBAction)onClickUndo:(id)sender { | 84 - (IBAction)onClickUndo:(id)sender { |
| 79 base::ResetAndReturn(&startSyncCallback_).Run( | 85 if (isSyncDialog_) { |
| 80 OneClickSigninSyncStarter::UNDO_SYNC); | |
| 81 | |
| 82 if (isModalDialog_) { | |
| 83 OneClickSigninHelper::LogConfirmHistogramValue( | 86 OneClickSigninHelper::LogConfirmHistogramValue( |
| 84 clickedLearnMore_ ? | 87 clickedLearnMore_ ? |
| 85 one_click_signin::HISTOGRAM_CONFIRM_LEARN_MORE_UNDO : | 88 one_click_signin::HISTOGRAM_CONFIRM_LEARN_MORE_UNDO : |
| 86 one_click_signin::HISTOGRAM_CONFIRM_UNDO); | 89 one_click_signin::HISTOGRAM_CONFIRM_UNDO); |
| 90 |
| 91 base::ResetAndReturn(&startSyncCallback_).Run( |
| 92 OneClickSigninSyncStarter::UNDO_SYNC); |
| 93 |
| 87 } | 94 } |
| 88 | |
| 89 [self close]; | 95 [self close]; |
| 90 } | 96 } |
| 91 | 97 |
| 92 - (IBAction)onClickAdvancedLink:(id)sender { | 98 - (IBAction)onClickAdvancedLink:(id)sender { |
| 93 base::ResetAndReturn(&startSyncCallback_).Run( | 99 if (isSyncDialog_) { |
| 94 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); | |
| 95 | |
| 96 if (isModalDialog_) { | |
| 97 OneClickSigninHelper::LogConfirmHistogramValue( | 100 OneClickSigninHelper::LogConfirmHistogramValue( |
| 98 clickedLearnMore_ ? | 101 clickedLearnMore_ ? |
| 99 one_click_signin::HISTOGRAM_CONFIRM_LEARN_MORE_ADVANCED : | 102 one_click_signin::HISTOGRAM_CONFIRM_LEARN_MORE_ADVANCED : |
| 100 one_click_signin::HISTOGRAM_CONFIRM_ADVANCED); | 103 one_click_signin::HISTOGRAM_CONFIRM_ADVANCED); |
| 104 |
| 105 base::ResetAndReturn(&startSyncCallback_).Run( |
| 106 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); |
| 107 } |
| 108 else { |
| 109 content::OpenURLParams params(GURL(chrome::kChromeUISettingsURL), |
| 110 content::Referrer(), CURRENT_TAB, |
| 111 content::PAGE_TRANSITION_LINK, false); |
| 112 webContents_->OpenURL(params); |
| 101 } | 113 } |
| 102 [self close]; | 114 [self close]; |
| 103 } | 115 } |
| 104 | 116 |
| 105 - (IBAction)onClickClose:(id)sender { | 117 - (IBAction)onClickClose:(id)sender { |
| 106 base::ResetAndReturn(&startSyncCallback_).Run( | 118 if (isSyncDialog_) { |
| 107 OneClickSigninSyncStarter::UNDO_SYNC); | |
| 108 | |
| 109 if (isModalDialog_) { | |
| 110 OneClickSigninHelper::LogConfirmHistogramValue( | 119 OneClickSigninHelper::LogConfirmHistogramValue( |
| 111 clickedLearnMore_ ? | 120 clickedLearnMore_ ? |
| 112 one_click_signin::HISTOGRAM_CONFIRM_LEARN_MORE_CLOSE : | 121 one_click_signin::HISTOGRAM_CONFIRM_LEARN_MORE_CLOSE : |
| 113 one_click_signin::HISTOGRAM_CONFIRM_CLOSE); | 122 one_click_signin::HISTOGRAM_CONFIRM_CLOSE); |
| 123 |
| 124 base::ResetAndReturn(&startSyncCallback_).Run( |
| 125 OneClickSigninSyncStarter::UNDO_SYNC); |
| 114 } | 126 } |
| 115 | |
| 116 [self close]; | 127 [self close]; |
| 117 } | 128 } |
| 118 | 129 |
| 119 - (void)awakeFromNib { | 130 - (void)awakeFromNib { |
| 120 // Lay out the text controls from the bottom up. | 131 // Lay out the text controls from the bottom up. |
| 121 CGFloat totalYOffset = 0.0; | 132 CGFloat totalYOffset = 0.0; |
| 122 | 133 |
| 123 totalYOffset += | 134 totalYOffset += |
| 124 [GTMUILocalizerAndLayoutTweaker sizeToFitView:advancedLink_].height; | 135 [GTMUILocalizerAndLayoutTweaker sizeToFitView:advancedLink_].height; |
| 125 [[advancedLink_ cell] setTextColor: | 136 [[advancedLink_ cell] setTextColor: |
| 126 gfx::SkColorToCalibratedNSColor(chrome_style::GetLinkColor())]; | 137 gfx::SkColorToCalibratedNSColor(chrome_style::GetLinkColor())]; |
| 127 | 138 |
| 128 if (informativePlaceholderTextField_) { | 139 if (informativePlaceholderTextField_) { |
| 129 ShiftOriginY(informativePlaceholderTextField_, totalYOffset); | 140 ShiftOriginY(informativePlaceholderTextField_, totalYOffset); |
| 130 totalYOffset += [self initializeInformativeTextView]; | 141 totalYOffset += [self initializeInformativeTextView]; |
| 131 } | 142 } |
| 132 | 143 |
| 133 ShiftOriginY(messageTextField_, totalYOffset); | 144 ShiftOriginY(messageTextField_, totalYOffset); |
| 134 totalYOffset += | 145 totalYOffset += |
| 135 [GTMUILocalizerAndLayoutTweaker | 146 [GTMUILocalizerAndLayoutTweaker |
| 136 sizeToFitFixedWidthTextField:messageTextField_]; | 147 sizeToFitFixedWidthTextField:messageTextField_]; |
| 137 | 148 |
| 138 if (closeButton_) | 149 if (closeButton_) |
| 139 ShiftOriginY(closeButton_, totalYOffset); | 150 ShiftOriginY(closeButton_, totalYOffset); |
| 140 | 151 |
| 141 NSSize delta = NSMakeSize(0.0, totalYOffset); | 152 NSSize delta = NSMakeSize(0.0, totalYOffset); |
| 142 | 153 |
| 154 if (!isSyncDialog_ && [errorMessage_ length] != 0) |
| 155 [messageTextField_ setStringValue:errorMessage_]; |
| 156 |
| 143 // Resize bubble and window to hold the controls. | 157 // Resize bubble and window to hold the controls. |
| 144 [GTMUILocalizerAndLayoutTweaker | 158 [GTMUILocalizerAndLayoutTweaker |
| 145 resizeViewWithoutAutoResizingSubViews:[self view] | 159 resizeViewWithoutAutoResizingSubViews:[self view] |
| 146 delta:delta]; | 160 delta:delta]; |
| 147 | 161 |
| 148 if (isModalDialog_) { | 162 if (isSyncDialog_) { |
| 149 OneClickSigninHelper::LogConfirmHistogramValue( | 163 OneClickSigninHelper::LogConfirmHistogramValue( |
| 150 one_click_signin::HISTOGRAM_CONFIRM_SHOWN); | 164 one_click_signin::HISTOGRAM_CONFIRM_SHOWN); |
| 151 } | 165 } |
| 152 } | 166 } |
| 153 | 167 |
| 154 - (CGFloat)initializeInformativeTextView { | 168 - (CGFloat)initializeInformativeTextView { |
| 155 NSRect oldFrame = [informativePlaceholderTextField_ frame]; | 169 NSRect oldFrame = [informativePlaceholderTextField_ frame]; |
| 156 | 170 |
| 157 // Replace the placeholder NSTextField with the real label NSTextView. The | 171 // Replace the placeholder NSTextField with the real label NSTextView. The |
| 158 // former doesn't show links in a nice way, but the latter can't be added in | 172 // former doesn't show links in a nice way, but the latter can't be added in |
| 159 // a xib without a containing scroll view, so create the NSTextView | 173 // a xib without a containing scroll view, so create the NSTextView |
| 160 // programmatically. | 174 // programmatically. |
| 161 informativeTextView_.reset( | 175 informativeTextView_.reset( |
| 162 [[HyperlinkTextView alloc] initWithFrame:oldFrame]); | 176 [[HyperlinkTextView alloc] initWithFrame:oldFrame]); |
| 163 [informativeTextView_.get() setAutoresizingMask: | 177 [informativeTextView_.get() setAutoresizingMask: |
| 164 [informativePlaceholderTextField_ autoresizingMask]]; | 178 [informativePlaceholderTextField_ autoresizingMask]]; |
| 165 [informativeTextView_.get() setDelegate:self]; | 179 [informativeTextView_.get() setDelegate:self]; |
| 166 | 180 |
| 167 // Set the text. | 181 // Set the text. |
| 168 NSString* learnMoreText = l10n_util::GetNSStringWithFixup(IDS_LEARN_MORE); | 182 NSString* learnMoreText = l10n_util::GetNSStringWithFixup(IDS_LEARN_MORE); |
| 169 NSString* messageText = | 183 NSString* messageText; |
| 170 l10n_util::GetNSStringWithFixup(IDS_ONE_CLICK_SIGNIN_DIALOG_MESSAGE); | 184 |
| 171 messageText = [messageText stringByAppendingString:@" "]; | 185 ui::ResourceBundle::FontStyle fontStyle = isSyncDialog_ ? |
| 186 chrome_style::kTextFontStyle : ui::ResourceBundle::SmallFont; |
| 172 NSFont* font = ui::ResourceBundle::GetSharedInstance().GetFont( | 187 NSFont* font = ui::ResourceBundle::GetSharedInstance().GetFont( |
| 173 chrome_style::kTextFontStyle).GetNativeFont(); | 188 fontStyle).GetNativeFont(); |
| 189 |
| 190 // The non-modal bubble already has a text content and only needs the |
| 191 // Learn More link (in a smaller font). |
| 192 if (isSyncDialog_) { |
| 193 messageText = l10n_util::GetNSStringWithFixup( |
| 194 IDS_ONE_CLICK_SIGNIN_DIALOG_MESSAGE); |
| 195 messageText = [messageText stringByAppendingString:@" "]; |
| 196 } else { |
| 197 messageText = @""; |
| 198 } |
| 199 |
| 174 NSColor* linkColor = | 200 NSColor* linkColor = |
| 175 gfx::SkColorToCalibratedNSColor(chrome_style::GetLinkColor()); | 201 gfx::SkColorToCalibratedNSColor(chrome_style::GetLinkColor()); |
| 176 [informativeTextView_ setMessageAndLink:messageText | 202 [informativeTextView_ setMessageAndLink:messageText |
| 177 withLink:learnMoreText | 203 withLink:learnMoreText |
| 178 atOffset:[messageText length] | 204 atOffset:[messageText length] |
| 179 font:font | 205 font:font |
| 180 messageColor:[NSColor blackColor] | 206 messageColor:[NSColor blackColor] |
| 181 linkColor:linkColor]; | 207 linkColor:linkColor]; |
| 182 | 208 |
| 183 // Size to fit. | 209 // Size to fit. |
| 184 [[informativePlaceholderTextField_ cell] setAttributedStringValue: | 210 [[informativePlaceholderTextField_ cell] setAttributedStringValue: |
| 185 [informativeTextView_ attributedString]]; | 211 [informativeTextView_ attributedString]]; |
| 186 [GTMUILocalizerAndLayoutTweaker | 212 [GTMUILocalizerAndLayoutTweaker |
| 187 sizeToFitFixedWidthTextField:informativePlaceholderTextField_]; | 213 sizeToFitFixedWidthTextField:informativePlaceholderTextField_]; |
| 188 NSRect newFrame = [informativePlaceholderTextField_ frame]; | 214 NSRect newFrame = [informativePlaceholderTextField_ frame]; |
| 189 [informativeTextView_ setFrame:newFrame]; | 215 [informativeTextView_ setFrame:newFrame]; |
| 190 | 216 |
| 191 // Swap placeholder. | 217 // Swap placeholder. |
| 192 [[informativePlaceholderTextField_ superview] | 218 [[informativePlaceholderTextField_ superview] |
| 193 replaceSubview:informativePlaceholderTextField_ | 219 replaceSubview:informativePlaceholderTextField_ |
| 194 with:informativeTextView_.get()]; | 220 with:informativeTextView_.get()]; |
| 195 informativePlaceholderTextField_ = nil; // Now released. | 221 informativePlaceholderTextField_ = nil; // Now released. |
| 196 | 222 |
| 197 return NSHeight(newFrame) - NSHeight(oldFrame); | 223 return NSHeight(newFrame) - NSHeight(oldFrame); |
| 198 } | 224 } |
| 199 | 225 |
| 200 - (BOOL)textView:(NSTextView*)textView | 226 - (BOOL)textView:(NSTextView*)textView |
| 201 clickedOnLink:(id)link | 227 clickedOnLink:(id)link |
| 202 atIndex:(NSUInteger)charIndex { | 228 atIndex:(NSUInteger)charIndex { |
| 203 | 229 if (isSyncDialog_ && !clickedLearnMore_) { |
| 204 if (isModalDialog_ && !clickedLearnMore_) { | |
| 205 clickedLearnMore_ = YES; | 230 clickedLearnMore_ = YES; |
| 206 | 231 |
| 207 OneClickSigninHelper::LogConfirmHistogramValue( | 232 OneClickSigninHelper::LogConfirmHistogramValue( |
| 208 one_click_signin::HISTOGRAM_CONFIRM_LEARN_MORE); | 233 one_click_signin::HISTOGRAM_CONFIRM_LEARN_MORE); |
| 209 } | 234 } |
| 235 WindowOpenDisposition location = isSyncDialog_ ? |
| 236 NEW_WINDOW : NEW_FOREGROUND_TAB; |
| 210 content::OpenURLParams params(GURL(chrome::kChromeSyncLearnMoreURL), | 237 content::OpenURLParams params(GURL(chrome::kChromeSyncLearnMoreURL), |
| 211 content::Referrer(), NEW_WINDOW, | 238 content::Referrer(), location, |
| 212 content::PAGE_TRANSITION_LINK, false); | 239 content::PAGE_TRANSITION_LINK, false); |
| 213 webContents_->OpenURL(params); | 240 webContents_->OpenURL(params); |
| 214 return YES; | 241 return YES; |
| 215 } | 242 } |
| 216 | 243 |
| 217 - (void)close { | 244 - (void)close { |
| 218 base::ResetAndReturn(&closeCallback_).Run(); | 245 base::ResetAndReturn(&closeCallback_).Run(); |
| 219 } | 246 } |
| 220 | 247 |
| 221 @end | 248 @end |
| OLD | NEW |