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 | |
82 std::string resolved_locale; | |
83 if (!l10n_util::CheckAndResolveLocale(requested_locale, &resolved_locale)) | |
84 return loaded_locale; | |
85 | |
86 if (resolved_locale == loaded_locale) | |
87 return requested_locale; | |
88 | |
89 return loaded_locale; | |
90 } | |
91 | |
75 } // namespace | 92 } // namespace |
76 | 93 |
77 namespace chromeos { | 94 namespace chromeos { |
78 | 95 |
79 // NetworkScreenHandler, public: ----------------------------------------------- | 96 // NetworkScreenHandler, public: ----------------------------------------------- |
80 | 97 |
81 NetworkScreenHandler::NetworkScreenHandler(CoreOobeActor* core_oobe_actor) | 98 NetworkScreenHandler::NetworkScreenHandler(CoreOobeActor* core_oobe_actor) |
82 : BaseScreenHandler(kJsScreenPath), | 99 : BaseScreenHandler(kJsScreenPath), |
83 screen_(NULL), | 100 screen_(NULL), |
84 core_oobe_actor_(core_oobe_actor), | 101 core_oobe_actor_(core_oobe_actor), |
(...skipping 26 matching lines...) Expand all Loading... | |
111 | 128 |
112 void NetworkScreenHandler::PrepareToShow() { | 129 void NetworkScreenHandler::PrepareToShow() { |
113 } | 130 } |
114 | 131 |
115 void NetworkScreenHandler::Show() { | 132 void NetworkScreenHandler::Show() { |
116 if (!page_is_ready()) { | 133 if (!page_is_ready()) { |
117 show_on_init_ = true; | 134 show_on_init_ = true; |
118 return; | 135 return; |
119 } | 136 } |
120 | 137 |
138 // Here we should handle default locales, for which we do not have UI | |
139 // resources. This would load fallback, but properly show "selected" locale | |
140 // in the UI. | |
141 if (selected_language_code_.empty()) { | |
Nikita (slow)
2014/04/08 07:56:01
What happens for this scenario:
1. First boot, ou
Alexander Alekseev
2014/04/08 11:58:19
Yes. Now each time network screen is shown after r
Nikita (slow)
2014/04/08 12:19:25
Ok then.
| |
142 const StartupCustomizationDocument* startup_manifest = | |
143 StartupCustomizationDocument::GetInstance(); | |
144 HandleOnLanguageChanged(startup_manifest->initial_locale_default()); | |
145 } | |
146 | |
121 ShowScreen(OobeUI::kScreenOobeNetwork, NULL); | 147 ShowScreen(OobeUI::kScreenOobeNetwork, NULL); |
122 | 148 |
123 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableDemoMode)) | 149 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableDemoMode)) |
124 return; | 150 return; |
125 | 151 |
126 if (IsDerelict()) | 152 if (IsDerelict()) |
127 StartIdleDetection(); | 153 StartIdleDetection(); |
128 else | 154 else |
129 StartOobeTimer(); | 155 StartOobeTimer(); |
130 } | 156 } |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 | 258 |
233 base::WeakPtr<NetworkScreenHandler> handler_; | 259 base::WeakPtr<NetworkScreenHandler> handler_; |
234 | 260 |
235 // Block UI while resource bundle is being reloaded. | 261 // Block UI while resource bundle is being reloaded. |
236 chromeos::InputEventsBlocker input_events_blocker; | 262 chromeos::InputEventsBlocker input_events_blocker; |
237 }; | 263 }; |
238 | 264 |
239 // static | 265 // static |
240 void NetworkScreenHandler::OnLanguageChangedCallback( | 266 void NetworkScreenHandler::OnLanguageChangedCallback( |
241 scoped_ptr<NetworkScreenHandlerOnLanguageChangedCallbackData> context, | 267 scoped_ptr<NetworkScreenHandlerOnLanguageChangedCallbackData> context, |
242 const std::string& /*requested locale*/, | 268 const std::string& requested_locale, |
243 const std::string& /*loaded_locale*/, | 269 const std::string& loaded_locale, |
244 const bool /*success*/) { | 270 const bool success) { |
245 if (!context or !context->handler_) | 271 if (!context or !context->handler_) |
246 return; | 272 return; |
247 | 273 |
248 NetworkScreenHandler* const self = context->handler_.get(); | 274 NetworkScreenHandler* const self = context->handler_.get(); |
275 | |
276 if (success) { | |
277 if (requested_locale == loaded_locale) { | |
278 self->selected_language_code_ = requested_locale; | |
279 } else { | |
280 self->selected_language_code_ = | |
281 CalculateSelectedLanguage(requested_locale, loaded_locale); | |
282 } | |
283 } else { | |
284 self->selected_language_code_ = loaded_locale; | |
285 } | |
286 | |
249 self->ReloadLocalizedContent(); | 287 self->ReloadLocalizedContent(); |
250 | 288 |
251 AccessibilityManager::Get()->OnLocaleChanged(); | 289 AccessibilityManager::Get()->OnLocaleChanged(); |
252 } | 290 } |
253 | 291 |
254 void NetworkScreenHandler::HandleOnLanguageChanged(const std::string& locale) { | 292 void NetworkScreenHandler::HandleOnLanguageChanged(const std::string& locale) { |
255 const std::string app_locale = g_browser_process->GetApplicationLocale(); | 293 const std::string app_locale = g_browser_process->GetApplicationLocale(); |
256 if (app_locale == locale) | 294 if (app_locale == locale) |
257 return; | 295 return; |
258 | 296 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
367 oobe_timer_update_interval_ = | 405 oobe_timer_update_interval_ = |
368 std::max(std::min(oobe_timer_update_interval_, | 406 std::max(std::min(oobe_timer_update_interval_, |
369 derelict_detection_timeout_ - time_on_oobe_), | 407 derelict_detection_timeout_ - time_on_oobe_), |
370 base::TimeDelta::FromSeconds(0)); | 408 base::TimeDelta::FromSeconds(0)); |
371 } | 409 } |
372 | 410 |
373 bool NetworkScreenHandler::IsDerelict() { | 411 bool NetworkScreenHandler::IsDerelict() { |
374 return time_on_oobe_ >= derelict_detection_timeout_; | 412 return time_on_oobe_ >= derelict_detection_timeout_; |
375 } | 413 } |
376 | 414 |
377 // static | |
378 base::ListValue* NetworkScreenHandler::GetLanguageList() { | 415 base::ListValue* NetworkScreenHandler::GetLanguageList() { |
379 const std::string app_locale = g_browser_process->GetApplicationLocale(); | 416 const std::string app_locale = g_browser_process->GetApplicationLocale(); |
380 input_method::InputMethodManager* manager = | 417 input_method::InputMethodManager* manager = |
381 input_method::InputMethodManager::Get(); | 418 input_method::InputMethodManager::Get(); |
382 ComponentExtensionIMEManager* comp_manager = | 419 ComponentExtensionIMEManager* comp_manager = |
383 manager->GetComponentExtensionIMEManager(); | 420 manager->GetComponentExtensionIMEManager(); |
384 input_method::InputMethodDescriptors descriptors; | 421 input_method::InputMethodDescriptors descriptors; |
385 if (extension_ime_util::UseWrappedExtensionKeyboardLayouts()) { | 422 if (extension_ime_util::UseWrappedExtensionKeyboardLayouts()) { |
386 if (comp_manager->IsInitialized()) | 423 if (comp_manager->IsInitialized()) |
387 descriptors = comp_manager->GetXkbIMEAsInputMethodDescriptor(); | 424 descriptors = comp_manager->GetXkbIMEAsInputMethodDescriptor(); |
(...skipping 21 matching lines...) Expand all Loading... | |
409 l10n_util::GetStringUTF16(IDS_OOBE_OTHER_LANGUAGES)); | 446 l10n_util::GetStringUTF16(IDS_OOBE_OTHER_LANGUAGES)); |
410 } | 447 } |
411 if (display_name != native_name) { | 448 if (display_name != native_name) { |
412 display_name = base::StringPrintf("%s - %s", | 449 display_name = base::StringPrintf("%s - %s", |
413 display_name.c_str(), | 450 display_name.c_str(), |
414 native_name.c_str()); | 451 native_name.c_str()); |
415 } | 452 } |
416 | 453 |
417 language_info->SetString("value", value); | 454 language_info->SetString("value", value); |
418 language_info->SetString("title", display_name); | 455 language_info->SetString("title", display_name); |
419 language_info->SetBoolean("selected", value == app_locale); | 456 if (selected_language_code_.empty()) { |
457 if (value == app_locale) | |
458 language_info->SetBoolean("selected", true); | |
459 } else { | |
460 if (value == selected_language_code_) | |
461 language_info->SetBoolean("selected", true); | |
462 } | |
420 } | 463 } |
421 return languages_list; | 464 return languages_list; |
422 } | 465 } |
423 | 466 |
424 base::DictionaryValue* CreateInputMethodsEntry( | 467 base::DictionaryValue* CreateInputMethodsEntry( |
425 const input_method::InputMethodDescriptor& method, | 468 const input_method::InputMethodDescriptor& method, |
426 const std::string current_input_method_id) { | 469 const std::string current_input_method_id) { |
427 input_method::InputMethodUtil* util = | 470 input_method::InputMethodUtil* util = |
428 input_method::InputMethodManager::Get()->GetInputMethodUtil(); | 471 input_method::InputMethodManager::Get()->GetInputMethodUtil(); |
429 const std::string& ime_id = method.id(); | 472 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); | 592 timezone_option->SetString("value", timezone_id); |
550 timezone_option->SetString("title", timezone_name); | 593 timezone_option->SetString("title", timezone_name); |
551 timezone_option->SetBoolean("selected", timezone_id == current_timezone_id); | 594 timezone_option->SetBoolean("selected", timezone_id == current_timezone_id); |
552 timezone_list->Append(timezone_option.release()); | 595 timezone_list->Append(timezone_option.release()); |
553 } | 596 } |
554 | 597 |
555 return timezone_list.release(); | 598 return timezone_list.release(); |
556 } | 599 } |
557 | 600 |
558 } // namespace chromeos | 601 } // namespace chromeos |
OLD | NEW |