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