OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/signin_screen_handler.h" | 5 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <vector> | 10 #include <vector> |
(...skipping 22 matching lines...) Expand all Loading... |
33 #include "chrome/browser/browser_process_platform_part_chromeos.h" | 33 #include "chrome/browser/browser_process_platform_part_chromeos.h" |
34 #include "chrome/browser/browser_shutdown.h" | 34 #include "chrome/browser/browser_shutdown.h" |
35 #include "chrome/browser/chrome_notification_types.h" | 35 #include "chrome/browser/chrome_notification_types.h" |
36 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" | 36 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" |
37 #include "chrome/browser/chromeos/language_preferences.h" | 37 #include "chrome/browser/chromeos/language_preferences.h" |
38 #include "chrome/browser/chromeos/lock_screen_apps/state_controller.h" | 38 #include "chrome/browser/chromeos/lock_screen_apps/state_controller.h" |
39 #include "chrome/browser/chromeos/login/error_screens_histogram_helper.h" | 39 #include "chrome/browser/chromeos/login/error_screens_histogram_helper.h" |
40 #include "chrome/browser/chromeos/login/hwid_checker.h" | 40 #include "chrome/browser/chromeos/login/hwid_checker.h" |
41 #include "chrome/browser/chromeos/login/lock/screen_locker.h" | 41 #include "chrome/browser/chromeos/login/lock/screen_locker.h" |
42 #include "chrome/browser/chromeos/login/lock/webui_screen_locker.h" | 42 #include "chrome/browser/chromeos/login/lock/webui_screen_locker.h" |
| 43 #include "chrome/browser/chromeos/login/lock_screen_utils.h" |
43 #include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_factory.h" | 44 #include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_factory.h" |
44 #include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_storage.h" | 45 #include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_storage.h" |
45 #include "chrome/browser/chromeos/login/reauth_stats.h" | 46 #include "chrome/browser/chromeos/login/reauth_stats.h" |
46 #include "chrome/browser/chromeos/login/screens/core_oobe_view.h" | 47 #include "chrome/browser/chromeos/login/screens/core_oobe_view.h" |
47 #include "chrome/browser/chromeos/login/screens/network_error.h" | 48 #include "chrome/browser/chromeos/login/screens/network_error.h" |
48 #include "chrome/browser/chromeos/login/startup_utils.h" | 49 #include "chrome/browser/chromeos/login/startup_utils.h" |
49 #include "chrome/browser/chromeos/login/ui/login_display_host.h" | 50 #include "chrome/browser/chromeos/login/ui/login_display_host.h" |
50 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" | 51 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" |
51 #include "chrome/browser/chromeos/login/ui/login_feedback.h" | 52 #include "chrome/browser/chromeos/login/ui/login_feedback.h" |
52 #include "chrome/browser/chromeos/login/ui/webui_login_display.h" | 53 #include "chrome/browser/chromeos/login/ui/webui_login_display.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 | 120 |
120 // Type of the login screen UI that is currently presented to user. | 121 // Type of the login screen UI that is currently presented to user. |
121 const char kSourceGaiaSignin[] = "gaia-signin"; | 122 const char kSourceGaiaSignin[] = "gaia-signin"; |
122 const char kSourceAccountPicker[] = "account-picker"; | 123 const char kSourceAccountPicker[] = "account-picker"; |
123 | 124 |
124 // Constants for lock screen apps activity state values: | 125 // Constants for lock screen apps activity state values: |
125 const char kNoLockScreenApps[] = "LOCK_SCREEN_APPS_STATE.NONE"; | 126 const char kNoLockScreenApps[] = "LOCK_SCREEN_APPS_STATE.NONE"; |
126 const char kBackgroundLockScreenApps[] = "LOCK_SCREEN_APPS_STATE.BACKGROUND"; | 127 const char kBackgroundLockScreenApps[] = "LOCK_SCREEN_APPS_STATE.BACKGROUND"; |
127 const char kForegroundLockScreenApps[] = "LOCK_SCREEN_APPS_STATE.FOREGROUND"; | 128 const char kForegroundLockScreenApps[] = "LOCK_SCREEN_APPS_STATE.FOREGROUND"; |
128 | 129 |
129 static bool Contains(const std::vector<std::string>& container, | |
130 const std::string& value) { | |
131 return std::find(container.begin(), container.end(), value) != | |
132 container.end(); | |
133 } | |
134 | |
135 class CallOnReturn { | 130 class CallOnReturn { |
136 public: | 131 public: |
137 explicit CallOnReturn(const base::Closure& callback) | 132 explicit CallOnReturn(const base::Closure& callback) |
138 : callback_(callback), call_scheduled_(false) {} | 133 : callback_(callback), call_scheduled_(false) {} |
139 | 134 |
140 ~CallOnReturn() { | 135 ~CallOnReturn() { |
141 if (call_scheduled_ && !callback_.is_null()) | 136 if (call_scheduled_ && !callback_.is_null()) |
142 callback_.Run(); | 137 callback_.Run(); |
143 } | 138 } |
144 | 139 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 | 191 |
197 // Returns network name by service path. | 192 // Returns network name by service path. |
198 std::string GetNetworkName(const std::string& service_path) { | 193 std::string GetNetworkName(const std::string& service_path) { |
199 const NetworkState* network = NetworkHandler::Get()->network_state_handler()-> | 194 const NetworkState* network = NetworkHandler::Get()->network_state_handler()-> |
200 GetNetworkState(service_path); | 195 GetNetworkState(service_path); |
201 if (!network) | 196 if (!network) |
202 return std::string(); | 197 return std::string(); |
203 return network->name(); | 198 return network->name(); |
204 } | 199 } |
205 | 200 |
206 static bool SetUserInputMethodImpl( | |
207 const std::string& username, | |
208 const std::string& user_input_method, | |
209 input_method::InputMethodManager::State* ime_state) { | |
210 if (!chromeos::input_method::InputMethodManager::Get()->IsLoginKeyboard( | |
211 user_input_method)) { | |
212 LOG(WARNING) << "SetUserInputMethod('" << username | |
213 << "'): stored user last input method '" << user_input_method | |
214 << "' is no longer Full Latin Keyboard Language" | |
215 << " (entry dropped). Use hardware default instead."; | |
216 | |
217 PrefService* const local_state = g_browser_process->local_state(); | |
218 DictionaryPrefUpdate updater(local_state, prefs::kUsersLastInputMethod); | |
219 | |
220 base::DictionaryValue* const users_last_input_methods = updater.Get(); | |
221 if (users_last_input_methods != nullptr) { | |
222 users_last_input_methods->SetStringWithoutPathExpansion(username, ""); | |
223 } | |
224 return false; | |
225 } | |
226 | |
227 if (!Contains(ime_state->GetActiveInputMethodIds(), user_input_method)) { | |
228 if (!ime_state->EnableInputMethod(user_input_method)) { | |
229 DLOG(ERROR) << "SigninScreenHandler::SetUserInputMethod('" << username | |
230 << "'): user input method '" << user_input_method | |
231 << "' is not enabled and enabling failed (ignored!)."; | |
232 } | |
233 } | |
234 ime_state->ChangeInputMethod(user_input_method, false /* show_message */); | |
235 | |
236 return true; | |
237 } | |
238 | |
239 void EnforcePolicyInputMethods(std::string user_input_method) { | |
240 chromeos::CrosSettings* cros_settings = chromeos::CrosSettings::Get(); | |
241 const base::ListValue* login_screen_input_methods = nullptr; | |
242 if (!cros_settings->GetList(chromeos::kDeviceLoginScreenInputMethods, | |
243 &login_screen_input_methods)) { | |
244 return; | |
245 } | |
246 | |
247 std::vector<std::string> allowed_input_methods; | |
248 | |
249 // Add user's input method first so it is pre-selected. | |
250 if (!user_input_method.empty()) { | |
251 allowed_input_methods.push_back(user_input_method); | |
252 } | |
253 | |
254 std::string input_method; | |
255 for (const auto& input_method_entry : *login_screen_input_methods) { | |
256 if (input_method_entry.GetAsString(&input_method)) | |
257 allowed_input_methods.push_back(input_method); | |
258 } | |
259 chromeos::input_method::InputMethodManager* imm = | |
260 chromeos::input_method::InputMethodManager::Get(); | |
261 imm->GetActiveIMEState()->SetAllowedInputMethods(allowed_input_methods); | |
262 } | |
263 | |
264 void StopEnforcingPolicyInputMethods() { | 201 void StopEnforcingPolicyInputMethods() { |
265 // Empty means all input methods are allowed | 202 // Empty means all input methods are allowed |
266 std::vector<std::string> allowed_input_methods; | 203 std::vector<std::string> allowed_input_methods; |
267 chromeos::input_method::InputMethodManager* imm = | 204 chromeos::input_method::InputMethodManager* imm = |
268 chromeos::input_method::InputMethodManager::Get(); | 205 chromeos::input_method::InputMethodManager::Get(); |
269 imm->GetActiveIMEState()->SetAllowedInputMethods(allowed_input_methods); | 206 imm->GetActiveIMEState()->SetAllowedInputMethods(allowed_input_methods); |
270 } | 207 } |
271 | 208 |
272 } // namespace | 209 } // namespace |
273 | 210 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 keyboard->RemoveObserver(this); | 303 keyboard->RemoveObserver(this); |
367 StopEnforcingPolicyInputMethods(); | 304 StopEnforcingPolicyInputMethods(); |
368 weak_factory_.InvalidateWeakPtrs(); | 305 weak_factory_.InvalidateWeakPtrs(); |
369 if (delegate_) | 306 if (delegate_) |
370 delegate_->SetWebUIHandler(nullptr); | 307 delegate_->SetWebUIHandler(nullptr); |
371 network_state_informer_->RemoveObserver(this); | 308 network_state_informer_->RemoveObserver(this); |
372 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(nullptr); | 309 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(nullptr); |
373 proximity_auth::ScreenlockBridge::Get()->SetFocusedUser(EmptyAccountId()); | 310 proximity_auth::ScreenlockBridge::Get()->SetFocusedUser(EmptyAccountId()); |
374 } | 311 } |
375 | 312 |
376 // static | |
377 std::string SigninScreenHandler::GetUserLastInputMethod( | |
378 const std::string& username) { | |
379 PrefService* const local_state = g_browser_process->local_state(); | |
380 const base::DictionaryValue* users_last_input_methods = | |
381 local_state->GetDictionary(prefs::kUsersLastInputMethod); | |
382 | |
383 if (!users_last_input_methods) { | |
384 DLOG(WARNING) << "GetUserLastInputMethod('" << username | |
385 << "'): no kUsersLastInputMethod"; | |
386 return std::string(); | |
387 } | |
388 | |
389 std::string input_method; | |
390 | |
391 if (!users_last_input_methods->GetStringWithoutPathExpansion(username, | |
392 &input_method)) { | |
393 DVLOG(0) << "GetUserLastInputMethod('" << username | |
394 << "'): no input method for this user"; | |
395 return std::string(); | |
396 } | |
397 | |
398 return input_method; | |
399 } | |
400 | |
401 // static | |
402 // Update keyboard layout to least recently used by the user. | |
403 void SigninScreenHandler::SetUserInputMethod( | |
404 const std::string& username, | |
405 input_method::InputMethodManager::State* ime_state) { | |
406 bool succeed = false; | |
407 | |
408 const std::string input_method = GetUserLastInputMethod(username); | |
409 | |
410 EnforcePolicyInputMethods(input_method); | |
411 | |
412 if (!input_method.empty()) | |
413 succeed = SetUserInputMethodImpl(username, input_method, ime_state); | |
414 | |
415 // This is also a case when last layout is set only for a few local users, | |
416 // thus others need to be switched to default locale. | |
417 // Otherwise they will end up using another user's locale to log in. | |
418 if (!succeed) { | |
419 DVLOG(0) << "SetUserInputMethod('" << username | |
420 << "'): failed to set user layout. Switching to default."; | |
421 | |
422 ime_state->SetInputMethodLoginDefault(); | |
423 } | |
424 } | |
425 | |
426 void SigninScreenHandler::DeclareLocalizedValues( | 313 void SigninScreenHandler::DeclareLocalizedValues( |
427 ::login::LocalizedValuesBuilder* builder) { | 314 ::login::LocalizedValuesBuilder* builder) { |
428 // Format numbers to be used on the pin keyboard. | 315 // Format numbers to be used on the pin keyboard. |
429 for (int j = 0; j <= 9; j++) { | 316 for (int j = 0; j <= 9; j++) { |
430 builder->Add("pinKeyboard" + base::IntToString(j), | 317 builder->Add("pinKeyboard" + base::IntToString(j), |
431 base::FormatNumber(int64_t{j})); | 318 base::FormatNumber(int64_t{j})); |
432 } | 319 } |
433 | 320 |
434 builder->Add("passwordHint", IDS_LOGIN_POD_EMPTY_PASSWORD_TEXT); | 321 builder->Add("passwordHint", IDS_LOGIN_POD_EMPTY_PASSWORD_TEXT); |
435 builder->Add("pinKeyboardPlaceholderPin", | 322 builder->Add("pinKeyboardPlaceholderPin", |
(...skipping 1050 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1486 test_focus_pod_callback_.Run(); | 1373 test_focus_pod_callback_.Run(); |
1487 | 1374 |
1488 focused_pod_account_id_ = base::MakeUnique<AccountId>(account_id); | 1375 focused_pod_account_id_ = base::MakeUnique<AccountId>(account_id); |
1489 | 1376 |
1490 const user_manager::User* user = | 1377 const user_manager::User* user = |
1491 user_manager::UserManager::Get()->FindUser(account_id); | 1378 user_manager::UserManager::Get()->FindUser(account_id); |
1492 // |user| may be nullptr in kiosk mode or unit tests. | 1379 // |user| may be nullptr in kiosk mode or unit tests. |
1493 if (user && user->is_logged_in() && !user->is_active()) { | 1380 if (user && user->is_logged_in() && !user->is_active()) { |
1494 SessionControllerClient::DoSwitchActiveUser(account_id); | 1381 SessionControllerClient::DoSwitchActiveUser(account_id); |
1495 } else { | 1382 } else { |
1496 SetUserInputMethod(account_id.GetUserEmail(), ime_state_.get()); | 1383 lock_screen_utils::SetUserInputMethod(account_id.GetUserEmail(), |
1497 SetKeyboardSettings(account_id); | 1384 ime_state_.get()); |
| 1385 lock_screen_utils::SetKeyboardSettings(account_id); |
1498 WallpaperManager::Get()->SetUserWallpaperDelayed(account_id); | 1386 WallpaperManager::Get()->SetUserWallpaperDelayed(account_id); |
1499 | 1387 |
1500 bool use_24hour_clock = false; | 1388 bool use_24hour_clock = false; |
1501 if (user_manager::known_user::GetBooleanPref( | 1389 if (user_manager::known_user::GetBooleanPref( |
1502 account_id, prefs::kUse24HourClock, &use_24hour_clock)) { | 1390 account_id, prefs::kUse24HourClock, &use_24hour_clock)) { |
1503 g_browser_process->platform_part() | 1391 g_browser_process->platform_part() |
1504 ->GetSystemClock() | 1392 ->GetSystemClock() |
1505 ->SetLastFocusedPodHourClockType( | 1393 ->SetLastFocusedPodHourClockType( |
1506 use_24hour_clock ? base::k24HourClock : base::k12HourClock); | 1394 use_24hour_clock ? base::k24HourClock : base::k12HourClock); |
1507 } | 1395 } |
1508 } | 1396 } |
1509 } | 1397 } |
1510 | 1398 |
1511 void SigninScreenHandler::HandleNoPodFocused() { | 1399 void SigninScreenHandler::HandleNoPodFocused() { |
1512 focused_pod_account_id_.reset(); | 1400 focused_pod_account_id_.reset(); |
1513 EnforcePolicyInputMethods(std::string()); | 1401 lock_screen_utils::EnforcePolicyInputMethods(std::string()); |
1514 } | 1402 } |
1515 | 1403 |
1516 void SigninScreenHandler::HandleGetPublicSessionKeyboardLayouts( | 1404 void SigninScreenHandler::HandleGetPublicSessionKeyboardLayouts( |
1517 const AccountId& account_id, | 1405 const AccountId& account_id, |
1518 const std::string& locale) { | 1406 const std::string& locale) { |
1519 GetKeyboardLayoutsForLocale( | 1407 GetKeyboardLayoutsForLocale( |
1520 base::Bind(&SigninScreenHandler::SendPublicSessionKeyboardLayouts, | 1408 base::Bind(&SigninScreenHandler::SendPublicSessionKeyboardLayouts, |
1521 weak_factory_.GetWeakPtr(), account_id, locale), | 1409 weak_factory_.GetWeakPtr(), account_id, locale), |
1522 locale); | 1410 locale); |
1523 } | 1411 } |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1644 CrosSettings* cros_settings = CrosSettings::Get(); | 1532 CrosSettings* cros_settings = CrosSettings::Get(); |
1645 if (!cros_settings) | 1533 if (!cros_settings) |
1646 return false; | 1534 return false; |
1647 bool allow_guest; | 1535 bool allow_guest; |
1648 cros_settings->GetBoolean(kAccountsPrefAllowGuest, &allow_guest); | 1536 cros_settings->GetBoolean(kAccountsPrefAllowGuest, &allow_guest); |
1649 return allow_guest; | 1537 return allow_guest; |
1650 } | 1538 } |
1651 | 1539 |
1652 void SigninScreenHandler::OnShowAddUser() { | 1540 void SigninScreenHandler::OnShowAddUser() { |
1653 is_account_picker_showing_first_time_ = false; | 1541 is_account_picker_showing_first_time_ = false; |
1654 EnforcePolicyInputMethods(std::string()); | 1542 lock_screen_utils::EnforcePolicyInputMethods(std::string()); |
1655 gaia_screen_handler_->ShowGaiaAsync(); | 1543 gaia_screen_handler_->ShowGaiaAsync(); |
1656 } | 1544 } |
1657 | 1545 |
1658 net::Error SigninScreenHandler::FrameError() const { | 1546 net::Error SigninScreenHandler::FrameError() const { |
1659 return gaia_screen_handler_->frame_error(); | 1547 return gaia_screen_handler_->frame_error(); |
1660 } | 1548 } |
1661 | 1549 |
1662 void SigninScreenHandler::OnCapsLockChanged(bool enabled) { | 1550 void SigninScreenHandler::OnCapsLockChanged(bool enabled) { |
1663 caps_lock_enabled_ = enabled; | 1551 caps_lock_enabled_ = enabled; |
1664 if (page_is_ready()) | 1552 if (page_is_ready()) |
1665 CallJS("login.AccountPickerScreen.setCapsLockState", caps_lock_enabled_); | 1553 CallJS("login.AccountPickerScreen.setCapsLockState", caps_lock_enabled_); |
1666 } | 1554 } |
1667 | 1555 |
1668 void SigninScreenHandler::OnFeedbackFinished() { | 1556 void SigninScreenHandler::OnFeedbackFinished() { |
1669 CallJS("login.UnrecoverableCryptohomeErrorScreen.resumeAfterFeedbackUI"); | 1557 CallJS("login.UnrecoverableCryptohomeErrorScreen.resumeAfterFeedbackUI"); |
1670 | 1558 |
1671 // Recreate user's cryptohome after the feedback is attempted. | 1559 // Recreate user's cryptohome after the feedback is attempted. |
1672 HandleResyncUserData(); | 1560 HandleResyncUserData(); |
1673 } | 1561 } |
1674 | 1562 |
1675 void SigninScreenHandler::OnAllowedInputMethodsChanged() { | 1563 void SigninScreenHandler::OnAllowedInputMethodsChanged() { |
1676 if (!webui_visible_) | 1564 if (!webui_visible_) |
1677 return; | 1565 return; |
1678 | 1566 |
1679 if (focused_pod_account_id_) { | 1567 if (focused_pod_account_id_) { |
1680 std::string user_input_method = | 1568 std::string user_input_method = lock_screen_utils::GetUserLastInputMethod( |
1681 GetUserLastInputMethod(focused_pod_account_id_->GetUserEmail()); | 1569 focused_pod_account_id_->GetUserEmail()); |
1682 EnforcePolicyInputMethods(user_input_method); | 1570 lock_screen_utils::EnforcePolicyInputMethods(user_input_method); |
1683 } else { | 1571 } else { |
1684 EnforcePolicyInputMethods(std::string()); | 1572 lock_screen_utils::EnforcePolicyInputMethods(std::string()); |
1685 } | 1573 } |
1686 } | 1574 } |
1687 | 1575 |
1688 void SigninScreenHandler::SetKeyboardSettings(const AccountId& account_id) { | |
1689 bool auto_repeat_enabled = language_prefs::kXkbAutoRepeatEnabled; | |
1690 if (user_manager::known_user::GetBooleanPref( | |
1691 account_id, prefs::kLanguageXkbAutoRepeatEnabled, | |
1692 &auto_repeat_enabled) && | |
1693 !auto_repeat_enabled) { | |
1694 input_method::InputMethodManager::Get() | |
1695 ->GetImeKeyboard() | |
1696 ->SetAutoRepeatEnabled(false); | |
1697 return; | |
1698 } | |
1699 | |
1700 int auto_repeat_delay = language_prefs::kXkbAutoRepeatDelayInMs; | |
1701 int auto_repeat_interval = language_prefs::kXkbAutoRepeatIntervalInMs; | |
1702 user_manager::known_user::GetIntegerPref( | |
1703 account_id, prefs::kLanguageXkbAutoRepeatDelay, &auto_repeat_delay); | |
1704 user_manager::known_user::GetIntegerPref( | |
1705 account_id, prefs::kLanguageXkbAutoRepeatInterval, &auto_repeat_interval); | |
1706 input_method::AutoRepeatRate rate; | |
1707 rate.initial_delay_in_ms = auto_repeat_delay; | |
1708 rate.repeat_interval_in_ms = auto_repeat_interval; | |
1709 input_method::InputMethodManager::Get() | |
1710 ->GetImeKeyboard() | |
1711 ->SetAutoRepeatEnabled(true); | |
1712 input_method::InputMethodManager::Get()->GetImeKeyboard()->SetAutoRepeatRate( | |
1713 rate); | |
1714 } | |
1715 | |
1716 } // namespace chromeos | 1576 } // namespace chromeos |
OLD | NEW |