| 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 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 if (!router->HasEventListener(extensions::event_names::kOnInputMethodChanged)) | 42 if (!router->HasEventListener(extensions::event_names::kOnInputMethodChanged)) |
| 43 return; | 43 return; |
| 44 | 44 |
| 45 scoped_ptr<ListValue> args(new ListValue()); | 45 scoped_ptr<ListValue> args(new ListValue()); |
| 46 StringValue *input_method_name = new StringValue( | 46 StringValue *input_method_name = new StringValue( |
| 47 GetInputMethodForXkb(manager->GetCurrentInputMethod().id())); | 47 GetInputMethodForXkb(manager->GetCurrentInputMethod().id())); |
| 48 args->Append(input_method_name); | 48 args->Append(input_method_name); |
| 49 | 49 |
| 50 // 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. |
| 51 router->DispatchEventToRenderers( | 51 scoped_ptr<extensions::Event> event(new extensions::Event( |
| 52 extensions::event_names::kOnInputMethodChanged, args.Pass(), profile, | 52 extensions::event_names::kOnInputMethodChanged, args.Pass())); |
| 53 GURL()); | 53 event->restrict_to_profile = profile; |
| 54 extensions::ExtensionSystem::Get(profile)->event_router()-> |
| 55 BroadcastEvent(event.Pass()); |
| 54 } | 56 } |
| 55 | 57 |
| 56 std::string ExtensionInputMethodEventRouter::GetInputMethodForXkb( | 58 std::string ExtensionInputMethodEventRouter::GetInputMethodForXkb( |
| 57 const std::string& xkb_id) { | 59 const std::string& xkb_id) { |
| 58 size_t prefix_length = std::string(kXkbPrefix).length(); | 60 size_t prefix_length = std::string(kXkbPrefix).length(); |
| 59 DCHECK(xkb_id.substr(0, prefix_length) == kXkbPrefix); | 61 DCHECK(xkb_id.substr(0, prefix_length) == kXkbPrefix); |
| 60 return xkb_id.substr(prefix_length); | 62 return xkb_id.substr(prefix_length); |
| 61 } | 63 } |
| 62 | 64 |
| 63 } // namespace chromeos | 65 } // namespace chromeos |
| OLD | NEW |