| 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()) { |
| 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( |
| 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))); |
| 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::DidFailProvisionalLoad( |
| 514 int64 frame_id, |
| 515 const base::string16& frame_unique_name, |
| 516 bool is_main_frame, |
| 517 const GURL& validated_url, |
| 518 int error_code, |
| 519 const base::string16& error_description, |
| 520 content::RenderViewHost* render_view_host) { |
| 521 if (MatchPattern(frame_unique_name, |
| 522 base::UTF8ToUTF16("*oauth-enroll-signin-frame*"))) { |
| 523 HandleFrameLoadingCompleted(net::ERR_FAILED); |
| 524 } |
| 525 } |
| 357 // EnrollmentScreenHandler, private ----------------------------- | 526 // EnrollmentScreenHandler, private ----------------------------- |
| 358 | 527 |
| 359 void EnrollmentScreenHandler::HandleRetrieveAuthenticatedUserEmail( | 528 void EnrollmentScreenHandler::HandleRetrieveAuthenticatedUserEmail( |
| 360 double attempt_token) { | 529 double attempt_token) { |
| 361 email_retriever_.reset(new AuthenticatedUserEmailRetriever( | 530 email_retriever_.reset(new AuthenticatedUserEmailRetriever( |
| 362 base::Bind(&EnrollmentScreenHandler::CallJS<double, std::string>, | 531 base::Bind(&EnrollmentScreenHandler::CallJS<double, std::string>, |
| 363 base::Unretained(this), | 532 base::Unretained(this), |
| 364 "setAuthenticatedUserEmail", | 533 "setAuthenticatedUserEmail", |
| 365 attempt_token), | 534 attempt_token), |
| 366 Profile::FromWebUI(web_ui())->GetRequestContext())); | 535 Profile::FromWebUI(web_ui())->GetRequestContext())); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 389 } | 558 } |
| 390 | 559 |
| 391 void EnrollmentScreenHandler::HandleRetry() { | 560 void EnrollmentScreenHandler::HandleRetry() { |
| 392 if (!controller_) { | 561 if (!controller_) { |
| 393 NOTREACHED(); | 562 NOTREACHED(); |
| 394 return; | 563 return; |
| 395 } | 564 } |
| 396 controller_->OnRetry(); | 565 controller_->OnRetry(); |
| 397 } | 566 } |
| 398 | 567 |
| 568 void EnrollmentScreenHandler::HandleFrameLoadingCompleted(int status) { |
| 569 const net::Error frame_error = static_cast<net::Error>(status); |
| 570 frame_error_ = frame_error; |
| 571 |
| 572 if (network_state_informer_->state() != NetworkStateInformer::ONLINE) |
| 573 return; |
| 574 if (frame_error_) |
| 575 UpdateState(ErrorScreenActor::ERROR_REASON_FRAME_ERROR); |
| 576 else |
| 577 UpdateState(ErrorScreenActor::ERROR_REASON_UPDATE); |
| 578 } |
| 579 |
| 399 void EnrollmentScreenHandler::ShowStep(const char* step) { | 580 void EnrollmentScreenHandler::ShowStep(const char* step) { |
| 400 CallJS("showStep", std::string(step)); | 581 CallJS("showStep", std::string(step)); |
| 401 } | 582 } |
| 402 | 583 |
| 403 void EnrollmentScreenHandler::ShowError(int message_id, bool retry) { | 584 void EnrollmentScreenHandler::ShowError(int message_id, bool retry) { |
| 404 ShowErrorMessage(l10n_util::GetStringUTF8(message_id), retry); | 585 ShowErrorMessage(l10n_util::GetStringUTF8(message_id), retry); |
| 405 } | 586 } |
| 406 | 587 |
| 407 void EnrollmentScreenHandler::ShowErrorMessage(const std::string& message, | 588 void EnrollmentScreenHandler::ShowErrorMessage(const std::string& message, |
| 408 bool retry) { | 589 bool retry) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 430 screen_data.SetString("signin_url", kGaiaExtStartPage); | 611 screen_data.SetString("signin_url", kGaiaExtStartPage); |
| 431 screen_data.SetString("gaiaUrl", GaiaUrls::GetInstance()->gaia_url().spec()); | 612 screen_data.SetString("gaiaUrl", GaiaUrls::GetInstance()->gaia_url().spec()); |
| 432 screen_data.SetString("enrollment_mode", | 613 screen_data.SetString("enrollment_mode", |
| 433 EnrollmentModeToString(enrollment_mode_)); | 614 EnrollmentModeToString(enrollment_mode_)); |
| 434 screen_data.SetString("management_domain", management_domain_); | 615 screen_data.SetString("management_domain", management_domain_); |
| 435 | 616 |
| 436 ShowScreen(OobeUI::kScreenOobeEnrollment, &screen_data); | 617 ShowScreen(OobeUI::kScreenOobeEnrollment, &screen_data); |
| 437 } | 618 } |
| 438 | 619 |
| 439 } // namespace chromeos | 620 } // namespace chromeos |
| OLD | NEW |