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

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

Issue 2617583006: Using native sheet to display modal dialogs for sign in (Closed)
Patch Set: Rebase Created 3 years, 11 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 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
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 Browser* browser, 56 Browser* browser,
57 NSRect frame, 57 NSRect frame,
58 ui::ModalType 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 browser_(browser), 63 browser_(browser),
64 dialog_modal_type_(dialog_modal_type),
63 window_frame_(frame) { 65 window_frame_(frame) {
64 DCHECK(browser_); 66 DCHECK(browser_);
65 DCHECK(browser_->tab_strip_model()->GetActiveWebContents()) 67 DCHECK(browser_->tab_strip_model()->GetActiveWebContents())
66 << "A tab must be active to present the sign-in modal dialog."; 68 << "A tab must be active to present the sign-in modal dialog.";
67 69
68 if (!wait_for_size_) 70 if (!wait_for_size_)
69 DisplayModal(); 71 DisplayModal();
70 } 72 }
71 73
72 SigninViewControllerDelegateMac::~SigninViewControllerDelegateMac() {} 74 SigninViewControllerDelegateMac::~SigninViewControllerDelegateMac() {}
73 75
74 void SigninViewControllerDelegateMac::OnConstrainedWindowClosed( 76 void SigninViewControllerDelegateMac::OnConstrainedWindowClosed(
75 ConstrainedWindowMac* window) { 77 ConstrainedWindowMac* window) {
76 ResetSigninViewControllerDelegate(); 78 CleanupAndDeleteThis();
77 delete this;
78 } 79 }
79 80
80 // static 81 // static
81 std::unique_ptr<content::WebContents> 82 std::unique_ptr<content::WebContents>
82 SigninViewControllerDelegateMac::CreateGaiaWebContents( 83 SigninViewControllerDelegateMac::CreateGaiaWebContents(
83 content::WebContentsDelegate* delegate, 84 content::WebContentsDelegate* delegate,
84 profiles::BubbleViewMode mode, 85 profiles::BubbleViewMode mode,
85 Profile* profile, 86 Profile* profile,
86 signin_metrics::AccessPoint access_point) { 87 signin_metrics::AccessPoint access_point) {
87 GURL url = 88 GURL url =
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); 143 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string());
143 144
144 NSView* webview = web_contents->GetNativeView(); 145 NSView* webview = web_contents->GetNativeView();
145 [webview 146 [webview
146 setFrameSize:NSMakeSize(kModalDialogWidth, kSigninErrorDialogHeight)]; 147 setFrameSize:NSMakeSize(kModalDialogWidth, kSigninErrorDialogHeight)];
147 148
148 return web_contents; 149 return web_contents;
149 } 150 }
150 151
151 void SigninViewControllerDelegateMac::PerformClose() { 152 void SigninViewControllerDelegateMac::PerformClose() {
152 if (constrained_window_.get()) 153 switch (dialog_modal_type_) {
153 constrained_window_->CloseWebContentsModalDialog(); 154 case ui::MODAL_TYPE_CHILD:
155 if (constrained_window_.get())
156 constrained_window_->CloseWebContentsModalDialog();
157 break;
158 case ui::MODAL_TYPE_WINDOW:
159 if (window_.get()) {
160 [window_.get().sheetParent endSheet:window_];
161 window_.reset(nil);
162 CleanupAndDeleteThis();
163 }
164 break;
165 default:
166 NOTREACHED() << "Unsupported dialog modal type " << dialog_modal_type_;
167 }
154 } 168 }
155 169
156 void SigninViewControllerDelegateMac::ResizeNativeView(int height) { 170 void SigninViewControllerDelegateMac::ResizeNativeView(int height) {
157 if (wait_for_size_) { 171 if (wait_for_size_) {
158 [window_.get().contentView 172 [window_.get().contentView
159 setFrameSize:NSMakeSize(kModalDialogWidth, 173 setFrameSize:NSMakeSize(kModalDialogWidth,
160 height)]; 174 height)];
161 window_frame_.size = NSMakeSize(kModalDialogWidth, height); 175 window_frame_.size = NSMakeSize(kModalDialogWidth, height);
162 DisplayModal(); 176 DisplayModal();
163 } 177 }
164 } 178 }
165 179
166 void SigninViewControllerDelegateMac::DisplayModal() { 180 void SigninViewControllerDelegateMac::DisplayModal() {
167 content::WebContents* host_web_contents = 181 content::WebContents* host_web_contents =
168 browser_->tab_strip_model()->GetActiveWebContents(); 182 browser_->tab_strip_model()->GetActiveWebContents();
169 183
170 // Avoid displaying the sign-in modal view if there are no active web 184 // Avoid displaying the sign-in modal view if there are no active web
171 // contents. This happens if the user closes the browser window before this 185 // contents. This happens if the user closes the browser window before this
172 // dialog has a chance to be displayed. 186 // dialog has a chance to be displayed.
173 if (!host_web_contents) 187 if (!host_web_contents)
174 return; 188 return;
175 189
176 window_.reset( 190 window_.reset(
177 [[ConstrainedWindowCustomWindow alloc] 191 [[ConstrainedWindowCustomWindow alloc]
178 initWithContentRect:window_frame_]); 192 initWithContentRect:window_frame_]);
179 window_.get().contentView = web_contents_->GetNativeView(); 193 window_.get().contentView = web_contents_->GetNativeView();
180 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet( 194 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet(
181 [[CustomConstrainedWindowSheet alloc] initWithCustomWindow:window_]); 195 [[CustomConstrainedWindowSheet alloc] initWithCustomWindow:window_]);
182 constrained_window_ = 196 switch (dialog_modal_type_) {
183 CreateAndShowWebModalDialogMac(this, host_web_contents, sheet); 197 case ui::MODAL_TYPE_CHILD:
198 constrained_window_ =
199 CreateAndShowWebModalDialogMac(this, host_web_contents, sheet);
200 break;
201 case ui::MODAL_TYPE_WINDOW:
202 [host_web_contents->GetTopLevelNativeWindow() beginSheet:window_
203 completionHandler:nil];
204 break;
205 default:
206 NOTREACHED() << "Unsupported dialog modal type " << dialog_modal_type_;
207 }
184 } 208 }
185 209
186 void SigninViewControllerDelegateMac::HandleKeyboardEvent( 210 void SigninViewControllerDelegateMac::HandleKeyboardEvent(
187 content::WebContents* source, 211 content::WebContents* source,
188 const content::NativeWebKeyboardEvent& event) { 212 const content::NativeWebKeyboardEvent& event) {
189 int chrome_command_id = [BrowserWindowUtils getCommandId:event]; 213 int chrome_command_id = [BrowserWindowUtils getCommandId:event];
190 bool can_handle_command = [BrowserWindowUtils isTextEditingEvent:event] || 214 bool can_handle_command = [BrowserWindowUtils isTextEditingEvent:event] ||
191 chrome_command_id == IDC_CLOSE_WINDOW || 215 chrome_command_id == IDC_CLOSE_WINDOW ||
192 chrome_command_id == IDC_EXIT; 216 chrome_command_id == IDC_EXIT;
193 if ([BrowserWindowUtils shouldHandleKeyboardEvent:event] && 217 if ([BrowserWindowUtils shouldHandleKeyboardEvent:event] &&
194 can_handle_command) { 218 can_handle_command) {
195 [[NSApp mainMenu] performKeyEquivalent:event.os_event]; 219 [[NSApp mainMenu] performKeyEquivalent:event.os_event];
196 } 220 }
197 } 221 }
198 222
223 void SigninViewControllerDelegateMac::CleanupAndDeleteThis() {
224 ResetSigninViewControllerDelegate();
225 delete this;
226 }
227
199 // static 228 // static
200 SigninViewControllerDelegate* 229 SigninViewControllerDelegate*
201 SigninViewControllerDelegate::CreateModalSigninDelegate( 230 SigninViewControllerDelegate::CreateModalSigninDelegate(
202 SigninViewController* signin_view_controller, 231 SigninViewController* signin_view_controller,
203 profiles::BubbleViewMode mode, 232 profiles::BubbleViewMode mode,
204 Browser* browser, 233 Browser* browser,
205 signin_metrics::AccessPoint access_point) { 234 signin_metrics::AccessPoint access_point) {
206 return new SigninViewControllerDelegateMac( 235 return new SigninViewControllerDelegateMac(
207 signin_view_controller, 236 signin_view_controller,
208 SigninViewControllerDelegateMac::CreateGaiaWebContents( 237 SigninViewControllerDelegateMac::CreateGaiaWebContents(
209 nullptr, mode, browser->profile(), access_point), 238 nullptr, mode, browser->profile(), access_point),
210 browser, NSMakeRect(0, 0, kModalDialogWidth, kFixedGaiaViewHeight), 239 browser, NSMakeRect(0, 0, kModalDialogWidth, kFixedGaiaViewHeight),
211 false /* wait_for_size */); 240 ui::MODAL_TYPE_CHILD, false /* wait_for_size */);
212 } 241 }
213 242
214 // static 243 // static
215 SigninViewControllerDelegate* 244 SigninViewControllerDelegate*
216 SigninViewControllerDelegate::CreateSyncConfirmationDelegate( 245 SigninViewControllerDelegate::CreateSyncConfirmationDelegate(
217 SigninViewController* signin_view_controller, 246 SigninViewController* signin_view_controller,
218 Browser* browser) { 247 Browser* browser) {
219 return new SigninViewControllerDelegateMac( 248 return new SigninViewControllerDelegateMac(
220 signin_view_controller, 249 signin_view_controller,
221 SigninViewControllerDelegateMac::CreateSyncConfirmationWebContents( 250 SigninViewControllerDelegateMac::CreateSyncConfirmationWebContents(
222 browser->profile()), 251 browser->profile()),
223 browser, 252 browser,
224 NSMakeRect(0, 0, kModalDialogWidth, 253 NSMakeRect(0, 0, kModalDialogWidth,
225 GetSyncConfirmationDialogPreferredHeight(browser->profile())), 254 GetSyncConfirmationDialogPreferredHeight(browser->profile())),
226 true /* wait_for_size */); 255 ui::MODAL_TYPE_WINDOW, true /* wait_for_size */);
227 } 256 }
228 257
229 // static 258 // static
230 SigninViewControllerDelegate* 259 SigninViewControllerDelegate*
231 SigninViewControllerDelegate::CreateSigninErrorDelegate( 260 SigninViewControllerDelegate::CreateSigninErrorDelegate(
232 SigninViewController* signin_view_controller, 261 SigninViewController* signin_view_controller,
233 Browser* browser) { 262 Browser* browser) {
234 return new SigninViewControllerDelegateMac( 263 return new SigninViewControllerDelegateMac(
235 signin_view_controller, 264 signin_view_controller,
236 SigninViewControllerDelegateMac::CreateSigninErrorWebContents( 265 SigninViewControllerDelegateMac::CreateSigninErrorWebContents(
237 browser->profile()), 266 browser->profile()),
238 browser, NSMakeRect(0, 0, kModalDialogWidth, kSigninErrorDialogHeight), 267 browser, NSMakeRect(0, 0, kModalDialogWidth, kSigninErrorDialogHeight),
239 true /* wait_for_size */); 268 ui::MODAL_TYPE_WINDOW, true /* wait_for_size */);
240 } 269 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698