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

Side by Side Diff: content/browser/devtools/protocol/input_handler.cc

Issue 2387353004: Delay Input.dispatchKeyEvent response until after key event ack. (Closed)
Patch Set: rebase, make sure that tests build and run Created 4 years, 2 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/protocol/input_handler.h" 5 #include "content/browser/devtools/protocol/input_handler.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 130
131 InputHandler::InputHandler() 131 InputHandler::InputHandler()
132 : host_(NULL), 132 : host_(NULL),
133 page_scale_factor_(1.0), 133 page_scale_factor_(1.0),
134 weak_factory_(this) { 134 weak_factory_(this) {
135 } 135 }
136 136
137 InputHandler::~InputHandler() { 137 InputHandler::~InputHandler() {
138 } 138 }
139 139
140 void InputHandler::OnInputEventAck(const blink::WebInputEvent& event,
141 bool was_synthetic) {
tdresser 2016/10/12 19:49:36 We appear to switch between is_synthetic and was_s
samuong 2016/10/13 22:59:10 Done.
142 if (blink::WebInputEvent::isKeyboardEventType(event.type) && was_synthetic) {
143 DCHECK(!pending_key_event_ids_.empty());
tdresser 2016/10/12 19:49:36 A compromised renderer could send bogus acks, and
samuong 2016/10/13 22:59:10 Done. That's a good point, I've added this to the
144 SendDispatchKeyEventResponse(pending_key_event_ids_.front());
145 pending_key_event_ids_.pop();
146 }
147 }
148
140 void InputHandler::SetRenderWidgetHost(RenderWidgetHostImpl* host) { 149 void InputHandler::SetRenderWidgetHost(RenderWidgetHostImpl* host) {
141 host_ = host; 150 host_ = host;
142 } 151 }
143 152
144 void InputHandler::SetClient(std::unique_ptr<Client> client) { 153 void InputHandler::SetClient(std::unique_ptr<Client> client) {
145 client_.swap(client); 154 client_.swap(client);
146 } 155 }
147 156
148 void InputHandler::OnSwapCompositorFrame( 157 void InputHandler::OnSwapCompositorFrame(
149 const cc::CompositorFrameMetadata& frame_metadata) { 158 const cc::CompositorFrameMetadata& frame_metadata) {
150 page_scale_factor_ = frame_metadata.page_scale_factor; 159 page_scale_factor_ = frame_metadata.page_scale_factor;
151 scrollable_viewport_size_ = frame_metadata.scrollable_viewport_size; 160 scrollable_viewport_size_ = frame_metadata.scrollable_viewport_size;
152 } 161 }
153 162
154 Response InputHandler::DispatchKeyEvent( 163 Response InputHandler::DispatchKeyEvent(
164 DevToolsCommandId command_id,
155 const std::string& type, 165 const std::string& type,
156 const int* modifiers, 166 const int* modifiers,
157 const double* timestamp, 167 const double* timestamp,
158 const std::string* text, 168 const std::string* text,
159 const std::string* unmodified_text, 169 const std::string* unmodified_text,
160 const std::string* key_identifier, 170 const std::string* key_identifier,
161 const std::string* code, 171 const std::string* code,
162 const std::string* key, 172 const std::string* key,
163 const int* windows_virtual_key_code, 173 const int* windows_virtual_key_code,
164 const int* native_virtual_key_code, 174 const int* native_virtual_key_code,
165 const bool* auto_repeat, 175 const bool* auto_repeat,
166 const bool* is_keypad, 176 const bool* is_keypad,
167 const bool* is_system_key) { 177 const bool* is_system_key) {
168 NativeWebKeyboardEvent event; 178 NativeWebKeyboardEvent event;
169 event.skip_in_browser = true; 179 event.skip_in_browser = true;
180 event.is_synthetic = true;
170 181
171 if (type == dispatch_key_event::kTypeKeyDown) { 182 if (type == dispatch_key_event::kTypeKeyDown) {
172 event.type = blink::WebInputEvent::KeyDown; 183 event.type = blink::WebInputEvent::KeyDown;
173 } else if (type == dispatch_key_event::kTypeKeyUp) { 184 } else if (type == dispatch_key_event::kTypeKeyUp) {
174 event.type = blink::WebInputEvent::KeyUp; 185 event.type = blink::WebInputEvent::KeyUp;
175 } else if (type == dispatch_key_event::kTypeChar) { 186 } else if (type == dispatch_key_event::kTypeChar) {
176 event.type = blink::WebInputEvent::Char; 187 event.type = blink::WebInputEvent::Char;
177 } else if (type == dispatch_key_event::kTypeRawKeyDown) { 188 } else if (type == dispatch_key_event::kTypeRawKeyDown) {
178 event.type = blink::WebInputEvent::RawKeyDown; 189 event.type = blink::WebInputEvent::RawKeyDown;
179 } else { 190 } else {
(...skipping 25 matching lines...) Expand all
205 } 216 }
206 217
207 if (key) { 218 if (key) {
208 event.domKey = static_cast<int>( 219 event.domKey = static_cast<int>(
209 ui::KeycodeConverter::KeyStringToDomKey(*key)); 220 ui::KeycodeConverter::KeyStringToDomKey(*key));
210 } 221 }
211 222
212 if (!host_) 223 if (!host_)
213 return Response::ServerError("Could not connect to view"); 224 return Response::ServerError("Could not connect to view");
214 225
226 pending_key_event_ids_.push(command_id);
215 host_->Focus(); 227 host_->Focus();
216 host_->ForwardKeyboardEvent(event); 228 host_->ForwardKeyboardEvent(event);
217 return Response::OK(); 229 return Response::OK();
218 } 230 }
219 231
220 Response InputHandler::DispatchMouseEvent( 232 Response InputHandler::DispatchMouseEvent(
221 const std::string& type, 233 const std::string& type,
222 int x, 234 int x,
223 int y, 235 int y,
224 const int* modifiers, 236 const int* modifiers,
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 bool is_last_tap = i == *tap_count - 1; 476 bool is_last_tap = i == *tap_count - 1;
465 host_->QueueSyntheticGesture( 477 host_->QueueSyntheticGesture(
466 SyntheticGesture::Create(gesture_params), 478 SyntheticGesture::Create(gesture_params),
467 base::Bind(&InputHandler::SendSynthesizeTapGestureResponse, 479 base::Bind(&InputHandler::SendSynthesizeTapGestureResponse,
468 weak_factory_.GetWeakPtr(), command_id, is_last_tap)); 480 weak_factory_.GetWeakPtr(), command_id, is_last_tap));
469 } 481 }
470 482
471 return Response::OK(); 483 return Response::OK();
472 } 484 }
473 485
486 void InputHandler::SendDispatchKeyEventResponse(DevToolsCommandId command_id) {
487 client_->SendDispatchKeyEventResponse(
488 command_id, DispatchKeyEventResponse::Create());
489 }
490
474 void InputHandler::SendSynthesizePinchGestureResponse( 491 void InputHandler::SendSynthesizePinchGestureResponse(
475 DevToolsCommandId command_id, 492 DevToolsCommandId command_id,
476 SyntheticGesture::Result result) { 493 SyntheticGesture::Result result) {
477 if (result == SyntheticGesture::Result::GESTURE_FINISHED) { 494 if (result == SyntheticGesture::Result::GESTURE_FINISHED) {
478 client_->SendSynthesizePinchGestureResponse( 495 client_->SendSynthesizePinchGestureResponse(
479 command_id, SynthesizePinchGestureResponse::Create()); 496 command_id, SynthesizePinchGestureResponse::Create());
480 } else { 497 } else {
481 client_->SendError(command_id, 498 client_->SendError(command_id,
482 Response::InternalError(base::StringPrintf( 499 Response::InternalError(base::StringPrintf(
483 "Synthetic pinch failed, result was %d", result))); 500 "Synthetic pinch failed, result was %d", result)));
(...skipping 25 matching lines...) Expand all
509 } else { 526 } else {
510 client_->SendError(command_id, 527 client_->SendError(command_id,
511 Response::InternalError(base::StringPrintf( 528 Response::InternalError(base::StringPrintf(
512 "Synthetic tap failed, result was %d", result))); 529 "Synthetic tap failed, result was %d", result)));
513 } 530 }
514 } 531 }
515 532
516 } // namespace input 533 } // namespace input
517 } // namespace devtools 534 } // namespace devtools
518 } // namespace content 535 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698