| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/extensions/api/virtual_keyboard_private/chrome_virtual_
keyboard_delegate.h" | 5 #include "chrome/browser/extensions/api/virtual_keyboard_private/chrome_virtual_
keyboard_delegate.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 11 #include "base/bind.h" |
| 11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 12 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 13 #include "base/metrics/user_metrics_action.h" | 14 #include "base/metrics/user_metrics_action.h" |
| 14 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
| 15 #include "chrome/browser/chromeos/login/lock/screen_locker.h" | 16 #include "chrome/browser/chromeos/login/lock/screen_locker.h" |
| 16 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" | 17 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" |
| 17 #include "chrome/browser/profiles/profile_manager.h" | 18 #include "chrome/browser/profiles/profile_manager.h" |
| 18 #include "chrome/browser/ui/chrome_pages.h" | 19 #include "chrome/browser/ui/chrome_pages.h" |
| 19 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
| 20 #include "components/user_manager/user_manager.h" | 21 #include "components/user_manager/user_manager.h" |
| 21 #include "content/public/browser/user_metrics.h" | 22 #include "content/public/browser/user_metrics.h" |
| 22 #include "extensions/common/api/virtual_keyboard_private.h" | 23 #include "extensions/common/api/virtual_keyboard_private.h" |
| 24 #include "media/audio/audio_system.h" |
| 23 #include "ui/aura/window_tree_host.h" | 25 #include "ui/aura/window_tree_host.h" |
| 24 #include "ui/keyboard/keyboard_controller.h" | 26 #include "ui/keyboard/keyboard_controller.h" |
| 25 #include "ui/keyboard/keyboard_switches.h" | 27 #include "ui/keyboard/keyboard_switches.h" |
| 26 #include "ui/keyboard/keyboard_util.h" | 28 #include "ui/keyboard/keyboard_util.h" |
| 27 | 29 |
| 28 namespace keyboard_api = extensions::api::virtual_keyboard_private; | 30 namespace keyboard_api = extensions::api::virtual_keyboard_private; |
| 29 | 31 |
| 30 namespace { | 32 namespace { |
| 31 | 33 |
| 32 aura::Window* GetKeyboardContainer() { | 34 aura::Window* GetKeyboardContainer() { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 62 case keyboard_api::KEYBOARD_STATE_NONE: | 64 case keyboard_api::KEYBOARD_STATE_NONE: |
| 63 return keyboard::KEYBOARD_STATE_AUTO; | 65 return keyboard::KEYBOARD_STATE_AUTO; |
| 64 } | 66 } |
| 65 return keyboard::KEYBOARD_STATE_AUTO; | 67 return keyboard::KEYBOARD_STATE_AUTO; |
| 66 } | 68 } |
| 67 | 69 |
| 68 } // namespace | 70 } // namespace |
| 69 | 71 |
| 70 namespace extensions { | 72 namespace extensions { |
| 71 | 73 |
| 72 bool ChromeVirtualKeyboardDelegate::GetKeyboardConfig( | 74 ChromeVirtualKeyboardDelegate::ChromeVirtualKeyboardDelegate() |
| 73 base::DictionaryValue* results) { | 75 : weak_factory_(this) { |
| 76 weak_this_ = weak_factory_.GetWeakPtr(); |
| 77 } |
| 78 |
| 79 ChromeVirtualKeyboardDelegate::~ChromeVirtualKeyboardDelegate() {} |
| 80 |
| 81 void ChromeVirtualKeyboardDelegate::GetKeyboardConfig( |
| 82 OnKeyboardSettingsCallback on_settings_callback) { |
| 74 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 83 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 75 results->SetString("layout", keyboard::GetKeyboardLayout()); | 84 media::AudioSystem::Get()->HasInputDevices( |
| 76 // TODO(bshe): Consolidate a11y, hotrod and normal mode into a mode enum. See | 85 base::Bind(&ChromeVirtualKeyboardDelegate::OnHasInputDevices, weak_this_, |
| 77 // crbug.com/529474. | 86 std::move(on_settings_callback))); |
| 78 results->SetBoolean("a11ymode", keyboard::GetAccessibilityKeyboardEnabled()); | |
| 79 results->SetBoolean("hotrodmode", keyboard::GetHotrodKeyboardEnabled()); | |
| 80 std::unique_ptr<base::ListValue> features(new base::ListValue()); | |
| 81 features->AppendString(GenerateFeatureFlag( | |
| 82 "floatingvirtualkeyboard", keyboard::IsFloatingVirtualKeyboardEnabled())); | |
| 83 features->AppendString( | |
| 84 GenerateFeatureFlag("gesturetyping", keyboard::IsGestureTypingEnabled())); | |
| 85 features->AppendString(GenerateFeatureFlag( | |
| 86 "gestureediting", keyboard::IsGestureEditingEnabled())); | |
| 87 features->AppendString( | |
| 88 GenerateFeatureFlag("voiceinput", keyboard::IsVoiceInputEnabled())); | |
| 89 features->AppendString(GenerateFeatureFlag("experimental", | |
| 90 keyboard::IsExperimentalInputViewEnabled())); | |
| 91 results->Set("features", std::move(features)); | |
| 92 return true; | |
| 93 } | 87 } |
| 94 | 88 |
| 95 bool ChromeVirtualKeyboardDelegate::HideKeyboard() { | 89 bool ChromeVirtualKeyboardDelegate::HideKeyboard() { |
| 96 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 90 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 97 keyboard::KeyboardController* controller = | 91 keyboard::KeyboardController* controller = |
| 98 keyboard::KeyboardController::GetInstance(); | 92 keyboard::KeyboardController::GetInstance(); |
| 99 if (!controller) | 93 if (!controller) |
| 100 return false; | 94 return false; |
| 101 | 95 |
| 102 UMA_HISTOGRAM_ENUMERATION("VirtualKeyboard.KeyboardControlEvent", | 96 UMA_HISTOGRAM_ENUMERATION("VirtualKeyboard.KeyboardControlEvent", |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 return true; | 185 return true; |
| 192 } | 186 } |
| 193 | 187 |
| 194 bool ChromeVirtualKeyboardDelegate::IsLanguageSettingsEnabled() { | 188 bool ChromeVirtualKeyboardDelegate::IsLanguageSettingsEnabled() { |
| 195 return (user_manager::UserManager::Get()->IsUserLoggedIn() && | 189 return (user_manager::UserManager::Get()->IsUserLoggedIn() && |
| 196 !chromeos::UserAddingScreen::Get()->IsRunning() && | 190 !chromeos::UserAddingScreen::Get()->IsRunning() && |
| 197 !(chromeos::ScreenLocker::default_screen_locker() && | 191 !(chromeos::ScreenLocker::default_screen_locker() && |
| 198 chromeos::ScreenLocker::default_screen_locker()->locked())); | 192 chromeos::ScreenLocker::default_screen_locker()->locked())); |
| 199 } | 193 } |
| 200 | 194 |
| 195 void ChromeVirtualKeyboardDelegate::OnHasInputDevices( |
| 196 OnKeyboardSettingsCallback on_settings_callback, |
| 197 bool has_input_devices) { |
| 198 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 199 std::unique_ptr<base::DictionaryValue> results(new base::DictionaryValue()); |
| 200 results->SetString("layout", keyboard::GetKeyboardLayout()); |
| 201 // TODO(bshe): Consolidate a11y, hotrod and normal mode into a mode enum. See |
| 202 // crbug.com/529474. |
| 203 results->SetBoolean("a11ymode", keyboard::GetAccessibilityKeyboardEnabled()); |
| 204 results->SetBoolean("hotrodmode", keyboard::GetHotrodKeyboardEnabled()); |
| 205 std::unique_ptr<base::ListValue> features(new base::ListValue()); |
| 206 features->AppendString(GenerateFeatureFlag( |
| 207 "floatingvirtualkeyboard", keyboard::IsFloatingVirtualKeyboardEnabled())); |
| 208 features->AppendString( |
| 209 GenerateFeatureFlag("gesturetyping", keyboard::IsGestureTypingEnabled())); |
| 210 features->AppendString(GenerateFeatureFlag( |
| 211 "gestureediting", keyboard::IsGestureEditingEnabled())); |
| 212 features->AppendString(GenerateFeatureFlag( |
| 213 "voiceinput", has_input_devices && keyboard::IsVoiceInputEnabled())); |
| 214 features->AppendString(GenerateFeatureFlag( |
| 215 "experimental", keyboard::IsExperimentalInputViewEnabled())); |
| 216 results->Set("features", std::move(features)); |
| 217 std::move(on_settings_callback).Run(std::move(results)); |
| 218 } |
| 219 |
| 201 } // namespace extensions | 220 } // namespace extensions |
| OLD | NEW |