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/chromeos/extensions/input_method_event_router.h" | 5 #include "chrome/browser/chromeos/extensions/input_method_event_router.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/browser/chromeos/extensions/input_method_api.h" | 12 #include "chrome/browser/chromeos/extensions/input_method_api.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/common/extensions/api/input_method_private.h" |
14 #include "content/public/browser/browser_context.h" | 15 #include "content/public/browser/browser_context.h" |
15 #include "extensions/browser/event_router.h" | 16 #include "extensions/browser/event_router.h" |
16 #include "extensions/browser/extension_system.h" | 17 #include "extensions/browser/extension_system.h" |
17 | 18 |
| 19 namespace OnChanged = extensions::api::input_method_private::OnChanged; |
| 20 |
18 namespace chromeos { | 21 namespace chromeos { |
19 | 22 |
20 ExtensionInputMethodEventRouter::ExtensionInputMethodEventRouter( | 23 ExtensionInputMethodEventRouter::ExtensionInputMethodEventRouter( |
21 content::BrowserContext* context) | 24 content::BrowserContext* context) |
22 : context_(context) { | 25 : context_(context) { |
23 input_method::InputMethodManager::Get()->AddObserver(this); | 26 input_method::InputMethodManager::Get()->AddObserver(this); |
24 } | 27 } |
25 | 28 |
26 ExtensionInputMethodEventRouter::~ExtensionInputMethodEventRouter() { | 29 ExtensionInputMethodEventRouter::~ExtensionInputMethodEventRouter() { |
27 input_method::InputMethodManager::Get()->RemoveObserver(this); | 30 input_method::InputMethodManager::Get()->RemoveObserver(this); |
28 } | 31 } |
29 | 32 |
30 void ExtensionInputMethodEventRouter::InputMethodChanged( | 33 void ExtensionInputMethodEventRouter::InputMethodChanged( |
31 input_method::InputMethodManager* manager, | 34 input_method::InputMethodManager* manager, |
32 Profile* profile, | 35 Profile* profile, |
33 bool show_message) { | 36 bool show_message) { |
34 // This should probably be CHECK, as delivering event to a wrong | 37 // This should probably be CHECK, as delivering event to a wrong |
35 // profile means delivering it to a wrong extension instance. | 38 // profile means delivering it to a wrong extension instance. |
36 DCHECK(profile->IsSameProfile(Profile::FromBrowserContext(context_))); | 39 DCHECK(profile->IsSameProfile(Profile::FromBrowserContext(context_))); |
37 extensions::EventRouter* router = extensions::EventRouter::Get(context_); | 40 extensions::EventRouter* router = extensions::EventRouter::Get(context_); |
38 | 41 |
39 if (!router->HasEventListener( | 42 if (!router->HasEventListener(OnChanged::kEventName)) |
40 extensions::InputMethodAPI::kOnInputMethodChanged)) { | |
41 return; | 43 return; |
42 } | |
43 | 44 |
44 scoped_ptr<base::ListValue> args(new base::ListValue()); | 45 scoped_ptr<base::ListValue> args(new base::ListValue()); |
45 args->Append(new base::StringValue( | 46 args->Append(new base::StringValue( |
46 manager->GetActiveIMEState()->GetCurrentInputMethod().id())); | 47 manager->GetActiveIMEState()->GetCurrentInputMethod().id())); |
47 | 48 |
48 // 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. |
49 scoped_ptr<extensions::Event> event(new extensions::Event( | 50 scoped_ptr<extensions::Event> event( |
50 extensions::events::INPUT_METHOD_PRIVATE_ON_CHANGED, | 51 new extensions::Event(extensions::events::INPUT_METHOD_PRIVATE_ON_CHANGED, |
51 extensions::InputMethodAPI::kOnInputMethodChanged, std::move(args))); | 52 OnChanged::kEventName, std::move(args))); |
52 event->restrict_to_browser_context = context_; | 53 event->restrict_to_browser_context = context_; |
53 router->BroadcastEvent(std::move(event)); | 54 router->BroadcastEvent(std::move(event)); |
54 } | 55 } |
55 | 56 |
56 } // namespace chromeos | 57 } // namespace chromeos |
OLD | NEW |