Commit f17ec46c authored by Roman Sorokin's avatar Roman Sorokin Committed by Commit Bot

cros: Honor DeviceLoginScreenInputMethods on the login screen.

Stop honor the policy on the lock screen.
Also tweaked LoginScreen*Policy tests a bit

Fixed: 1071012
Bug: 1067260, 1071010, 1071779
Change-Id: Icaa5fd108b66dbe22fde738f000b3eff49236347
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2149357
Commit-Queue: Roman Sorokin [CET] <rsorokin@chromium.org>
Reviewed-by: default avatarAlexander Alekseev <alemate@chromium.org>
Reviewed-by: default avatarDenis Kuznetsov [CET] <antrim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#760016}
parent e6f17955
...@@ -100,8 +100,6 @@ ViewsScreenLocker::~ViewsScreenLocker() { ...@@ -100,8 +100,6 @@ ViewsScreenLocker::~ViewsScreenLocker() {
void ViewsScreenLocker::Init() { void ViewsScreenLocker::Init() {
lock_time_ = base::TimeTicks::Now(); lock_time_ = base::TimeTicks::Now();
user_selection_screen_->Init(screen_locker_->GetUsersToShow()); user_selection_screen_->Init(screen_locker_->GetUsersToShow());
if (!ime_state_.get())
ime_state_ = input_method::InputMethodManager::Get()->GetActiveIMEState();
// Reset Caps Lock state when lock screen is shown. // Reset Caps Lock state when lock screen is shown.
input_method::InputMethodManager::Get()->GetImeKeyboard()->SetCapsLockEnabled( input_method::InputMethodManager::Get()->GetImeKeyboard()->SetCapsLockEnabled(
...@@ -128,13 +126,6 @@ void ViewsScreenLocker::Init() { ...@@ -128,13 +126,6 @@ void ViewsScreenLocker::Init() {
base::TimeTicks::Now() - lock_time_); base::TimeTicks::Now() - lock_time_);
screen_locker_->ScreenLockReady(); screen_locker_->ScreenLockReady();
lock_screen_apps::StateController::Get()->SetFocusCyclerDelegate(this); lock_screen_apps::StateController::Get()->SetFocusCyclerDelegate(this);
allowed_input_methods_subscription_ =
CrosSettings::Get()->AddSettingsObserver(
kDeviceLoginScreenInputMethods,
base::Bind(&ViewsScreenLocker::OnAllowedInputMethodsChanged,
base::Unretained(this)));
OnAllowedInputMethodsChanged();
} }
void ViewsScreenLocker::ShowErrorMessage( void ViewsScreenLocker::ShowErrorMessage(
...@@ -310,10 +301,6 @@ void ViewsScreenLocker::UpdateChallengeResponseAuthAvailability( ...@@ -310,10 +301,6 @@ void ViewsScreenLocker::UpdateChallengeResponseAuthAvailability(
account_id, enable_challenge_response); account_id, enable_challenge_response);
} }
void ViewsScreenLocker::OnAllowedInputMethodsChanged() {
user_selection_screen_->OnAllowedInputMethodsChanged();
}
void ViewsScreenLocker::OnPinCanAuthenticate(const AccountId& account_id, void ViewsScreenLocker::OnPinCanAuthenticate(const AccountId& account_id,
bool can_authenticate) { bool can_authenticate) {
ash::LoginScreen::Get()->GetModel()->SetPinEnabledForUser(account_id, ash::LoginScreen::Get()->GetModel()->SetPinEnabledForUser(account_id,
......
...@@ -84,7 +84,6 @@ class ViewsScreenLocker : public LoginScreenClient::Delegate, ...@@ -84,7 +84,6 @@ class ViewsScreenLocker : public LoginScreenClient::Delegate,
private: private:
void UpdatePinKeyboardState(const AccountId& account_id); void UpdatePinKeyboardState(const AccountId& account_id);
void UpdateChallengeResponseAuthAvailability(const AccountId& account_id); void UpdateChallengeResponseAuthAvailability(const AccountId& account_id);
void OnAllowedInputMethodsChanged();
void OnPinCanAuthenticate(const AccountId& account_id, bool can_authenticate); void OnPinCanAuthenticate(const AccountId& account_id, bool can_authenticate);
void OnExternalBinaryAuthTimeout(); void OnExternalBinaryAuthTimeout();
void OnExternalBinaryEnrollmentTimeout(); void OnExternalBinaryEnrollmentTimeout();
...@@ -98,12 +97,6 @@ class ViewsScreenLocker : public LoginScreenClient::Delegate, ...@@ -98,12 +97,6 @@ class ViewsScreenLocker : public LoginScreenClient::Delegate,
// Time when lock was initiated, required for metrics. // Time when lock was initiated, required for metrics.
base::TimeTicks lock_time_; base::TimeTicks lock_time_;
// Input Method Engine state used at lock screen.
scoped_refptr<input_method::InputMethodManager::State> ime_state_;
std::unique_ptr<CrosSettings::ObserverSubscription>
allowed_input_methods_subscription_;
base::OnceCallback<void(bool)> authenticate_with_external_binary_callback_; base::OnceCallback<void(bool)> authenticate_with_external_binary_callback_;
base::OnceCallback<void(bool)> enroll_user_with_external_binary_callback_; base::OnceCallback<void(bool)> enroll_user_with_external_binary_callback_;
......
...@@ -18,12 +18,14 @@ namespace chromeos { ...@@ -18,12 +18,14 @@ namespace chromeos {
namespace lock_screen_utils { namespace lock_screen_utils {
void SetUserInputMethod(const std::string& username, void SetUserInputMethod(const std::string& username,
input_method::InputMethodManager::State* ime_state) { input_method::InputMethodManager::State* ime_state,
bool honor_device_policy) {
bool succeed = false; bool succeed = false;
const std::string input_method = GetUserLastInputMethod(username); const std::string input_method = GetUserLastInputMethod(username);
EnforcePolicyInputMethods(input_method); if (honor_device_policy)
EnforceDevicePolicyInputMethods(input_method);
if (!input_method.empty()) if (!input_method.empty())
succeed = SetUserInputMethodImpl(username, input_method, ime_state); succeed = SetUserInputMethodImpl(username, input_method, ime_state);
...@@ -92,7 +94,7 @@ bool SetUserInputMethodImpl( ...@@ -92,7 +94,7 @@ bool SetUserInputMethodImpl(
return true; return true;
} }
void EnforcePolicyInputMethods(std::string user_input_method) { void EnforceDevicePolicyInputMethods(std::string user_input_method) {
chromeos::CrosSettings* cros_settings = chromeos::CrosSettings::Get(); chromeos::CrosSettings* cros_settings = chromeos::CrosSettings::Get();
const base::ListValue* login_screen_input_methods = nullptr; const base::ListValue* login_screen_input_methods = nullptr;
if (!cros_settings->GetList(chromeos::kDeviceLoginScreenInputMethods, if (!cros_settings->GetList(chromeos::kDeviceLoginScreenInputMethods,
...@@ -129,6 +131,7 @@ void StopEnforcingPolicyInputMethods() { ...@@ -129,6 +131,7 @@ void StopEnforcingPolicyInputMethods() {
imm->GetActiveIMEState()->SetAllowedInputMethods(allowed_input_methods, true); imm->GetActiveIMEState()->SetAllowedInputMethods(allowed_input_methods, true);
if (ImeControllerClient::Get()) // Can be null in tests. if (ImeControllerClient::Get()) // Can be null in tests.
ImeControllerClient::Get()->SetImesManagedByPolicy(false); ImeControllerClient::Get()->SetImesManagedByPolicy(false);
imm->GetActiveIMEState()->SetInputMethodLoginDefault();
} }
void SetKeyboardSettings(const AccountId& account_id) { void SetKeyboardSettings(const AccountId& account_id) {
......
...@@ -20,7 +20,8 @@ namespace lock_screen_utils { ...@@ -20,7 +20,8 @@ namespace lock_screen_utils {
// Update current input method (namely keyboard layout) in the given IME state // Update current input method (namely keyboard layout) in the given IME state
// to last input method used by this user. // to last input method used by this user.
void SetUserInputMethod(const std::string& username, void SetUserInputMethod(const std::string& username,
input_method::InputMethodManager::State* ime_state); input_method::InputMethodManager::State* ime_state,
bool honor_device_policy);
// Get user's last input method. // Get user's last input method.
std::string GetUserLastInputMethod(const std::string& username); std::string GetUserLastInputMethod(const std::string& username);
...@@ -31,8 +32,8 @@ bool SetUserInputMethodImpl(const std::string& username, ...@@ -31,8 +32,8 @@ bool SetUserInputMethodImpl(const std::string& username,
input_method::InputMethodManager::State* ime_state); input_method::InputMethodManager::State* ime_state);
// Sets the currently allowed input method, including those that are enforced // Sets the currently allowed input method, including those that are enforced
// by policy. // by device policy.
void EnforcePolicyInputMethods(std::string user_input_method); void EnforceDevicePolicyInputMethods(std::string user_input_method);
// Remove any policy limitations on allowed IMEs. // Remove any policy limitations on allowed IMEs.
void StopEnforcingPolicyInputMethods(); void StopEnforcingPolicyInputMethods();
......
...@@ -18,10 +18,13 @@ ...@@ -18,10 +18,13 @@
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/login/startup_utils.h" #include "chrome/browser/chromeos/login/startup_utils.h"
#include "chrome/browser/chromeos/login/test/js_checker.h" #include "chrome/browser/chromeos/login/test/js_checker.h"
#include "chrome/browser/chromeos/login/test/login_manager_mixin.h"
#include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h"
#include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h"
#include "chrome/browser/chromeos/settings/cros_settings.h" #include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/lifetime/application_lifetime.h" #include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/ui/ash/login_screen_client.h" #include "chrome/browser/ui/ash/login_screen_client.h"
#include "chrome/browser/ui/webui/chromeos/login/gaia_screen_handler.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "chromeos/constants/chromeos_switches.h" #include "chromeos/constants/chromeos_switches.h"
...@@ -52,26 +55,7 @@ class LoginScreenPolicyTest : public policy::DevicePolicyCrosBrowserTest { ...@@ -52,26 +55,7 @@ class LoginScreenPolicyTest : public policy::DevicePolicyCrosBrowserTest {
const char* cros_setting_name); const char* cros_setting_name);
protected: protected:
void WaitForLoginScreen() { LoginManagerMixin login_manager_{&mixin_host_};
content::WindowedNotificationObserver(
chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
content::NotificationService::AllSources())
.Wait();
}
void SetUpCommandLine(base::CommandLine* command_line) override {
policy::DevicePolicyCrosBrowserTest::SetUpCommandLine(command_line);
command_line->AppendSwitch(switches::kLoginManager);
command_line->AppendSwitch(switches::kForceLoginManagerInTests);
}
void TearDownOnMainThread() override {
// This shuts down the login UI.
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(&chrome::AttemptExit));
base::RunLoop().RunUntilIdle();
policy::DevicePolicyCrosBrowserTest::TearDownOnMainThread();
}
private: private:
DISALLOW_COPY_AND_ASSIGN(LoginScreenPolicyTest); DISALLOW_COPY_AND_ASSIGN(LoginScreenPolicyTest);
...@@ -79,46 +63,11 @@ class LoginScreenPolicyTest : public policy::DevicePolicyCrosBrowserTest { ...@@ -79,46 +63,11 @@ class LoginScreenPolicyTest : public policy::DevicePolicyCrosBrowserTest {
void LoginScreenPolicyTest::RefreshDevicePolicyAndWaitForSettingChange( void LoginScreenPolicyTest::RefreshDevicePolicyAndWaitForSettingChange(
const char* cros_setting_name) { const char* cros_setting_name) {
scoped_refptr<content::MessageLoopRunner> runner( policy_helper()->RefreshPolicyAndWaitUntilDeviceSettingsUpdated(
new content::MessageLoopRunner); {cros_setting_name});
std::unique_ptr<CrosSettings::ObserverSubscription> subscription(
chromeos::CrosSettings::Get()->AddSettingsObserver(
cros_setting_name,
base::BindLambdaForTesting([&]() { runner->Quit(); })));
RefreshDevicePolicy();
runner->Run();
}
IN_PROC_BROWSER_TEST_F(LoginScreenPolicyTest, RestrictInputMethods) {
WaitForLoginScreen();
input_method::InputMethodManager* imm =
input_method::InputMethodManager::Get();
ASSERT_TRUE(imm);
ASSERT_EQ(0U, imm->GetActiveIMEState()->GetAllowedInputMethods().size());
em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
proto.mutable_login_screen_input_methods()->add_login_screen_input_methods(
"xkb:de::ger");
RefreshDevicePolicyAndWaitForSettingChange(
chromeos::kDeviceLoginScreenInputMethods);
ASSERT_EQ(1U, imm->GetActiveIMEState()->GetAllowedInputMethods().size());
// Remove the policy again
proto.mutable_login_screen_input_methods()
->clear_login_screen_input_methods();
RefreshDevicePolicyAndWaitForSettingChange(
chromeos::kDeviceLoginScreenInputMethods);
ASSERT_EQ(0U, imm->GetActiveIMEState()->GetAllowedInputMethods().size());
} }
IN_PROC_BROWSER_TEST_F(LoginScreenPolicyTest, PolicyInputMethodsListEmpty) { IN_PROC_BROWSER_TEST_F(LoginScreenPolicyTest, PolicyInputMethodsListEmpty) {
WaitForLoginScreen();
input_method::InputMethodManager* imm = input_method::InputMethodManager* imm =
input_method::InputMethodManager::Get(); input_method::InputMethodManager::Get();
ASSERT_TRUE(imm); ASSERT_TRUE(imm);
...@@ -136,19 +85,18 @@ IN_PROC_BROWSER_TEST_F(LoginScreenPolicyTest, PolicyInputMethodsListEmpty) { ...@@ -136,19 +85,18 @@ IN_PROC_BROWSER_TEST_F(LoginScreenPolicyTest, PolicyInputMethodsListEmpty) {
ASSERT_EQ(0U, imm->GetActiveIMEState()->GetAllowedInputMethods().size()); ASSERT_EQ(0U, imm->GetActiveIMEState()->GetAllowedInputMethods().size());
} }
class LoginScreenGuestButtonPolicy : public LoginScreenPolicyTest { class LoginScreenGuestButtonPolicyTest : public LoginScreenPolicyTest {
public: protected:
LoginScreenGuestButtonPolicy() { void SetGuestModePolicy(bool enabled) {
device_state_.SetState( em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
DeviceStateMixin::State::OOBE_COMPLETED_CLOUD_ENROLLED); proto.mutable_guest_mode_enabled()->set_guest_mode_enabled(enabled);
RefreshDevicePolicyAndWaitForSettingChange(
chromeos::kAccountsPrefAllowGuest);
} }
private:
DISALLOW_COPY_AND_ASSIGN(LoginScreenGuestButtonPolicy);
}; };
IN_PROC_BROWSER_TEST_F(LoginScreenGuestButtonPolicy, NoUsers) { IN_PROC_BROWSER_TEST_F(LoginScreenGuestButtonPolicyTest, NoUsers) {
WaitForLoginScreen(); OobeScreenWaiter(GaiaView::kScreenId).Wait();
// Default. // Default.
EXPECT_TRUE(ash::LoginScreenTestApi::IsGuestButtonShown()); EXPECT_TRUE(ash::LoginScreenTestApi::IsGuestButtonShown());
...@@ -160,31 +108,21 @@ IN_PROC_BROWSER_TEST_F(LoginScreenGuestButtonPolicy, NoUsers) { ...@@ -160,31 +108,21 @@ IN_PROC_BROWSER_TEST_F(LoginScreenGuestButtonPolicy, NoUsers) {
test::ExecuteOobeJS("chrome.send('showGuestInOobe', [true]);"); test::ExecuteOobeJS("chrome.send('showGuestInOobe', [true]);");
EXPECT_TRUE(ash::LoginScreenTestApi::IsGuestButtonShown()); EXPECT_TRUE(ash::LoginScreenTestApi::IsGuestButtonShown());
{ SetGuestModePolicy(false);
em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
proto.mutable_guest_mode_enabled()->set_guest_mode_enabled(false);
RefreshDevicePolicyAndWaitForSettingChange(
chromeos::kAccountsPrefAllowGuest);
EXPECT_FALSE(ash::LoginScreenTestApi::IsGuestButtonShown()); EXPECT_FALSE(ash::LoginScreenTestApi::IsGuestButtonShown());
test::ExecuteOobeJS("chrome.send('showGuestInOobe', [true]);"); test::ExecuteOobeJS("chrome.send('showGuestInOobe', [true]);");
// Should not affect. // Should not affect.
EXPECT_FALSE(ash::LoginScreenTestApi::IsGuestButtonShown()); EXPECT_FALSE(ash::LoginScreenTestApi::IsGuestButtonShown());
}
{
em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
proto.mutable_guest_mode_enabled()->set_guest_mode_enabled(true);
RefreshDevicePolicyAndWaitForSettingChange(
chromeos::kAccountsPrefAllowGuest);
SetGuestModePolicy(true);
EXPECT_TRUE(ash::LoginScreenTestApi::IsGuestButtonShown()); EXPECT_TRUE(ash::LoginScreenTestApi::IsGuestButtonShown());
}
} }
IN_PROC_BROWSER_TEST_F(LoginScreenGuestButtonPolicy, HasUsers) { IN_PROC_BROWSER_TEST_F(LoginScreenGuestButtonPolicyTest, HasUsers) {
WaitForLoginScreen(); OobeScreenWaiter(GaiaView::kScreenId).Wait();
// Default.
EXPECT_TRUE(ash::LoginScreenTestApi::IsGuestButtonShown()); EXPECT_TRUE(ash::LoginScreenTestApi::IsGuestButtonShown());
ash::LoginScreen::Get()->GetModel()->SetUserList({{}}); ash::LoginScreen::Get()->GetModel()->SetUserList({{}});
...@@ -212,7 +150,6 @@ class LoginScreenLocalePolicyTestBase : public LoginScreenPolicyTest { ...@@ -212,7 +150,6 @@ class LoginScreenLocalePolicyTestBase : public LoginScreenPolicyTest {
void SetUpInProcessBrowserTestFixture() override { void SetUpInProcessBrowserTestFixture() override {
LoginScreenPolicyTest::SetUpInProcessBrowserTestFixture(); LoginScreenPolicyTest::SetUpInProcessBrowserTestFixture();
em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
proto.mutable_login_screen_locales()->add_login_screen_locales(locale_); proto.mutable_login_screen_locales()->add_login_screen_locales(locale_);
RefreshDevicePolicy(); RefreshDevicePolicy();
...@@ -231,24 +168,12 @@ class LoginScreenLocalePolicyTest : public LoginScreenLocalePolicyTestBase { ...@@ -231,24 +168,12 @@ class LoginScreenLocalePolicyTest : public LoginScreenLocalePolicyTestBase {
}; };
IN_PROC_BROWSER_TEST_F(LoginScreenLocalePolicyTest, IN_PROC_BROWSER_TEST_F(LoginScreenLocalePolicyTest,
DISABLED_PRE_LoginLocaleEnforcedByPolicy) { LoginLocaleEnforcedByPolicy) {
chromeos::StartupUtils::MarkOobeCompleted();
}
IN_PROC_BROWSER_TEST_F(LoginScreenLocalePolicyTest,
DISABLED_LoginLocaleEnforcedByPolicy) {
// Verifies that the default locale can be overridden with policy. // Verifies that the default locale can be overridden with policy.
EXPECT_EQ("fr", g_browser_process->GetApplicationLocale()); EXPECT_EQ("fr", g_browser_process->GetApplicationLocale());
base::string16 french_title =
l10n_util::GetStringUTF16(IDS_LOGIN_POD_SIGNING_IN); // TODO(https://crbug.com/1071010) Implement dynamic locale reload on policy
// change.
// Make sure this is really French and differs from the English title.
std::string loaded =
ui::ResourceBundle::GetSharedInstance().ReloadLocaleResources("en-US");
EXPECT_EQ("en-US", loaded);
base::string16 english_title =
l10n_util::GetStringUTF16(IDS_LOGIN_POD_SIGNING_IN);
EXPECT_NE(french_title, english_title);
} }
class LoginScreenButtonsLocalePolicy : public LoginScreenLocalePolicyTestBase { class LoginScreenButtonsLocalePolicy : public LoginScreenLocalePolicyTestBase {
......
...@@ -14,9 +14,11 @@ ...@@ -14,9 +14,11 @@
#include "chrome/browser/chromeos/login/login_manager_test.h" #include "chrome/browser/chromeos/login/login_manager_test.h"
#include "chrome/browser/chromeos/login/startup_utils.h" #include "chrome/browser/chromeos/login/startup_utils.h"
#include "chrome/browser/chromeos/login/test/js_checker.h" #include "chrome/browser/chromeos/login/test/js_checker.h"
#include "chrome/browser/chromeos/login/test/login_manager_mixin.h"
#include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h" #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h"
#include "chrome/browser/chromeos/login/ui/login_display_host.h" #include "chrome/browser/chromeos/login/ui/login_display_host.h"
#include "chrome/browser/chromeos/login/ui/user_adding_screen.h" #include "chrome/browser/chromeos/login/ui/user_adding_screen.h"
#include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h"
#include "chrome/browser/chromeos/settings/scoped_testing_cros_settings.h" #include "chrome/browser/chromeos/settings/scoped_testing_cros_settings.h"
#include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h"
#include "chrome/browser/ui/webui/chromeos/login/gaia_screen_handler.h" #include "chrome/browser/ui/webui/chromeos/login/gaia_screen_handler.h"
...@@ -25,6 +27,8 @@ ...@@ -25,6 +27,8 @@
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "content/public/test/test_utils.h" #include "content/public/test/test_utils.h"
namespace em = enterprise_management;
namespace chromeos { namespace chromeos {
namespace { namespace {
...@@ -317,4 +321,57 @@ IN_PROC_BROWSER_TEST_F(LoginUIKeyboardTestWithUsersAndOwner, ...@@ -317,4 +321,57 @@ IN_PROC_BROWSER_TEST_F(LoginUIKeyboardTestWithUsersAndOwner,
->GetActiveIMEState() ->GetActiveIMEState()
->GetActiveInputMethodIds()); ->GetActiveInputMethodIds());
} }
class LoginUIKeyboardPolicy : public policy::DevicePolicyCrosBrowserTest {
protected:
LoginManagerMixin login_manager_{&mixin_host_};
};
IN_PROC_BROWSER_TEST_F(LoginUIKeyboardPolicy, RestrictInputMethods) {
input_method::InputMethodManager* imm =
input_method::InputMethodManager::Get();
ASSERT_TRUE(imm);
ASSERT_EQ(imm->GetActiveIMEState()->GetAllowedInputMethods().size(), 0U);
std::vector<std::string> expected_input_methods;
Append_en_US_InputMethods(&expected_input_methods);
EXPECT_EQ(input_method::InputMethodManager::Get()
->GetActiveIMEState()
->GetActiveInputMethodIds(),
expected_input_methods);
std::vector<std::string> allowed_input_method{"xkb:de::ger"};
em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
proto.mutable_login_screen_input_methods()->add_login_screen_input_methods(
allowed_input_method.front());
policy_helper()->RefreshPolicyAndWaitUntilDeviceSettingsUpdated(
{chromeos::kDeviceLoginScreenInputMethods});
ASSERT_EQ(imm->GetActiveIMEState()->GetAllowedInputMethods().size(), 1U);
ASSERT_EQ(imm->GetActiveIMEState()->GetNumActiveInputMethods(), 1U);
chromeos::input_method::InputMethodManager::Get()->MigrateInputMethods(
&allowed_input_method);
ASSERT_EQ(imm->GetActiveIMEState()->GetCurrentInputMethod().id(),
allowed_input_method.front());
// The policy method stored to language_prefs::kPreferredKeyboardLayout. So
// it will be there after the policy is gone.
expected_input_methods.insert(
expected_input_methods.begin(),
imm->GetActiveIMEState()->GetActiveInputMethodIds()[0]);
// Remove the policy again
proto.mutable_login_screen_input_methods()
->clear_login_screen_input_methods();
policy_helper()->RefreshPolicyAndWaitUntilDeviceSettingsUpdated(
{chromeos::kDeviceLoginScreenInputMethods});
ASSERT_EQ(imm->GetActiveIMEState()->GetAllowedInputMethods().size(), 0U);
ASSERT_EQ(expected_input_methods, input_method::InputMethodManager::Get()
->GetActiveIMEState()
->GetActiveInputMethodIds());
}
} // namespace chromeos } // namespace chromeos
...@@ -373,7 +373,16 @@ class UserSelectionScreen::DircryptoMigrationChecker { ...@@ -373,7 +373,16 @@ class UserSelectionScreen::DircryptoMigrationChecker {
UserSelectionScreen::UserSelectionScreen(const std::string& display_type) UserSelectionScreen::UserSelectionScreen(const std::string& display_type)
: BaseScreen(UserBoardView::kScreenId, OobeScreenPriority::DEFAULT), : BaseScreen(UserBoardView::kScreenId, OobeScreenPriority::DEFAULT),
display_type_(display_type) {} display_type_(display_type) {
if (display_type_ != OobeUI::kLoginDisplay)
return;
allowed_input_methods_subscription_ =
CrosSettings::Get()->AddSettingsObserver(
kDeviceLoginScreenInputMethods,
base::Bind(&UserSelectionScreen::OnAllowedInputMethodsChanged,
base::Unretained(this)));
OnAllowedInputMethodsChanged();
}
UserSelectionScreen::~UserSelectionScreen() { UserSelectionScreen::~UserSelectionScreen() {
proximity_auth::ScreenlockBridge::Get()->SetLockHandler(nullptr); proximity_auth::ScreenlockBridge::Get()->SetLockHandler(nullptr);
...@@ -671,8 +680,9 @@ void UserSelectionScreen::HandleFocusPod(const AccountId& account_id) { ...@@ -671,8 +680,9 @@ void UserSelectionScreen::HandleFocusPod(const AccountId& account_id) {
if (focused_pod_account_id_ == account_id) if (focused_pod_account_id_ == account_id)
return; return;
CheckUserStatus(account_id); CheckUserStatus(account_id);
lock_screen_utils::SetUserInputMethod(account_id.GetUserEmail(), lock_screen_utils::SetUserInputMethod(
ime_state_.get()); account_id.GetUserEmail(), ime_state_.get(),
display_type_ == OobeUI::kLoginDisplay /* honor_device_policy */);
lock_screen_utils::SetKeyboardSettings(account_id); lock_screen_utils::SetKeyboardSettings(account_id);
bool use_24hour_clock = false; bool use_24hour_clock = false;
...@@ -688,16 +698,18 @@ void UserSelectionScreen::HandleFocusPod(const AccountId& account_id) { ...@@ -688,16 +698,18 @@ void UserSelectionScreen::HandleFocusPod(const AccountId& account_id) {
void UserSelectionScreen::HandleNoPodFocused() { void UserSelectionScreen::HandleNoPodFocused() {
focused_pod_account_id_ = EmptyAccountId(); focused_pod_account_id_ = EmptyAccountId();
lock_screen_utils::EnforcePolicyInputMethods(std::string()); if (display_type_ == OobeUI::kLoginDisplay)
lock_screen_utils::EnforceDevicePolicyInputMethods(std::string());
} }
void UserSelectionScreen::OnAllowedInputMethodsChanged() { void UserSelectionScreen::OnAllowedInputMethodsChanged() {
DCHECK_EQ(display_type_, OobeUI::kLoginDisplay);
if (focused_pod_account_id_.is_valid()) { if (focused_pod_account_id_.is_valid()) {
std::string user_input_method = lock_screen_utils::GetUserLastInputMethod( std::string user_input_method = lock_screen_utils::GetUserLastInputMethod(
focused_pod_account_id_.GetUserEmail()); focused_pod_account_id_.GetUserEmail());
lock_screen_utils::EnforcePolicyInputMethods(user_input_method); lock_screen_utils::EnforceDevicePolicyInputMethods(user_input_method);
} else { } else {
lock_screen_utils::EnforcePolicyInputMethods(std::string()); lock_screen_utils::EnforceDevicePolicyInputMethods(std::string());
} }
} }
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "chrome/browser/chromeos/login/screens/base_screen.h" #include "chrome/browser/chromeos/login/screens/base_screen.h"
#include "chrome/browser/chromeos/login/signin/token_handle_util.h" #include "chrome/browser/chromeos/login/signin/token_handle_util.h"
#include "chrome/browser/chromeos/login/ui/login_display.h" #include "chrome/browser/chromeos/login/ui/login_display.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chromeos/components/proximity_auth/screenlock_bridge.h" #include "chromeos/components/proximity_auth/screenlock_bridge.h"
#include "components/account_id/account_id.h" #include "components/account_id/account_id.h"
#include "components/user_manager/user.h" #include "components/user_manager/user.h"
...@@ -61,7 +62,6 @@ class UserSelectionScreen ...@@ -61,7 +62,6 @@ class UserSelectionScreen
void CheckUserStatus(const AccountId& account_id); void CheckUserStatus(const AccountId& account_id);
void HandleFocusPod(const AccountId& account_id); void HandleFocusPod(const AccountId& account_id);
void HandleNoPodFocused(); void HandleNoPodFocused();
void OnAllowedInputMethodsChanged();
void OnBeforeShow(); void OnBeforeShow();
// Build list of users and send it to the webui. // Build list of users and send it to the webui.
...@@ -145,6 +145,7 @@ class UserSelectionScreen ...@@ -145,6 +145,7 @@ class UserSelectionScreen
void OnUserStatusChecked(const AccountId& account_id, void OnUserStatusChecked(const AccountId& account_id,
TokenHandleUtil::TokenHandleStatus status); TokenHandleUtil::TokenHandleStatus status);
void OnAllowedInputMethodsChanged();
LoginDisplayWebUIHandler* handler_ = nullptr; LoginDisplayWebUIHandler* handler_ = nullptr;
...@@ -173,6 +174,9 @@ class UserSelectionScreen ...@@ -173,6 +174,9 @@ class UserSelectionScreen
// Input Method Engine state used at the user selection screen. // Input Method Engine state used at the user selection screen.
scoped_refptr<input_method::InputMethodManager::State> ime_state_; scoped_refptr<input_method::InputMethodManager::State> ime_state_;
std::unique_ptr<CrosSettings::ObserverSubscription>
allowed_input_methods_subscription_;
base::WeakPtrFactory<UserSelectionScreen> weak_factory_{this}; base::WeakPtrFactory<UserSelectionScreen> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(UserSelectionScreen); DISALLOW_COPY_AND_ASSIGN(UserSelectionScreen);
......
...@@ -1143,7 +1143,7 @@ void GaiaScreenHandler::HandleSecurityTokenPinEntered( ...@@ -1143,7 +1143,7 @@ void GaiaScreenHandler::HandleSecurityTokenPinEntered(
void GaiaScreenHandler::OnShowAddUser() { void GaiaScreenHandler::OnShowAddUser() {
signin_screen_handler_->is_account_picker_showing_first_time_ = false; signin_screen_handler_->is_account_picker_showing_first_time_ = false;
lock_screen_utils::EnforcePolicyInputMethods(std::string()); lock_screen_utils::EnforceDevicePolicyInputMethods(std::string());
ShowGaiaAsync(EmptyAccountId()); ShowGaiaAsync(EmptyAccountId());
} }
...@@ -1405,8 +1405,8 @@ void GaiaScreenHandler::ShowGaiaScreenIfReady() { ...@@ -1405,8 +1405,8 @@ void GaiaScreenHandler::ShowGaiaScreenIfReady() {
// Set Least Recently Used input method for the user. // Set Least Recently Used input method for the user.
if (!populated_email_.empty()) { if (!populated_email_.empty()) {
lock_screen_utils::SetUserInputMethod(populated_email_, lock_screen_utils::SetUserInputMethod(
gaia_ime_state.get()); populated_email_, gaia_ime_state.get(), true /*honor_device_policy*/);
} else { } else {
std::vector<std::string> input_methods; std::vector<std::string> input_methods;
if (gaia_ime_state->GetAllowedInputMethods().empty()) { if (gaia_ime_state->GetAllowedInputMethods().empty()) {
......
...@@ -259,11 +259,6 @@ SigninScreenHandler::SigninScreenHandler( ...@@ -259,11 +259,6 @@ SigninScreenHandler::SigninScreenHandler(
chromeos::input_method::InputMethodManager::Get()->GetImeKeyboard(); chromeos::input_method::InputMethodManager::Get()->GetImeKeyboard();
if (keyboard) if (keyboard)
keyboard->AddObserver(this); keyboard->AddObserver(this);
allowed_input_methods_subscription_ =
chromeos::CrosSettings::Get()->AddSettingsObserver(
chromeos::kDeviceLoginScreenInputMethods,
base::Bind(&SigninScreenHandler::OnAllowedInputMethodsChanged,
base::Unretained(this)));
ash::TabletMode* tablet_mode = ash::TabletMode::Get(); ash::TabletMode* tablet_mode = ash::TabletMode::Get();
tablet_mode->AddObserver(this); tablet_mode->AddObserver(this);
...@@ -1253,7 +1248,6 @@ void SigninScreenHandler::HandleLoginVisible(const std::string& source) { ...@@ -1253,7 +1248,6 @@ void SigninScreenHandler::HandleLoginVisible(const std::string& source) {
webui_visible_ = true; webui_visible_ = true;
if (preferences_changed_delayed_) if (preferences_changed_delayed_)
OnPreferencesChanged(); OnPreferencesChanged();
OnAllowedInputMethodsChanged();
} }
void SigninScreenHandler::HandleCancelPasswordChangedFlow( void SigninScreenHandler::HandleCancelPasswordChangedFlow(
...@@ -1337,8 +1331,12 @@ void SigninScreenHandler::HandleFocusPod(const AccountId& account_id, ...@@ -1337,8 +1331,12 @@ void SigninScreenHandler::HandleFocusPod(const AccountId& account_id,
if (is_same_pod_focused) if (is_same_pod_focused)
return; return;
// TODO(https://crbug.com/1071779): Migrate KioskTest to Views Account picker.
// DCHECK_EQ(session_manager::SessionManager::Get()->session_state(),
// session_manager::SessionState::LOGIN_SECONDARY);
lock_screen_utils::SetUserInputMethod(account_id.GetUserEmail(), lock_screen_utils::SetUserInputMethod(account_id.GetUserEmail(),
ime_state_.get()); ime_state_.get(),
false /*honor_device_policy*/);
lock_screen_utils::SetKeyboardSettings(account_id); lock_screen_utils::SetKeyboardSettings(account_id);
bool use_24hour_clock = false; bool use_24hour_clock = false;
...@@ -1353,7 +1351,6 @@ void SigninScreenHandler::HandleFocusPod(const AccountId& account_id, ...@@ -1353,7 +1351,6 @@ void SigninScreenHandler::HandleFocusPod(const AccountId& account_id,
void SigninScreenHandler::HandleNoPodFocused() { void SigninScreenHandler::HandleNoPodFocused() {
focused_pod_account_id_.reset(); focused_pod_account_id_.reset();
lock_screen_utils::EnforcePolicyInputMethods(std::string());
} }
void SigninScreenHandler::HandleGetPublicSessionKeyboardLayouts( void SigninScreenHandler::HandleGetPublicSessionKeyboardLayouts(
...@@ -1473,17 +1470,4 @@ void SigninScreenHandler::OnFeedbackFinished() { ...@@ -1473,17 +1470,4 @@ void SigninScreenHandler::OnFeedbackFinished() {
login_feedback_.reset(); login_feedback_.reset();
} }
void SigninScreenHandler::OnAllowedInputMethodsChanged() {
if (!webui_visible_)
return;
if (focused_pod_account_id_) {
std::string user_input_method = lock_screen_utils::GetUserLastInputMethod(
focused_pod_account_id_->GetUserEmail());
lock_screen_utils::EnforcePolicyInputMethods(user_input_method);
} else {
lock_screen_utils::EnforcePolicyInputMethods(std::string());
}
}
} // namespace chromeos } // namespace chromeos
...@@ -399,9 +399,6 @@ class SigninScreenHandler ...@@ -399,9 +399,6 @@ class SigninScreenHandler
// Callback invoked after the feedback is finished. // Callback invoked after the feedback is finished.
void OnFeedbackFinished(); void OnFeedbackFinished();
// Called when the cros property controlling allowed input methods changes.
void OnAllowedInputMethodsChanged();
// After proxy auth information has been supplied, this function re-enables // After proxy auth information has been supplied, this function re-enables
// responding to network state notifications. // responding to network state notifications.
void ReenableNetworkStateUpdatesAfterProxyAuth(); void ReenableNetworkStateUpdatesAfterProxyAuth();
...@@ -442,9 +439,6 @@ class SigninScreenHandler ...@@ -442,9 +439,6 @@ class SigninScreenHandler
content::NotificationRegistrar registrar_; content::NotificationRegistrar registrar_;
std::unique_ptr<CrosSettings::ObserverSubscription>
allowed_input_methods_subscription_;
// Whether we're currently ignoring network state updates because a proxy auth // Whether we're currently ignoring network state updates because a proxy auth
// UI pending (or we're waiting for a grace period after the proxy auth UI is // UI pending (or we're waiting for a grace period after the proxy auth UI is
// finished for the network to switch into the ONLINE state). // finished for the network to switch into the ONLINE state).
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment