| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/extensions/api/input/input.h" | 5 #include "chrome/browser/extensions/api/input/input.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 namespace extensions { | 31 namespace extensions { |
| 32 | 32 |
| 33 bool VirtualKeyboardPrivateInsertTextFunction::RunImpl() { | 33 bool VirtualKeyboardPrivateInsertTextFunction::RunImpl() { |
| 34 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 34 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 35 #if defined(USE_ASH) | 35 #if defined(USE_ASH) |
| 36 base::string16 text; | 36 base::string16 text; |
| 37 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &text)); | 37 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &text)); |
| 38 | 38 |
| 39 return keyboard::InsertText(text, ash::Shell::GetPrimaryRootWindow()); | 39 return keyboard::InsertText(text, ash::Shell::GetPrimaryRootWindow()); |
| 40 #endif | 40 #else |
| 41 error_ = kNotYetImplementedError; | 41 error_ = kNotYetImplementedError; |
| 42 return false; | 42 return false; |
| 43 #endif |
| 43 } | 44 } |
| 44 | 45 |
| 45 bool VirtualKeyboardPrivateMoveCursorFunction::RunImpl() { | 46 bool VirtualKeyboardPrivateMoveCursorFunction::RunImpl() { |
| 46 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 47 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 47 #if defined(USE_ASH) | 48 #if defined(USE_ASH) |
| 48 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 49 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 49 keyboard::switches::kEnableSwipeSelection)) { | 50 keyboard::switches::kEnableSwipeSelection)) { |
| 50 return false; | 51 return false; |
| 51 } | 52 } |
| 52 | 53 |
| 53 int swipe_direction; | 54 int swipe_direction; |
| 54 int modifier_flags; | 55 int modifier_flags; |
| 55 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &swipe_direction)); | 56 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &swipe_direction)); |
| 56 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(1, &modifier_flags)); | 57 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(1, &modifier_flags)); |
| 57 | 58 |
| 58 return keyboard::MoveCursor( | 59 return keyboard::MoveCursor( |
| 59 swipe_direction, | 60 swipe_direction, |
| 60 modifier_flags, | 61 modifier_flags, |
| 61 ash::Shell::GetPrimaryRootWindow()->GetHost()->dispatcher()); | 62 ash::Shell::GetPrimaryRootWindow()->GetHost()->dispatcher()); |
| 62 #endif | 63 #else |
| 63 error_ = kNotYetImplementedError; | 64 error_ = kNotYetImplementedError; |
| 64 return false; | 65 return false; |
| 66 #endif |
| 65 } | 67 } |
| 66 | 68 |
| 67 bool VirtualKeyboardPrivateSendKeyEventFunction::RunImpl() { | 69 bool VirtualKeyboardPrivateSendKeyEventFunction::RunImpl() { |
| 68 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 70 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 69 #if defined(USE_ASH) | 71 #if defined(USE_ASH) |
| 70 base::Value* options_value = NULL; | 72 base::Value* options_value = NULL; |
| 71 base::DictionaryValue* params = NULL; | 73 base::DictionaryValue* params = NULL; |
| 72 std::string type; | 74 std::string type; |
| 73 int char_value; | 75 int char_value; |
| 74 int key_code; | 76 int key_code; |
| 75 std::string key_name; | 77 std::string key_name; |
| 76 int modifiers; | 78 int modifiers; |
| 77 | 79 |
| 78 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &options_value)); | 80 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &options_value)); |
| 79 EXTENSION_FUNCTION_VALIDATE(options_value->GetAsDictionary(¶ms)); | 81 EXTENSION_FUNCTION_VALIDATE(options_value->GetAsDictionary(¶ms)); |
| 80 EXTENSION_FUNCTION_VALIDATE(params->GetString("type", &type)); | 82 EXTENSION_FUNCTION_VALIDATE(params->GetString("type", &type)); |
| 81 EXTENSION_FUNCTION_VALIDATE(params->GetInteger("charValue", &char_value)); | 83 EXTENSION_FUNCTION_VALIDATE(params->GetInteger("charValue", &char_value)); |
| 82 EXTENSION_FUNCTION_VALIDATE(params->GetInteger("keyCode", &key_code)); | 84 EXTENSION_FUNCTION_VALIDATE(params->GetInteger("keyCode", &key_code)); |
| 83 EXTENSION_FUNCTION_VALIDATE(params->GetString("keyName", &key_name)); | 85 EXTENSION_FUNCTION_VALIDATE(params->GetString("keyName", &key_name)); |
| 84 EXTENSION_FUNCTION_VALIDATE(params->GetInteger("modifiers", &modifiers)); | 86 EXTENSION_FUNCTION_VALIDATE(params->GetInteger("modifiers", &modifiers)); |
| 85 | 87 |
| 86 return keyboard::SendKeyEvent( | 88 return keyboard::SendKeyEvent( |
| 87 type, | 89 type, |
| 88 char_value, | 90 char_value, |
| 89 key_code, | 91 key_code, |
| 90 key_name, | 92 key_name, |
| 91 modifiers, | 93 modifiers, |
| 92 ash::Shell::GetPrimaryRootWindow()->GetHost()->dispatcher()); | 94 ash::Shell::GetPrimaryRootWindow()->GetHost()->dispatcher()); |
| 93 #endif | 95 #else |
| 94 error_ = kNotYetImplementedError; | 96 error_ = kNotYetImplementedError; |
| 95 return false; | 97 return false; |
| 98 #endif |
| 96 } | 99 } |
| 97 | 100 |
| 98 bool VirtualKeyboardPrivateHideKeyboardFunction::RunImpl() { | 101 bool VirtualKeyboardPrivateHideKeyboardFunction::RunImpl() { |
| 99 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 102 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 100 #if defined(USE_ASH) | 103 #if defined(USE_ASH) |
| 101 UMA_HISTOGRAM_ENUMERATION( | 104 UMA_HISTOGRAM_ENUMERATION( |
| 102 "VirtualKeyboard.KeyboardControlEvent", | 105 "VirtualKeyboard.KeyboardControlEvent", |
| 103 keyboard::KEYBOARD_CONTROL_HIDE_USER, | 106 keyboard::KEYBOARD_CONTROL_HIDE_USER, |
| 104 keyboard::KEYBOARD_CONTROL_MAX); | 107 keyboard::KEYBOARD_CONTROL_MAX); |
| 105 | 108 |
| 106 // Pass HIDE_REASON_MANUAL since calls to HideKeyboard as part of this API | 109 // Pass HIDE_REASON_MANUAL since calls to HideKeyboard as part of this API |
| 107 // would be user generated. | 110 // would be user generated. |
| 108 ash::Shell::GetInstance()->keyboard_controller()->HideKeyboard( | 111 ash::Shell::GetInstance()->keyboard_controller()->HideKeyboard( |
| 109 keyboard::KeyboardController::HIDE_REASON_MANUAL); | 112 keyboard::KeyboardController::HIDE_REASON_MANUAL); |
| 110 | 113 |
| 111 return true; | 114 return true; |
| 112 #endif | 115 #else |
| 113 error_ = kNotYetImplementedError; | 116 error_ = kNotYetImplementedError; |
| 114 return false; | 117 return false; |
| 118 #endif |
| 115 } | 119 } |
| 116 | 120 |
| 117 bool VirtualKeyboardPrivateLockKeyboardFunction::RunImpl() { | 121 bool VirtualKeyboardPrivateLockKeyboardFunction::RunImpl() { |
| 118 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 122 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 119 #if defined(USE_ASH) | 123 #if defined(USE_ASH) |
| 120 bool lock; | 124 bool lock; |
| 121 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(0, &lock)); | 125 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(0, &lock)); |
| 122 | |
| 123 ash::Shell::GetInstance()->keyboard_controller()->set_lock_keyboard(lock); | 126 ash::Shell::GetInstance()->keyboard_controller()->set_lock_keyboard(lock); |
| 124 | |
| 125 return true; | 127 return true; |
| 126 #endif | 128 #else |
| 127 error_ = kNotYetImplementedError; | 129 error_ = kNotYetImplementedError; |
| 128 return false; | 130 return false; |
| 131 #endif |
| 129 } | 132 } |
| 130 | 133 |
| 131 bool VirtualKeyboardPrivateKeyboardLoadedFunction::RunImpl() { | 134 bool VirtualKeyboardPrivateKeyboardLoadedFunction::RunImpl() { |
| 132 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 135 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 133 #if defined(USE_ASH) | 136 #if defined(USE_ASH) |
| 134 keyboard::MarkKeyboardLoadFinished(); | 137 keyboard::MarkKeyboardLoadFinished(); |
| 135 | |
| 136 base::UserMetricsAction("VirtualKeyboardLoaded"); | 138 base::UserMetricsAction("VirtualKeyboardLoaded"); |
| 137 | |
| 138 return true; | 139 return true; |
| 139 #endif | 140 #else |
| 140 error_ = kNotYetImplementedError; | 141 error_ = kNotYetImplementedError; |
| 141 return false; | 142 return false; |
| 143 #endif |
| 142 } | 144 } |
| 143 | 145 |
| 144 bool VirtualKeyboardPrivateGetKeyboardConfigFunction::RunImpl() { | 146 bool VirtualKeyboardPrivateGetKeyboardConfigFunction::RunImpl() { |
| 145 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 147 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 146 #if defined(USE_ASH) | 148 #if defined(USE_ASH) |
| 147 base::DictionaryValue* results = new base::DictionaryValue(); | 149 base::DictionaryValue* results = new base::DictionaryValue(); |
| 148 results->SetString("layout", keyboard::GetKeyboardLayout()); | 150 results->SetString("layout", keyboard::GetKeyboardLayout()); |
| 149 results->SetBoolean("a11ymode", keyboard::GetAccessibilityKeyboardEnabled()); | 151 results->SetBoolean("a11ymode", keyboard::GetAccessibilityKeyboardEnabled()); |
| 150 SetResult(results); | 152 SetResult(results); |
| 151 return true; | 153 return true; |
| 152 #endif | 154 #else |
| 153 error_ = kNotYetImplementedError; | 155 error_ = kNotYetImplementedError; |
| 154 return false; | 156 return false; |
| 157 #endif |
| 155 } | 158 } |
| 156 | 159 |
| 157 InputAPI::InputAPI(content::BrowserContext* context) {} | 160 InputAPI::InputAPI(content::BrowserContext* context) {} |
| 158 | 161 |
| 159 InputAPI::~InputAPI() { | 162 InputAPI::~InputAPI() { |
| 160 } | 163 } |
| 161 | 164 |
| 162 static base::LazyInstance<BrowserContextKeyedAPIFactory<InputAPI> > g_factory = | 165 static base::LazyInstance<BrowserContextKeyedAPIFactory<InputAPI> > g_factory = |
| 163 LAZY_INSTANCE_INITIALIZER; | 166 LAZY_INSTANCE_INITIALIZER; |
| 164 | 167 |
| 165 // static | 168 // static |
| 166 BrowserContextKeyedAPIFactory<InputAPI>* InputAPI::GetFactoryInstance() { | 169 BrowserContextKeyedAPIFactory<InputAPI>* InputAPI::GetFactoryInstance() { |
| 167 return g_factory.Pointer(); | 170 return g_factory.Pointer(); |
| 168 } | 171 } |
| 169 | 172 |
| 170 } // namespace extensions | 173 } // namespace extensions |
| OLD | NEW |