Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: chrome/browser/ui/webui/chromeos/login/l10n_util.cc

Issue 620563002: ChromeOS NetworkScreenHandler should not call CheckAndResolveLocale on UI thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 if (insert_divider && display_name == divider16) { 261 if (insert_divider && display_name == divider16) {
262 // Insert divider. 262 // Insert divider.
263 base::DictionaryValue* dictionary = new base::DictionaryValue(); 263 base::DictionaryValue* dictionary = new base::DictionaryValue();
264 dictionary->SetString("code", kMostRelevantLanguagesDivider); 264 dictionary->SetString("code", kMostRelevantLanguagesDivider);
265 language_list->Append(dictionary); 265 language_list->Append(dictionary);
266 continue; 266 continue;
267 } 267 }
268 const bool markup_removal = 268 const bool markup_removal =
269 base::i18n::UnadjustStringForLocaleDirection(&display_name); 269 base::i18n::UnadjustStringForLocaleDirection(&display_name);
270 DCHECK(markup_removal); 270 DCHECK(markup_removal);
271 const bool has_rtl_chars = 271 const std::string directionality = GetLanguageDirectionality(display_name);
272 base::i18n::StringContainsStrongRTLChars(display_name);
273 const std::string directionality = has_rtl_chars ? "rtl" : "ltr";
274 272
275 const LanguagePair& pair = language_map[out_display_names[i]]; 273 const LanguagePair& pair = language_map[out_display_names[i]];
276 base::DictionaryValue* dictionary = new base::DictionaryValue(); 274 language_list->Append(CreateLanguageEntry(
277 dictionary->SetString("code", pair.first); 275 pair.first, out_display_names[i], directionality, pair.second));
278 dictionary->SetString("displayName", out_display_names[i]);
279 dictionary->SetString("textDirection", directionality);
280 dictionary->SetString("nativeDisplayName", pair.second);
281 language_list->Append(dictionary);
282 } 276 }
283 277
284 return language_list.Pass(); 278 return language_list.Pass();
285 } 279 }
286 280
287 // Invokes |callback| with a list of keyboard layouts that can be used for 281 // Invokes |callback| with a list of keyboard layouts that can be used for
288 // |resolved_locale|. 282 // |resolved_locale|.
289 void GetKeyboardLayoutsForResolvedLocale( 283 void GetKeyboardLayoutsForResolvedLocale(
290 const GetKeyboardLayoutsForLocaleCallback& callback, 284 const GetKeyboardLayoutsForLocaleCallback& callback,
291 const std::string& resolved_locale) { 285 const std::string& resolved_locale) {
(...skipping 24 matching lines...) Expand all
316 continue; 310 continue;
317 input_methods_list->Append( 311 input_methods_list->Append(
318 CreateInputMethodsEntry(*ime, selected).release()); 312 CreateInputMethodsEntry(*ime, selected).release());
319 } 313 }
320 314
321 callback.Run(input_methods_list.Pass()); 315 callback.Run(input_methods_list.Pass());
322 } 316 }
323 317
324 } // namespace 318 } // namespace
325 319
320 base::DictionaryValue* CreateLanguageEntry(
321 const std::string& language_code,
322 const base::string16& language_display_name,
323 const std::string& language_directionality,
324 const base::string16& language_native_display_name) {
325 scoped_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue());
326 dictionary->SetString("code", language_code);
327 dictionary->SetString("displayName", language_display_name);
328 dictionary->SetString("textDirection", language_directionality);
329 dictionary->SetString("nativeDisplayName", language_native_display_name);
330 return dictionary.release();
331 }
332
333 const std::string GetLanguageDirectionality(
334 const base::string16& language_display_name) {
335 const bool has_rtl_chars =
336 base::i18n::StringContainsStrongRTLChars(language_display_name);
337 return has_rtl_chars ? "rtl" : "ltr";
338 }
339
326 const char kMostRelevantLanguagesDivider[] = "MOST_RELEVANT_LANGUAGES_DIVIDER"; 340 const char kMostRelevantLanguagesDivider[] = "MOST_RELEVANT_LANGUAGES_DIVIDER";
327 341
328 scoped_ptr<base::ListValue> GetUILanguageList( 342 scoped_ptr<base::ListValue> GetUILanguageList(
329 const std::vector<std::string>* most_relevant_language_codes, 343 const std::vector<std::string>* most_relevant_language_codes,
330 const std::string& selected) { 344 const std::string& selected) {
331 ComponentExtensionIMEManager* manager = 345 ComponentExtensionIMEManager* manager =
332 input_method::InputMethodManager::Get()-> 346 input_method::InputMethodManager::Get()->
333 GetComponentExtensionIMEManager(); 347 GetComponentExtensionIMEManager();
334 input_method::InputMethodDescriptors descriptors = 348 input_method::InputMethodDescriptors descriptors =
335 manager->GetXkbIMEAsInputMethodDescriptor(); 349 manager->GetXkbIMEAsInputMethodDescriptor();
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 scoped_ptr<base::DictionaryValue> GetCurrentKeyboardLayout() { 517 scoped_ptr<base::DictionaryValue> GetCurrentKeyboardLayout() {
504 const input_method::InputMethodDescriptor current_input_method = 518 const input_method::InputMethodDescriptor current_input_method =
505 input_method::InputMethodManager::Get() 519 input_method::InputMethodManager::Get()
506 ->GetActiveIMEState() 520 ->GetActiveIMEState()
507 ->GetCurrentInputMethod(); 521 ->GetCurrentInputMethod();
508 return CreateInputMethodsEntry(current_input_method, 522 return CreateInputMethodsEntry(current_input_method,
509 current_input_method.id()); 523 current_input_method.id());
510 } 524 }
511 525
512 } // namespace chromeos 526 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698