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

Side by Side Diff: chrome/browser/renderer_host/render_widget_host.cc

Issue 160494: Disable input events when a JS dialog is showing. (Closed)
Patch Set: beforeunload Created 11 years, 4 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
« no previous file with comments | « chrome/browser/renderer_host/render_view_host.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/renderer_host/render_widget_host.h" 5 #include "chrome/browser/renderer_host/render_widget_host.h"
6 6
7 #include "base/histogram.h" 7 #include "base/histogram.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/keyboard_codes.h" 9 #include "base/keyboard_codes.h"
10 #include "chrome/browser/renderer_host/backing_store.h" 10 #include "chrome/browser/renderer_host/backing_store.h"
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 338
339 // We do not bother to stop the hung_renderer_timer_ here in case it will be 339 // We do not bother to stop the hung_renderer_timer_ here in case it will be
340 // started again shortly, which happens to be the common use case. 340 // started again shortly, which happens to be the common use case.
341 } 341 }
342 342
343 void RenderWidgetHost::SystemThemeChanged() { 343 void RenderWidgetHost::SystemThemeChanged() {
344 Send(new ViewMsg_ThemeChanged(routing_id_)); 344 Send(new ViewMsg_ThemeChanged(routing_id_));
345 } 345 }
346 346
347 void RenderWidgetHost::ForwardMouseEvent(const WebMouseEvent& mouse_event) { 347 void RenderWidgetHost::ForwardMouseEvent(const WebMouseEvent& mouse_event) {
348 if (process_->ignore_input_events())
349 return;
350
348 // Avoid spamming the renderer with mouse move events. It is important 351 // Avoid spamming the renderer with mouse move events. It is important
349 // to note that WM_MOUSEMOVE events are anyways synthetic, but since our 352 // to note that WM_MOUSEMOVE events are anyways synthetic, but since our
350 // thread is able to rapidly consume WM_MOUSEMOVE events, we may get way 353 // thread is able to rapidly consume WM_MOUSEMOVE events, we may get way
351 // more WM_MOUSEMOVE events than we wish to send to the renderer. 354 // more WM_MOUSEMOVE events than we wish to send to the renderer.
352 if (mouse_event.type == WebInputEvent::MouseMove) { 355 if (mouse_event.type == WebInputEvent::MouseMove) {
353 if (mouse_move_pending_) { 356 if (mouse_move_pending_) {
354 next_mouse_move_.reset(new WebMouseEvent(mouse_event)); 357 next_mouse_move_.reset(new WebMouseEvent(mouse_event));
355 return; 358 return;
356 } 359 }
357 mouse_move_pending_ = true; 360 mouse_move_pending_ = true;
358 } else if (mouse_event.type == WebInputEvent::MouseDown) { 361 } else if (mouse_event.type == WebInputEvent::MouseDown) {
359 OnUserGesture(); 362 OnUserGesture();
360 } 363 }
361 364
362 ForwardInputEvent(mouse_event, sizeof(WebMouseEvent)); 365 ForwardInputEvent(mouse_event, sizeof(WebMouseEvent));
363 } 366 }
364 367
365 void RenderWidgetHost::ForwardWheelEvent( 368 void RenderWidgetHost::ForwardWheelEvent(
366 const WebMouseWheelEvent& wheel_event) { 369 const WebMouseWheelEvent& wheel_event) {
370 if (process_->ignore_input_events())
371 return;
372
367 ForwardInputEvent(wheel_event, sizeof(WebMouseWheelEvent)); 373 ForwardInputEvent(wheel_event, sizeof(WebMouseWheelEvent));
368 } 374 }
369 375
370 void RenderWidgetHost::ForwardKeyboardEvent( 376 void RenderWidgetHost::ForwardKeyboardEvent(
371 const NativeWebKeyboardEvent& key_event) { 377 const NativeWebKeyboardEvent& key_event) {
378 if (process_->ignore_input_events())
379 return;
380
372 if (key_event.type == WebKeyboardEvent::Char && 381 if (key_event.type == WebKeyboardEvent::Char &&
373 (key_event.windowsKeyCode == base::VKEY_RETURN || 382 (key_event.windowsKeyCode == base::VKEY_RETURN ||
374 key_event.windowsKeyCode == base::VKEY_SPACE)) { 383 key_event.windowsKeyCode == base::VKEY_SPACE)) {
375 OnUserGesture(); 384 OnUserGesture();
376 } 385 }
377 386
378 // Double check the type to make sure caller hasn't sent us nonsense that 387 // Double check the type to make sure caller hasn't sent us nonsense that
379 // will mess up our key queue. 388 // will mess up our key queue.
380 if (WebInputEvent::isKeyboardEventType(key_event.type)) { 389 if (WebInputEvent::isKeyboardEventType(key_event.type)) {
381 // Don't add this key to the queue if we have no way to send the message... 390 // Don't add this key to the queue if we have no way to send the message...
382 if (!process_->HasConnection()) 391 if (!process_->HasConnection())
383 return; 392 return;
384 393
385 // Put all WebKeyboardEvent objects in a queue since we can't trust the 394 // Put all WebKeyboardEvent objects in a queue since we can't trust the
386 // renderer and we need to give something to the UnhandledInputEvent 395 // renderer and we need to give something to the UnhandledInputEvent
387 // handler. 396 // handler.
388 key_queue_.push(key_event); 397 key_queue_.push(key_event);
389 HISTOGRAM_COUNTS_100("Renderer.KeyboardQueueSize", key_queue_.size()); 398 HISTOGRAM_COUNTS_100("Renderer.KeyboardQueueSize", key_queue_.size());
390 } 399 }
391 400
392 // Only forward the non-native portions of our event. 401 // Only forward the non-native portions of our event.
393 ForwardInputEvent(key_event, sizeof(WebKeyboardEvent)); 402 ForwardInputEvent(key_event, sizeof(WebKeyboardEvent));
394 } 403 }
395 404
396 void RenderWidgetHost::ForwardInputEvent(const WebInputEvent& input_event, 405 void RenderWidgetHost::ForwardInputEvent(const WebInputEvent& input_event,
397 int event_size) { 406 int event_size) {
398 if (!process_->HasConnection()) 407 if (!process_->HasConnection())
399 return; 408 return;
400 409
410 DCHECK(!process_->ignore_input_events());
411
401 IPC::Message* message = new ViewMsg_HandleInputEvent(routing_id_); 412 IPC::Message* message = new ViewMsg_HandleInputEvent(routing_id_);
402 message->WriteData( 413 message->WriteData(
403 reinterpret_cast<const char*>(&input_event), event_size); 414 reinterpret_cast<const char*>(&input_event), event_size);
404 input_event_start_time_ = TimeTicks::Now(); 415 input_event_start_time_ = TimeTicks::Now();
405 Send(message); 416 Send(message);
406 417
407 // Any input event cancels a pending mouse move event. 418 // Any input event cancels a pending mouse move event.
408 next_mouse_move_.reset(); 419 next_mouse_move_.reset();
409 420
410 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kHungRendererDelayMs)); 421 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kHungRendererDelayMs));
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 866
856 // TODO(darin): do we need to do something else if our backing store is not 867 // TODO(darin): do we need to do something else if our backing store is not
857 // the same size as the advertised view? maybe we just assume there is a 868 // the same size as the advertised view? maybe we just assume there is a
858 // full paint on its way? 869 // full paint on its way?
859 BackingStore* backing_store = BackingStoreManager::Lookup(this); 870 BackingStore* backing_store = BackingStoreManager::Lookup(this);
860 if (!backing_store || (backing_store->size() != view_size)) 871 if (!backing_store || (backing_store->size() != view_size))
861 return; 872 return;
862 backing_store->ScrollRect(process_->process().handle(), bitmap, bitmap_rect, 873 backing_store->ScrollRect(process_->process().handle(), bitmap, bitmap_rect,
863 dx, dy, clip_rect, view_size); 874 dx, dy, clip_rect, view_size);
864 } 875 }
OLDNEW
« no previous file with comments | « chrome/browser/renderer_host/render_view_host.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698