Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 #include "chrome/common/render_messages.h" | 47 #include "chrome/common/render_messages.h" |
| 48 #include "chrome/common/url_constants.h" | 48 #include "chrome/common/url_constants.h" |
| 49 #include "components/user_prefs/pref_registry_syncable.h" | 49 #include "components/user_prefs/pref_registry_syncable.h" |
| 50 #include "content/public/browser/browser_thread.h" | 50 #include "content/public/browser/browser_thread.h" |
| 51 #include "content/public/browser/child_process_security_policy.h" | 51 #include "content/public/browser/child_process_security_policy.h" |
| 52 #include "content/public/browser/devtools_agent_host.h" | 52 #include "content/public/browser/devtools_agent_host.h" |
| 53 #include "content/public/browser/devtools_client_host.h" | 53 #include "content/public/browser/devtools_client_host.h" |
| 54 #include "content/public/browser/devtools_manager.h" | 54 #include "content/public/browser/devtools_manager.h" |
| 55 #include "content/public/browser/favicon_status.h" | 55 #include "content/public/browser/favicon_status.h" |
| 56 #include "content/public/browser/load_notification_details.h" | 56 #include "content/public/browser/load_notification_details.h" |
| 57 #include "content/public/browser/native_web_keyboard_event.h" | |
| 57 #include "content/public/browser/navigation_controller.h" | 58 #include "content/public/browser/navigation_controller.h" |
| 58 #include "content/public/browser/navigation_entry.h" | 59 #include "content/public/browser/navigation_entry.h" |
| 59 #include "content/public/browser/notification_source.h" | 60 #include "content/public/browser/notification_source.h" |
| 60 #include "content/public/browser/render_frame_host.h" | 61 #include "content/public/browser/render_frame_host.h" |
| 61 #include "content/public/browser/render_process_host.h" | 62 #include "content/public/browser/render_process_host.h" |
| 62 #include "content/public/browser/render_view_host.h" | 63 #include "content/public/browser/render_view_host.h" |
| 63 #include "content/public/browser/user_metrics.h" | 64 #include "content/public/browser/user_metrics.h" |
| 64 #include "content/public/browser/web_contents.h" | 65 #include "content/public/browser/web_contents.h" |
| 65 #include "content/public/browser/web_contents_observer.h" | 66 #include "content/public/browser/web_contents_observer.h" |
| 66 #include "content/public/browser/web_contents_view.h" | 67 #include "content/public/browser/web_contents_view.h" |
| 67 #include "content/public/common/bindings_policy.h" | 68 #include "content/public/common/bindings_policy.h" |
| 68 #include "content/public/common/content_client.h" | 69 #include "content/public/common/content_client.h" |
| 69 #include "content/public/common/page_transition_types.h" | 70 #include "content/public/common/page_transition_types.h" |
| 70 #include "content/public/common/renderer_preferences.h" | 71 #include "content/public/common/renderer_preferences.h" |
| 71 #include "content/public/common/url_constants.h" | 72 #include "content/public/common/url_constants.h" |
| 72 #include "content/public/test/test_utils.h" | 73 #include "content/public/test/test_utils.h" |
| 73 #include "extensions/browser/extension_system.h" | 74 #include "extensions/browser/extension_system.h" |
| 74 #include "extensions/common/extension_set.h" | 75 #include "extensions/common/extension_set.h" |
| 75 #include "grit/generated_resources.h" | 76 #include "grit/generated_resources.h" |
| 76 #include "third_party/WebKit/public/web/WebInputEvent.h" | 77 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 77 #include "ui/base/l10n/l10n_util.h" | 78 #include "ui/base/l10n/l10n_util.h" |
| 79 #include "ui/events/keycodes/keyboard_codes.h" | |
| 78 | 80 |
| 79 using base::DictionaryValue; | 81 using base::DictionaryValue; |
| 82 using blink::WebInputEvent; | |
| 80 using content::BrowserThread; | 83 using content::BrowserThread; |
| 81 using content::DevToolsAgentHost; | 84 using content::DevToolsAgentHost; |
| 82 | 85 |
| 83 | 86 |
| 84 // DevToolsConfirmInfoBarDelegate --------------------------------------------- | 87 // DevToolsConfirmInfoBarDelegate --------------------------------------------- |
| 85 | 88 |
| 86 class DevToolsConfirmInfoBarDelegate : public ConfirmInfoBarDelegate { | 89 class DevToolsConfirmInfoBarDelegate : public ConfirmInfoBarDelegate { |
| 87 public: | 90 public: |
| 88 // If |infobar_service| is NULL, runs |callback| with a single argument with | 91 // If |infobar_service| is NULL, runs |callback| with a single argument with |
| 89 // value "false". Otherwise, creates a dev tools confirm infobar and delegate | 92 // value "false". Otherwise, creates a dev tools confirm infobar and delegate |
| (...skipping 1134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1224 return; | 1227 return; |
| 1225 } | 1228 } |
| 1226 file_system_indexer_->SearchInPath(file_system_path, | 1229 file_system_indexer_->SearchInPath(file_system_path, |
| 1227 query, | 1230 query, |
| 1228 Bind(&DevToolsWindow::SearchCompleted, | 1231 Bind(&DevToolsWindow::SearchCompleted, |
| 1229 weak_factory_.GetWeakPtr(), | 1232 weak_factory_.GetWeakPtr(), |
| 1230 request_id, | 1233 request_id, |
| 1231 file_system_path)); | 1234 file_system_path)); |
| 1232 } | 1235 } |
| 1233 | 1236 |
| 1237 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.
| |
| 1238 return keyCode | (modifiers << 16); | |
| 1239 } | |
| 1240 | |
| 1241 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
| |
| 1242 scoped_ptr<base::Value> parsed_message(base::JSONReader::Read(message)); | |
| 1243 base::ListValue* shortcut_list; | |
| 1244 if (!parsed_message->GetAsList(&shortcut_list)) | |
| 1245 return; | |
| 1246 base::ListValue::iterator it = shortcut_list->begin(); | |
| 1247 for (; it != shortcut_list->end(); ++it) { | |
| 1248 base::DictionaryValue* dictionary; | |
| 1249 if (!(*it)->GetAsDictionary(&dictionary)) | |
| 1250 continue; | |
| 1251 int keyCode = 0; | |
| 1252 dictionary->GetInteger("keyCode", &keyCode); | |
| 1253 if (keyCode == 0) | |
| 1254 continue; | |
| 1255 int modifiers = 0; | |
| 1256 dictionary->GetInteger("modifiers", &modifiers); | |
| 1257 whitelisted_keys_.push_back(hashKeyCodeAndModifiers(keyCode, modifiers)); | |
| 1258 } | |
| 1259 } | |
| 1260 | |
| 1234 void DevToolsWindow::ZoomIn() { | 1261 void DevToolsWindow::ZoomIn() { |
| 1235 chrome_page_zoom::Zoom(web_contents(), content::PAGE_ZOOM_IN); | 1262 chrome_page_zoom::Zoom(web_contents(), content::PAGE_ZOOM_IN); |
| 1236 } | 1263 } |
| 1237 | 1264 |
| 1238 void DevToolsWindow::ZoomOut() { | 1265 void DevToolsWindow::ZoomOut() { |
| 1239 chrome_page_zoom::Zoom(web_contents(), content::PAGE_ZOOM_OUT); | 1266 chrome_page_zoom::Zoom(web_contents(), content::PAGE_ZOOM_OUT); |
| 1240 } | 1267 } |
| 1241 | 1268 |
| 1242 void DevToolsWindow::ResetZoom() { | 1269 void DevToolsWindow::ResetZoom() { |
| 1243 chrome_page_zoom::Zoom(web_contents(), content::PAGE_ZOOM_RESET); | 1270 chrome_page_zoom::Zoom(web_contents(), content::PAGE_ZOOM_RESET); |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1535 } | 1562 } |
| 1536 | 1563 |
| 1537 void DevToolsWindow::SetLoadCompletedCallback(const base::Closure& closure) { | 1564 void DevToolsWindow::SetLoadCompletedCallback(const base::Closure& closure) { |
| 1538 if (load_state_ == kLoadCompleted) { | 1565 if (load_state_ == kLoadCompleted) { |
| 1539 if (!closure.is_null()) | 1566 if (!closure.is_null()) |
| 1540 closure.Run(); | 1567 closure.Run(); |
| 1541 return; | 1568 return; |
| 1542 } | 1569 } |
| 1543 load_completed_callback_ = closure; | 1570 load_completed_callback_ = closure; |
| 1544 } | 1571 } |
| 1572 | |
| 1573 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
| |
| 1574 { | |
| 1575 switch (keycode) { | |
| 1576 case ui::VKEY_LCONTROL: | |
| 1577 case ui::VKEY_RCONTROL: | |
| 1578 return ui::VKEY_CONTROL; | |
| 1579 case ui::VKEY_LSHIFT: | |
| 1580 case ui::VKEY_RSHIFT: | |
| 1581 return ui::VKEY_SHIFT; | |
| 1582 case ui::VKEY_LMENU: | |
| 1583 case ui::VKEY_RMENU: | |
| 1584 return ui::VKEY_MENU; | |
| 1585 default: | |
| 1586 return keycode; | |
| 1587 } | |
| 1588 } | |
| 1589 | |
| 1590 bool DevToolsWindow::ForwardKeyboardEvent( | |
| 1591 const content::NativeWebKeyboardEvent& event) { | |
| 1592 std::string event_type; | |
| 1593 switch (event.type) { | |
| 1594 case WebInputEvent::KeyDown: | |
| 1595 case WebInputEvent::RawKeyDown: | |
| 1596 event_type = "keydown"; | |
| 1597 break; | |
| 1598 case WebInputEvent::KeyUp: | |
| 1599 event_type = "keyup"; | |
| 1600 break; | |
| 1601 default: | |
| 1602 return false; | |
| 1603 } | |
| 1604 | |
| 1605 int keyCode = windowsVirtualKeyCodeWithoutLocation(event.windowsKeyCode); | |
| 1606 int hash = hashKeyCodeAndModifiers(keyCode, event.modifiers); | |
| 1607 if (std::find(whitelisted_keys_.begin(), whitelisted_keys_.end(), hash) == | |
| 1608 whitelisted_keys_.end()) | |
| 1609 return false; | |
| 1610 | |
| 1611 base::DictionaryValue event_data; | |
| 1612 event_data.SetString("type", event_type); | |
| 1613 event_data.SetString("keyIdentifier", event.keyIdentifier); | |
| 1614 event_data.SetInteger("keyCode", keyCode); | |
| 1615 event_data.SetInteger("modifiers", event.modifiers); | |
| 1616 CallClientFunction( | |
| 1617 "InspectorFrontendAPI.keyEventUnhandled", &event_data, NULL, NULL); | |
| 1618 return true; | |
| 1619 } | |
| OLD | NEW |