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