Chromium Code Reviews| Index: chrome/browser/devtools/devtools_window.cc |
| diff --git a/chrome/browser/devtools/devtools_window.cc b/chrome/browser/devtools/devtools_window.cc |
| index dce7133ed3df102a99d8b65cbe60eb275df79805..a0b1501db34a85531c88b84b3cda18d219bb66d9 100644 |
| --- a/chrome/browser/devtools/devtools_window.cc |
| +++ b/chrome/browser/devtools/devtools_window.cc |
| @@ -55,6 +55,7 @@ |
| #include "content/public/browser/devtools_manager.h" |
| #include "content/public/browser/favicon_status.h" |
| #include "content/public/browser/load_notification_details.h" |
| +#include "content/public/browser/native_web_keyboard_event.h" |
| #include "content/public/browser/navigation_controller.h" |
| #include "content/public/browser/navigation_entry.h" |
| #include "content/public/browser/notification_source.h" |
| @@ -76,8 +77,10 @@ |
| #include "grit/generated_resources.h" |
| #include "third_party/WebKit/public/web/WebInputEvent.h" |
| #include "ui/base/l10n/l10n_util.h" |
| +#include "ui/events/keycodes/keyboard_codes.h" |
| using base::DictionaryValue; |
| +using blink::WebInputEvent; |
| using content::BrowserThread; |
| using content::DevToolsAgentHost; |
| @@ -1232,6 +1235,41 @@ void DevToolsWindow::SearchInPath(int request_id, |
| file_system_path)); |
| } |
| +static inline int combineKeyCodeAndModifiers(int key_code, int modifiers) { |
|
pfeldman
2014/04/08 12:01:20
Lets move it all into a separate class? Could be l
apavlov
2014/04/08 13:28:12
Done.
|
| + return key_code | (modifiers << 16); |
| +} |
| + |
| +static bool keyWhitelistingAllowed(int key_code, int modifiers) { |
| + return (ui::VKEY_F1 <= key_code && key_code <= ui::VKEY_F12) || |
| + modifiers != 0; |
| +} |
| + |
| +void DevToolsWindow::SetWhitelistedShortcuts(const std::string& message) { |
| + scoped_ptr<base::Value> parsed_message(base::JSONReader::Read(message)); |
| + base::ListValue* shortcut_list; |
| + if (!parsed_message->GetAsList(&shortcut_list)) |
| + return; |
| + base::ListValue::iterator it = shortcut_list->begin(); |
| + for (; it != shortcut_list->end(); ++it) { |
| + base::DictionaryValue* dictionary; |
| + if (!(*it)->GetAsDictionary(&dictionary)) |
| + continue; |
| + int key_code = 0; |
| + dictionary->GetInteger("keyCode", &key_code); |
| + if (key_code == 0) |
| + continue; |
| + int modifiers = 0; |
| + dictionary->GetInteger("modifiers", &modifiers); |
| + if (!keyWhitelistingAllowed(key_code, modifiers)) { |
| + LOG(WARNING) << "Keystroke whitelisting forbidden: " |
| + << "(" << key_code << "," << modifiers << ")"; |
| + continue; |
| + } |
| + whitelisted_keys_.push_back( |
|
pfeldman
2014/04/08 12:01:20
Could you use a set?
apavlov
2014/04/08 13:28:12
Done.
|
| + combineKeyCodeAndModifiers(key_code, modifiers)); |
| + } |
| +} |
| + |
| void DevToolsWindow::ZoomIn() { |
| chrome_page_zoom::Zoom(web_contents(), content::PAGE_ZOOM_IN); |
| } |
| @@ -1543,3 +1581,53 @@ void DevToolsWindow::SetLoadCompletedCallback(const base::Closure& closure) { |
| } |
| load_completed_callback_ = closure; |
| } |
| + |
| +// Mapping copied from Blink's KeyboardEvent.cpp. |
| +static inline int virtualKeyCodeWithoutLocation(int key_code) |
| +{ |
| + switch (key_code) { |
| + case ui::VKEY_LCONTROL: |
| + case ui::VKEY_RCONTROL: |
| + return ui::VKEY_CONTROL; |
| + case ui::VKEY_LSHIFT: |
| + case ui::VKEY_RSHIFT: |
| + return ui::VKEY_SHIFT; |
| + case ui::VKEY_LMENU: |
| + case ui::VKEY_RMENU: |
| + return ui::VKEY_MENU; |
| + default: |
| + return key_code; |
| + } |
| +} |
| + |
| +bool DevToolsWindow::ForwardKeyboardEvent( |
| + const content::NativeWebKeyboardEvent& event) { |
| + std::string event_type; |
| + switch (event.type) { |
| + case WebInputEvent::KeyDown: |
| + case WebInputEvent::RawKeyDown: |
| + event_type = "keydown"; |
|
pfeldman
2014/04/08 12:01:20
lets extract some constants.
apavlov
2014/04/08 13:28:12
Done.
|
| + break; |
| + case WebInputEvent::KeyUp: |
| + event_type = "keyup"; |
| + break; |
| + default: |
| + return false; |
| + } |
| + |
| + int key_code = virtualKeyCodeWithoutLocation(event.windowsKeyCode); |
| + int keystroke = combineKeyCodeAndModifiers(key_code, event.modifiers); |
| + if (std::find( |
|
pfeldman
2014/04/08 12:01:20
lets use a set.
apavlov
2014/04/08 13:28:12
Done.
|
| + whitelisted_keys_.begin(), whitelisted_keys_.end(), keystroke) == |
| + whitelisted_keys_.end()) |
| + return false; |
| + |
| + base::DictionaryValue event_data; |
| + event_data.SetString("type", event_type); |
| + event_data.SetString("keyIdentifier", event.keyIdentifier); |
| + event_data.SetInteger("keyCode", key_code); |
| + event_data.SetInteger("modifiers", event.modifiers); |
| + CallClientFunction( |
| + "InspectorFrontendAPI.keyEventUnhandled", &event_data, NULL, NULL); |
| + return true; |
| +} |