Index: chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc |
diff --git a/chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc b/chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc |
index 6fc261635b5702fc6f6f8aaa455f02e76f745061..44fd987b4dd75cd4d6a204bcad6e036bb4e573ff 100644 |
--- a/chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc |
+++ b/chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc |
@@ -231,6 +231,39 @@ static bool SetUserInputMethodImpl( |
return true; |
} |
+void EnforcePolicyInputMethods(std::string user_input_method) { |
+ chromeos::CrosSettings* cros_settings = chromeos::CrosSettings::Get(); |
+ const base::ListValue* login_screen_input_methods = nullptr; |
+ if (!cros_settings->GetList(chromeos::kDeviceLoginScreenInputMethods, |
+ &login_screen_input_methods)) { |
+ return; |
+ } |
+ |
+ std::vector<std::string> allowed_input_methods; |
+ |
+ // Add user's input method first so it is pre-selected. |
+ if (!user_input_method.empty()) { |
+ allowed_input_methods.push_back(user_input_method); |
+ } |
+ |
+ std::string input_method; |
+ for (const auto& input_method_entry : *login_screen_input_methods) { |
+ if (input_method_entry->GetAsString(&input_method)) |
+ allowed_input_methods.push_back(input_method); |
+ } |
+ chromeos::input_method::InputMethodManager* imm = |
+ chromeos::input_method::InputMethodManager::Get(); |
+ imm->GetActiveIMEState()->SetAllowedInputMethods(allowed_input_methods); |
+} |
+ |
+void StopEnforcingPolicyInputMethods() { |
+ // Empty means all input methods are allowed |
+ std::vector<std::string> allowed_input_methods; |
+ chromeos::input_method::InputMethodManager* imm = |
+ chromeos::input_method::InputMethodManager::Get(); |
+ imm->GetActiveIMEState()->SetAllowedInputMethods(allowed_input_methods); |
+} |
+ |
} // namespace |
// LoginScreenContext implementation ------------------------------------------ |
@@ -294,6 +327,12 @@ SigninScreenHandler::SigninScreenHandler( |
chromeos::input_method::InputMethodManager::Get()->GetImeKeyboard(); |
if (keyboard) |
keyboard->AddObserver(this); |
+ OnAllowedInputMethodsChanged(); |
+ allowed_input_methods_subscription_ = |
+ chromeos::CrosSettings::Get()->AddSettingsObserver( |
+ chromeos::kDeviceLoginScreenInputMethods, |
+ base::Bind(&SigninScreenHandler::OnAllowedInputMethodsChanged, |
+ base::Unretained(this))); |
content::ServiceManagerConnection::GetForProcess() |
->GetConnector() |
@@ -312,6 +351,7 @@ SigninScreenHandler::~SigninScreenHandler() { |
chromeos::input_method::InputMethodManager::Get()->GetImeKeyboard(); |
if (keyboard) |
keyboard->RemoveObserver(this); |
+ StopEnforcingPolicyInputMethods(); |
weak_factory_.InvalidateWeakPtrs(); |
if (delegate_) |
delegate_->SetWebUIHandler(nullptr); |
@@ -354,6 +394,8 @@ void SigninScreenHandler::SetUserInputMethod( |
const std::string input_method = GetUserLRUInputMethod(username); |
+ EnforcePolicyInputMethods(input_method); |
+ |
if (!input_method.empty()) |
succeed = SetUserInputMethodImpl(username, input_method, ime_state); |
@@ -568,6 +610,7 @@ void SigninScreenHandler::RegisterMessages() { |
AddCallback("showLoadingTimeoutError", |
&SigninScreenHandler::HandleShowLoadingTimeoutError); |
AddCallback("focusPod", &SigninScreenHandler::HandleFocusPod); |
+ AddCallback("noPodFocused", &SigninScreenHandler::HandleNoPodFocused); |
AddCallback("getPublicSessionKeyboardLayouts", |
&SigninScreenHandler::HandleGetPublicSessionKeyboardLayouts); |
AddCallback("getTouchViewState", |
@@ -1387,6 +1430,8 @@ void SigninScreenHandler::HandleFocusPod(const AccountId& account_id) { |
if (!test_focus_pod_callback_.is_null()) |
test_focus_pod_callback_.Run(); |
+ focused_pod_account_id_ = base::MakeUnique<AccountId>(account_id); |
+ |
const user_manager::User* user = |
user_manager::UserManager::Get()->FindUser(account_id); |
// |user| may be nullptr in kiosk mode or unit tests. |
@@ -1408,6 +1453,11 @@ void SigninScreenHandler::HandleFocusPod(const AccountId& account_id) { |
} |
} |
+void SigninScreenHandler::HandleNoPodFocused() { |
+ focused_pod_account_id_.reset(); |
+ EnforcePolicyInputMethods(std::string()); |
+} |
+ |
void SigninScreenHandler::HandleGetPublicSessionKeyboardLayouts( |
const AccountId& account_id, |
const std::string& locale) { |
@@ -1555,4 +1605,14 @@ void SigninScreenHandler::OnFeedbackFinished() { |
HandleResyncUserData(); |
} |
+void SigninScreenHandler::OnAllowedInputMethodsChanged() { |
+ if (focused_pod_account_id_) { |
+ std::string user_input_method = |
+ GetUserLRUInputMethod(focused_pod_account_id_->GetUserEmail()); |
+ EnforcePolicyInputMethods(user_input_method); |
+ } else { |
+ EnforcePolicyInputMethods(std::string()); |
+ } |
+} |
+ |
} // namespace chromeos |