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

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

Issue 1408363004: [DevTools] Filter any messages from previous sessions in DevToolsAgentHostImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 return Response::ServerError("Could not connect to view"); 299 return Response::ServerError("Could not connect to view");
300 300
301 if (event->type == blink::WebInputEvent::MouseWheel) 301 if (event->type == blink::WebInputEvent::MouseWheel)
302 host_->ForwardWheelEvent(wheel_event); 302 host_->ForwardWheelEvent(wheel_event);
303 else 303 else
304 host_->ForwardMouseEvent(mouse_event); 304 host_->ForwardMouseEvent(mouse_event);
305 return Response::OK(); 305 return Response::OK();
306 } 306 }
307 307
308 Response InputHandler::SynthesizePinchGesture( 308 Response InputHandler::SynthesizePinchGesture(
309 int session_id,
309 DevToolsCommandId command_id, 310 DevToolsCommandId command_id,
310 int x, 311 int x,
311 int y, 312 int y,
312 double scale_factor, 313 double scale_factor,
313 const int* relative_speed, 314 const int* relative_speed,
314 const std::string* gesture_source_type) { 315 const std::string* gesture_source_type) {
315 if (!host_) 316 if (!host_)
316 return Response::ServerError("Could not connect to view"); 317 return Response::ServerError("Could not connect to view");
317 318
318 SyntheticPinchGestureParams gesture_params; 319 SyntheticPinchGestureParams gesture_params;
319 const int kDefaultRelativeSpeed = 800; 320 const int kDefaultRelativeSpeed = 800;
320 321
321 gesture_params.scale_factor = scale_factor; 322 gesture_params.scale_factor = scale_factor;
322 gesture_params.anchor = CssPixelsToPointF(x, y, page_scale_factor_); 323 gesture_params.anchor = CssPixelsToPointF(x, y, page_scale_factor_);
323 gesture_params.relative_pointer_speed_in_pixels_s = 324 gesture_params.relative_pointer_speed_in_pixels_s =
324 relative_speed ? *relative_speed : kDefaultRelativeSpeed; 325 relative_speed ? *relative_speed : kDefaultRelativeSpeed;
325 326
326 if (!StringToGestureSourceType( 327 if (!StringToGestureSourceType(
327 gesture_source_type ? *gesture_source_type : kGestureSourceTypeDefault, 328 gesture_source_type ? *gesture_source_type : kGestureSourceTypeDefault,
328 gesture_params.gesture_source_type)) { 329 gesture_params.gesture_source_type)) {
329 return Response::InvalidParams("gestureSourceType"); 330 return Response::InvalidParams("gestureSourceType");
330 } 331 }
331 332
332 host_->QueueSyntheticGesture( 333 host_->QueueSyntheticGesture(
333 SyntheticGesture::Create(gesture_params), 334 SyntheticGesture::Create(gesture_params),
334 base::Bind(&InputHandler::SendSynthesizePinchGestureResponse, 335 base::Bind(&InputHandler::SendSynthesizePinchGestureResponse,
335 weak_factory_.GetWeakPtr(), command_id)); 336 weak_factory_.GetWeakPtr(), session_id, command_id));
336 337
337 return Response::OK(); 338 return Response::OK();
338 } 339 }
339 340
340 Response InputHandler::SynthesizeScrollGesture( 341 Response InputHandler::SynthesizeScrollGesture(
342 int session_id,
341 DevToolsCommandId command_id, 343 DevToolsCommandId command_id,
342 int x, 344 int x,
343 int y, 345 int y,
344 const int* x_distance, 346 const int* x_distance,
345 const int* y_distance, 347 const int* y_distance,
346 const int* x_overscroll, 348 const int* x_overscroll,
347 const int* y_overscroll, 349 const int* y_overscroll,
348 const bool* prevent_fling, 350 const bool* prevent_fling,
349 const int* speed, 351 const int* speed,
350 const std::string* gesture_source_type, 352 const std::string* gesture_source_type,
(...skipping 27 matching lines...) Expand all
378 if (!StringToGestureSourceType( 380 if (!StringToGestureSourceType(
379 gesture_source_type ? *gesture_source_type : kGestureSourceTypeDefault, 381 gesture_source_type ? *gesture_source_type : kGestureSourceTypeDefault,
380 gesture_params.gesture_source_type)) { 382 gesture_params.gesture_source_type)) {
381 return Response::InvalidParams("gestureSourceType"); 383 return Response::InvalidParams("gestureSourceType");
382 } 384 }
383 385
384 SynthesizeRepeatingScroll( 386 SynthesizeRepeatingScroll(
385 gesture_params, repeat_count ? *repeat_count : 0, 387 gesture_params, repeat_count ? *repeat_count : 0,
386 base::TimeDelta::FromMilliseconds(repeat_delay_ms ? *repeat_delay_ms 388 base::TimeDelta::FromMilliseconds(repeat_delay_ms ? *repeat_delay_ms
387 : 250), 389 : 250),
388 interaction_marker_name ? *interaction_marker_name : "", command_id); 390 interaction_marker_name ? *interaction_marker_name : "", session_id,
391 command_id);
389 392
390 return Response::OK(); 393 return Response::OK();
391 } 394 }
392 395
393 void InputHandler::SynthesizeRepeatingScroll( 396 void InputHandler::SynthesizeRepeatingScroll(
394 SyntheticSmoothScrollGestureParams gesture_params, 397 SyntheticSmoothScrollGestureParams gesture_params,
395 int repeat_count, 398 int repeat_count,
396 base::TimeDelta repeat_delay, 399 base::TimeDelta repeat_delay,
397 std::string interaction_marker_name, 400 std::string interaction_marker_name,
401 int session_id,
398 DevToolsCommandId command_id) { 402 DevToolsCommandId command_id) {
399 if (!interaction_marker_name.empty()) { 403 if (!interaction_marker_name.empty()) {
400 // TODO(alexclarke): Can we move this elsewhere? It doesn't really fit here. 404 // TODO(alexclarke): Can we move this elsewhere? It doesn't really fit here.
401 TRACE_EVENT_COPY_ASYNC_BEGIN0("benchmark", 405 TRACE_EVENT_COPY_ASYNC_BEGIN0("benchmark",
402 interaction_marker_name.c_str(), command_id); 406 interaction_marker_name.c_str(), command_id);
403 } 407 }
404 408
405 host_->QueueSyntheticGesture( 409 host_->QueueSyntheticGesture(
406 SyntheticGesture::Create(gesture_params), 410 SyntheticGesture::Create(gesture_params),
407 base::Bind(&InputHandler::OnScrollFinished, weak_factory_.GetWeakPtr(), 411 base::Bind(&InputHandler::OnScrollFinished, weak_factory_.GetWeakPtr(),
408 gesture_params, repeat_count, repeat_delay, 412 gesture_params, repeat_count, repeat_delay,
409 interaction_marker_name, command_id)); 413 interaction_marker_name, session_id, command_id));
410 } 414 }
411 415
412 void InputHandler::OnScrollFinished( 416 void InputHandler::OnScrollFinished(
413 SyntheticSmoothScrollGestureParams gesture_params, 417 SyntheticSmoothScrollGestureParams gesture_params,
414 int repeat_count, 418 int repeat_count,
415 base::TimeDelta repeat_delay, 419 base::TimeDelta repeat_delay,
416 std::string interaction_marker_name, 420 std::string interaction_marker_name,
421 int session_id,
417 DevToolsCommandId command_id, 422 DevToolsCommandId command_id,
418 SyntheticGesture::Result result) { 423 SyntheticGesture::Result result) {
419 if (!interaction_marker_name.empty()) { 424 if (!interaction_marker_name.empty()) {
420 TRACE_EVENT_COPY_ASYNC_END0("benchmark", 425 TRACE_EVENT_COPY_ASYNC_END0("benchmark",
421 interaction_marker_name.c_str(), command_id); 426 interaction_marker_name.c_str(), command_id);
422 } 427 }
423 428
424 if (repeat_count > 0) { 429 if (repeat_count > 0) {
425 base::MessageLoop::current()->task_runner()->PostDelayedTask( 430 base::MessageLoop::current()->task_runner()->PostDelayedTask(
426 FROM_HERE, 431 FROM_HERE, base::Bind(&InputHandler::SynthesizeRepeatingScroll,
427 base::Bind(&InputHandler::SynthesizeRepeatingScroll, 432 weak_factory_.GetWeakPtr(), gesture_params,
428 weak_factory_.GetWeakPtr(), gesture_params, repeat_count - 1, 433 repeat_count - 1, repeat_delay,
429 repeat_delay, interaction_marker_name, command_id), 434 interaction_marker_name, session_id, command_id),
430 repeat_delay); 435 repeat_delay);
431 } else { 436 } else {
432 SendSynthesizeScrollGestureResponse(command_id, result); 437 SendSynthesizeScrollGestureResponse(session_id, command_id, result);
433 } 438 }
434 } 439 }
435 440
436 Response InputHandler::SynthesizeTapGesture( 441 Response InputHandler::SynthesizeTapGesture(
442 int session_id,
437 DevToolsCommandId command_id, 443 DevToolsCommandId command_id,
438 int x, 444 int x,
439 int y, 445 int y,
440 const int* duration, 446 const int* duration,
441 const int* tap_count, 447 const int* tap_count,
442 const std::string* gesture_source_type) { 448 const std::string* gesture_source_type) {
443 if (!host_) 449 if (!host_)
444 return Response::ServerError("Could not connect to view"); 450 return Response::ServerError("Could not connect to view");
445 451
446 SyntheticTapGestureParams gesture_params; 452 SyntheticTapGestureParams gesture_params;
(...skipping 12 matching lines...) Expand all
459 if (!tap_count) 465 if (!tap_count)
460 tap_count = &kDefaultTapCount; 466 tap_count = &kDefaultTapCount;
461 467
462 for (int i = 0; i < *tap_count; i++) { 468 for (int i = 0; i < *tap_count; i++) {
463 // If we're doing more than one tap, don't send the response to the client 469 // If we're doing more than one tap, don't send the response to the client
464 // until we've completed the last tap. 470 // until we've completed the last tap.
465 bool is_last_tap = i == *tap_count - 1; 471 bool is_last_tap = i == *tap_count - 1;
466 host_->QueueSyntheticGesture( 472 host_->QueueSyntheticGesture(
467 SyntheticGesture::Create(gesture_params), 473 SyntheticGesture::Create(gesture_params),
468 base::Bind(&InputHandler::SendSynthesizeTapGestureResponse, 474 base::Bind(&InputHandler::SendSynthesizeTapGestureResponse,
469 weak_factory_.GetWeakPtr(), command_id, is_last_tap)); 475 weak_factory_.GetWeakPtr(), session_id, command_id,
476 is_last_tap));
470 } 477 }
471 478
472 return Response::OK(); 479 return Response::OK();
473 } 480 }
474 481
475 void InputHandler::SendSynthesizePinchGestureResponse( 482 void InputHandler::SendSynthesizePinchGestureResponse(
483 int session_id,
476 DevToolsCommandId command_id, 484 DevToolsCommandId command_id,
477 SyntheticGesture::Result result) { 485 SyntheticGesture::Result result) {
486 // todo: session_id
478 if (result == SyntheticGesture::Result::GESTURE_FINISHED) { 487 if (result == SyntheticGesture::Result::GESTURE_FINISHED) {
479 client_->SendSynthesizePinchGestureResponse( 488 client_->SendSynthesizePinchGestureResponse(
480 command_id, SynthesizePinchGestureResponse::Create()); 489 session_id, command_id, SynthesizePinchGestureResponse::Create());
481 } else { 490 } else {
482 client_->SendError(command_id, 491 client_->SendError(session_id, command_id,
483 Response::InternalError(base::StringPrintf( 492 Response::InternalError(base::StringPrintf(
484 "Synthetic pinch failed, result was %d", result))); 493 "Synthetic pinch failed, result was %d", result)));
485 } 494 }
486 } 495 }
487 496
488 void InputHandler::SendSynthesizeScrollGestureResponse( 497 void InputHandler::SendSynthesizeScrollGestureResponse(
498 int session_id,
489 DevToolsCommandId command_id, 499 DevToolsCommandId command_id,
490 SyntheticGesture::Result result) { 500 SyntheticGesture::Result result) {
491 if (result == SyntheticGesture::Result::GESTURE_FINISHED) { 501 if (result == SyntheticGesture::Result::GESTURE_FINISHED) {
492 client_->SendSynthesizeScrollGestureResponse( 502 client_->SendSynthesizeScrollGestureResponse(
493 command_id, SynthesizeScrollGestureResponse::Create()); 503 session_id, command_id, SynthesizeScrollGestureResponse::Create());
494 } else { 504 } else {
495 client_->SendError(command_id, 505 client_->SendError(session_id, command_id,
496 Response::InternalError(base::StringPrintf( 506 Response::InternalError(base::StringPrintf(
497 "Synthetic scroll failed, result was %d", result))); 507 "Synthetic scroll failed, result was %d", result)));
498 } 508 }
499 } 509 }
500 510
501 void InputHandler::SendSynthesizeTapGestureResponse( 511 void InputHandler::SendSynthesizeTapGestureResponse(
512 int session_id,
502 DevToolsCommandId command_id, 513 DevToolsCommandId command_id,
503 bool send_success, 514 bool send_success,
504 SyntheticGesture::Result result) { 515 SyntheticGesture::Result result) {
505 if (result == SyntheticGesture::Result::GESTURE_FINISHED) { 516 if (result == SyntheticGesture::Result::GESTURE_FINISHED) {
506 if (send_success) { 517 if (send_success) {
507 client_->SendSynthesizeTapGestureResponse( 518 client_->SendSynthesizeTapGestureResponse(
508 command_id, SynthesizeTapGestureResponse::Create()); 519 session_id, command_id, SynthesizeTapGestureResponse::Create());
509 } 520 }
510 } else { 521 } else {
511 client_->SendError(command_id, 522 client_->SendError(session_id, command_id,
512 Response::InternalError(base::StringPrintf( 523 Response::InternalError(base::StringPrintf(
513 "Synthetic tap failed, result was %d", result))); 524 "Synthetic tap failed, result was %d", result)));
514 } 525 }
515 } 526 }
516 527
517 } // namespace input 528 } // namespace input
518 } // namespace devtools 529 } // namespace devtools
519 } // namespace content 530 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698