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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 } | 65 } |
66 | 66 |
67 void AddOptgroupOtherLayouts(base::ListValue* input_methods_list) { | 67 void AddOptgroupOtherLayouts(base::ListValue* input_methods_list) { |
68 base::DictionaryValue* optgroup = new base::DictionaryValue; | 68 base::DictionaryValue* optgroup = new base::DictionaryValue; |
69 optgroup->SetString( | 69 optgroup->SetString( |
70 "optionGroupName", | 70 "optionGroupName", |
71 l10n_util::GetStringUTF16(IDS_OOBE_OTHER_KEYBOARD_LAYOUTS)); | 71 l10n_util::GetStringUTF16(IDS_OOBE_OTHER_KEYBOARD_LAYOUTS)); |
72 input_methods_list->Append(optgroup); | 72 input_methods_list->Append(optgroup); |
73 } | 73 } |
74 | 74 |
75 // For "UI Language" drop-down menu at OOBE screen we need to decide which | |
76 // entry to mark "selected". If user has just selected "requested_locale", | |
77 // but "loaded_locale" was actually loaded, we mark original user choice | |
78 // "selected" only if loaded_locale is a backup for "requested_locale". | |
79 std::string CalculateSelectedLanguage(const std::string& requested_locale, | |
80 const std::string& loaded_locale) { | |
81 const size_t dash_pos_requested = requested_locale.find_first_of('-'); | |
82 | |
83 // Requested language doesn't have specific region. | |
84 if (dash_pos_requested == std::string::npos || dash_pos_requested == 0) | |
85 return loaded_locale; | |
86 | |
87 const size_t dash_pos_loaded = loaded_locale.find_first_of('-'); | |
88 | |
89 // loaded_locale doesn't have 'region' in name and requested_locale | |
90 // is a region-specific language of loaded_locale. | |
91 if (dash_pos_loaded == std::string::npos || dash_pos_loaded == 0) { | |
92 if (requested_locale.substr(0, dash_pos_requested) == loaded_locale) | |
93 return requested_locale; | |
94 // Languages differ. | |
95 return loaded_locale; | |
96 } | |
97 // Both locales are region-specific. Check that languages are the same. | |
98 if (requested_locale.substr(0, dash_pos_requested) == | |
99 loaded_locale.substr(0, dash_pos_loaded)) | |
100 return requested_locale; | |
101 | |
102 return loaded_locale; | |
103 } | |
104 | |
75 } // namespace | 105 } // namespace |
76 | 106 |
77 namespace chromeos { | 107 namespace chromeos { |
78 | 108 |
79 // NetworkScreenHandler, public: ----------------------------------------------- | 109 // NetworkScreenHandler, public: ----------------------------------------------- |
80 | 110 |
81 NetworkScreenHandler::NetworkScreenHandler(CoreOobeActor* core_oobe_actor) | 111 NetworkScreenHandler::NetworkScreenHandler(CoreOobeActor* core_oobe_actor) |
82 : BaseScreenHandler(kJsScreenPath), | 112 : BaseScreenHandler(kJsScreenPath), |
83 screen_(NULL), | 113 screen_(NULL), |
84 core_oobe_actor_(core_oobe_actor), | 114 core_oobe_actor_(core_oobe_actor), |
(...skipping 26 matching lines...) Expand all Loading... | |
111 | 141 |
112 void NetworkScreenHandler::PrepareToShow() { | 142 void NetworkScreenHandler::PrepareToShow() { |
113 } | 143 } |
114 | 144 |
115 void NetworkScreenHandler::Show() { | 145 void NetworkScreenHandler::Show() { |
116 if (!page_is_ready()) { | 146 if (!page_is_ready()) { |
117 show_on_init_ = true; | 147 show_on_init_ = true; |
118 return; | 148 return; |
119 } | 149 } |
120 | 150 |
151 const StartupCustomizationDocument* startup_manifest = | |
152 StartupCustomizationDocument::GetInstance(); | |
153 HandleOnLanguageChanged(startup_manifest->initial_locale_default()); | |
Nikita (slow)
2014/04/07 17:06:58
This won't quit work. This screen may be shown mul
Alexander Alekseev
2014/04/07 19:28:58
Done.
| |
154 | |
121 ShowScreen(OobeUI::kScreenOobeNetwork, NULL); | 155 ShowScreen(OobeUI::kScreenOobeNetwork, NULL); |
122 | 156 |
123 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableDemoMode)) | 157 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableDemoMode)) |
124 return; | 158 return; |
125 | 159 |
126 if (IsDerelict()) | 160 if (IsDerelict()) |
127 StartIdleDetection(); | 161 StartIdleDetection(); |
128 else | 162 else |
129 StartOobeTimer(); | 163 StartOobeTimer(); |
130 } | 164 } |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 | 266 |
233 base::WeakPtr<NetworkScreenHandler> handler_; | 267 base::WeakPtr<NetworkScreenHandler> handler_; |
234 | 268 |
235 // Block UI while resource bundle is being reloaded. | 269 // Block UI while resource bundle is being reloaded. |
236 chromeos::InputEventsBlocker input_events_blocker; | 270 chromeos::InputEventsBlocker input_events_blocker; |
237 }; | 271 }; |
238 | 272 |
239 // static | 273 // static |
240 void NetworkScreenHandler::OnLanguageChangedCallback( | 274 void NetworkScreenHandler::OnLanguageChangedCallback( |
241 scoped_ptr<NetworkScreenHandlerOnLanguageChangedCallbackData> context, | 275 scoped_ptr<NetworkScreenHandlerOnLanguageChangedCallbackData> context, |
242 const std::string& /*requested locale*/, | 276 const std::string& requested_locale, |
243 const std::string& /*loaded_locale*/, | 277 const std::string& loaded_locale, |
244 const bool /*success*/) { | 278 const bool success) { |
245 if (!context or !context->handler_) | 279 if (!context or !context->handler_) |
246 return; | 280 return; |
247 | 281 |
248 NetworkScreenHandler* const self = context->handler_.get(); | 282 NetworkScreenHandler* const self = context->handler_.get(); |
283 | |
284 if (success) { | |
285 if (requested_locale == loaded_locale) { | |
286 self->selected_language_code_ = requested_locale; | |
287 } else { | |
288 self->selected_language_code_ = | |
289 CalculateSelectedLanguage(requested_locale, loaded_locale); | |
290 } | |
291 } else { | |
292 self->selected_language_code_ = loaded_locale; | |
293 } | |
294 | |
249 self->ReloadLocalizedContent(); | 295 self->ReloadLocalizedContent(); |
250 | 296 |
251 AccessibilityManager::Get()->OnLocaleChanged(); | 297 AccessibilityManager::Get()->OnLocaleChanged(); |
252 } | 298 } |
253 | 299 |
254 void NetworkScreenHandler::HandleOnLanguageChanged(const std::string& locale) { | 300 void NetworkScreenHandler::HandleOnLanguageChanged(const std::string& locale) { |
255 const std::string app_locale = g_browser_process->GetApplicationLocale(); | 301 const std::string app_locale = g_browser_process->GetApplicationLocale(); |
256 if (app_locale == locale) | 302 if (app_locale == locale) |
257 return; | 303 return; |
258 | 304 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
367 oobe_timer_update_interval_ = | 413 oobe_timer_update_interval_ = |
368 std::max(std::min(oobe_timer_update_interval_, | 414 std::max(std::min(oobe_timer_update_interval_, |
369 derelict_detection_timeout_ - time_on_oobe_), | 415 derelict_detection_timeout_ - time_on_oobe_), |
370 base::TimeDelta::FromSeconds(0)); | 416 base::TimeDelta::FromSeconds(0)); |
371 } | 417 } |
372 | 418 |
373 bool NetworkScreenHandler::IsDerelict() { | 419 bool NetworkScreenHandler::IsDerelict() { |
374 return time_on_oobe_ >= derelict_detection_timeout_; | 420 return time_on_oobe_ >= derelict_detection_timeout_; |
375 } | 421 } |
376 | 422 |
377 // static | |
378 base::ListValue* NetworkScreenHandler::GetLanguageList() { | 423 base::ListValue* NetworkScreenHandler::GetLanguageList() { |
379 const std::string app_locale = g_browser_process->GetApplicationLocale(); | 424 const std::string app_locale = g_browser_process->GetApplicationLocale(); |
380 input_method::InputMethodManager* manager = | 425 input_method::InputMethodManager* manager = |
381 input_method::InputMethodManager::Get(); | 426 input_method::InputMethodManager::Get(); |
382 ComponentExtensionIMEManager* comp_manager = | 427 ComponentExtensionIMEManager* comp_manager = |
383 manager->GetComponentExtensionIMEManager(); | 428 manager->GetComponentExtensionIMEManager(); |
384 input_method::InputMethodDescriptors descriptors; | 429 input_method::InputMethodDescriptors descriptors; |
385 if (extension_ime_util::UseWrappedExtensionKeyboardLayouts()) { | 430 if (extension_ime_util::UseWrappedExtensionKeyboardLayouts()) { |
386 if (comp_manager->IsInitialized()) | 431 if (comp_manager->IsInitialized()) |
387 descriptors = comp_manager->GetXkbIMEAsInputMethodDescriptor(); | 432 descriptors = comp_manager->GetXkbIMEAsInputMethodDescriptor(); |
(...skipping 21 matching lines...) Expand all Loading... | |
409 l10n_util::GetStringUTF16(IDS_OOBE_OTHER_LANGUAGES)); | 454 l10n_util::GetStringUTF16(IDS_OOBE_OTHER_LANGUAGES)); |
410 } | 455 } |
411 if (display_name != native_name) { | 456 if (display_name != native_name) { |
412 display_name = base::StringPrintf("%s - %s", | 457 display_name = base::StringPrintf("%s - %s", |
413 display_name.c_str(), | 458 display_name.c_str(), |
414 native_name.c_str()); | 459 native_name.c_str()); |
415 } | 460 } |
416 | 461 |
417 language_info->SetString("value", value); | 462 language_info->SetString("value", value); |
418 language_info->SetString("title", display_name); | 463 language_info->SetString("title", display_name); |
419 language_info->SetBoolean("selected", value == app_locale); | 464 if (selected_language_code_.empty()) { |
465 if (value == app_locale) | |
466 language_info->SetBoolean("selected", true); | |
467 } else { | |
468 if (value == selected_language_code_) | |
469 language_info->SetBoolean("selected", true); | |
470 } | |
420 } | 471 } |
421 return languages_list; | 472 return languages_list; |
422 } | 473 } |
423 | 474 |
424 base::DictionaryValue* CreateInputMethodsEntry( | 475 base::DictionaryValue* CreateInputMethodsEntry( |
425 const input_method::InputMethodDescriptor& method, | 476 const input_method::InputMethodDescriptor& method, |
426 const std::string current_input_method_id) { | 477 const std::string current_input_method_id) { |
427 input_method::InputMethodUtil* util = | 478 input_method::InputMethodUtil* util = |
428 input_method::InputMethodManager::Get()->GetInputMethodUtil(); | 479 input_method::InputMethodManager::Get()->GetInputMethodUtil(); |
429 const std::string& ime_id = method.id(); | 480 const std::string& ime_id = method.id(); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
549 timezone_option->SetString("value", timezone_id); | 600 timezone_option->SetString("value", timezone_id); |
550 timezone_option->SetString("title", timezone_name); | 601 timezone_option->SetString("title", timezone_name); |
551 timezone_option->SetBoolean("selected", timezone_id == current_timezone_id); | 602 timezone_option->SetBoolean("selected", timezone_id == current_timezone_id); |
552 timezone_list->Append(timezone_option.release()); | 603 timezone_list->Append(timezone_option.release()); |
553 } | 604 } |
554 | 605 |
555 return timezone_list.release(); | 606 return timezone_list.release(); |
556 } | 607 } |
557 | 608 |
558 } // namespace chromeos | 609 } // namespace chromeos |
OLD | NEW |