Chromium Code Reviews| Index: chrome/browser/automation/testing_automation_provider.cc |
| =================================================================== |
| --- chrome/browser/automation/testing_automation_provider.cc (revision 76851) |
| +++ chrome/browser/automation/testing_automation_provider.cc (working copy) |
| @@ -2262,6 +2262,8 @@ |
| browser_handler_map["SendKeyEventToActiveTab"] = |
| &TestingAutomationProvider::SendKeyEventToActiveTab; |
| + browser_handler_map["SendKeyEventToActiveBrowserWindow"] = |
| + &TestingAutomationProvider::SendKeyEventToActiveBrowserWindow; |
| browser_handler_map["GetNTPThumbnailMode"] = |
| &TestingAutomationProvider::GetNTPThumbnailMode; |
| @@ -4567,99 +4569,161 @@ |
| base::CloseProcessHandle(process); |
| } |
| -void TestingAutomationProvider::SendKeyEventToActiveTab( |
| - Browser* browser, |
| +bool TestingAutomationProvider::BuildNativeWebKeyEventFromArgs( |
| DictionaryValue* args, |
| - IPC::Message* reply_message) { |
| + IPC::Message* reply_message, |
| + NativeWebKeyboardEvent* event) { |
| int type, modifiers; |
| bool is_system_key; |
| string16 unmodified_text, text; |
| std::string key_identifier; |
| - NativeWebKeyboardEvent event; |
| - if (!args->GetInteger("type", &type)) { |
| + if (!args->GetInteger("type", &type)) { |
| AutomationJSONReply reply(this, reply_message); |
| reply.SendError("'type' missing or invalid."); |
| - return; |
| + return false; |
| } |
| if (!args->GetBoolean("isSystemKey", &is_system_key)) { |
| AutomationJSONReply reply(this, reply_message); |
| reply.SendError("'isSystemKey' missing or invalid."); |
| - return; |
| + return false; |
| } |
| if (!args->GetString("unmodifiedText", &unmodified_text)) { |
| AutomationJSONReply reply(this, reply_message); |
| reply.SendError("'unmodifiedText' missing or invalid."); |
| - return; |
| + return false; |
| } |
| if (!args->GetString("text", &text)) { |
| AutomationJSONReply reply(this, reply_message); |
| reply.SendError("'text' missing or invalid."); |
| - return; |
| + return false; |
| } |
| - if (!args->GetInteger("nativeKeyCode", &event.nativeKeyCode)) { |
| + if (!args->GetInteger("nativeKeyCode", &event->nativeKeyCode)) { |
| AutomationJSONReply reply(this, reply_message); |
| reply.SendError("'nativeKeyCode' missing or invalid."); |
| - return; |
| + return false; |
| } |
| - if (!args->GetInteger("windowsKeyCode", &event.windowsKeyCode)) { |
| + if (!args->GetInteger("windowsKeyCode", &event->windowsKeyCode)) { |
| AutomationJSONReply reply(this, reply_message); |
| reply.SendError("'windowsKeyCode' missing or invalid."); |
| - return; |
| + return false; |
| } |
| if (!args->GetInteger("modifiers", &modifiers)) { |
| AutomationJSONReply reply(this, reply_message); |
| reply.SendError("'modifiers' missing or invalid."); |
| - return; |
| + return false; |
| } |
| if (args->GetString("keyIdentifier", &key_identifier)) { |
| - base::strlcpy(event.keyIdentifier, |
| + base::strlcpy(event->keyIdentifier, |
| key_identifier.c_str(), |
| WebKit::WebKeyboardEvent::keyIdentifierLengthCap); |
| } else { |
| - event.setKeyIdentifierFromWindowsKeyCode(); |
| + event->setKeyIdentifierFromWindowsKeyCode(); |
| } |
| if (type == automation::kRawKeyDownType) { |
| - event.type = WebKit::WebInputEvent::RawKeyDown; |
| + event->type = WebKit::WebInputEvent::RawKeyDown; |
| } else if (type == automation::kKeyDownType) { |
| - event.type = WebKit::WebInputEvent::KeyDown; |
| + event->type = WebKit::WebInputEvent::KeyDown; |
| } else if (type == automation::kKeyUpType) { |
| - event.type = WebKit::WebInputEvent::KeyUp; |
| + event->type = WebKit::WebInputEvent::KeyUp; |
| } else if (type == automation::kCharType) { |
| - event.type = WebKit::WebInputEvent::Char; |
| + event->type = WebKit::WebInputEvent::Char; |
| } else { |
| AutomationJSONReply reply(this, reply_message); |
| reply.SendError("'type' refers to an unrecognized keyboard event type"); |
| - return; |
| + return false; |
| } |
| string16 unmodified_text_truncated = unmodified_text.substr( |
| 0, WebKit::WebKeyboardEvent::textLengthCap - 1); |
| - memcpy(event.unmodifiedText, |
| + memcpy(event->unmodifiedText, |
| unmodified_text_truncated.c_str(), |
| unmodified_text_truncated.length() + 1); |
| string16 text_truncated = text.substr( |
| 0, WebKit::WebKeyboardEvent::textLengthCap - 1); |
| - memcpy(event.text, text_truncated.c_str(), text_truncated.length() + 1); |
| + memcpy(event->text, text_truncated.c_str(), text_truncated.length() + 1); |
| - event.modifiers = 0; |
| + event->modifiers = 0; |
| if (modifiers & automation::kShiftKeyMask) |
| - event.modifiers |= WebKit::WebInputEvent::ShiftKey; |
| + event->modifiers |= WebKit::WebInputEvent::ShiftKey; |
| if (modifiers & automation::kControlKeyMask) |
| - event.modifiers |= WebKit::WebInputEvent::ControlKey; |
| + event->modifiers |= WebKit::WebInputEvent::ControlKey; |
| if (modifiers & automation::kAltKeyMask) |
| - event.modifiers |= WebKit::WebInputEvent::AltKey; |
| + event->modifiers |= WebKit::WebInputEvent::AltKey; |
| if (modifiers & automation::kMetaKeyMask) |
| - event.modifiers |= WebKit::WebInputEvent::MetaKey; |
| + event->modifiers |= WebKit::WebInputEvent::MetaKey; |
| - event.isSystemKey = is_system_key; |
| - event.timeStampSeconds = base::Time::Now().ToDoubleT(); |
| - event.skip_in_browser = true; |
| + event->isSystemKey = is_system_key; |
| + event->timeStampSeconds = base::Time::Now().ToDoubleT(); |
| + event->skip_in_browser = true; |
| + return true; |
| +} |
| + |
| +void TestingAutomationProvider::SendKeyEventToActiveTab( |
|
kkania
2011/03/10 00:28:58
This function has changed since a couple days ago.
timothe faudot
2011/03/10 05:34:32
Done.
|
| + Browser* browser, |
| + DictionaryValue* args, |
| + IPC::Message* reply_message) { |
| + NativeWebKeyboardEvent event; |
| + // BuildNativeWebKeyEventFromArgs handles telling what when wrong and sending |
| + // the reply message, if it failed we just have to stop here. |
| + if (!BuildNativeWebKeyEventFromArgs(args, reply_message, &event)) |
| + return; |
| + |
| new InputEventAckNotificationObserver(this, reply_message, event.type); |
| - browser->GetSelectedTabContents()->render_view_host()-> |
| + browser->GetSelectedTabContents()->render_view_host()-> |
|
kkania
2011/03/10 00:28:58
4 space indentation here
timothe faudot
2011/03/10 05:34:32
Done.
|
| ForwardKeyboardEvent(event); |
| + return; |
|
kkania
2011/03/10 00:28:58
remove the extra return
timothe faudot
2011/03/10 05:34:32
Done.
|
| } |
| +void TestingAutomationProvider::SendKeyEventToActiveBrowserWindow( |
| + Browser* browser, |
| + DictionaryValue* args, |
| + IPC::Message* reply_message) { |
| + NativeWebKeyboardEvent event; |
| + // BuildNativeWebKeyEventFromArgs handles telling what when wrong and sending |
| + // the reply message, if it failed we just have to stop here. |
| + if (!BuildNativeWebKeyEventFromArgs(args, reply_message, &event)) |
| + return; |
| + |
| + // The ui_controls::SendKeyPress function will generate up and down events |
| + // from one keycode for us so we only need to send one event to it. |
| + // Filtering is done via the RawKeyDown type because it is the one sent by |
| + // the current webdriver implementation of WebElement.SendKeys(...). |
| + DictionaryValue* reply_details = new DictionaryValue(); |
| + if (event.type != WebKit::WebInputEvent::RawKeyDown) { |
| + AutomationJSONReply reply(this, reply_message); |
| + reply_details->SetBoolean("processed", false); |
| + reply.SendSuccess(reply_details); |
| + return; |
| + } |
| + BrowserWindow* browser_window = browser->window(); |
| + if (!browser_window) { |
| + AutomationJSONReply reply(this, reply_message); |
| + reply.SendError("Could not get the browser window"); |
| + return; |
| + } |
| + gfx::NativeWindow window = browser_window->GetNativeHandle(); |
| + if (!window) { |
| + AutomationJSONReply reply(this, reply_message); |
| + reply.SendError("Could not get the browser window handle"); |
| + return; |
| + } |
| + bool control = !!(event.modifiers & WebKit::WebInputEvent::ControlKey); |
| + bool shift = !!(event.modifiers & WebKit::WebInputEvent::ShiftKey); |
| + bool alt = !!(event.modifiers & WebKit::WebInputEvent::AltKey); |
| + bool meta = !!(event.modifiers & WebKit::WebInputEvent::MetaKey); |
| + if (!ui_controls::SendKeyPress( |
| + window, static_cast<ui::KeyboardCode>(event.nativeKeyCode), |
| + control, shift, alt, meta)) { |
| + AutomationJSONReply reply(this, reply_message); |
| + reply.SendError("Could not send the native key event"); |
| + } else { |
| + AutomationJSONReply reply(this, reply_message); |
| + reply_details->SetBoolean("processed", true); |
| + reply.SendSuccess(reply_details); |
| + } |
| +} |
| + |
| // Sample JSON input: { "command": "GetNTPThumbnailMode" } |
| // For output, refer to GetNTPThumbnailMode() in |
| // chrome/test/pyautolib/pyauto.py. |
| @@ -4772,8 +4836,7 @@ |
| section = MENU_THUMB; |
| } else if (section_name.compare("recently_closed") == 0) { |
| section = MENU_RECENT; |
| - } |
| - else { |
| + } else { |
| reply.SendError(StringPrintf("Unexpected section name: '%s'", |
| section_name.c_str())); |
| return; |