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 int surface_id() const { return surface_id_
; }
181 bool empty() const { return current_size_
.IsEmpty(); }
183 // Called when a renderer object already been created for this host, and we
184 // just need to be attached to it. Used for window.open, <select> dropdown
185 // menus, and other times when the renderer initiates creating an object.
188 // Initializes a RenderWidgetHost that is attached to a RenderFrameHost.
191 // Signal whether this RenderWidgetHost is owned by a RenderFrameHost, in
192 // which case it does not do self-deletion.
193 void set_owned_by_render_frame_host(bool owned_by_rfh
) {
194 owned_by_render_frame_host_
= owned_by_rfh
;
197 // Tells the renderer to die and then calls Destroy().
198 virtual void Shutdown();
201 bool OnMessageReceived(const IPC::Message
& msg
) override
;
203 // Sends a message to the corresponding object in the renderer.
204 bool Send(IPC::Message
* msg
) override
;
206 // Indicates if the page has finished loading.
207 virtual void SetIsLoading(bool is_loading
);
209 // Called to notify the RenderWidget that it has been hidden or restored from
210 // having been hidden.
211 virtual void WasHidden();
212 virtual void WasShown(const ui::LatencyInfo
& latency_info
);
214 // Returns true if the RenderWidget is hidden.
215 bool is_hidden() const { return is_hidden_
; }
217 // Called to notify the RenderWidget that its associated native window
219 virtual void GotFocus();
220 virtual void LostCapture();
222 // Indicates whether the RenderWidgetHost thinks it is focused.
223 // This is different from RenderWidgetHostView::HasFocus() in the sense that
224 // it reflects what the renderer process knows: it saves the state that is
226 // RenderWidgetHostView::HasFocus() is checking whether the view is focused so
227 // it is possible in some edge cases that a view was requested to be focused
228 // but it failed, thus HasFocus() returns false.
229 bool is_focused() const { return is_focused_
; }
231 // Called to notify the RenderWidget that it has lost the mouse lock.
232 virtual void LostMouseLock();
234 // Noifies the RenderWidget of the current mouse cursor visibility state.
235 void SendCursorVisibilityState(bool is_visible
);
237 // Notifies the RenderWidgetHost that the View was destroyed.
238 void ViewDestroyed();
240 #if defined(OS_MACOSX)
241 // Pause for a moment to wait for pending repaint or resize messages sent to
242 // the renderer to arrive. If pending resize messages are for an old window
243 // size, then also pump through a new resize message if there is time.
244 void PauseForPendingResizeOrRepaints();
246 // Whether pausing may be useful.
247 bool CanPauseForPendingResizeOrRepaints();
249 // Wait for a surface matching the size of the widget's view, possibly
250 // blocking until the renderer sends a new frame.
251 void WaitForSurface();
254 bool resize_ack_pending_for_testing() { return resize_ack_pending_
; }
256 // GPU accelerated version of GetBackingStore function. This will
257 // trigger a re-composite to the view. It may fail if a resize is pending, or
258 // if a composite has already been requested and not acked yet.
259 bool ScheduleComposite();
261 // Starts a hang monitor timeout. If there's already a hang monitor timeout
262 // the new one will only fire if it has a shorter delay than the time
263 // left on the existing timeouts.
264 void StartHangMonitorTimeout(base::TimeDelta delay
);
266 // Stops all existing hang monitor timeouts and assumes the renderer is
268 void StopHangMonitorTimeout();
270 // Forwards the given message to the renderer. These are called by the view
271 // when it has received a message.
272 void ForwardGestureEventWithLatencyInfo(
273 const blink::WebGestureEvent
& gesture_event
,
274 const ui::LatencyInfo
& ui_latency
);
275 void ForwardTouchEventWithLatencyInfo(
276 const blink::WebTouchEvent
& touch_event
,
277 const ui::LatencyInfo
& ui_latency
);
278 void ForwardMouseEventWithLatencyInfo(
279 const blink::WebMouseEvent
& mouse_event
,
280 const ui::LatencyInfo
& ui_latency
);
281 void ForwardWheelEventWithLatencyInfo(
282 const blink::WebMouseWheelEvent
& wheel_event
,
283 const ui::LatencyInfo
& ui_latency
);
285 // Enables/disables touch emulation using mouse event. See TouchEmulator.
286 void SetTouchEventEmulationEnabled(
287 bool enabled
, ui::GestureProviderConfigType config_type
);
289 // TouchEmulatorClient implementation.
290 void ForwardGestureEvent(
291 const blink::WebGestureEvent
& gesture_event
) override
;
292 void ForwardEmulatedTouchEvent(
293 const blink::WebTouchEvent
& touch_event
) override
;
294 void SetCursor(const WebCursor
& cursor
) override
;
295 void ShowContextMenuAtPoint(const gfx::Point
& point
) override
;
297 // Queues a synthetic gesture for testing purposes. Invokes the on_complete
298 // callback when the gesture is finished running.
299 void QueueSyntheticGesture(
300 scoped_ptr
<SyntheticGesture
> synthetic_gesture
,
301 const base::Callback
<void(SyntheticGesture::Result
)>& on_complete
);
303 void CancelUpdateTextDirection();
305 // Notifies the renderer whether or not the input method attached to this
306 // process is activated.
307 // When the input method is activated, a renderer process sends IPC messages
308 // to notify the status of its composition node. (This message is mainly used
309 // for notifying the position of the input cursor so that the browser can
310 // display input method windows under the cursor.)
311 void SetInputMethodActive(bool activate
);
313 // Update the composition node of the renderer (or WebKit).
314 // WebKit has a special node (a composition node) for input method to change
315 // its text without affecting any other DOM nodes. When the input method
316 // (attached to the browser) updates its text, the browser sends IPC messages
317 // to update the composition node of the renderer.
318 // (Read the comments of each function for its detail.)
320 // Sets the text of the composition node.
321 // This function can also update the cursor position and mark the specified
322 // range in the composition node.
323 // A browser should call this function:
324 // * when it receives a WM_IME_COMPOSITION message with a GCS_COMPSTR flag
326 // * when it receives a "preedit_changed" signal of GtkIMContext (on Linux);
327 // * when markedText of NSTextInput is called (on Mac).
328 void ImeSetComposition(
329 const base::string16
& text
,
330 const std::vector
<blink::WebCompositionUnderline
>& underlines
,
334 // Finishes an ongoing composition with the specified text.
335 // A browser should call this function:
336 // * when it receives a WM_IME_COMPOSITION message with a GCS_RESULTSTR flag
338 // * when it receives a "commit" signal of GtkIMContext (on Linux);
339 // * when insertText of NSTextInput is called (on Mac).
340 void ImeConfirmComposition(const base::string16
& text
,
341 const gfx::Range
& replacement_range
,
342 bool keep_selection
);
344 // Cancels an ongoing composition.
345 void ImeCancelComposition();
347 // This is for derived classes to give us access to the resizer rect.
348 // And to also expose it to the RenderWidgetHostView.
349 virtual gfx::Rect
GetRootWindowResizerRect() const;
351 bool ignore_input_events() const {
352 return ignore_input_events_
;
355 bool input_method_active() const {
356 return input_method_active_
;
359 // Whether forwarded WebInputEvents should be ignored. True if either
360 // |ignore_input_events_| or |process_->IgnoreInputEvents()| is true.
361 bool IgnoreInputEvents() const;
363 bool has_touch_handler() const { return has_touch_handler_
; }
365 // Notification that the user has made some kind of input that could
366 // perform an action. See OnUserGesture for more details.
367 void StartUserGesture();
369 // Set the RenderView background transparency.
370 void SetBackgroundOpaque(bool opaque
);
372 // Notifies the renderer that the next key event is bound to one or more
373 // pre-defined edit commands
374 void SetEditCommandsForNextKeyEvent(
375 const std::vector
<EditCommand
>& commands
);
377 // Executes the edit command on the RenderView.
378 void ExecuteEditCommand(const std::string
& command
,
379 const std::string
& value
);
381 // Tells the renderer to scroll the currently focused node into rect only if
382 // the currently focused node is a Text node (textfield, text area or content
384 void ScrollFocusedEditableNodeIntoRect(const gfx::Rect
& rect
);
386 // Requests the renderer to move the caret selection towards the point.
387 void MoveCaret(const gfx::Point
& point
);
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
392 bool GotResponseToLockMouseRequest(bool allowed
);
394 // Tells the RenderWidget about the latest vsync parameters.
395 virtual void UpdateVSyncParameters(base::TimeTicks timebase
,
396 base::TimeDelta interval
);
398 // Called by the view in response to OnSwapCompositorFrame.
399 static void SendSwapCompositorFrameAck(
401 uint32 output_surface_id
,
402 int renderer_host_id
,
403 const cc::CompositorFrameAck
& ack
);
405 // Called by the view to return resources to the compositor.
406 static void SendReclaimCompositorResources(int32 route_id
,
407 uint32 output_surface_id
,
408 int renderer_host_id
,
409 const cc::CompositorFrameAck
& ack
);
411 void set_allow_privileged_mouse_lock(bool allow
) {
412 allow_privileged_mouse_lock_
= allow
;
415 // Resets state variables related to tracking pending size and painting.
417 // We need to reset these flags when we want to repaint the contents of
418 // browser plugin in this RWH. Resetting these flags will ensure we ignore
419 // any previous pending acks that are not relevant upon repaint.
420 void ResetSizeAndRepaintPendingFlags();
422 void DetachDelegate();
424 // Update the renderer's cache of the screen rect of the view and window.
425 void SendScreenRects();
427 // Suppreses future char events until a keydown. See
428 // suppress_next_char_events_.
429 void SuppressNextCharEvents();
431 // Called by the view in response to a flush request.
434 // Request a flush signal from the view.
435 void SetNeedsFlush();
437 // Indicates whether the renderer drives the RenderWidgetHosts's size or the
439 bool auto_resize_enabled() { return auto_resize_enabled_
; }
441 // The minimum size of this renderer when auto-resize is enabled.
442 const gfx::Size
& min_size_for_auto_resize() const {
443 return min_size_for_auto_resize_
;
446 // The maximum size of this renderer when auto-resize is enabled.
447 const gfx::Size
& max_size_for_auto_resize() const {
448 return max_size_for_auto_resize_
;
451 void FrameSwapped(const ui::LatencyInfo
& latency_info
);
452 void DidReceiveRendererFrame();
454 // Returns the ID that uniquely describes this component to the latency
456 int64
GetLatencyComponentId() const;
458 base::TimeDelta
GetEstimatedBrowserCompositeTime() const;
460 static void CompositorFrameDrawn(
461 const std::vector
<ui::LatencyInfo
>& latency_info
);
463 // Don't check whether we expected a resize ack during layout tests.
464 static void DisableResizeAckCheckForTesting();
466 InputRouter
* input_router() { return input_router_
.get(); }
468 // Get the BrowserAccessibilityManager for the root of the frame tree,
469 BrowserAccessibilityManager
* GetRootBrowserAccessibilityManager();
471 // Get the BrowserAccessibilityManager for the root of the frame tree,
472 // or create it if it doesn't already exist.
473 BrowserAccessibilityManager
* GetOrCreateRootBrowserAccessibilityManager();
475 void RejectMouseLockOrUnlockIfNecessary();
478 gfx::NativeViewAccessible
GetParentNativeViewAccessible();
481 void set_renderer_initialized(bool renderer_initialized
) {
482 renderer_initialized_
= renderer_initialized
;
486 RenderWidgetHostImpl
* AsRenderWidgetHostImpl() override
;
488 // Called when we receive a notification indicating that the renderer
489 // process has gone. This will reset our state so that our state will be
490 // consistent if a new renderer is created.
491 void RendererExited(base::TerminationStatus status
, int exit_code
);
493 // Retrieves an id the renderer can use to refer to its view.
494 // This is used for various IPC messages, including plugins.
495 gfx::NativeViewId
GetNativeViewId() const;
497 // Retrieves an id for the surface that the renderer can draw to
498 // when accelerated compositing is enabled.
499 gfx::GLSurfaceHandle
GetCompositingSurface();
501 // ---------------------------------------------------------------------------
502 // The following methods are overridden by RenderViewHost to send upwards to
505 // Called when a mousewheel event was not processed by the renderer.
506 virtual void UnhandledWheelEvent(const blink::WebMouseWheelEvent
& event
) {}
508 // Notification that the user has made some kind of input that could
509 // perform an action. The gestures that count are 1) any mouse down
510 // event and 2) enter or space key presses.
511 virtual void OnUserGesture() {}
513 // Callbacks for notification when the renderer becomes unresponsive to user
514 // input events, and subsequently responsive again.
515 virtual void NotifyRendererUnresponsive() {}
516 virtual void NotifyRendererResponsive() {}
518 // Called when auto-resize resulted in the renderer size changing.
519 virtual void OnRenderAutoResized(const gfx::Size
& new_size
) {}
521 // ---------------------------------------------------------------------------
523 // RenderViewHost overrides this method to impose further restrictions on when
524 // to allow mouse lock.
525 // Once the request is approved or rejected, GotResponseToLockMouseRequest()
527 virtual void RequestToLockMouse(bool user_gesture
,
528 bool last_unlocked_by_target
);
530 bool IsMouseLocked() const;
532 // RenderViewHost overrides this method to report whether tab-initiated
533 // fullscreen was granted.
534 virtual bool IsFullscreenGranted() const;
536 virtual blink::WebDisplayMode
GetDisplayMode() const;
538 // Indicates if the render widget host should track the render widget's size
539 // as opposed to visa versa.
540 void SetAutoResize(bool enable
,
541 const gfx::Size
& min_size
,
542 const gfx::Size
& max_size
);
544 // Fills in the |resize_params| struct.
545 // Returns |false| if the update is redundant, |true| otherwise.
546 bool GetResizeParams(ViewMsg_Resize_Params
* resize_params
);
548 // Sets the |resize_params| that were sent to the renderer bundled with the
549 // request to create a new RenderWidget.
550 void SetInitialRenderSizeParams(const ViewMsg_Resize_Params
& resize_params
);
552 // Expose increment/decrement of the in-flight event count, so
553 // RenderViewHostImpl can account for in-flight beforeunload/unload events.
554 int increment_in_flight_event_count() { return ++in_flight_event_count_
; }
555 int decrement_in_flight_event_count() {
556 DCHECK_GT(in_flight_event_count_
, 0);
557 return --in_flight_event_count_
;
560 bool renderer_initialized() const { return renderer_initialized_
; }
562 // The View associated with the RenderViewHost. The lifetime of this object
563 // is associated with the lifetime of the Render process. If the Renderer
564 // crashes, its View is destroyed and this pointer becomes NULL, even though
565 // render_view_host_ lives on to load another URL (creating a new View while
567 RenderWidgetHostViewBase
* view_
;
569 // A weak pointer to the view. The above pointer should be weak, but changing
570 // that to be weak causes crashes on Android.
571 // TODO(ccameron): Fix this.
572 // http://crbug.com/404828
573 base::WeakPtr
<RenderWidgetHostViewBase
> view_weak_
;
575 // This value indicates how long to wait before we consider a renderer hung.
576 base::TimeDelta hung_renderer_delay_
;
579 friend class MockRenderWidgetHost
;
581 // Tell this object to destroy itself.
584 // Called by |hang_monitor_timeout_| on delayed response from the renderer.
585 void RendererIsUnresponsive();
587 // Called if we know the renderer is responsive. When we currently think the
588 // renderer is unresponsive, this will clear that state and call
589 // NotifyRendererResponsive.
590 void RendererIsResponsive();
592 // IPC message handlers
593 void OnRenderViewReady();
594 void OnRenderProcessGone(int status
, int error_code
);
596 void OnUpdateScreenRectsAck();
597 void OnRequestMove(const gfx::Rect
& pos
);
598 void OnSetTooltipText(const base::string16
& tooltip_text
,
599 blink::WebTextDirection text_direction_hint
);
600 bool OnSwapCompositorFrame(const IPC::Message
& message
);
601 void OnUpdateRect(const ViewHostMsg_UpdateRect_Params
& params
);
602 void OnQueueSyntheticGesture(const SyntheticGesturePacket
& gesture_packet
);
603 virtual void OnFocus();
604 virtual void OnBlur();
605 void OnSetCursor(const WebCursor
& cursor
);
606 void OnTextInputTypeChanged(ui::TextInputType type
,
607 ui::TextInputMode input_mode
,
608 bool can_compose_inline
,
611 void OnImeCompositionRangeChanged(
612 const gfx::Range
& range
,
613 const std::vector
<gfx::Rect
>& character_bounds
);
614 void OnImeCancelComposition();
615 void OnLockMouse(bool user_gesture
,
616 bool last_unlocked_by_target
,
618 void OnUnlockMouse();
619 void OnShowDisambiguationPopup(const gfx::Rect
& rect_pixels
,
620 const gfx::Size
& size
,
621 const cc::SharedBitmapId
& id
);
623 void OnWindowlessPluginDummyWindowCreated(
624 gfx::NativeViewId dummy_activation_window
);
625 void OnWindowlessPluginDummyWindowDestroyed(
626 gfx::NativeViewId dummy_activation_window
);
628 void OnSelectionChanged(const base::string16
& text
,
630 const gfx::Range
& range
);
631 void OnSelectionBoundsChanged(
632 const ViewHostMsg_SelectionBounds_Params
& params
);
633 void OnSnapshot(bool success
, const SkBitmap
& bitmap
);
635 // Called (either immediately or asynchronously) after we're done with our
636 // BackingStore and can send an ACK to the renderer so it can paint onto it
638 void DidUpdateBackingStore(const ViewHostMsg_UpdateRect_Params
& params
,
639 const base::TimeTicks
& paint_start
);
641 // Give key press listeners a chance to handle this key press. This allow
642 // widgets that don't have focus to still handle key presses.
643 bool KeyPressListenersHandleEvent(const NativeWebKeyboardEvent
& event
);
646 InputEventAckState
FilterInputEvent(
647 const blink::WebInputEvent
& event
,
648 const ui::LatencyInfo
& latency_info
) override
;
649 void IncrementInFlightEventCount() override
;
650 void DecrementInFlightEventCount() override
;
651 void OnHasTouchEventHandlers(bool has_handlers
) override
;
652 void DidFlush() override
;
653 void DidOverscroll(const DidOverscrollParams
& params
) override
;
654 void DidStopFlinging() override
;
657 void OnKeyboardEventAck(const NativeWebKeyboardEvent
& event
,
658 InputEventAckState ack_result
) override
;
659 void OnWheelEventAck(const MouseWheelEventWithLatencyInfo
& event
,
660 InputEventAckState ack_result
) override
;
661 void OnTouchEventAck(const TouchEventWithLatencyInfo
& event
,
662 InputEventAckState ack_result
) override
;
663 void OnGestureEventAck(const GestureEventWithLatencyInfo
& event
,
664 InputEventAckState ack_result
) override
;
665 void OnUnexpectedEventAck(UnexpectedEventAckType type
) override
;
667 void OnSyntheticGestureCompleted(SyntheticGesture::Result result
);
669 // Called when there is a new auto resize (using a post to avoid a stack
670 // which may get in recursive loops).
671 void DelayedAutoResized();
673 void WindowSnapshotReachedScreen(int snapshot_id
);
675 void OnSnapshotDataReceived(int snapshot_id
,
676 const unsigned char* png
,
679 void OnSnapshotDataReceivedAsync(
681 scoped_refptr
<base::RefCountedBytes
> png_data
);
683 // true if a renderer has once been valid. We use this flag to display a sad
684 // tab only when we lose our renderer and not if a paint occurs during
686 bool renderer_initialized_
;
688 // Our delegate, which wants to know mainly about keyboard events.
689 // It will remain non-NULL until DetachDelegate() is called.
690 RenderWidgetHostDelegate
* delegate_
;
692 // Created during construction but initialized during Init*(). Therefore, it
693 // is guaranteed never to be NULL, but its channel may be NULL if the
694 // renderer crashed, so you must always check that.
695 RenderProcessHost
* process_
;
697 // The ID of the corresponding object in the Renderer Instance.
700 // The ID of the surface corresponding to this render widget.
703 // Indicates whether a page is loading or not.
706 // Indicates whether a page is hidden or not. It has to stay in sync with the
707 // most recent call to process_->WidgetRestored() / WidgetHidden().
710 // Set if we are waiting for a repaint ack for the view.
711 bool repaint_ack_pending_
;
713 // True when waiting for RESIZE_ACK.
714 bool resize_ack_pending_
;
716 // The current size of the RenderWidget.
717 gfx::Size current_size_
;
719 // Resize information that was previously sent to the renderer.
720 scoped_ptr
<ViewMsg_Resize_Params
> old_resize_params_
;
722 // The next auto resize to send.
723 gfx::Size new_auto_size_
;
725 // True if the render widget host should track the render widget's size as
726 // opposed to visa versa.
727 bool auto_resize_enabled_
;
729 // The minimum size for the render widget if auto-resize is enabled.
730 gfx::Size min_size_for_auto_resize_
;
732 // The maximum size for the render widget if auto-resize is enabled.
733 gfx::Size max_size_for_auto_resize_
;
735 bool waiting_for_screen_rects_ack_
;
736 gfx::Rect last_view_screen_rect_
;
737 gfx::Rect last_window_screen_rect_
;
739 // Keyboard event listeners.
740 std::vector
<KeyPressEventCallback
> key_press_event_callbacks_
;
742 // Mouse event callbacks.
743 std::vector
<MouseEventCallback
> mouse_event_callbacks_
;
745 // If true, then we should repaint when restoring even if we have a
746 // backingstore. This flag is set to true if we receive a paint message
747 // while is_hidden_ to true. Even though we tell the render widget to hide
748 // itself, a paint message could already be in flight at that point.
749 bool needs_repainting_on_restore_
;
751 // This is true if the renderer is currently unresponsive.
752 bool is_unresponsive_
;
754 // This value denotes the number of input events yet to be acknowledged
756 int in_flight_event_count_
;
758 // Flag to detect recursive calls to GetBackingStore().
759 bool in_get_backing_store_
;
761 // Used for UMA histogram logging to measure the time for a repaint view
762 // operation to finish.
763 base::TimeTicks repaint_start_time_
;
765 // Set to true if we shouldn't send input events from the render widget.
766 bool ignore_input_events_
;
768 // Indicates whether IME is active.
769 bool input_method_active_
;
771 // Set when we update the text direction of the selected input element.
772 bool text_direction_updated_
;
773 blink::WebTextDirection text_direction_
;
775 // Set when we cancel updating the text direction.
776 // This flag also ignores succeeding update requests until we call
777 // NotifyTextDirection().
778 bool text_direction_canceled_
;
780 // Indicates if the next sequence of Char events should be suppressed or not.
781 // System may translate a RawKeyDown event into zero or more Char events,
782 // usually we send them to the renderer directly in sequence. However, If a
783 // RawKeyDown event was not handled by the renderer but was handled by
784 // our UnhandledKeyboardEvent() method, e.g. as an accelerator key, then we
785 // shall not send the following sequence of Char events, which was generated
786 // by this RawKeyDown event, to the renderer. Otherwise the renderer may
787 // handle the Char events and cause unexpected behavior.
788 // For example, pressing alt-2 may let the browser switch to the second tab,
789 // but the Char event generated by alt-2 may also activate a HTML element
790 // if its accesskey happens to be "2", then the user may get confused when
791 // switching back to the original tab, because the content may already be
793 bool suppress_next_char_events_
;
795 bool pending_mouse_lock_request_
;
796 bool allow_privileged_mouse_lock_
;
798 // Keeps track of whether the webpage has any touch event handler. If it does,
799 // then touch events are sent to the renderer. Otherwise, the touch events are
800 // not sent to the renderer.
801 bool has_touch_handler_
;
803 scoped_ptr
<SyntheticGestureController
> synthetic_gesture_controller_
;
805 scoped_ptr
<TouchEmulator
> touch_emulator_
;
807 // Receives and handles all input events.
808 scoped_ptr
<InputRouter
> input_router_
;
810 scoped_ptr
<TimeoutMonitor
> hang_monitor_timeout_
;
813 std::list
<HWND
> dummy_windows_for_activation_
;
816 RenderWidgetHostLatencyTracker latency_tracker_
;
818 int next_browser_snapshot_id_
;
819 typedef std::map
<int,
820 base::Callback
<void(const unsigned char*, size_t)> > PendingSnapshotMap
;
821 PendingSnapshotMap pending_browser_snapshots_
;
823 // Indicates whether a RenderFramehost has ownership, in which case this
824 // object does not self destroy.
825 bool owned_by_render_frame_host_
;
827 // Indicates whether this RenderWidgetHost thinks is focused. This is trying
828 // to match what the renderer process knows. It is different from
829 // RenderWidgetHostView::HasFocus in that in that the focus request may fail,
830 // causing HasFocus to return false when is_focused_ is true.
833 base::WeakPtrFactory
<RenderWidgetHostImpl
> weak_factory_
;
835 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostImpl
);
838 } // namespace content
840 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_IMPL_H_