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

Side by Side 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: Address comments from tsepez@ Created 6 years, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/devtools/devtools_window.h" 5 #include "chrome/browser/devtools/devtools_window.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 #include "chrome/common/render_messages.h" 48 #include "chrome/common/render_messages.h"
49 #include "chrome/common/url_constants.h" 49 #include "chrome/common/url_constants.h"
50 #include "components/user_prefs/pref_registry_syncable.h" 50 #include "components/user_prefs/pref_registry_syncable.h"
51 #include "content/public/browser/browser_thread.h" 51 #include "content/public/browser/browser_thread.h"
52 #include "content/public/browser/child_process_security_policy.h" 52 #include "content/public/browser/child_process_security_policy.h"
53 #include "content/public/browser/devtools_agent_host.h" 53 #include "content/public/browser/devtools_agent_host.h"
54 #include "content/public/browser/devtools_client_host.h" 54 #include "content/public/browser/devtools_client_host.h"
55 #include "content/public/browser/devtools_manager.h" 55 #include "content/public/browser/devtools_manager.h"
56 #include "content/public/browser/favicon_status.h" 56 #include "content/public/browser/favicon_status.h"
57 #include "content/public/browser/load_notification_details.h" 57 #include "content/public/browser/load_notification_details.h"
58 #include "content/public/browser/native_web_keyboard_event.h"
58 #include "content/public/browser/navigation_controller.h" 59 #include "content/public/browser/navigation_controller.h"
59 #include "content/public/browser/navigation_entry.h" 60 #include "content/public/browser/navigation_entry.h"
60 #include "content/public/browser/notification_source.h" 61 #include "content/public/browser/notification_source.h"
61 #include "content/public/browser/render_frame_host.h" 62 #include "content/public/browser/render_frame_host.h"
62 #include "content/public/browser/render_process_host.h" 63 #include "content/public/browser/render_process_host.h"
63 #include "content/public/browser/render_view_host.h" 64 #include "content/public/browser/render_view_host.h"
64 #include "content/public/browser/user_metrics.h" 65 #include "content/public/browser/user_metrics.h"
65 #include "content/public/browser/web_contents.h" 66 #include "content/public/browser/web_contents.h"
66 #include "content/public/browser/web_contents_observer.h" 67 #include "content/public/browser/web_contents_observer.h"
67 #include "content/public/browser/web_contents_view.h" 68 #include "content/public/browser/web_contents_view.h"
68 #include "content/public/common/bindings_policy.h" 69 #include "content/public/common/bindings_policy.h"
69 #include "content/public/common/content_client.h" 70 #include "content/public/common/content_client.h"
70 #include "content/public/common/page_transition_types.h" 71 #include "content/public/common/page_transition_types.h"
71 #include "content/public/common/renderer_preferences.h" 72 #include "content/public/common/renderer_preferences.h"
72 #include "content/public/common/url_constants.h" 73 #include "content/public/common/url_constants.h"
73 #include "content/public/test/test_utils.h" 74 #include "content/public/test/test_utils.h"
74 #include "extensions/browser/extension_system.h" 75 #include "extensions/browser/extension_system.h"
75 #include "extensions/common/extension_set.h" 76 #include "extensions/common/extension_set.h"
76 #include "grit/generated_resources.h" 77 #include "grit/generated_resources.h"
77 #include "third_party/WebKit/public/web/WebInputEvent.h" 78 #include "third_party/WebKit/public/web/WebInputEvent.h"
78 #include "ui/base/l10n/l10n_util.h" 79 #include "ui/base/l10n/l10n_util.h"
80 #include "ui/events/keycodes/keyboard_codes.h"
79 81
80 using base::DictionaryValue; 82 using base::DictionaryValue;
83 using blink::WebInputEvent;
81 using content::BrowserThread; 84 using content::BrowserThread;
82 using content::DevToolsAgentHost; 85 using content::DevToolsAgentHost;
83 86
84 87
85 // DevToolsConfirmInfoBarDelegate --------------------------------------------- 88 // DevToolsConfirmInfoBarDelegate ---------------------------------------------
86 89
87 class DevToolsConfirmInfoBarDelegate : public ConfirmInfoBarDelegate { 90 class DevToolsConfirmInfoBarDelegate : public ConfirmInfoBarDelegate {
88 public: 91 public:
89 // If |infobar_service| is NULL, runs |callback| with a single argument with 92 // If |infobar_service| is NULL, runs |callback| with a single argument with
90 // value "false". Otherwise, creates a dev tools confirm infobar and delegate 93 // value "false". Otherwise, creates a dev tools confirm infobar and delegate
(...skipping 1134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1225 return; 1228 return;
1226 } 1229 }
1227 file_system_indexer_->SearchInPath(file_system_path, 1230 file_system_indexer_->SearchInPath(file_system_path,
1228 query, 1231 query,
1229 Bind(&DevToolsWindow::SearchCompleted, 1232 Bind(&DevToolsWindow::SearchCompleted,
1230 weak_factory_.GetWeakPtr(), 1233 weak_factory_.GetWeakPtr(),
1231 request_id, 1234 request_id,
1232 file_system_path)); 1235 file_system_path));
1233 } 1236 }
1234 1237
1238 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.
1239 return key_code | (modifiers << 16);
1240 }
1241
1242 static bool keyWhitelistingAllowed(int key_code, int modifiers) {
1243 return (ui::VKEY_F1 <= key_code && key_code <= ui::VKEY_F12) ||
1244 modifiers != 0;
1245 }
1246
1247 void DevToolsWindow::SetWhitelistedShortcuts(const std::string& message) {
1248 scoped_ptr<base::Value> parsed_message(base::JSONReader::Read(message));
1249 base::ListValue* shortcut_list;
1250 if (!parsed_message->GetAsList(&shortcut_list))
1251 return;
1252 base::ListValue::iterator it = shortcut_list->begin();
1253 for (; it != shortcut_list->end(); ++it) {
1254 base::DictionaryValue* dictionary;
1255 if (!(*it)->GetAsDictionary(&dictionary))
1256 continue;
1257 int key_code = 0;
1258 dictionary->GetInteger("keyCode", &key_code);
1259 if (key_code == 0)
1260 continue;
1261 int modifiers = 0;
1262 dictionary->GetInteger("modifiers", &modifiers);
1263 if (!keyWhitelistingAllowed(key_code, modifiers)) {
1264 LOG(WARNING) << "Keystroke whitelisting forbidden: "
1265 << "(" << key_code << "," << modifiers << ")";
1266 continue;
1267 }
1268 whitelisted_keys_.push_back(
pfeldman 2014/04/08 12:01:20 Could you use a set?
apavlov 2014/04/08 13:28:12 Done.
1269 combineKeyCodeAndModifiers(key_code, modifiers));
1270 }
1271 }
1272
1235 void DevToolsWindow::ZoomIn() { 1273 void DevToolsWindow::ZoomIn() {
1236 chrome_page_zoom::Zoom(web_contents(), content::PAGE_ZOOM_IN); 1274 chrome_page_zoom::Zoom(web_contents(), content::PAGE_ZOOM_IN);
1237 } 1275 }
1238 1276
1239 void DevToolsWindow::ZoomOut() { 1277 void DevToolsWindow::ZoomOut() {
1240 chrome_page_zoom::Zoom(web_contents(), content::PAGE_ZOOM_OUT); 1278 chrome_page_zoom::Zoom(web_contents(), content::PAGE_ZOOM_OUT);
1241 } 1279 }
1242 1280
1243 void DevToolsWindow::ResetZoom() { 1281 void DevToolsWindow::ResetZoom() {
1244 chrome_page_zoom::Zoom(web_contents(), content::PAGE_ZOOM_RESET); 1282 chrome_page_zoom::Zoom(web_contents(), content::PAGE_ZOOM_RESET);
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
1536 } 1574 }
1537 1575
1538 void DevToolsWindow::SetLoadCompletedCallback(const base::Closure& closure) { 1576 void DevToolsWindow::SetLoadCompletedCallback(const base::Closure& closure) {
1539 if (load_state_ == kLoadCompleted) { 1577 if (load_state_ == kLoadCompleted) {
1540 if (!closure.is_null()) 1578 if (!closure.is_null())
1541 closure.Run(); 1579 closure.Run();
1542 return; 1580 return;
1543 } 1581 }
1544 load_completed_callback_ = closure; 1582 load_completed_callback_ = closure;
1545 } 1583 }
1584
1585 // Mapping copied from Blink's KeyboardEvent.cpp.
1586 static inline int virtualKeyCodeWithoutLocation(int key_code)
1587 {
1588 switch (key_code) {
1589 case ui::VKEY_LCONTROL:
1590 case ui::VKEY_RCONTROL:
1591 return ui::VKEY_CONTROL;
1592 case ui::VKEY_LSHIFT:
1593 case ui::VKEY_RSHIFT:
1594 return ui::VKEY_SHIFT;
1595 case ui::VKEY_LMENU:
1596 case ui::VKEY_RMENU:
1597 return ui::VKEY_MENU;
1598 default:
1599 return key_code;
1600 }
1601 }
1602
1603 bool DevToolsWindow::ForwardKeyboardEvent(
1604 const content::NativeWebKeyboardEvent& event) {
1605 std::string event_type;
1606 switch (event.type) {
1607 case WebInputEvent::KeyDown:
1608 case WebInputEvent::RawKeyDown:
1609 event_type = "keydown";
pfeldman 2014/04/08 12:01:20 lets extract some constants.
apavlov 2014/04/08 13:28:12 Done.
1610 break;
1611 case WebInputEvent::KeyUp:
1612 event_type = "keyup";
1613 break;
1614 default:
1615 return false;
1616 }
1617
1618 int key_code = virtualKeyCodeWithoutLocation(event.windowsKeyCode);
1619 int keystroke = combineKeyCodeAndModifiers(key_code, event.modifiers);
1620 if (std::find(
pfeldman 2014/04/08 12:01:20 lets use a set.
apavlov 2014/04/08 13:28:12 Done.
1621 whitelisted_keys_.begin(), whitelisted_keys_.end(), keystroke) ==
1622 whitelisted_keys_.end())
1623 return false;
1624
1625 base::DictionaryValue event_data;
1626 event_data.SetString("type", event_type);
1627 event_data.SetString("keyIdentifier", event.keyIdentifier);
1628 event_data.SetInteger("keyCode", key_code);
1629 event_data.SetInteger("modifiers", event.modifiers);
1630 CallClientFunction(
1631 "InspectorFrontendAPI.keyEventUnhandled", &event_data, NULL, NULL);
1632 return true;
1633 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698