+OobeUI::Screen EnrollmentScreenHandler::GetCurrentScreen() const {
+ OobeUI::Screen screen = OobeUI::SCREEN_UNKNOWN;
+ OobeUI* oobe_ui = static_cast<OobeUI*>(web_ui()->GetController());
+ if (oobe_ui)
+ screen = oobe_ui->current_screen();
+ return screen;
+}
+
+bool EnrollmentScreenHandler::IsOnEnrollmentScreen() const {
+ return (GetCurrentScreen() == OobeUI::SCREEN_OOBE_ENROLLMENT);
+}
+
+bool EnrollmentScreenHandler::IsEnrollmentScreenHiddenByError() const {
+ return (GetCurrentScreen() == OobeUI::SCREEN_ERROR_MESSAGE &&
+ error_screen_actor_->parent_screen() ==
+ OobeUI::SCREEN_OOBE_ENROLLMENT);
+}
+
+// TODO(rsorokin): This function is mostly copied from SigninScreenHandler and
+// should be refactored in the future.
+void EnrollmentScreenHandler::UpdateState(
+ ErrorScreenActor::ErrorReason reason) {
+ if (!IsOnEnrollmentScreen() && !IsEnrollmentScreenHiddenByError())
+ return;
+
+ NetworkStateInformer::State state = network_state_informer_->state();
+ const std::string network_path = network_state_informer_->network_path();
+ const bool is_online = (state == NetworkStateInformer::ONLINE);
+ const bool is_behind_captive_portal =
+ (state == NetworkStateInformer::CAPTIVE_PORTAL);
+ const bool is_frame_error =
+ (frame_error() != net::OK) ||
+ (reason == ErrorScreenActor::ERROR_REASON_FRAME_ERROR);
+
+ LOG(WARNING) << "EnrollmentScreenHandler::UpdateState(): "
+ << "state=" << NetworkStateInformer::StatusString(state) << ", "
+ << "reason=" << ErrorScreenActor::ErrorReasonString(reason);
+
+ if (is_online || !is_behind_captive_portal)
+ error_screen_actor_->HideCaptivePortal();
+
+ if (is_frame_error) {
+ LOG(WARNING) << "Retry page load";
+ // TODO(rsorokin): Too many consecutive reloads.
+ CallJS("doReload");
+ }
+
+ if (!is_online || is_frame_error)
+ SetupAndShowOfflineMessage(state, reason);
+ else
+ HideOfflineMessage(state, reason);
+}
+
+void EnrollmentScreenHandler::SetupAndShowOfflineMessage(
+ NetworkStateInformer::State state,
+ ErrorScreenActor::ErrorReason reason) {
+ const std::string network_path = network_state_informer_->network_path();
+ const bool is_behind_captive_portal = IsBehindCaptivePortal(state, reason);
+ const bool is_proxy_error = IsProxyError(state, reason);
+ const bool is_frame_error =
+ (frame_error() != net::OK) ||
+ (reason == ErrorScreenActor::ERROR_REASON_FRAME_ERROR);
+
+ if (is_proxy_error) {
+ error_screen_actor_->SetErrorState(ErrorScreen::ERROR_STATE_PROXY,
+ std::string());
+ } else if (is_behind_captive_portal) {
+ // Do not bother a user with obsessive captive portal showing. This
+ // check makes captive portal being shown only once: either when error
+ // screen is shown for the first time or when switching from another
+ // error screen (offline, proxy).
+ if (IsOnEnrollmentScreen() || (error_screen_actor_->error_state() !=
+ ErrorScreen::ERROR_STATE_PORTAL)) {
+ error_screen_actor_->FixCaptivePortal();
+ }
+ const std::string network_name = GetNetworkName(network_path);
+ error_screen_actor_->SetErrorState(ErrorScreen::ERROR_STATE_PORTAL,
+ network_name);
+ } else if (is_frame_error) {
+ error_screen_actor_->SetErrorState(
+ ErrorScreen::ERROR_STATE_AUTH_EXT_TIMEOUT, std::string());
+ } else {
+ error_screen_actor_->SetErrorState(ErrorScreen::ERROR_STATE_OFFLINE,
+ std::string());
+ }
+
+ if (GetCurrentScreen() != OobeUI::SCREEN_ERROR_MESSAGE) {
+ base::DictionaryValue params;
+ const std::string network_type = network_state_informer_->network_type();
+ params.SetString("lastNetworkType", network_type);
+ error_screen_actor_->SetUIState(ErrorScreen::UI_STATE_SIGNIN);
+ error_screen_actor_->Show(OobeUI::SCREEN_OOBE_ENROLLMENT,
+ ¶ms,
+ base::Bind(&EnrollmentScreenHandler::DoShow,
+ weak_ptr_factory_.GetWeakPtr()));
+ }
+}
+
+void EnrollmentScreenHandler::HideOfflineMessage(
+ NetworkStateInformer::State state,
+ ErrorScreenActor::ErrorReason reason) {
+ if (IsEnrollmentScreenHiddenByError())
+ error_screen_actor_->Hide();
+}
+
+void EnrollmentScreenHandler::OnFrameError(
+ const std::string& frame_unique_name) {
+ if (frame_unique_name == "oauth-enroll-signin-frame") {
+ HandleFrameLoadingCompleted(net::ERR_FAILED);
+ }
+}