Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1441)

Unified Diff: chrome/browser/devtools/devtools_window.cc

Issue 225973003: DevTools: Forward whitelisted unhandled shortcuts from inspected page into DevTools frontend (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/devtools/devtools_window.h ('k') | chrome/browser/ui/browser.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/devtools/devtools_window.cc
diff --git a/chrome/browser/devtools/devtools_window.cc b/chrome/browser/devtools/devtools_window.cc
index 36002a38f79f39232b946cc00a5ac6d5b5b5545e..f16606874f7e68bfbe9d73fcddf9bbcb2f087179 100644
--- a/chrome/browser/devtools/devtools_window.cc
+++ b/chrome/browser/devtools/devtools_window.cc
@@ -54,6 +54,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"
@@ -75,8 +76,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;
@@ -1231,6 +1234,30 @@ void DevToolsWindow::SearchInPath(int request_id,
file_system_path));
}
+static inline int hashKeyCodeAndModifiers(int keyCode, int modifiers) {
Tom Sepez 2014/04/07 18:01:14 nit: this isn't really a "hash" per-se, in that it
apavlov 2014/04/08 10:11:31 Done.
+ return keyCode | (modifiers << 16);
+}
+
+void DevToolsWindow::SetWhitelistedShortcuts(const std::string& message) {
Tom Sepez 2014/04/07 18:01:14 You'll probably want to check here that the keycod
apavlov 2014/04/08 10:11:31 Good point. For now, let's allow keys with modifie
+ 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 keyCode = 0;
+ dictionary->GetInteger("keyCode", &keyCode);
+ if (keyCode == 0)
+ continue;
+ int modifiers = 0;
+ dictionary->GetInteger("modifiers", &modifiers);
+ whitelisted_keys_.push_back(hashKeyCodeAndModifiers(keyCode, modifiers));
+ }
+}
+
void DevToolsWindow::ZoomIn() {
chrome_page_zoom::Zoom(web_contents(), content::PAGE_ZOOM_IN);
}
@@ -1542,3 +1569,51 @@ void DevToolsWindow::SetLoadCompletedCallback(const base::Closure& closure) {
}
load_completed_callback_ = closure;
}
+
+static inline int windowsVirtualKeyCodeWithoutLocation(int keycode)
Tom Sepez 2014/04/07 18:01:14 nit: if you want to call this windows... I'd expe
apavlov 2014/04/08 10:11:31 Yeah, I just wanted to make it consistent with the
+{
+ switch (keycode) {
+ 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 keycode;
+ }
+}
+
+bool DevToolsWindow::ForwardKeyboardEvent(
+ const content::NativeWebKeyboardEvent& event) {
+ std::string event_type;
+ switch (event.type) {
+ case WebInputEvent::KeyDown:
+ case WebInputEvent::RawKeyDown:
+ event_type = "keydown";
+ break;
+ case WebInputEvent::KeyUp:
+ event_type = "keyup";
+ break;
+ default:
+ return false;
+ }
+
+ int keyCode = windowsVirtualKeyCodeWithoutLocation(event.windowsKeyCode);
+ int hash = hashKeyCodeAndModifiers(keyCode, event.modifiers);
+ if (std::find(whitelisted_keys_.begin(), whitelisted_keys_.end(), hash) ==
+ 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", keyCode);
+ event_data.SetInteger("modifiers", event.modifiers);
+ CallClientFunction(
+ "InspectorFrontendAPI.keyEventUnhandled", &event_data, NULL, NULL);
+ return true;
+}
« no previous file with comments | « chrome/browser/devtools/devtools_window.h ('k') | chrome/browser/ui/browser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698