| Index: chrome/browser/extensions/api/input/input.cc
|
| diff --git a/chrome/browser/extensions/api/input/input.cc b/chrome/browser/extensions/api/input/input.cc
|
| index 77d1d64111b4effd0635452f762c06bff9879676..f0eecbeb303d338e25d6c34953cc53bc1d89dcd3 100644
|
| --- a/chrome/browser/extensions/api/input/input.cc
|
| +++ b/chrome/browser/extensions/api/input/input.cc
|
| @@ -7,126 +7,42 @@
|
| #include <string>
|
|
|
| #include "base/lazy_instance.h"
|
| -#include "base/string_util.h"
|
| -#include "base/strings/string_number_conversions.h"
|
| -#include "base/values.h"
|
| +#include "base/memory/scoped_ptr.h"
|
| #include "chrome/browser/extensions/extension_function_registry.h"
|
| -#include "chrome/browser/ui/top_level_widget.h"
|
| -#include "chrome/common/chrome_notification_types.h"
|
| #include "content/public/browser/browser_thread.h"
|
| #include "ui/base/events/event.h"
|
| -#include "ui/base/events/key_identifier_conversion.h"
|
|
|
| -#if defined(USE_ASH) && defined(USE_AURA)
|
| +#if defined(USE_ASH)
|
| #include "ash/shell.h"
|
| #include "ui/aura/root_window.h"
|
| +#include "ui/keyboard/keyboard_util.h"
|
| #endif
|
|
|
| -namespace extensions {
|
| -
|
| namespace {
|
|
|
| -// Keys.
|
| -const char kType[] = "type";
|
| -const char kKeyIdentifier[] = "keyIdentifier";
|
| -const char kAlt[] = "altKey";
|
| -const char kCtrl[] = "ctrlKey";
|
| -const char kMeta[] = "metaKey";
|
| -const char kShift[] = "shiftKey";
|
| -const char kKeyDown[] = "keydown";
|
| -const char kKeyUp[] = "keyup";
|
| -
|
| -// Errors.
|
| -const char kUnknownEventTypeError[] = "Unknown event type.";
|
| -const char kUnknownOrUnsupportedKeyIdentiferError[] = "Unknown or unsupported "
|
| - "key identifier.";
|
| -const char kUnsupportedModifier[] = "Unsupported modifier.";
|
| -const char kNoValidRecipientError[] = "No valid recipient for event.";
|
| -const char kKeyEventUnprocessedError[] = "Event was not handled.";
|
| -
|
| -ui::EventType GetTypeFromString(const std::string& type) {
|
| - if (type == kKeyDown) {
|
| - return ui::ET_KEY_PRESSED;
|
| - } else if (type == kKeyUp) {
|
| - return ui::ET_KEY_RELEASED;
|
| - }
|
| - return ui::ET_UNKNOWN;
|
| -}
|
| -
|
| -// Converts a hex string "U+NNNN" to uint16. Returns 0 on error.
|
| -uint16 UnicodeIdentifierStringToInt(const std::string& key_identifier) {
|
| - int character = 0;
|
| - if ((key_identifier.length() == 6) &&
|
| - (key_identifier.substr(0, 2) == "U+") &&
|
| - (key_identifier.substr(2).find_first_not_of("0123456789abcdefABCDEF") ==
|
| - std::string::npos)) {
|
| - const bool result =
|
| - base::HexStringToInt(key_identifier.substr(2), &character);
|
| - DCHECK(result) << key_identifier;
|
| - }
|
| - return character;
|
| -}
|
| +const char kNotYetImplementedError[] =
|
| + "API is not implemented on this platform.";
|
|
|
| } // namespace
|
|
|
| -bool SendKeyboardEventInputFunction::RunImpl() {
|
| - DictionaryValue* args;
|
| - EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args));
|
| -
|
| - std::string type_name;
|
| - EXTENSION_FUNCTION_VALIDATE(args->GetString(kType, &type_name));
|
| - ui::EventType type = GetTypeFromString(type_name);
|
| - if (type == ui::ET_UNKNOWN) {
|
| - error_ = kUnknownEventTypeError;
|
| - return false;
|
| - }
|
| -
|
| - std::string identifier;
|
| - EXTENSION_FUNCTION_VALIDATE(args->GetString(kKeyIdentifier, &identifier));
|
| - TrimWhitespaceASCII(identifier, TRIM_ALL, &identifier);
|
| +namespace extensions {
|
|
|
| +bool SendKeyboardEventInputFunction::RunImpl() {
|
| +#if defined(USE_ASH)
|
| DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
|
| - const ui::KeyEvent& prototype_event =
|
| - ui::KeyEventFromKeyIdentifier(identifier);
|
| - uint16 character = 0;
|
| - if (prototype_event.key_code() == ui::VKEY_UNKNOWN) {
|
| - // Check if |identifier| is "U+NNNN" format.
|
| - character = UnicodeIdentifierStringToInt(identifier);
|
| - if (!character) {
|
| - error_ = kUnknownOrUnsupportedKeyIdentiferError;
|
| - return false;
|
| - }
|
| - }
|
| -
|
| - bool flag = false;
|
| - int flags = 0;
|
| - if (prototype_event.key_code() != ui::VKEY_UNKNOWN)
|
| - flags = prototype_event.flags();
|
| - flags |= (args->GetBoolean(kAlt, &flag) && flag) ? ui::EF_ALT_DOWN : 0;
|
| - flags |= (args->GetBoolean(kCtrl, &flag) && flag) ? ui::EF_CONTROL_DOWN : 0;
|
| - flags |= (args->GetBoolean(kShift, &flag) && flag) ? ui::EF_SHIFT_DOWN : 0;
|
| - if (args->GetBoolean(kMeta, &flag) && flag) {
|
| - // Views does not have a Meta event flag, so return an error for now.
|
| - error_ = kUnsupportedModifier;
|
| +
|
| + scoped_ptr<ui::KeyEvent> event(
|
| + keyboard::KeyEventFromArgs(args_.get(), &error_));
|
| + if (!event)
|
| return false;
|
| - }
|
| -
|
| - ui::KeyEvent event(type,
|
| - prototype_event.key_code(),
|
| - flags,
|
| - prototype_event.is_char());
|
| - if (character) {
|
| - event.set_character(character);
|
| - event.set_unmodified_character(character);
|
| - }
|
| -
|
| -#if defined(USE_ASH) && defined(USE_AURA)
|
| +
|
| ash::Shell::GetActiveRootWindow()->AsRootWindowHostDelegate()->OnHostKeyEvent(
|
| - &event);
|
| + event.get());
|
| +
|
| return true;
|
| -#else
|
| - return false;
|
| #endif
|
| + error_ = kNotYetImplementedError;
|
| + return false;
|
| }
|
|
|
| InputAPI::InputAPI(Profile* profile) {
|
|
|