OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 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. | |
4 | |
5 #include "chrome/browser/ui/webui/signin/profile_signin_confirmation_dialog.h" | |
6 | |
7 #include "base/json/json_writer.h" | |
8 #include "chrome/browser/profiles/profile_manager.h" | |
9 #include "chrome/browser/ui/browser.h" | |
10 #include "chrome/browser/ui/browser_dialogs.h" | |
11 #include "chrome/browser/ui/browser_finder.h" | |
12 #include "chrome/browser/ui/browser_list.h" | |
13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
14 #include "chrome/browser/ui/web_contents_modal_dialog.h" | |
15 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" | |
16 #include "chrome/common/url_constants.h" | |
17 #include "content/public/browser/web_ui.h" | |
18 #include "content/public/browser/web_ui_message_handler.h" | |
19 #include "grit/browser_resources.h" | |
20 #include "grit/chromium_strings.h" | |
21 #include "grit/generated_resources.h" | |
22 #include "ui/base/l10n/l10n_util.h" | |
23 | |
24 namespace { | |
25 const int kMinimumDialogWidth = 480; | |
James Hawkins
2013/02/12 21:40:40
nit: Blank line above this to be consistent with t
dconnelly
2013/02/13 09:02:27
Done.
| |
26 const int kMinimumDialogHeight = 300; | |
27 | |
28 class ProfileSigninConfirmationHandler : public content::WebUIMessageHandler { | |
29 public: | |
30 ProfileSigninConfirmationHandler( | |
31 const ProfileSigninConfirmationDialog* dialog, | |
32 const base::Closure& cancel_signin, | |
33 const base::Closure& signin_with_new_profile, | |
34 const base::Closure& continue_signin); | |
35 virtual ~ProfileSigninConfirmationHandler(); | |
36 virtual void RegisterMessages() OVERRIDE; | |
37 | |
38 private: | |
39 void OnCancelButtonClicked(const base::ListValue* args); | |
40 void OnCreateProfileClicked(const base::ListValue* args); | |
41 void OnContinueButtonClicked(const base::ListValue* args); | |
42 | |
43 // Weak ptr to parent dialog. | |
44 const ProfileSigninConfirmationDialog* dialog_; | |
45 | |
46 base::Closure cancel_signin_; | |
47 base::Closure signin_with_new_profile_; | |
48 base::Closure continue_signin_; | |
49 }; | |
50 | |
51 } // namespace | |
52 | |
53 ProfileSigninConfirmationHandler::ProfileSigninConfirmationHandler( | |
54 const ProfileSigninConfirmationDialog* dialog, | |
55 const base::Closure& cancel_signin, | |
56 const base::Closure& signin_with_new_profile, | |
57 const base::Closure& continue_signin) | |
58 : dialog_(dialog), | |
59 cancel_signin_(cancel_signin), | |
60 signin_with_new_profile_(signin_with_new_profile), | |
61 continue_signin_(continue_signin) { | |
62 } | |
63 | |
64 ProfileSigninConfirmationHandler::~ProfileSigninConfirmationHandler() { | |
65 } | |
66 | |
67 void ProfileSigninConfirmationHandler::RegisterMessages() { | |
68 web_ui()->RegisterMessageCallback("cancel", | |
69 base::Bind(&ProfileSigninConfirmationHandler::OnCancelButtonClicked, | |
70 base::Unretained(this))); | |
71 web_ui()->RegisterMessageCallback("createNewProfile", | |
72 base::Bind(&ProfileSigninConfirmationHandler::OnCreateProfileClicked, | |
73 base::Unretained(this))); | |
74 web_ui()->RegisterMessageCallback("continue", | |
75 base::Bind(&ProfileSigninConfirmationHandler::OnContinueButtonClicked, | |
76 base::Unretained(this))); | |
77 } | |
78 | |
79 void ProfileSigninConfirmationHandler::OnCancelButtonClicked( | |
80 const base::ListValue* args) { | |
81 // TODO(dconnelly): redirect back to NTP? | |
82 cancel_signin_.Run(); | |
83 dialog_->Close(); | |
84 } | |
85 | |
86 void ProfileSigninConfirmationHandler::OnCreateProfileClicked( | |
87 const base::ListValue* args) { | |
88 signin_with_new_profile_.Run(); | |
89 dialog_->Close(); | |
90 } | |
91 | |
92 void ProfileSigninConfirmationHandler::OnContinueButtonClicked( | |
93 const base::ListValue* args) { | |
94 continue_signin_.Run(); | |
95 dialog_->Close(); | |
96 } | |
97 | |
98 void ProfileSigninConfirmationDialog::ShowDialog( | |
99 Profile* profile, | |
100 const std::string& username, | |
101 const base::Closure& cancel_signin, | |
102 const base::Closure& signin_with_new_profile, | |
103 const base::Closure& continue_signin) { | |
104 new ProfileSigninConfirmationDialog(profile, | |
105 username, | |
106 cancel_signin, | |
107 signin_with_new_profile, | |
108 continue_signin); | |
109 } | |
110 | |
111 ProfileSigninConfirmationDialog::ProfileSigninConfirmationDialog( | |
112 Profile* profile, | |
113 const std::string& username, | |
114 const base::Closure& cancel_signin, | |
115 const base::Closure& signin_with_new_profile, | |
116 const base::Closure& continue_signin) | |
117 : username_(username), | |
118 cancel_signin_(cancel_signin), | |
119 signin_with_new_profile_(signin_with_new_profile), | |
120 continue_signin_(continue_signin) { | |
121 Browser* browser = FindBrowserWithProfile(profile, | |
122 chrome::HOST_DESKTOP_TYPE_FIRST); | |
123 DCHECK(browser); | |
124 delegate_ = CreateConstrainedWebDialog( | |
125 profile, this, NULL, browser->tab_strip_model()->GetActiveWebContents()); | |
126 } | |
127 | |
128 ProfileSigninConfirmationDialog::~ProfileSigninConfirmationDialog() { | |
129 } | |
130 | |
131 void ProfileSigninConfirmationDialog::Close() const { | |
132 closed_by_handler_ = true; | |
133 delegate_->GetWindow()->CloseWebContentsModalDialog(); | |
134 } | |
135 | |
136 ui::ModalType ProfileSigninConfirmationDialog::GetDialogModalType() const { | |
137 return ui::MODAL_TYPE_WINDOW; | |
138 } | |
139 | |
140 string16 ProfileSigninConfirmationDialog::GetDialogTitle() const { | |
141 return l10n_util::GetStringUTF16( | |
142 IDS_ENTERPRISE_SIGNIN_PROFILE_LINK_DIALOG_TITLE); | |
143 } | |
144 | |
145 GURL ProfileSigninConfirmationDialog::GetDialogContentURL() const { | |
146 return GURL(chrome::kChromeUIProfileSigninConfirmationURL); | |
147 } | |
148 | |
149 void ProfileSigninConfirmationDialog::GetWebUIMessageHandlers( | |
150 std::vector<content::WebUIMessageHandler*>* handlers) const { | |
151 handlers->push_back( | |
152 new ProfileSigninConfirmationHandler(this, | |
153 cancel_signin_, | |
154 signin_with_new_profile_, | |
155 continue_signin_)); | |
156 } | |
157 | |
158 void ProfileSigninConfirmationDialog::GetDialogSize(gfx::Size* size) const { | |
159 size->SetSize(kMinimumDialogWidth, kMinimumDialogHeight); | |
160 } | |
161 | |
162 std::string ProfileSigninConfirmationDialog::GetDialogArgs() const { | |
163 std::string data; | |
164 DictionaryValue dict; | |
165 dict.SetString("username", username_); | |
166 base::JSONWriter::Write(&dict, &data); | |
167 return data; | |
168 } | |
169 | |
170 void ProfileSigninConfirmationDialog::OnDialogClosed( | |
171 const std::string& json_retval) { | |
172 if (!closed_by_handler_) | |
173 cancel_signin_.Run(); | |
174 } | |
175 | |
176 void ProfileSigninConfirmationDialog::OnCloseContents( | |
177 content::WebContents* source, | |
178 bool* out_close_dialog) { | |
179 if (out_close_dialog) | |
180 *out_close_dialog = true; | |
181 } | |
182 | |
183 bool ProfileSigninConfirmationDialog::ShouldShowDialogTitle() const { | |
184 return true; | |
185 } | |
OLD | NEW |