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 SkBitmap::Config& bitmap_config) 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 SkBitmap::Config 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 const NativeWebKeyboardEvent* GetLastKeyboardEvent() const;
197 // Notification that the screen info has changed.
198 void NotifyScreenInfoChanged();
200 // Invalidates the cached screen info so that next resize request
201 // will carry the up to date screen info. Unlike
202 // |NotifyScreenInfoChanged|, this doesn't send a message to the renderer.
203 void InvalidateScreenInfo();
205 // Sets the View of this RenderWidgetHost.
206 void SetView(RenderWidgetHostViewBase* view);
208 int surface_id() const { return surface_id_; }
210 bool empty() const { return current_size_.IsEmpty(); }
212 // Called when a renderer object already been created for this host, and we
213 // just need to be attached to it. Used for window.open, <select> dropdown
214 // menus, and other times when the renderer initiates creating an object.
217 // Tells the renderer to die and then calls Destroy().
218 virtual void Shutdown();
221 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
223 // Sends a message to the corresponding object in the renderer.
224 virtual bool Send(IPC::Message* msg) OVERRIDE;
226 // Called to notify the RenderWidget that it has been hidden or restored from
227 // having been hidden.
231 // Returns true if the RenderWidget is hidden.
232 bool is_hidden() const { return is_hidden_; }
234 // Called to notify the RenderWidget that its associated native window
236 virtual void GotFocus();
237 virtual void LostCapture();
239 // Called to notify the RenderWidget that it has lost the mouse lock.
240 virtual void LostMouseLock();
242 // Noifies the RenderWidget of the current mouse cursor visibility state.
243 void SendCursorVisibilityState(bool is_visible);
245 // Notifies the RenderWidgetHost that the View was destroyed.
246 void ViewDestroyed();
248 // Indicates if the page has finished loading.
249 void SetIsLoading(bool is_loading);
251 // Pause for a moment to wait for pending repaint or resize messages sent to
252 // the renderer to arrive. If pending resize messages are for an old window
253 // size, then also pump through a new resize message if there is time.
254 void PauseForPendingResizeOrRepaints();
256 // Whether pausing may be useful.
257 bool CanPauseForPendingResizeOrRepaints();
259 // Wait for a surface matching the size of the widget's view, possibly
260 // blocking until the renderer sends a new frame.
261 void WaitForSurface();
263 // GPU accelerated version of GetBackingStore function. This will
264 // trigger a re-composite to the view. It may fail if a resize is pending, or
265 // if a composite has already been requested and not acked yet.
266 bool ScheduleComposite();
268 // Starts a hang monitor timeout. If there's already a hang monitor timeout
269 // the new one will only fire if it has a shorter delay than the time
270 // left on the existing timeouts.
271 void StartHangMonitorTimeout(base::TimeDelta delay);
273 // Stops all existing hang monitor timeouts and assumes the renderer is
275 void StopHangMonitorTimeout();
277 // Forwards the given message to the renderer. These are called by the view
278 // when it has received a message.
279 void ForwardGestureEventWithLatencyInfo(
280 const blink::WebGestureEvent& gesture_event,
281 const ui::LatencyInfo& ui_latency);
282 void ForwardTouchEventWithLatencyInfo(
283 const blink::WebTouchEvent& touch_event,
284 const ui::LatencyInfo& ui_latency);
285 void ForwardMouseEventWithLatencyInfo(
286 const blink::WebMouseEvent& mouse_event,
287 const ui::LatencyInfo& ui_latency);
288 void ForwardWheelEventWithLatencyInfo(
289 const blink::WebMouseWheelEvent& wheel_event,
290 const ui::LatencyInfo& ui_latency);
292 // TouchEmulatorClient overrides.
293 virtual void ForwardGestureEvent(
294 const blink::WebGestureEvent& gesture_event) OVERRIDE;
295 virtual void ForwardTouchEvent(
296 const blink::WebTouchEvent& touch_event) OVERRIDE;
297 virtual void SetCursor(const WebCursor& cursor) OVERRIDE;
298 virtual void ShowContextMenuAtPoint(const gfx::Point& point) OVERRIDE;
300 // Queues a synthetic gesture for testing purposes. Invokes the on_complete
301 // callback when the gesture is finished running.
302 void QueueSyntheticGesture(
303 scoped_ptr<SyntheticGesture> synthetic_gesture,
304 const base::Callback<void(SyntheticGesture::Result)>& on_complete);
306 void CancelUpdateTextDirection();
308 // Called when a mouse click/gesture tap activates the renderer.
309 virtual void OnPointerEventActivate();
311 // Notifies the renderer whether or not the input method attached to this
312 // process is activated.
313 // When the input method is activated, a renderer process sends IPC messages
314 // to notify the status of its composition node. (This message is mainly used
315 // for notifying the position of the input cursor so that the browser can
316 // display input method windows under the cursor.)
317 void SetInputMethodActive(bool activate);
319 // Notifies the renderer changes of IME candidate window state.
320 void CandidateWindowShown();
321 void CandidateWindowUpdated();
322 void CandidateWindowHidden();
324 // Update the composition node of the renderer (or WebKit).
325 // WebKit has a special node (a composition node) for input method to change
326 // its text without affecting any other DOM nodes. When the input method
327 // (attached to the browser) updates its text, the browser sends IPC messages
328 // to update the composition node of the renderer.
329 // (Read the comments of each function for its detail.)
331 // Sets the text of the composition node.
332 // This function can also update the cursor position and mark the specified
333 // range in the composition node.
334 // A browser should call this function:
335 // * when it receives a WM_IME_COMPOSITION message with a GCS_COMPSTR flag
337 // * when it receives a "preedit_changed" signal of GtkIMContext (on Linux);
338 // * when markedText of NSTextInput is called (on Mac).
339 void ImeSetComposition(
340 const base::string16& text,
341 const std::vector<blink::WebCompositionUnderline>& underlines,
345 // Finishes an ongoing composition with the specified text.
346 // A browser should call this function:
347 // * when it receives a WM_IME_COMPOSITION message with a GCS_RESULTSTR flag
349 // * when it receives a "commit" signal of GtkIMContext (on Linux);
350 // * when insertText of NSTextInput is called (on Mac).
351 void ImeConfirmComposition(const base::string16& text,
352 const gfx::Range& replacement_range,
353 bool keep_selection);
355 // Cancels an ongoing composition.
356 void ImeCancelComposition();
358 // This is for derived classes to give us access to the resizer rect.
359 // And to also expose it to the RenderWidgetHostView.
360 virtual gfx::Rect GetRootWindowResizerRect() const;
362 bool ignore_input_events() const {
363 return ignore_input_events_;
366 bool input_method_active() const {
367 return input_method_active_;
370 // Whether forwarded WebInputEvents should be ignored. True if either
371 // |ignore_input_events_| or |process_->IgnoreInputEvents()| is true.
372 bool IgnoreInputEvents() const;
374 // Event queries delegated to the |input_router_|.
375 bool ShouldForwardTouchEvent() const;
377 bool has_touch_handler() const { return has_touch_handler_; }
379 // Notification that the user has made some kind of input that could
380 // perform an action. See OnUserGesture for more details.
381 void StartUserGesture();
383 // Set the RenderView background transparency.
384 void SetBackgroundOpaque(bool opaque);
386 // Notifies the renderer that the next key event is bound to one or more
387 // pre-defined edit commands
388 void SetEditCommandsForNextKeyEvent(
389 const std::vector<EditCommand>& commands);
391 // Gets the accessibility mode.
392 AccessibilityMode accessibility_mode() const {
393 return accessibility_mode_;
396 // Adds the given accessibility mode to the current accessibility mode bitmap.
397 void AddAccessibilityMode(AccessibilityMode mode);
399 // Removes the given accessibility mode from the current accessibility mode
400 // bitmap, managing the bits that are shared with other modes such that a
401 // bit will only be turned off when all modes that depend on it have been
403 void RemoveAccessibilityMode(AccessibilityMode mode);
405 // Resets the accessibility mode to the default setting in
406 // BrowserStateAccessibilityImpl.
407 void ResetAccessibilityMode();
410 void SetParentNativeViewAccessible(
411 gfx::NativeViewAccessible accessible_parent);
412 gfx::NativeViewAccessible GetParentNativeViewAccessible() const;
415 // Executes the edit command on the RenderView.
416 void ExecuteEditCommand(const std::string& command,
417 const std::string& value);
419 // Tells the renderer to scroll the currently focused node into rect only if
420 // the currently focused node is a Text node (textfield, text area or content
422 void ScrollFocusedEditableNodeIntoRect(const gfx::Rect& rect);
424 // Requests the renderer to move the caret selection towards the point.
425 void MoveCaret(const gfx::Point& point);
427 // Called when the reponse to a pending mouse lock request has arrived.
428 // Returns true if |allowed| is true and the mouse has been successfully
430 bool GotResponseToLockMouseRequest(bool allowed);
432 // Tells the RenderWidget about the latest vsync parameters.
433 // Note: Make sure the timebase was obtained using
434 // base::TimeTicks::HighResNow. Using the non-high res timer will result in
435 // incorrect synchronization across processes.
436 virtual void UpdateVSyncParameters(base::TimeTicks timebase,
437 base::TimeDelta interval);
439 // Called by the view in response to AcceleratedSurfaceBuffersSwapped or
440 // AcceleratedSurfacePostSubBuffer.
441 static void AcknowledgeBufferPresent(
444 const AcceleratedSurfaceMsg_BufferPresented_Params& params);
446 // Called by the view in response to OnSwapCompositorFrame.
447 static void SendSwapCompositorFrameAck(
449 uint32 output_surface_id,
450 int renderer_host_id,
451 const cc::CompositorFrameAck& ack);
453 // Called by the view to return resources to the compositor.
454 static void SendReclaimCompositorResources(int32 route_id,
455 uint32 output_surface_id,
456 int renderer_host_id,
457 const cc::CompositorFrameAck& ack);
459 void set_allow_privileged_mouse_lock(bool allow) {
460 allow_privileged_mouse_lock_ = allow;
463 // Resets state variables related to tracking pending size and painting.
465 // We need to reset these flags when we want to repaint the contents of
466 // browser plugin in this RWH. Resetting these flags will ensure we ignore
467 // any previous pending acks that are not relevant upon repaint.
468 void ResetSizeAndRepaintPendingFlags();
470 void DetachDelegate();
472 // Update the renderer's cache of the screen rect of the view and window.
473 void SendScreenRects();
475 // Suppreses future char events until a keydown. See
476 // suppress_next_char_events_.
477 void SuppressNextCharEvents();
479 // Called by RenderWidgetHostView in response to OnSetNeedsFlushInput.
483 virtual void SetNeedsFlush() OVERRIDE;
485 // Indicates whether the renderer drives the RenderWidgetHosts's size or the
487 bool should_auto_resize() { return should_auto_resize_; }
489 void ComputeTouchLatency(const ui::LatencyInfo& latency_info);
490 void FrameSwapped(const ui::LatencyInfo& latency_info);
491 void DidReceiveRendererFrame();
493 // Returns the ID that uniquely describes this component to the latency
495 int64 GetLatencyComponentId();
497 static void CompositorFrameDrawn(
498 const std::vector<ui::LatencyInfo>& latency_info);
500 // Don't check whether we expected a resize ack during layout tests.
501 static void DisableResizeAckCheckForTesting();
503 void WindowSnapshotAsyncCallback(
506 gfx::Size snapshot_size,
507 scoped_refptr<base::RefCountedBytes> png_data);
509 // LatencyComponents generated in the renderer must have component IDs
510 // provided to them by the browser process. This function adds the correct
511 // component ID where necessary.
512 void AddLatencyInfoComponentIds(ui::LatencyInfo* latency_info);
514 InputRouter* input_router() { return input_router_.get(); }
517 virtual RenderWidgetHostImpl* AsRenderWidgetHostImpl() OVERRIDE;
519 // Create a LatencyInfo struct with INPUT_EVENT_LATENCY_RWH_COMPONENT
520 // component if it is not already in |original|. And if |original| is
521 // not NULL, it is also merged into the resulting LatencyInfo.
522 ui::LatencyInfo CreateRWHLatencyInfoIfNotExist(
523 const ui::LatencyInfo* original, blink::WebInputEvent::Type type);
525 // Called when we receive a notification indicating that the renderer
526 // process has gone. This will reset our state so that our state will be
527 // consistent if a new renderer is created.
528 void RendererExited(base::TerminationStatus status, int exit_code);
530 // Retrieves an id the renderer can use to refer to its view.
531 // This is used for various IPC messages, including plugins.
532 gfx::NativeViewId GetNativeViewId() const;
534 // Retrieves an id for the surface that the renderer can draw to
535 // when accelerated compositing is enabled.
536 gfx::GLSurfaceHandle GetCompositingSurface();
538 // ---------------------------------------------------------------------------
539 // The following methods are overridden by RenderViewHost to send upwards to
542 // Called when a mousewheel event was not processed by the renderer.
543 virtual void UnhandledWheelEvent(const blink::WebMouseWheelEvent& event) {}
545 // Notification that the user has made some kind of input that could
546 // perform an action. The gestures that count are 1) any mouse down
547 // event and 2) enter or space key presses.
548 virtual void OnUserGesture() {}
550 // Callbacks for notification when the renderer becomes unresponsive to user
551 // input events, and subsequently responsive again.
552 virtual void NotifyRendererUnresponsive() {}
553 virtual void NotifyRendererResponsive() {}
555 // Called when auto-resize resulted in the renderer size changing.
556 virtual void OnRenderAutoResized(const gfx::Size& new_size) {}
558 // ---------------------------------------------------------------------------
560 // RenderViewHost overrides this method to impose further restrictions on when
561 // to allow mouse lock.
562 // Once the request is approved or rejected, GotResponseToLockMouseRequest()
564 virtual void RequestToLockMouse(bool user_gesture,
565 bool last_unlocked_by_target);
567 void RejectMouseLockOrUnlockIfNecessary();
568 bool IsMouseLocked() const;
570 // RenderViewHost overrides this method to report when in fullscreen mode.
571 virtual bool IsFullscreen() const;
573 // Indicates if the render widget host should track the render widget's size
574 // as opposed to visa versa.
575 void SetShouldAutoResize(bool enable);
577 // Expose increment/decrement of the in-flight event count, so
578 // RenderViewHostImpl can account for in-flight beforeunload/unload events.
579 int increment_in_flight_event_count() { return ++in_flight_event_count_; }
580 int decrement_in_flight_event_count() { return --in_flight_event_count_; }
582 // The View associated with the RenderViewHost. The lifetime of this object
583 // is associated with the lifetime of the Render process. If the Renderer
584 // crashes, its View is destroyed and this pointer becomes NULL, even though
585 // render_view_host_ lives on to load another URL (creating a new View while
587 RenderWidgetHostViewBase* view_;
589 // true if a renderer has once been valid. We use this flag to display a sad
590 // tab only when we lose our renderer and not if a paint occurs during
592 bool renderer_initialized_;
594 // This value indicates how long to wait before we consider a renderer hung.
595 int hung_renderer_delay_ms_;
598 friend class MockRenderWidgetHost;
600 // Tell this object to destroy itself.
603 // Called by |hang_timeout_monitor_| on delayed response from the renderer.
604 void RendererIsUnresponsive();
606 // Called if we know the renderer is responsive. When we currently think the
607 // renderer is unresponsive, this will clear that state and call
608 // NotifyRendererResponsive.
609 void RendererIsResponsive();
611 // IPC message handlers
612 void OnRenderViewReady();
613 void OnRenderProcessGone(int status, int error_code);
615 void OnUpdateScreenRectsAck();
616 void OnRequestMove(const gfx::Rect& pos);
617 void OnSetTooltipText(const base::string16& tooltip_text,
618 blink::WebTextDirection text_direction_hint);
619 #if defined(OS_MACOSX)
620 void OnCompositorSurfaceBuffersSwapped(
621 const ViewHostMsg_CompositorSurfaceBuffersSwapped_Params& params);
623 bool OnSwapCompositorFrame(const IPC::Message& message);
624 void OnFlingingStopped();
625 void OnUpdateRect(const ViewHostMsg_UpdateRect_Params& params);
626 void OnQueueSyntheticGesture(const SyntheticGesturePacket& gesture_packet);
627 virtual void OnFocus();
628 virtual void OnBlur();
629 void OnSetCursor(const WebCursor& cursor);
630 void OnSetTouchEventEmulationEnabled(bool enabled, bool allow_pinch);
631 void OnTextInputStateChanged(
632 const ViewHostMsg_TextInputState_Params& params);
634 #if defined(OS_MACOSX) || defined(USE_AURA)
635 void OnImeCompositionRangeChanged(
636 const gfx::Range& range,
637 const std::vector<gfx::Rect>& character_bounds);
639 void OnImeCancelComposition();
640 void OnLockMouse(bool user_gesture,
641 bool last_unlocked_by_target,
643 void OnUnlockMouse();
644 void OnShowDisambiguationPopup(const gfx::Rect& rect,
645 const gfx::Size& size,
646 const cc::SharedBitmapId& id);
648 void OnWindowlessPluginDummyWindowCreated(
649 gfx::NativeViewId dummy_activation_window);
650 void OnWindowlessPluginDummyWindowDestroyed(
651 gfx::NativeViewId dummy_activation_window);
653 void OnSelectionChanged(const base::string16& text,
655 const gfx::Range& range);
656 void OnSelectionBoundsChanged(
657 const ViewHostMsg_SelectionBounds_Params& params);
658 void OnSnapshot(bool success, const SkBitmap& bitmap);
660 // Called (either immediately or asynchronously) after we're done with our
661 // BackingStore and can send an ACK to the renderer so it can paint onto it
663 void DidUpdateBackingStore(const ViewHostMsg_UpdateRect_Params& params,
664 const base::TimeTicks& paint_start);
666 // Give key press listeners a chance to handle this key press. This allow
667 // widgets that don't have focus to still handle key presses.
668 bool KeyPressListenersHandleEvent(const NativeWebKeyboardEvent& event);
671 virtual InputEventAckState FilterInputEvent(
672 const blink::WebInputEvent& event,
673 const ui::LatencyInfo& latency_info) OVERRIDE;
674 virtual void IncrementInFlightEventCount() OVERRIDE;
675 virtual void DecrementInFlightEventCount() OVERRIDE;
676 virtual void OnHasTouchEventHandlers(bool has_handlers) OVERRIDE;
677 virtual void DidFlush() OVERRIDE;
678 virtual void DidOverscroll(const DidOverscrollParams& params) OVERRIDE;
681 virtual void OnKeyboardEventAck(const NativeWebKeyboardEvent& event,
682 InputEventAckState ack_result) OVERRIDE;
683 virtual void OnWheelEventAck(const MouseWheelEventWithLatencyInfo& event,
684 InputEventAckState ack_result) OVERRIDE;
685 virtual void OnTouchEventAck(const TouchEventWithLatencyInfo& event,
686 InputEventAckState ack_result) OVERRIDE;
687 virtual void OnGestureEventAck(const GestureEventWithLatencyInfo& event,
688 InputEventAckState ack_result) OVERRIDE;
689 virtual void OnUnexpectedEventAck(UnexpectedEventAckType type) OVERRIDE;
691 void OnSyntheticGestureCompleted(SyntheticGesture::Result result);
693 // Called when there is a new auto resize (using a post to avoid a stack
694 // which may get in recursive loops).
695 void DelayedAutoResized();
697 void WindowSnapshotReachedScreen(int snapshot_id);
699 // Send a message to the renderer process to change the accessibility mode.
700 void SetAccessibilityMode(AccessibilityMode AccessibilityMode);
702 // Our delegate, which wants to know mainly about keyboard events.
703 // It will remain non-NULL until DetachDelegate() is called.
704 RenderWidgetHostDelegate* delegate_;
706 // Created during construction but initialized during Init*(). Therefore, it
707 // is guaranteed never to be NULL, but its channel may be NULL if the
708 // renderer crashed, so you must always check that.
709 RenderProcessHost* process_;
711 // The ID of the corresponding object in the Renderer Instance.
714 // The ID of the surface corresponding to this render widget.
717 // Indicates whether a page is loading or not.
720 // Indicates whether a page is hidden or not.
723 // Indicates whether a page is fullscreen or not.
726 // Set if we are waiting for a repaint ack for the view.
727 bool repaint_ack_pending_;
729 // True when waiting for RESIZE_ACK.
730 bool resize_ack_pending_;
732 // Cached copy of the screen info so that it doesn't need to be updated every
733 // time the window is resized.
734 scoped_ptr<blink::WebScreenInfo> screen_info_;
736 // Set if screen_info_ may have changed and should be recomputed and force a
738 bool screen_info_out_of_date_;
740 // The current size of the RenderWidget.
741 gfx::Size current_size_;
743 // The size of the view's backing surface in non-DPI-adjusted pixels.
744 gfx::Size physical_backing_size_;
746 // The height of the physical backing surface that is overdrawn opaquely in
747 // the browser, for example by an on-screen-keyboard (in DPI-adjusted pixels).
748 float overdraw_bottom_height_;
750 // The size of the visible viewport, which may be smaller than the view if the
751 // view is partially occluded (e.g. by a virtual keyboard). The size is in
752 // DPI-adjusted pixels.
753 gfx::Size visible_viewport_size_;
755 // The size we last sent as requested size to the renderer. |current_size_|
756 // is only updated once the resize message has been ack'd. This on the other
757 // hand is updated when the resize message is sent. This is very similar to
758 // |resize_ack_pending_|, but the latter is not set if the new size has width
759 // or height zero, which is why we need this too.
760 gfx::Size last_requested_size_;
762 // The next auto resize to send.
763 gfx::Size new_auto_size_;
765 // True if the render widget host should track the render widget's size as
766 // opposed to visa versa.
767 bool should_auto_resize_;
769 bool waiting_for_screen_rects_ack_;
770 gfx::Rect last_view_screen_rect_;
771 gfx::Rect last_window_screen_rect_;
773 AccessibilityMode accessibility_mode_;
775 // Keyboard event listeners.
776 std::vector<KeyPressEventCallback> key_press_event_callbacks_;
778 // Mouse event callbacks.
779 std::vector<MouseEventCallback> mouse_event_callbacks_;
781 // If true, then we should repaint when restoring even if we have a
782 // backingstore. This flag is set to true if we receive a paint message
783 // while is_hidden_ to true. Even though we tell the render widget to hide
784 // itself, a paint message could already be in flight at that point.
785 bool needs_repainting_on_restore_;
787 // This is true if the renderer is currently unresponsive.
788 bool is_unresponsive_;
790 // The following value indicates a time in the future when we would consider
791 // the renderer hung if it does not generate an appropriate response message.
792 base::Time time_when_considered_hung_;
794 // This value denotes the number of input events yet to be acknowledged
796 int in_flight_event_count_;
798 // This timer runs to check if time_when_considered_hung_ has past.
799 base::OneShotTimer<RenderWidgetHostImpl> hung_renderer_timer_;
801 // Flag to detect recursive calls to GetBackingStore().
802 bool in_get_backing_store_;
804 // Used for UMA histogram logging to measure the time for a repaint view
805 // operation to finish.
806 base::TimeTicks repaint_start_time_;
808 // Set to true if we shouldn't send input events from the render widget.
809 bool ignore_input_events_;
811 // Indicates whether IME is active.
812 bool input_method_active_;
814 // Set when we update the text direction of the selected input element.
815 bool text_direction_updated_;
816 blink::WebTextDirection text_direction_;
818 // Set when we cancel updating the text direction.
819 // This flag also ignores succeeding update requests until we call
820 // NotifyTextDirection().
821 bool text_direction_canceled_;
823 // Indicates if the next sequence of Char events should be suppressed or not.
824 // System may translate a RawKeyDown event into zero or more Char events,
825 // usually we send them to the renderer directly in sequence. However, If a
826 // RawKeyDown event was not handled by the renderer but was handled by
827 // our UnhandledKeyboardEvent() method, e.g. as an accelerator key, then we
828 // shall not send the following sequence of Char events, which was generated
829 // by this RawKeyDown event, to the renderer. Otherwise the renderer may
830 // handle the Char events and cause unexpected behavior.
831 // For example, pressing alt-2 may let the browser switch to the second tab,
832 // but the Char event generated by alt-2 may also activate a HTML element
833 // if its accesskey happens to be "2", then the user may get confused when
834 // switching back to the original tab, because the content may already be
836 bool suppress_next_char_events_;
838 // The last scroll offset of the render widget.
839 gfx::Vector2d last_scroll_offset_;
841 bool pending_mouse_lock_request_;
842 bool allow_privileged_mouse_lock_;
844 // Keeps track of whether the webpage has any touch event handler. If it does,
845 // then touch events are sent to the renderer. Otherwise, the touch events are
846 // not sent to the renderer.
847 bool has_touch_handler_;
849 base::WeakPtrFactory<RenderWidgetHostImpl> weak_factory_;
851 scoped_ptr<SyntheticGestureController> synthetic_gesture_controller_;
853 scoped_ptr<TouchEmulator> touch_emulator_;
855 // Receives and handles all input events.
856 scoped_ptr<InputRouter> input_router_;
858 scoped_ptr<TimeoutMonitor> hang_monitor_timeout_;
861 std::list<HWND> dummy_windows_for_activation_;
864 int64 last_input_number_;
866 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostImpl);
869 } // namespace content
871 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_IMPL_H_