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) |
| @@ -4655,9 +4655,57 @@ |
| event.isSystemKey = is_system_key; |
| event.timeStampSeconds = base::Time::Now().ToDoubleT(); |
| event.skip_in_browser = true; |
| - new InputEventAckNotificationObserver(this, reply_message, event.type); |
| - browser->GetSelectedTabContents()->render_view_host()-> |
| - ForwardKeyboardEvent(event); |
| + bool use_native_events = false; |
| + // If useNativeEvents is true, this funciton will call |
| + // ui_controls::endKeyPress to the native window handle of the browser, |
| + // allowing events to be catched higher up; if false it will send an |
| + // event directly to webkit. |
| + if (args->GetBoolean("useNativeEvents", &use_native_events) |
| + && use_native_events) { |
|
Hironori Bono
2011/03/04 06:25:17
nit: This operator should be the end of the previo
timothe faudot
2011/03/04 06:47:35
Done.
|
| + // 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(...). |
| + if (event.type == WebKit::WebInputEvent::RawKeyDown) { |
| + BrowserWindow* browser_window = browser->window(); |
| + if (browser_window == NULL) { |
|
Hironori Bono
2011/03/04 06:25:17
nit: browser_window == NULL -> !browser_window
timothe faudot
2011/03/04 06:47:35
Done.
|
| + AutomationJSONReply reply(this, reply_message); |
| + reply.SendError("Could not get the browser window"); |
| + return; |
| + } |
| + gfx::NativeWindow window = browser_window->GetNativeHandle(); |
| + if (window == NULL) { |
|
Hironori Bono
2011/03/04 06:25:17
nit: window == NULL -> !window
timothe faudot
2011/03/04 06:47:35
Done.
|
| + AutomationJSONReply reply(this, reply_message); |
| + reply.SendError("Could not get the browser window handle"); |
| + return; |
| + } |
| + if (!ui_controls::SendKeyPress( |
| + window, static_cast<ui::KeyboardCode>(event.nativeKeyCode), |
| + ((event.modifiers & WebKit::WebInputEvent::ControlKey) == |
| + WebKit::WebInputEvent::ControlKey), |
|
Hironori Bono
2011/03/04 06:25:17
nit: I prefer using a local variable as listed in
timothe faudot
2011/03/04 06:47:35
Done.
|
| + ((event.modifiers & WebKit::WebInputEvent::ShiftKey) == |
| + WebKit::WebInputEvent::ShiftKey), |
| + ((event.modifiers & WebKit::WebInputEvent::AltKey) == |
| + WebKit::WebInputEvent::AltKey), |
| + ((event.modifiers & WebKit::WebInputEvent::MetaKey) == |
| + WebKit::WebInputEvent::MetaKey))) { |
| + AutomationJSONReply reply(this, reply_message); |
| + reply.SendError("Could not send the native key event"); |
| + return; |
| + } else { |
| + AutomationJSONReply reply(this, reply_message); |
| + reply.SendSuccess(NULL); |
| + } |
| + } else { |
| + // Skip this event by acknowledging it without doing nothing. |
| + AutomationJSONReply reply(this, reply_message); |
| + reply.SendSuccess(NULL); |
| + } |
| + } else { |
| + new InputEventAckNotificationObserver(this, reply_message, event.type); |
| + browser->GetSelectedTabContents()->render_view_host()-> |
| + ForwardKeyboardEvent(event); |
|
Hironori Bono
2011/03/04 06:25:17
nit: I prefer using an early exit as listed in the
timothe faudot
2011/03/04 06:47:35
Down, also added an early return statement up.
|
| + } |
| } |
| // Sample JSON input: { "command": "GetNTPThumbnailMode" } |
| @@ -4772,8 +4820,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; |