render_widget_host_impl.h revision b2df76ea8fec9e32f6f3718986dba0d95315b29c
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 3// found in the LICENSE file. 4 5#ifndef CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_IMPL_H_ 6#define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_IMPL_H_ 7 8#include <deque> 9#include <list> 10#include <map> 11#include <queue> 12#include <string> 13#include <utility> 14#include <vector> 15 16#include "base/callback.h" 17#include "base/gtest_prod_util.h" 18#include "base/memory/scoped_ptr.h" 19#include "base/memory/weak_ptr.h" 20#include "base/observer_list.h" 21#include "base/process_util.h" 22#include "base/string16.h" 23#include "base/time.h" 24#include "base/timer.h" 25#include "build/build_config.h" 26#include "cc/debug/latency_info.h" 27#include "content/browser/renderer_host/event_with_latency_info.h" 28#include "content/browser/renderer_host/smooth_scroll_gesture_controller.h" 29#include "content/common/view_message_enums.h" 30#include "content/port/common/input_event_ack_state.h" 31#include "content/public/browser/render_widget_host.h" 32#include "content/public/common/page_zoom.h" 33#include "ipc/ipc_listener.h" 34#include "ui/base/ime/text_input_type.h" 35#include "ui/gfx/native_widget_types.h" 36 37class WebCursor; 38struct AcceleratedSurfaceMsg_BufferPresented_Params; 39struct ViewHostMsg_UpdateRect_Params; 40struct ViewHostMsg_TextInputState_Params; 41struct ViewHostMsg_BeginSmoothScroll_Params; 42 43namespace base { 44class TimeTicks; 45} 46 47namespace cc { 48class CompositorFrame; 49class CompositorFrameAck; 50} 51 52namespace ui { 53class KeyEvent; 54class Range; 55} 56 57namespace WebKit { 58class WebInputEvent; 59class WebMouseEvent; 60struct WebCompositionUnderline; 61struct WebScreenInfo; 62} 63 64#if defined(OS_ANDROID) 65namespace WebKit { 66class WebLayer; 67} 68#endif 69 70namespace content { 71class BackingStore; 72class GestureEventFilter; 73class MockRenderWidgetHost; 74class OverscrollController; 75class RenderWidgetHostDelegate; 76class RenderWidgetHostViewPort; 77class SmoothScrollGestureController; 78class TouchEventQueue; 79struct EditCommand; 80 81// This implements the RenderWidgetHost interface that is exposed to 82// embedders of content, and adds things only visible to content. 83class CONTENT_EXPORT RenderWidgetHostImpl : virtual public RenderWidgetHost, 84 public IPC::Listener { 85 public: 86 // routing_id can be MSG_ROUTING_NONE, in which case the next available 87 // routing id is taken from the RenderProcessHost. 88 // If this object outlives |delegate|, DetachDelegate() must be called when 89 // |delegate| goes away. 90 RenderWidgetHostImpl(RenderWidgetHostDelegate* delegate, 91 RenderProcessHost* process, 92 int routing_id); 93 virtual ~RenderWidgetHostImpl(); 94 95 // Use RenderWidgetHostImpl::From(rwh) to downcast a 96 // RenderWidgetHost to a RenderWidgetHostImpl. Internally, this 97 // uses RenderWidgetHost::AsRenderWidgetHostImpl(). 98 static RenderWidgetHostImpl* From(RenderWidgetHost* rwh); 99 100 void set_hung_renderer_delay_ms(const base::TimeDelta& timeout) { 101 hung_renderer_delay_ms_ = timeout.InMilliseconds(); 102 } 103 104 // RenderWidgetHost implementation. 105 virtual void Undo() OVERRIDE; 106 virtual void Redo() OVERRIDE; 107 virtual void Cut() OVERRIDE; 108 virtual void Copy() OVERRIDE; 109 virtual void CopyToFindPboard() OVERRIDE; 110 virtual void Paste() OVERRIDE; 111 virtual void PasteAndMatchStyle() OVERRIDE; 112 virtual void Delete() OVERRIDE; 113 virtual void SelectAll() OVERRIDE; 114 virtual void UpdateTextDirection(WebKit::WebTextDirection direction) OVERRIDE; 115 virtual void NotifyTextDirection() OVERRIDE; 116 virtual void Focus() OVERRIDE; 117 virtual void Blur() OVERRIDE; 118 virtual void SetActive(bool active) OVERRIDE; 119 virtual void CopyFromBackingStore( 120 const gfx::Rect& src_rect, 121 const gfx::Size& accelerated_dst_size, 122 const base::Callback<void(bool, const SkBitmap&)>& callback) OVERRIDE; 123#if defined(TOOLKIT_GTK) 124 virtual bool CopyFromBackingStoreToGtkWindow(const gfx::Rect& dest_rect, 125 GdkWindow* target) OVERRIDE; 126#elif defined(OS_MACOSX) 127 virtual gfx::Size GetBackingStoreSize() OVERRIDE; 128 virtual bool CopyFromBackingStoreToCGContext(const CGRect& dest_rect, 129 CGContextRef target) OVERRIDE; 130#endif 131 virtual void EnableFullAccessibilityMode() OVERRIDE; 132 virtual void ForwardMouseEvent( 133 const WebKit::WebMouseEvent& mouse_event) OVERRIDE; 134 virtual void ForwardWheelEvent( 135 const WebKit::WebMouseWheelEvent& wheel_event) OVERRIDE; 136 virtual void ForwardKeyboardEvent( 137 const NativeWebKeyboardEvent& key_event) OVERRIDE; 138 virtual const gfx::Vector2d& GetLastScrollOffset() const OVERRIDE; 139 virtual RenderProcessHost* GetProcess() const OVERRIDE; 140 virtual int GetRoutingID() const OVERRIDE; 141 virtual RenderWidgetHostView* GetView() const OVERRIDE; 142 virtual bool IsLoading() const OVERRIDE; 143 virtual bool IsRenderView() const OVERRIDE; 144 virtual void PaintAtSize(TransportDIB::Handle dib_handle, 145 int tag, 146 const gfx::Size& page_size, 147 const gfx::Size& desired_size) OVERRIDE; 148 virtual void Replace(const string16& word) OVERRIDE; 149 virtual void ReplaceMisspelling(const string16& word) OVERRIDE; 150 virtual void ResizeRectChanged(const gfx::Rect& new_rect) OVERRIDE; 151 virtual void RestartHangMonitorTimeout() OVERRIDE; 152 virtual void SetIgnoreInputEvents(bool ignore_input_events) OVERRIDE; 153 virtual void Stop() OVERRIDE; 154 virtual void WasResized() OVERRIDE; 155 virtual void AddKeyboardListener(KeyboardListener* listener) OVERRIDE; 156 virtual void RemoveKeyboardListener(KeyboardListener* listener) OVERRIDE; 157 virtual void GetWebScreenInfo(WebKit::WebScreenInfo* result) OVERRIDE; 158 virtual void GetSnapshotFromRenderer( 159 const gfx::Rect& src_subrect, 160 const base::Callback<void(bool, const SkBitmap&)>& callback) OVERRIDE; 161 162 const NativeWebKeyboardEvent* GetLastKeyboardEvent() const; 163 164 // Notification that the screen info has changed. 165 void NotifyScreenInfoChanged(); 166 167 // Sets the View of this RenderWidgetHost. 168 void SetView(RenderWidgetHostView* view); 169 170 int surface_id() const { return surface_id_; } 171 172 bool empty() const { return current_size_.IsEmpty(); } 173 174 // Called when a renderer object already been created for this host, and we 175 // just need to be attached to it. Used for window.open, <select> dropdown 176 // menus, and other times when the renderer initiates creating an object. 177 void Init(); 178 179 // Tells the renderer to die and then calls Destroy(). 180 virtual void Shutdown(); 181 182 // IPC::Listener 183 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; 184 185 // Sends a message to the corresponding object in the renderer. 186 virtual bool Send(IPC::Message* msg) OVERRIDE; 187 188 // Called to notify the RenderWidget that it has been hidden or restored from 189 // having been hidden. 190 void WasHidden(); 191 void WasShown(); 192 193 // Returns true if the RenderWidget is hidden. 194 bool is_hidden() const { return is_hidden_; } 195 196 // Called to notify the RenderWidget that its associated native window 197 // got/lost focused. 198 virtual void GotFocus(); 199 virtual void LostCapture(); 200 201 // Called to notify the RenderWidget that it has lost the mouse lock. 202 virtual void LostMouseLock(); 203 204 // Noifies the RenderWidget of the current mouse cursor visibility state. 205 void SendCursorVisibilityState(bool is_visible); 206 207 // Tells us whether the page is rendered directly via the GPU process. 208 bool is_accelerated_compositing_active() { 209 return is_accelerated_compositing_active_; 210 } 211 212 // Notifies the RenderWidgetHost that the View was destroyed. 213 void ViewDestroyed(); 214 215 // Indicates if the page has finished loading. 216 void SetIsLoading(bool is_loading); 217 218 // Check for the existance of a BackingStore of the given |desired_size| and 219 // return it if it exists. If the BackingStore is GPU, true is returned and 220 // |*backing_store| is set to NULL. 221 bool TryGetBackingStore(const gfx::Size& desired_size, 222 BackingStore** backing_store); 223 224 // Get access to the widget's backing store matching the size of the widget's 225 // view. If you pass |force_create| as true, then GetBackingStore may block 226 // for the renderer to send a new frame. Otherwise, NULL will be returned if 227 // the backing store doesn't already exist. It will also return NULL if the 228 // backing store could not be created. 229 // 230 // Mac only: NULL may also be returned if the last frame was GPU accelerated. 231 // Call GetView()->HasAcceleratedSurface to determine if the last frame was 232 // accelerated. 233 BackingStore* GetBackingStore(bool force_create); 234 235 // Allocate a new backing store of the given size. Returns NULL on failure 236 // (for example, if we don't currently have a RenderWidgetHostView.) 237 BackingStore* AllocBackingStore(const gfx::Size& size); 238 239 // When a backing store does asynchronous painting, it will call this function 240 // when it is done with the DIB. We will then forward a message to the 241 // renderer to send another paint. 242 void DonePaintingToBackingStore(); 243 244 // GPU accelerated version of GetBackingStore function. This will 245 // trigger a re-composite to the view. If a resize is pending, it will 246 // block briefly waiting for an ack from the renderer. 247 void ScheduleComposite(); 248 249 // Starts a hang monitor timeout. If there's already a hang monitor timeout 250 // the new one will only fire if it has a shorter delay than the time 251 // left on the existing timeouts. 252 void StartHangMonitorTimeout(base::TimeDelta delay); 253 254 // Stops all existing hang monitor timeouts and assumes the renderer is 255 // responsive. 256 void StopHangMonitorTimeout(); 257 258 // Forwards the given message to the renderer. These are called by the view 259 // when it has received a message. 260 void ForwardGestureEvent(const WebKit::WebGestureEvent& gesture_event); 261 virtual void ForwardTouchEvent(const WebKit::WebTouchEvent& touch_event); 262 263 // Forwards the given event immediately to the renderer. 264 void ForwardMouseEventImmediately( 265 const MouseEventWithLatencyInfo& mouse_event); 266 void ForwardTouchEventImmediately(const WebKit::WebTouchEvent& touch_event); 267 void ForwardGestureEventImmediately( 268 const GestureEventWithLatencyInfo& gesture_event); 269 270 void CancelUpdateTextDirection(); 271 272 // Called when a mouse click/gesture tap activates the renderer. 273 virtual void OnPointerEventActivate(); 274 275 // Notifies the renderer whether or not the input method attached to this 276 // process is activated. 277 // When the input method is activated, a renderer process sends IPC messages 278 // to notify the status of its composition node. (This message is mainly used 279 // for notifying the position of the input cursor so that the browser can 280 // display input method windows under the cursor.) 281 void SetInputMethodActive(bool activate); 282 283 // Update the composition node of the renderer (or WebKit). 284 // WebKit has a special node (a composition node) for input method to change 285 // its text without affecting any other DOM nodes. When the input method 286 // (attached to the browser) updates its text, the browser sends IPC messages 287 // to update the composition node of the renderer. 288 // (Read the comments of each function for its detail.) 289 290 // Sets the text of the composition node. 291 // This function can also update the cursor position and mark the specified 292 // range in the composition node. 293 // A browser should call this function: 294 // * when it receives a WM_IME_COMPOSITION message with a GCS_COMPSTR flag 295 // (on Windows); 296 // * when it receives a "preedit_changed" signal of GtkIMContext (on Linux); 297 // * when markedText of NSTextInput is called (on Mac). 298 void ImeSetComposition( 299 const string16& text, 300 const std::vector<WebKit::WebCompositionUnderline>& underlines, 301 int selection_start, 302 int selection_end); 303 304 // Finishes an ongoing composition with the specified text. 305 // A browser should call this function: 306 // * when it receives a WM_IME_COMPOSITION message with a GCS_RESULTSTR flag 307 // (on Windows); 308 // * when it receives a "commit" signal of GtkIMContext (on Linux); 309 // * when insertText of NSTextInput is called (on Mac). 310 void ImeConfirmComposition(const string16& text); 311 void ImeConfirmComposition(const string16& text, 312 const ui::Range& replacement_range); 313 314 // Finishes an ongoing composition with the composition text set by last 315 // SetComposition() call. 316 void ImeConfirmComposition(); 317 318 // Cancels an ongoing composition. 319 void ImeCancelComposition(); 320 321 // Deletes the current selection plus the specified number of characters 322 // before and after the selection or caret. 323 void ExtendSelectionAndDelete(size_t before, size_t after); 324 325 // This is for derived classes to give us access to the resizer rect. 326 // And to also expose it to the RenderWidgetHostView. 327 virtual gfx::Rect GetRootWindowResizerRect() const; 328 329 bool ignore_input_events() const { 330 return ignore_input_events_; 331 } 332 333 bool ShouldForwardTouchEvent() const; 334 335 bool has_touch_handler() const { return has_touch_handler_; } 336 337 // Notification that the user has made some kind of input that could 338 // perform an action. See OnUserGesture for more details. 339 void StartUserGesture(); 340 341 // Set the RenderView background. 342 void SetBackground(const SkBitmap& background); 343 344 // Notifies the renderer that the next key event is bound to one or more 345 // pre-defined edit commands 346 void SetEditCommandsForNextKeyEvent( 347 const std::vector<EditCommand>& commands); 348 349 // Gets the accessibility mode. 350 AccessibilityMode accessibility_mode() const { 351 return accessibility_mode_; 352 } 353 354 // Send a message to the renderer process to change the accessibility mode. 355 void SetAccessibilityMode(AccessibilityMode mode); 356 357 // Relay a request from assistive technology to perform the default action 358 // on a given node. 359 void AccessibilityDoDefaultAction(int object_id); 360 361 // Relay a request from assistive technology to set focus to a given node. 362 void AccessibilitySetFocus(int object_id); 363 364 // Relay a request from assistive technology to make a given object 365 // visible by scrolling as many scrollable containers as necessary. 366 // In addition, if it's not possible to make the entire object visible, 367 // scroll so that the |subfocus| rect is visible at least. The subfocus 368 // rect is in local coordinates of the object itself. 369 void AccessibilityScrollToMakeVisible( 370 int acc_obj_id, gfx::Rect subfocus); 371 372 // Relay a request from assistive technology to move a given object 373 // to a specific location, in the WebContents area coordinate space, i.e. 374 // (0, 0) is the top-left corner of the WebContents. 375 void AccessibilityScrollToPoint(int acc_obj_id, gfx::Point point); 376 377 // Relay a request from assistive technology to set text selection. 378 void AccessibilitySetTextSelection( 379 int acc_obj_id, int start_offset, int end_offset); 380 381 // Kill the renderer because we got a fatal accessibility error. 382 void FatalAccessibilityTreeError(); 383 384#if defined(OS_WIN) && defined(USE_AURA) 385 gfx::NativeViewAccessible GetParentNativeViewAccessible() const; 386#endif 387 388 // Executes the edit command on the RenderView. 389 void ExecuteEditCommand(const std::string& command, 390 const std::string& value); 391 392 // Tells the renderer to scroll the currently focused node into rect only if 393 // the currently focused node is a Text node (textfield, text area or content 394 // editable divs). 395 void ScrollFocusedEditableNodeIntoRect(const gfx::Rect& rect); 396 397 // Requests the renderer to select the region between two points. 398 void SelectRange(const gfx::Point& start, const gfx::Point& end); 399 400 // Requests the renderer to move the caret selection towards the point. 401 void MoveCaret(const gfx::Point& point); 402 403 // Called when the reponse to a pending mouse lock request has arrived. 404 // Returns true if |allowed| is true and the mouse has been successfully 405 // locked. 406 bool GotResponseToLockMouseRequest(bool allowed); 407 408 // Tells the RenderWidget about the latest vsync parameters. 409 // Note: Make sure the timebase was obtained using 410 // base::TimeTicks::HighResNow. Using the non-high res timer will result in 411 // incorrect synchronization across processes. 412 virtual void UpdateVSyncParameters(base::TimeTicks timebase, 413 base::TimeDelta interval); 414 415 // Called by the view in response to AcceleratedSurfaceBuffersSwapped or 416 // AcceleratedSurfacePostSubBuffer. 417 static void AcknowledgeBufferPresent( 418 int32 route_id, 419 int gpu_host_id, 420 const AcceleratedSurfaceMsg_BufferPresented_Params& params); 421 422 // Called by the view in response to OnSwapCompositorFrame. 423 static void SendSwapCompositorFrameAck( 424 int32 route_id, int renderer_host_id, const cc::CompositorFrameAck& ack); 425 426 // Called by the view in response to AcceleratedSurfaceBuffersSwapped for 427 // platforms that support deferred GPU process descheduling. This does 428 // nothing if the compositor thread is enabled. 429 // TODO(jbates) Once the compositor thread is always on, this can be removed. 430 void AcknowledgeSwapBuffersToRenderer(); 431 432#if defined(USE_AURA) 433 // Called by the view when the parent changes. If a parent isn't available, 434 // NULL is used. 435 void ParentChanged(gfx::NativeViewId new_parent); 436#endif 437 438 // Signals that the compositing surface was updated, e.g. after a lost context 439 // event. 440 void CompositingSurfaceUpdated(); 441 442 void set_allow_privileged_mouse_lock(bool allow) { 443 allow_privileged_mouse_lock_ = allow; 444 } 445 446 // Resets state variables related to tracking pending size and painting. 447 // 448 // We need to reset these flags when we want to repaint the contents of 449 // browser plugin in this RWH. Resetting these flags will ensure we ignore 450 // any previous pending acks that are not relevant upon repaint. 451 void ResetSizeAndRepaintPendingFlags(); 452 453 void DetachDelegate(); 454 455 // Update the renderer's cache of the screen rect of the view and window. 456 void SendScreenRects(); 457 458 GestureEventFilter* gesture_event_filter() { 459 return gesture_event_filter_.get(); 460 } 461 462 OverscrollController* overscroll_controller() { 463 return overscroll_controller_.get(); 464 } 465 466 base::TimeDelta GetSyntheticScrollMessageInterval() const; 467 468 // Sets whether the overscroll controller should be enabled for this page. 469 void SetOverscrollControllerEnabled(bool enabled); 470 471 // Suppreses future char events until a keydown. See 472 // suppress_next_char_events_. 473 void SuppressNextCharEvents(); 474 475 // Indicates whether the renderer drives the RenderWidgetHosts's size or the 476 // other way around. 477 bool should_auto_resize() { return should_auto_resize_; } 478 479 void FrameSwapped(const cc::LatencyInfo& latency_info); 480 481 // Returns the ID that uniquely describes this component to the latency 482 // subsystem. 483 int64 GetLatencyComponentId(); 484 485 protected: 486 virtual RenderWidgetHostImpl* AsRenderWidgetHostImpl() OVERRIDE; 487 488 // Transmits the given input event. This is an internal helper for 489 // |ForwardInputEvent()| and should not be used directly from elsewhere. 490 void SendInputEvent(const WebKit::WebInputEvent& input_event, 491 int event_size, const cc::LatencyInfo& latency_info, 492 bool is_keyboard_shortcut); 493 494 // Internal implementation of the public Forward*Event() methods. 495 void ForwardInputEvent(const WebKit::WebInputEvent& input_event, 496 int event_size, const cc::LatencyInfo& latency_info, 497 bool is_keyboard_shortcut); 498 499 // Internal forwarding implementations that take a LatencyInfo. 500 virtual void ForwardMouseEventWithLatencyInfo( 501 const MouseEventWithLatencyInfo& mouse_event); 502 virtual void ForwardWheelEventWithLatencyInfo( 503 const WebKit::WebMouseWheelEvent& wheel_event, 504 const cc::LatencyInfo& latency_info); 505 506 // Create a LatencyInfo struct for a new input event that was just received. 507 cc::LatencyInfo NewInputLatencyInfo(); 508 509 // Called when we receive a notification indicating that the renderer 510 // process has gone. This will reset our state so that our state will be 511 // consistent if a new renderer is created. 512 void RendererExited(base::TerminationStatus status, int exit_code); 513 514 // Retrieves an id the renderer can use to refer to its view. 515 // This is used for various IPC messages, including plugins. 516 gfx::NativeViewId GetNativeViewId() const; 517 518 // Retrieves an id for the surface that the renderer can draw to 519 // when accelerated compositing is enabled. 520 gfx::GLSurfaceHandle GetCompositingSurface(); 521 522 // --------------------------------------------------------------------------- 523 // The following methods are overridden by RenderViewHost to send upwards to 524 // its delegate. 525 526 // Called when a mousewheel event was not processed by the renderer. 527 virtual void UnhandledWheelEvent(const WebKit::WebMouseWheelEvent& event) {} 528 529 // Notification that the user has made some kind of input that could 530 // perform an action. The gestures that count are 1) any mouse down 531 // event and 2) enter or space key presses. 532 virtual void OnUserGesture() {} 533 534 // Callbacks for notification when the renderer becomes unresponsive to user 535 // input events, and subsequently responsive again. 536 virtual void NotifyRendererUnresponsive() {} 537 virtual void NotifyRendererResponsive() {} 538 539 // Called when auto-resize resulted in the renderer size changing. 540 virtual void OnRenderAutoResized(const gfx::Size& new_size) {} 541 542 // --------------------------------------------------------------------------- 543 544 // RenderViewHost overrides this method to impose further restrictions on when 545 // to allow mouse lock. 546 // Once the request is approved or rejected, GotResponseToLockMouseRequest() 547 // will be called. 548 virtual void RequestToLockMouse(bool user_gesture, 549 bool last_unlocked_by_target); 550 551 void RejectMouseLockOrUnlockIfNecessary(); 552 bool IsMouseLocked() const; 553 554 // RenderViewHost overrides this method to report when in fullscreen mode. 555 virtual bool IsFullscreen() const; 556 557 // Indicates if the render widget host should track the render widget's size 558 // as opposed to visa versa. 559 void SetShouldAutoResize(bool enable); 560 561 // Expose increment/decrement of the in-flight event count, so 562 // RenderViewHostImpl can account for in-flight beforeunload/unload events. 563 int increment_in_flight_event_count() { return ++in_flight_event_count_; } 564 int decrement_in_flight_event_count() { return --in_flight_event_count_; } 565 566 // Returns whether an overscroll gesture is in progress. 567 bool IsInOverscrollGesture() const; 568 569 // The View associated with the RenderViewHost. The lifetime of this object 570 // is associated with the lifetime of the Render process. If the Renderer 571 // crashes, its View is destroyed and this pointer becomes NULL, even though 572 // render_view_host_ lives on to load another URL (creating a new View while 573 // doing so). 574 RenderWidgetHostViewPort* view_; 575 576 // true if a renderer has once been valid. We use this flag to display a sad 577 // tab only when we lose our renderer and not if a paint occurs during 578 // initialization. 579 bool renderer_initialized_; 580 581 // This value indicates how long to wait before we consider a renderer hung. 582 int hung_renderer_delay_ms_; 583 584 std::queue<WebKit::WebInputEvent::Type> in_process_event_types_; 585 586 private: 587 friend class MockRenderWidgetHost; 588 589 // Tell this object to destroy itself. 590 void Destroy(); 591 592 // Checks whether the renderer is hung and calls NotifyRendererUnresponsive 593 // if it is. 594 void CheckRendererIsUnresponsive(); 595 596 // Called if we know the renderer is responsive. When we currently think the 597 // renderer is unresponsive, this will clear that state and call 598 // NotifyRendererResponsive. 599 void RendererIsResponsive(); 600 601 // IPC message handlers 602 void OnRenderViewReady(); 603 void OnRenderViewGone(int status, int error_code); 604 void OnClose(); 605 void OnUpdateScreenRectsAck(); 606 void OnRequestMove(const gfx::Rect& pos); 607 void OnSetTooltipText(const string16& tooltip_text, 608 WebKit::WebTextDirection text_direction_hint); 609 void OnPaintAtSizeAck(int tag, const gfx::Size& size); 610 void OnCompositorSurfaceBuffersSwapped(int32 surface_id, 611 uint64 surface_handle, 612 int32 route_id, 613 const gfx::Size& size, 614 int32 gpu_process_host_id); 615 bool OnSwapCompositorFrame(const IPC::Message& message); 616 void OnUpdateRect(const ViewHostMsg_UpdateRect_Params& params); 617 void OnUpdateIsDelayed(); 618 void OnInputEventAck(WebKit::WebInputEvent::Type event_type, 619 InputEventAckState ack_result); 620 void OnBeginSmoothScroll( 621 const ViewHostMsg_BeginSmoothScroll_Params& params); 622 void OnSelectRangeAck(); 623 void OnMsgMoveCaretAck(); 624 virtual void OnFocus(); 625 virtual void OnBlur(); 626 void OnHasTouchEventHandlers(bool has_handlers); 627 void OnSetCursor(const WebCursor& cursor); 628 void OnTextInputStateChanged( 629 const ViewHostMsg_TextInputState_Params& params); 630 void OnImeCompositionRangeChanged( 631 const ui::Range& range, 632 const std::vector<gfx::Rect>& character_bounds); 633 void OnImeCancelComposition(); 634 void OnDidActivateAcceleratedCompositing(bool activated); 635 void OnLockMouse(bool user_gesture, 636 bool last_unlocked_by_target, 637 bool privileged); 638 void OnUnlockMouse(); 639 void OnShowDisambiguationPopup(const gfx::Rect& rect, 640 const gfx::Size& size, 641 const TransportDIB::Id& id); 642#if defined(OS_WIN) 643 void OnWindowlessPluginDummyWindowCreated( 644 gfx::NativeViewId dummy_activation_window); 645 void OnWindowlessPluginDummyWindowDestroyed( 646 gfx::NativeViewId dummy_activation_window); 647#endif 648 void OnSnapshot(bool success, const SkBitmap& bitmap); 649 650 // Called (either immediately or asynchronously) after we're done with our 651 // BackingStore and can send an ACK to the renderer so it can paint onto it 652 // again. 653 void DidUpdateBackingStore(const ViewHostMsg_UpdateRect_Params& params, 654 const base::TimeTicks& paint_start); 655 656 // Paints the given bitmap to the current backing store at the given 657 // location. Returns true if the passed callback was asynchronously 658 // scheduled in the future (and thus the caller must manually synchronously 659 // call the callback function). 660 bool PaintBackingStoreRect(TransportDIB::Id bitmap, 661 const gfx::Rect& bitmap_rect, 662 const std::vector<gfx::Rect>& copy_rects, 663 const gfx::Size& view_size, 664 float scale_factor, 665 const base::Closure& completion_callback); 666 667 // Scrolls the given |clip_rect| in the backing by the given dx/dy amount. The 668 // |dib| and its corresponding location |bitmap_rect| in the backing store 669 // is the newly painted pixels by the renderer. 670 void ScrollBackingStoreRect(const gfx::Vector2d& delta, 671 const gfx::Rect& clip_rect, 672 const gfx::Size& view_size); 673 674 // Give key press listeners a chance to handle this key press. This allow 675 // widgets that don't have focus to still handle key presses. 676 bool KeyPressListenersHandleEvent(const NativeWebKeyboardEvent& event); 677 678 // Called by OnInputEventAck() to process a keyboard event ack message. 679 void ProcessKeyboardEventAck(int type, bool processed); 680 681 // Called by OnInputEventAck() to process a wheel event ack message. 682 // This could result in a task being posted to allow additional wheel 683 // input messages to be coalesced. 684 void ProcessWheelAck(bool processed); 685 686 // Called by OnInputEventAck() to process a gesture event ack message. 687 // This validates the gesture for suppression of touchpad taps and sends one 688 // previously queued coalesced gesture if it exists. 689 void ProcessGestureAck(bool processed, int type); 690 691 void SimulateTouchGestureWithMouse(const WebKit::WebMouseEvent& mouse_event); 692 693 // Called on OnInputEventAck() to process a touch event ack message. 694 // This can result in a gesture event being generated and sent back to the 695 // renderer. 696 void ProcessTouchAck(InputEventAckState ack_result); 697 698 // Called when there is a new auto resize (using a post to avoid a stack 699 // which may get in recursive loops). 700 void DelayedAutoResized(); 701 702 703 // Our delegate, which wants to know mainly about keyboard events. 704 // It will remain non-NULL until DetachDelegate() is called. 705 RenderWidgetHostDelegate* delegate_; 706 707 // Created during construction but initialized during Init*(). Therefore, it 708 // is guaranteed never to be NULL, but its channel may be NULL if the 709 // renderer crashed, so you must always check that. 710 RenderProcessHost* process_; 711 712 // The ID of the corresponding object in the Renderer Instance. 713 int routing_id_; 714 715 // The ID of the surface corresponding to this render widget. 716 int surface_id_; 717 718 // Indicates whether a page is loading or not. 719 bool is_loading_; 720 721 // Indicates whether a page is hidden or not. 722 bool is_hidden_; 723 724 // Indicates whether a page is fullscreen or not. 725 bool is_fullscreen_; 726 727 // True when a page is rendered directly via the GPU process. 728 bool is_accelerated_compositing_active_; 729 730 // True if threaded compositing is enabled on this view. 731 bool is_threaded_compositing_enabled_; 732 733 // Set if we are waiting for a repaint ack for the view. 734 bool repaint_ack_pending_; 735 736 // True when waiting for RESIZE_ACK. 737 bool resize_ack_pending_; 738 739 // The current size of the RenderWidget. 740 gfx::Size current_size_; 741 742 // The size of the view's backing surface in non-DPI-adjusted pixels. 743 gfx::Size physical_backing_size_; 744 745 // The height of the physical backing surface that is overdrawn opaquely in 746 // the browser, for example by an on-screen-keyboard (in DPI-adjusted pixels). 747 float overdraw_bottom_height_; 748 749 // The size we last sent as requested size to the renderer. |current_size_| 750 // is only updated once the resize message has been ack'd. This on the other 751 // hand is updated when the resize message is sent. This is very similar to 752 // |resize_ack_pending_|, but the latter is not set if the new size has width 753 // or height zero, which is why we need this too. 754 gfx::Size in_flight_size_; 755 756 // The next auto resize to send. 757 gfx::Size new_auto_size_; 758 759 // True if the render widget host should track the render widget's size as 760 // opposed to visa versa. 761 bool should_auto_resize_; 762 763 bool waiting_for_screen_rects_ack_; 764 gfx::Rect last_view_screen_rect_; 765 gfx::Rect last_window_screen_rect_; 766 767 // True if a mouse move event was sent to the render view and we are waiting 768 // for a corresponding InputHostMsg_HandleInputEvent_ACK message. 769 bool mouse_move_pending_; 770 771 // The next mouse move event to send (only non-null while mouse_move_pending_ 772 // is true). 773 scoped_ptr<MouseEventWithLatencyInfo> next_mouse_move_; 774 775 // (Similar to |mouse_move_pending_|.) True if a mouse wheel event was sent 776 // and we are waiting for a corresponding ack. 777 bool mouse_wheel_pending_; 778 WebKit::WebMouseWheelEvent current_wheel_event_; 779 780 typedef std::deque<MouseWheelEventWithLatencyInfo> WheelEventQueue; 781 782 // (Similar to |next_mouse_move_|.) The next mouse wheel events to send. 783 // Unlike mouse moves, mouse wheel events received while one is pending are 784 // coalesced (by accumulating deltas) if they match the previous event in 785 // modifiers. On the Mac, in particular, mouse wheel events are received at a 786 // high rate; not waiting for the ack results in jankiness, and using the same 787 // mechanism as for mouse moves (just dropping old events when multiple ones 788 // would be queued) results in very slow scrolling. 789 WheelEventQueue coalesced_mouse_wheel_events_; 790 791 AccessibilityMode accessibility_mode_; 792 793 // (Similar to |mouse_move_pending_|.) True while waiting for SelectRange_ACK. 794 bool select_range_pending_; 795 796 // (Similar to |next_mouse_move_|.) The next SelectRange to send, if any. 797 struct SelectionRange { 798 gfx::Point start, end; 799 }; 800 scoped_ptr<SelectionRange> next_selection_range_; 801 802 // (Similar to |mouse_move_pending_|.) True while waiting for MoveCaret_ACK. 803 bool move_caret_pending_; 804 805 // (Similar to |next_mouse_move_|.) The next MoveCaret to send, if any. 806 scoped_ptr<gfx::Point> next_move_caret_; 807 808 // The time when an input event was sent to the RenderWidget. 809 base::TimeTicks input_event_start_time_; 810 811 // Keyboard event listeners. 812 ObserverList<KeyboardListener> keyboard_listeners_; 813 814 // If true, then we should repaint when restoring even if we have a 815 // backingstore. This flag is set to true if we receive a paint message 816 // while is_hidden_ to true. Even though we tell the render widget to hide 817 // itself, a paint message could already be in flight at that point. 818 bool needs_repainting_on_restore_; 819 820 // This is true if the renderer is currently unresponsive. 821 bool is_unresponsive_; 822 823 // The following value indicates a time in the future when we would consider 824 // the renderer hung if it does not generate an appropriate response message. 825 base::Time time_when_considered_hung_; 826 827 // This value denotes the number of input events yet to be acknowledged 828 // by the renderer. 829 int in_flight_event_count_; 830 831 // This timer runs to check if time_when_considered_hung_ has past. 832 base::OneShotTimer<RenderWidgetHostImpl> hung_renderer_timer_; 833 834 // Flag to detect recursive calls to GetBackingStore(). 835 bool in_get_backing_store_; 836 837 // Flag to trigger the GetBackingStore method to abort early. 838 bool abort_get_backing_store_; 839 840 // Set when we call DidPaintRect/DidScrollRect on the view. 841 bool view_being_painted_; 842 843 // Used for UMA histogram logging to measure the time for a repaint view 844 // operation to finish. 845 base::TimeTicks repaint_start_time_; 846 847 // Queue of keyboard events that we need to track. 848 typedef std::deque<NativeWebKeyboardEvent> KeyQueue; 849 850 // A queue of keyboard events. We can't trust data from the renderer so we 851 // stuff key events into a queue and pop them out on ACK, feeding our copy 852 // back to whatever unhandled handler instead of the returned version. 853 KeyQueue key_queue_; 854 855 // Set to true if we shouldn't send input events from the render widget. 856 bool ignore_input_events_; 857 858 // Set when we update the text direction of the selected input element. 859 bool text_direction_updated_; 860 WebKit::WebTextDirection text_direction_; 861 862 // Set when we cancel updating the text direction. 863 // This flag also ignores succeeding update requests until we call 864 // NotifyTextDirection(). 865 bool text_direction_canceled_; 866 867 // Indicates if the next sequence of Char events should be suppressed or not. 868 // System may translate a RawKeyDown event into zero or more Char events, 869 // usually we send them to the renderer directly in sequence. However, If a 870 // RawKeyDown event was not handled by the renderer but was handled by 871 // our UnhandledKeyboardEvent() method, e.g. as an accelerator key, then we 872 // shall not send the following sequence of Char events, which was generated 873 // by this RawKeyDown event, to the renderer. Otherwise the renderer may 874 // handle the Char events and cause unexpected behavior. 875 // For example, pressing alt-2 may let the browser switch to the second tab, 876 // but the Char event generated by alt-2 may also activate a HTML element 877 // if its accesskey happens to be "2", then the user may get confused when 878 // switching back to the original tab, because the content may already be 879 // changed. 880 bool suppress_next_char_events_; 881 882 // The last scroll offset of the render widget. 883 gfx::Vector2d last_scroll_offset_; 884 885 bool pending_mouse_lock_request_; 886 bool allow_privileged_mouse_lock_; 887 888 // Keeps track of whether the webpage has any touch event handler. If it does, 889 // then touch events are sent to the renderer. Otherwise, the touch events are 890 // not sent to the renderer. 891 bool has_touch_handler_; 892 893 base::WeakPtrFactory<RenderWidgetHostImpl> weak_factory_; 894 895 SmoothScrollGestureController smooth_scroll_gesture_controller_; 896 scoped_ptr<TouchEventQueue> touch_event_queue_; 897 scoped_ptr<GestureEventFilter> gesture_event_filter_; 898 scoped_ptr<OverscrollController> overscroll_controller_; 899 900#if defined(OS_WIN) 901 std::list<HWND> dummy_windows_for_activation_; 902#endif 903 904 // List of callbacks for pending snapshot requests to the renderer. 905 std::queue<base::Callback<void(bool, const SkBitmap&)> > pending_snapshots_; 906 907 int64 last_input_number_; 908 909 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostImpl); 910}; 911 912} // namespace content 913 914#endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_IMPL_H_ 915