summaryrefslogtreecommitdiffstats
path: root/ui/keyboard/keyboard_ui_handler.cc
blob: 291f3a05f4cee02bf4feb7bbd6b99dd89e0b16dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/keyboard/keyboard_ui_handler.h"

#include <string>

#include "base/bind.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_view.h"
#include "content/public/browser/web_ui.h"
#include "ui/aura/root_window.h"
#include "ui/base/events/event.h"
#include "ui/keyboard/keyboard_util.h"

namespace keyboard {

KeyboardUIHandler::KeyboardUIHandler() {
}

KeyboardUIHandler::~KeyboardUIHandler() {
}

void KeyboardUIHandler::RegisterMessages() {
  web_ui()->RegisterMessageCallback(
      "sendKeyEvent",
      base::Bind(&KeyboardUIHandler::HandleSendKeyEventMessage,
                 base::Unretained(this)));
}

void KeyboardUIHandler::HandleSendKeyEventMessage(const base::ListValue* args) {
  std::string error;
  scoped_ptr<ui::KeyEvent> event(keyboard::KeyEventFromArgs(args, &error));
  if (!event) {
    LOG(ERROR) << "sendKeyEvent failed: " << error;
    return;
  }

  aura::RootWindow* root_window =
      web_ui()->GetWebContents()->GetView()->GetNativeView()->GetRootWindow();
  root_window->AsRootWindowHostDelegate()->OnHostKeyEvent(event.get());
}

}  // namespace keyboard