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

Unified Diff: chrome/browser/chromeos/input_method/input_method_manager_impl.cc

Issue 2652793003: Add login screen locale and input method device policies (Closed)
Patch Set: Rebase. Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/input_method/input_method_manager_impl.cc
diff --git a/chrome/browser/chromeos/input_method/input_method_manager_impl.cc b/chrome/browser/chromeos/input_method/input_method_manager_impl.cc
index 9cd43a2b523a1f04aa076724b6220f5141ca4edf..c9d7ab0c233d6e8ff7fa02f77f9a246caef43aec 100644
--- a/chrome/browser/chromeos/input_method/input_method_manager_impl.cc
+++ b/chrome/browser/chromeos/input_method/input_method_manager_impl.cc
@@ -130,6 +130,8 @@ void InputMethodManagerImpl::StateImpl::InitFrom(const StateImpl& other) {
enabled_extension_imes = other.enabled_extension_imes;
extra_input_methods = other.extra_input_methods;
menu_activated = other.menu_activated;
+ allowed_keyboard_layout_input_method_ids =
+ other.allowed_keyboard_layout_input_method_ids;
}
bool InputMethodManagerImpl::StateImpl::IsActive() const {
@@ -255,7 +257,12 @@ void InputMethodManagerImpl::StateImpl::EnableLoginLayouts(
for (size_t i = 0; i < initial_layouts.size(); ++i) {
if (manager_->util_.IsValidInputMethodId(initial_layouts[i])) {
if (manager_->IsLoginKeyboard(initial_layouts[i])) {
- layouts.push_back(initial_layouts[i]);
+ if (IsInputMethodAllowed(initial_layouts[i])) {
+ layouts.push_back(initial_layouts[i]);
+ } else {
+ DVLOG(1) << "EnableLoginLayouts: ignoring layout disallowd by policy:"
+ << initial_layouts[i];
+ }
} else {
DVLOG(1)
<< "EnableLoginLayouts: ignoring non-login initial keyboard layout:"
@@ -272,8 +279,10 @@ void InputMethodManagerImpl::StateImpl::EnableLoginLayouts(
const std::string& candidate = candidates[i];
// Not efficient, but should be fine, as the two vectors are very
// short (2-5 items).
- if (!Contains(layouts, candidate) && manager_->IsLoginKeyboard(candidate))
+ if (!Contains(layouts, candidate) && manager_->IsLoginKeyboard(candidate) &&
+ IsInputMethodAllowed(candidate)) {
layouts.push_back(candidate);
+ }
}
manager_->MigrateInputMethods(&layouts);
@@ -334,6 +343,11 @@ void InputMethodManagerImpl::StateImpl::EnableLockScreenLayouts() {
bool InputMethodManagerImpl::StateImpl::EnableInputMethodImpl(
const std::string& input_method_id,
std::vector<std::string>* new_active_input_method_ids) const {
+ if (!IsInputMethodAllowed(input_method_id)) {
+ DVLOG(1) << "EnableInputMethod: " << input_method_id << " is not allowed.";
+ return false;
+ }
+
DCHECK(new_active_input_method_ids);
if (!manager_->util_.IsValidInputMethodId(input_method_id)) {
DVLOG(1) << "EnableInputMethod: Invalid ID: " << input_method_id;
@@ -395,6 +409,54 @@ bool InputMethodManagerImpl::StateImpl::ReplaceEnabledInputMethods(
return true;
}
+bool InputMethodManagerImpl::StateImpl::SetAllowedInputMethods(
+ const std::vector<std::string>& new_allowed_input_method_ids) {
+ allowed_keyboard_layout_input_method_ids.clear();
+ for (auto input_method_id : new_allowed_input_method_ids) {
+ std::string migrated_id =
+ manager_->util_.MigrateInputMethod(input_method_id);
+ if (manager_->util_.IsValidInputMethodId(migrated_id)) {
+ allowed_keyboard_layout_input_method_ids.push_back(migrated_id);
+ }
+ }
+
+ if (allowed_keyboard_layout_input_method_ids.empty()) {
+ // None of the passed input methods were valid, so allow everything.
+ return false;
+ }
+
+ // Enable all allowed keyboard layout input methods. Leave all non-keyboard
+ // input methods enabled.
+ std::vector<std::string> new_active_input_method_ids(
+ allowed_keyboard_layout_input_method_ids);
+ for (auto active_input_method_id : active_input_method_ids) {
+ if (!manager_->util_.IsKeyboardLayout(active_input_method_id))
+ new_active_input_method_ids.push_back(active_input_method_id);
+ }
+ return ReplaceEnabledInputMethods(new_active_input_method_ids);
+}
+
+const std::vector<std::string>&
+InputMethodManagerImpl::StateImpl::GetAllowedInputMethods() {
+ return allowed_keyboard_layout_input_method_ids;
+}
+
+bool InputMethodManagerImpl::StateImpl::IsInputMethodAllowed(
+ const std::string& input_method_id) const {
+ // Every input method is allowed if SetAllowedKeyboardLayoutInputMethods has
+ // not been called.
+ if (allowed_keyboard_layout_input_method_ids.empty())
+ return true;
+
+ // We only restrict keyboard layouts.
+ if (!manager_->util_.IsKeyboardLayout(input_method_id))
+ return true;
+
+ return Contains(allowed_keyboard_layout_input_method_ids, input_method_id) ||
+ Contains(allowed_keyboard_layout_input_method_ids,
+ manager_->util_.MigrateInputMethod(input_method_id));
+}
+
void InputMethodManagerImpl::StateImpl::ChangeInputMethod(
const std::string& input_method_id,
bool show_message) {

Powered by Google App Engine
This is Rietveld 408576698