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

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

Issue 11232066: Remove GetExtensionEventRouter from Profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rerebase Created 8 years, 1 month 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"
11 #include "chrome/browser/chromeos/input_method/input_method_engine.h" 11 #include "chrome/browser/chromeos/input_method/input_method_engine.h"
12 #include "chrome/browser/extensions/event_router.h" 12 #include "chrome/browser/extensions/event_router.h"
13 #include "chrome/browser/extensions/extension_input_module_constants.h" 13 #include "chrome/browser/extensions/extension_input_module_constants.h"
14 #include "chrome/browser/extensions/extension_system.h"
14 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
15 16
16 namespace keys = extension_input_module_constants; 17 namespace keys = extension_input_module_constants;
17 18
18 namespace { 19 namespace {
19 20
20 const char kStyleNone[] = "none"; 21 const char kStyleNone[] = "none";
21 const char kStyleCheck[] = "check"; 22 const char kStyleCheck[] = "check";
22 const char kStyleRadio[] = "radio"; 23 const char kStyleRadio[] = "radio";
23 const char kStyleSeparator[] = "separator"; 24 const char kStyleSeparator[] = "separator";
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 152
152 virtual ~ImeObserver() {} 153 virtual ~ImeObserver() {}
153 154
154 virtual void OnActivate(const std::string& engine_id) { 155 virtual void OnActivate(const std::string& engine_id) {
155 if (profile_ == NULL || extension_id_.empty()) 156 if (profile_ == NULL || extension_id_.empty())
156 return; 157 return;
157 158
158 scoped_ptr<base::ListValue> args(new ListValue()); 159 scoped_ptr<base::ListValue> args(new ListValue());
159 args->Append(Value::CreateStringValue(engine_id)); 160 args->Append(Value::CreateStringValue(engine_id));
160 161
161 profile_->GetExtensionEventRouter()->DispatchEventToExtension( 162 extensions::ExtensionSystem::Get(profile_)->event_router()->
162 extension_id_, events::kOnActivate, args.Pass(), profile_, GURL()); 163 DispatchEventToExtension(extension_id_, events::kOnActivate,
164 args.Pass(), profile_, GURL());
163 } 165 }
164 166
165 virtual void OnDeactivated(const std::string& engine_id) { 167 virtual void OnDeactivated(const std::string& engine_id) {
166 if (profile_ == NULL || extension_id_.empty()) 168 if (profile_ == NULL || extension_id_.empty())
167 return; 169 return;
168 170
169 scoped_ptr<base::ListValue> args(new ListValue()); 171 scoped_ptr<base::ListValue> args(new ListValue());
170 args->Append(Value::CreateStringValue(engine_id)); 172 args->Append(Value::CreateStringValue(engine_id));
171 173
172 profile_->GetExtensionEventRouter()->DispatchEventToExtension( 174 extensions::ExtensionSystem::Get(profile_)->event_router()->
173 extension_id_, events::kOnDeactivated, args.Pass(), profile_, GURL()); 175 DispatchEventToExtension(extension_id_, events::kOnDeactivated,
176 args.Pass(), profile_, GURL());
174 } 177 }
175 178
176 virtual void OnFocus(const InputMethodEngine::InputContext& context) { 179 virtual void OnFocus(const InputMethodEngine::InputContext& context) {
177 if (profile_ == NULL || extension_id_.empty()) 180 if (profile_ == NULL || extension_id_.empty())
178 return; 181 return;
179 182
180 DictionaryValue* dict = new DictionaryValue(); 183 DictionaryValue* dict = new DictionaryValue();
181 dict->SetInteger("contextID", context.id); 184 dict->SetInteger("contextID", context.id);
182 dict->SetString("type", context.type); 185 dict->SetString("type", context.type);
183 186
184 scoped_ptr<base::ListValue> args(new ListValue()); 187 scoped_ptr<base::ListValue> args(new ListValue());
185 args->Append(dict); 188 args->Append(dict);
186 189
187 profile_->GetExtensionEventRouter()->DispatchEventToExtension( 190 extensions::ExtensionSystem::Get(profile_)->event_router()->
188 extension_id_, events::kOnFocus, args.Pass(), profile_, GURL()); 191 DispatchEventToExtension(extension_id_, events::kOnFocus,
192 args.Pass(), profile_, GURL());
189 } 193 }
190 194
191 virtual void OnBlur(int context_id) { 195 virtual void OnBlur(int context_id) {
192 if (profile_ == NULL || extension_id_.empty()) 196 if (profile_ == NULL || extension_id_.empty())
193 return; 197 return;
194 198
195 scoped_ptr<base::ListValue> args(new ListValue()); 199 scoped_ptr<base::ListValue> args(new ListValue());
196 args->Append(Value::CreateIntegerValue(context_id)); 200 args->Append(Value::CreateIntegerValue(context_id));
197 201
198 profile_->GetExtensionEventRouter()->DispatchEventToExtension( 202 extensions::ExtensionSystem::Get(profile_)->event_router()->
199 extension_id_, events::kOnBlur, args.Pass(), profile_, GURL()); 203 DispatchEventToExtension(extension_id_, events::kOnBlur,
204 args.Pass(), profile_, GURL());
200 } 205 }
201 206
202 virtual void OnInputContextUpdate( 207 virtual void OnInputContextUpdate(
203 const InputMethodEngine::InputContext& context) { 208 const InputMethodEngine::InputContext& context) {
204 if (profile_ == NULL || extension_id_.empty()) 209 if (profile_ == NULL || extension_id_.empty())
205 return; 210 return;
206 211
207 DictionaryValue* dict = new DictionaryValue(); 212 DictionaryValue* dict = new DictionaryValue();
208 dict->SetInteger("contextID", context.id); 213 dict->SetInteger("contextID", context.id);
209 dict->SetString("type", context.type); 214 dict->SetString("type", context.type);
210 215
211 scoped_ptr<base::ListValue> args(new ListValue()); 216 scoped_ptr<base::ListValue> args(new ListValue());
212 args->Append(dict); 217 args->Append(dict);
213 218
214 profile_->GetExtensionEventRouter()->DispatchEventToExtension( 219 extensions::ExtensionSystem::Get(profile_)->event_router()->
215 extension_id_, events::kOnInputContextUpdate, args.Pass(), profile_, 220 DispatchEventToExtension(extension_id_, events::kOnInputContextUpdate,
216 GURL()); 221 args.Pass(), profile_, GURL());
217 } 222 }
218 223
219 virtual void OnKeyEvent(const std::string& engine_id, 224 virtual void OnKeyEvent(const std::string& engine_id,
220 const InputMethodEngine::KeyboardEvent& event, 225 const InputMethodEngine::KeyboardEvent& event,
221 chromeos::input_method::KeyEventHandle* key_data) { 226 chromeos::input_method::KeyEventHandle* key_data) {
222 if (profile_ == NULL || extension_id_.empty()) 227 if (profile_ == NULL || extension_id_.empty())
223 return; 228 return;
224 229
225 std::string request_id = 230 std::string request_id =
226 extensions::InputImeEventRouter::GetInstance()->AddRequest(engine_id, 231 extensions::InputImeEventRouter::GetInstance()->AddRequest(engine_id,
227 key_data); 232 key_data);
228 233
229 DictionaryValue* dict = new DictionaryValue(); 234 DictionaryValue* dict = new DictionaryValue();
230 dict->SetString("type", event.type); 235 dict->SetString("type", event.type);
231 dict->SetString("requestId", request_id); 236 dict->SetString("requestId", request_id);
232 dict->SetString("key", event.key); 237 dict->SetString("key", event.key);
233 dict->SetBoolean("altKey", event.alt_key); 238 dict->SetBoolean("altKey", event.alt_key);
234 dict->SetBoolean("ctrlKey", event.ctrl_key); 239 dict->SetBoolean("ctrlKey", event.ctrl_key);
235 dict->SetBoolean("shiftKey", event.shift_key); 240 dict->SetBoolean("shiftKey", event.shift_key);
236 241
237 scoped_ptr<base::ListValue> args(new ListValue()); 242 scoped_ptr<base::ListValue> args(new ListValue());
238 args->Append(Value::CreateStringValue(engine_id)); 243 args->Append(Value::CreateStringValue(engine_id));
239 args->Append(dict); 244 args->Append(dict);
240 245
241 profile_->GetExtensionEventRouter()->DispatchEventToExtension( 246 extensions::ExtensionSystem::Get(profile_)->event_router()->
242 extension_id_, events::kOnKeyEvent, args.Pass(), profile_, GURL()); 247 DispatchEventToExtension(extension_id_, events::kOnKeyEvent,
248 args.Pass(), profile_, GURL());
243 } 249 }
244 250
245 virtual void OnCandidateClicked( 251 virtual void OnCandidateClicked(
246 const std::string& engine_id, 252 const std::string& engine_id,
247 int candidate_id, 253 int candidate_id,
248 chromeos::InputMethodEngine::MouseButtonEvent button) { 254 chromeos::InputMethodEngine::MouseButtonEvent button) {
249 if (profile_ == NULL || extension_id_.empty()) 255 if (profile_ == NULL || extension_id_.empty())
250 return; 256 return;
251 257
252 scoped_ptr<base::ListValue> args(new ListValue()); 258 scoped_ptr<base::ListValue> args(new ListValue());
253 args->Append(Value::CreateStringValue(engine_id)); 259 args->Append(Value::CreateStringValue(engine_id));
254 args->Append(Value::CreateIntegerValue(candidate_id)); 260 args->Append(Value::CreateIntegerValue(candidate_id));
255 switch (button) { 261 switch (button) {
256 case chromeos::InputMethodEngine::MOUSE_BUTTON_MIDDLE: 262 case chromeos::InputMethodEngine::MOUSE_BUTTON_MIDDLE:
257 args->Append(Value::CreateStringValue("middle")); 263 args->Append(Value::CreateStringValue("middle"));
258 break; 264 break;
259 265
260 case chromeos::InputMethodEngine::MOUSE_BUTTON_RIGHT: 266 case chromeos::InputMethodEngine::MOUSE_BUTTON_RIGHT:
261 args->Append(Value::CreateStringValue("right")); 267 args->Append(Value::CreateStringValue("right"));
262 break; 268 break;
263 269
264 case chromeos::InputMethodEngine::MOUSE_BUTTON_LEFT: 270 case chromeos::InputMethodEngine::MOUSE_BUTTON_LEFT:
265 // Default to left. 271 // Default to left.
266 default: 272 default:
267 args->Append(Value::CreateStringValue("left")); 273 args->Append(Value::CreateStringValue("left"));
268 break; 274 break;
269 } 275 }
270 276
271 profile_->GetExtensionEventRouter()->DispatchEventToExtension( 277 extensions::ExtensionSystem::Get(profile_)->event_router()->
272 extension_id_, events::kOnCandidateClicked, args.Pass(), profile_, 278 DispatchEventToExtension(extension_id_, events::kOnCandidateClicked,
273 GURL()); 279 args.Pass(), profile_, GURL());
274 } 280 }
275 281
276 virtual void OnMenuItemActivated(const std::string& engine_id, 282 virtual void OnMenuItemActivated(const std::string& engine_id,
277 const std::string& menu_id) { 283 const std::string& menu_id) {
278 if (profile_ == NULL || extension_id_.empty()) 284 if (profile_ == NULL || extension_id_.empty())
279 return; 285 return;
280 286
281 scoped_ptr<base::ListValue> args(new ListValue()); 287 scoped_ptr<base::ListValue> args(new ListValue());
282 args->Append(Value::CreateStringValue(engine_id)); 288 args->Append(Value::CreateStringValue(engine_id));
283 args->Append(Value::CreateStringValue(menu_id)); 289 args->Append(Value::CreateStringValue(menu_id));
284 290
285 profile_->GetExtensionEventRouter()->DispatchEventToExtension( 291 extensions::ExtensionSystem::Get(profile_)->event_router()->
286 extension_id_, events::kOnMenuItemActivated, args.Pass(), profile_, 292 DispatchEventToExtension(extension_id_, events::kOnMenuItemActivated,
287 GURL()); 293 args.Pass(), profile_, GURL());
288 } 294 }
289 295
290 private: 296 private:
291 Profile* profile_; 297 Profile* profile_;
292 std::string extension_id_; 298 std::string extension_id_;
293 std::string engine_id_; 299 std::string engine_id_;
294 300
295 DISALLOW_COPY_AND_ASSIGN(ImeObserver); 301 DISALLOW_COPY_AND_ASSIGN(ImeObserver);
296 }; 302 };
297 303
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &handled)); 814 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &handled));
809 815
810 InputImeEventRouter::GetInstance()->OnEventHandled( 816 InputImeEventRouter::GetInstance()->OnEventHandled(
811 extension_id(), request_id_str, handled); 817 extension_id(), request_id_str, handled);
812 818
813 return true; 819 return true;
814 } 820 }
815 #endif 821 #endif
816 822
817 } // namespace extensions 823 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/idle/idle_api.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