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_dialogs.h"
10 #include "chrome/browser/ui/browser_finder.h"
11 #include "chrome/browser/ui/browser_window.h"
12 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sheet.h"
13 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_window.h"
14 #include "chrome/browser/ui/sync/profile_signin_confirmation_helper.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
22 content::WebContents* web_contents,
24 const std::string& username,
25 ui::ProfileSigninConfirmationDelegate* delegate,
26 bool offer_profile_creation) {
27 // The dialog owns itself.
28 new ProfileSigninConfirmationDialogCocoa(browser,
33 offer_profile_creation);
40 // Declared in browser_dialogs.h
41 void ShowProfileSigninConfirmationDialog(
43 content::WebContents* web_contents,
45 const std::string& username,
46 ui::ProfileSigninConfirmationDelegate* delegate) {
47 ui::CheckShouldPromptForNewProfile(
49 base::Bind(ShowDialog,
50 browser, web_contents, profile, username, delegate));
55 ProfileSigninConfirmationDialogCocoa::ProfileSigninConfirmationDialogCocoa(
57 content::WebContents* web_contents,
59 const std::string& username,
60 ui::ProfileSigninConfirmationDelegate* delegate,
61 bool offer_profile_creation) {
62 // Setup the dialog view controller.
63 const base::Closure& closeDialogCallback =
64 base::Bind(&ProfileSigninConfirmationDialogCocoa::Close,
65 base::Unretained(this));
67 [[ProfileSigninConfirmationViewController alloc]
68 initWithBrowser:browser
71 closeDialogCallback:closeDialogCallback
72 offerProfileCreation:offer_profile_creation]);
74 // Setup the constrained window that will show the view.
75 base::scoped_nsobject<NSWindow> window([[ConstrainedWindowCustomWindow alloc]
76 initWithContentRect:[[controller_ view] bounds]]);
77 [[window contentView] addSubview:[controller_ view]];
78 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet(
79 [[CustomConstrainedWindowSheet alloc] initWithCustomWindow:window]);
80 window_.reset(new ConstrainedWindowMac(this, web_contents, sheet));
83 ProfileSigninConfirmationDialogCocoa::~ProfileSigninConfirmationDialogCocoa() {
86 void ProfileSigninConfirmationDialogCocoa::Close() {
87 window_->CloseWebContentsModalDialog();
90 void ProfileSigninConfirmationDialogCocoa::OnConstrainedWindowClosed(
91 ConstrainedWindowMac* window) {
92 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);