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
3 // found in the LICENSE file.
5 #import "chrome/browser/ui/cocoa/profiles/profile_signin_confirmation_dialog_cocoa.h"
7 #include "base/message_loop/message_loop.h"
8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_finder.h"
10 #include "chrome/browser/ui/browser_window.h"
11 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sheet.h"
12 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_window.h"
13 #include "chrome/browser/ui/sync/profile_signin_confirmation_helper.h"
14 #include "chrome/browser/ui/tabs/tab_strip_model.h"
21 content::WebContents* web_contents,
23 const std::string& username,
24 ui::ProfileSigninConfirmationDelegate* delegate,
25 bool offer_profile_creation) {
26 // The dialog owns itself.
27 new ProfileSigninConfirmationDialogCocoa(browser,
32 offer_profile_creation);
37 ProfileSigninConfirmationDialogCocoa::ProfileSigninConfirmationDialogCocoa(
39 content::WebContents* web_contents,
41 const std::string& username,
42 ui::ProfileSigninConfirmationDelegate* delegate,
43 bool offer_profile_creation) {
44 // Setup the dialog view controller.
45 const base::Closure& closeDialogCallback =
46 base::Bind(&ProfileSigninConfirmationDialogCocoa::Close,
47 base::Unretained(this));
49 [[ProfileSigninConfirmationViewController alloc]
50 initWithBrowser:browser
53 closeDialogCallback:closeDialogCallback
54 offerProfileCreation:offer_profile_creation]);
56 // Setup the constrained window that will show the view.
57 base::scoped_nsobject<NSWindow> window([[ConstrainedWindowCustomWindow alloc]
58 initWithContentRect:[[controller_ view] bounds]]);
59 [[window contentView] addSubview:[controller_ view]];
60 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet(
61 [[CustomConstrainedWindowSheet alloc] initWithCustomWindow:window]);
62 window_.reset(new ConstrainedWindowMac(this, web_contents, sheet));
65 ProfileSigninConfirmationDialogCocoa::~ProfileSigninConfirmationDialogCocoa() {
69 void ProfileSigninConfirmationDialogCocoa::Show(
71 content::WebContents* web_contents,
73 const std::string& username,
74 ui::ProfileSigninConfirmationDelegate* delegate) {
75 ui::CheckShouldPromptForNewProfile(
76 profile, base::Bind(ShowDialog, browser, web_contents, profile, username,
80 void ProfileSigninConfirmationDialogCocoa::Close() {
81 window_->CloseWebContentsModalDialog();
84 void ProfileSigninConfirmationDialogCocoa::OnConstrainedWindowClosed(
85 ConstrainedWindowMac* window) {
86 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);