| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/api/input/input.h" | 5 #include "chrome/browser/extensions/api/input/input.h" |
| 6 | 6 |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 10 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/strings/string16.h" |
| 11 #include "chrome/browser/extensions/extension_function_registry.h" | 10 #include "chrome/browser/extensions/extension_function_registry.h" |
| 12 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 13 #include "ui/base/events/event.h" | 12 #include "ui/base/events/event.h" |
| 14 | 13 |
| 15 #if defined(USE_ASH) | 14 #if defined(USE_ASH) |
| 16 #include "ash/shell.h" | 15 #include "ash/shell.h" |
| 17 #include "ui/aura/root_window.h" | |
| 18 #include "ui/keyboard/keyboard_util.h" | 16 #include "ui/keyboard/keyboard_util.h" |
| 19 #endif | 17 #endif |
| 20 | 18 |
| 21 namespace { | 19 namespace { |
| 22 | 20 |
| 23 const char kNotYetImplementedError[] = | 21 const char kNotYetImplementedError[] = |
| 24 "API is not implemented on this platform."; | 22 "API is not implemented on this platform."; |
| 25 | 23 |
| 26 } // namespace | 24 } // namespace |
| 27 | 25 |
| 28 namespace extensions { | 26 namespace extensions { |
| 29 | 27 |
| 30 bool SendKeyboardEventInputFunction::RunImpl() { | 28 bool InsertTextInputFunction::RunImpl() { |
| 31 #if defined(USE_ASH) | 29 #if defined(USE_ASH) |
| 32 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 30 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 33 | 31 |
| 34 scoped_ptr<ui::KeyEvent> event( | 32 string16 text; |
| 35 keyboard::KeyEventFromArgs(args_.get(), &error_)); | 33 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &text)); |
| 36 if (!event) | |
| 37 return false; | |
| 38 | 34 |
| 39 ash::Shell::GetActiveRootWindow()->AsRootWindowHostDelegate()->OnHostKeyEvent( | 35 return keyboard::InsertText(text, ash::Shell::GetPrimaryRootWindow()); |
| 40 event.get()); | |
| 41 | |
| 42 return true; | |
| 43 #endif | 36 #endif |
| 44 error_ = kNotYetImplementedError; | 37 error_ = kNotYetImplementedError; |
| 45 return false; | 38 return false; |
| 46 } | 39 } |
| 47 | 40 |
| 48 InputAPI::InputAPI(Profile* profile) { | 41 InputAPI::InputAPI(Profile* profile) { |
| 49 ExtensionFunctionRegistry* registry = | 42 ExtensionFunctionRegistry* registry = |
| 50 ExtensionFunctionRegistry::GetInstance(); | 43 ExtensionFunctionRegistry::GetInstance(); |
| 51 registry->RegisterFunction<SendKeyboardEventInputFunction>(); | 44 registry->RegisterFunction<InsertTextInputFunction>(); |
| 52 } | 45 } |
| 53 | 46 |
| 54 InputAPI::~InputAPI() { | 47 InputAPI::~InputAPI() { |
| 55 } | 48 } |
| 56 | 49 |
| 57 static base::LazyInstance<ProfileKeyedAPIFactory<InputAPI> > | 50 static base::LazyInstance<ProfileKeyedAPIFactory<InputAPI> > |
| 58 g_factory = LAZY_INSTANCE_INITIALIZER; | 51 g_factory = LAZY_INSTANCE_INITIALIZER; |
| 59 | 52 |
| 60 // static | 53 // static |
| 61 ProfileKeyedAPIFactory<InputAPI>* InputAPI::GetFactoryInstance() { | 54 ProfileKeyedAPIFactory<InputAPI>* InputAPI::GetFactoryInstance() { |
| 62 return &g_factory.Get(); | 55 return &g_factory.Get(); |
| 63 } | 56 } |
| 64 | 57 |
| 65 } // namespace extensions | 58 } // namespace extensions |
| OLD | NEW |