| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/l10n_util.h" | 5 #include "chrome/browser/ui/webui/chromeos/login/l10n_util.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <iterator> | 9 #include <iterator> |
| 10 #include <map> | 10 #include <map> |
| 11 #include <memory> |
| 11 #include <set> | 12 #include <set> |
| 12 #include <utility> | 13 #include <utility> |
| 13 | 14 |
| 14 #include "base/bind.h" | 15 #include "base/bind.h" |
| 15 #include "base/i18n/rtl.h" | 16 #include "base/i18n/rtl.h" |
| 16 #include "base/location.h" | 17 #include "base/location.h" |
| 17 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "base/memory/ptr_util.h" |
| 18 #include "base/memory/ref_counted.h" | 20 #include "base/memory/ref_counted.h" |
| 19 #include "base/sequenced_task_runner.h" | 21 #include "base/sequenced_task_runner.h" |
| 20 #include "base/stl_util.h" | 22 #include "base/stl_util.h" |
| 21 #include "base/strings/string16.h" | 23 #include "base/strings/string16.h" |
| 22 #include "base/strings/stringprintf.h" | 24 #include "base/strings/stringprintf.h" |
| 23 #include "base/strings/utf_string_conversions.h" | 25 #include "base/strings/utf_string_conversions.h" |
| 24 #include "base/task_runner_util.h" | 26 #include "base/task_runner_util.h" |
| 25 #include "base/threading/sequenced_worker_pool.h" | 27 #include "base/threading/sequenced_worker_pool.h" |
| 26 #include "base/values.h" | 28 #include "base/values.h" |
| 27 #include "chrome/browser/browser_process.h" | 29 #include "chrome/browser/browser_process.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 const std::pair<std::set<std::string>::iterator, bool> result = | 66 const std::pair<std::set<std::string>::iterator, bool> result = |
| 65 to->insert(str); | 67 to->insert(str); |
| 66 return result.second; | 68 return result.second; |
| 67 } | 69 } |
| 68 | 70 |
| 69 void AddOptgroupOtherLayouts(base::ListValue* input_methods_list) { | 71 void AddOptgroupOtherLayouts(base::ListValue* input_methods_list) { |
| 70 std::unique_ptr<base::DictionaryValue> optgroup(new base::DictionaryValue); | 72 std::unique_ptr<base::DictionaryValue> optgroup(new base::DictionaryValue); |
| 71 optgroup->SetString( | 73 optgroup->SetString( |
| 72 "optionGroupName", | 74 "optionGroupName", |
| 73 l10n_util::GetStringUTF16(IDS_OOBE_OTHER_KEYBOARD_LAYOUTS)); | 75 l10n_util::GetStringUTF16(IDS_OOBE_OTHER_KEYBOARD_LAYOUTS)); |
| 74 input_methods_list->Append(optgroup.release()); | 76 input_methods_list->Append(std::move(optgroup)); |
| 75 } | 77 } |
| 76 | 78 |
| 77 base::DictionaryValue* CreateLanguageEntry( | 79 base::DictionaryValue* CreateLanguageEntry( |
| 78 const std::string& language_code, | 80 const std::string& language_code, |
| 79 const base::string16& language_display_name, | 81 const base::string16& language_display_name, |
| 80 const base::string16& language_native_display_name) { | 82 const base::string16& language_native_display_name) { |
| 81 base::string16 display_name = language_display_name; | 83 base::string16 display_name = language_display_name; |
| 82 const bool markup_removal = | 84 const bool markup_removal = |
| 83 base::i18n::UnadjustStringForLocaleDirection(&display_name); | 85 base::i18n::UnadjustStringForLocaleDirection(&display_name); |
| 84 DCHECK(markup_removal); | 86 DCHECK(markup_removal); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 display_names.end(), | 262 display_names.end(), |
| 261 std::back_inserter(out_display_names)); | 263 std::back_inserter(out_display_names)); |
| 262 | 264 |
| 263 // Build the language list from the language map. | 265 // Build the language list from the language map. |
| 264 std::unique_ptr<base::ListValue> language_list(new base::ListValue()); | 266 std::unique_ptr<base::ListValue> language_list(new base::ListValue()); |
| 265 for (size_t i = 0; i < out_display_names.size(); ++i) { | 267 for (size_t i = 0; i < out_display_names.size(); ++i) { |
| 266 // Sets the directionality of the display language name. | 268 // Sets the directionality of the display language name. |
| 267 base::string16 display_name(out_display_names[i]); | 269 base::string16 display_name(out_display_names[i]); |
| 268 if (insert_divider && display_name == divider16) { | 270 if (insert_divider && display_name == divider16) { |
| 269 // Insert divider. | 271 // Insert divider. |
| 270 base::DictionaryValue* dictionary = new base::DictionaryValue(); | 272 auto dictionary = base::MakeUnique<base::DictionaryValue>(); |
| 271 dictionary->SetString("code", kMostRelevantLanguagesDivider); | 273 dictionary->SetString("code", kMostRelevantLanguagesDivider); |
| 272 language_list->Append(dictionary); | 274 language_list->Append(std::move(dictionary)); |
| 273 continue; | 275 continue; |
| 274 } | 276 } |
| 275 | 277 |
| 276 const LanguagePair& pair = language_map[out_display_names[i]]; | 278 const LanguagePair& pair = language_map[out_display_names[i]]; |
| 277 language_list->Append( | 279 language_list->Append( |
| 278 CreateLanguageEntry(pair.first, out_display_names[i], pair.second)); | 280 CreateLanguageEntry(pair.first, out_display_names[i], pair.second)); |
| 279 } | 281 } |
| 280 | 282 |
| 281 return language_list; | 283 return language_list; |
| 282 } | 284 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 &layouts); | 317 &layouts); |
| 316 | 318 |
| 317 std::unique_ptr<base::ListValue> input_methods_list(new base::ListValue); | 319 std::unique_ptr<base::ListValue> input_methods_list(new base::ListValue); |
| 318 std::set<std::string> input_methods_added; | 320 std::set<std::string> input_methods_added; |
| 319 for (std::vector<std::string>::const_iterator it = layouts.begin(); | 321 for (std::vector<std::string>::const_iterator it = layouts.begin(); |
| 320 it != layouts.end(); ++it) { | 322 it != layouts.end(); ++it) { |
| 321 const input_method::InputMethodDescriptor* ime = | 323 const input_method::InputMethodDescriptor* ime = |
| 322 util->GetInputMethodDescriptorFromId(*it); | 324 util->GetInputMethodDescriptorFromId(*it); |
| 323 if (!InsertString(ime->id(), &input_methods_added)) | 325 if (!InsertString(ime->id(), &input_methods_added)) |
| 324 continue; | 326 continue; |
| 325 input_methods_list->Append( | 327 input_methods_list->Append(CreateInputMethodsEntry(*ime, selected)); |
| 326 CreateInputMethodsEntry(*ime, selected).release()); | |
| 327 } | 328 } |
| 328 | 329 |
| 329 callback.Run(std::move(input_methods_list)); | 330 callback.Run(std::move(input_methods_list)); |
| 330 } | 331 } |
| 331 | 332 |
| 332 // For "UI Language" drop-down menu at OOBE screen we need to decide which | 333 // For "UI Language" drop-down menu at OOBE screen we need to decide which |
| 333 // entry to mark "selected". If user has just selected "requested_locale", | 334 // entry to mark "selected". If user has just selected "requested_locale", |
| 334 // but "loaded_locale" was actually loaded, we mark original user choice | 335 // but "loaded_locale" was actually loaded, we mark original user choice |
| 335 // "selected" only if loaded_locale is a backup for "requested_locale". | 336 // "selected" only if loaded_locale is a backup for "requested_locale". |
| 336 std::string CalculateSelectedLanguage(const std::string& requested_locale, | 337 std::string CalculateSelectedLanguage(const std::string& requested_locale, |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 | 529 |
| 529 for (std::vector<std::string>::const_iterator i = | 530 for (std::vector<std::string>::const_iterator i = |
| 530 hardware_login_input_methods.begin(); | 531 hardware_login_input_methods.begin(); |
| 531 i != hardware_login_input_methods.end(); | 532 i != hardware_login_input_methods.end(); |
| 532 ++i) { | 533 ++i) { |
| 533 const input_method::InputMethodDescriptor* ime = | 534 const input_method::InputMethodDescriptor* ime = |
| 534 util->GetInputMethodDescriptorFromId(*i); | 535 util->GetInputMethodDescriptorFromId(*i); |
| 535 // Do not crash in case of misconfiguration. | 536 // Do not crash in case of misconfiguration. |
| 536 if (ime) { | 537 if (ime) { |
| 537 input_methods_added.insert(*i); | 538 input_methods_added.insert(*i); |
| 538 input_methods_list->Append( | 539 input_methods_list->Append(CreateInputMethodsEntry(*ime, selected)); |
| 539 CreateInputMethodsEntry(*ime, selected).release()); | |
| 540 } else { | 540 } else { |
| 541 NOTREACHED(); | 541 NOTREACHED(); |
| 542 } | 542 } |
| 543 } | 543 } |
| 544 | 544 |
| 545 bool optgroup_added = false; | 545 bool optgroup_added = false; |
| 546 for (size_t i = 0; i < input_methods->size(); ++i) { | 546 for (size_t i = 0; i < input_methods->size(); ++i) { |
| 547 // Makes sure the id is in legacy xkb id format. | 547 // Makes sure the id is in legacy xkb id format. |
| 548 const std::string& ime_id = (*input_methods)[i].id(); | 548 const std::string& ime_id = (*input_methods)[i].id(); |
| 549 if (!InsertString(ime_id, &input_methods_added)) | 549 if (!InsertString(ime_id, &input_methods_added)) |
| 550 continue; | 550 continue; |
| 551 if (!optgroup_added) { | 551 if (!optgroup_added) { |
| 552 optgroup_added = true; | 552 optgroup_added = true; |
| 553 AddOptgroupOtherLayouts(input_methods_list.get()); | 553 AddOptgroupOtherLayouts(input_methods_list.get()); |
| 554 } | 554 } |
| 555 input_methods_list->Append(CreateInputMethodsEntry((*input_methods)[i], | 555 input_methods_list->Append( |
| 556 selected).release()); | 556 CreateInputMethodsEntry((*input_methods)[i], selected)); |
| 557 } | 557 } |
| 558 | 558 |
| 559 // "xkb:us::eng" should always be in the list of available layouts. | 559 // "xkb:us::eng" should always be in the list of available layouts. |
| 560 const std::string us_keyboard_id = | 560 const std::string us_keyboard_id = |
| 561 util->GetFallbackInputMethodDescriptor().id(); | 561 util->GetFallbackInputMethodDescriptor().id(); |
| 562 if (input_methods_added.find(us_keyboard_id) == input_methods_added.end()) { | 562 if (input_methods_added.find(us_keyboard_id) == input_methods_added.end()) { |
| 563 const input_method::InputMethodDescriptor* us_eng_descriptor = | 563 const input_method::InputMethodDescriptor* us_eng_descriptor = |
| 564 util->GetInputMethodDescriptorFromId(us_keyboard_id); | 564 util->GetInputMethodDescriptorFromId(us_keyboard_id); |
| 565 DCHECK(us_eng_descriptor); | 565 DCHECK(us_eng_descriptor); |
| 566 if (!optgroup_added) { | 566 if (!optgroup_added) { |
| 567 optgroup_added = true; | 567 optgroup_added = true; |
| 568 AddOptgroupOtherLayouts(input_methods_list.get()); | 568 AddOptgroupOtherLayouts(input_methods_list.get()); |
| 569 } | 569 } |
| 570 input_methods_list->Append(CreateInputMethodsEntry(*us_eng_descriptor, | 570 input_methods_list->Append( |
| 571 selected).release()); | 571 CreateInputMethodsEntry(*us_eng_descriptor, selected)); |
| 572 manager->GetActiveIMEState()->EnableInputMethod(us_keyboard_id); | 572 manager->GetActiveIMEState()->EnableInputMethod(us_keyboard_id); |
| 573 } | 573 } |
| 574 return input_methods_list; | 574 return input_methods_list; |
| 575 } | 575 } |
| 576 | 576 |
| 577 void GetKeyboardLayoutsForLocale( | 577 void GetKeyboardLayoutsForLocale( |
| 578 const GetKeyboardLayoutsForLocaleCallback& callback, | 578 const GetKeyboardLayoutsForLocaleCallback& callback, |
| 579 const std::string& locale) { | 579 const std::string& locale) { |
| 580 base::SequencedWorkerPool* worker_pool = | 580 base::SequencedWorkerPool* worker_pool = |
| 581 content::BrowserThread::GetBlockingPool(); | 581 content::BrowserThread::GetBlockingPool(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 597 std::unique_ptr<base::DictionaryValue> GetCurrentKeyboardLayout() { | 597 std::unique_ptr<base::DictionaryValue> GetCurrentKeyboardLayout() { |
| 598 const input_method::InputMethodDescriptor current_input_method = | 598 const input_method::InputMethodDescriptor current_input_method = |
| 599 input_method::InputMethodManager::Get() | 599 input_method::InputMethodManager::Get() |
| 600 ->GetActiveIMEState() | 600 ->GetActiveIMEState() |
| 601 ->GetCurrentInputMethod(); | 601 ->GetCurrentInputMethod(); |
| 602 return CreateInputMethodsEntry(current_input_method, | 602 return CreateInputMethodsEntry(current_input_method, |
| 603 current_input_method.id()); | 603 current_input_method.id()); |
| 604 } | 604 } |
| 605 | 605 |
| 606 } // namespace chromeos | 606 } // namespace chromeos |
| OLD | NEW |