Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(227)

Side by Side Diff: chrome/browser/ui/webui/chromeos/login/enterprise_enrollment_screen_handler.cc

Issue 8436002: [cros] Remove Views implementation for login/OOBE. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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/chromeos/login/enterprise_enrollment_screen_ha ndler.h"
6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/json/json_reader.h"
10 #include "base/json/json_writer.h"
11 #include "base/utf_string_conversions.h"
12 #include "base/values.h"
13 #include "chrome/common/net/gaia/google_service_auth_error.h"
14 #include "content/browser/renderer_host/render_view_host.h"
15 #include "content/browser/tab_contents/tab_contents.h"
16 #include "grit/generated_resources.h"
17 #include "grit/chromium_strings.h"
18 #include "ui/base/l10n/l10n_util.h"
19
20 namespace chromeos {
21
22 // EnterpriseEnrollmentScreenHandler, public -----------------------------------
23
24 EnterpriseEnrollmentScreenHandler::EnterpriseEnrollmentScreenHandler()
25 : controller_(NULL), editable_user_(true), show_on_init_(false) {
26 }
27
28 EnterpriseEnrollmentScreenHandler::~EnterpriseEnrollmentScreenHandler() {}
29
30 void EnterpriseEnrollmentScreenHandler::SetupGaiaStrings() {
31 if (!controller_) {
32 NOTREACHED();
33 return;
34 }
35 std::string user;
36 bool has_init_user = controller_->GetInitialUser(&user);
37 if (!has_init_user)
38 user = "";
39 // Set the arguments for showing the gaia login page.
40 base::DictionaryValue args;
41 args.SetString("user", user);
42 args.SetInteger("error", 0);
43 args.SetBoolean("editable_user", !has_init_user);
44 std::string json_args;
45 base::JSONWriter::Write(&args, false, &json_args);
46 RenderViewHost* render_view_host =
47 web_ui_->tab_contents()->render_view_host();
48 render_view_host->SetWebUIProperty("dialogArguments", json_args);
49 }
50
51 // EnterpriseEnrollmentScreenHandler, WebUIMessageHandler implementation -------
52
53 void EnterpriseEnrollmentScreenHandler::RegisterMessages() {
54 web_ui_->RegisterMessageCallback(
55 "SubmitAuth",
56 base::Bind(&EnterpriseEnrollmentScreenHandler::HandleSubmitAuth,
57 base::Unretained(this)));
58 web_ui_->RegisterMessageCallback(
59 "DialogClose",
60 base::Bind(&EnterpriseEnrollmentScreenHandler::HandleCancelAuth,
61 base::Unretained(this)));
62 web_ui_->RegisterMessageCallback(
63 "confirmationClose",
64 base::Bind(&EnterpriseEnrollmentScreenHandler::HandleConfirmationClose,
65 base::Unretained(this)));
66 }
67
68 // EnterpriseEnrollmentScreenHandler
69 // EnterpriseEnrollmentScreenActor implementation -------------------------
70
71 void EnterpriseEnrollmentScreenHandler::SetController(Controller* controller) {
72 controller_ = controller;
73 }
74
75 void EnterpriseEnrollmentScreenHandler::PrepareToShow() {
76 }
77
78 void EnterpriseEnrollmentScreenHandler::Show() {
79 SetupGaiaStrings();
80
81 if (!page_is_ready()) {
82 show_on_init_ = true;
83 return;
84 }
85 ShowScreen("enrollment", NULL);
86 }
87
88 void EnterpriseEnrollmentScreenHandler::Hide() {
89 }
90
91 void EnterpriseEnrollmentScreenHandler::SetEditableUser(bool editable) {
92 editable_user_ = editable;
93 }
94
95 void EnterpriseEnrollmentScreenHandler::ShowConfirmationScreen() {
96 web_ui_->CallJavascriptFunction(
97 "oobe.EnrollmentScreen.showConfirmationScreen");
98 NotifyObservers(true);
99 }
100
101 void EnterpriseEnrollmentScreenHandler::ShowAuthError(
102 const GoogleServiceAuthError& error) {
103 base::DictionaryValue args;
104 args.SetInteger("error", error.state());
105 args.SetBoolean("editable_user", editable_user_);
106 args.SetString("captchaUrl", error.captcha().image_url.spec());
107 UpdateGaiaLogin(args);
108 }
109
110 void EnterpriseEnrollmentScreenHandler::ShowAccountError() {
111 ShowError(IDS_ENTERPRISE_ENROLLMENT_ACCOUNT_ERROR);
112 NotifyObservers(false);
113 }
114
115 void EnterpriseEnrollmentScreenHandler::ShowSerialNumberError() {
116 ShowError(IDS_ENTERPRISE_ENROLLMENT_SERIAL_NUMBER_ERROR);
117 NotifyObservers(false);
118 }
119
120 void EnterpriseEnrollmentScreenHandler::ShowFatalAuthError() {
121 ShowError(IDS_ENTERPRISE_ENROLLMENT_FATAL_AUTH_ERROR);
122 NotifyObservers(false);
123 }
124
125 void EnterpriseEnrollmentScreenHandler::ShowFatalEnrollmentError() {
126 ShowError(IDS_ENTERPRISE_ENROLLMENT_FATAL_ENROLLMENT_ERROR);
127 NotifyObservers(false);
128 }
129
130 void EnterpriseEnrollmentScreenHandler::ShowNetworkEnrollmentError() {
131 ShowError(IDS_ENTERPRISE_ENROLLMENT_NETWORK_ENROLLMENT_ERROR);
132 NotifyObservers(false);
133 }
134
135 // EnterpriseEnrollmentScreenHandler BaseScreenHandler implementation ---------
136
137 void EnterpriseEnrollmentScreenHandler::GetLocalizedStrings(
138 base::DictionaryValue *localized_strings) {
139
140 localized_strings->SetString(
141 "loginHeader",
142 l10n_util::GetStringUTF16(IDS_ENTERPRISE_ENROLLMENT_LOGIN_HEADER));
143 localized_strings->SetString(
144 "loginExplain",
145 l10n_util::GetStringFUTF16(IDS_ENTERPRISE_ENROLLMENT_LOGIN_EXPLAIN,
146 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)));
147 localized_strings->SetString(
148 "cloudHeader",
149 l10n_util::GetStringUTF16(IDS_ENTERPRISE_ENROLLMENT_CLOUD_HEADER));
150 localized_strings->SetString(
151 "cloudExplain",
152 l10n_util::GetStringUTF16(IDS_ENTERPRISE_ENROLLMENT_CLOUD_EXPLAIN));
153 localized_strings->SetString(
154 "accesscontrolHeader",
155 l10n_util::GetStringUTF16(
156 IDS_ENTERPRISE_ENROLLMENT_ACCESSCONTROL_HEADER));
157 localized_strings->SetString(
158 "accesscontrolExplain",
159 l10n_util::GetStringUTF16(
160 IDS_ENTERPRISE_ENROLLMENT_ACCESSCONTROL_EXPLAIN));
161 localized_strings->SetString(
162 "confirmationHeader",
163 l10n_util::GetStringUTF16(IDS_ENTERPRISE_ENROLLMENT_CONFIRMATION_HEADER));
164 localized_strings->SetString(
165 "confirmationMessage",
166 l10n_util::GetStringUTF16(
167 IDS_ENTERPRISE_ENROLLMENT_CONFIRMATION_MESSAGE));
168 localized_strings->SetString(
169 "confirmationClose",
170 l10n_util::GetStringUTF16(IDS_ENTERPRISE_ENROLLMENT_CONFIRMATION_CLOSE));
171
172 localized_strings->SetString("invalidpasswordhelpurl", "");
173 localized_strings->SetString("invalidaccessaccounturl", "");
174 localized_strings->SetString("cannotaccessaccount", "");
175 localized_strings->SetString("cannotaccessaccounturl", "");
176 localized_strings->SetString("createaccount", "");
177 localized_strings->SetString("createnewaccounturl", "");
178 localized_strings->SetString("getaccesscodehelp", "");
179 localized_strings->SetString("getaccesscodeurl", "");
180
181 // None of the strings used here currently have sync-specific wording in
182 // them. We have a unit test to catch if that happens.
183 localized_strings->SetString("introduction", "");
184 localized_strings->SetString(
185 "signinprefix", l10n_util::GetStringUTF16(IDS_SYNC_LOGIN_SIGNIN_PREFIX));
186 localized_strings->SetString(
187 "signinsuffix", l10n_util::GetStringUTF16(IDS_SYNC_LOGIN_SIGNIN_SUFFIX));
188 localized_strings->SetString(
189 "cannotbeblank", l10n_util::GetStringUTF16(IDS_SYNC_CANNOT_BE_BLANK));
190 localized_strings->SetString("emaillabel", l10n_util::GetStringUTF16(
191 IDS_SYNC_LOGIN_EMAIL_SAME_LINE));
192 localized_strings->SetString("passwordlabel", l10n_util::GetStringUTF16(
193 IDS_SYNC_LOGIN_PASSWORD_SAME_LINE));
194 localized_strings->SetString(
195 "invalidcredentials",
196 l10n_util::GetStringUTF16(IDS_SYNC_INVALID_USER_CREDENTIALS));
197 localized_strings->SetString("signin",
198 l10n_util::GetStringUTF16(IDS_SYNC_SIGNIN));
199 localized_strings->SetString(
200 "couldnotconnect",
201 l10n_util::GetStringUTF16(IDS_SYNC_LOGIN_COULD_NOT_CONNECT));
202 localized_strings->SetString("cancel", l10n_util::GetStringUTF16(IDS_CANCEL));
203 localized_strings->SetString(
204 "settingup", l10n_util::GetStringUTF16(IDS_SYNC_LOGIN_SETTING_UP));
205 localized_strings->SetString("success",
206 l10n_util::GetStringUTF16(IDS_SYNC_SUCCESS));
207 localized_strings->SetString(
208 "errorsigningin", l10n_util::GetStringUTF16(IDS_SYNC_ERROR_SIGNING_IN));
209 localized_strings->SetString(
210 "captchainstructions",
211 l10n_util::GetStringUTF16(IDS_SYNC_GAIA_CAPTCHA_INSTRUCTIONS));
212 localized_strings->SetString(
213 "invalidaccesscode",
214 l10n_util::GetStringUTF16(IDS_SYNC_INVALID_ACCESS_CODE_LABEL));
215 localized_strings->SetString(
216 "enteraccesscode",
217 l10n_util::GetStringUTF16(IDS_SYNC_ENTER_ACCESS_CODE_LABEL));
218 }
219
220 void EnterpriseEnrollmentScreenHandler::Initialize() {
221 if (show_on_init_) {
222 Show();
223 show_on_init_ = false;
224 }
225 }
226
227 // EnterpriseEnrollmentScreenHandler, private ----------------------------------
228
229 void EnterpriseEnrollmentScreenHandler::HandleSubmitAuth(
230 const base::ListValue* value) {
231 if (!controller_) {
232 NOTREACHED();
233 return;
234 }
235
236 // Value carries single list entry, which is a json-encoded string that
237 // contains the auth parameters (see gaia_login.js).
238 std::string json_params;
239 if (!value->GetString(0, &json_params)) {
240 NOTREACHED();
241 return;
242 }
243
244 // Check the value type.
245 scoped_ptr<base::Value> params(base::JSONReader::Read(json_params, false));
246 if (!params.get() || !params->IsType(base::Value::TYPE_DICTIONARY)) {
247 NOTREACHED();
248 return;
249 }
250
251 // Read the parameters.
252 base::DictionaryValue* params_dict =
253 static_cast<base::DictionaryValue*>(params.get());
254 std::string user;
255 std::string pass;
256 std::string captcha;
257 std::string access_code;
258 if (!params_dict->GetString("user", &user) ||
259 !params_dict->GetString("pass", &pass) ||
260 !params_dict->GetString("captcha", &captcha) ||
261 !params_dict->GetString("access_code", &access_code)) {
262 NOTREACHED();
263 return;
264 }
265
266 controller_->OnAuthSubmitted(user, pass, captcha, access_code);
267 }
268
269 void EnterpriseEnrollmentScreenHandler::HandleCancelAuth(
270 const base::ListValue* value) {
271 if (!controller_) {
272 NOTREACHED();
273 return;
274 }
275
276 controller_->OnAuthCancelled();
277 }
278
279 void EnterpriseEnrollmentScreenHandler::HandleConfirmationClose(
280 const base::ListValue* value) {
281 if (!controller_) {
282 NOTREACHED();
283 return;
284 }
285
286 controller_->OnConfirmationClosed();
287 }
288
289 void EnterpriseEnrollmentScreenHandler::ShowError(int message_id) {
290 base::DictionaryValue args;
291 args.SetInteger("error", GoogleServiceAuthError::NONE);
292 args.SetBoolean("editable_user", editable_user_);
293 args.SetString("error_message", l10n_util::GetStringUTF16(message_id));
294 UpdateGaiaLogin(args);
295 }
296
297 void EnterpriseEnrollmentScreenHandler::UpdateGaiaLogin(
298 const base::DictionaryValue& args) {
299 std::string json;
300 base::JSONWriter::Write(&args, false, &json);
301
302 RenderViewHost* render_view_host =
303 web_ui_->tab_contents()->render_view_host();
304 render_view_host->ExecuteJavascriptInWebFrame(
305 ASCIIToUTF16("//iframe[@id='gaia-local-login']"),
306 UTF8ToUTF16("showGaiaLogin(" + json + ");"));
307 }
308
309 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698