| 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 10 matching lines...) Expand all Loading... |
| 21 input_method::InputMethodManager::Get()->AddObserver(this); | 21 input_method::InputMethodManager::Get()->AddObserver(this); |
| 22 } | 22 } |
| 23 | 23 |
| 24 ExtensionInputMethodEventRouter::~ExtensionInputMethodEventRouter() { | 24 ExtensionInputMethodEventRouter::~ExtensionInputMethodEventRouter() { |
| 25 input_method::InputMethodManager::Get()->RemoveObserver(this); | 25 input_method::InputMethodManager::Get()->RemoveObserver(this); |
| 26 } | 26 } |
| 27 | 27 |
| 28 void ExtensionInputMethodEventRouter::InputMethodChanged( | 28 void ExtensionInputMethodEventRouter::InputMethodChanged( |
| 29 input_method::InputMethodManager *manager, | 29 input_method::InputMethodManager *manager, |
| 30 bool show_message) { | 30 bool show_message) { |
| 31 extensions::EventRouter *router = | 31 extensions::EventRouter* router = extensions::EventRouter::Get(context_); |
| 32 extensions::ExtensionSystem::Get(context_)->event_router(); | |
| 33 | 32 |
| 34 if (!router->HasEventListener( | 33 if (!router->HasEventListener( |
| 35 extensions::InputMethodAPI::kOnInputMethodChanged)) { | 34 extensions::InputMethodAPI::kOnInputMethodChanged)) { |
| 36 return; | 35 return; |
| 37 } | 36 } |
| 38 | 37 |
| 39 scoped_ptr<base::ListValue> args(new base::ListValue()); | 38 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 40 base::StringValue *input_method_name = new base::StringValue( | 39 base::StringValue *input_method_name = new base::StringValue( |
| 41 extensions::InputMethodAPI::GetInputMethodForXkb( | 40 extensions::InputMethodAPI::GetInputMethodForXkb( |
| 42 manager->GetCurrentInputMethod().id())); | 41 manager->GetCurrentInputMethod().id())); |
| 43 args->Append(input_method_name); | 42 args->Append(input_method_name); |
| 44 | 43 |
| 45 // The router will only send the event to extensions that are listening. | 44 // The router will only send the event to extensions that are listening. |
| 46 scoped_ptr<extensions::Event> event(new extensions::Event( | 45 scoped_ptr<extensions::Event> event(new extensions::Event( |
| 47 extensions::InputMethodAPI::kOnInputMethodChanged, args.Pass())); | 46 extensions::InputMethodAPI::kOnInputMethodChanged, args.Pass())); |
| 48 event->restrict_to_browser_context = context_; | 47 event->restrict_to_browser_context = context_; |
| 49 router->BroadcastEvent(event.Pass()); | 48 router->BroadcastEvent(event.Pass()); |
| 50 } | 49 } |
| 51 | 50 |
| 52 } // namespace chromeos | 51 } // namespace chromeos |
| OLD | NEW |