Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / webui / chromeos / login / network_screen_handler.cc
blobfb8ebb40847e520b0cd614a0f2daf81913140516
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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/webui/chromeos/login/network_screen_handler.h"
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/command_line.h"
10 #include "base/prefs/pref_service.h"
11 #include "base/strings/string16.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "base/task_runner_util.h"
14 #include "base/threading/worker_pool.h"
15 #include "base/values.h"
16 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
18 #include "chrome/browser/chromeos/customization/customization_document.h"
19 #include "chrome/browser/chromeos/idle_detector.h"
20 #include "chrome/browser/chromeos/login/screens/core_oobe_actor.h"
21 #include "chrome/browser/chromeos/login/screens/network_model.h"
22 #include "chrome/browser/chromeos/login/ui/input_events_blocker.h"
23 #include "chrome/browser/chromeos/system/input_device_settings.h"
24 #include "chrome/browser/chromeos/system/timezone_util.h"
25 #include "chrome/browser/ui/webui/chromeos/login/l10n_util.h"
26 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
27 #include "chrome/common/pref_names.h"
28 #include "chrome/grit/generated_resources.h"
29 #include "chromeos/chromeos_switches.h"
30 #include "chromeos/network/network_handler.h"
31 #include "chromeos/network/network_state_handler.h"
32 #include "components/login/localized_values_builder.h"
33 #include "components/user_manager/user_manager.h"
34 #include "content/public/browser/browser_thread.h"
35 #include "ui/base/ime/chromeos/extension_ime_util.h"
36 #include "ui/base/l10n/l10n_util.h"
37 #include "ui/gfx/geometry/rect.h"
38 #include "ui/views/layout/fill_layout.h"
39 #include "ui/views/widget/widget.h"
41 namespace {
43 const char kJsScreenPath[] = "login.NetworkScreen";
45 } // namespace
47 namespace chromeos {
49 // NetworkScreenHandler, public: -----------------------------------------------
51 NetworkScreenHandler::NetworkScreenHandler(CoreOobeActor* core_oobe_actor)
52 : BaseScreenHandler(kJsScreenPath),
53 core_oobe_actor_(core_oobe_actor),
54 model_(nullptr),
55 show_on_init_(false) {
56 DCHECK(core_oobe_actor_);
59 NetworkScreenHandler::~NetworkScreenHandler() {
60 if (model_)
61 model_->OnViewDestroyed(this);
64 // NetworkScreenHandler, NetworkScreenActor implementation: --------------------
66 void NetworkScreenHandler::PrepareToShow() {
69 void NetworkScreenHandler::Show() {
70 if (!page_is_ready()) {
71 show_on_init_ = true;
72 return;
75 PrefService* prefs = g_browser_process->local_state();
76 if (prefs->GetBoolean(prefs::kFactoryResetRequested)) {
77 if (core_oobe_actor_)
78 core_oobe_actor_->ShowDeviceResetScreen();
80 return;
81 } else if (prefs->GetBoolean(prefs::kDebuggingFeaturesRequested)) {
82 if (core_oobe_actor_)
83 core_oobe_actor_->ShowEnableDebuggingScreen();
85 return;
88 // Make sure all our network technologies are turned on. On OOBE, the user
89 // should be able to select any of the available networks on the device.
90 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
91 handler->SetTechnologyEnabled(NetworkTypePattern::NonVirtual(),
92 true,
93 chromeos::network_handler::ErrorCallback());
95 base::DictionaryValue network_screen_params;
96 network_screen_params.SetBoolean("isDeveloperMode",
97 base::CommandLine::ForCurrentProcess()->HasSwitch(
98 chromeos::switches::kSystemDevMode));
99 ShowScreen(OobeUI::kScreenOobeNetwork, &network_screen_params);
100 core_oobe_actor_->InitDemoModeDetection();
103 void NetworkScreenHandler::Hide() {
106 void NetworkScreenHandler::Bind(NetworkModel& model) {
107 model_ = &model;
108 BaseScreenHandler::SetBaseScreen(model_);
111 void NetworkScreenHandler::Unbind() {
112 model_ = nullptr;
113 BaseScreenHandler::SetBaseScreen(nullptr);
116 void NetworkScreenHandler::ShowError(const base::string16& message) {
117 CallJS("showError", message);
120 void NetworkScreenHandler::ClearErrors() {
121 if (page_is_ready())
122 core_oobe_actor_->ClearErrors();
125 void NetworkScreenHandler::StopDemoModeDetection() {
126 core_oobe_actor_->StopDemoModeDetection();
129 void NetworkScreenHandler::ShowConnectingStatus(
130 bool connecting,
131 const base::string16& network_id) {
134 void NetworkScreenHandler::ReloadLocalizedContent() {
135 base::DictionaryValue localized_strings;
136 static_cast<OobeUI*>(web_ui()->GetController())
137 ->GetLocalizedStrings(&localized_strings);
138 core_oobe_actor_->ReloadContent(localized_strings);
141 // NetworkScreenHandler, BaseScreenHandler implementation: --------------------
143 void NetworkScreenHandler::DeclareLocalizedValues(
144 ::login::LocalizedValuesBuilder* builder) {
145 if (system::InputDeviceSettings::Get()->ForceKeyboardDrivenUINavigation())
146 builder->Add("networkScreenGreeting", IDS_REMORA_CONFIRM_MESSAGE);
147 else
148 builder->Add("networkScreenGreeting", IDS_WELCOME_SCREEN_GREETING);
150 builder->Add("networkScreenTitle", IDS_WELCOME_SCREEN_TITLE);
151 builder->Add("networkScreenAccessibleTitle",
152 IDS_NETWORK_SCREEN_ACCESSIBLE_TITLE);
153 builder->Add("selectLanguage", IDS_LANGUAGE_SELECTION_SELECT);
154 builder->Add("selectKeyboard", IDS_KEYBOARD_SELECTION_SELECT);
155 builder->Add("selectNetwork", IDS_NETWORK_SELECTION_SELECT);
156 builder->Add("selectTimezone", IDS_OPTIONS_SETTINGS_TIMEZONE_DESCRIPTION);
157 builder->Add("proxySettings", IDS_OPTIONS_PROXIES_CONFIGURE_BUTTON);
158 builder->Add("continueButton", IDS_NETWORK_SELECTION_CONTINUE_BUTTON);
159 builder->Add("debuggingFeaturesLink", IDS_NETWORK_ENABLE_DEV_FEATURES_LINK);
162 void NetworkScreenHandler::GetAdditionalParameters(
163 base::DictionaryValue* dict) {
164 const std::string application_locale =
165 g_browser_process->GetApplicationLocale();
166 const std::string selected_input_method =
167 input_method::InputMethodManager::Get()
168 ->GetActiveIMEState()
169 ->GetCurrentInputMethod()
170 .id();
172 scoped_ptr<base::ListValue> language_list;
173 if (model_) {
174 if (model_->GetLanguageList() &&
175 model_->GetLanguageListLocale() == application_locale) {
176 language_list.reset(model_->GetLanguageList()->DeepCopy());
177 } else {
178 model_->UpdateLanguageList();
182 if (!language_list.get())
183 language_list.reset(GetMinimalUILanguageList().release());
185 // GetAdditionalParameters() is called when OOBE language is updated.
186 // This happens in two diferent cases:
188 // 1) User selects new locale on OOBE screen. We need to sync active input
189 // methods with locale, so EnableLoginLayouts() is needed.
191 // 2) This is signin to public session. User has selected some locale & input
192 // method on "Public Session User POD". After "Login" button is pressed,
193 // new user session is created, locale & input method are changed (both
194 // asynchronously).
195 // But after public user session is started, "Terms of Service" dialog is
196 // shown. It is a part of OOBE UI screens, so it initiates reload of UI
197 // strings in new locale. It also happens asynchronously, that leads to race
198 // between "locale change", "input method change" and
199 // "EnableLoginLayouts()". This way EnableLoginLayouts() happens after user
200 // input method has been changed, resetting input method to hardware default.
202 // So we need to disable activation of login layouts if we are already in
203 // active user session.
205 const bool enable_layouts =
206 !user_manager::UserManager::Get()->IsUserLoggedIn();
208 dict->Set("languageList", language_list.release());
209 dict->Set(
210 "inputMethodsList",
211 GetAndActivateLoginKeyboardLayouts(
212 application_locale, selected_input_method, enable_layouts).release());
213 dict->Set("timezoneList", GetTimezoneList());
216 void NetworkScreenHandler::Initialize() {
217 if (show_on_init_) {
218 show_on_init_ = false;
219 Show();
222 // Reload localized strings if they are already resolved.
223 if (model_ && model_->GetLanguageList())
224 ReloadLocalizedContent();
227 // NetworkScreenHandler, private: ----------------------------------------------
229 // static
230 base::ListValue* NetworkScreenHandler::GetTimezoneList() {
231 std::string current_timezone_id;
232 CrosSettings::Get()->GetString(kSystemTimezone, &current_timezone_id);
234 scoped_ptr<base::ListValue> timezone_list(new base::ListValue);
235 scoped_ptr<base::ListValue> timezones = system::GetTimezoneList().Pass();
236 for (size_t i = 0; i < timezones->GetSize(); ++i) {
237 const base::ListValue* timezone = NULL;
238 CHECK(timezones->GetList(i, &timezone));
240 std::string timezone_id;
241 CHECK(timezone->GetString(0, &timezone_id));
243 std::string timezone_name;
244 CHECK(timezone->GetString(1, &timezone_name));
246 scoped_ptr<base::DictionaryValue> timezone_option(
247 new base::DictionaryValue);
248 timezone_option->SetString("value", timezone_id);
249 timezone_option->SetString("title", timezone_name);
250 timezone_option->SetBoolean("selected", timezone_id == current_timezone_id);
251 timezone_list->Append(timezone_option.release());
254 return timezone_list.release();
257 } // namespace chromeos