Extend EnrollmentHandler to handle consumer management.
[chromium-blink-merge.git] / chrome / browser / ui / webui / chromeos / login / enrollment_screen_handler.cc
blobec2f2cf50544f5ec0f4d7b9c9fb9694aab00b7d2
1 // Copyright (c) 2012 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 #include "chrome/browser/ui/webui/chromeos/login/enrollment_screen_handler.h"
7 #include <algorithm>
9 #include "base/bind.h"
10 #include "base/bind_helpers.h"
11 #include "base/compiler_specific.h"
12 #include "base/macros.h"
13 #include "base/message_loop/message_loop.h"
14 #include "base/strings/string_util.h"
15 #include "base/values.h"
16 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/browsing_data/browsing_data_helper.h"
18 #include "chrome/browser/browsing_data/browsing_data_remover.h"
19 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
20 #include "chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.h"
21 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/ui/webui/chromeos/login/authenticated_user_email_retriever.h"
23 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
24 #include "chromeos/network/network_state.h"
25 #include "chromeos/network/network_state_handler.h"
26 #include "components/policy/core/browser/cloud/message_util.h"
27 #include "content/public/browser/web_contents.h"
28 #include "google_apis/gaia/gaia_auth_fetcher.h"
29 #include "google_apis/gaia/gaia_auth_util.h"
30 #include "google_apis/gaia/gaia_constants.h"
31 #include "google_apis/gaia/gaia_urls.h"
32 #include "google_apis/gaia/google_service_auth_error.h"
33 #include "grit/chromium_strings.h"
34 #include "grit/generated_resources.h"
35 #include "net/url_request/url_request_context_getter.h"
36 #include "ui/base/l10n/l10n_util.h"
38 namespace chromeos {
39 namespace {
41 const char kJsScreenPath[] = "login.OAuthEnrollmentScreen";
43 // Start page of GAIA authentication extension.
44 const char kGaiaExtStartPage[] =
45 "chrome-extension://mfffpogegjflfpflabcdkioaeobkgjik/main.html";
47 // Enrollment step names.
48 const char kEnrollmentStepSignin[] = "signin";
49 const char kEnrollmentStepSuccess[] = "success";
51 // Enrollment mode strings.
52 const char* const kModeStrings[EnrollmentScreenActor::ENROLLMENT_MODE_COUNT] =
53 { "manual", "forced", "auto", "recovery" };
55 std::string EnrollmentModeToString(EnrollmentScreenActor::EnrollmentMode mode) {
56 CHECK(0 <= mode && mode < EnrollmentScreenActor::ENROLLMENT_MODE_COUNT);
57 return kModeStrings[mode];
60 // A helper class that takes care of asynchronously revoking a given token.
61 class TokenRevoker : public GaiaAuthConsumer {
62 public:
63 TokenRevoker()
64 : gaia_fetcher_(this,
65 GaiaConstants::kChromeOSSource,
66 g_browser_process->system_request_context()) {}
67 virtual ~TokenRevoker() {}
69 void Start(const std::string& token) {
70 gaia_fetcher_.StartRevokeOAuth2Token(token);
73 // GaiaAuthConsumer:
74 virtual void OnOAuth2RevokeTokenCompleted() OVERRIDE {
75 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
78 private:
79 GaiaAuthFetcher gaia_fetcher_;
81 DISALLOW_COPY_AND_ASSIGN(TokenRevoker);
84 // Returns network name by service path.
85 std::string GetNetworkName(const std::string& service_path) {
86 const NetworkState* network =
87 NetworkHandler::Get()->network_state_handler()->GetNetworkState(
88 service_path);
89 if (!network)
90 return std::string();
91 return network->name();
94 bool IsBehindCaptivePortal(NetworkStateInformer::State state,
95 ErrorScreenActor::ErrorReason reason) {
96 return state == NetworkStateInformer::CAPTIVE_PORTAL ||
97 reason == ErrorScreenActor::ERROR_REASON_PORTAL_DETECTED;
100 bool IsProxyError(NetworkStateInformer::State state,
101 ErrorScreenActor::ErrorReason reason) {
102 return state == NetworkStateInformer::PROXY_AUTH_REQUIRED ||
103 reason == ErrorScreenActor::ERROR_REASON_PROXY_AUTH_CANCELLED ||
104 reason == ErrorScreenActor::ERROR_REASON_PROXY_CONNECTION_FAILED;
107 } // namespace
109 // EnrollmentScreenHandler, public ------------------------------
111 EnrollmentScreenHandler::EnrollmentScreenHandler(
112 const scoped_refptr<NetworkStateInformer>& network_state_informer,
113 ErrorScreenActor* error_screen_actor)
114 : BaseScreenHandler(kJsScreenPath),
115 controller_(NULL),
116 show_on_init_(false),
117 enrollment_mode_(ENROLLMENT_MODE_MANUAL),
118 browsing_data_remover_(NULL),
119 frame_error_(net::OK),
120 network_state_informer_(network_state_informer),
121 error_screen_actor_(error_screen_actor),
122 weak_ptr_factory_(this) {
123 set_async_assets_load_id(OobeUI::kScreenOobeEnrollment);
124 DCHECK(network_state_informer_.get());
125 DCHECK(error_screen_actor_);
126 network_state_informer_->AddObserver(this);
128 if (chromeos::LoginDisplayHostImpl::default_host()) {
129 chromeos::WebUILoginView* login_view =
130 chromeos::LoginDisplayHostImpl::default_host()->GetWebUILoginView();
131 if (login_view)
132 login_view->AddFrameObserver(this);
136 EnrollmentScreenHandler::~EnrollmentScreenHandler() {
137 if (browsing_data_remover_)
138 browsing_data_remover_->RemoveObserver(this);
139 network_state_informer_->RemoveObserver(this);
141 if (chromeos::LoginDisplayHostImpl::default_host()) {
142 chromeos::WebUILoginView* login_view =
143 chromeos::LoginDisplayHostImpl::default_host()->GetWebUILoginView();
144 if (login_view)
145 login_view->RemoveFrameObserver(this);
149 // EnrollmentScreenHandler, WebUIMessageHandler implementation --
151 void EnrollmentScreenHandler::RegisterMessages() {
152 AddCallback("oauthEnrollRetrieveAuthenticatedUserEmail",
153 &EnrollmentScreenHandler::HandleRetrieveAuthenticatedUserEmail);
154 AddCallback("oauthEnrollClose",
155 &EnrollmentScreenHandler::HandleClose);
156 AddCallback("oauthEnrollCompleteLogin",
157 &EnrollmentScreenHandler::HandleCompleteLogin);
158 AddCallback("oauthEnrollRetry",
159 &EnrollmentScreenHandler::HandleRetry);
160 AddCallback("frameLoadingCompleted",
161 &EnrollmentScreenHandler::HandleFrameLoadingCompleted);
164 // EnrollmentScreenHandler
165 // EnrollmentScreenActor implementation -----------------------------------
167 void EnrollmentScreenHandler::SetParameters(
168 Controller* controller,
169 EnrollmentMode enrollment_mode,
170 const std::string& management_domain) {
171 controller_ = controller;
172 enrollment_mode_ = enrollment_mode;
173 management_domain_ = management_domain;
176 void EnrollmentScreenHandler::PrepareToShow() {
179 void EnrollmentScreenHandler::Show() {
180 if (!page_is_ready())
181 show_on_init_ = true;
182 else
183 DoShow();
186 void EnrollmentScreenHandler::Hide() {
189 void EnrollmentScreenHandler::FetchOAuthToken() {
190 Profile* profile = Profile::FromWebUI(web_ui());
191 oauth_fetcher_.reset(
192 new policy::PolicyOAuth2TokenFetcher(
193 profile->GetRequestContext(),
194 g_browser_process->system_request_context(),
195 base::Bind(&EnrollmentScreenHandler::OnTokenFetched,
196 base::Unretained(this))));
197 oauth_fetcher_->Start();
200 void EnrollmentScreenHandler::ResetAuth(const base::Closure& callback) {
201 auth_reset_callbacks_.push_back(callback);
202 if (browsing_data_remover_)
203 return;
205 if (oauth_fetcher_) {
206 if (!oauth_fetcher_->oauth2_access_token().empty())
207 (new TokenRevoker())->Start(oauth_fetcher_->oauth2_access_token());
209 if (!oauth_fetcher_->oauth2_refresh_token().empty())
210 (new TokenRevoker())->Start(oauth_fetcher_->oauth2_refresh_token());
213 Profile* profile = Profile::FromBrowserContext(
214 web_ui()->GetWebContents()->GetBrowserContext());
215 browsing_data_remover_ =
216 BrowsingDataRemover::CreateForUnboundedRange(profile);
217 browsing_data_remover_->AddObserver(this);
218 browsing_data_remover_->Remove(BrowsingDataRemover::REMOVE_SITE_DATA,
219 BrowsingDataHelper::UNPROTECTED_WEB);
222 void EnrollmentScreenHandler::ShowSigninScreen() {
223 ShowStep(kEnrollmentStepSignin);
226 void EnrollmentScreenHandler::ShowEnrollmentSpinnerScreen() {
227 ShowWorking(IDS_ENTERPRISE_ENROLLMENT_WORKING);
230 void EnrollmentScreenHandler::ShowLoginSpinnerScreen() {
231 ShowWorking(IDS_ENTERPRISE_ENROLLMENT_RESUMING_LOGIN);
234 void EnrollmentScreenHandler::ShowAuthError(
235 const GoogleServiceAuthError& error) {
236 switch (error.state()) {
237 case GoogleServiceAuthError::NONE:
238 case GoogleServiceAuthError::CAPTCHA_REQUIRED:
239 case GoogleServiceAuthError::TWO_FACTOR:
240 case GoogleServiceAuthError::HOSTED_NOT_ALLOWED:
241 case GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS:
242 case GoogleServiceAuthError::REQUEST_CANCELED:
243 case GoogleServiceAuthError::UNEXPECTED_SERVICE_RESPONSE:
244 case GoogleServiceAuthError::SERVICE_ERROR:
245 ShowError(IDS_ENTERPRISE_ENROLLMENT_AUTH_FATAL_ERROR, false);
246 return;
247 case GoogleServiceAuthError::USER_NOT_SIGNED_UP:
248 case GoogleServiceAuthError::ACCOUNT_DELETED:
249 case GoogleServiceAuthError::ACCOUNT_DISABLED:
250 ShowError(IDS_ENTERPRISE_ENROLLMENT_AUTH_ACCOUNT_ERROR, true);
251 return;
252 case GoogleServiceAuthError::CONNECTION_FAILED:
253 case GoogleServiceAuthError::SERVICE_UNAVAILABLE:
254 ShowError(IDS_ENTERPRISE_ENROLLMENT_AUTH_NETWORK_ERROR, true);
255 return;
256 case GoogleServiceAuthError::NUM_STATES:
257 break;
259 NOTREACHED();
262 void EnrollmentScreenHandler::ShowUIError(UIError error) {
263 switch (error) {
264 case UI_ERROR_DOMAIN_MISMATCH:
265 ShowError(IDS_ENTERPRISE_ENROLLMENT_STATUS_LOCK_WRONG_USER, true);
266 return;
267 case UI_ERROR_AUTO_ENROLLMENT_BAD_MODE:
268 ShowError(IDS_ENTERPRISE_AUTO_ENROLLMENT_BAD_MODE, true);
269 return;
270 case UI_ERROR_FATAL:
271 ShowError(IDS_ENTERPRISE_ENROLLMENT_FATAL_ENROLLMENT_ERROR, true);
272 return;
274 NOTREACHED();
277 void EnrollmentScreenHandler::ShowEnrollmentStatus(
278 policy::EnrollmentStatus status) {
279 switch (status.status()) {
280 case policy::EnrollmentStatus::STATUS_SUCCESS:
281 ShowStep(kEnrollmentStepSuccess);
282 return;
283 case policy::EnrollmentStatus::STATUS_NO_STATE_KEYS:
284 ShowError(IDS_ENTERPRISE_ENROLLMENT_STATUS_NO_STATE_KEYS, false);
285 return;
286 case policy::EnrollmentStatus::STATUS_REGISTRATION_FAILED:
287 // Some special cases for generating a nicer message that's more helpful.
288 switch (status.client_status()) {
289 case policy::DM_STATUS_SERVICE_MANAGEMENT_NOT_SUPPORTED:
290 ShowError(IDS_ENTERPRISE_ENROLLMENT_ACCOUNT_ERROR, true);
291 break;
292 case policy::DM_STATUS_SERVICE_MISSING_LICENSES:
293 ShowError(IDS_ENTERPRISE_ENROLLMENT_MISSING_LICENSES_ERROR, true);
294 break;
295 case policy::DM_STATUS_SERVICE_DEPROVISIONED:
296 ShowError(IDS_ENTERPRISE_ENROLLMENT_DEPROVISIONED_ERROR, true);
297 break;
298 case policy::DM_STATUS_SERVICE_DOMAIN_MISMATCH:
299 ShowError(IDS_ENTERPRISE_ENROLLMENT_DOMAIN_MISMATCH_ERROR, true);
300 break;
301 default:
302 ShowErrorMessage(
303 l10n_util::GetStringFUTF8(
304 IDS_ENTERPRISE_ENROLLMENT_STATUS_REGISTRATION_FAILED,
305 policy::FormatDeviceManagementStatus(status.client_status())),
306 true);
308 return;
309 case policy::EnrollmentStatus::STATUS_ROBOT_AUTH_FETCH_FAILED:
310 ShowError(IDS_ENTERPRISE_ENROLLMENT_ROBOT_AUTH_FETCH_FAILED, true);
311 return;
312 case policy::EnrollmentStatus::STATUS_ROBOT_REFRESH_FETCH_FAILED:
313 ShowError(IDS_ENTERPRISE_ENROLLMENT_ROBOT_REFRESH_FETCH_FAILED, true);
314 return;
315 case policy::EnrollmentStatus::STATUS_ROBOT_REFRESH_STORE_FAILED:
316 ShowError(IDS_ENTERPRISE_ENROLLMENT_ROBOT_REFRESH_STORE_FAILED, true);
317 return;
318 case policy::EnrollmentStatus::STATUS_REGISTRATION_BAD_MODE:
319 ShowError(IDS_ENTERPRISE_ENROLLMENT_STATUS_REGISTRATION_BAD_MODE, false);
320 return;
321 case policy::EnrollmentStatus::STATUS_POLICY_FETCH_FAILED:
322 ShowErrorMessage(
323 l10n_util::GetStringFUTF8(
324 IDS_ENTERPRISE_ENROLLMENT_STATUS_POLICY_FETCH_FAILED,
325 policy::FormatDeviceManagementStatus(status.client_status())),
326 true);
327 return;
328 case policy::EnrollmentStatus::STATUS_VALIDATION_FAILED:
329 ShowErrorMessage(
330 l10n_util::GetStringFUTF8(
331 IDS_ENTERPRISE_ENROLLMENT_STATUS_VALIDATION_FAILED,
332 policy::FormatValidationStatus(status.validation_status())),
333 true);
334 return;
335 case policy::EnrollmentStatus::STATUS_LOCK_ERROR:
336 ShowError(IDS_ENTERPRISE_ENROLLMENT_STATUS_LOCK_ERROR, false);
337 return;
338 case policy::EnrollmentStatus::STATUS_LOCK_TIMEOUT:
339 ShowError(IDS_ENTERPRISE_ENROLLMENT_STATUS_LOCK_TIMEOUT, false);
340 return;
341 case policy::EnrollmentStatus::STATUS_LOCK_WRONG_USER:
342 ShowError(IDS_ENTERPRISE_ENROLLMENT_STATUS_LOCK_WRONG_USER, true);
343 return;
344 case policy::EnrollmentStatus::STATUS_STORE_ERROR:
345 ShowErrorMessage(
346 l10n_util::GetStringFUTF8(
347 IDS_ENTERPRISE_ENROLLMENT_STATUS_STORE_ERROR,
348 policy::FormatStoreStatus(status.store_status(),
349 status.validation_status())),
350 true);
351 return;
352 case policy::EnrollmentStatus::STATUS_STORE_TOKEN_AND_ID_FAILED:
353 // This error should not happen for enterprise enrollment.
354 ShowError(IDS_ENTERPRISE_ENROLLMENT_STATUS_STORE_TOKEN_AND_ID_FAILED,
355 true);
356 NOTREACHED();
357 return;
359 NOTREACHED();
362 // EnrollmentScreenHandler BaseScreenHandler implementation -----
364 void EnrollmentScreenHandler::Initialize() {
365 if (show_on_init_) {
366 Show();
367 show_on_init_ = false;
371 void EnrollmentScreenHandler::DeclareLocalizedValues(
372 LocalizedValuesBuilder* builder) {
373 builder->Add("oauthEnrollScreenTitle",
374 IDS_ENTERPRISE_ENROLLMENT_SCREEN_TITLE);
375 builder->Add("oauthEnrollDescription", IDS_ENTERPRISE_ENROLLMENT_DESCRIPTION);
376 builder->Add("oauthEnrollReEnrollmentText",
377 IDS_ENTERPRISE_ENROLLMENT_RE_ENROLLMENT_TEXT);
378 builder->Add("oauthEnrollRetry", IDS_ENTERPRISE_ENROLLMENT_RETRY);
379 builder->Add("oauthEnrollCancel", IDS_ENTERPRISE_ENROLLMENT_CANCEL);
380 builder->Add("oauthEnrollDone", IDS_ENTERPRISE_ENROLLMENT_DONE);
381 builder->Add("oauthEnrollSuccess", IDS_ENTERPRISE_ENROLLMENT_SUCCESS);
382 builder->Add("oauthEnrollExplain", IDS_ENTERPRISE_ENROLLMENT_EXPLAIN);
383 builder->Add("oauthEnrollExplainLink",
384 IDS_ENTERPRISE_ENROLLMENT_EXPLAIN_LINK);
385 builder->Add("oauthEnrollExplainButton",
386 IDS_ENTERPRISE_ENROLLMENT_EXPLAIN_BUTTON);
387 builder->Add("oauthEnrollCancelAutoEnrollmentReally",
388 IDS_ENTERPRISE_ENROLLMENT_CANCEL_AUTO_REALLY);
389 builder->Add("oauthEnrollCancelAutoEnrollmentConfirm",
390 IDS_ENTERPRISE_ENROLLMENT_CANCEL_AUTO_CONFIRM);
391 builder->Add("oauthEnrollCancelAutoEnrollmentGoBack",
392 IDS_ENTERPRISE_ENROLLMENT_CANCEL_AUTO_GO_BACK);
395 void EnrollmentScreenHandler::OnBrowsingDataRemoverDone() {
396 browsing_data_remover_->RemoveObserver(this);
397 browsing_data_remover_ = NULL;
399 std::vector<base::Closure> callbacks_to_run;
400 callbacks_to_run.swap(auth_reset_callbacks_);
401 for (std::vector<base::Closure>::iterator callback(callbacks_to_run.begin());
402 callback != callbacks_to_run.end(); ++callback) {
403 callback->Run();
407 OobeUI::Screen EnrollmentScreenHandler::GetCurrentScreen() const {
408 OobeUI::Screen screen = OobeUI::SCREEN_UNKNOWN;
409 OobeUI* oobe_ui = static_cast<OobeUI*>(web_ui()->GetController());
410 if (oobe_ui)
411 screen = oobe_ui->current_screen();
412 return screen;
415 bool EnrollmentScreenHandler::IsOnEnrollmentScreen() const {
416 return (GetCurrentScreen() == OobeUI::SCREEN_OOBE_ENROLLMENT);
419 bool EnrollmentScreenHandler::IsEnrollmentScreenHiddenByError() const {
420 return (GetCurrentScreen() == OobeUI::SCREEN_ERROR_MESSAGE &&
421 error_screen_actor_->parent_screen() ==
422 OobeUI::SCREEN_OOBE_ENROLLMENT);
425 // TODO(rsorokin): This function is mostly copied from SigninScreenHandler and
426 // should be refactored in the future.
427 void EnrollmentScreenHandler::UpdateState(
428 ErrorScreenActor::ErrorReason reason) {
429 if (!IsOnEnrollmentScreen() && !IsEnrollmentScreenHiddenByError())
430 return;
432 NetworkStateInformer::State state = network_state_informer_->state();
433 const std::string network_path = network_state_informer_->network_path();
434 const bool is_online = (state == NetworkStateInformer::ONLINE);
435 const bool is_behind_captive_portal =
436 (state == NetworkStateInformer::CAPTIVE_PORTAL);
437 const bool is_frame_error =
438 (frame_error() != net::OK) ||
439 (reason == ErrorScreenActor::ERROR_REASON_FRAME_ERROR);
441 LOG(WARNING) << "EnrollmentScreenHandler::UpdateState(): "
442 << "state=" << NetworkStateInformer::StatusString(state) << ", "
443 << "reason=" << ErrorScreenActor::ErrorReasonString(reason);
445 if (is_online || !is_behind_captive_portal)
446 error_screen_actor_->HideCaptivePortal();
448 if (is_frame_error) {
449 LOG(WARNING) << "Retry page load";
450 // TODO(rsorokin): Too many consecutive reloads.
451 CallJS("doReload");
454 if (!is_online || is_frame_error)
455 SetupAndShowOfflineMessage(state, reason);
456 else
457 HideOfflineMessage(state, reason);
460 void EnrollmentScreenHandler::SetupAndShowOfflineMessage(
461 NetworkStateInformer::State state,
462 ErrorScreenActor::ErrorReason reason) {
463 const std::string network_path = network_state_informer_->network_path();
464 const bool is_behind_captive_portal = IsBehindCaptivePortal(state, reason);
465 const bool is_proxy_error = IsProxyError(state, reason);
466 const bool is_frame_error =
467 (frame_error() != net::OK) ||
468 (reason == ErrorScreenActor::ERROR_REASON_FRAME_ERROR);
470 if (is_proxy_error) {
471 error_screen_actor_->SetErrorState(ErrorScreen::ERROR_STATE_PROXY,
472 std::string());
473 } else if (is_behind_captive_portal) {
474 // Do not bother a user with obsessive captive portal showing. This
475 // check makes captive portal being shown only once: either when error
476 // screen is shown for the first time or when switching from another
477 // error screen (offline, proxy).
478 if (IsOnEnrollmentScreen() || (error_screen_actor_->error_state() !=
479 ErrorScreen::ERROR_STATE_PORTAL)) {
480 error_screen_actor_->FixCaptivePortal();
482 const std::string network_name = GetNetworkName(network_path);
483 error_screen_actor_->SetErrorState(ErrorScreen::ERROR_STATE_PORTAL,
484 network_name);
485 } else if (is_frame_error) {
486 error_screen_actor_->SetErrorState(
487 ErrorScreen::ERROR_STATE_AUTH_EXT_TIMEOUT, std::string());
488 } else {
489 error_screen_actor_->SetErrorState(ErrorScreen::ERROR_STATE_OFFLINE,
490 std::string());
493 if (GetCurrentScreen() != OobeUI::SCREEN_ERROR_MESSAGE) {
494 base::DictionaryValue params;
495 const std::string network_type = network_state_informer_->network_type();
496 params.SetString("lastNetworkType", network_type);
497 error_screen_actor_->SetUIState(ErrorScreen::UI_STATE_SIGNIN);
498 error_screen_actor_->Show(OobeUI::SCREEN_OOBE_ENROLLMENT,
499 &params,
500 base::Bind(&EnrollmentScreenHandler::DoShow,
501 weak_ptr_factory_.GetWeakPtr()));
505 void EnrollmentScreenHandler::HideOfflineMessage(
506 NetworkStateInformer::State state,
507 ErrorScreenActor::ErrorReason reason) {
508 if (IsEnrollmentScreenHiddenByError())
509 error_screen_actor_->Hide();
512 void EnrollmentScreenHandler::OnFrameError(
513 const std::string& frame_unique_name) {
514 if (frame_unique_name == "oauth-enroll-signin-frame") {
515 HandleFrameLoadingCompleted(net::ERR_FAILED);
518 // EnrollmentScreenHandler, private -----------------------------
520 void EnrollmentScreenHandler::HandleRetrieveAuthenticatedUserEmail(
521 double attempt_token) {
522 email_retriever_.reset(new AuthenticatedUserEmailRetriever(
523 base::Bind(&EnrollmentScreenHandler::CallJS<double, std::string>,
524 base::Unretained(this),
525 "setAuthenticatedUserEmail",
526 attempt_token),
527 Profile::FromWebUI(web_ui())->GetRequestContext()));
530 void EnrollmentScreenHandler::HandleClose(const std::string& reason) {
531 DCHECK(controller_);
533 if (reason == "cancel" || reason == "autocancel")
534 controller_->OnCancel();
535 else if (reason == "done")
536 controller_->OnConfirmationClosed();
537 else
538 NOTREACHED();
541 void EnrollmentScreenHandler::HandleCompleteLogin(const std::string& user) {
542 DCHECK(controller_);
543 controller_->OnLoginDone(gaia::SanitizeEmail(user));
546 void EnrollmentScreenHandler::HandleRetry() {
547 DCHECK(controller_);
548 controller_->OnRetry();
551 void EnrollmentScreenHandler::HandleFrameLoadingCompleted(int status) {
552 const net::Error frame_error = static_cast<net::Error>(status);
553 frame_error_ = frame_error;
555 if (network_state_informer_->state() != NetworkStateInformer::ONLINE)
556 return;
557 if (frame_error_)
558 UpdateState(ErrorScreenActor::ERROR_REASON_FRAME_ERROR);
559 else
560 UpdateState(ErrorScreenActor::ERROR_REASON_UPDATE);
563 void EnrollmentScreenHandler::ShowStep(const char* step) {
564 CallJS("showStep", std::string(step));
567 void EnrollmentScreenHandler::ShowError(int message_id, bool retry) {
568 ShowErrorMessage(l10n_util::GetStringUTF8(message_id), retry);
571 void EnrollmentScreenHandler::ShowErrorMessage(const std::string& message,
572 bool retry) {
573 CallJS("showError", message, retry);
576 void EnrollmentScreenHandler::ShowWorking(int message_id) {
577 CallJS("showWorking", l10n_util::GetStringUTF16(message_id));
580 void EnrollmentScreenHandler::OnTokenFetched(
581 const std::string& token,
582 const GoogleServiceAuthError& error) {
583 if (!controller_)
584 return;
586 if (error.state() != GoogleServiceAuthError::NONE)
587 controller_->OnAuthError(error);
588 else
589 controller_->OnOAuthTokenAvailable(token);
592 void EnrollmentScreenHandler::DoShow() {
593 base::DictionaryValue screen_data;
594 screen_data.SetString("signin_url", kGaiaExtStartPage);
595 screen_data.SetString("gaiaUrl", GaiaUrls::GetInstance()->gaia_url().spec());
596 screen_data.SetString("enrollment_mode",
597 EnrollmentModeToString(enrollment_mode_));
598 screen_data.SetString("management_domain", management_domain_);
600 ShowScreen(OobeUI::kScreenOobeEnrollment, &screen_data);
603 } // namespace chromeos