| 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::Get()-> |
| 90 GetComponentExtensionIMEManager()->AddObserver(this); |
| 88 } | 91 } |
| 89 | 92 |
| 90 NetworkScreenHandler::~NetworkScreenHandler() { | 93 NetworkScreenHandler::~NetworkScreenHandler() { |
| 91 if (screen_) | 94 if (screen_) |
| 92 screen_->OnActorDestroyed(this); | 95 screen_->OnActorDestroyed(this); |
| 96 |
| 97 input_method::InputMethodManager::Get()-> |
| 98 GetComponentExtensionIMEManager()->RemoveObserver(this); |
| 93 } | 99 } |
| 94 | 100 |
| 95 // NetworkScreenHandler, NetworkScreenActor implementation: -------------------- | 101 // NetworkScreenHandler, NetworkScreenActor implementation: -------------------- |
| 96 | 102 |
| 97 void NetworkScreenHandler::SetDelegate(NetworkScreenActor::Delegate* screen) { | 103 void NetworkScreenHandler::SetDelegate(NetworkScreenActor::Delegate* screen) { |
| 98 screen_ = screen; | 104 screen_ = screen; |
| 99 } | 105 } |
| 100 | 106 |
| 101 void NetworkScreenHandler::PrepareToShow() { | 107 void NetworkScreenHandler::PrepareToShow() { |
| 102 } | 108 } |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 | 372 |
| 367 bool NetworkScreenHandler::IsDerelict() { | 373 bool NetworkScreenHandler::IsDerelict() { |
| 368 return time_on_oobe_ >= derelict_detection_timeout_; | 374 return time_on_oobe_ >= derelict_detection_timeout_; |
| 369 } | 375 } |
| 370 | 376 |
| 371 // static | 377 // static |
| 372 base::ListValue* NetworkScreenHandler::GetLanguageList() { | 378 base::ListValue* NetworkScreenHandler::GetLanguageList() { |
| 373 const std::string app_locale = g_browser_process->GetApplicationLocale(); | 379 const std::string app_locale = g_browser_process->GetApplicationLocale(); |
| 374 input_method::InputMethodManager* manager = | 380 input_method::InputMethodManager* manager = |
| 375 input_method::InputMethodManager::Get(); | 381 input_method::InputMethodManager::Get(); |
| 376 // GetSupportedInputMethods() never returns NULL. | 382 ComponentExtensionIMEManager* comp_manager = |
| 377 scoped_ptr<input_method::InputMethodDescriptors> descriptors( | 383 manager->GetComponentExtensionIMEManager(); |
| 378 manager->GetSupportedInputMethods()); | 384 input_method::InputMethodDescriptors descriptors; |
| 385 if (extension_ime_util::UseWrappedExtensionKeyboardLayouts()) { |
| 386 if (comp_manager->IsInitialized()) |
| 387 descriptors = comp_manager->GetXkbIMEAsInputMethodDescriptor(); |
| 388 } else { |
| 389 descriptors = *(manager->GetSupportedInputMethods()); |
| 390 } |
| 379 base::ListValue* languages_list = | 391 base::ListValue* languages_list = |
| 380 options::CrosLanguageOptionsHandler::GetUILanguageList(*descriptors); | 392 options::CrosLanguageOptionsHandler::GetUILanguageList(descriptors); |
| 381 for (size_t i = 0; i < languages_list->GetSize(); ++i) { | 393 for (size_t i = 0; i < languages_list->GetSize(); ++i) { |
| 382 base::DictionaryValue* language_info = NULL; | 394 base::DictionaryValue* language_info = NULL; |
| 383 if (!languages_list->GetDictionary(i, &language_info)) | 395 if (!languages_list->GetDictionary(i, &language_info)) |
| 384 NOTREACHED(); | 396 NOTREACHED(); |
| 385 | 397 |
| 386 std::string value; | 398 std::string value; |
| 387 language_info->GetString("code", &value); | 399 language_info->GetString("code", &value); |
| 388 std::string display_name; | 400 std::string display_name; |
| 389 language_info->GetString("displayName", &display_name); | 401 language_info->GetString("displayName", &display_name); |
| 390 std::string native_name; | 402 std::string native_name; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 415 input_method::InputMethodUtil* util = | 427 input_method::InputMethodUtil* util = |
| 416 input_method::InputMethodManager::Get()->GetInputMethodUtil(); | 428 input_method::InputMethodManager::Get()->GetInputMethodUtil(); |
| 417 const std::string& ime_id = method.id(); | 429 const std::string& ime_id = method.id(); |
| 418 scoped_ptr<base::DictionaryValue> input_method(new base::DictionaryValue); | 430 scoped_ptr<base::DictionaryValue> input_method(new base::DictionaryValue); |
| 419 input_method->SetString("value", ime_id); | 431 input_method->SetString("value", ime_id); |
| 420 input_method->SetString("title", util->GetInputMethodLongName(method)); | 432 input_method->SetString("title", util->GetInputMethodLongName(method)); |
| 421 input_method->SetBoolean("selected", ime_id == current_input_method_id); | 433 input_method->SetBoolean("selected", ime_id == current_input_method_id); |
| 422 return input_method.release(); | 434 return input_method.release(); |
| 423 } | 435 } |
| 424 | 436 |
| 437 void NetworkScreenHandler::OnImeComponentExtensionInitialized() { |
| 438 input_method::InputMethodManager* manager = |
| 439 input_method::InputMethodManager::Get(); |
| 440 manager->SetInputMethodLoginDefault(); |
| 441 |
| 442 base::DictionaryValue localized_strings; |
| 443 static_cast<OobeUI*>(this->web_ui()->GetController()) |
| 444 ->GetLocalizedStrings(&localized_strings); |
| 445 this->core_oobe_actor_->ReloadContent(localized_strings); |
| 446 |
| 447 // Buttons are recreated, updated "Continue" button state. |
| 448 this->EnableContinue(this->is_continue_enabled_); |
| 449 } |
| 450 |
| 425 // static | 451 // static |
| 426 base::ListValue* NetworkScreenHandler::GetInputMethods() { | 452 base::ListValue* NetworkScreenHandler::GetInputMethods() { |
| 427 base::ListValue* input_methods_list = new base::ListValue; | 453 base::ListValue* input_methods_list = new base::ListValue; |
| 428 input_method::InputMethodManager* manager = | 454 input_method::InputMethodManager* manager = |
| 429 input_method::InputMethodManager::Get(); | 455 input_method::InputMethodManager::Get(); |
| 430 input_method::InputMethodUtil* util = manager->GetInputMethodUtil(); | 456 input_method::InputMethodUtil* util = manager->GetInputMethodUtil(); |
| 457 ComponentExtensionIMEManager* comp_manager = |
| 458 manager->GetComponentExtensionIMEManager(); |
| 459 if (!comp_manager->IsInitialized()) { |
| 460 input_method::InputMethodDescriptor fallback = |
| 461 util->GetFallbackInputMethodDescriptor(); |
| 462 input_methods_list->Append( |
| 463 CreateInputMethodsEntry(fallback, fallback.id())); |
| 464 return input_methods_list; |
| 465 } |
| 466 |
| 431 scoped_ptr<input_method::InputMethodDescriptors> input_methods( | 467 scoped_ptr<input_method::InputMethodDescriptors> input_methods( |
| 432 manager->GetActiveInputMethods()); | 468 manager->GetActiveInputMethods()); |
| 433 // Uses extension_ime_util::MaybeGetLegacyXkbId() to make sure the input | 469 const std::string& current_input_method_id = |
| 434 // method id is in legacy xkb id format (e.g. xkb:us::eng), instead of | 470 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 = | 471 const std::vector<std::string>& hardware_login_input_methods = |
| 443 util->GetHardwareLoginInputMethodIds(); | 472 util->GetHardwareLoginInputMethodIds(); |
| 444 std::set<std::string> input_methods_added; | 473 std::set<std::string> input_methods_added; |
| 445 | 474 |
| 446 for (std::vector<std::string>::const_iterator i = | 475 for (std::vector<std::string>::const_iterator i = |
| 447 hardware_login_input_methods.begin(); | 476 hardware_login_input_methods.begin(); |
| 448 i != hardware_login_input_methods.end(); | 477 i != hardware_login_input_methods.end(); |
| 449 ++i) { | 478 ++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 = | 479 const input_method::InputMethodDescriptor* ime = |
| 454 util->GetInputMethodDescriptorFromId(id); | 480 util->GetInputMethodDescriptorFromId(*i); |
| 455 DCHECK(ime != NULL); | 481 DCHECK(ime != NULL); |
| 456 // Do not crash in case of misconfiguration. | 482 // Do not crash in case of misconfiguration. |
| 457 if (ime != NULL) { | 483 if (ime != NULL) { |
| 484 input_methods_added.insert(*i); |
| 458 input_methods_list->Append( | 485 input_methods_list->Append( |
| 459 CreateInputMethodsEntry(*ime, current_input_method_id)); | 486 CreateInputMethodsEntry(*ime, current_input_method_id)); |
| 460 } | 487 } |
| 461 } | 488 } |
| 462 | 489 |
| 463 bool optgroup_added = false; | 490 bool optgroup_added = false; |
| 464 for (size_t i = 0; i < input_methods->size(); ++i) { | 491 for (size_t i = 0; i < input_methods->size(); ++i) { |
| 465 // Makes sure the id is in legacy xkb id format. | 492 // Makes sure the id is in legacy xkb id format. |
| 466 const std::string& ime_id = extension_ime_util::MaybeGetLegacyXkbId( | 493 const std::string& ime_id = (*input_methods)[i].id(); |
| 467 (*input_methods)[i].id()); | |
| 468 if (!InsertString(ime_id, input_methods_added)) | 494 if (!InsertString(ime_id, input_methods_added)) |
| 469 continue; | 495 continue; |
| 470 if (!optgroup_added) { | 496 if (!optgroup_added) { |
| 471 optgroup_added = true; | 497 optgroup_added = true; |
| 472 AddOptgroupOtherLayouts(input_methods_list); | 498 AddOptgroupOtherLayouts(input_methods_list); |
| 473 } | 499 } |
| 474 input_methods_list->Append( | 500 input_methods_list->Append( |
| 475 CreateInputMethodsEntry((*input_methods)[i], current_input_method_id)); | 501 CreateInputMethodsEntry((*input_methods)[i], current_input_method_id)); |
| 476 } | 502 } |
| 477 // "xkb:us::eng" should always be in the list of available layouts. | 503 // "xkb:us::eng" should always be in the list of available layouts. |
| 478 if (input_methods_added.count(kUSlayout) == 0) { | 504 const std::string& us_keyboard_id = |
| 505 extension_ime_util::GetInputMethodIDByKeyboardLayout(kUSLayout); |
| 506 if (input_methods_added.find(us_keyboard_id) == input_methods_added.end()) { |
| 479 const input_method::InputMethodDescriptor* us_eng_descriptor = | 507 const input_method::InputMethodDescriptor* us_eng_descriptor = |
| 480 util->GetInputMethodDescriptorFromId(kUSlayout); | 508 util->GetInputMethodDescriptorFromId(us_keyboard_id); |
| 481 DCHECK(us_eng_descriptor != NULL); | 509 DCHECK(us_eng_descriptor != NULL); |
| 482 if (!optgroup_added) { | 510 if (!optgroup_added) { |
| 483 optgroup_added = true; | 511 optgroup_added = true; |
| 484 AddOptgroupOtherLayouts(input_methods_list); | 512 AddOptgroupOtherLayouts(input_methods_list); |
| 485 } | 513 } |
| 486 input_methods_list->Append( | 514 input_methods_list->Append( |
| 487 CreateInputMethodsEntry(*us_eng_descriptor, current_input_method_id)); | 515 CreateInputMethodsEntry(*us_eng_descriptor, current_input_method_id)); |
| 488 } | 516 } |
| 489 return input_methods_list; | 517 return input_methods_list; |
| 490 } | 518 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 511 timezone_option->SetString("value", timezone_id); | 539 timezone_option->SetString("value", timezone_id); |
| 512 timezone_option->SetString("title", timezone_name); | 540 timezone_option->SetString("title", timezone_name); |
| 513 timezone_option->SetBoolean("selected", timezone_id == current_timezone_id); | 541 timezone_option->SetBoolean("selected", timezone_id == current_timezone_id); |
| 514 timezone_list->Append(timezone_option.release()); | 542 timezone_list->Append(timezone_option.release()); |
| 515 } | 543 } |
| 516 | 544 |
| 517 return timezone_list.release(); | 545 return timezone_list.release(); |
| 518 } | 546 } |
| 519 | 547 |
| 520 } // namespace chromeos | 548 } // namespace chromeos |
| OLD | NEW |