OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #import "chrome/browser/ui/cocoa/profiles/profile_signin_confirmation_dialog_coc
oa.h" | 5 #import "chrome/browser/ui/cocoa/profiles/profile_signin_confirmation_dialog_coc
oa.h" |
6 | 6 |
7 #include "base/threading/thread_task_runner_handle.h" | 7 #include "base/threading/thread_task_runner_handle.h" |
8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
9 #include "chrome/browser/ui/browser_finder.h" | 9 #include "chrome/browser/ui/browser_finder.h" |
10 #include "chrome/browser/ui/browser_window.h" | 10 #include "chrome/browser/ui/browser_window.h" |
11 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sh
eet.h" | 11 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sh
eet.h" |
12 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_wi
ndow.h" | 12 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_wi
ndow.h" |
13 #include "chrome/browser/ui/sync/profile_signin_confirmation_helper.h" | 13 #include "chrome/browser/ui/sync/profile_signin_confirmation_helper.h" |
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 // static | 18 // static |
19 void ShowDialog(Browser* browser, | 19 void ShowDialog( |
20 content::WebContents* web_contents, | 20 Browser* browser, |
21 Profile* profile, | 21 content::WebContents* web_contents, |
22 const std::string& username, | 22 Profile* profile, |
23 std::unique_ptr<ui::ProfileSigninConfirmationDelegate> delegate, | 23 const std::string& username, |
24 bool offer_profile_creation) { | 24 ui::ProfileSigninConfirmationDelegate* delegate, |
| 25 bool offer_profile_creation) { |
25 // The dialog owns itself. | 26 // The dialog owns itself. |
26 new ProfileSigninConfirmationDialogCocoa(browser, web_contents, profile, | 27 new ProfileSigninConfirmationDialogCocoa(browser, |
27 username, std::move(delegate), | 28 web_contents, |
| 29 profile, |
| 30 username, |
| 31 delegate, |
28 offer_profile_creation); | 32 offer_profile_creation); |
29 } | 33 } |
30 | 34 |
31 } // namespace | 35 } // namespace |
32 | 36 |
33 ProfileSigninConfirmationDialogCocoa::ProfileSigninConfirmationDialogCocoa( | 37 ProfileSigninConfirmationDialogCocoa::ProfileSigninConfirmationDialogCocoa( |
34 Browser* browser, | 38 Browser* browser, |
35 content::WebContents* web_contents, | 39 content::WebContents* web_contents, |
36 Profile* profile, | 40 Profile* profile, |
37 const std::string& username, | 41 const std::string& username, |
38 std::unique_ptr<ui::ProfileSigninConfirmationDelegate> delegate, | 42 ui::ProfileSigninConfirmationDelegate* delegate, |
39 bool offer_profile_creation) { | 43 bool offer_profile_creation) { |
40 // Setup the dialog view controller. | 44 // Setup the dialog view controller. |
41 const base::Closure& closeDialogCallback = | 45 const base::Closure& closeDialogCallback = |
42 base::Bind(&ProfileSigninConfirmationDialogCocoa::Close, | 46 base::Bind(&ProfileSigninConfirmationDialogCocoa::Close, |
43 base::Unretained(this)); | 47 base::Unretained(this)); |
44 controller_.reset([[ProfileSigninConfirmationViewController alloc] | 48 controller_.reset( |
45 initWithBrowser:browser | 49 [[ProfileSigninConfirmationViewController alloc] |
46 username:username | 50 initWithBrowser:browser |
47 delegate:std::move(delegate) | 51 username:username |
48 closeDialogCallback:closeDialogCallback | 52 delegate:delegate |
49 offerProfileCreation:offer_profile_creation]); | 53 closeDialogCallback:closeDialogCallback |
| 54 offerProfileCreation:offer_profile_creation]); |
50 | 55 |
51 // Setup the constrained window that will show the view. | 56 // Setup the constrained window that will show the view. |
52 base::scoped_nsobject<NSWindow> window([[ConstrainedWindowCustomWindow alloc] | 57 base::scoped_nsobject<NSWindow> window([[ConstrainedWindowCustomWindow alloc] |
53 initWithContentRect:[[controller_ view] bounds]]); | 58 initWithContentRect:[[controller_ view] bounds]]); |
54 [[window contentView] addSubview:[controller_ view]]; | 59 [[window contentView] addSubview:[controller_ view]]; |
55 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet( | 60 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet( |
56 [[CustomConstrainedWindowSheet alloc] initWithCustomWindow:window]); | 61 [[CustomConstrainedWindowSheet alloc] initWithCustomWindow:window]); |
57 window_ = CreateAndShowWebModalDialogMac(this, web_contents, sheet); | 62 window_ = CreateAndShowWebModalDialogMac(this, web_contents, sheet); |
58 } | 63 } |
59 | 64 |
60 ProfileSigninConfirmationDialogCocoa::~ProfileSigninConfirmationDialogCocoa() { | 65 ProfileSigninConfirmationDialogCocoa::~ProfileSigninConfirmationDialogCocoa() { |
61 } | 66 } |
62 | 67 |
63 // static | 68 // static |
64 void ProfileSigninConfirmationDialogCocoa::Show( | 69 void ProfileSigninConfirmationDialogCocoa::Show( |
65 Browser* browser, | 70 Browser* browser, |
66 content::WebContents* web_contents, | 71 content::WebContents* web_contents, |
67 Profile* profile, | 72 Profile* profile, |
68 const std::string& username, | 73 const std::string& username, |
69 std::unique_ptr<ui::ProfileSigninConfirmationDelegate> delegate) { | 74 ui::ProfileSigninConfirmationDelegate* delegate) { |
70 ui::CheckShouldPromptForNewProfile( | 75 ui::CheckShouldPromptForNewProfile( |
71 profile, base::Bind(ShowDialog, browser, web_contents, profile, username, | 76 profile, base::Bind(ShowDialog, browser, web_contents, profile, username, |
72 base::Passed(std::move(delegate)))); | 77 delegate)); |
73 } | 78 } |
74 | 79 |
75 void ProfileSigninConfirmationDialogCocoa::Close() { | 80 void ProfileSigninConfirmationDialogCocoa::Close() { |
76 window_->CloseWebContentsModalDialog(); | 81 window_->CloseWebContentsModalDialog(); |
77 } | 82 } |
78 | 83 |
79 void ProfileSigninConfirmationDialogCocoa::OnConstrainedWindowClosed( | 84 void ProfileSigninConfirmationDialogCocoa::OnConstrainedWindowClosed( |
80 ConstrainedWindowMac* window) { | 85 ConstrainedWindowMac* window) { |
81 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); | 86 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); |
82 } | 87 } |
OLD | NEW |