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

Side by Side Diff: content/browser/renderer_host/render_widget_host_impl.cc

Issue 1984173002: Log First User Interaction in Page Load Metrics (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Only record user interaction after first paint Created 4 years, 6 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 (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 "content/browser/renderer_host/render_widget_host_impl.h" 5 #include "content/browser/renderer_host/render_widget_host_impl.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 using RoutingIDWidgetMap = 104 using RoutingIDWidgetMap =
105 base::hash_map<RenderWidgetHostID, RenderWidgetHostImpl*>; 105 base::hash_map<RenderWidgetHostID, RenderWidgetHostImpl*>;
106 base::LazyInstance<RoutingIDWidgetMap> g_routing_id_widget_map = 106 base::LazyInstance<RoutingIDWidgetMap> g_routing_id_widget_map =
107 LAZY_INSTANCE_INITIALIZER; 107 LAZY_INSTANCE_INITIALIZER;
108 108
109 // Implements the RenderWidgetHostIterator interface. It keeps a list of 109 // Implements the RenderWidgetHostIterator interface. It keeps a list of
110 // RenderWidgetHosts, and makes sure it returns a live RenderWidgetHost at each 110 // RenderWidgetHosts, and makes sure it returns a live RenderWidgetHost at each
111 // iteration (or NULL if there isn't any left). 111 // iteration (or NULL if there isn't any left).
112 class RenderWidgetHostIteratorImpl : public RenderWidgetHostIterator { 112 class RenderWidgetHostIteratorImpl : public RenderWidgetHostIterator {
113 public: 113 public:
114 RenderWidgetHostIteratorImpl() 114 RenderWidgetHostIteratorImpl() : current_index_(0) {}
115 : current_index_(0) {
116 }
117 115
118 ~RenderWidgetHostIteratorImpl() override {} 116 ~RenderWidgetHostIteratorImpl() override {}
119 117
120 void Add(RenderWidgetHost* host) { 118 void Add(RenderWidgetHost* host) {
121 hosts_.push_back(RenderWidgetHostID(host->GetProcess()->GetID(), 119 hosts_.push_back(
122 host->GetRoutingID())); 120 RenderWidgetHostID(host->GetProcess()->GetID(), host->GetRoutingID()));
123 } 121 }
124 122
125 // RenderWidgetHostIterator: 123 // RenderWidgetHostIterator:
126 RenderWidgetHost* GetNextHost() override { 124 RenderWidgetHost* GetNextHost() override {
127 RenderWidgetHost* host = NULL; 125 RenderWidgetHost* host = NULL;
128 while (current_index_ < hosts_.size() && !host) { 126 while (current_index_ < hosts_.size() && !host) {
129 RenderWidgetHostID id = hosts_[current_index_]; 127 RenderWidgetHostID id = hosts_[current_index_];
130 host = RenderWidgetHost::FromID(id.first, id.second); 128 host = RenderWidgetHost::FromID(id.first, id.second);
131 ++current_index_; 129 ++current_index_;
132 } 130 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 CHECK(result.second) << "Inserting a duplicate item!"; 220 CHECK(result.second) << "Inserting a duplicate item!";
223 process_->AddRoute(routing_id_, this); 221 process_->AddRoute(routing_id_, this);
224 222
225 // If we're initially visible, tell the process host that we're alive. 223 // If we're initially visible, tell the process host that we're alive.
226 // Otherwise we'll notify the process host when we are first shown. 224 // Otherwise we'll notify the process host when we are first shown.
227 if (!hidden) 225 if (!hidden)
228 process_->WidgetRestored(); 226 process_->WidgetRestored();
229 227
230 latency_tracker_.Initialize(routing_id_, GetProcess()->GetID()); 228 latency_tracker_.Initialize(routing_id_, GetProcess()->GetID());
231 229
232 input_router_.reset(new InputRouterImpl( 230 input_router_.reset(new InputRouterImpl(process_, this, this, routing_id_,
233 process_->GetImmediateSender(), this, this, routing_id_, 231 GetInputRouterConfigForPlatform()));
234 GetInputRouterConfigForPlatform()));
235 232
236 touch_emulator_.reset(); 233 touch_emulator_.reset();
237 234
238 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( 235 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
239 switches::kDisableHangMonitor)) { 236 switches::kDisableHangMonitor)) {
240 hang_monitor_timeout_.reset(new TimeoutMonitor( 237 hang_monitor_timeout_.reset(new TimeoutMonitor(
241 base::Bind(&RenderWidgetHostImpl::RendererIsUnresponsive, 238 base::Bind(&RenderWidgetHostImpl::RendererIsUnresponsive,
242 weak_factory_.GetWeakPtr()))); 239 weak_factory_.GetWeakPtr())));
243 } 240 }
244 241
245 new_content_rendering_timeout_.reset(new TimeoutMonitor( 242 new_content_rendering_timeout_.reset(new TimeoutMonitor(
246 base::Bind(&RenderWidgetHostImpl::ClearDisplayedGraphics, 243 base::Bind(&RenderWidgetHostImpl::ClearDisplayedGraphics,
247 weak_factory_.GetWeakPtr()))); 244 weak_factory_.GetWeakPtr())));
248 245
249 delegate_->RenderWidgetCreated(this); 246 delegate_->RenderWidgetCreated(this);
250 } 247 }
251 248
252 RenderWidgetHostImpl::~RenderWidgetHostImpl() { 249 RenderWidgetHostImpl::~RenderWidgetHostImpl() {
253 if (!destroyed_) 250 if (!destroyed_)
254 Destroy(false); 251 Destroy(false);
255 } 252 }
256 253
257 // static 254 // static
258 RenderWidgetHost* RenderWidgetHost::FromID( 255 RenderWidgetHost* RenderWidgetHost::FromID(int32_t process_id,
259 int32_t process_id, 256 int32_t routing_id) {
260 int32_t routing_id) {
261 return RenderWidgetHostImpl::FromID(process_id, routing_id); 257 return RenderWidgetHostImpl::FromID(process_id, routing_id);
262 } 258 }
263 259
264 // static 260 // static
265 RenderWidgetHostImpl* RenderWidgetHostImpl::FromID( 261 RenderWidgetHostImpl* RenderWidgetHostImpl::FromID(int32_t process_id,
266 int32_t process_id, 262 int32_t routing_id) {
267 int32_t routing_id) {
268 DCHECK_CURRENTLY_ON(BrowserThread::UI); 263 DCHECK_CURRENTLY_ON(BrowserThread::UI);
269 RoutingIDWidgetMap* widgets = g_routing_id_widget_map.Pointer(); 264 RoutingIDWidgetMap* widgets = g_routing_id_widget_map.Pointer();
270 RoutingIDWidgetMap::iterator it = widgets->find( 265 RoutingIDWidgetMap::iterator it =
271 RenderWidgetHostID(process_id, routing_id)); 266 widgets->find(RenderWidgetHostID(process_id, routing_id));
272 return it == widgets->end() ? NULL : it->second; 267 return it == widgets->end() ? NULL : it->second;
273 } 268 }
274 269
275 // static 270 // static
276 std::unique_ptr<RenderWidgetHostIterator> 271 std::unique_ptr<RenderWidgetHostIterator>
277 RenderWidgetHost::GetRenderWidgetHosts() { 272 RenderWidgetHost::GetRenderWidgetHosts() {
278 std::unique_ptr<RenderWidgetHostIteratorImpl> hosts( 273 std::unique_ptr<RenderWidgetHostIteratorImpl> hosts(
279 new RenderWidgetHostIteratorImpl()); 274 new RenderWidgetHostIteratorImpl());
280 for (auto& it : g_routing_id_widget_map.Get()) { 275 for (auto& it : g_routing_id_widget_map.Get()) {
281 RenderWidgetHost* widget = it.second; 276 RenderWidgetHost* widget = it.second;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 return routing_id_; 329 return routing_id_;
335 } 330 }
336 331
337 RenderWidgetHostViewBase* RenderWidgetHostImpl::GetView() const { 332 RenderWidgetHostViewBase* RenderWidgetHostImpl::GetView() const {
338 return view_.get(); 333 return view_.get();
339 } 334 }
340 335
341 void RenderWidgetHostImpl::ResetSizeAndRepaintPendingFlags() { 336 void RenderWidgetHostImpl::ResetSizeAndRepaintPendingFlags() {
342 resize_ack_pending_ = false; 337 resize_ack_pending_ = false;
343 if (repaint_ack_pending_) { 338 if (repaint_ack_pending_) {
344 TRACE_EVENT_ASYNC_END0( 339 TRACE_EVENT_ASYNC_END0("renderer_host",
345 "renderer_host", "RenderWidgetHostImpl::repaint_ack_pending_", this); 340 "RenderWidgetHostImpl::repaint_ack_pending_", this);
346 } 341 }
347 repaint_ack_pending_ = false; 342 repaint_ack_pending_ = false;
348 if (old_resize_params_) 343 if (old_resize_params_)
349 old_resize_params_->new_size = gfx::Size(); 344 old_resize_params_->new_size = gfx::Size();
350 } 345 }
351 346
352 void RenderWidgetHostImpl::SendScreenRects() { 347 void RenderWidgetHostImpl::SendScreenRects() {
353 if (!renderer_initialized_ || waiting_for_screen_rects_ack_) 348 if (!renderer_initialized_ || waiting_for_screen_rects_ack_)
354 return; 349 return;
355 350
356 if (is_hidden_) { 351 if (is_hidden_) {
357 // On GTK, this comes in for backgrounded tabs. Ignore, to match what 352 // On GTK, this comes in for backgrounded tabs. Ignore, to match what
358 // happens on Win & Mac, and when the view is shown it'll call this again. 353 // happens on Win & Mac, and when the view is shown it'll call this again.
359 return; 354 return;
360 } 355 }
361 356
362 if (!view_) 357 if (!view_)
363 return; 358 return;
364 359
365 last_view_screen_rect_ = view_->GetViewBounds(); 360 last_view_screen_rect_ = view_->GetViewBounds();
366 last_window_screen_rect_ = view_->GetBoundsInRootWindow(); 361 last_window_screen_rect_ = view_->GetBoundsInRootWindow();
367 Send(new ViewMsg_UpdateScreenRects( 362 Send(new ViewMsg_UpdateScreenRects(GetRoutingID(), last_view_screen_rect_,
368 GetRoutingID(), last_view_screen_rect_, last_window_screen_rect_)); 363 last_window_screen_rect_));
369 waiting_for_screen_rects_ack_ = true; 364 waiting_for_screen_rects_ack_ = true;
370 } 365 }
371 366
372 void RenderWidgetHostImpl::SuppressNextCharEvents() { 367 void RenderWidgetHostImpl::SuppressNextCharEvents() {
373 suppress_next_char_events_ = true; 368 suppress_next_char_events_ = true;
374 } 369 }
375 370
376 void RenderWidgetHostImpl::FlushInput() { 371 void RenderWidgetHostImpl::FlushInput() {
377 input_router_->RequestNotificationWhenFlushed(); 372 input_router_->RequestNotificationWhenFlushed();
378 if (synthetic_gesture_controller_) 373 if (synthetic_gesture_controller_)
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 DCHECK(rv); 412 DCHECK(rv);
418 } 413 }
419 414
420 Destroy(also_delete); 415 Destroy(also_delete);
421 } 416 }
422 417
423 bool RenderWidgetHostImpl::IsLoading() const { 418 bool RenderWidgetHostImpl::IsLoading() const {
424 return is_loading_; 419 return is_loading_;
425 } 420 }
426 421
427 bool RenderWidgetHostImpl::OnMessageReceived(const IPC::Message &msg) { 422 bool RenderWidgetHostImpl::OnMessageReceived(const IPC::Message& msg) {
428 // Only process messages if the RenderWidget is alive. 423 // Only process messages if the RenderWidget is alive.
429 if (!renderer_initialized()) 424 if (!renderer_initialized())
430 return false; 425 return false;
431 426
432 if (owner_delegate_ && owner_delegate_->OnMessageReceived(msg)) 427 if (owner_delegate_ && owner_delegate_->OnMessageReceived(msg))
433 return true; 428 return true;
434 429
435 bool handled = true; 430 bool handled = true;
436 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostImpl, msg) 431 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostImpl, msg)
437 IPC_MESSAGE_HANDLER(FrameHostMsg_RenderProcessGone, OnRenderProcessGone) 432 IPC_MESSAGE_HANDLER(FrameHostMsg_RenderProcessGone, OnRenderProcessGone)
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 // If we have a renderer, then inform it that we are being hidden so it can 500 // If we have a renderer, then inform it that we are being hidden so it can
506 // reduce its resource utilization. 501 // reduce its resource utilization.
507 Send(new ViewMsg_WasHidden(routing_id_)); 502 Send(new ViewMsg_WasHidden(routing_id_));
508 503
509 // Tell the RenderProcessHost we were hidden. 504 // Tell the RenderProcessHost we were hidden.
510 process_->WidgetHidden(); 505 process_->WidgetHidden();
511 506
512 bool is_visible = false; 507 bool is_visible = false;
513 NotificationService::current()->Notify( 508 NotificationService::current()->Notify(
514 NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, 509 NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED,
515 Source<RenderWidgetHost>(this), 510 Source<RenderWidgetHost>(this), Details<bool>(&is_visible));
516 Details<bool>(&is_visible));
517 } 511 }
518 512
519 void RenderWidgetHostImpl::WasShown(const ui::LatencyInfo& latency_info) { 513 void RenderWidgetHostImpl::WasShown(const ui::LatencyInfo& latency_info) {
520 if (!is_hidden_) 514 if (!is_hidden_)
521 return; 515 return;
522 516
523 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::WasShown"); 517 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::WasShown");
524 is_hidden_ = false; 518 is_hidden_ = false;
525 519
526 SendScreenRects(); 520 SendScreenRects();
527 521
528 // When hidden, timeout monitoring for input events is disabled. Restore it 522 // When hidden, timeout monitoring for input events is disabled. Restore it
529 // now to ensure consistent hang detection. 523 // now to ensure consistent hang detection.
530 if (in_flight_event_count_) 524 if (in_flight_event_count_)
531 RestartHangMonitorTimeout(); 525 RestartHangMonitorTimeout();
532 526
533 // Always repaint on restore. 527 // Always repaint on restore.
534 bool needs_repainting = true; 528 bool needs_repainting = true;
535 needs_repainting_on_restore_ = false; 529 needs_repainting_on_restore_ = false;
536 Send(new ViewMsg_WasShown(routing_id_, needs_repainting, latency_info)); 530 Send(new ViewMsg_WasShown(routing_id_, needs_repainting, latency_info));
537 531
538 process_->WidgetRestored(); 532 process_->WidgetRestored();
539 533
540 bool is_visible = true; 534 bool is_visible = true;
541 NotificationService::current()->Notify( 535 NotificationService::current()->Notify(
542 NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, 536 NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED,
543 Source<RenderWidgetHost>(this), 537 Source<RenderWidgetHost>(this), Details<bool>(&is_visible));
544 Details<bool>(&is_visible));
545 538
546 // It's possible for our size to be out of sync with the renderer. The 539 // It's possible for our size to be out of sync with the renderer. The
547 // following is one case that leads to this: 540 // following is one case that leads to this:
548 // 1. WasResized -> Send ViewMsg_Resize to render 541 // 1. WasResized -> Send ViewMsg_Resize to render
549 // 2. WasResized -> do nothing as resize_ack_pending_ is true 542 // 2. WasResized -> do nothing as resize_ack_pending_ is true
550 // 3. WasHidden 543 // 3. WasHidden
551 // 4. OnUpdateRect from (1) processed. Does NOT invoke WasResized as view 544 // 4. OnUpdateRect from (1) processed. Does NOT invoke WasResized as view
552 // is hidden. Now renderer/browser out of sync with what they think size 545 // is hidden. Now renderer/browser out of sync with what they think size
553 // is. 546 // is.
554 // By invoking WasResized the renderer is updated as necessary. WasResized 547 // By invoking WasResized the renderer is updated as necessary. WasResized
(...skipping 27 matching lines...) Expand all
582 resize_params->top_controls_shrink_blink_size = 575 resize_params->top_controls_shrink_blink_size =
583 view_->DoTopControlsShrinkBlinkSize(); 576 view_->DoTopControlsShrinkBlinkSize();
584 resize_params->visible_viewport_size = view_->GetVisibleViewportSize(); 577 resize_params->visible_viewport_size = view_->GetVisibleViewportSize();
585 } 578 }
586 579
587 const bool size_changed = 580 const bool size_changed =
588 !old_resize_params_ || 581 !old_resize_params_ ||
589 old_resize_params_->new_size != resize_params->new_size || 582 old_resize_params_->new_size != resize_params->new_size ||
590 (old_resize_params_->physical_backing_size.IsEmpty() && 583 (old_resize_params_->physical_backing_size.IsEmpty() &&
591 !resize_params->physical_backing_size.IsEmpty()); 584 !resize_params->physical_backing_size.IsEmpty());
592 bool dirty = size_changed || 585 bool dirty =
586 size_changed ||
593 old_resize_params_->screen_info != resize_params->screen_info || 587 old_resize_params_->screen_info != resize_params->screen_info ||
594 old_resize_params_->physical_backing_size != 588 old_resize_params_->physical_backing_size !=
595 resize_params->physical_backing_size || 589 resize_params->physical_backing_size ||
596 old_resize_params_->is_fullscreen_granted != 590 old_resize_params_->is_fullscreen_granted !=
597 resize_params->is_fullscreen_granted || 591 resize_params->is_fullscreen_granted ||
598 old_resize_params_->display_mode != resize_params->display_mode || 592 old_resize_params_->display_mode != resize_params->display_mode ||
599 old_resize_params_->top_controls_height != 593 old_resize_params_->top_controls_height !=
600 resize_params->top_controls_height || 594 resize_params->top_controls_height ||
601 old_resize_params_->top_controls_shrink_blink_size != 595 old_resize_params_->top_controls_shrink_blink_size !=
602 resize_params->top_controls_shrink_blink_size || 596 resize_params->top_controls_shrink_blink_size ||
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 resize_ack_pending_ = params->needs_resize_ack; 636 resize_ack_pending_ = params->needs_resize_ack;
643 old_resize_params_.swap(params); 637 old_resize_params_.swap(params);
644 } 638 }
645 639
646 if (delegate_) 640 if (delegate_)
647 delegate_->RenderWidgetWasResized(this, width_changed); 641 delegate_->RenderWidgetWasResized(this, width_changed);
648 } 642 }
649 643
650 void RenderWidgetHostImpl::DispatchColorProfile() { 644 void RenderWidgetHostImpl::DispatchColorProfile() {
651 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) 645 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX)
652 static bool image_profiles = base::CommandLine::ForCurrentProcess()-> 646 static bool image_profiles =
653 HasSwitch(switches::kEnableImageColorProfiles); 647 base::CommandLine::ForCurrentProcess()->HasSwitch(
648 switches::kEnableImageColorProfiles);
654 if (!image_profiles) 649 if (!image_profiles)
655 return; 650 return;
656 #if defined(OS_WIN) 651 #if defined(OS_WIN)
657 // Windows will read disk to get the color profile data if needed, so 652 // Windows will read disk to get the color profile data if needed, so
658 // dispatch the SendColorProfile() work off the UI thread. 653 // dispatch the SendColorProfile() work off the UI thread.
659 BrowserThread::PostBlockingPoolTask( 654 BrowserThread::PostBlockingPoolTask(
660 FROM_HERE, 655 FROM_HERE, base::Bind(&RenderWidgetHostImpl::SendColorProfile,
661 base::Bind(&RenderWidgetHostImpl::SendColorProfile, 656 weak_factory_.GetWeakPtr()));
662 weak_factory_.GetWeakPtr()));
663 #elif !defined(OS_CHROMEOS) && !defined(OS_ANDROID) 657 #elif !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
664 // Only support desktop Mac and Linux at this time. 658 // Only support desktop Mac and Linux at this time.
665 SendColorProfile(); 659 SendColorProfile();
666 #endif 660 #endif
667 #endif 661 #endif
668 } 662 }
669 663
670 void RenderWidgetHostImpl::SendColorProfile() { 664 void RenderWidgetHostImpl::SendColorProfile() {
671 if (!view_ || !delegate_) 665 if (!view_ || !delegate_)
672 return; 666 return;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 // eliminate this function if so. 750 // eliminate this function if so.
757 SetView(NULL); 751 SetView(NULL);
758 } 752 }
759 753
760 void RenderWidgetHostImpl::CopyFromBackingStore( 754 void RenderWidgetHostImpl::CopyFromBackingStore(
761 const gfx::Rect& src_subrect, 755 const gfx::Rect& src_subrect,
762 const gfx::Size& accelerated_dst_size, 756 const gfx::Size& accelerated_dst_size,
763 const ReadbackRequestCallback& callback, 757 const ReadbackRequestCallback& callback,
764 const SkColorType preferred_color_type) { 758 const SkColorType preferred_color_type) {
765 if (view_) { 759 if (view_) {
766 TRACE_EVENT0("browser", 760 TRACE_EVENT0(
761 "browser",
767 "RenderWidgetHostImpl::CopyFromBackingStore::FromCompositingSurface"); 762 "RenderWidgetHostImpl::CopyFromBackingStore::FromCompositingSurface");
768 gfx::Rect accelerated_copy_rect = src_subrect.IsEmpty() ? 763 gfx::Rect accelerated_copy_rect =
769 gfx::Rect(view_->GetViewBounds().size()) : src_subrect; 764 src_subrect.IsEmpty() ? gfx::Rect(view_->GetViewBounds().size())
765 : src_subrect;
770 view_->CopyFromCompositingSurface(accelerated_copy_rect, 766 view_->CopyFromCompositingSurface(accelerated_copy_rect,
771 accelerated_dst_size, callback, 767 accelerated_dst_size, callback,
772 preferred_color_type); 768 preferred_color_type);
773 return; 769 return;
774 } 770 }
775 771
776 callback.Run(SkBitmap(), content::READBACK_FAILED); 772 callback.Run(SkBitmap(), content::READBACK_FAILED);
777 } 773 }
778 774
779 bool RenderWidgetHostImpl::CanCopyFromBackingStore() { 775 bool RenderWidgetHostImpl::CanCopyFromBackingStore() {
780 if (view_) 776 if (view_)
781 return view_->IsSurfaceAvailableForCopy(); 777 return view_->IsSurfaceAvailableForCopy();
782 return false; 778 return false;
783 } 779 }
784 780
785 void RenderWidgetHostImpl::LockBackingStore() { 781 void RenderWidgetHostImpl::LockBackingStore() {
786 if (view_) 782 if (view_)
787 view_->LockCompositingSurface(); 783 view_->LockCompositingSurface();
788 } 784 }
789 785
790 void RenderWidgetHostImpl::UnlockBackingStore() { 786 void RenderWidgetHostImpl::UnlockBackingStore() {
791 if (view_) 787 if (view_)
792 view_->UnlockCompositingSurface(); 788 view_->UnlockCompositingSurface();
793 } 789 }
794 790
795 #if defined(OS_MACOSX) 791 #if defined(OS_MACOSX)
796 void RenderWidgetHostImpl::PauseForPendingResizeOrRepaints() { 792 void RenderWidgetHostImpl::PauseForPendingResizeOrRepaints() {
797 TRACE_EVENT0("browser", 793 TRACE_EVENT0("browser",
798 "RenderWidgetHostImpl::PauseForPendingResizeOrRepaints"); 794 "RenderWidgetHostImpl::PauseForPendingResizeOrRepaints");
799 795
800 if (!CanPauseForPendingResizeOrRepaints()) 796 if (!CanPauseForPendingResizeOrRepaints())
801 return; 797 return;
802 798
803 WaitForSurface(); 799 WaitForSurface();
804 } 800 }
805 801
806 bool RenderWidgetHostImpl::CanPauseForPendingResizeOrRepaints() { 802 bool RenderWidgetHostImpl::CanPauseForPendingResizeOrRepaints() {
807 // Do not pause if the view is hidden. 803 // Do not pause if the view is hidden.
808 if (is_hidden()) 804 if (is_hidden())
(...skipping 20 matching lines...) Expand all
829 // UpdateRect messages.) 825 // UpdateRect messages.)
830 gfx::Size view_size = current_size_; 826 gfx::Size view_size = current_size_;
831 if (!auto_resize_enabled_) { 827 if (!auto_resize_enabled_) {
832 // Get the desired size from the current view bounds. 828 // Get the desired size from the current view bounds.
833 gfx::Rect view_rect = view_->GetViewBounds(); 829 gfx::Rect view_rect = view_->GetViewBounds();
834 if (view_rect.IsEmpty()) 830 if (view_rect.IsEmpty())
835 return; 831 return;
836 view_size = view_rect.size(); 832 view_size = view_rect.size();
837 } 833 }
838 834
839 TRACE_EVENT2("renderer_host", 835 TRACE_EVENT2("renderer_host", "RenderWidgetHostImpl::WaitForSurface", "width",
840 "RenderWidgetHostImpl::WaitForSurface", 836 base::IntToString(view_size.width()), "height",
841 "width",
842 base::IntToString(view_size.width()),
843 "height",
844 base::IntToString(view_size.height())); 837 base::IntToString(view_size.height()));
845 838
846 // We should not be asked to paint while we are hidden. If we are hidden, 839 // We should not be asked to paint while we are hidden. If we are hidden,
847 // then it means that our consumer failed to call WasShown. 840 // then it means that our consumer failed to call WasShown.
848 DCHECK(!is_hidden_) << "WaitForSurface called while hidden!"; 841 DCHECK(!is_hidden_) << "WaitForSurface called while hidden!";
849 842
850 // We should never be called recursively; this can theoretically lead to 843 // We should never be called recursively; this can theoretically lead to
851 // infinite recursion and almost certainly leads to lower performance. 844 // infinite recursion and almost certainly leads to lower performance.
852 DCHECK(!in_get_backing_store_) << "WaitForSurface called recursively!"; 845 DCHECK(!in_get_backing_store_) << "WaitForSurface called recursively!";
853 base::AutoReset<bool> auto_reset_in_get_backing_store( 846 base::AutoReset<bool> auto_reset_in_get_backing_store(&in_get_backing_store_,
854 &in_get_backing_store_, true); 847 true);
855 848
856 // We might have a surface that we can use already. 849 // We might have a surface that we can use already.
857 if (view_->HasAcceleratedSurface(view_size)) 850 if (view_->HasAcceleratedSurface(view_size))
858 return; 851 return;
859 852
860 // Request that the renderer produce a frame of the right size, if it 853 // Request that the renderer produce a frame of the right size, if it
861 // hasn't been requested already. 854 // hasn't been requested already.
862 if (!repaint_ack_pending_ && !resize_ack_pending_) { 855 if (!repaint_ack_pending_ && !resize_ack_pending_) {
863 repaint_start_time_ = TimeTicks::Now(); 856 repaint_start_time_ = TimeTicks::Now();
864 repaint_ack_pending_ = true; 857 repaint_ack_pending_ = true;
(...skipping 28 matching lines...) Expand all
893 886
894 bool RenderWidgetHostImpl::ScheduleComposite() { 887 bool RenderWidgetHostImpl::ScheduleComposite() {
895 if (is_hidden_ || current_size_.IsEmpty() || repaint_ack_pending_ || 888 if (is_hidden_ || current_size_.IsEmpty() || repaint_ack_pending_ ||
896 resize_ack_pending_) { 889 resize_ack_pending_) {
897 return false; 890 return false;
898 } 891 }
899 892
900 // Send out a request to the renderer to paint the view if required. 893 // Send out a request to the renderer to paint the view if required.
901 repaint_start_time_ = TimeTicks::Now(); 894 repaint_start_time_ = TimeTicks::Now();
902 repaint_ack_pending_ = true; 895 repaint_ack_pending_ = true;
903 TRACE_EVENT_ASYNC_BEGIN0( 896 TRACE_EVENT_ASYNC_BEGIN0("renderer_host",
904 "renderer_host", "RenderWidgetHostImpl::repaint_ack_pending_", this); 897 "RenderWidgetHostImpl::repaint_ack_pending_", this);
905 Send(new ViewMsg_Repaint(routing_id_, current_size_)); 898 Send(new ViewMsg_Repaint(routing_id_, current_size_));
906 return true; 899 return true;
907 } 900 }
908 901
909 void RenderWidgetHostImpl::StartHangMonitorTimeout(base::TimeDelta delay) { 902 void RenderWidgetHostImpl::StartHangMonitorTimeout(base::TimeDelta delay) {
910 if (hang_monitor_timeout_) 903 if (hang_monitor_timeout_)
911 hang_monitor_timeout_->Start(delay); 904 hang_monitor_timeout_->Start(delay);
912 } 905 }
913 906
914 void RenderWidgetHostImpl::RestartHangMonitorTimeout() { 907 void RenderWidgetHostImpl::RestartHangMonitorTimeout() {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 delegate_->OnFirstPaintAfterLoad(this); 943 delegate_->OnFirstPaintAfterLoad(this);
951 } 944 }
952 945
953 void RenderWidgetHostImpl::ForwardMouseEvent(const WebMouseEvent& mouse_event) { 946 void RenderWidgetHostImpl::ForwardMouseEvent(const WebMouseEvent& mouse_event) {
954 ForwardMouseEventWithLatencyInfo(mouse_event, ui::LatencyInfo()); 947 ForwardMouseEventWithLatencyInfo(mouse_event, ui::LatencyInfo());
955 if (owner_delegate_) 948 if (owner_delegate_)
956 owner_delegate_->RenderWidgetDidForwardMouseEvent(mouse_event); 949 owner_delegate_->RenderWidgetDidForwardMouseEvent(mouse_event);
957 } 950 }
958 951
959 void RenderWidgetHostImpl::ForwardMouseEventWithLatencyInfo( 952 void RenderWidgetHostImpl::ForwardMouseEventWithLatencyInfo(
960 const blink::WebMouseEvent& mouse_event, 953 const blink::WebMouseEvent& mouse_event,
961 const ui::LatencyInfo& ui_latency) { 954 const ui::LatencyInfo& ui_latency) {
962 TRACE_EVENT2("input", "RenderWidgetHostImpl::ForwardMouseEvent", 955 TRACE_EVENT2("input", "RenderWidgetHostImpl::ForwardMouseEvent", "x",
963 "x", mouse_event.x, "y", mouse_event.y); 956 mouse_event.x, "y", mouse_event.y);
964 957
965 for (size_t i = 0; i < mouse_event_callbacks_.size(); ++i) { 958 for (size_t i = 0; i < mouse_event_callbacks_.size(); ++i) {
966 if (mouse_event_callbacks_[i].Run(mouse_event)) 959 if (mouse_event_callbacks_[i].Run(mouse_event))
967 return; 960 return;
968 } 961 }
969 962
970 if (ShouldDropInputEvents()) 963 if (ShouldDropInputEvents())
971 return; 964 return;
972 965
973 if (touch_emulator_ && touch_emulator_->HandleMouseEvent(mouse_event)) 966 if (touch_emulator_ && touch_emulator_->HandleMouseEvent(mouse_event))
974 return; 967 return;
975 968
976 MouseEventWithLatencyInfo mouse_with_latency(mouse_event, ui_latency); 969 MouseEventWithLatencyInfo mouse_with_latency(mouse_event, ui_latency);
977 latency_tracker_.OnInputEvent(mouse_event, &mouse_with_latency.latency); 970 latency_tracker_.OnInputEvent(mouse_event, &mouse_with_latency.latency);
978 input_router_->SendMouseEvent(mouse_with_latency); 971 input_router_->SendMouseEvent(mouse_with_latency);
972 FOR_EACH_OBSERVER(InputEventObserver, input_event_observers_,
973 OnInputEvent(mouse_event));
979 } 974 }
980 975
981 void RenderWidgetHostImpl::ForwardWheelEvent( 976 void RenderWidgetHostImpl::ForwardWheelEvent(
982 const WebMouseWheelEvent& wheel_event) { 977 const WebMouseWheelEvent& wheel_event) {
983 ForwardWheelEventWithLatencyInfo(wheel_event, ui::LatencyInfo()); 978 ForwardWheelEventWithLatencyInfo(wheel_event, ui::LatencyInfo());
984 } 979 }
985 980
986 void RenderWidgetHostImpl::ForwardWheelEventWithLatencyInfo( 981 void RenderWidgetHostImpl::ForwardWheelEventWithLatencyInfo(
987 const blink::WebMouseWheelEvent& wheel_event, 982 const blink::WebMouseWheelEvent& wheel_event,
988 const ui::LatencyInfo& ui_latency) { 983 const ui::LatencyInfo& ui_latency) {
989 TRACE_EVENT2("input", "RenderWidgetHostImpl::ForwardWheelEvent", 984 TRACE_EVENT2("input", "RenderWidgetHostImpl::ForwardWheelEvent", "dx",
990 "dx", wheel_event.deltaX, "dy", wheel_event.deltaY); 985 wheel_event.deltaX, "dy", wheel_event.deltaY);
991 986
992 if (ShouldDropInputEvents()) 987 if (ShouldDropInputEvents())
993 return; 988 return;
994 989
995 if (touch_emulator_ && touch_emulator_->HandleMouseWheelEvent(wheel_event)) 990 if (touch_emulator_ && touch_emulator_->HandleMouseWheelEvent(wheel_event))
996 return; 991 return;
997 992
998 MouseWheelEventWithLatencyInfo wheel_with_latency(wheel_event, ui_latency); 993 MouseWheelEventWithLatencyInfo wheel_with_latency(wheel_event, ui_latency);
999 latency_tracker_.OnInputEvent(wheel_event, &wheel_with_latency.latency); 994 latency_tracker_.OnInputEvent(wheel_event, &wheel_with_latency.latency);
1000 input_router_->SendWheelEvent(wheel_with_latency); 995 input_router_->SendWheelEvent(wheel_with_latency);
996 FOR_EACH_OBSERVER(InputEventObserver, input_event_observers_,
997 OnInputEvent(wheel_event));
1001 } 998 }
1002 999
1003 void RenderWidgetHostImpl::ForwardEmulatedGestureEvent( 1000 void RenderWidgetHostImpl::ForwardEmulatedGestureEvent(
1004 const blink::WebGestureEvent& gesture_event) { 1001 const blink::WebGestureEvent& gesture_event) {
1005 ForwardGestureEvent(gesture_event); 1002 ForwardGestureEvent(gesture_event);
1006 } 1003 }
1007 1004
1008 void RenderWidgetHostImpl::ForwardGestureEvent( 1005 void RenderWidgetHostImpl::ForwardGestureEvent(
1009 const blink::WebGestureEvent& gesture_event) { 1006 const blink::WebGestureEvent& gesture_event) {
1010 ForwardGestureEventWithLatencyInfo(gesture_event, ui::LatencyInfo()); 1007 ForwardGestureEventWithLatencyInfo(gesture_event, ui::LatencyInfo());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1047 CreateScrollBeginForWrapping(gesture_event), ui::LatencyInfo()); 1044 CreateScrollBeginForWrapping(gesture_event), ui::LatencyInfo());
1048 } 1045 }
1049 1046
1050 // Delegate must be non-null, due to |ShouldDropInputEvents()| test. 1047 // Delegate must be non-null, due to |ShouldDropInputEvents()| test.
1051 if (delegate_->PreHandleGestureEvent(gesture_event)) 1048 if (delegate_->PreHandleGestureEvent(gesture_event))
1052 return; 1049 return;
1053 1050
1054 GestureEventWithLatencyInfo gesture_with_latency(gesture_event, ui_latency); 1051 GestureEventWithLatencyInfo gesture_with_latency(gesture_event, ui_latency);
1055 latency_tracker_.OnInputEvent(gesture_event, &gesture_with_latency.latency); 1052 latency_tracker_.OnInputEvent(gesture_event, &gesture_with_latency.latency);
1056 input_router_->SendGestureEvent(gesture_with_latency); 1053 input_router_->SendGestureEvent(gesture_with_latency);
1054 FOR_EACH_OBSERVER(InputEventObserver, input_event_observers_,
1055 OnInputEvent(gesture_event));
1057 1056
1058 if (scroll_update_needs_wrapping) { 1057 if (scroll_update_needs_wrapping) {
1059 ForwardGestureEventWithLatencyInfo( 1058 ForwardGestureEventWithLatencyInfo(
1060 CreateScrollEndForWrapping(gesture_event), ui::LatencyInfo()); 1059 CreateScrollEndForWrapping(gesture_event), ui::LatencyInfo());
1061 } 1060 }
1062 } 1061 }
1063 1062
1064 void RenderWidgetHostImpl::ForwardEmulatedTouchEvent( 1063 void RenderWidgetHostImpl::ForwardEmulatedTouchEvent(
1065 const blink::WebTouchEvent& touch_event) { 1064 const blink::WebTouchEvent& touch_event) {
1066 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardEmulatedTouchEvent"); 1065 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardEmulatedTouchEvent");
1067 1066
1068 TouchEventWithLatencyInfo touch_with_latency(touch_event); 1067 TouchEventWithLatencyInfo touch_with_latency(touch_event);
1069 latency_tracker_.OnInputEvent(touch_event, &touch_with_latency.latency); 1068 latency_tracker_.OnInputEvent(touch_event, &touch_with_latency.latency);
1070 input_router_->SendTouchEvent(touch_with_latency); 1069 input_router_->SendTouchEvent(touch_with_latency);
1070 FOR_EACH_OBSERVER(InputEventObserver, input_event_observers_,
1071 OnInputEvent(touch_event));
1071 } 1072 }
1072 1073
1073 void RenderWidgetHostImpl::ForwardTouchEventWithLatencyInfo( 1074 void RenderWidgetHostImpl::ForwardTouchEventWithLatencyInfo(
1074 const blink::WebTouchEvent& touch_event, 1075 const blink::WebTouchEvent& touch_event,
1075 const ui::LatencyInfo& ui_latency) { 1076 const ui::LatencyInfo& ui_latency) {
1076 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardTouchEvent"); 1077 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardTouchEvent");
1077 1078
1078 // Always forward TouchEvents for touch stream consistency. They will be 1079 // Always forward TouchEvents for touch stream consistency. They will be
1079 // ignored if appropriate in FilterInputEvent(). 1080 // ignored if appropriate in FilterInputEvent().
1080 1081
1081 TouchEventWithLatencyInfo touch_with_latency(touch_event, ui_latency); 1082 TouchEventWithLatencyInfo touch_with_latency(touch_event, ui_latency);
1082 if (touch_emulator_ && 1083 if (touch_emulator_ &&
1083 touch_emulator_->HandleTouchEvent(touch_with_latency.event)) { 1084 touch_emulator_->HandleTouchEvent(touch_with_latency.event)) {
1084 if (view_) { 1085 if (view_) {
1085 view_->ProcessAckedTouchEvent( 1086 view_->ProcessAckedTouchEvent(touch_with_latency,
1086 touch_with_latency, INPUT_EVENT_ACK_STATE_CONSUMED); 1087 INPUT_EVENT_ACK_STATE_CONSUMED);
1087 } 1088 }
1088 return; 1089 return;
1089 } 1090 }
1090 1091
1091 latency_tracker_.OnInputEvent(touch_event, &touch_with_latency.latency); 1092 latency_tracker_.OnInputEvent(touch_event, &touch_with_latency.latency);
1092 input_router_->SendTouchEvent(touch_with_latency); 1093 input_router_->SendTouchEvent(touch_with_latency);
1094 FOR_EACH_OBSERVER(InputEventObserver, input_event_observers_,
1095 OnInputEvent(touch_event));
1093 } 1096 }
1094 1097
1095 void RenderWidgetHostImpl::ForwardKeyboardEvent( 1098 void RenderWidgetHostImpl::ForwardKeyboardEvent(
1096 const NativeWebKeyboardEvent& key_event) { 1099 const NativeWebKeyboardEvent& key_event) {
1097 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardKeyboardEvent"); 1100 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardKeyboardEvent");
1098 if (owner_delegate_ && 1101 if (owner_delegate_ &&
1099 !owner_delegate_->MayRenderWidgetForwardKeyboardEvent(key_event)) { 1102 !owner_delegate_->MayRenderWidgetForwardKeyboardEvent(key_event)) {
1100 return; 1103 return;
1101 } 1104 }
1102 1105
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1152 suppress_next_char_events_ = false; 1155 suppress_next_char_events_ = false;
1153 } 1156 }
1154 1157
1155 if (touch_emulator_ && touch_emulator_->HandleKeyboardEvent(key_event)) 1158 if (touch_emulator_ && touch_emulator_->HandleKeyboardEvent(key_event))
1156 return; 1159 return;
1157 1160
1158 NativeWebKeyboardEventWithLatencyInfo key_event_with_latency(key_event); 1161 NativeWebKeyboardEventWithLatencyInfo key_event_with_latency(key_event);
1159 key_event_with_latency.event.isBrowserShortcut = is_shortcut; 1162 key_event_with_latency.event.isBrowserShortcut = is_shortcut;
1160 latency_tracker_.OnInputEvent(key_event, &key_event_with_latency.latency); 1163 latency_tracker_.OnInputEvent(key_event, &key_event_with_latency.latency);
1161 input_router_->SendKeyboardEvent(key_event_with_latency); 1164 input_router_->SendKeyboardEvent(key_event_with_latency);
1165 FOR_EACH_OBSERVER(InputEventObserver, input_event_observers_,
1166 OnInputEvent(key_event));
1162 } 1167 }
1163 1168
1164 void RenderWidgetHostImpl::QueueSyntheticGesture( 1169 void RenderWidgetHostImpl::QueueSyntheticGesture(
1165 std::unique_ptr<SyntheticGesture> synthetic_gesture, 1170 std::unique_ptr<SyntheticGesture> synthetic_gesture,
1166 const base::Callback<void(SyntheticGesture::Result)>& on_complete) { 1171 const base::Callback<void(SyntheticGesture::Result)>& on_complete) {
1167 if (!synthetic_gesture_controller_ && view_) { 1172 if (!synthetic_gesture_controller_ && view_) {
1168 synthetic_gesture_controller_.reset( 1173 synthetic_gesture_controller_.reset(
1169 new SyntheticGestureController(view_->CreateSyntheticGestureTarget())); 1174 new SyntheticGestureController(view_->CreateSyntheticGestureTarget()));
1170 } 1175 }
1171 if (synthetic_gesture_controller_) { 1176 if (synthetic_gesture_controller_) {
1172 synthetic_gesture_controller_->QueueSyntheticGesture( 1177 synthetic_gesture_controller_->QueueSyntheticGesture(
1173 std::move(synthetic_gesture), on_complete); 1178 std::move(synthetic_gesture), on_complete);
1174 } 1179 }
1175 } 1180 }
1176 1181
1177 void RenderWidgetHostImpl::SetCursor(const WebCursor& cursor) { 1182 void RenderWidgetHostImpl::SetCursor(const WebCursor& cursor) {
1178 if (!view_) 1183 if (!view_)
1179 return; 1184 return;
1180 view_->UpdateCursor(cursor); 1185 view_->UpdateCursor(cursor);
1181 } 1186 }
1182 1187
1183 void RenderWidgetHostImpl::ShowContextMenuAtPoint(const gfx::Point& point) { 1188 void RenderWidgetHostImpl::ShowContextMenuAtPoint(const gfx::Point& point) {
1184 Send(new ViewMsg_ShowContextMenu( 1189 Send(new ViewMsg_ShowContextMenu(GetRoutingID(), ui::MENU_SOURCE_MOUSE,
1185 GetRoutingID(), ui::MENU_SOURCE_MOUSE, point)); 1190 point));
1186 } 1191 }
1187 1192
1188 void RenderWidgetHostImpl::SendCursorVisibilityState(bool is_visible) { 1193 void RenderWidgetHostImpl::SendCursorVisibilityState(bool is_visible) {
1189 Send(new InputMsg_CursorVisibilityChange(GetRoutingID(), is_visible)); 1194 Send(new InputMsg_CursorVisibilityChange(GetRoutingID(), is_visible));
1190 } 1195 }
1191 1196
1192 int64_t RenderWidgetHostImpl::GetLatencyComponentId() const { 1197 int64_t RenderWidgetHostImpl::GetLatencyComponentId() const {
1193 return latency_tracker_.latency_component_id(); 1198 return latency_tracker_.latency_component_id();
1194 } 1199 }
1195 1200
1196 // static 1201 // static
1197 void RenderWidgetHostImpl::DisableResizeAckCheckForTesting() { 1202 void RenderWidgetHostImpl::DisableResizeAckCheckForTesting() {
1198 g_check_for_pending_resize_ack = false; 1203 g_check_for_pending_resize_ack = false;
1199 } 1204 }
1200 1205
1201 void RenderWidgetHostImpl::AddKeyPressEventCallback( 1206 void RenderWidgetHostImpl::AddKeyPressEventCallback(
1202 const KeyPressEventCallback& callback) { 1207 const KeyPressEventCallback& callback) {
1203 key_press_event_callbacks_.push_back(callback); 1208 key_press_event_callbacks_.push_back(callback);
1204 } 1209 }
1205 1210
1206 void RenderWidgetHostImpl::RemoveKeyPressEventCallback( 1211 void RenderWidgetHostImpl::RemoveKeyPressEventCallback(
1207 const KeyPressEventCallback& callback) { 1212 const KeyPressEventCallback& callback) {
1208 for (size_t i = 0; i < key_press_event_callbacks_.size(); ++i) { 1213 for (size_t i = 0; i < key_press_event_callbacks_.size(); ++i) {
1209 if (key_press_event_callbacks_[i].Equals(callback)) { 1214 if (key_press_event_callbacks_[i].Equals(callback)) {
1210 key_press_event_callbacks_.erase( 1215 key_press_event_callbacks_.erase(key_press_event_callbacks_.begin() + i);
1211 key_press_event_callbacks_.begin() + i);
1212 return; 1216 return;
1213 } 1217 }
1214 } 1218 }
1215 } 1219 }
1216 1220
1217 void RenderWidgetHostImpl::AddMouseEventCallback( 1221 void RenderWidgetHostImpl::AddMouseEventCallback(
1218 const MouseEventCallback& callback) { 1222 const MouseEventCallback& callback) {
1219 mouse_event_callbacks_.push_back(callback); 1223 mouse_event_callbacks_.push_back(callback);
1220 } 1224 }
1221 1225
1222 void RenderWidgetHostImpl::RemoveMouseEventCallback( 1226 void RenderWidgetHostImpl::RemoveMouseEventCallback(
1223 const MouseEventCallback& callback) { 1227 const MouseEventCallback& callback) {
1224 for (size_t i = 0; i < mouse_event_callbacks_.size(); ++i) { 1228 for (size_t i = 0; i < mouse_event_callbacks_.size(); ++i) {
1225 if (mouse_event_callbacks_[i].Equals(callback)) { 1229 if (mouse_event_callbacks_[i].Equals(callback)) {
1226 mouse_event_callbacks_.erase(mouse_event_callbacks_.begin() + i); 1230 mouse_event_callbacks_.erase(mouse_event_callbacks_.begin() + i);
1227 return; 1231 return;
1228 } 1232 }
1229 } 1233 }
1230 } 1234 }
1231 1235
1236 void RenderWidgetHostImpl::AddInputEventObserver(
1237 RenderWidgetHost::InputEventObserver* observer) {
1238 input_event_observers_.AddObserver(observer);
1239 }
1240
1241 void RenderWidgetHostImpl::RemoveInputEventObserver(
1242 RenderWidgetHost::InputEventObserver* observer) {
1243 input_event_observers_.RemoveObserver(observer);
1244 }
1245
1232 void RenderWidgetHostImpl::GetWebScreenInfo(blink::WebScreenInfo* result) { 1246 void RenderWidgetHostImpl::GetWebScreenInfo(blink::WebScreenInfo* result) {
1233 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::GetWebScreenInfo"); 1247 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::GetWebScreenInfo");
1234 if (view_) 1248 if (view_)
1235 view_->GetScreenInfo(result); 1249 view_->GetScreenInfo(result);
1236 else 1250 else
1237 RenderWidgetHostViewBase::GetDefaultScreenInfo(result); 1251 RenderWidgetHostViewBase::GetDefaultScreenInfo(result);
1238 // TODO(sievers): find a way to make this done another way so the method 1252 // TODO(sievers): find a way to make this done another way so the method
1239 // can be const. 1253 // can be const.
1240 latency_tracker_.set_device_scale_factor(result->deviceScaleFactor); 1254 latency_tracker_.set_device_scale_factor(result->deviceScaleFactor);
1241 if (IsUseZoomForDSFEnabled()) 1255 if (IsUseZoomForDSFEnabled())
(...skipping 26 matching lines...) Expand all
1268 WasResized(); 1282 WasResized();
1269 } 1283 }
1270 1284
1271 void RenderWidgetHostImpl::GetSnapshotFromBrowser( 1285 void RenderWidgetHostImpl::GetSnapshotFromBrowser(
1272 const GetSnapshotFromBrowserCallback& callback) { 1286 const GetSnapshotFromBrowserCallback& callback) {
1273 int id = next_browser_snapshot_id_++; 1287 int id = next_browser_snapshot_id_++;
1274 pending_browser_snapshots_.insert(std::make_pair(id, callback)); 1288 pending_browser_snapshots_.insert(std::make_pair(id, callback));
1275 Send(new ViewMsg_ForceRedraw(GetRoutingID(), id)); 1289 Send(new ViewMsg_ForceRedraw(GetRoutingID(), id));
1276 } 1290 }
1277 1291
1278 const NativeWebKeyboardEvent* 1292 const NativeWebKeyboardEvent* RenderWidgetHostImpl::GetLastKeyboardEvent()
1279 RenderWidgetHostImpl::GetLastKeyboardEvent() const { 1293 const {
1280 return input_router_->GetLastKeyboardEvent(); 1294 return input_router_->GetLastKeyboardEvent();
1281 } 1295 }
1282 1296
1283 void RenderWidgetHostImpl::OnSelectionChanged(const base::string16& text, 1297 void RenderWidgetHostImpl::OnSelectionChanged(const base::string16& text,
1284 uint32_t offset, 1298 uint32_t offset,
1285 const gfx::Range& range) { 1299 const gfx::Range& range) {
1286 if (view_) 1300 if (view_)
1287 view_->SelectionChanged(text, static_cast<size_t>(offset), range); 1301 view_->SelectionChanged(text, static_cast<size_t>(offset), range);
1288 } 1302 }
1289 1303
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1342 1356
1343 if (view_) { 1357 if (view_) {
1344 view_->RenderProcessGone(status, exit_code); 1358 view_->RenderProcessGone(status, exit_code);
1345 view_.reset(); // The View should be deleted by RenderProcessGone. 1359 view_.reset(); // The View should be deleted by RenderProcessGone.
1346 } 1360 }
1347 1361
1348 // Reconstruct the input router to ensure that it has fresh state for a new 1362 // Reconstruct the input router to ensure that it has fresh state for a new
1349 // renderer. Otherwise it may be stuck waiting for the old renderer to ack an 1363 // renderer. Otherwise it may be stuck waiting for the old renderer to ack an
1350 // event. (In particular, the above call to view_->RenderProcessGone will 1364 // event. (In particular, the above call to view_->RenderProcessGone will
1351 // destroy the aura window, which may dispatch a synthetic mouse move.) 1365 // destroy the aura window, which may dispatch a synthetic mouse move.)
1352 input_router_.reset(new InputRouterImpl( 1366 input_router_.reset(new InputRouterImpl(process_, this, this, routing_id_,
1353 process_->GetImmediateSender(), this, this, routing_id_, 1367 GetInputRouterConfigForPlatform()));
1354 GetInputRouterConfigForPlatform()));
1355 1368
1356 synthetic_gesture_controller_.reset(); 1369 synthetic_gesture_controller_.reset();
1357 } 1370 }
1358 1371
1359 void RenderWidgetHostImpl::UpdateTextDirection(WebTextDirection direction) { 1372 void RenderWidgetHostImpl::UpdateTextDirection(WebTextDirection direction) {
1360 text_direction_updated_ = true; 1373 text_direction_updated_ = true;
1361 text_direction_ = direction; 1374 text_direction_ = direction;
1362 } 1375 }
1363 1376
1364 void RenderWidgetHostImpl::CancelUpdateTextDirection() { 1377 void RenderWidgetHostImpl::CancelUpdateTextDirection() {
1365 if (text_direction_updated_) 1378 if (text_direction_updated_)
1366 text_direction_canceled_ = true; 1379 text_direction_canceled_ = true;
1367 } 1380 }
1368 1381
1369 void RenderWidgetHostImpl::NotifyTextDirection() { 1382 void RenderWidgetHostImpl::NotifyTextDirection() {
1370 if (text_direction_updated_) { 1383 if (text_direction_updated_) {
1371 if (!text_direction_canceled_) 1384 if (!text_direction_canceled_)
1372 Send(new ViewMsg_SetTextDirection(GetRoutingID(), text_direction_)); 1385 Send(new ViewMsg_SetTextDirection(GetRoutingID(), text_direction_));
1373 text_direction_updated_ = false; 1386 text_direction_updated_ = false;
1374 text_direction_canceled_ = false; 1387 text_direction_canceled_ = false;
1375 } 1388 }
1376 } 1389 }
1377 1390
1378 void RenderWidgetHostImpl::ImeSetComposition( 1391 void RenderWidgetHostImpl::ImeSetComposition(
1379 const base::string16& text, 1392 const base::string16& text,
1380 const std::vector<blink::WebCompositionUnderline>& underlines, 1393 const std::vector<blink::WebCompositionUnderline>& underlines,
1381 const gfx::Range& replacement_range, 1394 const gfx::Range& replacement_range,
1382 int selection_start, 1395 int selection_start,
1383 int selection_end) { 1396 int selection_end) {
1384 Send(new InputMsg_ImeSetComposition( 1397 Send(new InputMsg_ImeSetComposition(GetRoutingID(), text, underlines,
1385 GetRoutingID(), text, underlines, replacement_range, 1398 replacement_range, selection_start,
1386 selection_start, selection_end)); 1399 selection_end));
1387 } 1400 }
1388 1401
1389 void RenderWidgetHostImpl::ImeConfirmComposition( 1402 void RenderWidgetHostImpl::ImeConfirmComposition(
1390 const base::string16& text, 1403 const base::string16& text,
1391 const gfx::Range& replacement_range, 1404 const gfx::Range& replacement_range,
1392 bool keep_selection) { 1405 bool keep_selection) {
1393 Send(new InputMsg_ImeConfirmComposition( 1406 Send(new InputMsg_ImeConfirmComposition(GetRoutingID(), text,
1394 GetRoutingID(), text, replacement_range, keep_selection)); 1407 replacement_range, keep_selection));
1395 } 1408 }
1396 1409
1397 void RenderWidgetHostImpl::ImeCancelComposition() { 1410 void RenderWidgetHostImpl::ImeCancelComposition() {
1398 Send(new InputMsg_ImeSetComposition(GetRoutingID(), base::string16(), 1411 Send(new InputMsg_ImeSetComposition(
1399 std::vector<blink::WebCompositionUnderline>(), 1412 GetRoutingID(), base::string16(),
1400 gfx::Range::InvalidRange(), 0, 0)); 1413 std::vector<blink::WebCompositionUnderline>(), gfx::Range::InvalidRange(),
1414 0, 0));
1401 } 1415 }
1402 1416
1403 void RenderWidgetHostImpl::RejectMouseLockOrUnlockIfNecessary() { 1417 void RenderWidgetHostImpl::RejectMouseLockOrUnlockIfNecessary() {
1404 DCHECK(!pending_mouse_lock_request_ || !IsMouseLocked()); 1418 DCHECK(!pending_mouse_lock_request_ || !IsMouseLocked());
1405 if (pending_mouse_lock_request_) { 1419 if (pending_mouse_lock_request_) {
1406 pending_mouse_lock_request_ = false; 1420 pending_mouse_lock_request_ = false;
1407 Send(new ViewMsg_LockMouse_ACK(routing_id_, false)); 1421 Send(new ViewMsg_LockMouse_ACK(routing_id_, false));
1408 } else if (IsMouseLocked()) { 1422 } else if (IsMouseLocked()) {
1409 view_->UnlockMouse(); 1423 view_->UnlockMouse();
1410 } 1424 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1446 if (delegate_) 1460 if (delegate_)
1447 delegate_->RenderWidgetDeleted(this); 1461 delegate_->RenderWidgetDeleted(this);
1448 1462
1449 if (also_delete) { 1463 if (also_delete) {
1450 CHECK(!owner_delegate_); 1464 CHECK(!owner_delegate_);
1451 delete this; 1465 delete this;
1452 } 1466 }
1453 } 1467 }
1454 1468
1455 void RenderWidgetHostImpl::RendererIsUnresponsive() { 1469 void RenderWidgetHostImpl::RendererIsUnresponsive() {
1456 NotificationService::current()->Notify( 1470 NotificationService::current()->Notify(NOTIFICATION_RENDER_WIDGET_HOST_HANG,
1457 NOTIFICATION_RENDER_WIDGET_HOST_HANG, 1471 Source<RenderWidgetHost>(this),
1458 Source<RenderWidgetHost>(this), 1472 NotificationService::NoDetails());
1459 NotificationService::NoDetails());
1460 is_unresponsive_ = true; 1473 is_unresponsive_ = true;
1461 if (delegate_) 1474 if (delegate_)
1462 delegate_->RendererUnresponsive(this); 1475 delegate_->RendererUnresponsive(this);
1463 } 1476 }
1464 1477
1465 void RenderWidgetHostImpl::RendererIsResponsive() { 1478 void RenderWidgetHostImpl::RendererIsResponsive() {
1466 if (is_unresponsive_) { 1479 if (is_unresponsive_) {
1467 is_unresponsive_ = false; 1480 is_unresponsive_ = false;
1468 if (delegate_) 1481 if (delegate_)
1469 delegate_->RendererResponsive(this); 1482 delegate_->RendererResponsive(this);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1544 SendScreenRects(); 1557 SendScreenRects();
1545 } 1558 }
1546 1559
1547 void RenderWidgetHostImpl::OnRequestMove(const gfx::Rect& pos) { 1560 void RenderWidgetHostImpl::OnRequestMove(const gfx::Rect& pos) {
1548 if (view_) { 1561 if (view_) {
1549 view_->SetBounds(pos); 1562 view_->SetBounds(pos);
1550 Send(new ViewMsg_Move_ACK(routing_id_)); 1563 Send(new ViewMsg_Move_ACK(routing_id_));
1551 } 1564 }
1552 } 1565 }
1553 1566
1554 bool RenderWidgetHostImpl::OnSwapCompositorFrame( 1567 bool RenderWidgetHostImpl::OnSwapCompositorFrame(const IPC::Message& message) {
1555 const IPC::Message& message) {
1556 // This trace event is used in 1568 // This trace event is used in
1557 // chrome/browser/extensions/api/cast_streaming/performance_test.cc 1569 // chrome/browser/extensions/api/cast_streaming/performance_test.cc
1558 TRACE_EVENT0("test_fps,benchmark", "OnSwapCompositorFrame"); 1570 TRACE_EVENT0("test_fps,benchmark", "OnSwapCompositorFrame");
1559 1571
1560 ViewHostMsg_SwapCompositorFrame::Param param; 1572 ViewHostMsg_SwapCompositorFrame::Param param;
1561 if (!ViewHostMsg_SwapCompositorFrame::Read(&message, &param)) 1573 if (!ViewHostMsg_SwapCompositorFrame::Read(&message, &param))
1562 return false; 1574 return false;
1563 std::unique_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); 1575 std::unique_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame);
1564 uint32_t output_surface_id = base::get<0>(param); 1576 uint32_t output_surface_id = base::get<0>(param);
1565 base::get<1>(param).AssignTo(frame.get()); 1577 base::get<1>(param).AssignTo(frame.get());
(...skipping 15 matching lines...) Expand all
1581 if (view_) { 1593 if (view_) {
1582 view_->OnSwapCompositorFrame(output_surface_id, std::move(frame)); 1594 view_->OnSwapCompositorFrame(output_surface_id, std::move(frame));
1583 view_->DidReceiveRendererFrame(); 1595 view_->DidReceiveRendererFrame();
1584 } else { 1596 } else {
1585 cc::CompositorFrameAck ack; 1597 cc::CompositorFrameAck ack;
1586 if (frame->gl_frame_data) { 1598 if (frame->gl_frame_data) {
1587 ack.gl_frame_data = std::move(frame->gl_frame_data); 1599 ack.gl_frame_data = std::move(frame->gl_frame_data);
1588 ack.gl_frame_data->sync_token.Clear(); 1600 ack.gl_frame_data->sync_token.Clear();
1589 } else if (frame->delegated_frame_data) { 1601 } else if (frame->delegated_frame_data) {
1590 cc::TransferableResource::ReturnResources( 1602 cc::TransferableResource::ReturnResources(
1591 frame->delegated_frame_data->resource_list, 1603 frame->delegated_frame_data->resource_list, &ack.resources);
1592 &ack.resources);
1593 } 1604 }
1594 SendSwapCompositorFrameAck(routing_id_, output_surface_id, 1605 SendSwapCompositorFrameAck(routing_id_, output_surface_id,
1595 process_->GetID(), ack); 1606 process_->GetID(), ack);
1596 } 1607 }
1597 1608
1598 RenderProcessHost* rph = GetProcess(); 1609 RenderProcessHost* rph = GetProcess();
1599 for (std::vector<IPC::Message>::const_iterator i = 1610 for (std::vector<IPC::Message>::const_iterator i =
1600 messages_to_deliver_with_frame.begin(); 1611 messages_to_deliver_with_frame.begin();
1601 i != messages_to_deliver_with_frame.end(); 1612 i != messages_to_deliver_with_frame.end(); ++i) {
1602 ++i) {
1603 rph->OnMessageReceived(*i); 1613 rph->OnMessageReceived(*i);
1604 if (i->dispatch_error()) 1614 if (i->dispatch_error())
1605 rph->OnBadMessageReceived(*i); 1615 rph->OnBadMessageReceived(*i);
1606 } 1616 }
1607 messages_to_deliver_with_frame.clear(); 1617 messages_to_deliver_with_frame.clear();
1608 1618
1609 return true; 1619 return true;
1610 } 1620 }
1611 1621
1612 void RenderWidgetHostImpl::OnUpdateRect( 1622 void RenderWidgetHostImpl::OnUpdateRect(
(...skipping 11 matching lines...) Expand all
1624 // that will end up reaching GetBackingStore. 1634 // that will end up reaching GetBackingStore.
1625 if (is_resize_ack) { 1635 if (is_resize_ack) {
1626 DCHECK(!g_check_for_pending_resize_ack || resize_ack_pending_); 1636 DCHECK(!g_check_for_pending_resize_ack || resize_ack_pending_);
1627 resize_ack_pending_ = false; 1637 resize_ack_pending_ = false;
1628 } 1638 }
1629 1639
1630 bool is_repaint_ack = 1640 bool is_repaint_ack =
1631 ViewHostMsg_UpdateRect_Flags::is_repaint_ack(params.flags); 1641 ViewHostMsg_UpdateRect_Flags::is_repaint_ack(params.flags);
1632 if (is_repaint_ack) { 1642 if (is_repaint_ack) {
1633 DCHECK(repaint_ack_pending_); 1643 DCHECK(repaint_ack_pending_);
1634 TRACE_EVENT_ASYNC_END0( 1644 TRACE_EVENT_ASYNC_END0("renderer_host",
1635 "renderer_host", "RenderWidgetHostImpl::repaint_ack_pending_", this); 1645 "RenderWidgetHostImpl::repaint_ack_pending_", this);
1636 repaint_ack_pending_ = false; 1646 repaint_ack_pending_ = false;
1637 TimeDelta delta = TimeTicks::Now() - repaint_start_time_; 1647 TimeDelta delta = TimeTicks::Now() - repaint_start_time_;
1638 UMA_HISTOGRAM_TIMES("MPArch.RWH_RepaintDelta", delta); 1648 UMA_HISTOGRAM_TIMES("MPArch.RWH_RepaintDelta", delta);
1639 } 1649 }
1640 1650
1641 DCHECK(!params.view_size.IsEmpty()); 1651 DCHECK(!params.view_size.IsEmpty());
1642 1652
1643 DidUpdateBackingStore(params, paint_start); 1653 DidUpdateBackingStore(params, paint_start);
1644 1654
1645 if (auto_resize_enabled_) { 1655 if (auto_resize_enabled_) {
(...skipping 14 matching lines...) Expand all
1660 } 1670 }
1661 1671
1662 void RenderWidgetHostImpl::DidUpdateBackingStore( 1672 void RenderWidgetHostImpl::DidUpdateBackingStore(
1663 const ViewHostMsg_UpdateRect_Params& params, 1673 const ViewHostMsg_UpdateRect_Params& params,
1664 const TimeTicks& paint_start) { 1674 const TimeTicks& paint_start) {
1665 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::DidUpdateBackingStore"); 1675 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::DidUpdateBackingStore");
1666 TimeTicks update_start = TimeTicks::Now(); 1676 TimeTicks update_start = TimeTicks::Now();
1667 1677
1668 NotificationService::current()->Notify( 1678 NotificationService::current()->Notify(
1669 NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE, 1679 NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE,
1670 Source<RenderWidgetHost>(this), 1680 Source<RenderWidgetHost>(this), NotificationService::NoDetails());
1671 NotificationService::NoDetails());
1672 1681
1673 // We don't need to update the view if the view is hidden. We must do this 1682 // We don't need to update the view if the view is hidden. We must do this
1674 // early return after the ACK is sent, however, or the renderer will not send 1683 // early return after the ACK is sent, however, or the renderer will not send
1675 // us more data. 1684 // us more data.
1676 if (is_hidden_) 1685 if (is_hidden_)
1677 return; 1686 return;
1678 1687
1679 // If we got a resize ack, then perhaps we have another resize to send? 1688 // If we got a resize ack, then perhaps we have another resize to send?
1680 bool is_resize_ack = 1689 bool is_resize_ack =
1681 ViewHostMsg_UpdateRect_Flags::is_resize_ack(params.flags); 1690 ViewHostMsg_UpdateRect_Flags::is_resize_ack(params.flags);
(...skipping 10 matching lines...) Expand all
1692 const SyntheticGesturePacket& gesture_packet) { 1701 const SyntheticGesturePacket& gesture_packet) {
1693 // Only allow untrustworthy gestures if explicitly enabled. 1702 // Only allow untrustworthy gestures if explicitly enabled.
1694 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( 1703 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
1695 cc::switches::kEnableGpuBenchmarking)) { 1704 cc::switches::kEnableGpuBenchmarking)) {
1696 bad_message::ReceivedBadMessage(GetProcess(), 1705 bad_message::ReceivedBadMessage(GetProcess(),
1697 bad_message::RWH_SYNTHETIC_GESTURE); 1706 bad_message::RWH_SYNTHETIC_GESTURE);
1698 return; 1707 return;
1699 } 1708 }
1700 1709
1701 QueueSyntheticGesture( 1710 QueueSyntheticGesture(
1702 SyntheticGesture::Create(*gesture_packet.gesture_params()), 1711 SyntheticGesture::Create(*gesture_packet.gesture_params()),
1703 base::Bind(&RenderWidgetHostImpl::OnSyntheticGestureCompleted, 1712 base::Bind(&RenderWidgetHostImpl::OnSyntheticGestureCompleted,
1704 weak_factory_.GetWeakPtr())); 1713 weak_factory_.GetWeakPtr()));
1705 } 1714 }
1706 1715
1707 void RenderWidgetHostImpl::OnSetCursor(const WebCursor& cursor) { 1716 void RenderWidgetHostImpl::OnSetCursor(const WebCursor& cursor) {
1708 SetCursor(cursor); 1717 SetCursor(cursor);
1709 } 1718 }
1710 1719
1711 void RenderWidgetHostImpl::SetTouchEventEmulationEnabled( 1720 void RenderWidgetHostImpl::SetTouchEventEmulationEnabled(
1712 bool enabled, ui::GestureProviderConfigType config_type) { 1721 bool enabled,
1722 ui::GestureProviderConfigType config_type) {
1713 if (enabled) { 1723 if (enabled) {
1714 if (!touch_emulator_) { 1724 if (!touch_emulator_) {
1715 touch_emulator_.reset(new TouchEmulator( 1725 touch_emulator_.reset(new TouchEmulator(
1716 this, 1726 this,
1717 view_.get() ? content::GetScaleFactorForView(view_.get()) : 1.0f)); 1727 view_.get() ? content::GetScaleFactorForView(view_.get()) : 1.0f));
1718 } 1728 }
1719 touch_emulator_->Enable(config_type); 1729 touch_emulator_->Enable(config_type);
1720 } else { 1730 } else {
1721 if (touch_emulator_) 1731 if (touch_emulator_)
1722 touch_emulator_->Disable(); 1732 touch_emulator_->Disable();
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1824 if (current_size != original_size) { 1834 if (current_size != original_size) {
1825 DCHECK_EQ(original_size - 1, current_size); 1835 DCHECK_EQ(original_size - 1, current_size);
1826 --i; 1836 --i;
1827 } 1837 }
1828 } 1838 }
1829 1839
1830 return false; 1840 return false;
1831 } 1841 }
1832 1842
1833 InputEventAckState RenderWidgetHostImpl::FilterInputEvent( 1843 InputEventAckState RenderWidgetHostImpl::FilterInputEvent(
1834 const blink::WebInputEvent& event, const ui::LatencyInfo& latency_info) { 1844 const blink::WebInputEvent& event,
1845 const ui::LatencyInfo& latency_info) {
1835 // Don't ignore touch cancel events, since they may be sent while input 1846 // Don't ignore touch cancel events, since they may be sent while input
1836 // events are being ignored in order to keep the renderer from getting 1847 // events are being ignored in order to keep the renderer from getting
1837 // confused about how many touches are active. 1848 // confused about how many touches are active.
1838 if (ShouldDropInputEvents() && event.type != WebInputEvent::TouchCancel) 1849 if (ShouldDropInputEvents() && event.type != WebInputEvent::TouchCancel)
1839 return INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS; 1850 return INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
1840 1851
1841 if (!process_->HasConnection()) 1852 if (!process_->HasConnection())
1842 return INPUT_EVENT_ACK_STATE_UNKNOWN; 1853 return INPUT_EVENT_ACK_STATE_UNKNOWN;
1843 1854
1844 if (delegate_ && (event.type == WebInputEvent::MouseDown || 1855 if (delegate_ && (event.type == WebInputEvent::MouseDown ||
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1882 if (view_) 1893 if (view_)
1883 view_->DidOverscroll(params); 1894 view_->DidOverscroll(params);
1884 } 1895 }
1885 1896
1886 void RenderWidgetHostImpl::DidStopFlinging() { 1897 void RenderWidgetHostImpl::DidStopFlinging() {
1887 if (view_) 1898 if (view_)
1888 view_->DidStopFlinging(); 1899 view_->DidStopFlinging();
1889 } 1900 }
1890 1901
1891 void RenderWidgetHostImpl::OnKeyboardEventAck( 1902 void RenderWidgetHostImpl::OnKeyboardEventAck(
1892 const NativeWebKeyboardEventWithLatencyInfo& event, 1903 const NativeWebKeyboardEventWithLatencyInfo& event,
1893 InputEventAckState ack_result) { 1904 InputEventAckState ack_result) {
1894 latency_tracker_.OnInputEventAck(event.event, &event.latency, ack_result); 1905 latency_tracker_.OnInputEventAck(event.event, &event.latency, ack_result);
1895 1906
1896 const bool processed = (INPUT_EVENT_ACK_STATE_CONSUMED == ack_result); 1907 const bool processed = (INPUT_EVENT_ACK_STATE_CONSUMED == ack_result);
1897 1908
1898 // We only send unprocessed key event upwards if we are not hidden, 1909 // We only send unprocessed key event upwards if we are not hidden,
1899 // because the user has moved away from us and no longer expect any effect 1910 // because the user has moved away from us and no longer expect any effect
1900 // of this key event. 1911 // of this key event.
1901 if (delegate_ && !processed && !is_hidden() && !event.event.skip_in_browser) { 1912 if (delegate_ && !processed && !is_hidden() && !event.event.skip_in_browser) {
1902 delegate_->HandleKeyboardEvent(event.event); 1913 delegate_->HandleKeyboardEvent(event.event);
1903 1914
(...skipping 10 matching lines...) Expand all
1914 ack_result); 1925 ack_result);
1915 } 1926 }
1916 1927
1917 void RenderWidgetHostImpl::OnWheelEventAck( 1928 void RenderWidgetHostImpl::OnWheelEventAck(
1918 const MouseWheelEventWithLatencyInfo& wheel_event, 1929 const MouseWheelEventWithLatencyInfo& wheel_event,
1919 InputEventAckState ack_result) { 1930 InputEventAckState ack_result) {
1920 latency_tracker_.OnInputEventAck(wheel_event.event, &wheel_event.latency, 1931 latency_tracker_.OnInputEventAck(wheel_event.event, &wheel_event.latency,
1921 ack_result); 1932 ack_result);
1922 1933
1923 if (!is_hidden() && view_) { 1934 if (!is_hidden() && view_) {
1924 if (ack_result != INPUT_EVENT_ACK_STATE_CONSUMED && 1935 if (ack_result != INPUT_EVENT_ACK_STATE_CONSUMED && delegate_ &&
1925 delegate_ && delegate_->HandleWheelEvent(wheel_event.event)) { 1936 delegate_->HandleWheelEvent(wheel_event.event)) {
1926 ack_result = INPUT_EVENT_ACK_STATE_CONSUMED; 1937 ack_result = INPUT_EVENT_ACK_STATE_CONSUMED;
1927 } 1938 }
1928 view_->WheelEventAck(wheel_event.event, ack_result); 1939 view_->WheelEventAck(wheel_event.event, ack_result);
1929 } 1940 }
1930 } 1941 }
1931 1942
1932 void RenderWidgetHostImpl::OnGestureEventAck( 1943 void RenderWidgetHostImpl::OnGestureEventAck(
1933 const GestureEventWithLatencyInfo& event, 1944 const GestureEventWithLatencyInfo& event,
1934 InputEventAckState ack_result) { 1945 InputEventAckState ack_result) {
1935 latency_tracker_.OnInputEventAck(event.event, &event.latency, ack_result); 1946 latency_tracker_.OnInputEventAck(event.event, &event.latency, ack_result);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1998 return false; 2009 return false;
1999 } 2010 }
2000 2011
2001 if (!pending_mouse_lock_request_) { 2012 if (!pending_mouse_lock_request_) {
2002 // This is possible, e.g., the plugin sends us an unlock request before 2013 // This is possible, e.g., the plugin sends us an unlock request before
2003 // the user allows to lock to mouse. 2014 // the user allows to lock to mouse.
2004 return false; 2015 return false;
2005 } 2016 }
2006 2017
2007 pending_mouse_lock_request_ = false; 2018 pending_mouse_lock_request_ = false;
2008 if (!view_ || !view_->HasFocus()|| !view_->LockMouse()) { 2019 if (!view_ || !view_->HasFocus() || !view_->LockMouse()) {
2009 Send(new ViewMsg_LockMouse_ACK(routing_id_, false)); 2020 Send(new ViewMsg_LockMouse_ACK(routing_id_, false));
2010 return false; 2021 return false;
2011 } 2022 }
2012 2023
2013 Send(new ViewMsg_LockMouse_ACK(routing_id_, true)); 2024 Send(new ViewMsg_LockMouse_ACK(routing_id_, true));
2014 return true; 2025 return true;
2015 } 2026 }
2016 2027
2017 // static 2028 // static
2018 void RenderWidgetHostImpl::SendSwapCompositorFrameAck( 2029 void RenderWidgetHostImpl::SendSwapCompositorFrameAck(
2019 int32_t route_id, 2030 int32_t route_id,
2020 uint32_t output_surface_id, 2031 uint32_t output_surface_id,
2021 int renderer_host_id, 2032 int renderer_host_id,
2022 const cc::CompositorFrameAck& ack) { 2033 const cc::CompositorFrameAck& ack) {
2023 RenderProcessHost* host = RenderProcessHost::FromID(renderer_host_id); 2034 RenderProcessHost* host = RenderProcessHost::FromID(renderer_host_id);
2024 if (!host) 2035 if (!host)
2025 return; 2036 return;
2026 host->Send(new ViewMsg_SwapCompositorFrameAck( 2037 host->Send(
2027 route_id, output_surface_id, ack)); 2038 new ViewMsg_SwapCompositorFrameAck(route_id, output_surface_id, ack));
2028 } 2039 }
2029 2040
2030 // static 2041 // static
2031 void RenderWidgetHostImpl::SendReclaimCompositorResources( 2042 void RenderWidgetHostImpl::SendReclaimCompositorResources(
2032 int32_t route_id, 2043 int32_t route_id,
2033 uint32_t output_surface_id, 2044 uint32_t output_surface_id,
2034 int renderer_host_id, 2045 int renderer_host_id,
2035 const cc::CompositorFrameAck& ack) { 2046 const cc::CompositorFrameAck& ack) {
2036 RenderProcessHost* host = RenderProcessHost::FromID(renderer_host_id); 2047 RenderProcessHost* host = RenderProcessHost::FromID(renderer_host_id);
2037 if (!host) 2048 if (!host)
(...skipping 17 matching lines...) Expand all
2055 2066
2056 void RenderWidgetHostImpl::DetachDelegate() { 2067 void RenderWidgetHostImpl::DetachDelegate() {
2057 delegate_ = NULL; 2068 delegate_ = NULL;
2058 } 2069 }
2059 2070
2060 void RenderWidgetHostImpl::FrameSwapped(const ui::LatencyInfo& latency_info) { 2071 void RenderWidgetHostImpl::FrameSwapped(const ui::LatencyInfo& latency_info) {
2061 ui::LatencyInfo::LatencyComponent window_snapshot_component; 2072 ui::LatencyInfo::LatencyComponent window_snapshot_component;
2062 if (latency_info.FindLatency(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT, 2073 if (latency_info.FindLatency(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT,
2063 GetLatencyComponentId(), 2074 GetLatencyComponentId(),
2064 &window_snapshot_component)) { 2075 &window_snapshot_component)) {
2065 int sequence_number = static_cast<int>( 2076 int sequence_number =
2066 window_snapshot_component.sequence_number); 2077 static_cast<int>(window_snapshot_component.sequence_number);
2067 #if defined(OS_MACOSX) 2078 #if defined(OS_MACOSX)
2068 // On Mac, when using CoreAnmation, there is a delay between when content 2079 // On Mac, when using CoreAnmation, there is a delay between when content
2069 // is drawn to the screen, and when the snapshot will actually pick up 2080 // is drawn to the screen, and when the snapshot will actually pick up
2070 // that content. Insert a manual delay of 1/6th of a second (to simulate 2081 // that content. Insert a manual delay of 1/6th of a second (to simulate
2071 // 10 frames at 60 fps) before actually taking the snapshot. 2082 // 10 frames at 60 fps) before actually taking the snapshot.
2072 base::MessageLoop::current()->PostDelayedTask( 2083 base::MessageLoop::current()->PostDelayedTask(
2073 FROM_HERE, 2084 FROM_HERE,
2074 base::Bind(&RenderWidgetHostImpl::WindowSnapshotReachedScreen, 2085 base::Bind(&RenderWidgetHostImpl::WindowSnapshotReachedScreen,
2075 weak_factory_.GetWeakPtr(), 2086 weak_factory_.GetWeakPtr(), sequence_number),
2076 sequence_number),
2077 base::TimeDelta::FromSecondsD(1. / 6)); 2087 base::TimeDelta::FromSecondsD(1. / 6));
2078 #else 2088 #else
2079 WindowSnapshotReachedScreen(sequence_number); 2089 WindowSnapshotReachedScreen(sequence_number);
2080 #endif 2090 #endif
2081 } 2091 }
2082 2092
2083 latency_tracker_.OnFrameSwapped(latency_info); 2093 latency_tracker_.OnFrameSwapped(latency_info);
2084 } 2094 }
2085 2095
2086 void RenderWidgetHostImpl::DidReceiveRendererFrame() { 2096 void RenderWidgetHostImpl::DidReceiveRendererFrame() {
2087 view_->DidReceiveRendererFrame(); 2097 view_->DidReceiveRendererFrame();
2088 } 2098 }
2089 2099
2090 void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) { 2100 void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) {
2091 DCHECK(base::MessageLoopForUI::IsCurrent()); 2101 DCHECK(base::MessageLoopForUI::IsCurrent());
2092 2102
2093 gfx::Rect view_bounds = GetView()->GetViewBounds(); 2103 gfx::Rect view_bounds = GetView()->GetViewBounds();
2094 gfx::Rect snapshot_bounds(view_bounds.size()); 2104 gfx::Rect snapshot_bounds(view_bounds.size());
2095 2105
2096 std::vector<unsigned char> png; 2106 std::vector<unsigned char> png;
2097 if (ui::GrabViewSnapshot( 2107 if (ui::GrabViewSnapshot(GetView()->GetNativeView(), &png, snapshot_bounds)) {
2098 GetView()->GetNativeView(), &png, snapshot_bounds)) {
2099 OnSnapshotDataReceived(snapshot_id, &png.front(), png.size()); 2108 OnSnapshotDataReceived(snapshot_id, &png.front(), png.size());
2100 return; 2109 return;
2101 } 2110 }
2102 2111
2103 ui::GrabViewSnapshotAsync( 2112 ui::GrabViewSnapshotAsync(
2104 GetView()->GetNativeView(), 2113 GetView()->GetNativeView(), snapshot_bounds,
2105 snapshot_bounds,
2106 base::ThreadTaskRunnerHandle::Get(), 2114 base::ThreadTaskRunnerHandle::Get(),
2107 base::Bind(&RenderWidgetHostImpl::OnSnapshotDataReceivedAsync, 2115 base::Bind(&RenderWidgetHostImpl::OnSnapshotDataReceivedAsync,
2108 weak_factory_.GetWeakPtr(), 2116 weak_factory_.GetWeakPtr(), snapshot_id));
2109 snapshot_id));
2110 } 2117 }
2111 2118
2112 void RenderWidgetHostImpl::OnSnapshotDataReceived(int snapshot_id, 2119 void RenderWidgetHostImpl::OnSnapshotDataReceived(int snapshot_id,
2113 const unsigned char* data, 2120 const unsigned char* data,
2114 size_t size) { 2121 size_t size) {
2115 // Any pending snapshots with a lower ID than the one received are considered 2122 // Any pending snapshots with a lower ID than the one received are considered
2116 // to be implicitly complete, and returned the same snapshot data. 2123 // to be implicitly complete, and returned the same snapshot data.
2117 PendingSnapshotMap::iterator it = pending_browser_snapshots_.begin(); 2124 PendingSnapshotMap::iterator it = pending_browser_snapshots_.begin();
2118 while (it != pending_browser_snapshots_.end()) { 2125 while (it != pending_browser_snapshots_.end()) {
2119 if (it->first <= snapshot_id) { 2126 if (it->first <= snapshot_id) {
2120 it->second.Run(data, size); 2127 it->second.Run(data, size);
2121 pending_browser_snapshots_.erase(it++); 2128 pending_browser_snapshots_.erase(it++);
2122 } else { 2129 } else {
2123 ++it; 2130 ++it;
2124 } 2131 }
2125 } 2132 }
2126 } 2133 }
2127 2134
2128 void RenderWidgetHostImpl::OnSnapshotDataReceivedAsync( 2135 void RenderWidgetHostImpl::OnSnapshotDataReceivedAsync(
2129 int snapshot_id, 2136 int snapshot_id,
2130 scoped_refptr<base::RefCountedBytes> png_data) { 2137 scoped_refptr<base::RefCountedBytes> png_data) {
2131 if (png_data.get()) 2138 if (png_data.get())
2132 OnSnapshotDataReceived(snapshot_id, png_data->front(), png_data->size()); 2139 OnSnapshotDataReceived(snapshot_id, png_data->front(), png_data->size());
2133 else 2140 else
2134 OnSnapshotDataReceived(snapshot_id, NULL, 0); 2141 OnSnapshotDataReceived(snapshot_id, NULL, 0);
(...skipping 18 matching lines...) Expand all
2153 } 2160 }
2154 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); 2161 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh);
2155 if (rwhi_set.insert(rwhi).second) 2162 if (rwhi_set.insert(rwhi).second)
2156 rwhi->FrameSwapped(latency_info[i]); 2163 rwhi->FrameSwapped(latency_info[i]);
2157 } 2164 }
2158 } 2165 }
2159 } 2166 }
2160 } 2167 }
2161 2168
2162 BrowserAccessibilityManager* 2169 BrowserAccessibilityManager*
2163 RenderWidgetHostImpl::GetRootBrowserAccessibilityManager() { 2170 RenderWidgetHostImpl::GetRootBrowserAccessibilityManager() {
2164 return delegate_ ? delegate_->GetRootBrowserAccessibilityManager() : NULL; 2171 return delegate_ ? delegate_->GetRootBrowserAccessibilityManager() : NULL;
2165 } 2172 }
2166 2173
2167 BrowserAccessibilityManager* 2174 BrowserAccessibilityManager*
2168 RenderWidgetHostImpl::GetOrCreateRootBrowserAccessibilityManager() { 2175 RenderWidgetHostImpl::GetOrCreateRootBrowserAccessibilityManager() {
2169 return delegate_ ? 2176 return delegate_ ? delegate_->GetOrCreateRootBrowserAccessibilityManager()
2170 delegate_->GetOrCreateRootBrowserAccessibilityManager() : NULL; 2177 : NULL;
2171 } 2178 }
2172 2179
2173 } // namespace content 2180 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698