Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / profiles / profile_signin_confirmation_dialog_cocoa.mm
bloba46b4ebea48574e68216ba6bd7f40219a2b26740
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"
16 namespace {
18 // static
19 void ShowDialog(
20     Browser* browser,
21     content::WebContents* web_contents,
22     Profile* profile,
23     const std::string& username,
24     ui::ProfileSigninConfirmationDelegate* delegate,
25     bool offer_profile_creation) {
26   // The dialog owns itself.
27   new ProfileSigninConfirmationDialogCocoa(browser,
28                                            web_contents,
29                                            profile,
30                                            username,
31                                            delegate,
32                                            offer_profile_creation);
35 }  // namespace
37 ProfileSigninConfirmationDialogCocoa::ProfileSigninConfirmationDialogCocoa(
38     Browser* browser,
39     content::WebContents* web_contents,
40     Profile* profile,
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));
48   controller_.reset(
49       [[ProfileSigninConfirmationViewController alloc]
50           initWithBrowser:browser
51                  username:username
52                  delegate:delegate
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() {
68 // static
69 void ProfileSigninConfirmationDialogCocoa::Show(
70     Browser* browser,
71     content::WebContents* web_contents,
72     Profile* profile,
73     const std::string& username,
74     ui::ProfileSigninConfirmationDelegate* delegate) {
75   ui::CheckShouldPromptForNewProfile(
76       profile, base::Bind(ShowDialog, browser, web_contents, profile, username,
77                           delegate));
80 void ProfileSigninConfirmationDialogCocoa::Close() {
81   window_->CloseWebContentsModalDialog();
84 void ProfileSigninConfirmationDialogCocoa::OnConstrainedWindowClosed(
85     ConstrainedWindowMac* window) {
86   base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);