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.
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_IMPL_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_IMPL_H_
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/kill.h"
22 #include "base/strings/string16.h"
23 #include "base/time/time.h"
24 #include "base/timer/timer.h"
25 #include "build/build_config.h"
26 #include "cc/resources/shared_bitmap.h"
27 #include "content/browser/accessibility/browser_accessibility_manager.h"
28 #include "content/browser/renderer_host/event_with_latency_info.h"
29 #include "content/browser/renderer_host/input/input_ack_handler.h"
30 #include "content/browser/renderer_host/input/input_router_client.h"
31 #include "content/browser/renderer_host/input/synthetic_gesture.h"
32 #include "content/browser/renderer_host/input/touch_emulator_client.h"
33 #include "content/common/input/input_event_ack_state.h"
34 #include "content/common/input/synthetic_gesture_packet.h"
35 #include "content/common/view_message_enums.h"
36 #include "content/public/browser/render_widget_host.h"
37 #include "content/public/common/page_zoom.h"
38 #include "ipc/ipc_listener.h"
39 #include "ui/base/ime/text_input_mode.h"
40 #include "ui/base/ime/text_input_type.h"
41 #include "ui/events/latency_info.h"
42 #include "ui/gfx/native_widget_types.h"
44 struct AcceleratedSurfaceMsg_BufferPresented_Params
;
45 struct ViewHostMsg_BeginSmoothScroll_Params
;
46 struct ViewHostMsg_CompositorSurfaceBuffersSwapped_Params
;
47 struct ViewHostMsg_SelectionBounds_Params
;
48 struct ViewHostMsg_TextInputState_Params
;
49 struct ViewHostMsg_UpdateRect_Params
;
56 class CompositorFrame
;
57 class CompositorFrameAck
;
71 struct WebCompositionUnderline
;
75 #if defined(OS_ANDROID)
83 class MockRenderWidgetHost
;
84 class RenderWidgetHostDelegate
;
85 class RenderWidgetHostViewBase
;
86 class SyntheticGestureController
;
92 // This implements the RenderWidgetHost interface that is exposed to
93 // embedders of content, and adds things only visible to content.
94 class CONTENT_EXPORT RenderWidgetHostImpl
95 : virtual public RenderWidgetHost
,
96 public InputRouterClient
,
97 public InputAckHandler
,
98 public TouchEmulatorClient
,
100 public BrowserAccessibilityDelegate
{
102 // routing_id can be MSG_ROUTING_NONE, in which case the next available
103 // routing id is taken from the RenderProcessHost.
104 // If this object outlives |delegate|, DetachDelegate() must be called when
105 // |delegate| goes away.
106 RenderWidgetHostImpl(RenderWidgetHostDelegate
* delegate
,
107 RenderProcessHost
* process
,
110 virtual ~RenderWidgetHostImpl();
112 // Similar to RenderWidgetHost::FromID, but returning the Impl object.
113 static RenderWidgetHostImpl
* FromID(int32 process_id
, int32 routing_id
);
115 // Returns all RenderWidgetHosts including swapped out ones for
116 // internal use. The public interface
117 // RendgerWidgetHost::GetRenderWidgetHosts only returns active ones.
118 static scoped_ptr
<RenderWidgetHostIterator
> GetAllRenderWidgetHosts();
120 // Use RenderWidgetHostImpl::From(rwh) to downcast a
121 // RenderWidgetHost to a RenderWidgetHostImpl. Internally, this
122 // uses RenderWidgetHost::AsRenderWidgetHostImpl().
123 static RenderWidgetHostImpl
* From(RenderWidgetHost
* rwh
);
125 void set_hung_renderer_delay_ms(const base::TimeDelta
& timeout
) {
126 hung_renderer_delay_ms_
= timeout
.InMilliseconds();
129 // RenderWidgetHost implementation.
130 virtual void UpdateTextDirection(blink::WebTextDirection direction
) OVERRIDE
;
131 virtual void NotifyTextDirection() OVERRIDE
;
132 virtual void Focus() OVERRIDE
;
133 virtual void Blur() OVERRIDE
;
134 virtual void SetActive(bool active
) OVERRIDE
;
135 virtual void CopyFromBackingStore(
136 const gfx::Rect
& src_rect
,
137 const gfx::Size
& accelerated_dst_size
,
138 const base::Callback
<void(bool, const SkBitmap
&)>& callback
,
139 const SkColorType color_type
) OVERRIDE
;
140 virtual bool CanCopyFromBackingStore() OVERRIDE
;
141 #if defined(OS_ANDROID)
142 virtual void LockBackingStore() OVERRIDE
;
143 virtual void UnlockBackingStore() OVERRIDE
;
145 virtual void EnableFullAccessibilityMode() OVERRIDE
;
146 virtual bool IsFullAccessibilityModeForTesting() OVERRIDE
;
147 virtual void EnableTreeOnlyAccessibilityMode() OVERRIDE
;
148 virtual bool IsTreeOnlyAccessibilityModeForTesting() OVERRIDE
;
149 virtual void ForwardMouseEvent(
150 const blink::WebMouseEvent
& mouse_event
) OVERRIDE
;
151 virtual void ForwardWheelEvent(
152 const blink::WebMouseWheelEvent
& wheel_event
) OVERRIDE
;
153 virtual void ForwardKeyboardEvent(
154 const NativeWebKeyboardEvent
& key_event
) OVERRIDE
;
155 virtual const gfx::Vector2d
& GetLastScrollOffset() const OVERRIDE
;
156 virtual RenderProcessHost
* GetProcess() const OVERRIDE
;
157 virtual int GetRoutingID() const OVERRIDE
;
158 virtual RenderWidgetHostView
* GetView() const OVERRIDE
;
159 virtual bool IsLoading() const OVERRIDE
;
160 virtual bool IsRenderView() const OVERRIDE
;
161 virtual void ResizeRectChanged(const gfx::Rect
& new_rect
) OVERRIDE
;
162 virtual void RestartHangMonitorTimeout() OVERRIDE
;
163 virtual void SetIgnoreInputEvents(bool ignore_input_events
) OVERRIDE
;
164 virtual void Stop() OVERRIDE
;
165 virtual void WasResized() OVERRIDE
;
166 virtual void AddKeyPressEventCallback(
167 const KeyPressEventCallback
& callback
) OVERRIDE
;
168 virtual void RemoveKeyPressEventCallback(
169 const KeyPressEventCallback
& callback
) OVERRIDE
;
170 virtual void AddMouseEventCallback(
171 const MouseEventCallback
& callback
) OVERRIDE
;
172 virtual void RemoveMouseEventCallback(
173 const MouseEventCallback
& callback
) OVERRIDE
;
174 virtual void GetWebScreenInfo(blink::WebScreenInfo
* result
) OVERRIDE
;
176 virtual SkColorType
PreferredReadbackFormat() OVERRIDE
;
178 // BrowserAccessibilityDelegate
179 virtual void AccessibilitySetFocus(int acc_obj_id
) OVERRIDE
;
180 virtual void AccessibilityDoDefaultAction(int acc_obj_id
) OVERRIDE
;
181 virtual void AccessibilityShowMenu(int acc_obj_id
) OVERRIDE
;
182 virtual void AccessibilityScrollToMakeVisible(
183 int acc_obj_id
, gfx::Rect subfocus
) OVERRIDE
;
184 virtual void AccessibilityScrollToPoint(
185 int acc_obj_id
, gfx::Point point
) OVERRIDE
;
186 virtual void AccessibilitySetTextSelection(
187 int acc_obj_id
, int start_offset
, int end_offset
) OVERRIDE
;
188 virtual bool AccessibilityViewHasFocus() const OVERRIDE
;
189 virtual gfx::Rect
AccessibilityGetViewBounds() const OVERRIDE
;
190 virtual gfx::Point
AccessibilityOriginInScreen(const gfx::Rect
& bounds
)
192 virtual void AccessibilityHitTest(const gfx::Point
& point
) OVERRIDE
;
193 virtual void AccessibilityFatalError() OVERRIDE
;
195 // Forces redraw in the renderer and when the update reaches the browser
196 // grabs snapshot from the compositor. Returns PNG-encoded snapshot.
197 void GetSnapshotFromBrowser(
198 const base::Callback
<void(const unsigned char*,size_t)> callback
);
200 const NativeWebKeyboardEvent
* GetLastKeyboardEvent() const;
202 // Notification that the screen info has changed.
203 void NotifyScreenInfoChanged();
205 // Invalidates the cached screen info so that next resize request
206 // will carry the up to date screen info. Unlike
207 // |NotifyScreenInfoChanged|, this doesn't send a message to the renderer.
208 void InvalidateScreenInfo();
210 // Sets the View of this RenderWidgetHost.
211 void SetView(RenderWidgetHostViewBase
* view
);
213 int surface_id() const { return surface_id_
; }
215 bool empty() const { return current_size_
.IsEmpty(); }
217 // Called when a renderer object already been created for this host, and we
218 // just need to be attached to it. Used for window.open, <select> dropdown
219 // menus, and other times when the renderer initiates creating an object.
222 // Tells the renderer to die and then calls Destroy().
223 virtual void Shutdown();
226 virtual bool OnMessageReceived(const IPC::Message
& msg
) OVERRIDE
;
228 // Sends a message to the corresponding object in the renderer.
229 virtual bool Send(IPC::Message
* msg
) OVERRIDE
;
231 // Called to notify the RenderWidget that it has been hidden or restored from
232 // having been hidden.
236 // Returns true if the RenderWidget is hidden.
237 bool is_hidden() const { return is_hidden_
; }
239 // Called to notify the RenderWidget that its associated native window
241 virtual void GotFocus();
242 virtual void LostCapture();
244 // Called to notify the RenderWidget that it has lost the mouse lock.
245 virtual void LostMouseLock();
247 // Noifies the RenderWidget of the current mouse cursor visibility state.
248 void SendCursorVisibilityState(bool is_visible
);
250 // Notifies the RenderWidgetHost that the View was destroyed.
251 void ViewDestroyed();
253 // Indicates if the page has finished loading.
254 void SetIsLoading(bool is_loading
);
256 // Pause for a moment to wait for pending repaint or resize messages sent to
257 // the renderer to arrive. If pending resize messages are for an old window
258 // size, then also pump through a new resize message if there is time.
259 void PauseForPendingResizeOrRepaints();
261 // Whether pausing may be useful.
262 bool CanPauseForPendingResizeOrRepaints();
264 bool resize_ack_pending_for_testing() { return resize_ack_pending_
; }
266 // Wait for a surface matching the size of the widget's view, possibly
267 // blocking until the renderer sends a new frame.
268 void WaitForSurface();
270 // GPU accelerated version of GetBackingStore function. This will
271 // trigger a re-composite to the view. It may fail if a resize is pending, or
272 // if a composite has already been requested and not acked yet.
273 bool ScheduleComposite();
275 // Starts a hang monitor timeout. If there's already a hang monitor timeout
276 // the new one will only fire if it has a shorter delay than the time
277 // left on the existing timeouts.
278 void StartHangMonitorTimeout(base::TimeDelta delay
);
280 // Stops all existing hang monitor timeouts and assumes the renderer is
282 void StopHangMonitorTimeout();
284 // Forwards the given message to the renderer. These are called by the view
285 // when it has received a message.
286 void ForwardGestureEventWithLatencyInfo(
287 const blink::WebGestureEvent
& gesture_event
,
288 const ui::LatencyInfo
& ui_latency
);
289 void ForwardTouchEventWithLatencyInfo(
290 const blink::WebTouchEvent
& touch_event
,
291 const ui::LatencyInfo
& ui_latency
);
292 void ForwardMouseEventWithLatencyInfo(
293 const blink::WebMouseEvent
& mouse_event
,
294 const ui::LatencyInfo
& ui_latency
);
295 void ForwardWheelEventWithLatencyInfo(
296 const blink::WebMouseWheelEvent
& wheel_event
,
297 const ui::LatencyInfo
& ui_latency
);
299 // TouchEmulatorClient overrides.
300 virtual void ForwardGestureEvent(
301 const blink::WebGestureEvent
& gesture_event
) OVERRIDE
;
302 virtual void ForwardTouchEvent(
303 const blink::WebTouchEvent
& touch_event
) OVERRIDE
;
304 virtual void SetCursor(const WebCursor
& cursor
) OVERRIDE
;
306 // Queues a synthetic gesture for testing purposes. Invokes the on_complete
307 // callback when the gesture is finished running.
308 void QueueSyntheticGesture(
309 scoped_ptr
<SyntheticGesture
> synthetic_gesture
,
310 const base::Callback
<void(SyntheticGesture::Result
)>& on_complete
);
312 void CancelUpdateTextDirection();
314 // Called when a mouse click/gesture tap activates the renderer.
315 virtual void OnPointerEventActivate();
317 // Notifies the renderer whether or not the input method attached to this
318 // process is activated.
319 // When the input method is activated, a renderer process sends IPC messages
320 // to notify the status of its composition node. (This message is mainly used
321 // for notifying the position of the input cursor so that the browser can
322 // display input method windows under the cursor.)
323 void SetInputMethodActive(bool activate
);
325 // Notifies the renderer changes of IME candidate window state.
326 void CandidateWindowShown();
327 void CandidateWindowUpdated();
328 void CandidateWindowHidden();
330 // Update the composition node of the renderer (or WebKit).
331 // WebKit has a special node (a composition node) for input method to change
332 // its text without affecting any other DOM nodes. When the input method
333 // (attached to the browser) updates its text, the browser sends IPC messages
334 // to update the composition node of the renderer.
335 // (Read the comments of each function for its detail.)
337 // Sets the text of the composition node.
338 // This function can also update the cursor position and mark the specified
339 // range in the composition node.
340 // A browser should call this function:
341 // * when it receives a WM_IME_COMPOSITION message with a GCS_COMPSTR flag
343 // * when it receives a "preedit_changed" signal of GtkIMContext (on Linux);
344 // * when markedText of NSTextInput is called (on Mac).
345 void ImeSetComposition(
346 const base::string16
& text
,
347 const std::vector
<blink::WebCompositionUnderline
>& underlines
,
351 // Finishes an ongoing composition with the specified text.
352 // A browser should call this function:
353 // * when it receives a WM_IME_COMPOSITION message with a GCS_RESULTSTR flag
355 // * when it receives a "commit" signal of GtkIMContext (on Linux);
356 // * when insertText of NSTextInput is called (on Mac).
357 void ImeConfirmComposition(const base::string16
& text
,
358 const gfx::Range
& replacement_range
,
359 bool keep_selection
);
361 // Cancels an ongoing composition.
362 void ImeCancelComposition();
364 // This is for derived classes to give us access to the resizer rect.
365 // And to also expose it to the RenderWidgetHostView.
366 virtual gfx::Rect
GetRootWindowResizerRect() const;
368 bool ignore_input_events() const {
369 return ignore_input_events_
;
372 bool input_method_active() const {
373 return input_method_active_
;
376 // Whether forwarded WebInputEvents should be ignored. True if either
377 // |ignore_input_events_| or |process_->IgnoreInputEvents()| is true.
378 bool IgnoreInputEvents() const;
380 // Event queries delegated to the |input_router_|.
381 bool ShouldForwardTouchEvent() const;
383 bool has_touch_handler() const { return has_touch_handler_
; }
385 // Notification that the user has made some kind of input that could
386 // perform an action. See OnUserGesture for more details.
387 void StartUserGesture();
389 // Set the RenderView background transparency.
390 void SetBackgroundOpaque(bool opaque
);
392 // Notifies the renderer that the next key event is bound to one or more
393 // pre-defined edit commands
394 void SetEditCommandsForNextKeyEvent(
395 const std::vector
<EditCommand
>& commands
);
397 // Gets the accessibility mode.
398 AccessibilityMode
accessibility_mode() const {
399 return accessibility_mode_
;
402 // Adds the given accessibility mode to the current accessibility mode bitmap.
403 void AddAccessibilityMode(AccessibilityMode mode
);
405 // Removes the given accessibility mode from the current accessibility mode
406 // bitmap, managing the bits that are shared with other modes such that a
407 // bit will only be turned off when all modes that depend on it have been
409 void RemoveAccessibilityMode(AccessibilityMode mode
);
411 // Resets the accessibility mode to the default setting in
412 // BrowserStateAccessibilityImpl.
413 void ResetAccessibilityMode();
416 void SetParentNativeViewAccessible(
417 gfx::NativeViewAccessible accessible_parent
);
418 gfx::NativeViewAccessible
GetParentNativeViewAccessible() const;
421 // Executes the edit command on the RenderView.
422 void ExecuteEditCommand(const std::string
& command
,
423 const std::string
& value
);
425 // Tells the renderer to scroll the currently focused node into rect only if
426 // the currently focused node is a Text node (textfield, text area or content
428 void ScrollFocusedEditableNodeIntoRect(const gfx::Rect
& rect
);
430 // Requests the renderer to move the caret selection towards the point.
431 void MoveCaret(const gfx::Point
& point
);
433 // Called when the reponse to a pending mouse lock request has arrived.
434 // Returns true if |allowed| is true and the mouse has been successfully
436 bool GotResponseToLockMouseRequest(bool allowed
);
438 // Tells the RenderWidget about the latest vsync parameters.
439 // Note: Make sure the timebase was obtained using
440 // base::TimeTicks::HighResNow. Using the non-high res timer will result in
441 // incorrect synchronization across processes.
442 virtual void UpdateVSyncParameters(base::TimeTicks timebase
,
443 base::TimeDelta interval
);
445 // Called by the view in response to AcceleratedSurfaceBuffersSwapped or
446 // AcceleratedSurfacePostSubBuffer.
447 static void AcknowledgeBufferPresent(
450 const AcceleratedSurfaceMsg_BufferPresented_Params
& params
);
452 // Called by the view in response to OnSwapCompositorFrame.
453 static void SendSwapCompositorFrameAck(
455 uint32 output_surface_id
,
456 int renderer_host_id
,
457 const cc::CompositorFrameAck
& ack
);
459 // Called by the view to return resources to the compositor.
460 static void SendReclaimCompositorResources(int32 route_id
,
461 uint32 output_surface_id
,
462 int renderer_host_id
,
463 const cc::CompositorFrameAck
& ack
);
465 void set_allow_privileged_mouse_lock(bool allow
) {
466 allow_privileged_mouse_lock_
= allow
;
469 // Resets state variables related to tracking pending size and painting.
471 // We need to reset these flags when we want to repaint the contents of
472 // browser plugin in this RWH. Resetting these flags will ensure we ignore
473 // any previous pending acks that are not relevant upon repaint.
474 void ResetSizeAndRepaintPendingFlags();
476 void DetachDelegate();
478 // Update the renderer's cache of the screen rect of the view and window.
479 void SendScreenRects();
481 // Suppreses future char events until a keydown. See
482 // suppress_next_char_events_.
483 void SuppressNextCharEvents();
485 // Called by RenderWidgetHostView in response to OnSetNeedsFlushInput.
489 virtual void SetNeedsFlush() OVERRIDE
;
491 // Indicates whether the renderer drives the RenderWidgetHosts's size or the
493 bool should_auto_resize() { return should_auto_resize_
; }
495 void ComputeTouchLatency(const ui::LatencyInfo
& latency_info
);
496 void FrameSwapped(const ui::LatencyInfo
& latency_info
);
497 void DidReceiveRendererFrame();
499 // Returns the ID that uniquely describes this component to the latency
501 int64
GetLatencyComponentId();
503 static void CompositorFrameDrawn(
504 const std::vector
<ui::LatencyInfo
>& latency_info
);
506 // Don't check whether we expected a resize ack during layout tests.
507 static void DisableResizeAckCheckForTesting();
509 void WindowSnapshotAsyncCallback(
512 gfx::Size snapshot_size
,
513 scoped_refptr
<base::RefCountedBytes
> png_data
);
515 // LatencyComponents generated in the renderer must have component IDs
516 // provided to them by the browser process. This function adds the correct
517 // component ID where necessary.
518 void AddLatencyInfoComponentIds(ui::LatencyInfo
* latency_info
);
520 InputRouter
* input_router() { return input_router_
.get(); }
523 virtual RenderWidgetHostImpl
* AsRenderWidgetHostImpl() OVERRIDE
;
525 // Create a LatencyInfo struct with INPUT_EVENT_LATENCY_RWH_COMPONENT
526 // component if it is not already in |original|. And if |original| is
527 // not NULL, it is also merged into the resulting LatencyInfo.
528 ui::LatencyInfo
CreateRWHLatencyInfoIfNotExist(
529 const ui::LatencyInfo
* original
, blink::WebInputEvent::Type type
);
531 // Called when we receive a notification indicating that the renderer
532 // process has gone. This will reset our state so that our state will be
533 // consistent if a new renderer is created.
534 void RendererExited(base::TerminationStatus status
, int exit_code
);
536 // Retrieves an id the renderer can use to refer to its view.
537 // This is used for various IPC messages, including plugins.
538 gfx::NativeViewId
GetNativeViewId() const;
540 // Retrieves an id for the surface that the renderer can draw to
541 // when accelerated compositing is enabled.
542 gfx::GLSurfaceHandle
GetCompositingSurface();
544 // ---------------------------------------------------------------------------
545 // The following methods are overridden by RenderViewHost to send upwards to
548 // Called when a mousewheel event was not processed by the renderer.
549 virtual void UnhandledWheelEvent(const blink::WebMouseWheelEvent
& event
) {}
551 // Notification that the user has made some kind of input that could
552 // perform an action. The gestures that count are 1) any mouse down
553 // event and 2) enter or space key presses.
554 virtual void OnUserGesture() {}
556 // Callbacks for notification when the renderer becomes unresponsive to user
557 // input events, and subsequently responsive again.
558 virtual void NotifyRendererUnresponsive() {}
559 virtual void NotifyRendererResponsive() {}
561 // Called when auto-resize resulted in the renderer size changing.
562 virtual void OnRenderAutoResized(const gfx::Size
& new_size
) {}
564 // ---------------------------------------------------------------------------
566 // RenderViewHost overrides this method to impose further restrictions on when
567 // to allow mouse lock.
568 // Once the request is approved or rejected, GotResponseToLockMouseRequest()
570 virtual void RequestToLockMouse(bool user_gesture
,
571 bool last_unlocked_by_target
);
573 void RejectMouseLockOrUnlockIfNecessary();
574 bool IsMouseLocked() const;
576 // RenderViewHost overrides this method to report when in fullscreen mode.
577 virtual bool IsFullscreen() const;
579 // Indicates if the render widget host should track the render widget's size
580 // as opposed to visa versa.
581 void SetShouldAutoResize(bool enable
);
583 // Expose increment/decrement of the in-flight event count, so
584 // RenderViewHostImpl can account for in-flight beforeunload/unload events.
585 int increment_in_flight_event_count() { return ++in_flight_event_count_
; }
586 int decrement_in_flight_event_count() { return --in_flight_event_count_
; }
588 // The View associated with the RenderViewHost. The lifetime of this object
589 // is associated with the lifetime of the Render process. If the Renderer
590 // crashes, its View is destroyed and this pointer becomes NULL, even though
591 // render_view_host_ lives on to load another URL (creating a new View while
593 RenderWidgetHostViewBase
* view_
;
595 // true if a renderer has once been valid. We use this flag to display a sad
596 // tab only when we lose our renderer and not if a paint occurs during
598 bool renderer_initialized_
;
600 // This value indicates how long to wait before we consider a renderer hung.
601 int hung_renderer_delay_ms_
;
604 friend class MockRenderWidgetHost
;
606 // Tell this object to destroy itself.
609 // Called by |hang_timeout_monitor_| on delayed response from the renderer.
610 void RendererIsUnresponsive();
612 // Called if we know the renderer is responsive. When we currently think the
613 // renderer is unresponsive, this will clear that state and call
614 // NotifyRendererResponsive.
615 void RendererIsResponsive();
617 // IPC message handlers
618 void OnRenderViewReady();
619 void OnRenderProcessGone(int status
, int error_code
);
621 void OnUpdateScreenRectsAck();
622 void OnRequestMove(const gfx::Rect
& pos
);
623 void OnSetTooltipText(const base::string16
& tooltip_text
,
624 blink::WebTextDirection text_direction_hint
);
625 #if defined(OS_MACOSX)
626 void OnCompositorSurfaceBuffersSwapped(
627 const ViewHostMsg_CompositorSurfaceBuffersSwapped_Params
& params
);
629 bool OnSwapCompositorFrame(const IPC::Message
& message
);
630 void OnFlingingStopped();
631 void OnUpdateRect(const ViewHostMsg_UpdateRect_Params
& params
);
632 void OnQueueSyntheticGesture(const SyntheticGesturePacket
& gesture_packet
);
633 virtual void OnFocus();
634 virtual void OnBlur();
635 void OnSetCursor(const WebCursor
& cursor
);
636 void OnSetTouchEventEmulationEnabled(bool enabled
, bool allow_pinch
);
637 void OnTextInputStateChanged(
638 const ViewHostMsg_TextInputState_Params
& params
);
640 #if defined(OS_MACOSX) || defined(USE_AURA)
641 void OnImeCompositionRangeChanged(
642 const gfx::Range
& range
,
643 const std::vector
<gfx::Rect
>& character_bounds
);
645 void OnImeCancelComposition();
646 void OnLockMouse(bool user_gesture
,
647 bool last_unlocked_by_target
,
649 void OnUnlockMouse();
650 void OnShowDisambiguationPopup(const gfx::Rect
& rect
,
651 const gfx::Size
& size
,
652 const cc::SharedBitmapId
& id
);
654 void OnWindowlessPluginDummyWindowCreated(
655 gfx::NativeViewId dummy_activation_window
);
656 void OnWindowlessPluginDummyWindowDestroyed(
657 gfx::NativeViewId dummy_activation_window
);
659 void OnSelectionChanged(const base::string16
& text
,
661 const gfx::Range
& range
);
662 void OnSelectionBoundsChanged(
663 const ViewHostMsg_SelectionBounds_Params
& params
);
664 void OnSnapshot(bool success
, const SkBitmap
& bitmap
);
666 // Called (either immediately or asynchronously) after we're done with our
667 // BackingStore and can send an ACK to the renderer so it can paint onto it
669 void DidUpdateBackingStore(const ViewHostMsg_UpdateRect_Params
& params
,
670 const base::TimeTicks
& paint_start
);
672 // Give key press listeners a chance to handle this key press. This allow
673 // widgets that don't have focus to still handle key presses.
674 bool KeyPressListenersHandleEvent(const NativeWebKeyboardEvent
& event
);
677 virtual InputEventAckState
FilterInputEvent(
678 const blink::WebInputEvent
& event
,
679 const ui::LatencyInfo
& latency_info
) OVERRIDE
;
680 virtual void IncrementInFlightEventCount() OVERRIDE
;
681 virtual void DecrementInFlightEventCount() OVERRIDE
;
682 virtual void OnHasTouchEventHandlers(bool has_handlers
) OVERRIDE
;
683 virtual void DidFlush() OVERRIDE
;
684 virtual void DidOverscroll(const DidOverscrollParams
& params
) OVERRIDE
;
687 virtual void OnKeyboardEventAck(const NativeWebKeyboardEvent
& event
,
688 InputEventAckState ack_result
) OVERRIDE
;
689 virtual void OnWheelEventAck(const MouseWheelEventWithLatencyInfo
& event
,
690 InputEventAckState ack_result
) OVERRIDE
;
691 virtual void OnTouchEventAck(const TouchEventWithLatencyInfo
& event
,
692 InputEventAckState ack_result
) OVERRIDE
;
693 virtual void OnGestureEventAck(const GestureEventWithLatencyInfo
& event
,
694 InputEventAckState ack_result
) OVERRIDE
;
695 virtual void OnUnexpectedEventAck(UnexpectedEventAckType type
) OVERRIDE
;
697 void OnSyntheticGestureCompleted(SyntheticGesture::Result result
);
699 // Called when there is a new auto resize (using a post to avoid a stack
700 // which may get in recursive loops).
701 void DelayedAutoResized();
703 void WindowOldSnapshotReachedScreen(int snapshot_id
);
705 void WindowSnapshotReachedScreen(int snapshot_id
);
707 void OnSnapshotDataReceived(int snapshot_id
,
708 const unsigned char* png
,
711 void OnSnapshotDataReceivedAsync(
713 scoped_refptr
<base::RefCountedBytes
> png_data
);
715 // Send a message to the renderer process to change the accessibility mode.
716 void SetAccessibilityMode(AccessibilityMode AccessibilityMode
);
718 // Our delegate, which wants to know mainly about keyboard events.
719 // It will remain non-NULL until DetachDelegate() is called.
720 RenderWidgetHostDelegate
* delegate_
;
722 // Created during construction but initialized during Init*(). Therefore, it
723 // is guaranteed never to be NULL, but its channel may be NULL if the
724 // renderer crashed, so you must always check that.
725 RenderProcessHost
* process_
;
727 // The ID of the corresponding object in the Renderer Instance.
730 // The ID of the surface corresponding to this render widget.
733 // Indicates whether a page is loading or not.
736 // Indicates whether a page is hidden or not.
739 // Indicates whether a page is fullscreen or not.
742 // Set if we are waiting for a repaint ack for the view.
743 bool repaint_ack_pending_
;
745 // True when waiting for RESIZE_ACK.
746 bool resize_ack_pending_
;
748 // Cached copy of the screen info so that it doesn't need to be updated every
749 // time the window is resized.
750 scoped_ptr
<blink::WebScreenInfo
> screen_info_
;
752 // Set if screen_info_ may have changed and should be recomputed and force a
754 bool screen_info_out_of_date_
;
756 // The current size of the RenderWidget.
757 gfx::Size current_size_
;
759 // The size of the view's backing surface in non-DPI-adjusted pixels.
760 gfx::Size physical_backing_size_
;
762 // The height of the physical backing surface that is overdrawn opaquely in
763 // the browser, for example by an on-screen-keyboard (in DPI-adjusted pixels).
764 float overdraw_bottom_height_
;
766 // The size of the visible viewport, which may be smaller than the view if the
767 // view is partially occluded (e.g. by a virtual keyboard). The size is in
768 // DPI-adjusted pixels.
769 gfx::Size visible_viewport_size_
;
771 // The size we last sent as requested size to the renderer. |current_size_|
772 // is only updated once the resize message has been ack'd. This on the other
773 // hand is updated when the resize message is sent. This is very similar to
774 // |resize_ack_pending_|, but the latter is not set if the new size has width
775 // or height zero, which is why we need this too.
776 gfx::Size last_requested_size_
;
778 // The next auto resize to send.
779 gfx::Size new_auto_size_
;
781 // True if the render widget host should track the render widget's size as
782 // opposed to visa versa.
783 bool should_auto_resize_
;
785 bool waiting_for_screen_rects_ack_
;
786 gfx::Rect last_view_screen_rect_
;
787 gfx::Rect last_window_screen_rect_
;
789 AccessibilityMode accessibility_mode_
;
791 // Keyboard event listeners.
792 std::vector
<KeyPressEventCallback
> key_press_event_callbacks_
;
794 // Mouse event callbacks.
795 std::vector
<MouseEventCallback
> mouse_event_callbacks_
;
797 // If true, then we should repaint when restoring even if we have a
798 // backingstore. This flag is set to true if we receive a paint message
799 // while is_hidden_ to true. Even though we tell the render widget to hide
800 // itself, a paint message could already be in flight at that point.
801 bool needs_repainting_on_restore_
;
803 // This is true if the renderer is currently unresponsive.
804 bool is_unresponsive_
;
806 // The following value indicates a time in the future when we would consider
807 // the renderer hung if it does not generate an appropriate response message.
808 base::Time time_when_considered_hung_
;
810 // This value denotes the number of input events yet to be acknowledged
812 int in_flight_event_count_
;
814 // This timer runs to check if time_when_considered_hung_ has past.
815 base::OneShotTimer
<RenderWidgetHostImpl
> hung_renderer_timer_
;
817 // Flag to detect recursive calls to GetBackingStore().
818 bool in_get_backing_store_
;
820 // Used for UMA histogram logging to measure the time for a repaint view
821 // operation to finish.
822 base::TimeTicks repaint_start_time_
;
824 // Set to true if we shouldn't send input events from the render widget.
825 bool ignore_input_events_
;
827 // Indicates whether IME is active.
828 bool input_method_active_
;
830 // Set when we update the text direction of the selected input element.
831 bool text_direction_updated_
;
832 blink::WebTextDirection text_direction_
;
834 // Set when we cancel updating the text direction.
835 // This flag also ignores succeeding update requests until we call
836 // NotifyTextDirection().
837 bool text_direction_canceled_
;
839 // Indicates if the next sequence of Char events should be suppressed or not.
840 // System may translate a RawKeyDown event into zero or more Char events,
841 // usually we send them to the renderer directly in sequence. However, If a
842 // RawKeyDown event was not handled by the renderer but was handled by
843 // our UnhandledKeyboardEvent() method, e.g. as an accelerator key, then we
844 // shall not send the following sequence of Char events, which was generated
845 // by this RawKeyDown event, to the renderer. Otherwise the renderer may
846 // handle the Char events and cause unexpected behavior.
847 // For example, pressing alt-2 may let the browser switch to the second tab,
848 // but the Char event generated by alt-2 may also activate a HTML element
849 // if its accesskey happens to be "2", then the user may get confused when
850 // switching back to the original tab, because the content may already be
852 bool suppress_next_char_events_
;
854 // The last scroll offset of the render widget.
855 gfx::Vector2d last_scroll_offset_
;
857 bool pending_mouse_lock_request_
;
858 bool allow_privileged_mouse_lock_
;
860 // Keeps track of whether the webpage has any touch event handler. If it does,
861 // then touch events are sent to the renderer. Otherwise, the touch events are
862 // not sent to the renderer.
863 bool has_touch_handler_
;
865 base::WeakPtrFactory
<RenderWidgetHostImpl
> weak_factory_
;
867 scoped_ptr
<SyntheticGestureController
> synthetic_gesture_controller_
;
869 scoped_ptr
<TouchEmulator
> touch_emulator_
;
871 // Receives and handles all input events.
872 scoped_ptr
<InputRouter
> input_router_
;
874 scoped_ptr
<TimeoutMonitor
> hang_monitor_timeout_
;
877 std::list
<HWND
> dummy_windows_for_activation_
;
880 int64 last_input_number_
;
882 int next_browser_snapshot_id_
;
883 typedef std::map
<int,
884 base::Callback
<void(const unsigned char*, size_t)> > PendingSnapshotMap
;
885 PendingSnapshotMap pending_browser_snapshots_
;
887 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostImpl
);
890 } // namespace content
892 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_IMPL_H_