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. 4 5 #include "ui/keyboard/keyboard_ui_handler.h" 6 7 #include <string> 8 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" 17 18 namespace keyboard { 19 20 KeyboardUIHandler::KeyboardUIHandler() { 21 } 22 23 KeyboardUIHandler::~KeyboardUIHandler() { 24 } 25 26 void KeyboardUIHandler::RegisterMessages() { 27 web_ui()->RegisterMessageCallback( 28 "insertText", 29 base::Bind(&KeyboardUIHandler::HandleInsertTextMessage, 30 base::Unretained(this))); 31 } 32 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; 38 } 39 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; 45 } 46 47 if (!keyboard::InsertText(text, root_window)) 48 LOG(ERROR) << "insertText failed"; 49 } 50 51 } // namespace keyboard 52