OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "content/browser/devtools/renderer_overrides_handler.h" | 5 #include "content/browser/devtools/renderer_overrides_handler.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/barrier_closure.h" | 10 #include "base/barrier_closure.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 namespace content { | 58 namespace content { |
59 | 59 |
60 namespace { | 60 namespace { |
61 | 61 |
62 static const char kPng[] = "png"; | 62 static const char kPng[] = "png"; |
63 static const char kJpeg[] = "jpeg"; | 63 static const char kJpeg[] = "jpeg"; |
64 static int kDefaultScreenshotQuality = 80; | 64 static int kDefaultScreenshotQuality = 80; |
65 static int kFrameRateThresholdMs = 100; | 65 static int kFrameRateThresholdMs = 100; |
66 static int kCaptureRetryLimit = 2; | 66 static int kCaptureRetryLimit = 2; |
67 | 67 |
68 void ParseGenericInputParams(base::DictionaryValue* params, | |
69 WebInputEvent* event) { | |
70 int modifiers = 0; | |
71 if (params->GetInteger( | |
72 devtools::Input::emulateTouchFromMouseEvent::kParamModifiers, | |
73 &modifiers)) { | |
74 if (modifiers & 1) | |
75 event->modifiers |= WebInputEvent::AltKey; | |
76 if (modifiers & 2) | |
77 event->modifiers |= WebInputEvent::ControlKey; | |
78 if (modifiers & 4) | |
79 event->modifiers |= WebInputEvent::MetaKey; | |
80 if (modifiers & 8) | |
81 event->modifiers |= WebInputEvent::ShiftKey; | |
82 } | |
83 | |
84 params->GetDouble( | |
85 devtools::Input::emulateTouchFromMouseEvent::kParamTimestamp, | |
86 &event->timeStampSeconds); | |
87 } | |
88 | |
89 } // namespace | 68 } // namespace |
90 | 69 |
91 RendererOverridesHandler::RendererOverridesHandler(DevToolsAgentHost* agent) | 70 RendererOverridesHandler::RendererOverridesHandler(DevToolsAgentHost* agent) |
92 : agent_(agent), | 71 : agent_(agent), |
93 capture_retry_count_(0), | 72 capture_retry_count_(0), |
94 weak_factory_(this) { | 73 weak_factory_(this) { |
95 RegisterCommandHandler( | 74 RegisterCommandHandler( |
96 devtools::DOM::setFileInputFiles::kName, | 75 devtools::DOM::setFileInputFiles::kName, |
97 base::Bind( | 76 base::Bind( |
98 &RendererOverridesHandler::GrantPermissionsForSetFileInputFiles, | 77 &RendererOverridesHandler::GrantPermissionsForSetFileInputFiles, |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 devtools::Page::stopScreencast::kName, | 134 devtools::Page::stopScreencast::kName, |
156 base::Bind( | 135 base::Bind( |
157 &RendererOverridesHandler::PageStopScreencast, | 136 &RendererOverridesHandler::PageStopScreencast, |
158 base::Unretained(this))); | 137 base::Unretained(this))); |
159 RegisterCommandHandler( | 138 RegisterCommandHandler( |
160 devtools::Page::queryUsageAndQuota::kName, | 139 devtools::Page::queryUsageAndQuota::kName, |
161 base::Bind( | 140 base::Bind( |
162 &RendererOverridesHandler::PageQueryUsageAndQuota, | 141 &RendererOverridesHandler::PageQueryUsageAndQuota, |
163 base::Unretained(this))); | 142 base::Unretained(this))); |
164 RegisterCommandHandler( | 143 RegisterCommandHandler( |
165 devtools::Input::dispatchMouseEvent::kName, | |
166 base::Bind( | |
167 &RendererOverridesHandler::InputDispatchMouseEvent, | |
168 base::Unretained(this))); | |
169 RegisterCommandHandler( | |
170 devtools::Input::dispatchGestureEvent::kName, | |
171 base::Bind( | |
172 &RendererOverridesHandler::InputDispatchGestureEvent, | |
173 base::Unretained(this))); | |
174 RegisterCommandHandler( | |
175 devtools::Input::emulateTouchFromMouseEvent::kName, | 144 devtools::Input::emulateTouchFromMouseEvent::kName, |
176 base::Bind( | 145 base::Bind( |
177 &RendererOverridesHandler::InputEmulateTouchFromMouseEvent, | 146 &RendererOverridesHandler::InputEmulateTouchFromMouseEvent, |
178 base::Unretained(this))); | 147 base::Unretained(this))); |
179 } | 148 } |
180 | 149 |
181 RendererOverridesHandler::~RendererOverridesHandler() {} | 150 RendererOverridesHandler::~RendererOverridesHandler() {} |
182 | 151 |
183 void RendererOverridesHandler::OnClientDetached() { | 152 void RendererOverridesHandler::OnClientDetached() { |
184 RenderViewHostImpl* host = static_cast<RenderViewHostImpl*>( | 153 RenderViewHostImpl* host = static_cast<RenderViewHostImpl*>( |
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
872 base::DictionaryValue* params = new base::DictionaryValue(); | 841 base::DictionaryValue* params = new base::DictionaryValue(); |
873 params->SetBoolean( | 842 params->SetBoolean( |
874 devtools::Page::screencastVisibilityChanged::kParamVisible, visible); | 843 devtools::Page::screencastVisibilityChanged::kParamVisible, visible); |
875 SendNotification( | 844 SendNotification( |
876 devtools::Page::screencastVisibilityChanged::kName, params); | 845 devtools::Page::screencastVisibilityChanged::kName, params); |
877 } | 846 } |
878 | 847 |
879 // Input agent handlers ------------------------------------------------------ | 848 // Input agent handlers ------------------------------------------------------ |
880 | 849 |
881 scoped_refptr<DevToolsProtocol::Response> | 850 scoped_refptr<DevToolsProtocol::Response> |
882 RendererOverridesHandler::InputDispatchMouseEvent( | |
883 scoped_refptr<DevToolsProtocol::Command> command) { | |
884 base::DictionaryValue* params = command->params(); | |
885 if (!params) | |
886 return NULL; | |
887 | |
888 bool device_space = false; | |
889 if (!params->GetBoolean( | |
890 devtools::Input::dispatchMouseEvent::kParamDeviceSpace, | |
891 &device_space) || | |
892 !device_space) { | |
893 return NULL; | |
894 } | |
895 | |
896 if (!DispatchMouseEventFromCommand(command)) | |
897 return NULL; | |
898 return command->SuccessResponse(NULL); | |
899 } | |
900 | |
901 scoped_refptr<DevToolsProtocol::Response> | |
902 RendererOverridesHandler::InputEmulateTouchFromMouseEvent( | 851 RendererOverridesHandler::InputEmulateTouchFromMouseEvent( |
903 scoped_refptr<DevToolsProtocol::Command> command) { | 852 scoped_refptr<DevToolsProtocol::Command> command) { |
904 if (!screencast_command_) | 853 if (!screencast_command_) |
905 return NULL; | 854 return NULL; |
906 if (!DispatchMouseEventFromCommand(command)) | |
907 return NULL; | |
908 return command->SuccessResponse(NULL); | |
909 } | |
910 | 855 |
911 bool RendererOverridesHandler::DispatchMouseEventFromCommand( | |
912 scoped_refptr<DevToolsProtocol::Command> command) { | |
913 base::DictionaryValue* params = command->params(); | 856 base::DictionaryValue* params = command->params(); |
914 if (!params) | 857 if (!params) |
915 return false; | 858 return NULL; |
pfeldman
2014/08/04 12:16:22
return error responce instead.
dgozman
2014/08/05 08:21:01
Done.
| |
916 | 859 |
917 RenderViewHost* host = agent_->GetRenderViewHost(); | 860 RenderViewHost* host = agent_->GetRenderViewHost(); |
918 | 861 |
919 std::string type; | 862 std::string type; |
920 if (!params->GetString( | 863 if (!params->GetString( |
921 devtools::Input::emulateTouchFromMouseEvent::kParamType, | 864 devtools::Input::emulateTouchFromMouseEvent::kParamType, |
922 &type)) { | 865 &type)) { |
923 return false; | 866 return NULL; |
924 } | 867 } |
925 | 868 |
926 blink::WebMouseWheelEvent wheel_event; | 869 blink::WebMouseWheelEvent wheel_event; |
927 blink::WebMouseEvent mouse_event; | 870 blink::WebMouseEvent mouse_event; |
928 blink::WebMouseEvent* event = &mouse_event; | 871 blink::WebMouseEvent* event = &mouse_event; |
929 | 872 |
930 if (type == | 873 if (type == |
931 devtools::Input::emulateTouchFromMouseEvent::Type::kEnumMousePressed) { | 874 devtools::Input::emulateTouchFromMouseEvent::Type::kEnumMousePressed) { |
932 event->type = WebInputEvent::MouseDown; | 875 event->type = WebInputEvent::MouseDown; |
933 } else if (type == | 876 } else if (type == |
934 devtools::Input::emulateTouchFromMouseEvent::Type::kEnumMouseReleased) { | 877 devtools::Input::emulateTouchFromMouseEvent::Type::kEnumMouseReleased) { |
935 event->type = WebInputEvent::MouseUp; | 878 event->type = WebInputEvent::MouseUp; |
936 } else if (type == | 879 } else if (type == |
937 devtools::Input::emulateTouchFromMouseEvent::Type::kEnumMouseMoved) { | 880 devtools::Input::emulateTouchFromMouseEvent::Type::kEnumMouseMoved) { |
938 event->type = WebInputEvent::MouseMove; | 881 event->type = WebInputEvent::MouseMove; |
939 } else if (type == | 882 } else if (type == |
940 devtools::Input::emulateTouchFromMouseEvent::Type::kEnumMouseWheel) { | 883 devtools::Input::emulateTouchFromMouseEvent::Type::kEnumMouseWheel) { |
941 double deltaX = 0; | 884 double deltaX = 0; |
942 double deltaY = 0; | 885 double deltaY = 0; |
943 if (!params->GetDouble( | 886 if (!params->GetDouble( |
944 devtools::Input::emulateTouchFromMouseEvent::kParamDeltaX, | 887 devtools::Input::emulateTouchFromMouseEvent::kParamDeltaX, |
945 &deltaX) || | 888 &deltaX) || |
946 !params->GetDouble( | 889 !params->GetDouble( |
947 devtools::Input::emulateTouchFromMouseEvent::kParamDeltaY, | 890 devtools::Input::emulateTouchFromMouseEvent::kParamDeltaY, |
948 &deltaY)) { | 891 &deltaY)) { |
949 return false; | 892 return NULL; |
950 } | 893 } |
951 wheel_event.deltaX = static_cast<float>(deltaX); | 894 wheel_event.deltaX = static_cast<float>(deltaX); |
952 wheel_event.deltaY = static_cast<float>(deltaY); | 895 wheel_event.deltaY = static_cast<float>(deltaY); |
953 event = &wheel_event; | 896 event = &wheel_event; |
954 event->type = WebInputEvent::MouseWheel; | 897 event->type = WebInputEvent::MouseWheel; |
955 } else { | 898 } else { |
956 return false; | 899 return NULL; |
957 } | 900 } |
958 | 901 |
959 ParseGenericInputParams(params, event); | 902 int modifiers = 0; |
903 if (params->GetInteger( | |
904 devtools::Input::emulateTouchFromMouseEvent::kParamModifiers, | |
905 &modifiers)) { | |
906 if (modifiers & 1) | |
907 event->modifiers |= WebInputEvent::AltKey; | |
908 if (modifiers & 2) | |
909 event->modifiers |= WebInputEvent::ControlKey; | |
910 if (modifiers & 4) | |
911 event->modifiers |= WebInputEvent::MetaKey; | |
912 if (modifiers & 8) | |
913 event->modifiers |= WebInputEvent::ShiftKey; | |
914 } | |
915 | |
916 params->GetDouble( | |
917 devtools::Input::emulateTouchFromMouseEvent::kParamTimestamp, | |
918 &event->timeStampSeconds); | |
960 | 919 |
961 if (!params->GetInteger(devtools::Input::emulateTouchFromMouseEvent::kParamX, | 920 if (!params->GetInteger(devtools::Input::emulateTouchFromMouseEvent::kParamX, |
962 &event->x) || | 921 &event->x) || |
963 !params->GetInteger(devtools::Input::emulateTouchFromMouseEvent::kParamY, | 922 !params->GetInteger(devtools::Input::emulateTouchFromMouseEvent::kParamY, |
964 &event->y)) { | 923 &event->y)) { |
965 return false; | 924 return NULL; |
966 } | 925 } |
967 | 926 |
968 event->windowX = event->x; | 927 event->windowX = event->x; |
969 event->windowY = event->y; | 928 event->windowY = event->y; |
970 event->globalX = event->x; | 929 event->globalX = event->x; |
971 event->globalY = event->y; | 930 event->globalY = event->y; |
972 | 931 |
973 params->GetInteger( | 932 params->GetInteger( |
974 devtools::Input::emulateTouchFromMouseEvent::kParamClickCount, | 933 devtools::Input::emulateTouchFromMouseEvent::kParamClickCount, |
975 &event->clickCount); | 934 &event->clickCount); |
976 | 935 |
977 std::string button; | 936 std::string button; |
978 if (!params->GetString( | 937 if (!params->GetString( |
979 devtools::Input::emulateTouchFromMouseEvent::kParamButton, | 938 devtools::Input::emulateTouchFromMouseEvent::kParamButton, |
980 &button)) { | 939 &button)) { |
981 return false; | 940 return NULL; |
982 } | 941 } |
983 | 942 |
984 if (button == "none") { | 943 if (button == "none") { |
985 event->button = WebMouseEvent::ButtonNone; | 944 event->button = WebMouseEvent::ButtonNone; |
986 } else if (button == "left") { | 945 } else if (button == "left") { |
987 event->button = WebMouseEvent::ButtonLeft; | 946 event->button = WebMouseEvent::ButtonLeft; |
988 event->modifiers |= WebInputEvent::LeftButtonDown; | 947 event->modifiers |= WebInputEvent::LeftButtonDown; |
989 } else if (button == "middle") { | 948 } else if (button == "middle") { |
990 event->button = WebMouseEvent::ButtonMiddle; | 949 event->button = WebMouseEvent::ButtonMiddle; |
991 event->modifiers |= WebInputEvent::MiddleButtonDown; | 950 event->modifiers |= WebInputEvent::MiddleButtonDown; |
992 } else if (button == "right") { | 951 } else if (button == "right") { |
993 event->button = WebMouseEvent::ButtonRight; | 952 event->button = WebMouseEvent::ButtonRight; |
994 event->modifiers |= WebInputEvent::RightButtonDown; | 953 event->modifiers |= WebInputEvent::RightButtonDown; |
995 } else { | 954 } else { |
996 return false; | 955 return NULL; |
997 } | 956 } |
998 | 957 |
999 if (event->type == WebInputEvent::MouseWheel) | 958 if (event->type == WebInputEvent::MouseWheel) |
1000 host->ForwardWheelEvent(wheel_event); | 959 host->ForwardWheelEvent(wheel_event); |
1001 else | 960 else |
1002 host->ForwardMouseEvent(mouse_event); | 961 host->ForwardMouseEvent(mouse_event); |
1003 return true; | |
1004 } | |
1005 | |
1006 scoped_refptr<DevToolsProtocol::Response> | |
1007 RendererOverridesHandler::InputDispatchGestureEvent( | |
1008 scoped_refptr<DevToolsProtocol::Command> command) { | |
1009 base::DictionaryValue* params = command->params(); | |
1010 if (!params) | |
1011 return NULL; | |
1012 | |
1013 RenderViewHostImpl* host = static_cast<RenderViewHostImpl*>( | |
1014 agent_->GetRenderViewHost()); | |
1015 blink::WebGestureEvent event; | |
1016 ParseGenericInputParams(params, &event); | |
1017 event.sourceDevice = blink::WebGestureDeviceTouchscreen; | |
1018 | |
1019 std::string type; | |
1020 if (params->GetString(devtools::Input::dispatchGestureEvent::kParamType, | |
1021 &type)) { | |
1022 if (type == | |
1023 devtools::Input::dispatchGestureEvent::Type::kEnumScrollBegin) | |
1024 event.type = WebInputEvent::GestureScrollBegin; | |
1025 else if (type == | |
1026 devtools::Input::dispatchGestureEvent::Type::kEnumScrollUpdate) | |
1027 event.type = WebInputEvent::GestureScrollUpdate; | |
1028 else if (type == | |
1029 devtools::Input::dispatchGestureEvent::Type::kEnumScrollEnd) | |
1030 event.type = WebInputEvent::GestureScrollEnd; | |
1031 else if (type == | |
1032 devtools::Input::dispatchGestureEvent::Type::kEnumTapDown) | |
1033 event.type = WebInputEvent::GestureTapDown; | |
1034 else if (type == | |
1035 devtools::Input::dispatchGestureEvent::Type::kEnumTap) | |
1036 event.type = WebInputEvent::GestureTap; | |
1037 else if (type == | |
1038 devtools::Input::dispatchGestureEvent::Type::kEnumPinchBegin) | |
1039 event.type = WebInputEvent::GesturePinchBegin; | |
1040 else if (type == | |
1041 devtools::Input::dispatchGestureEvent::Type::kEnumPinchUpdate) | |
1042 event.type = WebInputEvent::GesturePinchUpdate; | |
1043 else if (type == | |
1044 devtools::Input::dispatchGestureEvent::Type::kEnumPinchEnd) | |
1045 event.type = WebInputEvent::GesturePinchEnd; | |
1046 else | |
1047 return NULL; | |
1048 } else { | |
1049 return NULL; | |
1050 } | |
1051 | |
1052 if (!params->GetInteger(devtools::Input::dispatchGestureEvent::kParamX, | |
1053 &event.x) || | |
1054 !params->GetInteger(devtools::Input::dispatchGestureEvent::kParamY, | |
1055 &event.y)) { | |
1056 return NULL; | |
1057 } | |
1058 event.globalX = event.x; | |
1059 event.globalY = event.y; | |
1060 | |
1061 if (type == "scrollUpdate") { | |
1062 int dx = 0; | |
1063 int dy = 0; | |
1064 if (!params->GetInteger( | |
1065 devtools::Input::dispatchGestureEvent::kParamDeltaX, &dx) || | |
1066 !params->GetInteger( | |
1067 devtools::Input::dispatchGestureEvent::kParamDeltaY, &dy)) { | |
1068 return NULL; | |
1069 } | |
1070 event.data.scrollUpdate.deltaX = dx; | |
1071 event.data.scrollUpdate.deltaY = dy; | |
1072 } | |
1073 | |
1074 if (type == "pinchUpdate") { | |
1075 double scale; | |
1076 if (!params->GetDouble( | |
1077 devtools::Input::dispatchGestureEvent::kParamPinchScale, | |
1078 &scale)) { | |
1079 return NULL; | |
1080 } | |
1081 event.data.pinchUpdate.scale = static_cast<float>(scale); | |
1082 } | |
1083 | |
1084 host->ForwardGestureEvent(event); | |
1085 return command->SuccessResponse(NULL); | 962 return command->SuccessResponse(NULL); |
1086 } | 963 } |
1087 | 964 |
1088 } // namespace content | 965 } // namespace content |
OLD | NEW |