BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / chromeos / extensions / input_method_event_router.cc
blobf6ad3ac2ab3f446e610f35340eb4cfe89a7f56c6
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 "chrome/browser/profiles/profile.h"
13 #include "content/public/browser/browser_context.h"
14 #include "extensions/browser/event_router.h"
15 #include "extensions/browser/extension_system.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 Profile* profile,
32 bool show_message) {
33 // This should probably be CHECK, as delivering event to a wrong
34 // profile means delivering it to a wrong extension instance.
35 DCHECK(profile->IsSameProfile(Profile::FromBrowserContext(context_)));
36 extensions::EventRouter* router = extensions::EventRouter::Get(context_);
38 if (!router->HasEventListener(
39 extensions::InputMethodAPI::kOnInputMethodChanged)) {
40 return;
43 scoped_ptr<base::ListValue> args(new base::ListValue());
44 base::StringValue* input_method_name =
45 new base::StringValue(extensions::InputMethodAPI::GetInputMethodForXkb(
46 manager->GetActiveIMEState()->GetCurrentInputMethod().id()));
47 args->Append(input_method_name);
49 // The router will only send the event to extensions that are listening.
50 scoped_ptr<extensions::Event> event(new extensions::Event(
51 extensions::events::INPUT_METHOD_PRIVATE_ON_CHANGED,
52 extensions::InputMethodAPI::kOnInputMethodChanged, args.Pass()));
53 event->restrict_to_browser_context = context_;
54 router->BroadcastEvent(event.Pass());
57 } // namespace chromeos