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" |
11 #include "chrome/browser/chromeos/web_socket_proxy_controller.h" | 11 #include "chrome/browser/chromeos/web_socket_proxy_controller.h" |
12 #include "chrome/browser/extensions/event_names.h" | 12 #include "chrome/browser/extensions/event_names.h" |
13 #include "chrome/browser/extensions/event_router.h" | 13 #include "chrome/browser/extensions/event_router.h" |
| 14 #include "chrome/browser/extensions/extension_system.h" |
14 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 // Prefix, which is used by XKB. | 20 // Prefix, which is used by XKB. |
20 const char kXkbPrefix[] = "xkb:"; | 21 const char kXkbPrefix[] = "xkb:"; |
21 | 22 |
22 } // namespace | 23 } // namespace |
23 | 24 |
24 namespace chromeos { | 25 namespace chromeos { |
25 | 26 |
26 ExtensionInputMethodEventRouter::ExtensionInputMethodEventRouter() { | 27 ExtensionInputMethodEventRouter::ExtensionInputMethodEventRouter() { |
27 input_method::InputMethodManager::GetInstance()->AddObserver(this); | 28 input_method::InputMethodManager::GetInstance()->AddObserver(this); |
28 } | 29 } |
29 | 30 |
30 ExtensionInputMethodEventRouter::~ExtensionInputMethodEventRouter() { | 31 ExtensionInputMethodEventRouter::~ExtensionInputMethodEventRouter() { |
31 input_method::InputMethodManager::GetInstance()->RemoveObserver(this); | 32 input_method::InputMethodManager::GetInstance()->RemoveObserver(this); |
32 } | 33 } |
33 | 34 |
34 void ExtensionInputMethodEventRouter::InputMethodChanged( | 35 void ExtensionInputMethodEventRouter::InputMethodChanged( |
35 input_method::InputMethodManager *manager, | 36 input_method::InputMethodManager *manager, |
36 bool show_message) { | 37 bool show_message) { |
37 Profile *profile = ProfileManager::GetDefaultProfile(); | 38 Profile *profile = ProfileManager::GetDefaultProfile(); |
38 extensions::EventRouter *router = profile->GetExtensionEventRouter(); | 39 extensions::EventRouter *router = |
| 40 extensions::ExtensionSystem::Get(profile)->event_router(); |
39 | 41 |
40 if (!router->HasEventListener(extensions::event_names::kOnInputMethodChanged)) | 42 if (!router->HasEventListener(extensions::event_names::kOnInputMethodChanged)) |
41 return; | 43 return; |
42 | 44 |
43 scoped_ptr<ListValue> args(new ListValue()); | 45 scoped_ptr<ListValue> args(new ListValue()); |
44 StringValue *input_method_name = new StringValue( | 46 StringValue *input_method_name = new StringValue( |
45 GetInputMethodForXkb(manager->GetCurrentInputMethod().id())); | 47 GetInputMethodForXkb(manager->GetCurrentInputMethod().id())); |
46 args->Append(input_method_name); | 48 args->Append(input_method_name); |
47 | 49 |
48 // The router will only send the event to extensions that are listening. | 50 // The router will only send the event to extensions that are listening. |
49 router->DispatchEventToRenderers( | 51 router->DispatchEventToRenderers( |
50 extensions::event_names::kOnInputMethodChanged, args.Pass(), profile, | 52 extensions::event_names::kOnInputMethodChanged, args.Pass(), profile, |
51 GURL()); | 53 GURL()); |
52 } | 54 } |
53 | 55 |
54 std::string ExtensionInputMethodEventRouter::GetInputMethodForXkb( | 56 std::string ExtensionInputMethodEventRouter::GetInputMethodForXkb( |
55 const std::string& xkb_id) { | 57 const std::string& xkb_id) { |
56 size_t prefix_length = std::string(kXkbPrefix).length(); | 58 size_t prefix_length = std::string(kXkbPrefix).length(); |
57 DCHECK(xkb_id.substr(0, prefix_length) == kXkbPrefix); | 59 DCHECK(xkb_id.substr(0, prefix_length) == kXkbPrefix); |
58 return xkb_id.substr(prefix_length); | 60 return xkb_id.substr(prefix_length); |
59 } | 61 } |
60 | 62 |
61 } // namespace chromeos | 63 } // namespace chromeos |
OLD | NEW |