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/extensions/extension_input_ime_api.h" | 5 #include "chrome/browser/extensions/extension_input_ime_api.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 extension_id_(extension_id), | 148 extension_id_(extension_id), |
149 engine_id_(engine_id) { | 149 engine_id_(engine_id) { |
150 } | 150 } |
151 | 151 |
152 virtual ~ImeObserver() {} | 152 virtual ~ImeObserver() {} |
153 | 153 |
154 virtual void OnActivate(const std::string& engine_id) { | 154 virtual void OnActivate(const std::string& engine_id) { |
155 if (profile_ == NULL || extension_id_.empty()) | 155 if (profile_ == NULL || extension_id_.empty()) |
156 return; | 156 return; |
157 | 157 |
158 ListValue args; | 158 ListValue* args = new ListValue(); |
159 args.Append(Value::CreateStringValue(engine_id)); | 159 args->Append(Value::CreateStringValue(engine_id)); |
160 | 160 |
161 std::string json_args; | |
162 base::JSONWriter::Write(&args, &json_args); | |
163 profile_->GetExtensionEventRouter()->DispatchEventToExtension( | 161 profile_->GetExtensionEventRouter()->DispatchEventToExtension( |
164 extension_id_, events::kOnActivate, json_args, profile_, GURL()); | 162 extension_id_, events::kOnActivate, args, profile_, GURL()); |
165 } | 163 } |
166 | 164 |
167 virtual void OnDeactivated(const std::string& engine_id) { | 165 virtual void OnDeactivated(const std::string& engine_id) { |
168 if (profile_ == NULL || extension_id_.empty()) | 166 if (profile_ == NULL || extension_id_.empty()) |
169 return; | 167 return; |
170 | 168 |
171 ListValue args; | 169 ListValue* args = new ListValue(); |
172 args.Append(Value::CreateStringValue(engine_id)); | 170 args->Append(Value::CreateStringValue(engine_id)); |
173 | 171 |
174 std::string json_args; | |
175 base::JSONWriter::Write(&args, &json_args); | |
176 profile_->GetExtensionEventRouter()->DispatchEventToExtension( | 172 profile_->GetExtensionEventRouter()->DispatchEventToExtension( |
177 extension_id_, events::kOnDeactivated, json_args, profile_, GURL()); | 173 extension_id_, events::kOnDeactivated, args, profile_, GURL()); |
178 } | 174 } |
179 | 175 |
180 virtual void OnFocus(const InputMethodEngine::InputContext& context) { | 176 virtual void OnFocus(const InputMethodEngine::InputContext& context) { |
181 if (profile_ == NULL || extension_id_.empty()) | 177 if (profile_ == NULL || extension_id_.empty()) |
182 return; | 178 return; |
183 | 179 |
184 DictionaryValue* dict = new DictionaryValue(); | 180 DictionaryValue* dict = new DictionaryValue(); |
185 dict->SetInteger("contextID", context.id); | 181 dict->SetInteger("contextID", context.id); |
186 dict->SetString("type", context.type); | 182 dict->SetString("type", context.type); |
187 | 183 |
188 ListValue args; | 184 ListValue* args = new ListValue(); |
189 args.Append(dict); | 185 args->Append(dict); |
190 | 186 |
191 std::string json_args; | |
192 base::JSONWriter::Write(&args, &json_args); | |
193 profile_->GetExtensionEventRouter()->DispatchEventToExtension( | 187 profile_->GetExtensionEventRouter()->DispatchEventToExtension( |
194 extension_id_, events::kOnFocus, json_args, profile_, GURL()); | 188 extension_id_, events::kOnFocus, args, profile_, GURL()); |
195 } | 189 } |
196 | 190 |
197 virtual void OnBlur(int context_id) { | 191 virtual void OnBlur(int context_id) { |
198 if (profile_ == NULL || extension_id_.empty()) | 192 if (profile_ == NULL || extension_id_.empty()) |
199 return; | 193 return; |
200 | 194 |
201 ListValue args; | 195 ListValue* args = new ListValue(); |
202 args.Append(Value::CreateIntegerValue(context_id)); | 196 args->Append(Value::CreateIntegerValue(context_id)); |
203 | 197 |
204 std::string json_args; | |
205 base::JSONWriter::Write(&args, &json_args); | |
206 profile_->GetExtensionEventRouter()->DispatchEventToExtension( | 198 profile_->GetExtensionEventRouter()->DispatchEventToExtension( |
207 extension_id_, events::kOnBlur, json_args, profile_, GURL()); | 199 extension_id_, events::kOnBlur, args, profile_, GURL()); |
208 } | 200 } |
209 | 201 |
210 virtual void OnInputContextUpdate( | 202 virtual void OnInputContextUpdate( |
211 const InputMethodEngine::InputContext& context) { | 203 const InputMethodEngine::InputContext& context) { |
212 if (profile_ == NULL || extension_id_.empty()) | 204 if (profile_ == NULL || extension_id_.empty()) |
213 return; | 205 return; |
214 | 206 |
215 DictionaryValue* dict = new DictionaryValue(); | 207 DictionaryValue* dict = new DictionaryValue(); |
216 dict->SetInteger("contextID", context.id); | 208 dict->SetInteger("contextID", context.id); |
217 dict->SetString("type", context.type); | 209 dict->SetString("type", context.type); |
218 | 210 |
219 ListValue args; | 211 ListValue* args = new ListValue(); |
220 args.Append(dict); | 212 args->Append(dict); |
221 | 213 |
222 std::string json_args; | |
223 base::JSONWriter::Write(&args, &json_args); | |
224 profile_->GetExtensionEventRouter()->DispatchEventToExtension( | 214 profile_->GetExtensionEventRouter()->DispatchEventToExtension( |
225 extension_id_, events::kOnInputContextUpdate, json_args, profile_, | 215 extension_id_, events::kOnInputContextUpdate, args, profile_, GURL()); |
226 GURL()); | |
227 } | 216 } |
228 | 217 |
229 virtual void OnKeyEvent(const std::string& engine_id, | 218 virtual void OnKeyEvent(const std::string& engine_id, |
230 const InputMethodEngine::KeyboardEvent& event, | 219 const InputMethodEngine::KeyboardEvent& event, |
231 chromeos::input_method::KeyEventHandle* key_data) { | 220 chromeos::input_method::KeyEventHandle* key_data) { |
232 if (profile_ == NULL || extension_id_.empty()) | 221 if (profile_ == NULL || extension_id_.empty()) |
233 return; | 222 return; |
234 | 223 |
235 std::string request_id = | 224 std::string request_id = |
236 ExtensionInputImeEventRouter::GetInstance()->AddRequest(engine_id, | 225 ExtensionInputImeEventRouter::GetInstance()->AddRequest(engine_id, |
237 key_data); | 226 key_data); |
238 | 227 |
239 DictionaryValue* dict = new DictionaryValue(); | 228 DictionaryValue* dict = new DictionaryValue(); |
240 dict->SetString("type", event.type); | 229 dict->SetString("type", event.type); |
241 dict->SetString("requestId", request_id); | 230 dict->SetString("requestId", request_id); |
242 dict->SetString("key", event.key); | 231 dict->SetString("key", event.key); |
243 dict->SetBoolean("altKey", event.alt_key); | 232 dict->SetBoolean("altKey", event.alt_key); |
244 dict->SetBoolean("ctrlKey", event.ctrl_key); | 233 dict->SetBoolean("ctrlKey", event.ctrl_key); |
245 dict->SetBoolean("shiftKey", event.shift_key); | 234 dict->SetBoolean("shiftKey", event.shift_key); |
246 | 235 |
247 ListValue args; | 236 ListValue* args = new ListValue(); |
248 args.Append(Value::CreateStringValue(engine_id)); | 237 args->Append(Value::CreateStringValue(engine_id)); |
249 args.Append(dict); | 238 args->Append(dict); |
250 | 239 |
251 std::string json_args; | |
252 base::JSONWriter::Write(&args, &json_args); | |
253 profile_->GetExtensionEventRouter()->DispatchEventToExtension( | 240 profile_->GetExtensionEventRouter()->DispatchEventToExtension( |
254 extension_id_, events::kOnKeyEvent, json_args, profile_, GURL()); | 241 extension_id_, events::kOnKeyEvent, args, profile_, GURL()); |
255 } | 242 } |
256 | 243 |
257 virtual void OnCandidateClicked( | 244 virtual void OnCandidateClicked( |
258 const std::string& engine_id, | 245 const std::string& engine_id, |
259 int candidate_id, | 246 int candidate_id, |
260 chromeos::InputMethodEngine::MouseButtonEvent button) { | 247 chromeos::InputMethodEngine::MouseButtonEvent button) { |
261 if (profile_ == NULL || extension_id_.empty()) | 248 if (profile_ == NULL || extension_id_.empty()) |
262 return; | 249 return; |
263 | 250 |
264 ListValue args; | 251 ListValue* args = new ListValue(); |
265 args.Append(Value::CreateStringValue(engine_id)); | 252 args->Append(Value::CreateStringValue(engine_id)); |
266 args.Append(Value::CreateIntegerValue(candidate_id)); | 253 args->Append(Value::CreateIntegerValue(candidate_id)); |
267 switch (button) { | 254 switch (button) { |
268 case chromeos::InputMethodEngine::MOUSE_BUTTON_MIDDLE: | 255 case chromeos::InputMethodEngine::MOUSE_BUTTON_MIDDLE: |
269 args.Append(Value::CreateStringValue("middle")); | 256 args->Append(Value::CreateStringValue("middle")); |
270 break; | 257 break; |
271 | 258 |
272 case chromeos::InputMethodEngine::MOUSE_BUTTON_RIGHT: | 259 case chromeos::InputMethodEngine::MOUSE_BUTTON_RIGHT: |
273 args.Append(Value::CreateStringValue("right")); | 260 args->Append(Value::CreateStringValue("right")); |
274 break; | 261 break; |
275 | 262 |
276 case chromeos::InputMethodEngine::MOUSE_BUTTON_LEFT: | 263 case chromeos::InputMethodEngine::MOUSE_BUTTON_LEFT: |
277 // Default to left. | 264 // Default to left. |
278 default: | 265 default: |
279 args.Append(Value::CreateStringValue("left")); | 266 args->Append(Value::CreateStringValue("left")); |
280 break; | 267 break; |
281 } | 268 } |
282 | 269 |
283 std::string json_args; | |
284 base::JSONWriter::Write(&args, &json_args); | |
285 profile_->GetExtensionEventRouter()->DispatchEventToExtension( | 270 profile_->GetExtensionEventRouter()->DispatchEventToExtension( |
286 extension_id_, events::kOnCandidateClicked, json_args, profile_, | 271 extension_id_, events::kOnCandidateClicked, args, profile_, GURL()); |
287 GURL()); | |
288 } | 272 } |
289 | 273 |
290 virtual void OnMenuItemActivated(const std::string& engine_id, | 274 virtual void OnMenuItemActivated(const std::string& engine_id, |
291 const std::string& menu_id) { | 275 const std::string& menu_id) { |
292 if (profile_ == NULL || extension_id_.empty()) | 276 if (profile_ == NULL || extension_id_.empty()) |
293 return; | 277 return; |
294 | 278 |
295 ListValue args; | 279 ListValue* args = new ListValue(); |
296 args.Append(Value::CreateStringValue(engine_id)); | 280 args->Append(Value::CreateStringValue(engine_id)); |
297 args.Append(Value::CreateStringValue(menu_id)); | 281 args->Append(Value::CreateStringValue(menu_id)); |
298 | 282 |
299 std::string json_args; | |
300 base::JSONWriter::Write(&args, &json_args); | |
301 profile_->GetExtensionEventRouter()->DispatchEventToExtension( | 283 profile_->GetExtensionEventRouter()->DispatchEventToExtension( |
302 extension_id_, events::kOnMenuItemActivated, json_args, profile_, | 284 extension_id_, events::kOnMenuItemActivated, args, profile_, GURL()); |
303 GURL()); | |
304 } | 285 } |
305 | 286 |
306 private: | 287 private: |
307 Profile* profile_; | 288 Profile* profile_; |
308 std::string extension_id_; | 289 std::string extension_id_; |
309 std::string engine_id_; | 290 std::string engine_id_; |
310 | 291 |
311 DISALLOW_COPY_AND_ASSIGN(ImeObserver); | 292 DISALLOW_COPY_AND_ASSIGN(ImeObserver); |
312 }; | 293 }; |
313 | 294 |
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 | 809 |
829 bool handled = false; | 810 bool handled = false; |
830 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &handled)); | 811 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &handled)); |
831 | 812 |
832 ExtensionInputImeEventRouter::GetInstance()->OnEventHandled( | 813 ExtensionInputImeEventRouter::GetInstance()->OnEventHandled( |
833 extension_id(), request_id_str, handled); | 814 extension_id(), request_id_str, handled); |
834 | 815 |
835 return true; | 816 return true; |
836 } | 817 } |
837 #endif | 818 #endif |
OLD | NEW |