OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/ui/webui/chromeos/login/enrollment_screen_handler.h" | 5 #include "chrome/browser/ui/webui/chromeos/login/enrollment_screen_handler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/strings/string_util.h" | |
14 #include "base/strings/utf_string_conversions.h" | |
13 #include "base/values.h" | 15 #include "base/values.h" |
14 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 17 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
16 #include "chrome/browser/browsing_data/browsing_data_remover.h" | 18 #include "chrome/browser/browsing_data/browsing_data_remover.h" |
19 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" | |
17 #include "chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.h" | 20 #include "chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.h" |
18 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/ui/webui/chromeos/login/authenticated_user_email_retrie ver.h" | 22 #include "chrome/browser/ui/webui/chromeos/login/authenticated_user_email_retrie ver.h" |
20 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.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" | |
21 #include "components/policy/core/browser/cloud/message_util.h" | 26 #include "components/policy/core/browser/cloud/message_util.h" |
22 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
23 #include "google_apis/gaia/gaia_auth_fetcher.h" | 28 #include "google_apis/gaia/gaia_auth_fetcher.h" |
24 #include "google_apis/gaia/gaia_auth_util.h" | 29 #include "google_apis/gaia/gaia_auth_util.h" |
25 #include "google_apis/gaia/gaia_constants.h" | 30 #include "google_apis/gaia/gaia_constants.h" |
26 #include "google_apis/gaia/gaia_urls.h" | 31 #include "google_apis/gaia/gaia_urls.h" |
27 #include "google_apis/gaia/google_service_auth_error.h" | 32 #include "google_apis/gaia/google_service_auth_error.h" |
28 #include "grit/chromium_strings.h" | 33 #include "grit/chromium_strings.h" |
29 #include "grit/generated_resources.h" | 34 #include "grit/generated_resources.h" |
30 #include "net/url_request/url_request_context_getter.h" | 35 #include "net/url_request/url_request_context_getter.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 virtual void OnOAuth2RevokeTokenCompleted() OVERRIDE { | 84 virtual void OnOAuth2RevokeTokenCompleted() OVERRIDE { |
80 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 85 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
81 } | 86 } |
82 | 87 |
83 private: | 88 private: |
84 GaiaAuthFetcher gaia_fetcher_; | 89 GaiaAuthFetcher gaia_fetcher_; |
85 | 90 |
86 DISALLOW_COPY_AND_ASSIGN(TokenRevoker); | 91 DISALLOW_COPY_AND_ASSIGN(TokenRevoker); |
87 }; | 92 }; |
88 | 93 |
94 // Returns network name by service path. | |
95 std::string GetNetworkName(const std::string& service_path) { | |
96 const NetworkState* network = | |
97 NetworkHandler::Get()->network_state_handler()->GetNetworkState( | |
98 service_path); | |
99 if (!network) | |
100 return std::string(); | |
101 return network->name(); | |
102 } | |
103 | |
104 bool IsBehindCaptivePortal(NetworkStateInformer::State state, | |
105 ErrorScreenActor::ErrorReason reason) { | |
106 return state == NetworkStateInformer::CAPTIVE_PORTAL || | |
107 reason == ErrorScreenActor::ERROR_REASON_PORTAL_DETECTED; | |
108 } | |
109 | |
110 bool IsProxyError(NetworkStateInformer::State state, | |
111 ErrorScreenActor::ErrorReason reason) { | |
112 return state == NetworkStateInformer::PROXY_AUTH_REQUIRED || | |
113 reason == ErrorScreenActor::ERROR_REASON_PROXY_AUTH_CANCELLED || | |
114 reason == ErrorScreenActor::ERROR_REASON_PROXY_CONNECTION_FAILED; | |
115 } | |
116 | |
89 } // namespace | 117 } // namespace |
90 | 118 |
91 // EnrollmentScreenHandler, public ------------------------------ | 119 // EnrollmentScreenHandler, public ------------------------------ |
92 | 120 |
93 EnrollmentScreenHandler::EnrollmentScreenHandler() | 121 EnrollmentScreenHandler::EnrollmentScreenHandler( |
122 const scoped_refptr<NetworkStateInformer>& network_state_informer, | |
123 ErrorScreenActor* error_screen_actor) | |
94 : BaseScreenHandler(kJsScreenPath), | 124 : BaseScreenHandler(kJsScreenPath), |
95 controller_(NULL), | 125 controller_(NULL), |
96 show_on_init_(false), | 126 show_on_init_(false), |
97 enrollment_mode_(ENROLLMENT_MODE_MANUAL), | 127 enrollment_mode_(ENROLLMENT_MODE_MANUAL), |
98 browsing_data_remover_(NULL) { | 128 browsing_data_remover_(NULL), |
129 frame_error_(net::OK), | |
130 network_state_informer_(network_state_informer), | |
131 error_screen_actor_(error_screen_actor) { | |
99 set_async_assets_load_id(OobeUI::kScreenOobeEnrollment); | 132 set_async_assets_load_id(OobeUI::kScreenOobeEnrollment); |
133 DCHECK(network_state_informer_.get()); | |
134 DCHECK(error_screen_actor_); | |
135 network_state_informer_->AddObserver(this); | |
136 | |
137 if (chromeos::LoginDisplayHostImpl::default_host()) { | |
Denis Kuznetsov (DE-MUC)
2014/06/23 17:42:01
What if it is NULL here?
Roman Sorokin (ftl)
2014/06/25 16:30:12
It should be created at this point. If not we woul
| |
138 chromeos::WebUILoginView* login_view = | |
139 chromeos::LoginDisplayHostImpl::default_host()->GetWebUILoginView(); | |
140 if (login_view) | |
141 login_view->AddFrameObserver(this); | |
142 } | |
100 } | 143 } |
101 | 144 |
102 EnrollmentScreenHandler::~EnrollmentScreenHandler() { | 145 EnrollmentScreenHandler::~EnrollmentScreenHandler() { |
103 if (browsing_data_remover_) | 146 if (browsing_data_remover_) |
104 browsing_data_remover_->RemoveObserver(this); | 147 browsing_data_remover_->RemoveObserver(this); |
148 network_state_informer_->RemoveObserver(this); | |
149 | |
150 if (chromeos::LoginDisplayHostImpl::default_host()) { | |
151 chromeos::WebUILoginView* login_view = | |
152 chromeos::LoginDisplayHostImpl::default_host()->GetWebUILoginView(); | |
153 if (login_view) | |
154 login_view->RemoveFrameObserver(this); | |
155 } | |
105 } | 156 } |
106 | 157 |
107 // EnrollmentScreenHandler, WebUIMessageHandler implementation -- | 158 // EnrollmentScreenHandler, WebUIMessageHandler implementation -- |
108 | 159 |
109 void EnrollmentScreenHandler::RegisterMessages() { | 160 void EnrollmentScreenHandler::RegisterMessages() { |
110 AddCallback("oauthEnrollRetrieveAuthenticatedUserEmail", | 161 AddCallback("oauthEnrollRetrieveAuthenticatedUserEmail", |
111 &EnrollmentScreenHandler::HandleRetrieveAuthenticatedUserEmail); | 162 &EnrollmentScreenHandler::HandleRetrieveAuthenticatedUserEmail); |
112 AddCallback("oauthEnrollClose", | 163 AddCallback("oauthEnrollClose", |
113 &EnrollmentScreenHandler::HandleClose); | 164 &EnrollmentScreenHandler::HandleClose); |
114 AddCallback("oauthEnrollCompleteLogin", | 165 AddCallback("oauthEnrollCompleteLogin", |
115 &EnrollmentScreenHandler::HandleCompleteLogin); | 166 &EnrollmentScreenHandler::HandleCompleteLogin); |
116 AddCallback("oauthEnrollRetry", | 167 AddCallback("oauthEnrollRetry", |
117 &EnrollmentScreenHandler::HandleRetry); | 168 &EnrollmentScreenHandler::HandleRetry); |
169 AddCallback("frameLoadingCompleted", | |
170 &EnrollmentScreenHandler::HandleFrameLoadingCompleted); | |
118 } | 171 } |
119 | 172 |
120 // EnrollmentScreenHandler | 173 // EnrollmentScreenHandler |
121 // EnrollmentScreenActor implementation ----------------------------------- | 174 // EnrollmentScreenActor implementation ----------------------------------- |
122 | 175 |
123 void EnrollmentScreenHandler::SetParameters( | 176 void EnrollmentScreenHandler::SetParameters( |
124 Controller* controller, | 177 Controller* controller, |
125 EnrollmentMode enrollment_mode, | 178 EnrollmentMode enrollment_mode, |
126 const std::string& management_domain) { | 179 const std::string& management_domain) { |
127 controller_ = controller; | 180 controller_ = controller; |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
347 browsing_data_remover_ = NULL; | 400 browsing_data_remover_ = NULL; |
348 | 401 |
349 std::vector<base::Closure> callbacks_to_run; | 402 std::vector<base::Closure> callbacks_to_run; |
350 callbacks_to_run.swap(auth_reset_callbacks_); | 403 callbacks_to_run.swap(auth_reset_callbacks_); |
351 for (std::vector<base::Closure>::iterator callback(callbacks_to_run.begin()); | 404 for (std::vector<base::Closure>::iterator callback(callbacks_to_run.begin()); |
352 callback != callbacks_to_run.end(); ++callback) { | 405 callback != callbacks_to_run.end(); ++callback) { |
353 callback->Run(); | 406 callback->Run(); |
354 } | 407 } |
355 } | 408 } |
356 | 409 |
410 OobeUI::Screen EnrollmentScreenHandler::GetCurrentScreen() const { | |
411 OobeUI::Screen screen = OobeUI::SCREEN_UNKNOWN; | |
412 OobeUI* oobe_ui = static_cast<OobeUI*>(web_ui()->GetController()); | |
413 if (oobe_ui) | |
414 screen = oobe_ui->current_screen(); | |
415 return screen; | |
416 } | |
417 | |
418 bool EnrollmentScreenHandler::IsOnEnrollmentScreen() const { | |
419 return (GetCurrentScreen() == OobeUI::SCREEN_OOBE_ENROLLMENT); | |
420 } | |
421 | |
422 bool EnrollmentScreenHandler::IsEnrollmentScreenHiddenByError() const { | |
423 return (GetCurrentScreen() == OobeUI::SCREEN_ERROR_MESSAGE && | |
424 error_screen_actor_->parent_screen() == | |
425 OobeUI::SCREEN_OOBE_ENROLLMENT); | |
426 } | |
427 | |
428 void EnrollmentScreenHandler::UpdateState( | |
Denis Kuznetsov (DE-MUC)
2014/06/23 17:42:01
Make a note that this is a copy-pasted code from S
Roman Sorokin (ftl)
2014/06/25 16:30:12
Done.
| |
429 ErrorScreenActor::ErrorReason reason) { | |
430 if (!IsOnEnrollmentScreen() && !IsEnrollmentScreenHiddenByError()) | |
431 return; | |
432 | |
433 NetworkStateInformer::State state = network_state_informer_->state(); | |
434 const std::string network_path = network_state_informer_->network_path(); | |
435 const bool is_online = (state == NetworkStateInformer::ONLINE); | |
436 const bool is_behind_captive_portal = | |
437 (state == NetworkStateInformer::CAPTIVE_PORTAL); | |
438 const bool is_frame_error = | |
439 (FrameError() != net::OK) || | |
440 (reason == ErrorScreenActor::ERROR_REASON_FRAME_ERROR); | |
441 | |
442 LOG(WARNING) << "EnrollmentScreenHandler::UpdateState(): " | |
443 << "state=" << NetworkStateInformer::StatusString(state) << ", " | |
444 << "reason=" << ErrorScreenActor::ErrorReasonString(reason); | |
445 | |
446 if (is_online || !is_behind_captive_portal) | |
447 error_screen_actor_->HideCaptivePortal(); | |
448 | |
449 if (is_frame_error) { | |
450 LOG(WARNING) << "Retry page load"; | |
451 // TODO(rsorokin): Too many consecutive reloads. | |
452 CallJS("doReload"); | |
453 } | |
454 | |
455 if (!is_online || is_frame_error) | |
456 SetupAndShowOfflineMessage(state, reason); | |
457 else | |
458 HideOfflineMessage(state, reason); | |
459 } | |
460 | |
461 void EnrollmentScreenHandler::SetupAndShowOfflineMessage( | |
462 NetworkStateInformer::State state, | |
463 ErrorScreenActor::ErrorReason reason) { | |
464 const std::string network_path = network_state_informer_->network_path(); | |
465 const bool is_behind_captive_portal = IsBehindCaptivePortal(state, reason); | |
466 const bool is_proxy_error = IsProxyError(state, reason); | |
467 const bool is_frame_error = | |
468 (FrameError() != net::OK) || | |
469 (reason == ErrorScreenActor::ERROR_REASON_FRAME_ERROR); | |
470 | |
471 if (is_proxy_error) { | |
472 error_screen_actor_->SetErrorState(ErrorScreen::ERROR_STATE_PROXY, | |
473 std::string()); | |
474 } else if (is_behind_captive_portal) { | |
475 // Do not bother a user with obsessive captive portal showing. This | |
476 // check makes captive portal being shown only once: either when error | |
477 // screen is shown for the first time or when switching from another | |
478 // error screen (offline, proxy). | |
479 if (IsOnEnrollmentScreen() || (error_screen_actor_->error_state() != | |
480 ErrorScreen::ERROR_STATE_PORTAL)) { | |
481 error_screen_actor_->FixCaptivePortal(); | |
482 } | |
483 const std::string network_name = GetNetworkName(network_path); | |
484 error_screen_actor_->SetErrorState(ErrorScreen::ERROR_STATE_PORTAL, | |
485 network_name); | |
486 } else if (is_frame_error) { | |
487 error_screen_actor_->SetErrorState( | |
488 ErrorScreen::ERROR_STATE_AUTH_EXT_TIMEOUT, std::string()); | |
489 } else { | |
490 error_screen_actor_->SetErrorState(ErrorScreen::ERROR_STATE_OFFLINE, | |
491 std::string()); | |
492 } | |
493 | |
494 if (GetCurrentScreen() != OobeUI::SCREEN_ERROR_MESSAGE) { | |
495 base::DictionaryValue params; | |
496 const std::string network_type = network_state_informer_->network_type(); | |
497 params.SetString("lastNetworkType", network_type); | |
498 error_screen_actor_->SetUIState(ErrorScreen::UI_STATE_SIGNIN); | |
499 error_screen_actor_->Show( | |
500 OobeUI::SCREEN_OOBE_ENROLLMENT, | |
501 ¶ms, | |
502 base::Bind(&EnrollmentScreenHandler::DoShow, base::Unretained(this))); | |
Denis Kuznetsov (DE-MUC)
2014/06/23 17:42:01
Please use weak refs instead of unretained.
Roman Sorokin (ftl)
2014/06/25 16:30:12
Done.
| |
503 } | |
504 } | |
505 | |
506 void EnrollmentScreenHandler::HideOfflineMessage( | |
507 NetworkStateInformer::State state, | |
508 ErrorScreenActor::ErrorReason reason) { | |
509 if (IsEnrollmentScreenHiddenByError()) | |
510 error_screen_actor_->Hide(); | |
511 } | |
512 | |
513 void EnrollmentScreenHandler::onFrameError( | |
Denis Kuznetsov (DE-MUC)
2014/06/23 17:42:01
Why this method name starts with lower-case? (see
Roman Sorokin (ftl)
2014/06/25 16:30:12
Done.
| |
514 const base::string16& frame_unique_name) { | |
515 if (MatchPattern(frame_unique_name, | |
516 base::UTF8ToUTF16("*oauth-enroll-signin-frame*"))) { | |
517 HandleFrameLoadingCompleted(net::ERR_FAILED); | |
518 } | |
519 } | |
357 // EnrollmentScreenHandler, private ----------------------------- | 520 // EnrollmentScreenHandler, private ----------------------------- |
358 | 521 |
359 void EnrollmentScreenHandler::HandleRetrieveAuthenticatedUserEmail( | 522 void EnrollmentScreenHandler::HandleRetrieveAuthenticatedUserEmail( |
360 double attempt_token) { | 523 double attempt_token) { |
361 email_retriever_.reset(new AuthenticatedUserEmailRetriever( | 524 email_retriever_.reset(new AuthenticatedUserEmailRetriever( |
362 base::Bind(&EnrollmentScreenHandler::CallJS<double, std::string>, | 525 base::Bind(&EnrollmentScreenHandler::CallJS<double, std::string>, |
363 base::Unretained(this), | 526 base::Unretained(this), |
364 "setAuthenticatedUserEmail", | 527 "setAuthenticatedUserEmail", |
365 attempt_token), | 528 attempt_token), |
366 Profile::FromWebUI(web_ui())->GetRequestContext())); | 529 Profile::FromWebUI(web_ui())->GetRequestContext())); |
(...skipping 22 matching lines...) Expand all Loading... | |
389 } | 552 } |
390 | 553 |
391 void EnrollmentScreenHandler::HandleRetry() { | 554 void EnrollmentScreenHandler::HandleRetry() { |
392 if (!controller_) { | 555 if (!controller_) { |
393 NOTREACHED(); | 556 NOTREACHED(); |
394 return; | 557 return; |
395 } | 558 } |
396 controller_->OnRetry(); | 559 controller_->OnRetry(); |
397 } | 560 } |
398 | 561 |
562 void EnrollmentScreenHandler::HandleFrameLoadingCompleted(int status) { | |
563 const net::Error frame_error = static_cast<net::Error>(status); | |
564 frame_error_ = frame_error; | |
565 | |
566 if (network_state_informer_->state() != NetworkStateInformer::ONLINE) | |
567 return; | |
568 if (frame_error_) | |
569 UpdateState(ErrorScreenActor::ERROR_REASON_FRAME_ERROR); | |
570 else | |
571 UpdateState(ErrorScreenActor::ERROR_REASON_UPDATE); | |
572 } | |
573 | |
399 void EnrollmentScreenHandler::ShowStep(const char* step) { | 574 void EnrollmentScreenHandler::ShowStep(const char* step) { |
400 CallJS("showStep", std::string(step)); | 575 CallJS("showStep", std::string(step)); |
401 } | 576 } |
402 | 577 |
403 void EnrollmentScreenHandler::ShowError(int message_id, bool retry) { | 578 void EnrollmentScreenHandler::ShowError(int message_id, bool retry) { |
404 ShowErrorMessage(l10n_util::GetStringUTF8(message_id), retry); | 579 ShowErrorMessage(l10n_util::GetStringUTF8(message_id), retry); |
405 } | 580 } |
406 | 581 |
407 void EnrollmentScreenHandler::ShowErrorMessage(const std::string& message, | 582 void EnrollmentScreenHandler::ShowErrorMessage(const std::string& message, |
408 bool retry) { | 583 bool retry) { |
(...skipping 21 matching lines...) Expand all Loading... | |
430 screen_data.SetString("signin_url", kGaiaExtStartPage); | 605 screen_data.SetString("signin_url", kGaiaExtStartPage); |
431 screen_data.SetString("gaiaUrl", GaiaUrls::GetInstance()->gaia_url().spec()); | 606 screen_data.SetString("gaiaUrl", GaiaUrls::GetInstance()->gaia_url().spec()); |
432 screen_data.SetString("enrollment_mode", | 607 screen_data.SetString("enrollment_mode", |
433 EnrollmentModeToString(enrollment_mode_)); | 608 EnrollmentModeToString(enrollment_mode_)); |
434 screen_data.SetString("management_domain", management_domain_); | 609 screen_data.SetString("management_domain", management_domain_); |
435 | 610 |
436 ShowScreen(OobeUI::kScreenOobeEnrollment, &screen_data); | 611 ShowScreen(OobeUI::kScreenOobeEnrollment, &screen_data); |
437 } | 612 } |
438 | 613 |
439 } // namespace chromeos | 614 } // namespace chromeos |
OLD | NEW |