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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
239 base::DictionaryValue localized_strings; | 245 base::DictionaryValue localized_strings; |
240 static_cast<OobeUI*>(self->web_ui()->GetController()) | 246 static_cast<OobeUI*>(self->web_ui()->GetController()) |
241 ->GetLocalizedStrings(&localized_strings); | 247 ->GetLocalizedStrings(&localized_strings); |
242 self->core_oobe_actor_->ReloadContent(localized_strings); | 248 self->core_oobe_actor_->ReloadContent(localized_strings); |
243 | 249 |
244 // Buttons are recreated, updated "Continue" button state. | 250 // Buttons are recreated, updated "Continue" button state. |
245 self->EnableContinue(self->is_continue_enabled_); | 251 self->EnableContinue(self->is_continue_enabled_); |
246 } | 252 } |
247 | 253 |
248 void NetworkScreenHandler::HandleOnLanguageChanged(const std::string& locale) { | 254 void NetworkScreenHandler::HandleOnLanguageChanged(const std::string& locale) { |
255 HandleOnLanguageChangedInternal(locale, false); | |
256 } | |
257 | |
258 void NetworkScreenHandler::HandleOnLanguageChangedInternal( | |
259 const std::string& locale, bool force_refresh) { | |
249 const std::string app_locale = g_browser_process->GetApplicationLocale(); | 260 const std::string app_locale = g_browser_process->GetApplicationLocale(); |
250 if (app_locale == locale) | 261 if (app_locale == locale && !force_refresh) |
251 return; | 262 return; |
252 | 263 |
253 base::WeakPtr<NetworkScreenHandler> weak_self = | 264 base::WeakPtr<NetworkScreenHandler> weak_self = |
254 weak_ptr_factory_.GetWeakPtr(); | 265 weak_ptr_factory_.GetWeakPtr(); |
255 scoped_ptr<NetworkScreenHandlerOnLanguageChangedCallbackData> callback_data( | 266 scoped_ptr<NetworkScreenHandlerOnLanguageChangedCallbackData> callback_data( |
256 new NetworkScreenHandlerOnLanguageChangedCallbackData(weak_self)); | 267 new NetworkScreenHandlerOnLanguageChangedCallbackData(weak_self)); |
257 scoped_ptr<locale_util::SwitchLanguageCallback> callback( | 268 scoped_ptr<locale_util::SwitchLanguageCallback> callback( |
258 new locale_util::SwitchLanguageCallback( | 269 new locale_util::SwitchLanguageCallback( |
259 base::Bind(&NetworkScreenHandler::OnLanguageChangedCallback, | 270 base::Bind(&NetworkScreenHandler::OnLanguageChangedCallback, |
260 base::Passed(callback_data.Pass())))); | 271 base::Passed(callback_data.Pass())))); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
366 | 377 |
367 bool NetworkScreenHandler::IsDerelict() { | 378 bool NetworkScreenHandler::IsDerelict() { |
368 return time_on_oobe_ >= derelict_detection_timeout_; | 379 return time_on_oobe_ >= derelict_detection_timeout_; |
369 } | 380 } |
370 | 381 |
371 // static | 382 // static |
372 base::ListValue* NetworkScreenHandler::GetLanguageList() { | 383 base::ListValue* NetworkScreenHandler::GetLanguageList() { |
373 const std::string app_locale = g_browser_process->GetApplicationLocale(); | 384 const std::string app_locale = g_browser_process->GetApplicationLocale(); |
374 input_method::InputMethodManager* manager = | 385 input_method::InputMethodManager* manager = |
375 input_method::InputMethodManager::Get(); | 386 input_method::InputMethodManager::Get(); |
376 // GetSupportedInputMethods() never returns NULL. | 387 ComponentExtensionIMEManager* comp_manager = |
377 scoped_ptr<input_method::InputMethodDescriptors> descriptors( | 388 manager->GetComponentExtensionIMEManager(); |
378 manager->GetSupportedInputMethods()); | 389 input_method::InputMethodDescriptors descriptors; |
390 if (extension_ime_util::UseWrappedExtensionKeyboardLayouts()) { | |
391 if (comp_manager->IsInitialized()) | |
392 descriptors = comp_manager->GetXkbIMEAsInputMethodDescriptor(); | |
Seigo Nonaka
2014/03/07 07:21:21
What's happened if component extension manager is
Shu Chen
2014/03/07 07:30:29
If it's not initialized, descriptors will be an em
| |
393 } else { | |
394 descriptors = *(manager->GetSupportedInputMethods()); | |
395 } | |
379 base::ListValue* languages_list = | 396 base::ListValue* languages_list = |
380 options::CrosLanguageOptionsHandler::GetUILanguageList(*descriptors); | 397 options::CrosLanguageOptionsHandler::GetUILanguageList(descriptors); |
381 for (size_t i = 0; i < languages_list->GetSize(); ++i) { | 398 for (size_t i = 0; i < languages_list->GetSize(); ++i) { |
382 base::DictionaryValue* language_info = NULL; | 399 base::DictionaryValue* language_info = NULL; |
383 if (!languages_list->GetDictionary(i, &language_info)) | 400 if (!languages_list->GetDictionary(i, &language_info)) |
384 NOTREACHED(); | 401 NOTREACHED(); |
385 | 402 |
386 std::string value; | 403 std::string value; |
387 language_info->GetString("code", &value); | 404 language_info->GetString("code", &value); |
388 std::string display_name; | 405 std::string display_name; |
389 language_info->GetString("displayName", &display_name); | 406 language_info->GetString("displayName", &display_name); |
390 std::string native_name; | 407 std::string native_name; |
(...skipping 24 matching lines...) Expand all Loading... | |
415 input_method::InputMethodUtil* util = | 432 input_method::InputMethodUtil* util = |
416 input_method::InputMethodManager::Get()->GetInputMethodUtil(); | 433 input_method::InputMethodManager::Get()->GetInputMethodUtil(); |
417 const std::string& ime_id = method.id(); | 434 const std::string& ime_id = method.id(); |
418 scoped_ptr<base::DictionaryValue> input_method(new base::DictionaryValue); | 435 scoped_ptr<base::DictionaryValue> input_method(new base::DictionaryValue); |
419 input_method->SetString("value", ime_id); | 436 input_method->SetString("value", ime_id); |
420 input_method->SetString("title", util->GetInputMethodLongName(method)); | 437 input_method->SetString("title", util->GetInputMethodLongName(method)); |
421 input_method->SetBoolean("selected", ime_id == current_input_method_id); | 438 input_method->SetBoolean("selected", ime_id == current_input_method_id); |
422 return input_method.release(); | 439 return input_method.release(); |
423 } | 440 } |
424 | 441 |
442 void NetworkScreenHandler::OnInitialized() { | |
443 // Refreshes the whole UI. | |
444 HandleOnLanguageChangedInternal( | |
445 g_browser_process->GetApplicationLocale(), true); | |
446 } | |
447 | |
425 // static | 448 // static |
426 base::ListValue* NetworkScreenHandler::GetInputMethods() { | 449 base::ListValue* NetworkScreenHandler::GetInputMethods() { |
427 base::ListValue* input_methods_list = new base::ListValue; | 450 base::ListValue* input_methods_list = new base::ListValue; |
428 input_method::InputMethodManager* manager = | 451 input_method::InputMethodManager* manager = |
429 input_method::InputMethodManager::Get(); | 452 input_method::InputMethodManager::Get(); |
430 input_method::InputMethodUtil* util = manager->GetInputMethodUtil(); | 453 input_method::InputMethodUtil* util = manager->GetInputMethodUtil(); |
454 ComponentExtensionIMEManager* comp_manager = | |
455 manager->GetComponentExtensionIMEManager(); | |
456 if (!comp_manager->IsInitialized()) { | |
457 input_method::InputMethodDescriptor fallback = | |
458 util->GetFallbackInputMethodDescriptor(); | |
459 input_methods_list->Append( | |
460 CreateInputMethodsEntry(fallback, fallback.id())); | |
461 return input_methods_list; | |
462 } | |
463 | |
431 scoped_ptr<input_method::InputMethodDescriptors> input_methods( | 464 scoped_ptr<input_method::InputMethodDescriptors> input_methods( |
432 manager->GetActiveInputMethods()); | 465 manager->GetActiveInputMethods()); |
433 // Uses extension_ime_util::MaybeGetLegacyXkbId() to make sure the input | 466 std::string current_input_method_id = manager->GetCurrentInputMethod().id(); |
Yuki
2014/03/07 07:47:04
nit: Use a const reference for |current_input_meth
Shu Chen
2014/03/07 08:24:09
Done.
| |
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 = | 467 const std::vector<std::string>& hardware_login_input_methods = |
443 util->GetHardwareLoginInputMethodIds(); | 468 util->GetHardwareLoginInputMethodIds(); |
444 std::set<std::string> input_methods_added; | 469 std::set<std::string> input_methods_added; |
445 | 470 |
446 for (std::vector<std::string>::const_iterator i = | 471 for (std::vector<std::string>::const_iterator i = |
447 hardware_login_input_methods.begin(); | 472 hardware_login_input_methods.begin(); |
448 i != hardware_login_input_methods.end(); | 473 i != hardware_login_input_methods.end(); |
449 ++i) { | 474 ++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 = | 475 const input_method::InputMethodDescriptor* ime = |
454 util->GetInputMethodDescriptorFromId(id); | 476 util->GetInputMethodDescriptorFromId(*i); |
455 DCHECK(ime != NULL); | 477 DCHECK(ime != NULL); |
456 // Do not crash in case of misconfiguration. | 478 // Do not crash in case of misconfiguration. |
457 if (ime != NULL) { | 479 if (ime != NULL) { |
480 input_methods_added.insert(*i); | |
458 input_methods_list->Append( | 481 input_methods_list->Append( |
459 CreateInputMethodsEntry(*ime, current_input_method_id)); | 482 CreateInputMethodsEntry(*ime, current_input_method_id)); |
460 } | 483 } |
461 } | 484 } |
462 | 485 |
463 bool optgroup_added = false; | 486 bool optgroup_added = false; |
464 for (size_t i = 0; i < input_methods->size(); ++i) { | 487 for (size_t i = 0; i < input_methods->size(); ++i) { |
465 // Makes sure the id is in legacy xkb id format. | 488 // Makes sure the id is in legacy xkb id format. |
466 const std::string& ime_id = extension_ime_util::MaybeGetLegacyXkbId( | 489 const std::string& ime_id = (*input_methods)[i].id(); |
467 (*input_methods)[i].id()); | |
468 if (!InsertString(ime_id, input_methods_added)) | 490 if (!InsertString(ime_id, input_methods_added)) |
469 continue; | 491 continue; |
470 if (!optgroup_added) { | 492 if (!optgroup_added) { |
471 optgroup_added = true; | 493 optgroup_added = true; |
472 AddOptgroupOtherLayouts(input_methods_list); | 494 AddOptgroupOtherLayouts(input_methods_list); |
473 } | 495 } |
474 input_methods_list->Append( | 496 input_methods_list->Append( |
475 CreateInputMethodsEntry((*input_methods)[i], current_input_method_id)); | 497 CreateInputMethodsEntry((*input_methods)[i], current_input_method_id)); |
476 } | 498 } |
477 // "xkb:us::eng" should always be in the list of available layouts. | 499 // "xkb:us::eng" should always be in the list of available layouts. |
478 if (input_methods_added.count(kUSlayout) == 0) { | 500 std::string us_keyboard_id = |
Yuki
2014/03/07 07:47:04
nit: Use a const reference.
Shu Chen
2014/03/07 08:24:09
Done.
| |
501 extension_ime_util::GetInputMethodIDByKeyboardLayout(kUSlayout); | |
Yuki
2014/03/07 07:47:04
nit: kUsLayout or kUSLayout. L in Layout must be
Shu Chen
2014/03/07 08:24:09
Done.
| |
502 if (input_methods_added.count(us_keyboard_id) == 0) { | |
Yuki
2014/03/07 07:47:04
nit: Use find() rather than count() if the number
Shu Chen
2014/03/07 08:24:09
Done.
| |
479 const input_method::InputMethodDescriptor* us_eng_descriptor = | 503 const input_method::InputMethodDescriptor* us_eng_descriptor = |
480 util->GetInputMethodDescriptorFromId(kUSlayout); | 504 util->GetInputMethodDescriptorFromId(us_keyboard_id); |
481 DCHECK(us_eng_descriptor != NULL); | 505 DCHECK(us_eng_descriptor != NULL); |
482 if (!optgroup_added) { | 506 if (!optgroup_added) { |
483 optgroup_added = true; | 507 optgroup_added = true; |
484 AddOptgroupOtherLayouts(input_methods_list); | 508 AddOptgroupOtherLayouts(input_methods_list); |
485 } | 509 } |
486 input_methods_list->Append( | 510 input_methods_list->Append( |
487 CreateInputMethodsEntry(*us_eng_descriptor, current_input_method_id)); | 511 CreateInputMethodsEntry(*us_eng_descriptor, current_input_method_id)); |
488 } | 512 } |
489 return input_methods_list; | 513 return input_methods_list; |
490 } | 514 } |
(...skipping 20 matching lines...) Expand all Loading... | |
511 timezone_option->SetString("value", timezone_id); | 535 timezone_option->SetString("value", timezone_id); |
512 timezone_option->SetString("title", timezone_name); | 536 timezone_option->SetString("title", timezone_name); |
513 timezone_option->SetBoolean("selected", timezone_id == current_timezone_id); | 537 timezone_option->SetBoolean("selected", timezone_id == current_timezone_id); |
514 timezone_list->Append(timezone_option.release()); | 538 timezone_list->Append(timezone_option.release()); |
515 } | 539 } |
516 | 540 |
517 return timezone_list.release(); | 541 return timezone_list.release(); |
518 } | 542 } |
519 | 543 |
520 } // namespace chromeos | 544 } // namespace chromeos |
OLD | NEW |