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/chromeos/login/ui/login_display_host_impl.h" | 5 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/common/wallpaper/wallpaper_controller.h" | 10 #include "ash/common/wallpaper/wallpaper_controller.h" |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 void OnImplicitAnimationsCompleted() override { | 161 void OnImplicitAnimationsCompleted() override { |
162 callback_.Run(); | 162 callback_.Run(); |
163 delete this; | 163 delete this; |
164 } | 164 } |
165 | 165 |
166 base::Closure callback_; | 166 base::Closure callback_; |
167 | 167 |
168 DISALLOW_COPY_AND_ASSIGN(AnimationObserver); | 168 DISALLOW_COPY_AND_ASSIGN(AnimationObserver); |
169 }; | 169 }; |
170 | 170 |
| 171 bool ShouldShowSigninScreen(chromeos::OobeScreen first_screen) { |
| 172 return (first_screen == chromeos::OobeScreen::SCREEN_UNKNOWN && |
| 173 chromeos::StartupUtils::IsOobeCompleted()) || |
| 174 first_screen == chromeos::OobeScreen::SCREEN_SPECIAL_LOGIN; |
| 175 } |
| 176 |
171 // ShowLoginWizard is split into two parts. This function is sometimes called | 177 // ShowLoginWizard is split into two parts. This function is sometimes called |
172 // from ShowLoginWizard(), and sometimes from OnLanguageSwitchedCallback() | 178 // from TriggerShowLoginWizardFinish() directly, and sometimes from |
| 179 // OnLanguageSwitchedCallback() |
173 // (if locale was updated). | 180 // (if locale was updated). |
174 void ShowLoginWizardFinish( | 181 void ShowLoginWizardFinish( |
175 chromeos::OobeScreen first_screen, | 182 chromeos::OobeScreen first_screen, |
176 const chromeos::StartupCustomizationDocument* startup_manifest, | 183 const chromeos::StartupCustomizationDocument* startup_manifest, |
177 chromeos::LoginDisplayHost* display_host) { | 184 chromeos::LoginDisplayHost* display_host) { |
178 TRACE_EVENT0("chromeos", "ShowLoginWizard::ShowLoginWizardFinish"); | 185 TRACE_EVENT0("chromeos", "ShowLoginWizard::ShowLoginWizardFinish"); |
179 | 186 |
180 display_host->StartWizard(first_screen); | 187 if (ShouldShowSigninScreen(first_screen)) { |
| 188 display_host->StartSignInScreen(chromeos::LoginScreenContext()); |
| 189 } else { |
| 190 display_host->StartWizard(first_screen); |
181 | 191 |
182 // Set initial timezone if specified by customization. | 192 // Set initial timezone if specified by customization. |
183 const std::string timezone_name = startup_manifest->initial_timezone(); | 193 const std::string timezone_name = startup_manifest->initial_timezone(); |
184 VLOG(1) << "Initial time zone: " << timezone_name; | 194 VLOG(1) << "Initial time zone: " << timezone_name; |
185 // Apply locale customizations only once to preserve whatever locale | 195 // Apply locale customizations only once to preserve whatever locale |
186 // user has changed to during OOBE. | 196 // user has changed to during OOBE. |
187 if (!timezone_name.empty()) { | 197 if (!timezone_name.empty()) { |
188 chromeos::system::TimezoneSettings::GetInstance()->SetTimezoneFromID( | 198 chromeos::system::TimezoneSettings::GetInstance()->SetTimezoneFromID( |
189 base::UTF8ToUTF16(timezone_name)); | 199 base::UTF8ToUTF16(timezone_name)); |
| 200 } |
190 } | 201 } |
191 } | 202 } |
192 | 203 |
193 struct ShowLoginWizardSwitchLanguageCallbackData { | 204 struct ShowLoginWizardSwitchLanguageCallbackData { |
194 explicit ShowLoginWizardSwitchLanguageCallbackData( | 205 explicit ShowLoginWizardSwitchLanguageCallbackData( |
195 chromeos::OobeScreen first_screen, | 206 chromeos::OobeScreen first_screen, |
196 const chromeos::StartupCustomizationDocument* startup_manifest, | 207 const chromeos::StartupCustomizationDocument* startup_manifest, |
197 chromeos::LoginDisplayHost* display_host) | 208 chromeos::LoginDisplayHost* display_host) |
198 : first_screen(first_screen), | 209 : first_screen(first_screen), |
199 startup_manifest(startup_manifest), | 210 startup_manifest(startup_manifest), |
(...skipping 11 matching lines...) Expand all Loading... |
211 std::unique_ptr<ShowLoginWizardSwitchLanguageCallbackData> self, | 222 std::unique_ptr<ShowLoginWizardSwitchLanguageCallbackData> self, |
212 const chromeos::locale_util::LanguageSwitchResult& result) { | 223 const chromeos::locale_util::LanguageSwitchResult& result) { |
213 if (!result.success) | 224 if (!result.success) |
214 LOG(WARNING) << "Locale could not be found for '" << result.requested_locale | 225 LOG(WARNING) << "Locale could not be found for '" << result.requested_locale |
215 << "'"; | 226 << "'"; |
216 | 227 |
217 ShowLoginWizardFinish(self->first_screen, self->startup_manifest, | 228 ShowLoginWizardFinish(self->first_screen, self->startup_manifest, |
218 self->display_host); | 229 self->display_host); |
219 } | 230 } |
220 | 231 |
| 232 // Triggers ShowLoginWizardFinish directly if no locale switch is required |
| 233 // (|switch_locale| is empty) or after a locale switch otherwise. |
| 234 void TriggerShowLoginWizardFinish( |
| 235 std::string switch_locale, |
| 236 std::unique_ptr<ShowLoginWizardSwitchLanguageCallbackData> data) { |
| 237 if (switch_locale.empty()) { |
| 238 ShowLoginWizardFinish(data->first_screen, data->startup_manifest, |
| 239 data->display_host); |
| 240 } else { |
| 241 chromeos::locale_util::SwitchLanguageCallback callback( |
| 242 base::Bind(&OnLanguageSwitchedCallback, base::Passed(std::move(data)))); |
| 243 |
| 244 // Load locale keyboards here. Hardware layout would be automatically |
| 245 // enabled. |
| 246 chromeos::locale_util::SwitchLanguage( |
| 247 switch_locale, true, true /* login_layouts_only */, callback, |
| 248 ProfileManager::GetActiveUserProfile()); |
| 249 } |
| 250 } |
| 251 |
| 252 // Returns the login screen locale mandated by device policy, or an empty string |
| 253 // if no policy-specified locale is set. |
| 254 std::string GetManagedLoginScreenLocale() { |
| 255 chromeos::CrosSettings* cros_settings = chromeos::CrosSettings::Get(); |
| 256 const base::ListValue* loginScreenLocales = nullptr; |
| 257 if (!cros_settings->GetList(chromeos::kDeviceLoginScreenLocales, |
| 258 &loginScreenLocales)) |
| 259 return std::string(); |
| 260 |
| 261 // Currently, only the first element is used. The setting is a list for future |
| 262 // compatibility, if dynamically switching locales on the login screen will be |
| 263 // implemented. |
| 264 std::string loginScreenLocale; |
| 265 if (loginScreenLocales->empty() || |
| 266 !loginScreenLocales->GetString(0, &loginScreenLocale)) { |
| 267 return std::string(); |
| 268 } |
| 269 return loginScreenLocale; |
| 270 } |
| 271 |
221 void EnableSystemSoundsForAccessibility() { | 272 void EnableSystemSoundsForAccessibility() { |
222 chromeos::AccessibilityManager::Get()->EnableSystemSounds(true); | 273 chromeos::AccessibilityManager::Get()->EnableSystemSounds(true); |
223 } | 274 } |
224 | 275 |
225 // A login implementation of WidgetDelegate. | 276 // A login implementation of WidgetDelegate. |
226 class LoginWidgetDelegate : public views::WidgetDelegate { | 277 class LoginWidgetDelegate : public views::WidgetDelegate { |
227 public: | 278 public: |
228 explicit LoginWidgetDelegate(views::Widget* widget) : widget_(widget) { | 279 explicit LoginWidgetDelegate(views::Widget* widget) : widget_(widget) { |
229 } | 280 } |
230 ~LoginWidgetDelegate() override {} | 281 ~LoginWidgetDelegate() override {} |
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 ->wallpaper_delegate() | 911 ->wallpaper_delegate() |
861 ->OnWallpaperBootAnimationFinished(); | 912 ->OnWallpaperBootAnimationFinished(); |
862 } else { | 913 } else { |
863 NOTIMPLEMENTED(); | 914 NOTIMPLEMENTED(); |
864 } | 915 } |
865 if (waiting_for_wallpaper_load_) { | 916 if (waiting_for_wallpaper_load_) { |
866 // StartWizard / StartSignInScreen could be called multiple times through | 917 // StartWizard / StartSignInScreen could be called multiple times through |
867 // the lifetime of host. | 918 // the lifetime of host. |
868 // Make sure that subsequent calls are not postponed. | 919 // Make sure that subsequent calls are not postponed. |
869 waiting_for_wallpaper_load_ = false; | 920 waiting_for_wallpaper_load_ = false; |
870 if (initialize_webui_hidden_) | 921 if (initialize_webui_hidden_) { |
871 ShowWebUI(); | 922 // If we're in the process of switching locale, the wallpaper might |
872 else | 923 // have finished loading before the locale switch was completed. |
| 924 // Only show the UI if it already exists. |
| 925 if (login_window_ && login_view_) |
| 926 ShowWebUI(); |
| 927 } else { |
873 StartPostponedWebUI(); | 928 StartPostponedWebUI(); |
| 929 } |
874 } | 930 } |
875 registrar_.Remove(this, | 931 registrar_.Remove(this, |
876 chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED, | 932 chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED, |
877 content::NotificationService::AllSources()); | 933 content::NotificationService::AllSources()); |
878 } | 934 } |
879 } | 935 } |
880 | 936 |
881 //////////////////////////////////////////////////////////////////////////////// | 937 //////////////////////////////////////////////////////////////////////////////// |
882 // LoginDisplayHostImpl, WebContentsObserver: | 938 // LoginDisplayHostImpl, WebContentsObserver: |
883 | 939 |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1313 DelayNetworkCall( | 1369 DelayNetworkCall( |
1314 base::TimeDelta::FromMilliseconds(kDefaultNetworkRetryDelayMS), | 1370 base::TimeDelta::FromMilliseconds(kDefaultNetworkRetryDelayMS), |
1315 ServicesCustomizationDocument::GetInstance() | 1371 ServicesCustomizationDocument::GetInstance() |
1316 ->EnsureCustomizationAppliedClosure()); | 1372 ->EnsureCustomizationAppliedClosure()); |
1317 | 1373 |
1318 g_browser_process->platform_part() | 1374 g_browser_process->platform_part() |
1319 ->GetTimezoneResolverManager() | 1375 ->GetTimezoneResolverManager() |
1320 ->UpdateTimezoneResolver(); | 1376 ->UpdateTimezoneResolver(); |
1321 } | 1377 } |
1322 | 1378 |
1323 bool show_login_screen = (first_screen == OobeScreen::SCREEN_UNKNOWN && | 1379 PrefService* prefs = g_browser_process->local_state(); |
1324 StartupUtils::IsOobeCompleted()) || | 1380 const std::string& current_locale = |
1325 first_screen == OobeScreen::SCREEN_SPECIAL_LOGIN; | 1381 prefs->GetString(prefs::kApplicationLocale); |
| 1382 VLOG(1) << "Current locale: " << current_locale; |
1326 | 1383 |
1327 if (show_login_screen) { | 1384 if (ShouldShowSigninScreen(first_screen)) { |
1328 display_host->StartSignInScreen(LoginScreenContext()); | 1385 std::string switch_locale = GetManagedLoginScreenLocale(); |
| 1386 if (switch_locale == current_locale) |
| 1387 switch_locale.clear(); |
| 1388 |
| 1389 std::unique_ptr<ShowLoginWizardSwitchLanguageCallbackData> data = |
| 1390 base::MakeUnique<ShowLoginWizardSwitchLanguageCallbackData>( |
| 1391 first_screen, nullptr, display_host); |
| 1392 TriggerShowLoginWizardFinish(switch_locale, std::move(data)); |
1329 return; | 1393 return; |
1330 } | 1394 } |
1331 | 1395 |
1332 // Load startup manifest. | 1396 // Load startup manifest. |
1333 const StartupCustomizationDocument* startup_manifest = | 1397 const StartupCustomizationDocument* startup_manifest = |
1334 StartupCustomizationDocument::GetInstance(); | 1398 StartupCustomizationDocument::GetInstance(); |
1335 | 1399 |
1336 // Switch to initial locale if specified by customization | 1400 // Switch to initial locale if specified by customization |
1337 // and has not been set yet. We cannot call | 1401 // and has not been set yet. We cannot call |
1338 // LanguageSwitchMenu::SwitchLanguage here before | 1402 // LanguageSwitchMenu::SwitchLanguage here before |
1339 // EmitLoginPromptReady. | 1403 // EmitLoginPromptReady. |
1340 PrefService* prefs = g_browser_process->local_state(); | |
1341 const std::string& current_locale = | |
1342 prefs->GetString(prefs::kApplicationLocale); | |
1343 VLOG(1) << "Current locale: " << current_locale; | |
1344 const std::string& locale = startup_manifest->initial_locale_default(); | 1404 const std::string& locale = startup_manifest->initial_locale_default(); |
1345 | 1405 |
1346 const std::string& layout = startup_manifest->keyboard_layout(); | 1406 const std::string& layout = startup_manifest->keyboard_layout(); |
1347 VLOG(1) << "Initial locale: " << locale << "keyboard layout " << layout; | 1407 VLOG(1) << "Initial locale: " << locale << "keyboard layout " << layout; |
1348 | 1408 |
1349 // Determine keyboard layout from OEM customization (if provided) or | 1409 // Determine keyboard layout from OEM customization (if provided) or |
1350 // initial locale and save it in preferences. | 1410 // initial locale and save it in preferences. |
1351 manager->GetActiveIMEState()->SetInputMethodLoginDefaultFromVPD(locale, | 1411 manager->GetActiveIMEState()->SetInputMethodLoginDefaultFromVPD(locale, |
1352 layout); | 1412 layout); |
1353 | 1413 |
| 1414 std::unique_ptr<ShowLoginWizardSwitchLanguageCallbackData> data( |
| 1415 new ShowLoginWizardSwitchLanguageCallbackData( |
| 1416 first_screen, startup_manifest, display_host)); |
| 1417 |
1354 if (!current_locale.empty() || locale.empty()) { | 1418 if (!current_locale.empty() || locale.empty()) { |
1355 ShowLoginWizardFinish(first_screen, startup_manifest, display_host); | 1419 TriggerShowLoginWizardFinish(std::string(), std::move(data)); |
1356 return; | 1420 return; |
1357 } | 1421 } |
1358 | 1422 |
1359 // Save initial locale from VPD/customization manifest as current | 1423 // Save initial locale from VPD/customization manifest as current |
1360 // Chrome locale. Otherwise it will be lost if Chrome restarts. | 1424 // Chrome locale. Otherwise it will be lost if Chrome restarts. |
1361 // Don't need to schedule pref save because setting initial local | 1425 // Don't need to schedule pref save because setting initial local |
1362 // will enforce preference saving. | 1426 // will enforce preference saving. |
1363 prefs->SetString(prefs::kApplicationLocale, locale); | 1427 prefs->SetString(prefs::kApplicationLocale, locale); |
1364 StartupUtils::SetInitialLocale(locale); | 1428 StartupUtils::SetInitialLocale(locale); |
1365 | 1429 |
1366 std::unique_ptr<ShowLoginWizardSwitchLanguageCallbackData> data( | 1430 TriggerShowLoginWizardFinish(locale, std::move(data)); |
1367 new ShowLoginWizardSwitchLanguageCallbackData( | |
1368 first_screen, startup_manifest, display_host)); | |
1369 | |
1370 locale_util::SwitchLanguageCallback callback( | |
1371 base::Bind(&OnLanguageSwitchedCallback, base::Passed(std::move(data)))); | |
1372 | |
1373 // Load locale keyboards here. Hardware layout would be automatically enabled. | |
1374 locale_util::SwitchLanguage(locale, true, true /* login_layouts_only */, | |
1375 callback, ProfileManager::GetActiveUserProfile()); | |
1376 } | 1431 } |
1377 | 1432 |
1378 } // namespace chromeos | 1433 } // namespace chromeos |
OLD | NEW |