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

Side by Side Diff: chrome/browser/chromeos/login/lock_screen_utils.cc

Issue 2923773003: Adding mojo calls for several lock screen related operations. (Closed)
Patch Set: comments and rebase Created 3 years, 6 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
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/login/lock_screen_utils.h"
6
7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/chromeos/language_preferences.h"
9 #include "chrome/browser/chromeos/settings/cros_settings.h"
10 #include "chrome/common/pref_names.h"
11 #include "components/prefs/scoped_user_pref_update.h"
12 #include "components/signin/core/account_id/account_id.h"
13 #include "components/user_manager/known_user.h"
14 #include "ui/base/ime/chromeos/ime_keyboard.h"
15
16 namespace chromeos {
17 namespace lock_screen_utils {
18
19 void SetUserInputMethod(const std::string& username,
20 input_method::InputMethodManager::State* ime_state) {
21 bool succeed = false;
22
23 const std::string input_method = GetUserLastInputMethod(username);
24
25 EnforcePolicyInputMethods(input_method);
26
27 if (!input_method.empty())
28 succeed = SetUserInputMethodImpl(username, input_method, ime_state);
29
30 // This is also a case when last layout is set only for a few local users,
31 // thus others need to be switched to default locale.
32 // Otherwise they will end up using another user's locale to log in.
33 if (!succeed) {
34 DVLOG(0) << "SetUserInputMethod: failed to set user layout. Switching to "
35 "default.";
36
37 ime_state->SetInputMethodLoginDefault();
38 }
39 }
40
41 std::string GetUserLastInputMethod(const std::string& username) {
42 PrefService* const local_state = g_browser_process->local_state();
43 const base::DictionaryValue* users_last_input_methods =
44 local_state->GetDictionary(prefs::kUsersLastInputMethod);
45
46 if (!users_last_input_methods) {
47 DLOG(WARNING) << "GetUserLastInputMethod('" << username
jdufault 2017/06/12 18:05:49 don't log username
xiaoyinh(OOO Sep 11-29) 2017/06/12 21:53:53 Done.
48 << "'): no kUsersLastInputMethod";
49 return std::string();
50 }
51
52 std::string input_method;
53
54 if (!users_last_input_methods->GetStringWithoutPathExpansion(username,
55 &input_method)) {
56 DVLOG(0) << "GetUserLastInputMethod('" << username
57 << "'): no input method for this user";
58 return std::string();
59 }
60
61 return input_method;
62 }
63
64 bool SetUserInputMethodImpl(
65 const std::string& username,
66 const std::string& user_input_method,
67 input_method::InputMethodManager::State* ime_state) {
68 if (!chromeos::input_method::InputMethodManager::Get()->IsLoginKeyboard(
69 user_input_method)) {
70 LOG(WARNING) << "SetUserInputMethod('" << username
jdufault 2017/06/12 18:05:49 don't log username
xiaoyinh(OOO Sep 11-29) 2017/06/12 21:53:53 Done.
71 << "'): stored user last input method '" << user_input_method
72 << "' is no longer Full Latin Keyboard Language"
73 << " (entry dropped). Use hardware default instead.";
74
75 PrefService* const local_state = g_browser_process->local_state();
76 DictionaryPrefUpdate updater(local_state, prefs::kUsersLastInputMethod);
77
78 base::DictionaryValue* const users_last_input_methods = updater.Get();
79 if (users_last_input_methods)
80 users_last_input_methods->SetStringWithoutPathExpansion(username, "");
81 return false;
82 }
83 if (!base::ContainsValue(ime_state->GetActiveInputMethodIds(),
84 user_input_method)) {
85 if (!ime_state->EnableInputMethod(user_input_method)) {
86 DLOG(ERROR) << "SigninScreenHandler::SetUserInputMethod('" << username
jdufault 2017/06/12 18:05:49 don't log username
xiaoyinh(OOO Sep 11-29) 2017/06/12 21:53:53 Done.
87 << "'): user input method '" << user_input_method
88 << "' is not enabled and enabling failed (ignored!).";
89 }
90 }
91 ime_state->ChangeInputMethod(user_input_method, false /* show_message */);
92
93 return true;
94 }
95
96 void EnforcePolicyInputMethods(std::string user_input_method) {
97 chromeos::CrosSettings* cros_settings = chromeos::CrosSettings::Get();
98 const base::ListValue* login_screen_input_methods = nullptr;
99 if (!cros_settings->GetList(chromeos::kDeviceLoginScreenInputMethods,
100 &login_screen_input_methods)) {
101 return;
102 }
103
104 std::vector<std::string> allowed_input_methods;
105
106 // Add user's input method first so it is pre-selected.
107 if (!user_input_method.empty()) {
108 allowed_input_methods.push_back(user_input_method);
109 }
110
111 std::string input_method;
112 for (const auto& input_method_entry : *login_screen_input_methods) {
113 if (input_method_entry.GetAsString(&input_method))
114 allowed_input_methods.push_back(input_method);
115 }
116 chromeos::input_method::InputMethodManager* imm =
117 chromeos::input_method::InputMethodManager::Get();
118 imm->GetActiveIMEState()->SetAllowedInputMethods(allowed_input_methods);
119 }
120
121 void SetKeyboardSettings(const AccountId& account_id) {
122 bool auto_repeat_enabled = language_prefs::kXkbAutoRepeatEnabled;
123 if (user_manager::known_user::GetBooleanPref(
124 account_id, prefs::kLanguageXkbAutoRepeatEnabled,
125 &auto_repeat_enabled) &&
126 !auto_repeat_enabled) {
127 input_method::InputMethodManager::Get()
128 ->GetImeKeyboard()
129 ->SetAutoRepeatEnabled(false);
130 return;
131 }
132
133 int auto_repeat_delay = language_prefs::kXkbAutoRepeatDelayInMs;
134 int auto_repeat_interval = language_prefs::kXkbAutoRepeatIntervalInMs;
135 user_manager::known_user::GetIntegerPref(
136 account_id, prefs::kLanguageXkbAutoRepeatDelay, &auto_repeat_delay);
137 user_manager::known_user::GetIntegerPref(
138 account_id, prefs::kLanguageXkbAutoRepeatInterval, &auto_repeat_interval);
139 input_method::AutoRepeatRate rate;
140 rate.initial_delay_in_ms = auto_repeat_delay;
141 rate.repeat_interval_in_ms = auto_repeat_interval;
142 input_method::InputMethodManager::Get()
143 ->GetImeKeyboard()
144 ->SetAutoRepeatEnabled(true);
145 input_method::InputMethodManager::Get()->GetImeKeyboard()->SetAutoRepeatRate(
146 rate);
147 }
148
149 } // namespace lock_screen_utils
150 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698