Chromium Code Reviews| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after 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::OnInitialized() { | |
| 438 LOG(ERROR) << "------NetworkScreenHandler::OnInitialized"; | |
|
Seigo Nonaka
2014/03/07 07:50:05
Please remove debug code.
Shu Chen
2014/03/07 08:25:32
Done.
| |
| 439 input_method::InputMethodManager* manager = | |
| 440 input_method::InputMethodManager::Get(); | |
| 441 manager->SetInputMethodLoginDefault(); | |
| 442 LOG(ERROR) << "------NetworkScreenHandler::OnInitialized, set login layouts"; | |
| 443 | |
| 444 base::DictionaryValue localized_strings; | |
| 445 static_cast<OobeUI*>(this->web_ui()->GetController()) | |
| 446 ->GetLocalizedStrings(&localized_strings); | |
| 447 this->core_oobe_actor_->ReloadContent(localized_strings); | |
|
Seigo Nonaka
2014/03/07 07:50:05
Question: does ReloadContent cause display blink a
Shu Chen
2014/03/07 08:25:32
ReloadContent() methods will just call a JS functi
| |
| 448 LOG(ERROR) << "------NetworkScreenHandler::OnInitialized, reload content"; | |
| 449 | |
| 450 // Buttons are recreated, updated "Continue" button state. | |
| 451 this->EnableContinue(this->is_continue_enabled_); | |
| 452 } | |
| 453 | |
| 425 // static | 454 // static |
| 426 base::ListValue* NetworkScreenHandler::GetInputMethods() { | 455 base::ListValue* NetworkScreenHandler::GetInputMethods() { |
| 427 base::ListValue* input_methods_list = new base::ListValue; | 456 base::ListValue* input_methods_list = new base::ListValue; |
| 428 input_method::InputMethodManager* manager = | 457 input_method::InputMethodManager* manager = |
| 429 input_method::InputMethodManager::Get(); | 458 input_method::InputMethodManager::Get(); |
| 430 input_method::InputMethodUtil* util = manager->GetInputMethodUtil(); | 459 input_method::InputMethodUtil* util = manager->GetInputMethodUtil(); |
| 460 ComponentExtensionIMEManager* comp_manager = | |
| 461 manager->GetComponentExtensionIMEManager(); | |
| 462 if (!comp_manager->IsInitialized()) { | |
| 463 input_method::InputMethodDescriptor fallback = | |
| 464 util->GetFallbackInputMethodDescriptor(); | |
| 465 input_methods_list->Append( | |
| 466 CreateInputMethodsEntry(fallback, fallback.id())); | |
| 467 return input_methods_list; | |
| 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 std::string current_input_method_id = manager->GetCurrentInputMethod().id(); |
| 434 // method id is in legacy xkb id format (e.g. xkb:us::eng), instead of | |
| 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 = | 473 const std::vector<std::string>& hardware_login_input_methods = |
| 443 util->GetHardwareLoginInputMethodIds(); | 474 util->GetHardwareLoginInputMethodIds(); |
| 444 std::set<std::string> input_methods_added; | 475 std::set<std::string> input_methods_added; |
| 445 | 476 |
| 446 for (std::vector<std::string>::const_iterator i = | 477 for (std::vector<std::string>::const_iterator i = |
| 447 hardware_login_input_methods.begin(); | 478 hardware_login_input_methods.begin(); |
| 448 i != hardware_login_input_methods.end(); | 479 i != hardware_login_input_methods.end(); |
| 449 ++i) { | 480 ++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 = | 481 const input_method::InputMethodDescriptor* ime = |
| 454 util->GetInputMethodDescriptorFromId(id); | 482 util->GetInputMethodDescriptorFromId(*i); |
| 455 DCHECK(ime != NULL); | 483 DCHECK(ime != NULL); |
| 456 // Do not crash in case of misconfiguration. | 484 // Do not crash in case of misconfiguration. |
| 457 if (ime != NULL) { | 485 if (ime != NULL) { |
| 486 input_methods_added.insert(*i); | |
| 458 input_methods_list->Append( | 487 input_methods_list->Append( |
| 459 CreateInputMethodsEntry(*ime, current_input_method_id)); | 488 CreateInputMethodsEntry(*ime, current_input_method_id)); |
| 460 } | 489 } |
| 461 } | 490 } |
| 462 | 491 |
| 463 bool optgroup_added = false; | 492 bool optgroup_added = false; |
| 464 for (size_t i = 0; i < input_methods->size(); ++i) { | 493 for (size_t i = 0; i < input_methods->size(); ++i) { |
| 465 // Makes sure the id is in legacy xkb id format. | 494 // Makes sure the id is in legacy xkb id format. |
| 466 const std::string& ime_id = extension_ime_util::MaybeGetLegacyXkbId( | 495 const std::string& ime_id = (*input_methods)[i].id(); |
| 467 (*input_methods)[i].id()); | |
| 468 if (!InsertString(ime_id, input_methods_added)) | 496 if (!InsertString(ime_id, input_methods_added)) |
| 469 continue; | 497 continue; |
| 470 if (!optgroup_added) { | 498 if (!optgroup_added) { |
| 471 optgroup_added = true; | 499 optgroup_added = true; |
| 472 AddOptgroupOtherLayouts(input_methods_list); | 500 AddOptgroupOtherLayouts(input_methods_list); |
| 473 } | 501 } |
| 474 input_methods_list->Append( | 502 input_methods_list->Append( |
| 475 CreateInputMethodsEntry((*input_methods)[i], current_input_method_id)); | 503 CreateInputMethodsEntry((*input_methods)[i], current_input_method_id)); |
| 476 } | 504 } |
| 477 // "xkb:us::eng" should always be in the list of available layouts. | 505 // "xkb:us::eng" should always be in the list of available layouts. |
| 478 if (input_methods_added.count(kUSlayout) == 0) { | 506 std::string us_keyboard_id = |
| 507 extension_ime_util::GetInputMethodIDByKeyboardLayout(kUSlayout); | |
| 508 if (input_methods_added.count(us_keyboard_id) == 0) { | |
| 479 const input_method::InputMethodDescriptor* us_eng_descriptor = | 509 const input_method::InputMethodDescriptor* us_eng_descriptor = |
| 480 util->GetInputMethodDescriptorFromId(kUSlayout); | 510 util->GetInputMethodDescriptorFromId(us_keyboard_id); |
| 481 DCHECK(us_eng_descriptor != NULL); | 511 DCHECK(us_eng_descriptor != NULL); |
| 482 if (!optgroup_added) { | 512 if (!optgroup_added) { |
| 483 optgroup_added = true; | 513 optgroup_added = true; |
| 484 AddOptgroupOtherLayouts(input_methods_list); | 514 AddOptgroupOtherLayouts(input_methods_list); |
| 485 } | 515 } |
| 486 input_methods_list->Append( | 516 input_methods_list->Append( |
| 487 CreateInputMethodsEntry(*us_eng_descriptor, current_input_method_id)); | 517 CreateInputMethodsEntry(*us_eng_descriptor, current_input_method_id)); |
| 488 } | 518 } |
| 489 return input_methods_list; | 519 return input_methods_list; |
| 490 } | 520 } |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 511 timezone_option->SetString("value", timezone_id); | 541 timezone_option->SetString("value", timezone_id); |
| 512 timezone_option->SetString("title", timezone_name); | 542 timezone_option->SetString("title", timezone_name); |
| 513 timezone_option->SetBoolean("selected", timezone_id == current_timezone_id); | 543 timezone_option->SetBoolean("selected", timezone_id == current_timezone_id); |
| 514 timezone_list->Append(timezone_option.release()); | 544 timezone_list->Append(timezone_option.release()); |
| 515 } | 545 } |
| 516 | 546 |
| 517 return timezone_list.release(); | 547 return timezone_list.release(); |
| 518 } | 548 } |
| 519 | 549 |
| 520 } // namespace chromeos | 550 } // namespace chromeos |
| OLD | NEW |