| 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/api/input_ime/input_ime_api.h" | 5 #include "chrome/browser/extensions/api/input_ime/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 scoped_ptr<base::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.Pass(), 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 scoped_ptr<base::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.Pass(), 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 scoped_ptr<base::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.Pass(), 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 scoped_ptr<base::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.Pass(), 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 scoped_ptr<base::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.Pass(), profile_, |
| 226 GURL()); | 216 GURL()); |
| 227 } | 217 } |
| 228 | 218 |
| 229 virtual void OnKeyEvent(const std::string& engine_id, | 219 virtual void OnKeyEvent(const std::string& engine_id, |
| 230 const InputMethodEngine::KeyboardEvent& event, | 220 const InputMethodEngine::KeyboardEvent& event, |
| 231 chromeos::input_method::KeyEventHandle* key_data) { | 221 chromeos::input_method::KeyEventHandle* key_data) { |
| 232 if (profile_ == NULL || extension_id_.empty()) | 222 if (profile_ == NULL || extension_id_.empty()) |
| 233 return; | 223 return; |
| 234 | 224 |
| 235 std::string request_id = | 225 std::string request_id = |
| 236 extensions::InputImeEventRouter::GetInstance()->AddRequest(engine_id, | 226 extensions::InputImeEventRouter::GetInstance()->AddRequest(engine_id, |
| 237 key_data); | 227 key_data); |
| 238 | 228 |
| 239 DictionaryValue* dict = new DictionaryValue(); | 229 DictionaryValue* dict = new DictionaryValue(); |
| 240 dict->SetString("type", event.type); | 230 dict->SetString("type", event.type); |
| 241 dict->SetString("requestId", request_id); | 231 dict->SetString("requestId", request_id); |
| 242 dict->SetString("key", event.key); | 232 dict->SetString("key", event.key); |
| 243 dict->SetBoolean("altKey", event.alt_key); | 233 dict->SetBoolean("altKey", event.alt_key); |
| 244 dict->SetBoolean("ctrlKey", event.ctrl_key); | 234 dict->SetBoolean("ctrlKey", event.ctrl_key); |
| 245 dict->SetBoolean("shiftKey", event.shift_key); | 235 dict->SetBoolean("shiftKey", event.shift_key); |
| 246 | 236 |
| 247 ListValue args; | 237 scoped_ptr<base::ListValue> args(new ListValue()); |
| 248 args.Append(Value::CreateStringValue(engine_id)); | 238 args->Append(Value::CreateStringValue(engine_id)); |
| 249 args.Append(dict); | 239 args->Append(dict); |
| 250 | 240 |
| 251 std::string json_args; | |
| 252 base::JSONWriter::Write(&args, &json_args); | |
| 253 profile_->GetExtensionEventRouter()->DispatchEventToExtension( | 241 profile_->GetExtensionEventRouter()->DispatchEventToExtension( |
| 254 extension_id_, events::kOnKeyEvent, json_args, profile_, GURL()); | 242 extension_id_, events::kOnKeyEvent, args.Pass(), profile_, GURL()); |
| 255 } | 243 } |
| 256 | 244 |
| 257 virtual void OnCandidateClicked( | 245 virtual void OnCandidateClicked( |
| 258 const std::string& engine_id, | 246 const std::string& engine_id, |
| 259 int candidate_id, | 247 int candidate_id, |
| 260 chromeos::InputMethodEngine::MouseButtonEvent button) { | 248 chromeos::InputMethodEngine::MouseButtonEvent button) { |
| 261 if (profile_ == NULL || extension_id_.empty()) | 249 if (profile_ == NULL || extension_id_.empty()) |
| 262 return; | 250 return; |
| 263 | 251 |
| 264 ListValue args; | 252 scoped_ptr<base::ListValue> args(new ListValue()); |
| 265 args.Append(Value::CreateStringValue(engine_id)); | 253 args->Append(Value::CreateStringValue(engine_id)); |
| 266 args.Append(Value::CreateIntegerValue(candidate_id)); | 254 args->Append(Value::CreateIntegerValue(candidate_id)); |
| 267 switch (button) { | 255 switch (button) { |
| 268 case chromeos::InputMethodEngine::MOUSE_BUTTON_MIDDLE: | 256 case chromeos::InputMethodEngine::MOUSE_BUTTON_MIDDLE: |
| 269 args.Append(Value::CreateStringValue("middle")); | 257 args->Append(Value::CreateStringValue("middle")); |
| 270 break; | 258 break; |
| 271 | 259 |
| 272 case chromeos::InputMethodEngine::MOUSE_BUTTON_RIGHT: | 260 case chromeos::InputMethodEngine::MOUSE_BUTTON_RIGHT: |
| 273 args.Append(Value::CreateStringValue("right")); | 261 args->Append(Value::CreateStringValue("right")); |
| 274 break; | 262 break; |
| 275 | 263 |
| 276 case chromeos::InputMethodEngine::MOUSE_BUTTON_LEFT: | 264 case chromeos::InputMethodEngine::MOUSE_BUTTON_LEFT: |
| 277 // Default to left. | 265 // Default to left. |
| 278 default: | 266 default: |
| 279 args.Append(Value::CreateStringValue("left")); | 267 args->Append(Value::CreateStringValue("left")); |
| 280 break; | 268 break; |
| 281 } | 269 } |
| 282 | 270 |
| 283 std::string json_args; | |
| 284 base::JSONWriter::Write(&args, &json_args); | |
| 285 profile_->GetExtensionEventRouter()->DispatchEventToExtension( | 271 profile_->GetExtensionEventRouter()->DispatchEventToExtension( |
| 286 extension_id_, events::kOnCandidateClicked, json_args, profile_, | 272 extension_id_, events::kOnCandidateClicked, args.Pass(), profile_, |
| 287 GURL()); | 273 GURL()); |
| 288 } | 274 } |
| 289 | 275 |
| 290 virtual void OnMenuItemActivated(const std::string& engine_id, | 276 virtual void OnMenuItemActivated(const std::string& engine_id, |
| 291 const std::string& menu_id) { | 277 const std::string& menu_id) { |
| 292 if (profile_ == NULL || extension_id_.empty()) | 278 if (profile_ == NULL || extension_id_.empty()) |
| 293 return; | 279 return; |
| 294 | 280 |
| 295 ListValue args; | 281 scoped_ptr<base::ListValue> args(new ListValue()); |
| 296 args.Append(Value::CreateStringValue(engine_id)); | 282 args->Append(Value::CreateStringValue(engine_id)); |
| 297 args.Append(Value::CreateStringValue(menu_id)); | 283 args->Append(Value::CreateStringValue(menu_id)); |
| 298 | 284 |
| 299 std::string json_args; | |
| 300 base::JSONWriter::Write(&args, &json_args); | |
| 301 profile_->GetExtensionEventRouter()->DispatchEventToExtension( | 285 profile_->GetExtensionEventRouter()->DispatchEventToExtension( |
| 302 extension_id_, events::kOnMenuItemActivated, json_args, profile_, | 286 extension_id_, events::kOnMenuItemActivated, args.Pass(), profile_, |
| 303 GURL()); | 287 GURL()); |
| 304 } | 288 } |
| 305 | 289 |
| 306 private: | 290 private: |
| 307 Profile* profile_; | 291 Profile* profile_; |
| 308 std::string extension_id_; | 292 std::string extension_id_; |
| 309 std::string engine_id_; | 293 std::string engine_id_; |
| 310 | 294 |
| 311 DISALLOW_COPY_AND_ASSIGN(ImeObserver); | 295 DISALLOW_COPY_AND_ASSIGN(ImeObserver); |
| 312 }; | 296 }; |
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &handled)); | 808 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &handled)); |
| 825 | 809 |
| 826 InputImeEventRouter::GetInstance()->OnEventHandled( | 810 InputImeEventRouter::GetInstance()->OnEventHandled( |
| 827 extension_id(), request_id_str, handled); | 811 extension_id(), request_id_str, handled); |
| 828 | 812 |
| 829 return true; | 813 return true; |
| 830 } | 814 } |
| 831 #endif | 815 #endif |
| 832 | 816 |
| 833 } // namespace extensions | 817 } // namespace extensions |
| OLD | NEW |