| 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/network_screen_handler.h" | 5 #include "chrome/browser/ui/webui/chromeos/login/network_screen_handler.h" |
| 6 | 6 |
| 7 #include <algorithm> | |
| 8 | |
| 9 #include "base/bind.h" | 7 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 11 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 12 #include "base/logging.h" | |
| 13 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 14 #include "base/prefs/pref_registry_simple.h" | 11 #include "base/prefs/pref_registry_simple.h" |
| 15 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 16 #include "base/strings/stringprintf.h" | |
| 17 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 18 #include "base/sys_info.h" | 14 #include "base/sys_info.h" |
| 19 #include "base/values.h" | 15 #include "base/values.h" |
| 20 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 21 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | 17 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
| 22 #include "chrome/browser/chromeos/base/locale_util.h" | 18 #include "chrome/browser/chromeos/base/locale_util.h" |
| 23 #include "chrome/browser/chromeos/customization_document.h" | 19 #include "chrome/browser/chromeos/customization_document.h" |
| 24 #include "chrome/browser/chromeos/idle_detector.h" | 20 #include "chrome/browser/chromeos/idle_detector.h" |
| 25 #include "chrome/browser/chromeos/input_method/input_method_util.h" | |
| 26 #include "chrome/browser/chromeos/login/screens/core_oobe_actor.h" | 21 #include "chrome/browser/chromeos/login/screens/core_oobe_actor.h" |
| 27 #include "chrome/browser/chromeos/login/ui/input_events_blocker.h" | 22 #include "chrome/browser/chromeos/login/ui/input_events_blocker.h" |
| 28 #include "chrome/browser/chromeos/system/input_device_settings.h" | 23 #include "chrome/browser/chromeos/system/input_device_settings.h" |
| 29 #include "chrome/browser/chromeos/system/timezone_util.h" | 24 #include "chrome/browser/chromeos/system/timezone_util.h" |
| 25 #include "chrome/browser/ui/webui/chromeos/login/l10n_util.h" |
| 30 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" | 26 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" |
| 31 #include "chrome/browser/ui/webui/options/chromeos/cros_language_options_handler
.h" | |
| 32 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
| 33 #include "chromeos/chromeos_switches.h" | 28 #include "chromeos/chromeos_switches.h" |
| 34 #include "chromeos/ime/extension_ime_util.h" | 29 #include "chromeos/ime/extension_ime_util.h" |
| 35 #include "chromeos/network/network_handler.h" | 30 #include "chromeos/network/network_handler.h" |
| 36 #include "chromeos/network/network_state_handler.h" | 31 #include "chromeos/network/network_state_handler.h" |
| 37 #include "grit/chromium_strings.h" | 32 #include "grit/chromium_strings.h" |
| 38 #include "grit/generated_resources.h" | 33 #include "grit/generated_resources.h" |
| 39 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
| 40 #include "ui/gfx/rect.h" | 35 #include "ui/gfx/rect.h" |
| 41 #include "ui/views/layout/fill_layout.h" | 36 #include "ui/views/layout/fill_layout.h" |
| 42 #include "ui/views/widget/widget.h" | 37 #include "ui/views/widget/widget.h" |
| 43 | 38 |
| 44 namespace { | 39 namespace { |
| 45 | 40 |
| 46 const char kJsScreenPath[] = "login.NetworkScreen"; | 41 const char kJsScreenPath[] = "login.NetworkScreen"; |
| 47 | 42 |
| 48 // JS API callbacks names. | 43 // JS API callbacks names. |
| 49 const char kJsApiNetworkOnExit[] = "networkOnExit"; | 44 const char kJsApiNetworkOnExit[] = "networkOnExit"; |
| 50 const char kJsApiNetworkOnLanguageChanged[] = "networkOnLanguageChanged"; | 45 const char kJsApiNetworkOnLanguageChanged[] = "networkOnLanguageChanged"; |
| 51 const char kJsApiNetworkOnInputMethodChanged[] = "networkOnInputMethodChanged"; | 46 const char kJsApiNetworkOnInputMethodChanged[] = "networkOnInputMethodChanged"; |
| 52 const char kJsApiNetworkOnTimezoneChanged[] = "networkOnTimezoneChanged"; | 47 const char kJsApiNetworkOnTimezoneChanged[] = "networkOnTimezoneChanged"; |
| 53 | 48 |
| 54 // Returns true if element was inserted. | |
| 55 bool InsertString(const std::string& str, std::set<std::string>& to) { | |
| 56 const std::pair<std::set<std::string>::iterator, bool> result = | |
| 57 to.insert(str); | |
| 58 return result.second; | |
| 59 } | |
| 60 | |
| 61 void AddOptgroupOtherLayouts(base::ListValue* input_methods_list) { | |
| 62 base::DictionaryValue* optgroup = new base::DictionaryValue; | |
| 63 optgroup->SetString( | |
| 64 "optionGroupName", | |
| 65 l10n_util::GetStringUTF16(IDS_OOBE_OTHER_KEYBOARD_LAYOUTS)); | |
| 66 input_methods_list->Append(optgroup); | |
| 67 } | |
| 68 | |
| 69 // For "UI Language" drop-down menu at OOBE screen we need to decide which | 49 // For "UI Language" drop-down menu at OOBE screen we need to decide which |
| 70 // entry to mark "selected". If user has just selected "requested_locale", | 50 // entry to mark "selected". If user has just selected "requested_locale", |
| 71 // but "loaded_locale" was actually loaded, we mark original user choice | 51 // but "loaded_locale" was actually loaded, we mark original user choice |
| 72 // "selected" only if loaded_locale is a backup for "requested_locale". | 52 // "selected" only if loaded_locale is a backup for "requested_locale". |
| 73 std::string CalculateSelectedLanguage(const std::string& requested_locale, | 53 std::string CalculateSelectedLanguage(const std::string& requested_locale, |
| 74 const std::string& loaded_locale) { | 54 const std::string& loaded_locale) { |
| 75 | 55 |
| 76 std::string resolved_locale; | 56 std::string resolved_locale; |
| 77 if (!l10n_util::CheckAndResolveLocale(requested_locale, &resolved_locale)) | 57 if (!l10n_util::CheckAndResolveLocale(requested_locale, &resolved_locale)) |
| 78 return loaded_locale; | 58 return loaded_locale; |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 builder->Add("selectLanguage", IDS_LANGUAGE_SELECTION_SELECT); | 185 builder->Add("selectLanguage", IDS_LANGUAGE_SELECTION_SELECT); |
| 206 builder->Add("selectKeyboard", IDS_KEYBOARD_SELECTION_SELECT); | 186 builder->Add("selectKeyboard", IDS_KEYBOARD_SELECTION_SELECT); |
| 207 builder->Add("selectNetwork", IDS_NETWORK_SELECTION_SELECT); | 187 builder->Add("selectNetwork", IDS_NETWORK_SELECTION_SELECT); |
| 208 builder->Add("selectTimezone", IDS_OPTIONS_SETTINGS_TIMEZONE_DESCRIPTION); | 188 builder->Add("selectTimezone", IDS_OPTIONS_SETTINGS_TIMEZONE_DESCRIPTION); |
| 209 builder->Add("proxySettings", IDS_OPTIONS_PROXIES_CONFIGURE_BUTTON); | 189 builder->Add("proxySettings", IDS_OPTIONS_PROXIES_CONFIGURE_BUTTON); |
| 210 builder->Add("continueButton", IDS_NETWORK_SELECTION_CONTINUE_BUTTON); | 190 builder->Add("continueButton", IDS_NETWORK_SELECTION_CONTINUE_BUTTON); |
| 211 } | 191 } |
| 212 | 192 |
| 213 void NetworkScreenHandler::GetAdditionalParameters( | 193 void NetworkScreenHandler::GetAdditionalParameters( |
| 214 base::DictionaryValue* dict) { | 194 base::DictionaryValue* dict) { |
| 215 dict->Set("languageList", GetLanguageList()); | 195 const std::string selected_language = selected_language_code_.empty() ? |
| 216 dict->Set("inputMethodsList", GetInputMethods()); | 196 g_browser_process->GetApplicationLocale() : selected_language_code_; |
| 197 const std::string selected_input_method = |
| 198 input_method::InputMethodManager::Get()->GetCurrentInputMethod().id(); |
| 199 |
| 200 dict->Set("languageList", |
| 201 GetUILanguageList(NULL, selected_language).release()); |
| 202 dict->Set("inputMethodsList", |
| 203 GetLoginKeyboardLayouts(selected_language, |
| 204 selected_input_method).release()); |
| 217 dict->Set("timezoneList", GetTimezoneList()); | 205 dict->Set("timezoneList", GetTimezoneList()); |
| 218 } | 206 } |
| 219 | 207 |
| 220 void NetworkScreenHandler::Initialize() { | 208 void NetworkScreenHandler::Initialize() { |
| 221 EnableContinue(is_continue_enabled_); | 209 EnableContinue(is_continue_enabled_); |
| 222 if (show_on_init_) { | 210 if (show_on_init_) { |
| 223 show_on_init_ = false; | 211 show_on_init_ = false; |
| 224 Show(); | 212 Show(); |
| 225 } | 213 } |
| 226 | 214 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 | 327 |
| 340 CrosSettings::Get()->SetString(kSystemTimezone, timezone_id); | 328 CrosSettings::Get()->SetString(kSystemTimezone, timezone_id); |
| 341 } | 329 } |
| 342 | 330 |
| 343 void NetworkScreenHandler::OnSystemTimezoneChanged() { | 331 void NetworkScreenHandler::OnSystemTimezoneChanged() { |
| 344 std::string current_timezone_id; | 332 std::string current_timezone_id; |
| 345 CrosSettings::Get()->GetString(kSystemTimezone, ¤t_timezone_id); | 333 CrosSettings::Get()->GetString(kSystemTimezone, ¤t_timezone_id); |
| 346 CallJS("setTimezone", current_timezone_id); | 334 CallJS("setTimezone", current_timezone_id); |
| 347 } | 335 } |
| 348 | 336 |
| 349 base::ListValue* NetworkScreenHandler::GetLanguageList() { | |
| 350 const std::string app_locale = g_browser_process->GetApplicationLocale(); | |
| 351 input_method::InputMethodManager* manager = | |
| 352 input_method::InputMethodManager::Get(); | |
| 353 ComponentExtensionIMEManager* comp_manager = | |
| 354 manager->GetComponentExtensionIMEManager(); | |
| 355 input_method::InputMethodDescriptors descriptors; | |
| 356 if (comp_manager->IsInitialized()) | |
| 357 descriptors = comp_manager->GetXkbIMEAsInputMethodDescriptor(); | |
| 358 base::ListValue* languages_list = | |
| 359 options::CrosLanguageOptionsHandler::GetUILanguageList(descriptors); | |
| 360 for (size_t i = 0; i < languages_list->GetSize(); ++i) { | |
| 361 base::DictionaryValue* language_info = NULL; | |
| 362 if (!languages_list->GetDictionary(i, &language_info)) | |
| 363 NOTREACHED(); | |
| 364 | |
| 365 std::string value; | |
| 366 language_info->GetString("code", &value); | |
| 367 std::string display_name; | |
| 368 language_info->GetString("displayName", &display_name); | |
| 369 std::string native_name; | |
| 370 language_info->GetString("nativeDisplayName", &native_name); | |
| 371 | |
| 372 // If it's option group divider, add field name. | |
| 373 if (value == options::kVendorOtherLanguagesListDivider) { | |
| 374 language_info->SetString( | |
| 375 "optionGroupName", | |
| 376 l10n_util::GetStringUTF16(IDS_OOBE_OTHER_LANGUAGES)); | |
| 377 } | |
| 378 if (display_name != native_name) { | |
| 379 display_name = base::StringPrintf("%s - %s", | |
| 380 display_name.c_str(), | |
| 381 native_name.c_str()); | |
| 382 } | |
| 383 | |
| 384 language_info->SetString("value", value); | |
| 385 language_info->SetString("title", display_name); | |
| 386 if (selected_language_code_.empty()) { | |
| 387 if (value == app_locale) | |
| 388 language_info->SetBoolean("selected", true); | |
| 389 } else { | |
| 390 if (value == selected_language_code_) | |
| 391 language_info->SetBoolean("selected", true); | |
| 392 } | |
| 393 } | |
| 394 return languages_list; | |
| 395 } | |
| 396 | |
| 397 base::DictionaryValue* CreateInputMethodsEntry( | |
| 398 const input_method::InputMethodDescriptor& method, | |
| 399 const std::string current_input_method_id) { | |
| 400 input_method::InputMethodUtil* util = | |
| 401 input_method::InputMethodManager::Get()->GetInputMethodUtil(); | |
| 402 const std::string& ime_id = method.id(); | |
| 403 scoped_ptr<base::DictionaryValue> input_method(new base::DictionaryValue); | |
| 404 input_method->SetString("value", ime_id); | |
| 405 input_method->SetString("title", util->GetInputMethodLongName(method)); | |
| 406 input_method->SetBoolean("selected", ime_id == current_input_method_id); | |
| 407 return input_method.release(); | |
| 408 } | |
| 409 | |
| 410 void NetworkScreenHandler::OnImeComponentExtensionInitialized() { | 337 void NetworkScreenHandler::OnImeComponentExtensionInitialized() { |
| 411 // Refreshes the language and keyboard list once the component extension | 338 // Refreshes the language and keyboard list once the component extension |
| 412 // IMEs are initialized. | 339 // IMEs are initialized. |
| 413 if (page_is_ready()) | 340 if (page_is_ready()) |
| 414 ReloadLocalizedContent(); | 341 ReloadLocalizedContent(); |
| 415 else | 342 else |
| 416 should_reinitialize_language_keyboard_list_ = true; | 343 should_reinitialize_language_keyboard_list_ = true; |
| 417 } | 344 } |
| 418 | 345 |
| 419 void NetworkScreenHandler::InputMethodChanged( | 346 void NetworkScreenHandler::InputMethodChanged( |
| 420 input_method::InputMethodManager* manager, bool show_message) { | 347 input_method::InputMethodManager* manager, bool show_message) { |
| 421 CallJS("setInputMethod", manager->GetCurrentInputMethod().id()); | 348 CallJS("setInputMethod", manager->GetCurrentInputMethod().id()); |
| 422 } | 349 } |
| 423 | 350 |
| 424 void NetworkScreenHandler::ReloadLocalizedContent() { | 351 void NetworkScreenHandler::ReloadLocalizedContent() { |
| 425 base::DictionaryValue localized_strings; | 352 base::DictionaryValue localized_strings; |
| 426 static_cast<OobeUI*>(web_ui()->GetController()) | 353 static_cast<OobeUI*>(web_ui()->GetController()) |
| 427 ->GetLocalizedStrings(&localized_strings); | 354 ->GetLocalizedStrings(&localized_strings); |
| 428 core_oobe_actor_->ReloadContent(localized_strings); | 355 core_oobe_actor_->ReloadContent(localized_strings); |
| 429 | 356 |
| 430 // Buttons are recreated, updated "Continue" button state. | 357 // Buttons are recreated, updated "Continue" button state. |
| 431 EnableContinue(is_continue_enabled_); | 358 EnableContinue(is_continue_enabled_); |
| 432 } | 359 } |
| 433 | 360 |
| 434 // static | 361 // static |
| 435 base::ListValue* NetworkScreenHandler::GetInputMethods() { | |
| 436 base::ListValue* input_methods_list = new base::ListValue; | |
| 437 input_method::InputMethodManager* manager = | |
| 438 input_method::InputMethodManager::Get(); | |
| 439 input_method::InputMethodUtil* util = manager->GetInputMethodUtil(); | |
| 440 ComponentExtensionIMEManager* comp_manager = | |
| 441 manager->GetComponentExtensionIMEManager(); | |
| 442 if (!comp_manager->IsInitialized()) { | |
| 443 input_method::InputMethodDescriptor fallback = | |
| 444 util->GetFallbackInputMethodDescriptor(); | |
| 445 input_methods_list->Append( | |
| 446 CreateInputMethodsEntry(fallback, fallback.id())); | |
| 447 return input_methods_list; | |
| 448 } | |
| 449 | |
| 450 const std::vector<std::string>& hardware_login_input_methods = | |
| 451 util->GetHardwareLoginInputMethodIds(); | |
| 452 manager->EnableLoginLayouts(g_browser_process->GetApplicationLocale(), | |
| 453 hardware_login_input_methods); | |
| 454 | |
| 455 scoped_ptr<input_method::InputMethodDescriptors> input_methods( | |
| 456 manager->GetActiveInputMethods()); | |
| 457 const std::string current_input_method_id = | |
| 458 manager->GetCurrentInputMethod().id(); | |
| 459 std::set<std::string> input_methods_added; | |
| 460 | |
| 461 for (std::vector<std::string>::const_iterator i = | |
| 462 hardware_login_input_methods.begin(); | |
| 463 i != hardware_login_input_methods.end(); | |
| 464 ++i) { | |
| 465 const input_method::InputMethodDescriptor* ime = | |
| 466 util->GetInputMethodDescriptorFromId(*i); | |
| 467 DCHECK(ime != NULL); | |
| 468 // Do not crash in case of misconfiguration. | |
| 469 if (ime != NULL) { | |
| 470 input_methods_added.insert(*i); | |
| 471 input_methods_list->Append( | |
| 472 CreateInputMethodsEntry(*ime, current_input_method_id)); | |
| 473 } | |
| 474 } | |
| 475 | |
| 476 bool optgroup_added = false; | |
| 477 for (size_t i = 0; i < input_methods->size(); ++i) { | |
| 478 // Makes sure the id is in legacy xkb id format. | |
| 479 const std::string& ime_id = (*input_methods)[i].id(); | |
| 480 if (!InsertString(ime_id, input_methods_added)) | |
| 481 continue; | |
| 482 if (!optgroup_added) { | |
| 483 optgroup_added = true; | |
| 484 AddOptgroupOtherLayouts(input_methods_list); | |
| 485 } | |
| 486 input_methods_list->Append( | |
| 487 CreateInputMethodsEntry((*input_methods)[i], current_input_method_id)); | |
| 488 } | |
| 489 // "xkb:us::eng" should always be in the list of available layouts. | |
| 490 const std::string us_keyboard_id = | |
| 491 util->GetFallbackInputMethodDescriptor().id(); | |
| 492 if (input_methods_added.find(us_keyboard_id) == input_methods_added.end()) { | |
| 493 const input_method::InputMethodDescriptor* us_eng_descriptor = | |
| 494 util->GetInputMethodDescriptorFromId(us_keyboard_id); | |
| 495 DCHECK(us_eng_descriptor != NULL); | |
| 496 if (!optgroup_added) { | |
| 497 optgroup_added = true; | |
| 498 AddOptgroupOtherLayouts(input_methods_list); | |
| 499 } | |
| 500 input_methods_list->Append( | |
| 501 CreateInputMethodsEntry(*us_eng_descriptor, current_input_method_id)); | |
| 502 } | |
| 503 return input_methods_list; | |
| 504 } | |
| 505 | |
| 506 // static | |
| 507 base::ListValue* NetworkScreenHandler::GetTimezoneList() { | 362 base::ListValue* NetworkScreenHandler::GetTimezoneList() { |
| 508 std::string current_timezone_id; | 363 std::string current_timezone_id; |
| 509 CrosSettings::Get()->GetString(kSystemTimezone, ¤t_timezone_id); | 364 CrosSettings::Get()->GetString(kSystemTimezone, ¤t_timezone_id); |
| 510 | 365 |
| 511 scoped_ptr<base::ListValue> timezone_list(new base::ListValue); | 366 scoped_ptr<base::ListValue> timezone_list(new base::ListValue); |
| 512 scoped_ptr<base::ListValue> timezones = system::GetTimezoneList().Pass(); | 367 scoped_ptr<base::ListValue> timezones = system::GetTimezoneList().Pass(); |
| 513 for (size_t i = 0; i < timezones->GetSize(); ++i) { | 368 for (size_t i = 0; i < timezones->GetSize(); ++i) { |
| 514 const base::ListValue* timezone = NULL; | 369 const base::ListValue* timezone = NULL; |
| 515 CHECK(timezones->GetList(i, &timezone)); | 370 CHECK(timezones->GetList(i, &timezone)); |
| 516 | 371 |
| 517 std::string timezone_id; | 372 std::string timezone_id; |
| 518 CHECK(timezone->GetString(0, &timezone_id)); | 373 CHECK(timezone->GetString(0, &timezone_id)); |
| 519 | 374 |
| 520 std::string timezone_name; | 375 std::string timezone_name; |
| 521 CHECK(timezone->GetString(1, &timezone_name)); | 376 CHECK(timezone->GetString(1, &timezone_name)); |
| 522 | 377 |
| 523 scoped_ptr<base::DictionaryValue> timezone_option( | 378 scoped_ptr<base::DictionaryValue> timezone_option( |
| 524 new base::DictionaryValue); | 379 new base::DictionaryValue); |
| 525 timezone_option->SetString("value", timezone_id); | 380 timezone_option->SetString("value", timezone_id); |
| 526 timezone_option->SetString("title", timezone_name); | 381 timezone_option->SetString("title", timezone_name); |
| 527 timezone_option->SetBoolean("selected", timezone_id == current_timezone_id); | 382 timezone_option->SetBoolean("selected", timezone_id == current_timezone_id); |
| 528 timezone_list->Append(timezone_option.release()); | 383 timezone_list->Append(timezone_option.release()); |
| 529 } | 384 } |
| 530 | 385 |
| 531 return timezone_list.release(); | 386 return timezone_list.release(); |
| 532 } | 387 } |
| 533 | 388 |
| 534 } // namespace chromeos | 389 } // namespace chromeos |
| OLD | NEW |