Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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)) | |
|
Shu Chen
2017/02/07 02:47:09
nit: add brackets {} for the following line.
pmarko
2017/02/07 10:44:09
Done.
| |
| 276 layouts.push_back(candidate); | 284 layouts.push_back(candidate); |
| 277 } | 285 } |
| 278 | 286 |
| 279 manager_->MigrateInputMethods(&layouts); | 287 manager_->MigrateInputMethods(&layouts); |
| 280 active_input_method_ids.swap(layouts); | 288 active_input_method_ids.swap(layouts); |
| 281 | 289 |
| 282 if (IsActive()) { | 290 if (IsActive()) { |
| 283 // Initialize candidate window controller and widgets such as | 291 // Initialize candidate window controller and widgets such as |
| 284 // candidate window, infolist and mode indicator. Note, mode | 292 // candidate window, infolist and mode indicator. Note, mode |
| 285 // indicator is used by only keyboard layout input methods. | 293 // indicator is used by only keyboard layout input methods. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 327 active_input_method_ids.swap(new_active_input_method_ids); | 335 active_input_method_ids.swap(new_active_input_method_ids); |
| 328 | 336 |
| 329 // Re-check current_input_method. | 337 // Re-check current_input_method. |
| 330 ChangeInputMethod(current_input_method.id(), false); | 338 ChangeInputMethod(current_input_method.id(), false); |
| 331 } | 339 } |
| 332 | 340 |
| 333 // Adds new input method to given list. | 341 // Adds new input method to given list. |
| 334 bool InputMethodManagerImpl::StateImpl::EnableInputMethodImpl( | 342 bool InputMethodManagerImpl::StateImpl::EnableInputMethodImpl( |
| 335 const std::string& input_method_id, | 343 const std::string& input_method_id, |
| 336 std::vector<std::string>* new_active_input_method_ids) const { | 344 std::vector<std::string>* new_active_input_method_ids) const { |
| 345 if (!IsInputMethodAllowed(input_method_id)) { | |
| 346 DVLOG(1) << "EnableInputMethod: " << input_method_id << " is not allowed."; | |
| 347 return false; | |
| 348 } | |
| 349 | |
| 337 DCHECK(new_active_input_method_ids); | 350 DCHECK(new_active_input_method_ids); |
| 338 if (!manager_->util_.IsValidInputMethodId(input_method_id)) { | 351 if (!manager_->util_.IsValidInputMethodId(input_method_id)) { |
| 339 DVLOG(1) << "EnableInputMethod: Invalid ID: " << input_method_id; | 352 DVLOG(1) << "EnableInputMethod: Invalid ID: " << input_method_id; |
| 340 return false; | 353 return false; |
| 341 } | 354 } |
| 342 | 355 |
| 343 if (!Contains(*new_active_input_method_ids, input_method_id)) | 356 if (!Contains(*new_active_input_method_ids, input_method_id)) |
| 344 new_active_input_method_ids->push_back(input_method_id); | 357 new_active_input_method_ids->push_back(input_method_id); |
| 345 | 358 |
| 346 return true; | 359 return true; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 388 // ChangeInputMethod() picks the first one in |active_input_method_ids|. | 401 // ChangeInputMethod() picks the first one in |active_input_method_ids|. |
| 389 ChangeInputMethod(current_input_method.id(), false); | 402 ChangeInputMethod(current_input_method.id(), false); |
| 390 | 403 |
| 391 // Record histogram for active input method count. | 404 // Record histogram for active input method count. |
| 392 UMA_HISTOGRAM_COUNTS("InputMethod.ActiveCount", | 405 UMA_HISTOGRAM_COUNTS("InputMethod.ActiveCount", |
| 393 active_input_method_ids.size()); | 406 active_input_method_ids.size()); |
| 394 | 407 |
| 395 return true; | 408 return true; |
| 396 } | 409 } |
| 397 | 410 |
| 411 bool InputMethodManagerImpl::StateImpl::SetAllowedInputMethods( | |
| 412 const std::vector<std::string>& new_allowed_input_method_ids) { | |
| 413 allowed_keyboard_layout_input_method_ids.clear(); | |
| 414 for (auto input_method_id : new_allowed_input_method_ids) { | |
| 415 std::string migrated_id = | |
| 416 manager_->util_.MigrateInputMethod(input_method_id); | |
| 417 if (manager_->util_.IsValidInputMethodId(migrated_id)) { | |
| 418 allowed_keyboard_layout_input_method_ids.push_back(migrated_id); | |
| 419 } | |
| 420 } | |
| 421 | |
| 422 if (allowed_keyboard_layout_input_method_ids.empty()) { | |
| 423 // None of the passed input methods were valid, so allow everything. | |
| 424 return false; | |
| 425 } | |
| 426 | |
| 427 // Enable all allowed keyboard layout input methods. Leave all non-keyboard | |
| 428 // input methods enabled. | |
| 429 std::vector<std::string> new_active_input_method_ids( | |
| 430 allowed_keyboard_layout_input_method_ids); | |
| 431 for (auto active_input_method_id : active_input_method_ids) { | |
| 432 if (!manager_->util_.IsKeyboardLayout(active_input_method_id)) | |
| 433 new_active_input_method_ids.push_back(active_input_method_id); | |
| 434 } | |
| 435 return ReplaceEnabledInputMethods(new_active_input_method_ids); | |
| 436 } | |
| 437 | |
| 438 const std::vector<std::string>& | |
| 439 InputMethodManagerImpl::StateImpl::GetAllowedInputMethods() { | |
| 440 return allowed_keyboard_layout_input_method_ids; | |
| 441 } | |
| 442 | |
| 443 bool InputMethodManagerImpl::StateImpl::IsInputMethodAllowed( | |
| 444 const std::string& input_method_id) const { | |
| 445 // Every input method is allowed if SetAllowedKeyboardLayoutInputMethods has | |
| 446 // not been called. | |
| 447 if (allowed_keyboard_layout_input_method_ids.empty()) | |
| 448 return true; | |
| 449 | |
| 450 // We only restrict keyboard layouts. | |
| 451 if (!manager_->util_.IsKeyboardLayout(input_method_id)) | |
| 452 return true; | |
| 453 | |
| 454 return Contains(allowed_keyboard_layout_input_method_ids, input_method_id) || | |
| 455 Contains(allowed_keyboard_layout_input_method_ids, | |
| 456 manager_->util_.MigrateInputMethod(input_method_id)); | |
| 457 } | |
| 458 | |
| 398 void InputMethodManagerImpl::StateImpl::ChangeInputMethod( | 459 void InputMethodManagerImpl::StateImpl::ChangeInputMethod( |
| 399 const std::string& input_method_id, | 460 const std::string& input_method_id, |
| 400 bool show_message) { | 461 bool show_message) { |
| 401 if (manager_->ui_session_ == STATE_TERMINATING) | 462 if (manager_->ui_session_ == STATE_TERMINATING) |
| 402 return; | 463 return; |
| 403 | 464 |
| 404 bool notify_menu = false; | 465 bool notify_menu = false; |
| 405 | 466 |
| 406 // Always lookup input method, even if it is the same as | 467 // Always lookup input method, even if it is the same as |
| 407 // |current_input_method| because If it is no longer in | 468 // |current_input_method| because If it is no longer in |
| (...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1265 if (keyboard_controller) | 1326 if (keyboard_controller) |
| 1266 keyboard_controller->Reload(); | 1327 keyboard_controller->Reload(); |
| 1267 } | 1328 } |
| 1268 | 1329 |
| 1269 bool InputMethodManagerImpl::IsEmojiHandwritingVoiceOnImeMenuEnabled() { | 1330 bool InputMethodManagerImpl::IsEmojiHandwritingVoiceOnImeMenuEnabled() { |
| 1270 return base::FeatureList::IsEnabled(features::kEHVInputOnImeMenu); | 1331 return base::FeatureList::IsEnabled(features::kEHVInputOnImeMenu); |
| 1271 } | 1332 } |
| 1272 | 1333 |
| 1273 } // namespace input_method | 1334 } // namespace input_method |
| 1274 } // namespace chromeos | 1335 } // namespace chromeos |
| OLD | NEW |