Update .DEPS.git
[chromium-blink-merge.git] / ui / keyboard / keyboard_ui_handler.cc
blob0c412675d3e8d1b8fd12231f6335d858db5945a3
1 // Copyright (c) 2013 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 "ui/keyboard/keyboard_ui_handler.h"
7 #include <string>
9 #include "base/bind.h"
10 #include "base/logging.h"
11 #include "base/values.h"
12 #include "content/public/browser/web_contents.h"
13 #include "content/public/browser/web_contents_view.h"
14 #include "content/public/browser/web_ui.h"
15 #include "ui/aura/window.h"
16 #include "ui/keyboard/keyboard_util.h"
18 namespace keyboard {
20 KeyboardUIHandler::KeyboardUIHandler() {
23 KeyboardUIHandler::~KeyboardUIHandler() {
26 void KeyboardUIHandler::RegisterMessages() {
27 web_ui()->RegisterMessageCallback(
28 "insertText",
29 base::Bind(&KeyboardUIHandler::HandleInsertTextMessage,
30 base::Unretained(this)));
33 void KeyboardUIHandler::HandleInsertTextMessage(const base::ListValue* args) {
34 string16 text;
35 if (!args->GetString(0, &text)) {
36 LOG(ERROR) << "insertText failed: bad argument";
37 return;
40 aura::RootWindow* root_window =
41 web_ui()->GetWebContents()->GetView()->GetNativeView()->GetRootWindow();
42 if (!root_window) {
43 LOG(ERROR) << "insertText failed: no root window";
44 return;
47 if (!keyboard::InsertText(text, root_window))
48 LOG(ERROR) << "insertText failed";
51 } // namespace keyboard