Add ENABLE_MEDIA_ROUTER define to builds other than Android and iOS.
[chromium-blink-merge.git] / chrome / browser / chromeos / extensions / input_method_event_router.cc
blob79e4f7303b65926b0b969dcc0cedaee39c39befb
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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/extensions/input_method_event_router.h"
7 #include <algorithm>
9 #include "base/json/json_writer.h"
10 #include "base/values.h"
11 #include "chrome/browser/chromeos/extensions/input_method_api.h"
12 #include "content/public/browser/browser_context.h"
13 #include "extensions/browser/event_router.h"
14 #include "extensions/browser/extension_system.h"
16 namespace chromeos {
18 ExtensionInputMethodEventRouter::ExtensionInputMethodEventRouter(
19 content::BrowserContext* context)
20 : context_(context) {
21 input_method::InputMethodManager::Get()->AddObserver(this);
24 ExtensionInputMethodEventRouter::~ExtensionInputMethodEventRouter() {
25 input_method::InputMethodManager::Get()->RemoveObserver(this);
28 void ExtensionInputMethodEventRouter::InputMethodChanged(
29 input_method::InputMethodManager *manager,
30 bool show_message) {
31 extensions::EventRouter* router = extensions::EventRouter::Get(context_);
33 if (!router->HasEventListener(
34 extensions::InputMethodAPI::kOnInputMethodChanged)) {
35 return;
38 scoped_ptr<base::ListValue> args(new base::ListValue());
39 base::StringValue* input_method_name =
40 new base::StringValue(extensions::InputMethodAPI::GetInputMethodForXkb(
41 manager->GetActiveIMEState()->GetCurrentInputMethod().id()));
42 args->Append(input_method_name);
44 // The router will only send the event to extensions that are listening.
45 scoped_ptr<extensions::Event> event(new extensions::Event(
46 extensions::InputMethodAPI::kOnInputMethodChanged, args.Pass()));
47 event->restrict_to_browser_context = context_;
48 router->BroadcastEvent(event.Pass());
51 } // namespace chromeos