| 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/error_screen_handler.h" | 5 #include "chrome/browser/ui/webui/chromeos/login/error_screen_handler.h" |
| 6 | 6 |
| 7 #include "ash/common/system/chromeos/devicetype_utils.h" | 7 #include "ash/common/system/chromeos/devicetype_utils.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "chrome/browser/chromeos/login/screens/network_error_model.h" | 10 #include "chrome/browser/chromeos/login/screens/error_screen.h" |
| 11 #include "chrome/grit/chromium_strings.h" | 11 #include "chrome/grit/chromium_strings.h" |
| 12 #include "chrome/grit/generated_resources.h" | 12 #include "chrome/grit/generated_resources.h" |
| 13 #include "components/login/localized_values_builder.h" | 13 #include "components/login/localized_values_builder.h" |
| 14 #include "ui/strings/grit/ui_strings.h" | 14 #include "ui/strings/grit/ui_strings.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 const char kJsScreenPath[] = "login.ErrorMessageScreen"; | 18 const char kJsScreenPath[] = "login.ErrorMessageScreen"; |
| 19 | 19 |
| 20 } // namespace | 20 } // namespace |
| 21 | 21 |
| 22 namespace chromeos { | 22 namespace chromeos { |
| 23 | 23 |
| 24 ErrorScreenHandler::ErrorScreenHandler() | 24 ErrorScreenHandler::ErrorScreenHandler() |
| 25 : BaseScreenHandler(kJsScreenPath), | 25 : BaseScreenHandler(kJsScreenPath), |
| 26 model_(nullptr), | |
| 27 show_on_init_(false), | |
| 28 showing_(false), | |
| 29 weak_ptr_factory_(this) { | 26 weak_ptr_factory_(this) { |
| 30 } | 27 } |
| 31 | 28 |
| 32 ErrorScreenHandler::~ErrorScreenHandler() { | 29 ErrorScreenHandler::~ErrorScreenHandler() { |
| 33 if (model_) | 30 if (screen_) |
| 34 model_->OnViewDestroyed(this); | 31 screen_->OnViewDestroyed(this); |
| 35 } | 32 } |
| 36 | 33 |
| 37 void ErrorScreenHandler::Show() { | 34 void ErrorScreenHandler::Show() { |
| 38 if (!page_is_ready()) { | 35 if (!page_is_ready()) { |
| 39 show_on_init_ = true; | 36 show_on_init_ = true; |
| 40 return; | 37 return; |
| 41 } | 38 } |
| 42 BaseScreenHandler::ShowScreen(OobeScreen::SCREEN_ERROR_MESSAGE); | 39 BaseScreenHandler::ShowScreen(OobeScreen::SCREEN_ERROR_MESSAGE); |
| 43 if (model_) | 40 if (screen_) |
| 44 model_->OnShow(); | 41 screen_->OnShow(); |
| 45 showing_ = true; | 42 showing_ = true; |
| 46 } | 43 } |
| 47 | 44 |
| 48 void ErrorScreenHandler::Hide() { | 45 void ErrorScreenHandler::Hide() { |
| 49 showing_ = false; | 46 showing_ = false; |
| 50 if (model_) | 47 if (screen_) |
| 51 model_->OnHide(); | 48 screen_->OnHide(); |
| 52 } | 49 } |
| 53 | 50 |
| 54 void ErrorScreenHandler::Bind(NetworkErrorModel& model) { | 51 void ErrorScreenHandler::Bind(ErrorScreen* screen) { |
| 55 model_ = &model; | 52 screen_ = screen; |
| 56 BaseScreenHandler::SetBaseScreen(model_); | 53 BaseScreenHandler::SetBaseScreen(screen_); |
| 57 } | 54 } |
| 58 | 55 |
| 59 void ErrorScreenHandler::Unbind() { | 56 void ErrorScreenHandler::Unbind() { |
| 60 model_ = nullptr; | 57 screen_ = nullptr; |
| 61 BaseScreenHandler::SetBaseScreen(nullptr); | 58 BaseScreenHandler::SetBaseScreen(nullptr); |
| 62 } | 59 } |
| 63 | 60 |
| 64 void ErrorScreenHandler::ShowOobeScreen(OobeScreen screen) { | 61 void ErrorScreenHandler::ShowOobeScreen(OobeScreen screen) { |
| 65 ShowScreen(screen); | 62 ShowScreen(screen); |
| 66 } | 63 } |
| 67 | 64 |
| 68 void ErrorScreenHandler::HandleHideCaptivePortal() { | |
| 69 if (model_) | |
| 70 model_->HideCaptivePortal(); | |
| 71 } | |
| 72 | |
| 73 void ErrorScreenHandler::RegisterMessages() { | 65 void ErrorScreenHandler::RegisterMessages() { |
| 74 AddCallback("hideCaptivePortal", | 66 AddCallback("hideCaptivePortal", |
| 75 &ErrorScreenHandler::HandleHideCaptivePortal); | 67 &ErrorScreenHandler::HandleHideCaptivePortal); |
| 76 BaseScreenHandler::RegisterMessages(); | 68 BaseScreenHandler::RegisterMessages(); |
| 77 } | 69 } |
| 78 | 70 |
| 79 void ErrorScreenHandler::DeclareLocalizedValues( | 71 void ErrorScreenHandler::DeclareLocalizedValues( |
| 80 ::login::LocalizedValuesBuilder* builder) { | 72 ::login::LocalizedValuesBuilder* builder) { |
| 81 builder->Add("deviceType", ash::GetChromeOSDeviceName()); | 73 builder->Add("deviceType", ash::GetChromeOSDeviceName()); |
| 82 builder->Add("loginErrorTitle", IDS_LOGIN_ERROR_TITLE); | 74 builder->Add("loginErrorTitle", IDS_LOGIN_ERROR_TITLE); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 return; | 112 return; |
| 121 | 113 |
| 122 if (show_on_init_) { | 114 if (show_on_init_) { |
| 123 // TODO(nkostylev): Check that context initial state is properly passed. | 115 // TODO(nkostylev): Check that context initial state is properly passed. |
| 124 Show(); | 116 Show(); |
| 125 show_on_init_ = false; | 117 show_on_init_ = false; |
| 126 } | 118 } |
| 127 } | 119 } |
| 128 | 120 |
| 129 void ErrorScreenHandler::OnConnectToNetworkRequested() { | 121 void ErrorScreenHandler::OnConnectToNetworkRequested() { |
| 130 if (showing_ && model_) | 122 if (showing_ && screen_) |
| 131 model_->OnUserAction(NetworkErrorModel::kUserActionConnectRequested); | 123 screen_->OnUserAction(ErrorScreen::kUserActionConnectRequested); |
| 124 } |
| 125 |
| 126 void ErrorScreenHandler::HandleHideCaptivePortal() { |
| 127 if (screen_) |
| 128 screen_->HideCaptivePortal(); |
| 132 } | 129 } |
| 133 | 130 |
| 134 } // namespace chromeos | 131 } // namespace chromeos |
| OLD | NEW |