Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(317)

Side by Side Diff: chrome/browser/extensions/api/input_ime/input_ime_api.cc

Issue 11440004: Remove deprecated extension EventRouter APIs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: compile Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 118
119 if (!ReadMenuItems(sub_list, &(output->back().children))) { 119 if (!ReadMenuItems(sub_list, &(output->back().children))) {
120 return false; 120 return false;
121 } 121 }
122 } 122 }
123 } 123 }
124 124
125 return true; 125 return true;
126 } 126 }
127 127
128 static void DispatchEventToExtension(Profile* profile,
129 const std::string& extension_id,
130 const std::string& event_name,
131 scoped_ptr<ListValue> args) {
132 scoped_ptr<extensions::Event> event(new extensions::Event(
133 event_name, args.Pass()));
134 event->restrict_to_profile = profile;
135 extensions::ExtensionSystem::Get(profile)->event_router()->
136 DispatchEventToExtension(extension_id, event.Pass());
137 }
138
128 } // namespace 139 } // namespace
129 140
130 namespace events { 141 namespace events {
131 142
132 const char kOnActivate[] = "input.ime.onActivate"; 143 const char kOnActivate[] = "input.ime.onActivate";
133 const char kOnDeactivated[] = "input.ime.onDeactivated"; 144 const char kOnDeactivated[] = "input.ime.onDeactivated";
134 const char kOnFocus[] = "input.ime.onFocus"; 145 const char kOnFocus[] = "input.ime.onFocus";
135 const char kOnBlur[] = "input.ime.onBlur"; 146 const char kOnBlur[] = "input.ime.onBlur";
136 const char kOnInputContextUpdate[] = "input.ime.onInputContextUpdate"; 147 const char kOnInputContextUpdate[] = "input.ime.onInputContextUpdate";
137 const char kOnKeyEvent[] = "input.ime.onKeyEvent"; 148 const char kOnKeyEvent[] = "input.ime.onKeyEvent";
(...skipping 14 matching lines...) Expand all
152 163
153 virtual ~ImeObserver() {} 164 virtual ~ImeObserver() {}
154 165
155 virtual void OnActivate(const std::string& engine_id) OVERRIDE { 166 virtual void OnActivate(const std::string& engine_id) OVERRIDE {
156 if (profile_ == NULL || extension_id_.empty()) 167 if (profile_ == NULL || extension_id_.empty())
157 return; 168 return;
158 169
159 scoped_ptr<base::ListValue> args(new ListValue()); 170 scoped_ptr<base::ListValue> args(new ListValue());
160 args->Append(Value::CreateStringValue(engine_id)); 171 args->Append(Value::CreateStringValue(engine_id));
161 172
162 extensions::ExtensionSystem::Get(profile_)->event_router()-> 173 DispatchEventToExtension(profile_, extension_id_,
163 DispatchEventToExtension(extension_id_, events::kOnActivate, 174 events::kOnActivate, args.Pass());
164 args.Pass(), profile_, GURL());
165 } 175 }
166 176
167 virtual void OnDeactivated(const std::string& engine_id) OVERRIDE { 177 virtual void OnDeactivated(const std::string& engine_id) OVERRIDE {
168 if (profile_ == NULL || extension_id_.empty()) 178 if (profile_ == NULL || extension_id_.empty())
169 return; 179 return;
170 180
171 scoped_ptr<base::ListValue> args(new ListValue()); 181 scoped_ptr<base::ListValue> args(new ListValue());
172 args->Append(Value::CreateStringValue(engine_id)); 182 args->Append(Value::CreateStringValue(engine_id));
173 183
174 extensions::ExtensionSystem::Get(profile_)->event_router()-> 184 DispatchEventToExtension(profile_, extension_id_,
175 DispatchEventToExtension(extension_id_, events::kOnDeactivated, 185 events::kOnDeactivated, args.Pass());
176 args.Pass(), profile_, GURL());
177 } 186 }
178 187
179 virtual void OnFocus( 188 virtual void OnFocus(
180 const InputMethodEngine::InputContext& context) OVERRIDE { 189 const InputMethodEngine::InputContext& context) OVERRIDE {
181 if (profile_ == NULL || extension_id_.empty()) 190 if (profile_ == NULL || extension_id_.empty())
182 return; 191 return;
183 192
184 DictionaryValue* dict = new DictionaryValue(); 193 DictionaryValue* dict = new DictionaryValue();
185 dict->SetInteger("contextID", context.id); 194 dict->SetInteger("contextID", context.id);
186 dict->SetString("type", context.type); 195 dict->SetString("type", context.type);
187 196
188 scoped_ptr<base::ListValue> args(new ListValue()); 197 scoped_ptr<base::ListValue> args(new ListValue());
189 args->Append(dict); 198 args->Append(dict);
190 199
191 extensions::ExtensionSystem::Get(profile_)->event_router()-> 200 DispatchEventToExtension(profile_, extension_id_,
192 DispatchEventToExtension(extension_id_, events::kOnFocus, 201 events::kOnFocus, args.Pass());
193 args.Pass(), profile_, GURL());
194 } 202 }
195 203
196 virtual void OnBlur(int context_id) OVERRIDE { 204 virtual void OnBlur(int context_id) OVERRIDE {
197 if (profile_ == NULL || extension_id_.empty()) 205 if (profile_ == NULL || extension_id_.empty())
198 return; 206 return;
199 207
200 scoped_ptr<base::ListValue> args(new ListValue()); 208 scoped_ptr<base::ListValue> args(new ListValue());
201 args->Append(Value::CreateIntegerValue(context_id)); 209 args->Append(Value::CreateIntegerValue(context_id));
202 210
203 extensions::ExtensionSystem::Get(profile_)->event_router()-> 211 DispatchEventToExtension(profile_, extension_id_,
204 DispatchEventToExtension(extension_id_, events::kOnBlur, 212 events::kOnBlur, args.Pass());
205 args.Pass(), profile_, GURL());
206 } 213 }
207 214
208 virtual void OnInputContextUpdate( 215 virtual void OnInputContextUpdate(
209 const InputMethodEngine::InputContext& context) OVERRIDE { 216 const InputMethodEngine::InputContext& context) OVERRIDE {
210 if (profile_ == NULL || extension_id_.empty()) 217 if (profile_ == NULL || extension_id_.empty())
211 return; 218 return;
212 219
213 DictionaryValue* dict = new DictionaryValue(); 220 DictionaryValue* dict = new DictionaryValue();
214 dict->SetInteger("contextID", context.id); 221 dict->SetInteger("contextID", context.id);
215 dict->SetString("type", context.type); 222 dict->SetString("type", context.type);
216 223
217 scoped_ptr<base::ListValue> args(new ListValue()); 224 scoped_ptr<base::ListValue> args(new ListValue());
218 args->Append(dict); 225 args->Append(dict);
219 226
220 extensions::ExtensionSystem::Get(profile_)->event_router()-> 227 DispatchEventToExtension(profile_, extension_id_,
221 DispatchEventToExtension(extension_id_, events::kOnInputContextUpdate, 228 events::kOnInputContextUpdate, args.Pass());
222 args.Pass(), profile_, GURL());
223 } 229 }
224 230
225 virtual void OnKeyEvent( 231 virtual void OnKeyEvent(
226 const std::string& engine_id, 232 const std::string& engine_id,
227 const InputMethodEngine::KeyboardEvent& event, 233 const InputMethodEngine::KeyboardEvent& event,
228 chromeos::input_method::KeyEventHandle* key_data) OVERRIDE { 234 chromeos::input_method::KeyEventHandle* key_data) OVERRIDE {
229 if (profile_ == NULL || extension_id_.empty()) 235 if (profile_ == NULL || extension_id_.empty())
230 return; 236 return;
231 237
232 std::string request_id = 238 std::string request_id =
233 extensions::InputImeEventRouter::GetInstance()->AddRequest(engine_id, 239 extensions::InputImeEventRouter::GetInstance()->AddRequest(engine_id,
234 key_data); 240 key_data);
235 241
236 DictionaryValue* dict = new DictionaryValue(); 242 DictionaryValue* dict = new DictionaryValue();
237 dict->SetString("type", event.type); 243 dict->SetString("type", event.type);
238 dict->SetString("requestId", request_id); 244 dict->SetString("requestId", request_id);
239 dict->SetString("key", event.key); 245 dict->SetString("key", event.key);
240 dict->SetBoolean("altKey", event.alt_key); 246 dict->SetBoolean("altKey", event.alt_key);
241 dict->SetBoolean("ctrlKey", event.ctrl_key); 247 dict->SetBoolean("ctrlKey", event.ctrl_key);
242 dict->SetBoolean("shiftKey", event.shift_key); 248 dict->SetBoolean("shiftKey", event.shift_key);
243 249
244 scoped_ptr<base::ListValue> args(new ListValue()); 250 scoped_ptr<base::ListValue> args(new ListValue());
245 args->Append(Value::CreateStringValue(engine_id)); 251 args->Append(Value::CreateStringValue(engine_id));
246 args->Append(dict); 252 args->Append(dict);
247 253
248 extensions::ExtensionSystem::Get(profile_)->event_router()-> 254 DispatchEventToExtension(profile_, extension_id_,
249 DispatchEventToExtension(extension_id_, events::kOnKeyEvent, 255 events::kOnKeyEvent, args.Pass());
250 args.Pass(), profile_, GURL());
251 } 256 }
252 257
253 virtual void OnCandidateClicked( 258 virtual void OnCandidateClicked(
254 const std::string& engine_id, 259 const std::string& engine_id,
255 int candidate_id, 260 int candidate_id,
256 chromeos::InputMethodEngine::MouseButtonEvent button) OVERRIDE { 261 chromeos::InputMethodEngine::MouseButtonEvent button) OVERRIDE {
257 if (profile_ == NULL || extension_id_.empty()) 262 if (profile_ == NULL || extension_id_.empty())
258 return; 263 return;
259 264
260 scoped_ptr<base::ListValue> args(new ListValue()); 265 scoped_ptr<base::ListValue> args(new ListValue());
261 args->Append(Value::CreateStringValue(engine_id)); 266 args->Append(Value::CreateStringValue(engine_id));
262 args->Append(Value::CreateIntegerValue(candidate_id)); 267 args->Append(Value::CreateIntegerValue(candidate_id));
263 switch (button) { 268 switch (button) {
264 case chromeos::InputMethodEngine::MOUSE_BUTTON_MIDDLE: 269 case chromeos::InputMethodEngine::MOUSE_BUTTON_MIDDLE:
265 args->Append(Value::CreateStringValue("middle")); 270 args->Append(Value::CreateStringValue("middle"));
266 break; 271 break;
267 272
268 case chromeos::InputMethodEngine::MOUSE_BUTTON_RIGHT: 273 case chromeos::InputMethodEngine::MOUSE_BUTTON_RIGHT:
269 args->Append(Value::CreateStringValue("right")); 274 args->Append(Value::CreateStringValue("right"));
270 break; 275 break;
271 276
272 case chromeos::InputMethodEngine::MOUSE_BUTTON_LEFT: 277 case chromeos::InputMethodEngine::MOUSE_BUTTON_LEFT:
273 // Default to left. 278 // Default to left.
274 default: 279 default:
275 args->Append(Value::CreateStringValue("left")); 280 args->Append(Value::CreateStringValue("left"));
276 break; 281 break;
277 } 282 }
278 283
279 extensions::ExtensionSystem::Get(profile_)->event_router()-> 284 DispatchEventToExtension(profile_, extension_id_,
280 DispatchEventToExtension(extension_id_, events::kOnCandidateClicked, 285 events::kOnCandidateClicked, args.Pass());
281 args.Pass(), profile_, GURL());
282 } 286 }
283 287
284 virtual void OnMenuItemActivated(const std::string& engine_id, 288 virtual void OnMenuItemActivated(const std::string& engine_id,
285 const std::string& menu_id) OVERRIDE { 289 const std::string& menu_id) OVERRIDE {
286 if (profile_ == NULL || extension_id_.empty()) 290 if (profile_ == NULL || extension_id_.empty())
287 return; 291 return;
288 292
289 scoped_ptr<base::ListValue> args(new ListValue()); 293 scoped_ptr<base::ListValue> args(new ListValue());
290 args->Append(Value::CreateStringValue(engine_id)); 294 args->Append(Value::CreateStringValue(engine_id));
291 args->Append(Value::CreateStringValue(menu_id)); 295 args->Append(Value::CreateStringValue(menu_id));
292 296
293 extensions::ExtensionSystem::Get(profile_)->event_router()-> 297 DispatchEventToExtension(profile_, extension_id_,
294 DispatchEventToExtension(extension_id_, events::kOnMenuItemActivated, 298 events::kOnMenuItemActivated, args.Pass());
295 args.Pass(), profile_, GURL());
296 } 299 }
297 300
298 private: 301 private:
299 Profile* profile_; 302 Profile* profile_;
300 std::string extension_id_; 303 std::string extension_id_;
301 std::string engine_id_; 304 std::string engine_id_;
302 305
303 DISALLOW_COPY_AND_ASSIGN(ImeObserver); 306 DISALLOW_COPY_AND_ASSIGN(ImeObserver);
304 }; 307 };
305 308
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &handled)); 831 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &handled));
829 832
830 InputImeEventRouter::GetInstance()->OnKeyEventHandled( 833 InputImeEventRouter::GetInstance()->OnKeyEventHandled(
831 extension_id(), request_id_str, handled); 834 extension_id(), request_id_str, handled);
832 835
833 return true; 836 return true;
834 } 837 }
835 #endif 838 #endif
836 839
837 } // namespace extensions 840 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/idle/idle_manager.cc ('k') | chrome/browser/extensions/api/managed_mode/managed_mode_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698