| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "chrome/browser/ui/cocoa/profiles/signin_view_controller_delegate_mac.h
" | 5 #include "chrome/browser/ui/cocoa/profiles/signin_view_controller_delegate_mac.h
" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 : kSigninErrorDialogHeight; | 48 : kSigninErrorDialogHeight; |
| 49 } | 49 } |
| 50 | 50 |
| 51 } // namespace | 51 } // namespace |
| 52 | 52 |
| 53 SigninViewControllerDelegateMac::SigninViewControllerDelegateMac( | 53 SigninViewControllerDelegateMac::SigninViewControllerDelegateMac( |
| 54 SigninViewController* signin_view_controller, | 54 SigninViewController* signin_view_controller, |
| 55 std::unique_ptr<content::WebContents> web_contents, | 55 std::unique_ptr<content::WebContents> web_contents, |
| 56 content::WebContents* host_web_contents, | 56 content::WebContents* host_web_contents, |
| 57 NSRect frame, | 57 NSRect frame, |
| 58 DialogModalType dialog_modal_type, |
| 58 bool wait_for_size) | 59 bool wait_for_size) |
| 59 : SigninViewControllerDelegate(signin_view_controller, web_contents.get()), | 60 : SigninViewControllerDelegate(signin_view_controller, web_contents.get()), |
| 60 web_contents_(std::move(web_contents)), | 61 web_contents_(std::move(web_contents)), |
| 61 wait_for_size_(wait_for_size), | 62 wait_for_size_(wait_for_size), |
| 62 host_web_contents_(host_web_contents), | 63 host_web_contents_(host_web_contents), |
| 64 dialog_modal_type_(dialog_modal_type), |
| 63 window_frame_(frame) { | 65 window_frame_(frame) { |
| 64 if (!wait_for_size_) | 66 if (!wait_for_size_) |
| 65 DisplayModal(); | 67 DisplayModal(); |
| 66 } | 68 } |
| 67 | 69 |
| 68 SigninViewControllerDelegateMac::~SigninViewControllerDelegateMac() {} | 70 SigninViewControllerDelegateMac::~SigninViewControllerDelegateMac() {} |
| 69 | 71 |
| 70 void SigninViewControllerDelegateMac::OnConstrainedWindowClosed( | 72 void SigninViewControllerDelegateMac::OnConstrainedWindowClosed( |
| 71 ConstrainedWindowMac* window) { | 73 ConstrainedWindowMac* window) { |
| 72 ResetSigninViewControllerDelegate(); | 74 DeleteThis(); |
| 73 delete this; | |
| 74 } | 75 } |
| 75 | 76 |
| 76 // static | 77 // static |
| 77 std::unique_ptr<content::WebContents> | 78 std::unique_ptr<content::WebContents> |
| 78 SigninViewControllerDelegateMac::CreateGaiaWebContents( | 79 SigninViewControllerDelegateMac::CreateGaiaWebContents( |
| 79 content::WebContentsDelegate* delegate, | 80 content::WebContentsDelegate* delegate, |
| 80 profiles::BubbleViewMode mode, | 81 profiles::BubbleViewMode mode, |
| 81 Profile* profile, | 82 Profile* profile, |
| 82 signin_metrics::AccessPoint access_point) { | 83 signin_metrics::AccessPoint access_point) { |
| 83 GURL url = | 84 GURL url = |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); | 139 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); |
| 139 | 140 |
| 140 NSView* webview = web_contents->GetNativeView(); | 141 NSView* webview = web_contents->GetNativeView(); |
| 141 [webview | 142 [webview |
| 142 setFrameSize:NSMakeSize(kModalDialogWidth, kSigninErrorDialogHeight)]; | 143 setFrameSize:NSMakeSize(kModalDialogWidth, kSigninErrorDialogHeight)]; |
| 143 | 144 |
| 144 return web_contents; | 145 return web_contents; |
| 145 } | 146 } |
| 146 | 147 |
| 147 void SigninViewControllerDelegateMac::PerformClose() { | 148 void SigninViewControllerDelegateMac::PerformClose() { |
| 148 if (constrained_window_.get()) | 149 switch (dialog_modal_type_) { |
| 149 constrained_window_->CloseWebContentsModalDialog(); | 150 case TAB_MODAL: |
| 151 if (constrained_window_.get()) |
| 152 constrained_window_->CloseWebContentsModalDialog(); |
| 153 break; |
| 154 case WINDOW_MODAL: |
| 155 if (window_.get()) { |
| 156 [host_web_contents_->GetTopLevelNativeWindow() endSheet:window_]; |
| 157 window_.reset(nil); |
| 158 DeleteThis(); |
| 159 } |
| 160 break; |
| 161 } |
| 150 } | 162 } |
| 151 | 163 |
| 152 void SigninViewControllerDelegateMac::ResizeNativeView(int height) { | 164 void SigninViewControllerDelegateMac::ResizeNativeView(int height) { |
| 153 if (wait_for_size_) { | 165 if (wait_for_size_) { |
| 154 [window_.get().contentView | 166 [window_.get().contentView |
| 155 setFrameSize:NSMakeSize(kModalDialogWidth, | 167 setFrameSize:NSMakeSize(kModalDialogWidth, |
| 156 height)]; | 168 height)]; |
| 157 window_frame_.size = NSMakeSize(kModalDialogWidth, height); | 169 window_frame_.size = NSMakeSize(kModalDialogWidth, height); |
| 158 DisplayModal(); | 170 DisplayModal(); |
| 159 } | 171 } |
| 160 } | 172 } |
| 161 | 173 |
| 162 void SigninViewControllerDelegateMac::DisplayModal() { | 174 void SigninViewControllerDelegateMac::DisplayModal() { |
| 163 window_.reset( | 175 window_.reset( |
| 164 [[ConstrainedWindowCustomWindow alloc] | 176 [[ConstrainedWindowCustomWindow alloc] |
| 165 initWithContentRect:window_frame_]); | 177 initWithContentRect:window_frame_]); |
| 166 | 178 |
| 167 window_.get().contentView = web_contents_->GetNativeView(); | 179 window_.get().contentView = web_contents_->GetNativeView(); |
| 168 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet( | 180 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet( |
| 169 [[CustomConstrainedWindowSheet alloc] initWithCustomWindow:window_]); | 181 [[CustomConstrainedWindowSheet alloc] initWithCustomWindow:window_]); |
| 170 constrained_window_ = | 182 switch (dialog_modal_type_) { |
| 171 CreateAndShowWebModalDialogMac(this, host_web_contents_, sheet); | 183 case TAB_MODAL: |
| 184 constrained_window_ = |
| 185 CreateAndShowWebModalDialogMac(this, host_web_contents_, sheet); |
| 186 break; |
| 187 case WINDOW_MODAL: |
| 188 [host_web_contents_->GetTopLevelNativeWindow() beginSheet:window_ |
| 189 completionHandler:nil]; |
| 190 break; |
| 191 } |
| 172 } | 192 } |
| 173 | 193 |
| 174 void SigninViewControllerDelegateMac::HandleKeyboardEvent( | 194 void SigninViewControllerDelegateMac::HandleKeyboardEvent( |
| 175 content::WebContents* source, | 195 content::WebContents* source, |
| 176 const content::NativeWebKeyboardEvent& event) { | 196 const content::NativeWebKeyboardEvent& event) { |
| 177 int chrome_command_id = [BrowserWindowUtils getCommandId:event]; | 197 int chrome_command_id = [BrowserWindowUtils getCommandId:event]; |
| 178 bool can_handle_command = [BrowserWindowUtils isTextEditingEvent:event] || | 198 bool can_handle_command = [BrowserWindowUtils isTextEditingEvent:event] || |
| 179 chrome_command_id == IDC_CLOSE_WINDOW || | 199 chrome_command_id == IDC_CLOSE_WINDOW || |
| 180 chrome_command_id == IDC_EXIT; | 200 chrome_command_id == IDC_EXIT; |
| 181 if ([BrowserWindowUtils shouldHandleKeyboardEvent:event] && | 201 if ([BrowserWindowUtils shouldHandleKeyboardEvent:event] && |
| 182 can_handle_command) { | 202 can_handle_command) { |
| 183 [[NSApp mainMenu] performKeyEquivalent:event.os_event]; | 203 [[NSApp mainMenu] performKeyEquivalent:event.os_event]; |
| 184 } | 204 } |
| 185 } | 205 } |
| 186 | 206 |
| 207 void SigninViewControllerDelegateMac::DeleteThis() { |
| 208 ResetSigninViewControllerDelegate(); |
| 209 delete this; |
| 210 } |
| 211 |
| 187 // static | 212 // static |
| 188 SigninViewControllerDelegate* | 213 SigninViewControllerDelegate* |
| 189 SigninViewControllerDelegate::CreateModalSigninDelegate( | 214 SigninViewControllerDelegate::CreateModalSigninDelegate( |
| 190 SigninViewController* signin_view_controller, | 215 SigninViewController* signin_view_controller, |
| 191 profiles::BubbleViewMode mode, | 216 profiles::BubbleViewMode mode, |
| 192 Browser* browser, | 217 Browser* browser, |
| 193 signin_metrics::AccessPoint access_point) { | 218 signin_metrics::AccessPoint access_point) { |
| 194 return new SigninViewControllerDelegateMac( | 219 return new SigninViewControllerDelegateMac( |
| 195 signin_view_controller, | 220 signin_view_controller, |
| 196 SigninViewControllerDelegateMac::CreateGaiaWebContents( | 221 SigninViewControllerDelegateMac::CreateGaiaWebContents( |
| 197 nullptr, mode, browser->profile(), access_point), | 222 nullptr, mode, browser->profile(), access_point), |
| 198 browser->tab_strip_model()->GetActiveWebContents(), | 223 browser->tab_strip_model()->GetActiveWebContents(), |
| 199 NSMakeRect(0, 0, kModalDialogWidth, kFixedGaiaViewHeight), | 224 NSMakeRect(0, 0, kModalDialogWidth, kFixedGaiaViewHeight), |
| 200 false); | 225 DialogModalType::TAB_MODAL, false); |
| 201 } | 226 } |
| 202 | 227 |
| 203 // static | 228 // static |
| 204 SigninViewControllerDelegate* | 229 SigninViewControllerDelegate* |
| 205 SigninViewControllerDelegate::CreateSyncConfirmationDelegate( | 230 SigninViewControllerDelegate::CreateSyncConfirmationDelegate( |
| 206 SigninViewController* signin_view_controller, | 231 SigninViewController* signin_view_controller, |
| 207 Browser* browser) { | 232 Browser* browser) { |
| 208 return new SigninViewControllerDelegateMac( | 233 return new SigninViewControllerDelegateMac( |
| 209 signin_view_controller, | 234 signin_view_controller, |
| 210 SigninViewControllerDelegateMac::CreateSyncConfirmationWebContents( | 235 SigninViewControllerDelegateMac::CreateSyncConfirmationWebContents( |
| 211 browser->profile()), | 236 browser->profile()), |
| 212 browser->tab_strip_model()->GetActiveWebContents(), | 237 browser->tab_strip_model()->GetActiveWebContents(), |
| 213 NSMakeRect(0, 0, kModalDialogWidth, | 238 NSMakeRect(0, 0, kModalDialogWidth, |
| 214 GetSyncConfirmationDialogPreferredHeight(browser->profile())), | 239 GetSyncConfirmationDialogPreferredHeight(browser->profile())), |
| 215 true); | 240 DialogModalType::WINDOW_MODAL, true); |
| 216 } | 241 } |
| 217 | 242 |
| 218 // static | 243 // static |
| 219 SigninViewControllerDelegate* | 244 SigninViewControllerDelegate* |
| 220 SigninViewControllerDelegate::CreateSigninErrorDelegate( | 245 SigninViewControllerDelegate::CreateSigninErrorDelegate( |
| 221 SigninViewController* signin_view_controller, | 246 SigninViewController* signin_view_controller, |
| 222 Browser* browser) { | 247 Browser* browser) { |
| 223 return new SigninViewControllerDelegateMac( | 248 return new SigninViewControllerDelegateMac( |
| 224 signin_view_controller, | 249 signin_view_controller, |
| 225 SigninViewControllerDelegateMac::CreateSigninErrorWebContents( | 250 SigninViewControllerDelegateMac::CreateSigninErrorWebContents( |
| 226 browser->profile()), | 251 browser->profile()), |
| 227 browser->tab_strip_model()->GetActiveWebContents(), | 252 browser->tab_strip_model()->GetActiveWebContents(), |
| 228 NSMakeRect(0, 0, kModalDialogWidth, kSigninErrorDialogHeight), true); | 253 NSMakeRect(0, 0, kModalDialogWidth, kSigninErrorDialogHeight), |
| 254 DialogModalType::WINDOW_MODAL, true); |
| 229 } | 255 } |
| OLD | NEW |