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 "input_method_event_router.h" | 5 #include "input_method_event_router.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 | 25 |
26 ExtensionInputMethodEventRouter::ExtensionInputMethodEventRouter() { | 26 ExtensionInputMethodEventRouter::ExtensionInputMethodEventRouter() { |
27 input_method::InputMethodManager::GetInstance()->AddObserver(this); | 27 input_method::InputMethodManager::GetInstance()->AddObserver(this); |
28 } | 28 } |
29 | 29 |
30 ExtensionInputMethodEventRouter::~ExtensionInputMethodEventRouter() { | 30 ExtensionInputMethodEventRouter::~ExtensionInputMethodEventRouter() { |
31 input_method::InputMethodManager::GetInstance()->RemoveObserver(this); | 31 input_method::InputMethodManager::GetInstance()->RemoveObserver(this); |
32 } | 32 } |
33 | 33 |
34 void ExtensionInputMethodEventRouter::InputMethodChanged( | 34 void ExtensionInputMethodEventRouter::InputMethodChanged( |
35 input_method::InputMethodManager *manager, | 35 input_method::InputMethodManager *manager) { |
36 const input_method::InputMethodDescriptor ¤t_input_method, | |
37 size_t num_active_input_methods) { | |
38 Profile *profile = ProfileManager::GetDefaultProfile(); | 36 Profile *profile = ProfileManager::GetDefaultProfile(); |
39 ExtensionEventRouter *router = profile->GetExtensionEventRouter(); | 37 ExtensionEventRouter *router = profile->GetExtensionEventRouter(); |
40 | 38 |
41 if (!router->HasEventListener(extension_event_names::kOnInputMethodChanged)) | 39 if (!router->HasEventListener(extension_event_names::kOnInputMethodChanged)) |
42 return; | 40 return; |
43 | 41 |
44 ListValue args; | 42 ListValue args; |
45 StringValue *input_method_name = | 43 StringValue *input_method_name = new StringValue( |
46 new StringValue(GetInputMethodForXkb(current_input_method.id())); | 44 GetInputMethodForXkb(manager->GetCurrentInputMethod().id())); |
47 args.Append(input_method_name); | 45 args.Append(input_method_name); |
48 std::string args_json; | 46 std::string args_json; |
49 base::JSONWriter::Write(&args, &args_json); | 47 base::JSONWriter::Write(&args, &args_json); |
50 | 48 |
51 // The router will only send the event to extensions that are listening. | 49 // The router will only send the event to extensions that are listening. |
52 router->DispatchEventToRenderers( | 50 router->DispatchEventToRenderers( |
53 extension_event_names::kOnInputMethodChanged, | 51 extension_event_names::kOnInputMethodChanged, |
54 args_json, profile, GURL()); | 52 args_json, profile, GURL()); |
55 } | 53 } |
56 | 54 |
57 void ExtensionInputMethodEventRouter::ActiveInputMethodsChanged( | |
58 input_method::InputMethodManager *manager, | |
59 const input_method::InputMethodDescriptor ¤t_input_method, | |
60 size_t num_active_input_methods) { | |
61 } | |
62 | |
63 void ExtensionInputMethodEventRouter::PropertyListChanged( | |
64 input_method::InputMethodManager *manager, | |
65 const input_method::InputMethodPropertyList ¤t_ime_properties) { | |
66 } | |
67 | |
68 std::string ExtensionInputMethodEventRouter::GetInputMethodForXkb( | 55 std::string ExtensionInputMethodEventRouter::GetInputMethodForXkb( |
69 const std::string& xkb_id) { | 56 const std::string& xkb_id) { |
70 size_t prefix_length = std::string(kXkbPrefix).length(); | 57 size_t prefix_length = std::string(kXkbPrefix).length(); |
71 DCHECK(xkb_id.substr(0, prefix_length) == kXkbPrefix); | 58 DCHECK(xkb_id.substr(0, prefix_length) == kXkbPrefix); |
72 return xkb_id.substr(prefix_length); | 59 return xkb_id.substr(prefix_length); |
73 } | 60 } |
74 | 61 |
75 } // namespace chromeos | 62 } // namespace chromeos |
OLD | NEW |