OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/memory/scoped_ptr.h" | |
9 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
10 #include "chrome/browser/extensions/extension_function_registry.h" | 9 #include "chrome/browser/extensions/extension_function_registry.h" |
11 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
12 #include "ui/base/events/event.h" | 11 #include "ui/base/events/event.h" |
13 | 12 |
14 #if defined(USE_ASH) | 13 #if defined(USE_ASH) |
15 #include "ash/shell.h" | 14 #include "ash/shell.h" |
16 #include "ui/keyboard/keyboard_util.h" | 15 #include "ui/keyboard/keyboard_util.h" |
17 #endif | 16 #endif |
18 | 17 |
(...skipping 28 matching lines...) Expand all Loading... | |
47 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &swipe_direction)); | 46 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &swipe_direction)); |
48 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(1, &modifier_flags)); | 47 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(1, &modifier_flags)); |
49 | 48 |
50 return keyboard::MoveCursor(swipe_direction, modifier_flags, | 49 return keyboard::MoveCursor(swipe_direction, modifier_flags, |
51 ash::Shell::GetPrimaryRootWindow()); | 50 ash::Shell::GetPrimaryRootWindow()); |
52 #endif | 51 #endif |
53 error_ = kNotYetImplementedError; | 52 error_ = kNotYetImplementedError; |
54 return false; | 53 return false; |
55 } | 54 } |
56 | 55 |
56 bool SendKeyEventFunction::RunImpl() { | |
57 #if defined(USE_ASH) | |
58 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
59 | |
60 base::Value* options_value = NULL; | |
61 base::DictionaryValue* params = NULL; | |
62 std::string type; | |
63 int char_value; | |
64 int key_code; | |
65 bool shift_modifier; | |
66 | |
67 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &options_value)); | |
68 EXTENSION_FUNCTION_VALIDATE(options_value->GetAsDictionary(¶ms)); | |
69 EXTENSION_FUNCTION_VALIDATE(params->GetString("type", &type)); | |
70 EXTENSION_FUNCTION_VALIDATE(params->GetInteger("charValue", &char_value)); | |
71 EXTENSION_FUNCTION_VALIDATE(params->GetInteger("keyCode", &key_code)); | |
72 EXTENSION_FUNCTION_VALIDATE(params->GetBoolean("shiftKey", &shift_modifier)); | |
Matt Perry
2013/09/03 22:33:33
If you use the json schema compiler, you won't hav
| |
73 | |
74 return keyboard::SendKeyEvent(type, | |
75 char_value, | |
76 key_code, | |
77 shift_modifier, | |
78 ash::Shell::GetPrimaryRootWindow()); | |
79 | |
80 #endif | |
81 error_ = kNotYetImplementedError; | |
82 return false; | |
83 } | |
84 | |
57 InputAPI::InputAPI(Profile* profile) { | 85 InputAPI::InputAPI(Profile* profile) { |
58 ExtensionFunctionRegistry* registry = | 86 ExtensionFunctionRegistry* registry = |
59 ExtensionFunctionRegistry::GetInstance(); | 87 ExtensionFunctionRegistry::GetInstance(); |
60 registry->RegisterFunction<InsertTextFunction>(); | 88 registry->RegisterFunction<InsertTextFunction>(); |
61 registry->RegisterFunction<MoveCursorFunction>(); | 89 registry->RegisterFunction<MoveCursorFunction>(); |
90 registry->RegisterFunction<SendKeyEventFunction>(); | |
62 } | 91 } |
63 | 92 |
64 InputAPI::~InputAPI() { | 93 InputAPI::~InputAPI() { |
65 } | 94 } |
66 | 95 |
67 static base::LazyInstance<ProfileKeyedAPIFactory<InputAPI> > | 96 static base::LazyInstance<ProfileKeyedAPIFactory<InputAPI> > |
68 g_factory = LAZY_INSTANCE_INITIALIZER; | 97 g_factory = LAZY_INSTANCE_INITIALIZER; |
69 | 98 |
70 // static | 99 // static |
71 ProfileKeyedAPIFactory<InputAPI>* InputAPI::GetFactoryInstance() { | 100 ProfileKeyedAPIFactory<InputAPI>* InputAPI::GetFactoryInstance() { |
72 return &g_factory.Get(); | 101 return &g_factory.Get(); |
73 } | 102 } |
74 | 103 |
75 } // namespace extensions | 104 } // namespace extensions |
OLD | NEW |