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

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

Issue 484353005: ChromeOS: "Add New User" screen should enable all hardware keyboards. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests. 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 (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 <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 std::string GetNetworkName(const std::string& service_path) { 168 std::string GetNetworkName(const std::string& service_path) {
169 const NetworkState* network = NetworkHandler::Get()->network_state_handler()-> 169 const NetworkState* network = NetworkHandler::Get()->network_state_handler()->
170 GetNetworkState(service_path); 170 GetNetworkState(service_path);
171 if (!network) 171 if (!network)
172 return std::string(); 172 return std::string();
173 return network->name(); 173 return network->name();
174 } 174 }
175 175
176 static bool SetUserInputMethodImpl( 176 static bool SetUserInputMethodImpl(
177 const std::string& username, 177 const std::string& username,
178 chromeos::input_method::InputMethodManager* manager) { 178 const std::string& user_input_method,
179 PrefService* const local_state = g_browser_process->local_state(); 179 input_method::InputMethodManager::State* ime_state) {
180 180 if (!chromeos::input_method::InputMethodManager::Get()->IsLoginKeyboard(
181 const base::DictionaryValue* users_lru_input_methods = 181 user_input_method)) {
182 local_state->GetDictionary(prefs::kUsersLRUInputMethod);
183
184 if (users_lru_input_methods == NULL) {
185 DLOG(WARNING) << "SetUserInputMethod('" << username
186 << "'): no kUsersLRUInputMethod";
187 return false;
188 }
189
190 std::string input_method;
191
192 if (!users_lru_input_methods->GetStringWithoutPathExpansion(username,
193 &input_method)) {
194 DVLOG(0) << "SetUserInputMethod('" << username
195 << "'): no input method for this user";
196 return false;
197 }
198
199 if (input_method.empty())
200 return false;
201
202 if (!manager->IsLoginKeyboard(input_method)) {
203 LOG(WARNING) << "SetUserInputMethod('" << username 182 LOG(WARNING) << "SetUserInputMethod('" << username
204 << "'): stored user LRU input method '" << input_method 183 << "'): stored user LRU input method '" << user_input_method
205 << "' is no longer Full Latin Keyboard Language" 184 << "' is no longer Full Latin Keyboard Language"
206 << " (entry dropped). Use hardware default instead."; 185 << " (entry dropped). Use hardware default instead.";
207 186
187 PrefService* const local_state = g_browser_process->local_state();
208 DictionaryPrefUpdate updater(local_state, prefs::kUsersLRUInputMethod); 188 DictionaryPrefUpdate updater(local_state, prefs::kUsersLRUInputMethod);
209 189
210 base::DictionaryValue* const users_lru_input_methods = updater.Get(); 190 base::DictionaryValue* const users_lru_input_methods = updater.Get();
211 if (users_lru_input_methods != NULL) { 191 if (users_lru_input_methods != NULL) {
212 users_lru_input_methods->SetStringWithoutPathExpansion(username, ""); 192 users_lru_input_methods->SetStringWithoutPathExpansion(username, "");
213 } 193 }
214 return false; 194 return false;
215 } 195 }
216 196
217 if (!Contains(manager->GetActiveIMEState()->GetActiveInputMethodIds(), 197 if (!Contains(ime_state->GetActiveInputMethodIds(), user_input_method)) {
218 input_method)) { 198 if (!ime_state->EnableInputMethod(user_input_method)) {
219 if (!manager->GetActiveIMEState()->EnableInputMethod(input_method)) {
220 DLOG(ERROR) << "SigninScreenHandler::SetUserInputMethod('" << username 199 DLOG(ERROR) << "SigninScreenHandler::SetUserInputMethod('" << username
221 << "'): user input method '" << input_method 200 << "'): user input method '" << user_input_method
222 << "' is not enabled and enabling failed (ignored!)."; 201 << "' is not enabled and enabling failed (ignored!).";
223 } 202 }
224 } 203 }
225 manager->GetActiveIMEState()->ChangeInputMethod(input_method, 204 ime_state->ChangeInputMethod(user_input_method, false /* show_message */);
226 false /* show_message */);
227 205
228 return true; 206 return true;
229 } 207 }
230 208
231 } // namespace 209 } // namespace
232 210
233 // LoginScreenContext implementation ------------------------------------------ 211 // LoginScreenContext implementation ------------------------------------------
234 212
235 LoginScreenContext::LoginScreenContext() { 213 LoginScreenContext::LoginScreenContext() {
236 Init(); 214 Init();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 error_screen_actor_(error_screen_actor), 247 error_screen_actor_(error_screen_actor),
270 core_oobe_actor_(core_oobe_actor), 248 core_oobe_actor_(core_oobe_actor),
271 is_first_update_state_call_(true), 249 is_first_update_state_call_(true),
272 offline_login_active_(false), 250 offline_login_active_(false),
273 last_network_state_(NetworkStateInformer::UNKNOWN), 251 last_network_state_(NetworkStateInformer::UNKNOWN),
274 has_pending_auth_ui_(false), 252 has_pending_auth_ui_(false),
275 caps_lock_enabled_(chromeos::input_method::InputMethodManager::Get() 253 caps_lock_enabled_(chromeos::input_method::InputMethodManager::Get()
276 ->GetImeKeyboard() 254 ->GetImeKeyboard()
277 ->CapsLockIsEnabled()), 255 ->CapsLockIsEnabled()),
278 gaia_screen_handler_(gaia_screen_handler), 256 gaia_screen_handler_(gaia_screen_handler),
257 oobe_ui_observer_added_(false),
279 weak_factory_(this) { 258 weak_factory_(this) {
280 DCHECK(network_state_informer_.get()); 259 DCHECK(network_state_informer_.get());
281 DCHECK(error_screen_actor_); 260 DCHECK(error_screen_actor_);
282 DCHECK(core_oobe_actor_); 261 DCHECK(core_oobe_actor_);
283 DCHECK(gaia_screen_handler_); 262 DCHECK(gaia_screen_handler_);
284 gaia_screen_handler_->SetSigninScreenHandler(this); 263 gaia_screen_handler_->SetSigninScreenHandler(this);
285 network_state_informer_->AddObserver(this); 264 network_state_informer_->AddObserver(this);
286 265
287 registrar_.Add(this, 266 registrar_.Add(this,
288 chrome::NOTIFICATION_AUTH_NEEDED, 267 chrome::NOTIFICATION_AUTH_NEEDED,
(...skipping 18 matching lines...) Expand all
307 policy::ConsumerManagementService* consumer_management = 286 policy::ConsumerManagementService* consumer_management =
308 g_browser_process->platform_part()->browser_policy_connector_chromeos()-> 287 g_browser_process->platform_part()->browser_policy_connector_chromeos()->
309 GetConsumerManagementService(); 288 GetConsumerManagementService();
310 is_enrolling_consumer_management_ = 289 is_enrolling_consumer_management_ =
311 consumer_management && 290 consumer_management &&
312 consumer_management->GetEnrollmentStage() == 291 consumer_management->GetEnrollmentStage() ==
313 policy::ConsumerManagementService::ENROLLMENT_STAGE_REQUESTED; 292 policy::ConsumerManagementService::ENROLLMENT_STAGE_REQUESTED;
314 } 293 }
315 294
316 SigninScreenHandler::~SigninScreenHandler() { 295 SigninScreenHandler::~SigninScreenHandler() {
296 OobeUI* oobe_ui = GetOobeUI();
297 if (oobe_ui && oobe_ui_observer_added_)
298 oobe_ui->RemoveObserver(this);
317 chromeos::input_method::ImeKeyboard* keyboard = 299 chromeos::input_method::ImeKeyboard* keyboard =
318 chromeos::input_method::InputMethodManager::Get()->GetImeKeyboard(); 300 chromeos::input_method::InputMethodManager::Get()->GetImeKeyboard();
319 if (keyboard) 301 if (keyboard)
320 keyboard->RemoveObserver(this); 302 keyboard->RemoveObserver(this);
321 weak_factory_.InvalidateWeakPtrs(); 303 weak_factory_.InvalidateWeakPtrs();
322 if (delegate_) 304 if (delegate_)
323 delegate_->SetWebUIHandler(NULL); 305 delegate_->SetWebUIHandler(NULL);
324 network_state_informer_->RemoveObserver(this); 306 network_state_informer_->RemoveObserver(this);
325 if (max_mode_delegate_) { 307 if (max_mode_delegate_) {
326 max_mode_delegate_->RemoveObserver(this); 308 max_mode_delegate_->RemoveObserver(this);
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 void SigninScreenHandler::OnNetworkReady() { 453 void SigninScreenHandler::OnNetworkReady() {
472 VLOG(1) << "OnNetworkReady() call."; 454 VLOG(1) << "OnNetworkReady() call.";
473 DCHECK(gaia_screen_handler_); 455 DCHECK(gaia_screen_handler_);
474 gaia_screen_handler_->MaybePreloadAuthExtension(); 456 gaia_screen_handler_->MaybePreloadAuthExtension();
475 } 457 }
476 458
477 void SigninScreenHandler::UpdateState(ErrorScreenActor::ErrorReason reason) { 459 void SigninScreenHandler::UpdateState(ErrorScreenActor::ErrorReason reason) {
478 UpdateStateInternal(reason, false); 460 UpdateStateInternal(reason, false);
479 } 461 }
480 462
463 void SigninScreenHandler::SetFocusPODCallbackForTesting(
464 base::Closure callback) {
465 test_focus_pod_callback_ = callback;
466 }
467
481 // SigninScreenHandler, private: ----------------------------------------------- 468 // SigninScreenHandler, private: -----------------------------------------------
482 469
483 void SigninScreenHandler::ShowImpl() { 470 void SigninScreenHandler::ShowImpl() {
484 if (!page_is_ready()) { 471 if (!page_is_ready()) {
485 show_on_init_ = true; 472 show_on_init_ = true;
486 return; 473 return;
487 } 474 }
488 475
476 if (!ime_state_.get())
477 ime_state_ = input_method::InputMethodManager::Get()->GetActiveIMEState();
478
479 if (!oobe_ui_observer_added_) {
480 oobe_ui_observer_added_ = true;
481 GetOobeUI()->AddObserver(this);
482 }
483
489 if (oobe_ui_ || is_enrolling_consumer_management_) { 484 if (oobe_ui_ || is_enrolling_consumer_management_) {
490 // Shows new user sign-in for OOBE. 485 // Shows new user sign-in for OOBE.
491 OnShowAddUser(); 486 OnShowAddUser();
492 } else { 487 } else {
493 // Populates account picker. Animation is turned off for now until we 488 // Populates account picker. Animation is turned off for now until we
494 // figure out how to make it fast enough. 489 // figure out how to make it fast enough.
495 delegate_->HandleGetUsers(); 490 delegate_->HandleGetUsers();
496 491
497 // Reset Caps Lock state when login screen is shown. 492 // Reset Caps Lock state when login screen is shown.
498 input_method::InputMethodManager::Get() 493 input_method::InputMethodManager::Get()
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 782
788 // This message is sent by the kiosk app menu, but is handled here 783 // This message is sent by the kiosk app menu, but is handled here
789 // so we can tell the delegate to launch the app. 784 // so we can tell the delegate to launch the app.
790 AddCallback("launchKioskApp", &SigninScreenHandler::HandleLaunchKioskApp); 785 AddCallback("launchKioskApp", &SigninScreenHandler::HandleLaunchKioskApp);
791 } 786 }
792 787
793 void SigninScreenHandler::RegisterPrefs(PrefRegistrySimple* registry) { 788 void SigninScreenHandler::RegisterPrefs(PrefRegistrySimple* registry) {
794 registry->RegisterDictionaryPref(prefs::kUsersLRUInputMethod); 789 registry->RegisterDictionaryPref(prefs::kUsersLRUInputMethod);
795 } 790 }
796 791
792 void SigninScreenHandler::OnCurrentScreenChanged(OobeUI::Screen current_screen,
793 OobeUI::Screen new_screen) {
794 if (new_screen == OobeUI::SCREEN_ACCOUNT_PICKER) {
795 // Restore active IME state if returning to user pod row screen.
796 input_method::InputMethodManager::Get()->SetState(ime_state_);
797 }
798 }
799
800 std::string SigninScreenHandler::GetUserLRUInputMethod(
801 const std::string& username) const {
802 PrefService* const local_state = g_browser_process->local_state();
803 const base::DictionaryValue* users_lru_input_methods =
804 local_state->GetDictionary(prefs::kUsersLRUInputMethod);
805
806 if (users_lru_input_methods == NULL) {
807 DLOG(WARNING) << "GetUserLRUInputMethod('" << username
808 << "'): no kUsersLRUInputMethod";
809 return std::string();
810 }
811
812 std::string input_method;
813
814 if (!users_lru_input_methods->GetStringWithoutPathExpansion(username,
815 &input_method)) {
816 DVLOG(0) << "GetUserLRUInputMethod('" << username
817 << "'): no input method for this user";
818 return std::string();
819 }
820
821 return input_method;
822 }
823
797 void SigninScreenHandler::HandleGetUsers() { 824 void SigninScreenHandler::HandleGetUsers() {
798 if (delegate_) 825 if (delegate_)
799 delegate_->HandleGetUsers(); 826 delegate_->HandleGetUsers();
800 } 827 }
801 828
802 void SigninScreenHandler::ClearAndEnablePassword() { 829 void SigninScreenHandler::ClearAndEnablePassword() {
803 core_oobe_actor_->ResetSignInUI(false); 830 core_oobe_actor_->ResetSignInUI(false);
804 } 831 }
805 832
806 void SigninScreenHandler::ClearUserPodPassword() { 833 void SigninScreenHandler::ClearUserPodPassword() {
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
993 1020
994 bool SigninScreenHandler::ShouldLoadGaia() const { 1021 bool SigninScreenHandler::ShouldLoadGaia() const {
995 // Fetching of the extension is not started before account picker page is 1022 // Fetching of the extension is not started before account picker page is
996 // loaded because it can affect the loading speed. 1023 // loaded because it can affect the loading speed.
997 // Do not load the extension for the screen locker, see crosbug.com/25018. 1024 // Do not load the extension for the screen locker, see crosbug.com/25018.
998 return !ScreenLocker::default_screen_locker() && 1025 return !ScreenLocker::default_screen_locker() &&
999 is_account_picker_showing_first_time_; 1026 is_account_picker_showing_first_time_;
1000 } 1027 }
1001 1028
1002 // Update keyboard layout to least recently used by the user. 1029 // Update keyboard layout to least recently used by the user.
1003 void SigninScreenHandler::SetUserInputMethod(const std::string& username) { 1030 void SigninScreenHandler::SetUserInputMethod(
1031 const std::string& username,
1032 input_method::InputMethodManager::State* ime_state) {
1004 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); 1033 user_manager::UserManager* user_manager = user_manager::UserManager::Get();
1005 if (user_manager->IsUserLoggedIn()) { 1034 if (user_manager->IsUserLoggedIn()) {
1006 // We are on sign-in screen inside user session (adding new user to 1035 // We are on sign-in screen inside user session (adding new user to
1007 // the session or on lock screen), don't switch input methods in this case. 1036 // the session or on lock screen), don't switch input methods in this case.
1008 // TODO(dpolukhin): adding user and sign-in should be consistent 1037 // TODO(dpolukhin): adding user and sign-in should be consistent
1009 // crbug.com/292774 1038 // crbug.com/292774
1010 return; 1039 return;
1011 } 1040 }
1012 1041
1013 chromeos::input_method::InputMethodManager* const manager = 1042 bool succeed = false;
1014 chromeos::input_method::InputMethodManager::Get();
1015 1043
1016 const bool succeed = SetUserInputMethodImpl(username, manager); 1044 const std::string input_method = GetUserLRUInputMethod(username);
1045
1046 if (!input_method.empty())
1047 succeed = SetUserInputMethodImpl(username, input_method, ime_state);
1017 1048
1018 // This is also a case when LRU layout is set only for a few local users, 1049 // This is also a case when LRU layout is set only for a few local users,
1019 // thus others need to be switched to default locale. 1050 // thus others need to be switched to default locale.
1020 // Otherwise they will end up using another user's locale to log in. 1051 // Otherwise they will end up using another user's locale to log in.
1021 if (!succeed) { 1052 if (!succeed) {
1022 DVLOG(0) << "SetUserInputMethod('" << username 1053 DVLOG(0) << "SetUserInputMethod('" << username
1023 << "'): failed to set user layout. Switching to default."; 1054 << "'): failed to set user layout. Switching to default.";
1024 1055
1025 manager->GetActiveIMEState()->SetInputMethodLoginDefault(); 1056 ime_state->SetInputMethodLoginDefault();
1026 } 1057 }
1027 } 1058 }
1028 1059
1029 1060
1030 void SigninScreenHandler::UserSettingsChanged() { 1061 void SigninScreenHandler::UserSettingsChanged() {
1031 DCHECK(gaia_screen_handler_); 1062 DCHECK(gaia_screen_handler_);
1032 GaiaContext context; 1063 GaiaContext context;
1033 if (delegate_) 1064 if (delegate_)
1034 context.has_users = !delegate_->GetUsers().empty(); 1065 context.has_users = !delegate_->GetUsers().empty();
1035 gaia_screen_handler_->UpdateGaia(context); 1066 gaia_screen_handler_->UpdateGaia(context);
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
1318 1349
1319 void SigninScreenHandler::HandleShowLoadingTimeoutError() { 1350 void SigninScreenHandler::HandleShowLoadingTimeoutError() {
1320 UpdateState(ErrorScreenActor::ERROR_REASON_LOADING_TIMEOUT); 1351 UpdateState(ErrorScreenActor::ERROR_REASON_LOADING_TIMEOUT);
1321 } 1352 }
1322 1353
1323 void SigninScreenHandler::HandleUpdateOfflineLogin(bool offline_login_active) { 1354 void SigninScreenHandler::HandleUpdateOfflineLogin(bool offline_login_active) {
1324 offline_login_active_ = offline_login_active; 1355 offline_login_active_ = offline_login_active;
1325 } 1356 }
1326 1357
1327 void SigninScreenHandler::HandleFocusPod(const std::string& user_id) { 1358 void SigninScreenHandler::HandleFocusPod(const std::string& user_id) {
1328 SetUserInputMethod(user_id); 1359 SetUserInputMethod(user_id, ime_state_.get());
1329 #if !defined(USE_ATHENA) 1360 #if !defined(USE_ATHENA)
1330 // TODO(dpolukhin): crbug.com/408734. 1361 // TODO(dpolukhin): crbug.com/408734.
1331 WallpaperManager::Get()->SetUserWallpaperDelayed(user_id); 1362 WallpaperManager::Get()->SetUserWallpaperDelayed(user_id);
1332 #endif 1363 #endif
1333 ScreenlockBridge::Get()->SetFocusedUser(user_id); 1364 ScreenlockBridge::Get()->SetFocusedUser(user_id);
1365 if (!test_focus_pod_callback_.is_null())
1366 test_focus_pod_callback_.Run();
1334 } 1367 }
1335 1368
1336 void SigninScreenHandler::HandleHardlockPod(const std::string& user_id) { 1369 void SigninScreenHandler::HandleHardlockPod(const std::string& user_id) {
1337 SetAuthType(user_id, 1370 SetAuthType(user_id,
1338 ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD, 1371 ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD,
1339 base::string16()); 1372 base::string16());
1340 HideUserPodCustomIcon(user_id); 1373 HideUserPodCustomIcon(user_id);
1341 } 1374 }
1342 1375
1343 void SigninScreenHandler::HandleRetrieveAuthenticatedUserEmail( 1376 void SigninScreenHandler::HandleRetrieveAuthenticatedUserEmail(
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1424 return true; 1457 return true;
1425 } 1458 }
1426 1459
1427 void SigninScreenHandler::CancelPasswordChangedFlowInternal() { 1460 void SigninScreenHandler::CancelPasswordChangedFlowInternal() {
1428 if (delegate_) { 1461 if (delegate_) {
1429 ShowImpl(); 1462 ShowImpl();
1430 delegate_->CancelPasswordChangedFlow(); 1463 delegate_->CancelPasswordChangedFlow();
1431 } 1464 }
1432 } 1465 }
1433 1466
1467 OobeUI* SigninScreenHandler::GetOobeUI() const {
1468 return static_cast<OobeUI*>(web_ui()->GetController());
1469 }
1470
1434 OobeUI::Screen SigninScreenHandler::GetCurrentScreen() const { 1471 OobeUI::Screen SigninScreenHandler::GetCurrentScreen() const {
1435 OobeUI::Screen screen = OobeUI::SCREEN_UNKNOWN; 1472 OobeUI::Screen screen = OobeUI::SCREEN_UNKNOWN;
1436 OobeUI* oobe_ui = static_cast<OobeUI*>(web_ui()->GetController()); 1473 OobeUI* oobe_ui = GetOobeUI();
1437 if (oobe_ui) 1474 if (oobe_ui)
1438 screen = oobe_ui->current_screen(); 1475 screen = oobe_ui->current_screen();
1439 return screen; 1476 return screen;
1440 } 1477 }
1441 1478
1442 bool SigninScreenHandler::IsGaiaVisible() const { 1479 bool SigninScreenHandler::IsGaiaVisible() const {
1443 return IsSigninScreen(GetCurrentScreen()) && 1480 return IsSigninScreen(GetCurrentScreen()) &&
1444 ui_state_ == UI_STATE_GAIA_SIGNIN; 1481 ui_state_ == UI_STATE_GAIA_SIGNIN;
1445 } 1482 }
1446 1483
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1517 return gaia_screen_handler_->frame_error(); 1554 return gaia_screen_handler_->frame_error();
1518 } 1555 }
1519 1556
1520 void SigninScreenHandler::OnCapsLockChanged(bool enabled) { 1557 void SigninScreenHandler::OnCapsLockChanged(bool enabled) {
1521 caps_lock_enabled_ = enabled; 1558 caps_lock_enabled_ = enabled;
1522 if (page_is_ready()) 1559 if (page_is_ready())
1523 CallJS("login.AccountPickerScreen.setCapsLockState", caps_lock_enabled_); 1560 CallJS("login.AccountPickerScreen.setCapsLockState", caps_lock_enabled_);
1524 } 1561 }
1525 1562
1526 } // namespace chromeos 1563 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698