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