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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/input_method/input_method_manager_impl.h" 5 #include "chrome/browser/chromeos/input_method/input_method_manager_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> // std::find 9 #include <algorithm> // std::find
10 #include <memory> 10 #include <memory>
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 previous_input_method = other.previous_input_method; 123 previous_input_method = other.previous_input_method;
124 current_input_method = other.current_input_method; 124 current_input_method = other.current_input_method;
125 125
126 active_input_method_ids = other.active_input_method_ids; 126 active_input_method_ids = other.active_input_method_ids;
127 127
128 pending_input_method_id = other.pending_input_method_id; 128 pending_input_method_id = other.pending_input_method_id;
129 129
130 enabled_extension_imes = other.enabled_extension_imes; 130 enabled_extension_imes = other.enabled_extension_imes;
131 extra_input_methods = other.extra_input_methods; 131 extra_input_methods = other.extra_input_methods;
132 menu_activated = other.menu_activated; 132 menu_activated = other.menu_activated;
133 allowed_keyboard_layout_input_method_ids =
134 other.allowed_keyboard_layout_input_method_ids;
133 } 135 }
134 136
135 bool InputMethodManagerImpl::StateImpl::IsActive() const { 137 bool InputMethodManagerImpl::StateImpl::IsActive() const {
136 return manager_->state_.get() == this; 138 return manager_->state_.get() == this;
137 } 139 }
138 140
139 std::string InputMethodManagerImpl::StateImpl::Dump() const { 141 std::string InputMethodManagerImpl::StateImpl::Dump() const {
140 std::ostringstream os; 142 std::ostringstream os;
141 143
142 os << "################# " 144 os << "################# "
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 candidates.insert(candidates.end(), layouts_from_locale.begin(), 250 candidates.insert(candidates.end(), layouts_from_locale.begin(),
249 layouts_from_locale.end()); 251 layouts_from_locale.end());
250 252
251 std::vector<std::string> layouts; 253 std::vector<std::string> layouts;
252 // First, add the initial input method ID, if it's requested, to 254 // First, add the initial input method ID, if it's requested, to
253 // layouts, so it appears first on the list of active input 255 // layouts, so it appears first on the list of active input
254 // methods at the input language status menu. 256 // methods at the input language status menu.
255 for (size_t i = 0; i < initial_layouts.size(); ++i) { 257 for (size_t i = 0; i < initial_layouts.size(); ++i) {
256 if (manager_->util_.IsValidInputMethodId(initial_layouts[i])) { 258 if (manager_->util_.IsValidInputMethodId(initial_layouts[i])) {
257 if (manager_->IsLoginKeyboard(initial_layouts[i])) { 259 if (manager_->IsLoginKeyboard(initial_layouts[i])) {
258 layouts.push_back(initial_layouts[i]); 260 if (IsInputMethodAllowed(initial_layouts[i])) {
261 layouts.push_back(initial_layouts[i]);
262 } else {
263 DVLOG(1) << "EnableLoginLayouts: ignoring layout disallowd by policy:"
264 << initial_layouts[i];
265 }
259 } else { 266 } else {
260 DVLOG(1) 267 DVLOG(1)
261 << "EnableLoginLayouts: ignoring non-login initial keyboard layout:" 268 << "EnableLoginLayouts: ignoring non-login initial keyboard layout:"
262 << initial_layouts[i]; 269 << initial_layouts[i];
263 } 270 }
264 } else if (!initial_layouts[i].empty()) { 271 } else if (!initial_layouts[i].empty()) {
265 DVLOG(1) << "EnableLoginLayouts: ignoring non-keyboard or invalid ID: " 272 DVLOG(1) << "EnableLoginLayouts: ignoring non-keyboard or invalid ID: "
266 << initial_layouts[i]; 273 << initial_layouts[i];
267 } 274 }
268 } 275 }
269 276
270 // Add candidates to layouts, while skipping duplicates. 277 // Add candidates to layouts, while skipping duplicates.
271 for (size_t i = 0; i < candidates.size(); ++i) { 278 for (size_t i = 0; i < candidates.size(); ++i) {
272 const std::string& candidate = candidates[i]; 279 const std::string& candidate = candidates[i];
273 // Not efficient, but should be fine, as the two vectors are very 280 // Not efficient, but should be fine, as the two vectors are very
274 // short (2-5 items). 281 // short (2-5 items).
275 if (!Contains(layouts, candidate) && manager_->IsLoginKeyboard(candidate)) 282 if (!Contains(layouts, candidate) && manager_->IsLoginKeyboard(candidate) &&
283 IsInputMethodAllowed(candidate)) {
276 layouts.push_back(candidate); 284 layouts.push_back(candidate);
285 }
277 } 286 }
278 287
279 manager_->MigrateInputMethods(&layouts); 288 manager_->MigrateInputMethods(&layouts);
280 active_input_method_ids.swap(layouts); 289 active_input_method_ids.swap(layouts);
281 290
282 if (IsActive()) { 291 if (IsActive()) {
283 // Initialize candidate window controller and widgets such as 292 // Initialize candidate window controller and widgets such as
284 // candidate window, infolist and mode indicator. Note, mode 293 // candidate window, infolist and mode indicator. Note, mode
285 // indicator is used by only keyboard layout input methods. 294 // indicator is used by only keyboard layout input methods.
286 if (active_input_method_ids.size() > 1) 295 if (active_input_method_ids.size() > 1)
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 active_input_method_ids.swap(new_active_input_method_ids); 336 active_input_method_ids.swap(new_active_input_method_ids);
328 337
329 // Re-check current_input_method. 338 // Re-check current_input_method.
330 ChangeInputMethod(current_input_method.id(), false); 339 ChangeInputMethod(current_input_method.id(), false);
331 } 340 }
332 341
333 // Adds new input method to given list. 342 // Adds new input method to given list.
334 bool InputMethodManagerImpl::StateImpl::EnableInputMethodImpl( 343 bool InputMethodManagerImpl::StateImpl::EnableInputMethodImpl(
335 const std::string& input_method_id, 344 const std::string& input_method_id,
336 std::vector<std::string>* new_active_input_method_ids) const { 345 std::vector<std::string>* new_active_input_method_ids) const {
346 if (!IsInputMethodAllowed(input_method_id)) {
347 DVLOG(1) << "EnableInputMethod: " << input_method_id << " is not allowed.";
348 return false;
349 }
350
337 DCHECK(new_active_input_method_ids); 351 DCHECK(new_active_input_method_ids);
338 if (!manager_->util_.IsValidInputMethodId(input_method_id)) { 352 if (!manager_->util_.IsValidInputMethodId(input_method_id)) {
339 DVLOG(1) << "EnableInputMethod: Invalid ID: " << input_method_id; 353 DVLOG(1) << "EnableInputMethod: Invalid ID: " << input_method_id;
340 return false; 354 return false;
341 } 355 }
342 356
343 if (!Contains(*new_active_input_method_ids, input_method_id)) 357 if (!Contains(*new_active_input_method_ids, input_method_id))
344 new_active_input_method_ids->push_back(input_method_id); 358 new_active_input_method_ids->push_back(input_method_id);
345 359
346 return true; 360 return true;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 // ChangeInputMethod() picks the first one in |active_input_method_ids|. 402 // ChangeInputMethod() picks the first one in |active_input_method_ids|.
389 ChangeInputMethod(current_input_method.id(), false); 403 ChangeInputMethod(current_input_method.id(), false);
390 404
391 // Record histogram for active input method count. 405 // Record histogram for active input method count.
392 UMA_HISTOGRAM_COUNTS("InputMethod.ActiveCount", 406 UMA_HISTOGRAM_COUNTS("InputMethod.ActiveCount",
393 active_input_method_ids.size()); 407 active_input_method_ids.size());
394 408
395 return true; 409 return true;
396 } 410 }
397 411
412 bool InputMethodManagerImpl::StateImpl::SetAllowedInputMethods(
413 const std::vector<std::string>& new_allowed_input_method_ids) {
414 allowed_keyboard_layout_input_method_ids.clear();
415 for (auto input_method_id : new_allowed_input_method_ids) {
416 std::string migrated_id =
417 manager_->util_.MigrateInputMethod(input_method_id);
418 if (manager_->util_.IsValidInputMethodId(migrated_id)) {
419 allowed_keyboard_layout_input_method_ids.push_back(migrated_id);
420 }
421 }
422
423 if (allowed_keyboard_layout_input_method_ids.empty()) {
424 // None of the passed input methods were valid, so allow everything.
425 return false;
426 }
427
428 // Enable all allowed keyboard layout input methods. Leave all non-keyboard
429 // input methods enabled.
430 std::vector<std::string> new_active_input_method_ids(
431 allowed_keyboard_layout_input_method_ids);
432 for (auto active_input_method_id : active_input_method_ids) {
433 if (!manager_->util_.IsKeyboardLayout(active_input_method_id))
434 new_active_input_method_ids.push_back(active_input_method_id);
435 }
436 return ReplaceEnabledInputMethods(new_active_input_method_ids);
437 }
438
439 const std::vector<std::string>&
440 InputMethodManagerImpl::StateImpl::GetAllowedInputMethods() {
441 return allowed_keyboard_layout_input_method_ids;
442 }
443
444 bool InputMethodManagerImpl::StateImpl::IsInputMethodAllowed(
445 const std::string& input_method_id) const {
446 // Every input method is allowed if SetAllowedKeyboardLayoutInputMethods has
447 // not been called.
448 if (allowed_keyboard_layout_input_method_ids.empty())
449 return true;
450
451 // We only restrict keyboard layouts.
452 if (!manager_->util_.IsKeyboardLayout(input_method_id))
453 return true;
454
455 return Contains(allowed_keyboard_layout_input_method_ids, input_method_id) ||
456 Contains(allowed_keyboard_layout_input_method_ids,
457 manager_->util_.MigrateInputMethod(input_method_id));
458 }
459
398 void InputMethodManagerImpl::StateImpl::ChangeInputMethod( 460 void InputMethodManagerImpl::StateImpl::ChangeInputMethod(
399 const std::string& input_method_id, 461 const std::string& input_method_id,
400 bool show_message) { 462 bool show_message) {
401 if (manager_->ui_session_ == STATE_TERMINATING) 463 if (manager_->ui_session_ == STATE_TERMINATING)
402 return; 464 return;
403 465
404 bool notify_menu = false; 466 bool notify_menu = false;
405 467
406 // Always lookup input method, even if it is the same as 468 // Always lookup input method, even if it is the same as
407 // |current_input_method| because If it is no longer in 469 // |current_input_method| because If it is no longer in
(...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after
1265 if (keyboard_controller) 1327 if (keyboard_controller)
1266 keyboard_controller->Reload(); 1328 keyboard_controller->Reload();
1267 } 1329 }
1268 1330
1269 bool InputMethodManagerImpl::IsEmojiHandwritingVoiceOnImeMenuEnabled() { 1331 bool InputMethodManagerImpl::IsEmojiHandwritingVoiceOnImeMenuEnabled() {
1270 return base::FeatureList::IsEnabled(features::kEHVInputOnImeMenu); 1332 return base::FeatureList::IsEnabled(features::kEHVInputOnImeMenu);
1271 } 1333 }
1272 1334
1273 } // namespace input_method 1335 } // namespace input_method
1274 } // namespace chromeos 1336 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698