Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / extensions / input_method_event_router.cc
blob5f061bcda35347b46b3a21b53c38cc1d193554dc
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 "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 "chrome/browser/extensions/event_names.h"
13 #include "chrome/browser/extensions/extension_system.h"
14 #include "content/public/browser/browser_context.h"
15 #include "extensions/browser/event_router.h"
17 namespace chromeos {
19 ExtensionInputMethodEventRouter::ExtensionInputMethodEventRouter(
20 content::BrowserContext* context)
21 : context_(context) {
22 input_method::InputMethodManager::Get()->AddObserver(this);
25 ExtensionInputMethodEventRouter::~ExtensionInputMethodEventRouter() {
26 input_method::InputMethodManager::Get()->RemoveObserver(this);
29 void ExtensionInputMethodEventRouter::InputMethodChanged(
30 input_method::InputMethodManager *manager,
31 bool show_message) {
32 extensions::EventRouter *router =
33 extensions::ExtensionSystem::GetForBrowserContext(context_)->
34 event_router();
36 if (!router->HasEventListener(extensions::event_names::kOnInputMethodChanged))
37 return;
39 scoped_ptr<base::ListValue> args(new base::ListValue());
40 base::StringValue *input_method_name = new base::StringValue(
41 extensions::InputMethodAPI::GetInputMethodForXkb(
42 manager->GetCurrentInputMethod().id()));
43 args->Append(input_method_name);
45 // The router will only send the event to extensions that are listening.
46 scoped_ptr<extensions::Event> event(new extensions::Event(
47 extensions::event_names::kOnInputMethodChanged, args.Pass()));
48 event->restrict_to_browser_context = context_;
49 router->BroadcastEvent(event.Pass());
52 } // namespace chromeos