Commit f9affb12 authored by Sarah Hu's avatar Sarah Hu Committed by Commit Bot

Mojo api for requesting keyboard layouts for public account user.

The requested keyboard layouts will be used in public session UI to
populate a selection menu. (In a follow-up CL)

Bug: 809635
Change-Id: I1154647d4bfdf3637ec37033f4452742c71ec377
Reviewed-on: https://chromium-review.googlesource.com/1020664Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarAchuith Bhandarkar <achuith@chromium.org>
Commit-Queue: Xiaoyin Hu <xiaoyinh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#554517}
parent f5eeeb71
......@@ -221,6 +221,14 @@ void LoginScreenController::LaunchPublicSession(
login_screen_client_->LaunchPublicSession(account_id, locale, input_method);
}
void LoginScreenController::RequestPublicSessionKeyboardLayouts(
const AccountId& account_id,
const std::string& locale) {
if (!login_screen_client_)
return;
login_screen_client_->RequestPublicSessionKeyboardLayouts(account_id, locale);
}
void LoginScreenController::AddObserver(
LoginScreenControllerObserver* observer) {
observers_.AddObserver(observer);
......@@ -361,6 +369,16 @@ void LoginScreenController::SetPublicSessionLocales(
}
}
void LoginScreenController::SetPublicSessionKeyboardLayouts(
const AccountId& account_id,
const std::string& locale,
std::vector<mojom::InputMethodItemPtr> keyboard_layouts) {
if (DataDispatcher()) {
DataDispatcher()->SetPublicSessionKeyboardLayouts(account_id, locale,
keyboard_layouts);
}
}
void LoginScreenController::DoAuthenticateUser(const AccountId& account_id,
const std::string& password,
bool authenticated_by_pin,
......
......@@ -74,6 +74,8 @@ class ASH_EXPORT LoginScreenController : public mojom::LoginScreen {
void LaunchPublicSession(const AccountId& account_id,
const std::string& locale,
const std::string& input_method);
void RequestPublicSessionKeyboardLayouts(const AccountId& account_id,
const std::string& locale);
// Add or remove an observer.
void AddObserver(LoginScreenControllerObserver* observer);
......@@ -117,6 +119,10 @@ class ASH_EXPORT LoginScreenController : public mojom::LoginScreen {
base::Value locales,
const std::string& default_locale,
bool show_advanced_view) override;
void SetPublicSessionKeyboardLayouts(
const AccountId& account_id,
const std::string& locale,
std::vector<mojom::InputMethodItemPtr> keyboard_layouts) override;
// Flushes the mojo pipes - to be used in tests.
void FlushForTesting();
......
......@@ -65,6 +65,8 @@ class MockLoginScreenClient : public mojom::LoginScreenClient {
void(const AccountId& account_id,
const std::string& locale,
const std::string& input_method));
MOCK_METHOD2(RequestPublicSessionKeyboardLayouts,
void(const AccountId& account_id, const std::string& locale));
private:
bool authenticate_user_callback_result_ = true;
......
......@@ -556,6 +556,11 @@ void LockContentsView::OnPublicSessionLocalesChanged(
user_view->UpdateForUser(user_info, false /*animate*/);
}
void LockContentsView::OnPublicSessionKeyboardLayoutsChanged(
const AccountId& account_id,
const std::string& locale,
const std::vector<mojom::InputMethodItemPtr>& keyboard_layouts) {}
void LockContentsView::OnDetachableBasePairingStatusChanged(
DetachableBasePairingStatus pairing_status) {
const mojom::UserInfoPtr& user_info =
......
......@@ -133,6 +133,10 @@ class ASH_EXPORT LockContentsView : public NonAccessibleView,
const base::ListValue& locales,
const std::string& default_locale,
bool show_advanced_view) override;
void OnPublicSessionKeyboardLayoutsChanged(
const AccountId& account_id,
const std::string& locale,
const std::vector<mojom::InputMethodItemPtr>& keyboard_layouts) override;
void OnDetachableBasePairingStatusChanged(
DetachableBasePairingStatus pairing_status) override;
......
......@@ -264,6 +264,14 @@ class LockDebugView::DebugDataDispatcherTransformer
debug_dispatcher_.SetDetachableBasePairingStatus(pairing_status);
}
void OnPublicSessionKeyboardLayoutsChanged(
const AccountId& account_id,
const std::string& locale,
const std::vector<mojom::InputMethodItemPtr>& keyboard_layouts) override {
debug_dispatcher_.SetPublicSessionKeyboardLayouts(account_id, locale,
keyboard_layouts);
}
private:
// The debug overlay UI takes ground-truth data from |root_dispatcher_|,
// applies a series of transformations to it, and exposes it to the UI via
......
......@@ -41,6 +41,11 @@ void LoginDataDispatcher::Observer::OnPublicSessionLocalesChanged(
const std::string& default_locale,
bool show_advanced_view) {}
void LoginDataDispatcher::Observer::OnPublicSessionKeyboardLayoutsChanged(
const AccountId& account_id,
const std::string& locale,
const std::vector<mojom::InputMethodItemPtr>& keyboard_layouts) {}
void LoginDataDispatcher::Observer::OnDetachableBasePairingStatusChanged(
DetachableBasePairingStatus pairing_status) {}
......@@ -114,6 +119,16 @@ void LoginDataDispatcher::SetPublicSessionLocales(
}
}
void LoginDataDispatcher::SetPublicSessionKeyboardLayouts(
const AccountId& account_id,
const std::string& locale,
const std::vector<mojom::InputMethodItemPtr>& keyboard_layouts) {
for (auto& observer : observers_) {
observer.OnPublicSessionKeyboardLayoutsChanged(account_id, locale,
keyboard_layouts);
}
}
void LoginDataDispatcher::SetDetachableBasePairingStatus(
DetachableBasePairingStatus pairing_status) {
for (auto& observer : observers_)
......
......@@ -81,6 +81,13 @@ class ASH_EXPORT LoginDataDispatcher {
const std::string& default_locale,
bool show_advanced_view);
// Called when public session keyboard layouts are changed for user with
// |account_id|.
virtual void OnPublicSessionKeyboardLayoutsChanged(
const AccountId& account_id,
const std::string& locale,
const std::vector<mojom::InputMethodItemPtr>& keyboard_layouts);
// Called when the pairing status of detachable base changes - e.g. when the
// base is attached or detached.
virtual void OnDetachableBasePairingStatusChanged(
......@@ -108,6 +115,10 @@ class ASH_EXPORT LoginDataDispatcher {
std::unique_ptr<base::ListValue> locales,
const std::string& default_locale,
bool show_advanced_view);
void SetPublicSessionKeyboardLayouts(
const AccountId& account_id,
const std::string& locale,
const std::vector<mojom::InputMethodItemPtr>& keyboard_layouts);
void SetDetachableBasePairingStatus(
DetachableBasePairingStatus pairing_status);
......
......@@ -106,6 +106,12 @@ interface LoginScreen {
mojo_base.mojom.ListValue locales,
string default_locale,
bool show_advanced_view);
// Set the public session keyboard layouts for user with |account_id|.
// |locale|: The locale that |keyboard_layouts| can be used for.
SetPublicSessionKeyboardLayouts(signin.mojom.AccountId account_id,
string locale,
array<InputMethodItem> keyboard_layouts);
};
// Allows ash lock screen to control a client (e.g. Chrome browser). Requests
......@@ -187,4 +193,12 @@ interface LoginScreenClient {
LaunchPublicSession(signin.mojom.AccountId account_id,
string locale,
string input_method);
// Request public session keyboard layouts for user with |account_id|.
// This function send a request to chrome and the result will be returned by
// SetPublicSessionKeyboardLayouts.
// |locale|: Request a list of keyboard layouts that can be used by this
// locale.
RequestPublicSessionKeyboardLayouts(signin.mojom.AccountId account_id,
string locale);
};
......@@ -67,6 +67,20 @@ struct EasyUnlockIconOptions {
bool is_trial_run;
};
// Infomation of each input method. This is used to populate keyboard layouts
// for public account user.
struct InputMethodItem {
// An id that identifies an input method engine (e.g., "t:latn-post",
// "pinyin", "hangul").
string ime_id;
// Title of the imput method.
string title;
// Whether this input method is been selected.
bool selected;
};
// Infomation about a public account user.
struct PublicAccountInfo {
// Optional, the domain name displayed in the login screen UI.
......@@ -82,6 +96,9 @@ struct PublicAccountInfo {
// locales. This will be the case in multilingual environments where users
// are likely to want to choose among locales.
bool show_advanced_view;
// A list of available keyboard layouts.
array<InputMethodItem> keyboard_layouts;
};
// Info about a user in login/lock screen.
......
......@@ -31,6 +31,7 @@
#include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h"
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/ui/ash/login_screen_client.h"
#include "chrome/browser/ui/webui/chromeos/login/l10n_util.h"
#include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
#include "chrome/grit/generated_resources.h"
......@@ -864,6 +865,13 @@ UserSelectionScreen::UpdateAndReturnUserListForMojo() {
public_session_recommended_locales,
login_user_info.get());
login_user_info->can_remove = CanRemoveUser(*it);
// Send a request to get keyboard layouts for default locale.
if (is_public_account && LoginScreenClient::HasInstance()) {
LoginScreenClient::Get()->RequestPublicSessionKeyboardLayouts(
account_id, login_user_info->public_account_info->default_locale);
}
user_info_list.push_back(std::move(login_user_info));
}
......
......@@ -120,9 +120,6 @@ class UserSelectionScreen
const user_manager::User* user);
// Fills |user_info| with information about |user|.
// TODO: Public sesssions exist in login screen, but not lock screen.
// We will need public session locales in the future when we change login
// screen to view-based as well. See crbug.com/732452.
static void FillUserMojoStruct(
const user_manager::User* user,
bool is_owner,
......
......@@ -83,6 +83,10 @@ void UserBoardViewMojo::SetPublicSessionLocales(
LoginScreenClient::Get()->login_screen()->SetPublicSessionLocales(
account_id, std::move(*locales), default_locale,
multiple_recommended_locales);
// Send a request to get keyboard layouts for |default_locale|.
LoginScreenClient::Get()->RequestPublicSessionKeyboardLayouts(account_id,
default_locale);
}
void UserBoardViewMojo::ShowUserPodCustomIcon(
......
......@@ -13,6 +13,7 @@
#include "chrome/browser/chromeos/login/ui/user_adding_screen.h"
#include "chrome/browser/profiles/profile_metrics.h"
#include "chrome/browser/ui/ash/wallpaper_controller_client.h"
#include "chrome/browser/ui/webui/chromeos/login/l10n_util.h"
#include "components/user_manager/remove_user_delegate.h"
#include "content/public/common/service_manager_connection.h"
#include "services/service_manager/public/cpp/connector.h"
......@@ -24,7 +25,8 @@ LoginScreenClient* g_login_screen_client_instance = nullptr;
LoginScreenClient::Delegate::Delegate() = default;
LoginScreenClient::Delegate::~Delegate() = default;
LoginScreenClient::LoginScreenClient() : binding_(this) {
LoginScreenClient::LoginScreenClient()
: binding_(this), weak_ptr_factory_(this) {
content::ServiceManagerConnection::GetForProcess()
->GetConnector()
->BindInterface(ash::mojom::kServiceName, &login_screen_);
......@@ -136,6 +138,15 @@ void LoginScreenClient::LaunchPublicSession(const AccountId& account_id,
delegate_->HandleLaunchPublicSession(account_id, locale, input_method);
}
void LoginScreenClient::RequestPublicSessionKeyboardLayouts(
const AccountId& account_id,
const std::string& locale) {
chromeos::GetKeyboardLayoutsForLocale(
base::BindRepeating(&LoginScreenClient::SetPublicSessionKeyboardLayout,
weak_ptr_factory_.GetWeakPtr(), account_id, locale),
locale);
}
void LoginScreenClient::LoadWallpaper(const AccountId& account_id) {
WallpaperControllerClient::Get()->ShowUserWallpaper(account_id);
}
......@@ -158,3 +169,33 @@ void LoginScreenClient::OnMaxIncorrectPasswordAttempted(
RecordReauthReason(account_id,
chromeos::ReauthReason::INCORRECT_PASSWORD_ENTERED);
}
void LoginScreenClient::SetPublicSessionKeyboardLayout(
const AccountId& account_id,
const std::string& locale,
std::unique_ptr<base::ListValue> keyboard_layouts) {
std::vector<ash::mojom::InputMethodItemPtr> result;
for (const auto& i : *keyboard_layouts) {
const base::DictionaryValue* dictionary;
if (!i.GetAsDictionary(&dictionary))
continue;
ash::mojom::InputMethodItemPtr input_method_item =
ash::mojom::InputMethodItem::New();
std::string ime_id;
dictionary->GetString("value", &ime_id);
input_method_item->ime_id = ime_id;
std::string title;
dictionary->GetString("title", &title);
input_method_item->title = title;
bool selected;
dictionary->GetBoolean("selected", &selected);
input_method_item->selected = selected;
result.push_back(std::move(input_method_item));
}
login_screen_->SetPublicSessionKeyboardLayouts(account_id, locale,
std::move(result));
}
......@@ -82,8 +82,15 @@ class LoginScreenClient : public ash::mojom::LoginScreenClient {
void LaunchPublicSession(const AccountId& account_id,
const std::string& locale,
const std::string& input_method) override;
void RequestPublicSessionKeyboardLayouts(const AccountId& account_id,
const std::string& locale) override;
private:
void SetPublicSessionKeyboardLayout(
const AccountId& account_id,
const std::string& locale,
std::unique_ptr<base::ListValue> keyboard_layouts);
// Lock screen mojo service in ash.
ash::mojom::LoginScreenPtr login_screen_;
......@@ -91,6 +98,8 @@ class LoginScreenClient : public ash::mojom::LoginScreenClient {
mojo::Binding<ash::mojom::LoginScreenClient> binding_;
Delegate* delegate_ = nullptr;
base::WeakPtrFactory<LoginScreenClient> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(LoginScreenClient);
};
......
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