| 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> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 namespace { | 42 namespace { |
| 43 | 43 |
| 44 const char kJsScreenPath[] = "login.NetworkScreen"; | 44 const char kJsScreenPath[] = "login.NetworkScreen"; |
| 45 | 45 |
| 46 // JS API callbacks names. | 46 // JS API callbacks names. |
| 47 const char kJsApiNetworkOnExit[] = "networkOnExit"; | 47 const char kJsApiNetworkOnExit[] = "networkOnExit"; |
| 48 const char kJsApiNetworkOnLanguageChanged[] = "networkOnLanguageChanged"; | 48 const char kJsApiNetworkOnLanguageChanged[] = "networkOnLanguageChanged"; |
| 49 const char kJsApiNetworkOnInputMethodChanged[] = "networkOnInputMethodChanged"; | 49 const char kJsApiNetworkOnInputMethodChanged[] = "networkOnInputMethodChanged"; |
| 50 const char kJsApiNetworkOnTimezoneChanged[] = "networkOnTimezoneChanged"; | 50 const char kJsApiNetworkOnTimezoneChanged[] = "networkOnTimezoneChanged"; |
| 51 | 51 |
| 52 const char kUSlayout[] = "xkb:us::eng"; | 52 const char kUSLayout[] = "xkb:us::eng"; |
| 53 | 53 |
| 54 const int kDerelectDetectionTimeoutSeconds = 8 * 60 * 60; // 8 hours. | 54 const int kDerelectDetectionTimeoutSeconds = 8 * 60 * 60; // 8 hours. |
| 55 const int kDerelectIdleTimeoutSeconds = 5 * 60; // 5 minutes. | 55 const int kDerelectIdleTimeoutSeconds = 5 * 60; // 5 minutes. |
| 56 const int kOobeTimerUpdateIntervalSeconds = 5 * 60; // 5 minutes. | 56 const int kOobeTimerUpdateIntervalSeconds = 5 * 60; // 5 minutes. |
| 57 | 57 |
| 58 // Returns true if element was inserted. | 58 // Returns true if element was inserted. |
| 59 bool InsertString(const std::string& str, std::set<std::string>& to) { | 59 bool InsertString(const std::string& str, std::set<std::string>& to) { |
| 60 const std::pair<std::set<std::string>::iterator, bool> result = | 60 const std::pair<std::set<std::string>::iterator, bool> result = |
| 61 to.insert(str); | 61 to.insert(str); |
| 62 return result.second; | 62 return result.second; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 78 | 78 |
| 79 NetworkScreenHandler::NetworkScreenHandler(CoreOobeActor* core_oobe_actor) | 79 NetworkScreenHandler::NetworkScreenHandler(CoreOobeActor* core_oobe_actor) |
| 80 : BaseScreenHandler(kJsScreenPath), | 80 : BaseScreenHandler(kJsScreenPath), |
| 81 screen_(NULL), | 81 screen_(NULL), |
| 82 core_oobe_actor_(core_oobe_actor), | 82 core_oobe_actor_(core_oobe_actor), |
| 83 is_continue_enabled_(false), | 83 is_continue_enabled_(false), |
| 84 show_on_init_(false), | 84 show_on_init_(false), |
| 85 weak_ptr_factory_(this) { | 85 weak_ptr_factory_(this) { |
| 86 DCHECK(core_oobe_actor_); | 86 DCHECK(core_oobe_actor_); |
| 87 SetupTimeouts(); | 87 SetupTimeouts(); |
| 88 |
| 89 input_method::InputMethodManager* manager = |
| 90 input_method::InputMethodManager::Get(); |
| 91 manager->SetInputMethodLoginDefault(); |
| 92 manager->GetComponentExtensionIMEManager()->AddObserver(this); |
| 88 } | 93 } |
| 89 | 94 |
| 90 NetworkScreenHandler::~NetworkScreenHandler() { | 95 NetworkScreenHandler::~NetworkScreenHandler() { |
| 91 if (screen_) | 96 if (screen_) |
| 92 screen_->OnActorDestroyed(this); | 97 screen_->OnActorDestroyed(this); |
| 98 |
| 99 input_method::InputMethodManager::Get() |
| 100 ->GetComponentExtensionIMEManager() |
| 101 ->RemoveObserver(this); |
| 93 } | 102 } |
| 94 | 103 |
| 95 // NetworkScreenHandler, NetworkScreenActor implementation: -------------------- | 104 // NetworkScreenHandler, NetworkScreenActor implementation: -------------------- |
| 96 | 105 |
| 97 void NetworkScreenHandler::SetDelegate(NetworkScreenActor::Delegate* screen) { | 106 void NetworkScreenHandler::SetDelegate(NetworkScreenActor::Delegate* screen) { |
| 98 screen_ = screen; | 107 screen_ = screen; |
| 99 } | 108 } |
| 100 | 109 |
| 101 void NetworkScreenHandler::PrepareToShow() { | 110 void NetworkScreenHandler::PrepareToShow() { |
| 102 } | 111 } |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 | 375 |
| 367 bool NetworkScreenHandler::IsDerelict() { | 376 bool NetworkScreenHandler::IsDerelict() { |
| 368 return time_on_oobe_ >= derelict_detection_timeout_; | 377 return time_on_oobe_ >= derelict_detection_timeout_; |
| 369 } | 378 } |
| 370 | 379 |
| 371 // static | 380 // static |
| 372 base::ListValue* NetworkScreenHandler::GetLanguageList() { | 381 base::ListValue* NetworkScreenHandler::GetLanguageList() { |
| 373 const std::string app_locale = g_browser_process->GetApplicationLocale(); | 382 const std::string app_locale = g_browser_process->GetApplicationLocale(); |
| 374 input_method::InputMethodManager* manager = | 383 input_method::InputMethodManager* manager = |
| 375 input_method::InputMethodManager::Get(); | 384 input_method::InputMethodManager::Get(); |
| 376 // GetSupportedInputMethods() never returns NULL. | 385 ComponentExtensionIMEManager* comp_manager = |
| 377 scoped_ptr<input_method::InputMethodDescriptors> descriptors( | 386 manager->GetComponentExtensionIMEManager(); |
| 378 manager->GetSupportedInputMethods()); | 387 input_method::InputMethodDescriptors descriptors; |
| 388 if (extension_ime_util::UseWrappedExtensionKeyboardLayouts()) { |
| 389 if (comp_manager->IsInitialized()) |
| 390 descriptors = comp_manager->GetXkbIMEAsInputMethodDescriptor(); |
| 391 } else { |
| 392 descriptors = *(manager->GetSupportedInputMethods()); |
| 393 } |
| 379 base::ListValue* languages_list = | 394 base::ListValue* languages_list = |
| 380 options::CrosLanguageOptionsHandler::GetUILanguageList(*descriptors); | 395 options::CrosLanguageOptionsHandler::GetUILanguageList(descriptors); |
| 381 for (size_t i = 0; i < languages_list->GetSize(); ++i) { | 396 for (size_t i = 0; i < languages_list->GetSize(); ++i) { |
| 382 base::DictionaryValue* language_info = NULL; | 397 base::DictionaryValue* language_info = NULL; |
| 383 if (!languages_list->GetDictionary(i, &language_info)) | 398 if (!languages_list->GetDictionary(i, &language_info)) |
| 384 NOTREACHED(); | 399 NOTREACHED(); |
| 385 | 400 |
| 386 std::string value; | 401 std::string value; |
| 387 language_info->GetString("code", &value); | 402 language_info->GetString("code", &value); |
| 388 std::string display_name; | 403 std::string display_name; |
| 389 language_info->GetString("displayName", &display_name); | 404 language_info->GetString("displayName", &display_name); |
| 390 std::string native_name; | 405 std::string native_name; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 415 input_method::InputMethodUtil* util = | 430 input_method::InputMethodUtil* util = |
| 416 input_method::InputMethodManager::Get()->GetInputMethodUtil(); | 431 input_method::InputMethodManager::Get()->GetInputMethodUtil(); |
| 417 const std::string& ime_id = method.id(); | 432 const std::string& ime_id = method.id(); |
| 418 scoped_ptr<base::DictionaryValue> input_method(new base::DictionaryValue); | 433 scoped_ptr<base::DictionaryValue> input_method(new base::DictionaryValue); |
| 419 input_method->SetString("value", ime_id); | 434 input_method->SetString("value", ime_id); |
| 420 input_method->SetString("title", util->GetInputMethodLongName(method)); | 435 input_method->SetString("title", util->GetInputMethodLongName(method)); |
| 421 input_method->SetBoolean("selected", ime_id == current_input_method_id); | 436 input_method->SetBoolean("selected", ime_id == current_input_method_id); |
| 422 return input_method.release(); | 437 return input_method.release(); |
| 423 } | 438 } |
| 424 | 439 |
| 440 void NetworkScreenHandler::OnImeComponentExtensionInitialized() { |
| 441 input_method::InputMethodManager::Get()->SetInputMethodLoginDefault(); |
| 442 |
| 443 // Refreshes the language and keyboard list once the component extension |
| 444 // IMEs are initialized. |
| 445 base::DictionaryValue localized_strings; |
| 446 static_cast<OobeUI*>(this->web_ui()->GetController()) |
| 447 ->GetLocalizedStrings(&localized_strings); |
| 448 this->core_oobe_actor_->ReloadContent(localized_strings); |
| 449 this->EnableContinue(this->is_continue_enabled_); |
| 450 } |
| 451 |
| 425 // static | 452 // static |
| 426 base::ListValue* NetworkScreenHandler::GetInputMethods() { | 453 base::ListValue* NetworkScreenHandler::GetInputMethods() { |
| 427 base::ListValue* input_methods_list = new base::ListValue; | 454 base::ListValue* input_methods_list = new base::ListValue; |
| 428 input_method::InputMethodManager* manager = | 455 input_method::InputMethodManager* manager = |
| 429 input_method::InputMethodManager::Get(); | 456 input_method::InputMethodManager::Get(); |
| 430 input_method::InputMethodUtil* util = manager->GetInputMethodUtil(); | 457 input_method::InputMethodUtil* util = manager->GetInputMethodUtil(); |
| 458 if (extension_ime_util::UseWrappedExtensionKeyboardLayouts()) { |
| 459 ComponentExtensionIMEManager* comp_manager = |
| 460 manager->GetComponentExtensionIMEManager(); |
| 461 if (!comp_manager->IsInitialized()) { |
| 462 input_method::InputMethodDescriptor fallback = |
| 463 util->GetFallbackInputMethodDescriptor(); |
| 464 input_methods_list->Append( |
| 465 CreateInputMethodsEntry(fallback, fallback.id())); |
| 466 return input_methods_list; |
| 467 } |
| 468 } |
| 469 |
| 431 scoped_ptr<input_method::InputMethodDescriptors> input_methods( | 470 scoped_ptr<input_method::InputMethodDescriptors> input_methods( |
| 432 manager->GetActiveInputMethods()); | 471 manager->GetActiveInputMethods()); |
| 433 // Uses extension_ime_util::MaybeGetLegacyXkbId() to make sure the input | 472 const std::string& current_input_method_id = |
| 434 // method id is in legacy xkb id format (e.g. xkb:us::eng), instead of | 473 manager->GetCurrentInputMethod().id(); |
| 435 // extension based xkd id format (e.g. _comp_ime_...xkb:us::eng). | |
| 436 // Same for the rests. | |
| 437 // TODO(shuchen): support wait for component extension loading, and then show | |
| 438 // OOBE window. So that extension_ime_util::MaybeGetLegacyXkbId() can be | |
| 439 // removed. | |
| 440 std::string current_input_method_id = extension_ime_util::MaybeGetLegacyXkbId( | |
| 441 manager->GetCurrentInputMethod().id()); | |
| 442 const std::vector<std::string>& hardware_login_input_methods = | 474 const std::vector<std::string>& hardware_login_input_methods = |
| 443 util->GetHardwareLoginInputMethodIds(); | 475 util->GetHardwareLoginInputMethodIds(); |
| 444 std::set<std::string> input_methods_added; | 476 std::set<std::string> input_methods_added; |
| 445 | 477 |
| 446 for (std::vector<std::string>::const_iterator i = | 478 for (std::vector<std::string>::const_iterator i = |
| 447 hardware_login_input_methods.begin(); | 479 hardware_login_input_methods.begin(); |
| 448 i != hardware_login_input_methods.end(); | 480 i != hardware_login_input_methods.end(); |
| 449 ++i) { | 481 ++i) { |
| 450 // Makes sure the id is in legacy xkb id format. | |
| 451 const std::string id = extension_ime_util::MaybeGetLegacyXkbId(*i); | |
| 452 input_methods_added.insert(id); | |
| 453 const input_method::InputMethodDescriptor* ime = | 482 const input_method::InputMethodDescriptor* ime = |
| 454 util->GetInputMethodDescriptorFromId(id); | 483 util->GetInputMethodDescriptorFromId(*i); |
| 455 DCHECK(ime != NULL); | 484 DCHECK(ime != NULL); |
| 456 // Do not crash in case of misconfiguration. | 485 // Do not crash in case of misconfiguration. |
| 457 if (ime != NULL) { | 486 if (ime != NULL) { |
| 487 input_methods_added.insert(*i); |
| 458 input_methods_list->Append( | 488 input_methods_list->Append( |
| 459 CreateInputMethodsEntry(*ime, current_input_method_id)); | 489 CreateInputMethodsEntry(*ime, current_input_method_id)); |
| 460 } | 490 } |
| 461 } | 491 } |
| 462 | 492 |
| 463 bool optgroup_added = false; | 493 bool optgroup_added = false; |
| 464 for (size_t i = 0; i < input_methods->size(); ++i) { | 494 for (size_t i = 0; i < input_methods->size(); ++i) { |
| 465 // Makes sure the id is in legacy xkb id format. | 495 // Makes sure the id is in legacy xkb id format. |
| 466 const std::string& ime_id = extension_ime_util::MaybeGetLegacyXkbId( | 496 const std::string& ime_id = (*input_methods)[i].id(); |
| 467 (*input_methods)[i].id()); | |
| 468 if (!InsertString(ime_id, input_methods_added)) | 497 if (!InsertString(ime_id, input_methods_added)) |
| 469 continue; | 498 continue; |
| 470 if (!optgroup_added) { | 499 if (!optgroup_added) { |
| 471 optgroup_added = true; | 500 optgroup_added = true; |
| 472 AddOptgroupOtherLayouts(input_methods_list); | 501 AddOptgroupOtherLayouts(input_methods_list); |
| 473 } | 502 } |
| 474 input_methods_list->Append( | 503 input_methods_list->Append( |
| 475 CreateInputMethodsEntry((*input_methods)[i], current_input_method_id)); | 504 CreateInputMethodsEntry((*input_methods)[i], current_input_method_id)); |
| 476 } | 505 } |
| 477 // "xkb:us::eng" should always be in the list of available layouts. | 506 // "xkb:us::eng" should always be in the list of available layouts. |
| 478 if (input_methods_added.count(kUSlayout) == 0) { | 507 const std::string& us_keyboard_id = |
| 508 extension_ime_util::GetInputMethodIDByKeyboardLayout(kUSLayout); |
| 509 if (input_methods_added.find(us_keyboard_id) == input_methods_added.end()) { |
| 479 const input_method::InputMethodDescriptor* us_eng_descriptor = | 510 const input_method::InputMethodDescriptor* us_eng_descriptor = |
| 480 util->GetInputMethodDescriptorFromId(kUSlayout); | 511 util->GetInputMethodDescriptorFromId(us_keyboard_id); |
| 481 DCHECK(us_eng_descriptor != NULL); | 512 DCHECK(us_eng_descriptor != NULL); |
| 482 if (!optgroup_added) { | 513 if (!optgroup_added) { |
| 483 optgroup_added = true; | 514 optgroup_added = true; |
| 484 AddOptgroupOtherLayouts(input_methods_list); | 515 AddOptgroupOtherLayouts(input_methods_list); |
| 485 } | 516 } |
| 486 input_methods_list->Append( | 517 input_methods_list->Append( |
| 487 CreateInputMethodsEntry(*us_eng_descriptor, current_input_method_id)); | 518 CreateInputMethodsEntry(*us_eng_descriptor, current_input_method_id)); |
| 488 } | 519 } |
| 489 return input_methods_list; | 520 return input_methods_list; |
| 490 } | 521 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 511 timezone_option->SetString("value", timezone_id); | 542 timezone_option->SetString("value", timezone_id); |
| 512 timezone_option->SetString("title", timezone_name); | 543 timezone_option->SetString("title", timezone_name); |
| 513 timezone_option->SetBoolean("selected", timezone_id == current_timezone_id); | 544 timezone_option->SetBoolean("selected", timezone_id == current_timezone_id); |
| 514 timezone_list->Append(timezone_option.release()); | 545 timezone_list->Append(timezone_option.release()); |
| 515 } | 546 } |
| 516 | 547 |
| 517 return timezone_list.release(); | 548 return timezone_list.release(); |
| 518 } | 549 } |
| 519 | 550 |
| 520 } // namespace chromeos | 551 } // namespace chromeos |
| OLD | NEW |