| 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/base_screen_handler.h" | 5 #include "chrome/browser/ui/webui/chromeos/login/base_screen_handler.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | |
| 8 #include "base/memory/ptr_util.h" | |
| 9 #include "base/values.h" | |
| 10 #include "chrome/browser/chromeos/login/screens/base_screen.h" | |
| 11 #include "chrome/browser/chromeos/login/ui/login_display_host.h" | |
| 12 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" | |
| 13 #include "components/login/localized_values_builder.h" | |
| 14 #include "content/public/browser/web_ui.h" | |
| 15 | |
| 16 namespace chromeos { | 7 namespace chromeos { |
| 17 | 8 |
| 18 namespace { | 9 BaseScreenHandler::BaseScreenHandler(OobeScreen oobe_screen) |
| 19 const char kMethodContextChanged[] = "contextChanged"; | 10 : oobe_screen_(oobe_screen) {} |
| 20 } // namespace | |
| 21 | 11 |
| 22 BaseScreenHandler::BaseScreenHandler() = default; | 12 BaseScreenHandler::~BaseScreenHandler() {} |
| 23 | |
| 24 BaseScreenHandler::~BaseScreenHandler() { | |
| 25 if (base_screen_) | |
| 26 base_screen_->set_model_view_channel(nullptr); | |
| 27 } | |
| 28 | |
| 29 void BaseScreenHandler::InitializeBase() { | |
| 30 page_is_ready_ = true; | |
| 31 Initialize(); | |
| 32 if (!pending_context_changes_.empty()) { | |
| 33 CommitContextChanges(pending_context_changes_); | |
| 34 pending_context_changes_.Clear(); | |
| 35 } | |
| 36 } | |
| 37 | |
| 38 void BaseScreenHandler::GetLocalizedStrings(base::DictionaryValue* dict) { | |
| 39 auto builder = base::MakeUnique<::login::LocalizedValuesBuilder>(dict); | |
| 40 DeclareLocalizedValues(builder.get()); | |
| 41 GetAdditionalParameters(dict); | |
| 42 } | |
| 43 | |
| 44 void BaseScreenHandler::RegisterMessages() { | |
| 45 AddPrefixedCallback("userActed", | |
| 46 &BaseScreenHandler::HandleUserAction); | |
| 47 AddPrefixedCallback("contextChanged", | |
| 48 &BaseScreenHandler::HandleContextChanged); | |
| 49 DeclareJSCallbacks(); | |
| 50 } | |
| 51 | |
| 52 void BaseScreenHandler::CommitContextChanges( | |
| 53 const base::DictionaryValue& diff) { | |
| 54 if (!page_is_ready()) | |
| 55 pending_context_changes_.MergeDictionary(&diff); | |
| 56 else | |
| 57 CallJS(kMethodContextChanged, diff); | |
| 58 } | |
| 59 | |
| 60 void BaseScreenHandler::GetAdditionalParameters(base::DictionaryValue* dict) { | |
| 61 } | |
| 62 | |
| 63 void BaseScreenHandler::CallJS(const std::string& method) { | |
| 64 web_ui()->CallJavascriptFunctionUnsafe(FullMethodPath(method)); | |
| 65 } | |
| 66 | |
| 67 void BaseScreenHandler::ShowScreen(OobeScreen screen) { | |
| 68 ShowScreenWithData(screen, nullptr); | |
| 69 } | |
| 70 | |
| 71 void BaseScreenHandler::ShowScreenWithData(OobeScreen screen, | |
| 72 const base::DictionaryValue* data) { | |
| 73 if (!web_ui()) | |
| 74 return; | |
| 75 base::DictionaryValue screen_params; | |
| 76 screen_params.SetString("id", GetOobeScreenName(screen)); | |
| 77 if (data) | |
| 78 screen_params.SetWithoutPathExpansion("data", data->DeepCopy()); | |
| 79 web_ui()->CallJavascriptFunctionUnsafe("cr.ui.Oobe.showScreen", | |
| 80 screen_params); | |
| 81 } | |
| 82 | |
| 83 OobeUI* BaseScreenHandler::GetOobeUI() const { | |
| 84 return static_cast<OobeUI*>(web_ui()->GetController()); | |
| 85 } | |
| 86 | |
| 87 OobeScreen BaseScreenHandler::GetCurrentScreen() const { | |
| 88 OobeUI* oobe_ui = GetOobeUI(); | |
| 89 if (!oobe_ui) | |
| 90 return OobeScreen::SCREEN_UNKNOWN; | |
| 91 return oobe_ui->current_screen(); | |
| 92 } | |
| 93 | |
| 94 gfx::NativeWindow BaseScreenHandler::GetNativeWindow() { | |
| 95 return LoginDisplayHost::default_host()->GetNativeWindow(); | |
| 96 } | |
| 97 | |
| 98 void BaseScreenHandler::SetBaseScreen(BaseScreen* base_screen) { | |
| 99 if (base_screen_ == base_screen) | |
| 100 return; | |
| 101 if (base_screen_) | |
| 102 base_screen_->set_model_view_channel(nullptr); | |
| 103 base_screen_ = base_screen; | |
| 104 if (base_screen_) | |
| 105 base_screen_->set_model_view_channel(this); | |
| 106 } | |
| 107 | |
| 108 std::string BaseScreenHandler::FullMethodPath(const std::string& method) const { | |
| 109 DCHECK(!method.empty()); | |
| 110 return js_screen_path_prefix_ + method; | |
| 111 } | |
| 112 | |
| 113 void BaseScreenHandler::HandleUserAction(const std::string& action_id) { | |
| 114 if (base_screen_) | |
| 115 base_screen_->OnUserAction(action_id); | |
| 116 } | |
| 117 | |
| 118 void BaseScreenHandler::HandleContextChanged( | |
| 119 const base::DictionaryValue* diff) { | |
| 120 if (diff && base_screen_) | |
| 121 base_screen_->OnContextChanged(*diff); | |
| 122 } | |
| 123 | 13 |
| 124 } // namespace chromeos | 14 } // namespace chromeos |
| OLD | NEW |