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/renderer_host/event_with_latency_info.h"
28 #include "content/browser/renderer_host/input/input_ack_handler.h"
29 #include "content/browser/renderer_host/input/input_router_client.h"
30 #include "content/browser/renderer_host/input/render_widget_host_latency_tracker.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/readback_types.h"
37 #include "content/public/browser/render_widget_host.h"
38 #include "content/public/common/page_zoom.h"
39 #include "ipc/ipc_listener.h"
40 #include "third_party/WebKit/public/platform/WebDisplayMode.h"
41 #include "ui/base/ime/text_input_mode.h"
42 #include "ui/base/ime/text_input_type.h"
43 #include "ui/events/gesture_detection/gesture_provider_config_helper.h"
44 #include "ui/events/latency_info.h"
45 #include "ui/gfx/native_widget_types.h"
47 struct AcceleratedSurfaceMsg_BufferPresented_Params
;
48 struct ViewHostMsg_BeginSmoothScroll_Params
;
49 struct ViewHostMsg_SelectionBounds_Params
;
50 struct ViewHostMsg_TextInputState_Params
;
51 struct ViewHostMsg_UpdateRect_Params
;
52 struct ViewMsg_Resize_Params
;
59 class CompositorFrame
;
60 class CompositorFrameAck
;
74 struct WebCompositionUnderline
;
78 #if defined(OS_ANDROID)
85 class BrowserAccessibilityManager
;
87 class MockRenderWidgetHost
;
88 class RenderWidgetHostDelegate
;
89 class RenderWidgetHostViewBase
;
90 class SyntheticGestureController
;
96 // This implements the RenderWidgetHost interface that is exposed to
97 // embedders of content, and adds things only visible to content.
98 class CONTENT_EXPORT RenderWidgetHostImpl
99 : virtual public RenderWidgetHost
,
100 public InputRouterClient
,
101 public InputAckHandler
,
102 public TouchEmulatorClient
,
103 public IPC::Listener
{
105 // routing_id can be MSG_ROUTING_NONE, in which case the next available
106 // routing id is taken from the RenderProcessHost.
107 // If this object outlives |delegate|, DetachDelegate() must be called when
108 // |delegate| goes away.
109 RenderWidgetHostImpl(RenderWidgetHostDelegate
* delegate
,
110 RenderProcessHost
* process
,
113 ~RenderWidgetHostImpl() override
;
115 // Similar to RenderWidgetHost::FromID, but returning the Impl object.
116 static RenderWidgetHostImpl
* FromID(int32 process_id
, int32 routing_id
);
118 // Returns all RenderWidgetHosts including swapped out ones for
119 // internal use. The public interface
120 // RendgerWidgetHost::GetRenderWidgetHosts only returns active ones.
121 static scoped_ptr
<RenderWidgetHostIterator
> GetAllRenderWidgetHosts();
123 // Use RenderWidgetHostImpl::From(rwh) to downcast a
124 // RenderWidgetHost to a RenderWidgetHostImpl. Internally, this
125 // uses RenderWidgetHost::AsRenderWidgetHostImpl().
126 static RenderWidgetHostImpl
* From(RenderWidgetHost
* rwh
);
128 void set_hung_renderer_delay(const base::TimeDelta
& delay
) {
129 hung_renderer_delay_
= delay
;
132 // RenderWidgetHost implementation.
133 void UpdateTextDirection(blink::WebTextDirection direction
) override
;
134 void NotifyTextDirection() override
;
135 void Focus() override
;
136 void Blur() override
;
137 void SetActive(bool active
) override
;
138 void CopyFromBackingStore(const gfx::Rect
& src_rect
,
139 const gfx::Size
& accelerated_dst_size
,
140 ReadbackRequestCallback
& callback
,
141 const SkColorType preferred_color_type
) override
;
142 bool CanCopyFromBackingStore() override
;
143 #if defined(OS_ANDROID)
144 void LockBackingStore() override
;
145 void UnlockBackingStore() override
;
147 void ForwardMouseEvent(const blink::WebMouseEvent
& mouse_event
) override
;
148 void ForwardWheelEvent(const blink::WebMouseWheelEvent
& wheel_event
) override
;
149 void ForwardKeyboardEvent(const NativeWebKeyboardEvent
& key_event
) override
;
150 RenderProcessHost
* GetProcess() const override
;
151 int GetRoutingID() const override
;
152 RenderWidgetHostView
* GetView() const override
;
153 bool IsLoading() const override
;
154 bool IsRenderView() const override
;
155 void ResizeRectChanged(const gfx::Rect
& new_rect
) override
;
156 void RestartHangMonitorTimeout() override
;
157 void SetIgnoreInputEvents(bool ignore_input_events
) override
;
158 void WasResized() override
;
159 void AddKeyPressEventCallback(const KeyPressEventCallback
& callback
) override
;
160 void RemoveKeyPressEventCallback(
161 const KeyPressEventCallback
& callback
) override
;
162 void AddMouseEventCallback(const MouseEventCallback
& callback
) override
;
163 void RemoveMouseEventCallback(const MouseEventCallback
& callback
) override
;
164 void GetWebScreenInfo(blink::WebScreenInfo
* result
) override
;
166 // Forces redraw in the renderer and when the update reaches the browser
167 // grabs snapshot from the compositor. Returns PNG-encoded snapshot.
168 void GetSnapshotFromBrowser(
169 const base::Callback
<void(const unsigned char*,size_t)> callback
);
171 const NativeWebKeyboardEvent
* GetLastKeyboardEvent() const;
173 // Notification that the screen info has changed.
174 void NotifyScreenInfoChanged();
176 // Sets the View of this RenderWidgetHost.
177 void SetView(RenderWidgetHostViewBase
* view
);
179 RenderWidgetHostDelegate
* delegate() const { return delegate_
; }
181 int surface_id() const { return surface_id_
; }
183 bool empty() const { return current_size_
.IsEmpty(); }
185 // Called when a renderer object already been created for this host, and we
186 // just need to be attached to it. Used for window.open, <select> dropdown
187 // menus, and other times when the renderer initiates creating an object.
190 // Initializes a RenderWidgetHost that is attached to a RenderFrameHost.
193 // Signal whether this RenderWidgetHost is owned by a RenderFrameHost, in
194 // which case it does not do self-deletion.
195 void set_owned_by_render_frame_host(bool owned_by_rfh
) {
196 owned_by_render_frame_host_
= owned_by_rfh
;
199 // Tells the renderer to die and then calls Destroy().
200 virtual void Shutdown();
203 bool OnMessageReceived(const IPC::Message
& msg
) override
;
205 // Sends a message to the corresponding object in the renderer.
206 bool Send(IPC::Message
* msg
) override
;
208 // Indicates if the page has finished loading.
209 virtual void SetIsLoading(bool is_loading
);
211 // Called to notify the RenderWidget that it has been hidden or restored from
212 // having been hidden.
213 virtual void WasHidden();
214 virtual void WasShown(const ui::LatencyInfo
& latency_info
);
216 // Returns true if the RenderWidget is hidden.
217 bool is_hidden() const { return is_hidden_
; }
219 // Called to notify the RenderWidget that its associated native window
221 virtual void GotFocus();
222 virtual void LostCapture();
224 // Indicates whether the RenderWidgetHost thinks it is focused.
225 // This is different from RenderWidgetHostView::HasFocus() in the sense that
226 // it reflects what the renderer process knows: it saves the state that is
228 // RenderWidgetHostView::HasFocus() is checking whether the view is focused so
229 // it is possible in some edge cases that a view was requested to be focused
230 // but it failed, thus HasFocus() returns false.
231 bool is_focused() const { return is_focused_
; }
233 // Called to notify the RenderWidget that it has lost the mouse lock.
234 virtual void LostMouseLock();
236 // Noifies the RenderWidget of the current mouse cursor visibility state.
237 void SendCursorVisibilityState(bool is_visible
);
239 // Notifies the RenderWidgetHost that the View was destroyed.
240 void ViewDestroyed();
242 #if defined(OS_MACOSX)
243 // Pause for a moment to wait for pending repaint or resize messages sent to
244 // the renderer to arrive. If pending resize messages are for an old window
245 // size, then also pump through a new resize message if there is time.
246 void PauseForPendingResizeOrRepaints();
248 // Whether pausing may be useful.
249 bool CanPauseForPendingResizeOrRepaints();
251 // Wait for a surface matching the size of the widget's view, possibly
252 // blocking until the renderer sends a new frame.
253 void WaitForSurface();
256 bool resize_ack_pending_for_testing() { return resize_ack_pending_
; }
258 // GPU accelerated version of GetBackingStore function. This will
259 // trigger a re-composite to the view. It may fail if a resize is pending, or
260 // if a composite has already been requested and not acked yet.
261 bool ScheduleComposite();
263 // Starts a hang monitor timeout. If there's already a hang monitor timeout
264 // the new one will only fire if it has a shorter delay than the time
265 // left on the existing timeouts.
266 void StartHangMonitorTimeout(base::TimeDelta delay
);
268 // Stops all existing hang monitor timeouts and assumes the renderer is
270 void StopHangMonitorTimeout();
272 // Forwards the given message to the renderer. These are called by the view
273 // when it has received a message.
274 void ForwardGestureEventWithLatencyInfo(
275 const blink::WebGestureEvent
& gesture_event
,
276 const ui::LatencyInfo
& ui_latency
);
277 void ForwardTouchEventWithLatencyInfo(
278 const blink::WebTouchEvent
& touch_event
,
279 const ui::LatencyInfo
& ui_latency
);
280 void ForwardMouseEventWithLatencyInfo(
281 const blink::WebMouseEvent
& mouse_event
,
282 const ui::LatencyInfo
& ui_latency
);
283 void ForwardWheelEventWithLatencyInfo(
284 const blink::WebMouseWheelEvent
& wheel_event
,
285 const ui::LatencyInfo
& ui_latency
);
287 // Enables/disables touch emulation using mouse event. See TouchEmulator.
288 void SetTouchEventEmulationEnabled(
289 bool enabled
, ui::GestureProviderConfigType config_type
);
291 // TouchEmulatorClient implementation.
292 void ForwardGestureEvent(
293 const blink::WebGestureEvent
& gesture_event
) override
;
294 void ForwardEmulatedTouchEvent(
295 const blink::WebTouchEvent
& touch_event
) override
;
296 void SetCursor(const WebCursor
& cursor
) override
;
297 void ShowContextMenuAtPoint(const gfx::Point
& point
) override
;
299 // Queues a synthetic gesture for testing purposes. Invokes the on_complete
300 // callback when the gesture is finished running.
301 void QueueSyntheticGesture(
302 scoped_ptr
<SyntheticGesture
> synthetic_gesture
,
303 const base::Callback
<void(SyntheticGesture::Result
)>& on_complete
);
305 void CancelUpdateTextDirection();
307 // Update the composition node of the renderer (or WebKit).
308 // WebKit has a special node (a composition node) for input method to change
309 // its text without affecting any other DOM nodes. When the input method
310 // (attached to the browser) updates its text, the browser sends IPC messages
311 // to update the composition node of the renderer.
312 // (Read the comments of each function for its detail.)
314 // Sets the text of the composition node.
315 // This function can also update the cursor position and mark the specified
316 // range in the composition node.
317 // A browser should call this function:
318 // * when it receives a WM_IME_COMPOSITION message with a GCS_COMPSTR flag
320 // * when it receives a "preedit_changed" signal of GtkIMContext (on Linux);
321 // * when markedText of NSTextInput is called (on Mac).
322 void ImeSetComposition(
323 const base::string16
& text
,
324 const std::vector
<blink::WebCompositionUnderline
>& underlines
,
328 // Finishes an ongoing composition with the specified text.
329 // A browser should call this function:
330 // * when it receives a WM_IME_COMPOSITION message with a GCS_RESULTSTR flag
332 // * when it receives a "commit" signal of GtkIMContext (on Linux);
333 // * when insertText of NSTextInput is called (on Mac).
334 void ImeConfirmComposition(const base::string16
& text
,
335 const gfx::Range
& replacement_range
,
336 bool keep_selection
);
338 // Cancels an ongoing composition.
339 void ImeCancelComposition();
341 // This is for derived classes to give us access to the resizer rect.
342 // And to also expose it to the RenderWidgetHostView.
343 virtual gfx::Rect
GetRootWindowResizerRect() const;
345 bool ignore_input_events() const {
346 return ignore_input_events_
;
349 // Whether forwarded WebInputEvents should be ignored. True if either
350 // |ignore_input_events_| or |process_->IgnoreInputEvents()| is true.
351 bool IgnoreInputEvents() const;
353 bool has_touch_handler() const { return has_touch_handler_
; }
355 // Notification that the user has made some kind of input that could
356 // perform an action. See OnUserGesture for more details.
357 void StartUserGesture();
359 // Set the RenderView background transparency.
360 void SetBackgroundOpaque(bool opaque
);
362 // Notifies the renderer that the next key event is bound to one or more
363 // pre-defined edit commands
364 void SetEditCommandsForNextKeyEvent(
365 const std::vector
<EditCommand
>& commands
);
367 // Executes the edit command on the RenderView.
368 void ExecuteEditCommand(const std::string
& command
,
369 const std::string
& value
);
371 // Tells the renderer to scroll the currently focused node into rect only if
372 // the currently focused node is a Text node (textfield, text area or content
374 void ScrollFocusedEditableNodeIntoRect(const gfx::Rect
& rect
);
376 // Requests the renderer to move the caret selection towards the point.
377 void MoveCaret(const gfx::Point
& point
);
379 // Called when the reponse to a pending mouse lock request has arrived.
380 // Returns true if |allowed| is true and the mouse has been successfully
382 bool GotResponseToLockMouseRequest(bool allowed
);
384 // Tells the RenderWidget about the latest vsync parameters.
385 virtual void UpdateVSyncParameters(base::TimeTicks timebase
,
386 base::TimeDelta interval
);
388 // Called by the view in response to OnSwapCompositorFrame.
389 static void SendSwapCompositorFrameAck(
391 uint32 output_surface_id
,
392 int renderer_host_id
,
393 const cc::CompositorFrameAck
& ack
);
395 // Called by the view to return resources to the compositor.
396 static void SendReclaimCompositorResources(int32 route_id
,
397 uint32 output_surface_id
,
398 int renderer_host_id
,
399 const cc::CompositorFrameAck
& ack
);
401 void set_allow_privileged_mouse_lock(bool allow
) {
402 allow_privileged_mouse_lock_
= allow
;
405 // Resets state variables related to tracking pending size and painting.
407 // We need to reset these flags when we want to repaint the contents of
408 // browser plugin in this RWH. Resetting these flags will ensure we ignore
409 // any previous pending acks that are not relevant upon repaint.
410 void ResetSizeAndRepaintPendingFlags();
412 void DetachDelegate();
414 // Update the renderer's cache of the screen rect of the view and window.
415 void SendScreenRects();
417 // Suppreses future char events until a keydown. See
418 // suppress_next_char_events_.
419 void SuppressNextCharEvents();
421 // Called by the view in response to a flush request.
424 // Request a flush signal from the view.
425 void SetNeedsFlush();
427 // Indicates whether the renderer drives the RenderWidgetHosts's size or the
429 bool auto_resize_enabled() { return auto_resize_enabled_
; }
431 // The minimum size of this renderer when auto-resize is enabled.
432 const gfx::Size
& min_size_for_auto_resize() const {
433 return min_size_for_auto_resize_
;
436 // The maximum size of this renderer when auto-resize is enabled.
437 const gfx::Size
& max_size_for_auto_resize() const {
438 return max_size_for_auto_resize_
;
441 void FrameSwapped(const ui::LatencyInfo
& latency_info
);
442 void DidReceiveRendererFrame();
444 // Returns the ID that uniquely describes this component to the latency
446 int64
GetLatencyComponentId() const;
448 static void CompositorFrameDrawn(
449 const std::vector
<ui::LatencyInfo
>& latency_info
);
451 // Don't check whether we expected a resize ack during layout tests.
452 static void DisableResizeAckCheckForTesting();
454 InputRouter
* input_router() { return input_router_
.get(); }
456 // Get the BrowserAccessibilityManager for the root of the frame tree,
457 BrowserAccessibilityManager
* GetRootBrowserAccessibilityManager();
459 // Get the BrowserAccessibilityManager for the root of the frame tree,
460 // or create it if it doesn't already exist.
461 BrowserAccessibilityManager
* GetOrCreateRootBrowserAccessibilityManager();
463 void RejectMouseLockOrUnlockIfNecessary();
466 gfx::NativeViewAccessible
GetParentNativeViewAccessible();
469 void set_renderer_initialized(bool renderer_initialized
) {
470 renderer_initialized_
= renderer_initialized
;
474 RenderWidgetHostImpl
* AsRenderWidgetHostImpl() override
;
476 // Called when we receive a notification indicating that the renderer
477 // process has gone. This will reset our state so that our state will be
478 // consistent if a new renderer is created.
479 void RendererExited(base::TerminationStatus status
, int exit_code
);
481 // Retrieves an id the renderer can use to refer to its view.
482 // This is used for various IPC messages, including plugins.
483 gfx::NativeViewId
GetNativeViewId() const;
485 // Retrieves an id for the surface that the renderer can draw to
486 // when accelerated compositing is enabled.
487 gfx::GLSurfaceHandle
GetCompositingSurface();
489 // ---------------------------------------------------------------------------
490 // The following methods are overridden by RenderViewHost to send upwards to
493 // Called when a mousewheel event was not processed by the renderer.
494 virtual void UnhandledWheelEvent(const blink::WebMouseWheelEvent
& event
) {}
496 // Notification that the user has made some kind of input that could
497 // perform an action. The gestures that count are 1) any mouse down
498 // event and 2) enter or space key presses.
499 virtual void OnUserGesture() {}
501 // Callbacks for notification when the renderer becomes unresponsive to user
502 // input events, and subsequently responsive again.
503 virtual void NotifyRendererUnresponsive() {}
504 virtual void NotifyRendererResponsive() {}
506 // Called when auto-resize resulted in the renderer size changing.
507 virtual void OnRenderAutoResized(const gfx::Size
& new_size
) {}
509 // ---------------------------------------------------------------------------
511 // RenderViewHost overrides this method to impose further restrictions on when
512 // to allow mouse lock.
513 // Once the request is approved or rejected, GotResponseToLockMouseRequest()
515 virtual void RequestToLockMouse(bool user_gesture
,
516 bool last_unlocked_by_target
);
518 bool IsMouseLocked() const;
520 // RenderViewHost overrides this method to report whether tab-initiated
521 // fullscreen was granted.
522 virtual bool IsFullscreenGranted() const;
524 virtual blink::WebDisplayMode
GetDisplayMode() const;
526 // Indicates if the render widget host should track the render widget's size
527 // as opposed to visa versa.
528 void SetAutoResize(bool enable
,
529 const gfx::Size
& min_size
,
530 const gfx::Size
& max_size
);
532 // Fills in the |resize_params| struct.
533 // Returns |false| if the update is redundant, |true| otherwise.
534 bool GetResizeParams(ViewMsg_Resize_Params
* resize_params
);
536 // Sets the |resize_params| that were sent to the renderer bundled with the
537 // request to create a new RenderWidget.
538 void SetInitialRenderSizeParams(const ViewMsg_Resize_Params
& resize_params
);
540 // Expose increment/decrement of the in-flight event count, so
541 // RenderViewHostImpl can account for in-flight beforeunload/unload events.
542 int increment_in_flight_event_count() { return ++in_flight_event_count_
; }
543 int decrement_in_flight_event_count() {
544 DCHECK_GT(in_flight_event_count_
, 0);
545 return --in_flight_event_count_
;
548 bool renderer_initialized() const { return renderer_initialized_
; }
550 // The View associated with the RenderViewHost. The lifetime of this object
551 // is associated with the lifetime of the Render process. If the Renderer
552 // crashes, its View is destroyed and this pointer becomes NULL, even though
553 // render_view_host_ lives on to load another URL (creating a new View while
555 RenderWidgetHostViewBase
* view_
;
557 // A weak pointer to the view. The above pointer should be weak, but changing
558 // that to be weak causes crashes on Android.
559 // TODO(ccameron): Fix this.
560 // http://crbug.com/404828
561 base::WeakPtr
<RenderWidgetHostViewBase
> view_weak_
;
563 // This value indicates how long to wait before we consider a renderer hung.
564 base::TimeDelta hung_renderer_delay_
;
567 friend class MockRenderWidgetHost
;
569 // Tell this object to destroy itself.
572 // Called by |hang_monitor_timeout_| on delayed response from the renderer.
573 void RendererIsUnresponsive();
575 // Called if we know the renderer is responsive. When we currently think the
576 // renderer is unresponsive, this will clear that state and call
577 // NotifyRendererResponsive.
578 void RendererIsResponsive();
580 // IPC message handlers
581 void OnRenderViewReady();
582 void OnRenderProcessGone(int status
, int error_code
);
584 void OnUpdateScreenRectsAck();
585 void OnRequestMove(const gfx::Rect
& pos
);
586 void OnSetTooltipText(const base::string16
& tooltip_text
,
587 blink::WebTextDirection text_direction_hint
);
588 bool OnSwapCompositorFrame(const IPC::Message
& message
);
589 void OnUpdateRect(const ViewHostMsg_UpdateRect_Params
& params
);
590 void OnQueueSyntheticGesture(const SyntheticGesturePacket
& gesture_packet
);
591 virtual void OnFocus();
592 virtual void OnBlur();
593 void OnSetCursor(const WebCursor
& cursor
);
594 void OnTextInputStateChanged(
595 const ViewHostMsg_TextInputState_Params
& params
);
597 void OnImeCompositionRangeChanged(
598 const gfx::Range
& range
,
599 const std::vector
<gfx::Rect
>& character_bounds
);
600 void OnImeCancelComposition();
601 void OnLockMouse(bool user_gesture
,
602 bool last_unlocked_by_target
,
604 void OnUnlockMouse();
605 void OnShowDisambiguationPopup(const gfx::Rect
& rect_pixels
,
606 const gfx::Size
& size
,
607 const cc::SharedBitmapId
& id
);
609 void OnWindowlessPluginDummyWindowCreated(
610 gfx::NativeViewId dummy_activation_window
);
611 void OnWindowlessPluginDummyWindowDestroyed(
612 gfx::NativeViewId dummy_activation_window
);
614 void OnSelectionChanged(const base::string16
& text
,
616 const gfx::Range
& range
);
617 void OnSelectionBoundsChanged(
618 const ViewHostMsg_SelectionBounds_Params
& params
);
619 void OnSnapshot(bool success
, const SkBitmap
& bitmap
);
621 // Called (either immediately or asynchronously) after we're done with our
622 // BackingStore and can send an ACK to the renderer so it can paint onto it
624 void DidUpdateBackingStore(const ViewHostMsg_UpdateRect_Params
& params
,
625 const base::TimeTicks
& paint_start
);
627 // Give key press listeners a chance to handle this key press. This allow
628 // widgets that don't have focus to still handle key presses.
629 bool KeyPressListenersHandleEvent(const NativeWebKeyboardEvent
& event
);
632 InputEventAckState
FilterInputEvent(
633 const blink::WebInputEvent
& event
,
634 const ui::LatencyInfo
& latency_info
) override
;
635 void IncrementInFlightEventCount() override
;
636 void DecrementInFlightEventCount() override
;
637 void OnHasTouchEventHandlers(bool has_handlers
) override
;
638 void DidFlush() override
;
639 void DidOverscroll(const DidOverscrollParams
& params
) override
;
640 void DidStopFlinging() override
;
643 void OnKeyboardEventAck(const NativeWebKeyboardEventWithLatencyInfo
& event
,
644 InputEventAckState ack_result
) override
;
645 void OnMouseEventAck(const MouseEventWithLatencyInfo
& event
,
646 InputEventAckState ack_result
) override
;
647 void OnWheelEventAck(const MouseWheelEventWithLatencyInfo
& event
,
648 InputEventAckState ack_result
) override
;
649 void OnTouchEventAck(const TouchEventWithLatencyInfo
& event
,
650 InputEventAckState ack_result
) override
;
651 void OnGestureEventAck(const GestureEventWithLatencyInfo
& event
,
652 InputEventAckState ack_result
) override
;
653 void OnUnexpectedEventAck(UnexpectedEventAckType type
) override
;
655 void OnSyntheticGestureCompleted(SyntheticGesture::Result result
);
657 // Called when there is a new auto resize (using a post to avoid a stack
658 // which may get in recursive loops).
659 void DelayedAutoResized();
661 void WindowSnapshotReachedScreen(int snapshot_id
);
663 void OnSnapshotDataReceived(int snapshot_id
,
664 const unsigned char* png
,
667 void OnSnapshotDataReceivedAsync(
669 scoped_refptr
<base::RefCountedBytes
> png_data
);
671 // true if a renderer has once been valid. We use this flag to display a sad
672 // tab only when we lose our renderer and not if a paint occurs during
674 bool renderer_initialized_
;
676 // Our delegate, which wants to know mainly about keyboard events.
677 // It will remain non-NULL until DetachDelegate() is called.
678 RenderWidgetHostDelegate
* delegate_
;
680 // Created during construction but initialized during Init*(). Therefore, it
681 // is guaranteed never to be NULL, but its channel may be NULL if the
682 // renderer crashed, so you must always check that.
683 RenderProcessHost
* process_
;
685 // The ID of the corresponding object in the Renderer Instance.
688 // The ID of the surface corresponding to this render widget.
691 // Indicates whether a page is loading or not.
694 // Indicates whether a page is hidden or not. It has to stay in sync with the
695 // most recent call to process_->WidgetRestored() / WidgetHidden().
698 // Set if we are waiting for a repaint ack for the view.
699 bool repaint_ack_pending_
;
701 // True when waiting for RESIZE_ACK.
702 bool resize_ack_pending_
;
704 // The current size of the RenderWidget.
705 gfx::Size current_size_
;
707 // Resize information that was previously sent to the renderer.
708 scoped_ptr
<ViewMsg_Resize_Params
> old_resize_params_
;
710 // The next auto resize to send.
711 gfx::Size new_auto_size_
;
713 // True if the render widget host should track the render widget's size as
714 // opposed to visa versa.
715 bool auto_resize_enabled_
;
717 // The minimum size for the render widget if auto-resize is enabled.
718 gfx::Size min_size_for_auto_resize_
;
720 // The maximum size for the render widget if auto-resize is enabled.
721 gfx::Size max_size_for_auto_resize_
;
723 bool waiting_for_screen_rects_ack_
;
724 gfx::Rect last_view_screen_rect_
;
725 gfx::Rect last_window_screen_rect_
;
727 // Keyboard event listeners.
728 std::vector
<KeyPressEventCallback
> key_press_event_callbacks_
;
730 // Mouse event callbacks.
731 std::vector
<MouseEventCallback
> mouse_event_callbacks_
;
733 // If true, then we should repaint when restoring even if we have a
734 // backingstore. This flag is set to true if we receive a paint message
735 // while is_hidden_ to true. Even though we tell the render widget to hide
736 // itself, a paint message could already be in flight at that point.
737 bool needs_repainting_on_restore_
;
739 // This is true if the renderer is currently unresponsive.
740 bool is_unresponsive_
;
742 // This value denotes the number of input events yet to be acknowledged
744 int in_flight_event_count_
;
746 // Flag to detect recursive calls to GetBackingStore().
747 bool in_get_backing_store_
;
749 // Used for UMA histogram logging to measure the time for a repaint view
750 // operation to finish.
751 base::TimeTicks repaint_start_time_
;
753 // Set to true if we shouldn't send input events from the render widget.
754 bool ignore_input_events_
;
756 // Set when we update the text direction of the selected input element.
757 bool text_direction_updated_
;
758 blink::WebTextDirection text_direction_
;
760 // Set when we cancel updating the text direction.
761 // This flag also ignores succeeding update requests until we call
762 // NotifyTextDirection().
763 bool text_direction_canceled_
;
765 // Indicates if the next sequence of Char events should be suppressed or not.
766 // System may translate a RawKeyDown event into zero or more Char events,
767 // usually we send them to the renderer directly in sequence. However, If a
768 // RawKeyDown event was not handled by the renderer but was handled by
769 // our UnhandledKeyboardEvent() method, e.g. as an accelerator key, then we
770 // shall not send the following sequence of Char events, which was generated
771 // by this RawKeyDown event, to the renderer. Otherwise the renderer may
772 // handle the Char events and cause unexpected behavior.
773 // For example, pressing alt-2 may let the browser switch to the second tab,
774 // but the Char event generated by alt-2 may also activate a HTML element
775 // if its accesskey happens to be "2", then the user may get confused when
776 // switching back to the original tab, because the content may already be
778 bool suppress_next_char_events_
;
780 bool pending_mouse_lock_request_
;
781 bool allow_privileged_mouse_lock_
;
783 // Keeps track of whether the webpage has any touch event handler. If it does,
784 // then touch events are sent to the renderer. Otherwise, the touch events are
785 // not sent to the renderer.
786 bool has_touch_handler_
;
788 scoped_ptr
<SyntheticGestureController
> synthetic_gesture_controller_
;
790 scoped_ptr
<TouchEmulator
> touch_emulator_
;
792 // Receives and handles all input events.
793 scoped_ptr
<InputRouter
> input_router_
;
795 scoped_ptr
<TimeoutMonitor
> hang_monitor_timeout_
;
798 std::list
<HWND
> dummy_windows_for_activation_
;
801 RenderWidgetHostLatencyTracker latency_tracker_
;
803 int next_browser_snapshot_id_
;
804 typedef std::map
<int,
805 base::Callback
<void(const unsigned char*, size_t)> > PendingSnapshotMap
;
806 PendingSnapshotMap pending_browser_snapshots_
;
808 // Indicates whether a RenderFramehost has ownership, in which case this
809 // object does not self destroy.
810 bool owned_by_render_frame_host_
;
812 // Indicates whether this RenderWidgetHost thinks is focused. This is trying
813 // to match what the renderer process knows. It is different from
814 // RenderWidgetHostView::HasFocus in that in that the focus request may fail,
815 // causing HasFocus to return false when is_focused_ is true.
818 base::WeakPtrFactory
<RenderWidgetHostImpl
> weak_factory_
;
820 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostImpl
);
823 } // namespace content
825 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_IMPL_H_