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