OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/extensions/ime_menu_event_router.h" |
| 6 |
| 7 #include "base/values.h" |
| 8 #include "chrome/browser/chromeos/extensions/input_method_api.h" |
| 9 #include "chrome/common/extensions/api/input_method_private.h" |
| 10 #include "content/public/browser/browser_context.h" |
| 11 #include "extensions/browser/event_router.h" |
| 12 |
| 13 namespace OnImeMenuActivationChanged = |
| 14 extensions::api::input_method_private::OnImeMenuActivationChanged; |
| 15 |
| 16 namespace chromeos { |
| 17 |
| 18 ExtensionImeMenuEventRouter::ExtensionImeMenuEventRouter( |
| 19 content::BrowserContext* context) |
| 20 : context_(context) { |
| 21 input_method::InputMethodManager::Get()->AddImeMenuObserver(this); |
| 22 } |
| 23 |
| 24 ExtensionImeMenuEventRouter::~ExtensionImeMenuEventRouter() { |
| 25 input_method::InputMethodManager::Get()->RemoveImeMenuObserver(this); |
| 26 } |
| 27 |
| 28 void ExtensionImeMenuEventRouter::ImeMenuActivationChanged(bool activation) { |
| 29 extensions::EventRouter* router = extensions::EventRouter::Get(context_); |
| 30 |
| 31 if (!router->HasEventListener(OnImeMenuActivationChanged::kEventName)) |
| 32 return; |
| 33 |
| 34 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 35 args->AppendBoolean(activation); |
| 36 |
| 37 // The router will only send the event to extensions that are listening. |
| 38 scoped_ptr<extensions::Event> event(new extensions::Event( |
| 39 extensions::events::INPUT_METHOD_PRIVATE_ON_IME_MENU_ACTIVATION_CHANGED, |
| 40 OnImeMenuActivationChanged::kEventName, std::move(args))); |
| 41 event->restrict_to_browser_context = context_; |
| 42 router->BroadcastEvent(std::move(event)); |
| 43 } |
| 44 |
| 45 } // namespace chromeos |
OLD | NEW |