Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / content / browser / renderer_host / render_widget_host_impl.h
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_IMPL_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_IMPL_H_
7
8 #include <deque>
9 #include <list>
10 #include <map>
11 #include <queue>
12 #include <string>
13 #include <utility>
14 #include <vector>
15
16 #include "base/callback.h"
17 #include "base/gtest_prod_util.h"
18 #include "base/memory/scoped_ptr.h"
19 #include "base/memory/weak_ptr.h"
20 #include "base/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/synthetic_gesture.h"
31 #include "content/browser/renderer_host/input/touch_emulator_client.h"
32 #include "content/common/input/input_event_ack_state.h"
33 #include "content/common/input/synthetic_gesture_packet.h"
34 #include "content/common/view_message_enums.h"
35 #include "content/public/browser/render_widget_host.h"
36 #include "content/public/common/page_zoom.h"
37 #include "ipc/ipc_listener.h"
38 #include "ui/base/ime/text_input_mode.h"
39 #include "ui/base/ime/text_input_type.h"
40 #include "ui/events/latency_info.h"
41 #include "ui/gfx/native_widget_types.h"
42
43 struct AcceleratedSurfaceMsg_BufferPresented_Params;
44 struct ViewHostMsg_BeginSmoothScroll_Params;
45 struct ViewHostMsg_SelectionBounds_Params;
46 struct ViewHostMsg_TextInputState_Params;
47 struct ViewHostMsg_UpdateRect_Params;
48
49 namespace base {
50 class TimeTicks;
51 }
52
53 namespace cc {
54 class CompositorFrame;
55 class CompositorFrameAck;
56 }
57
58 namespace gfx {
59 class Range;
60 }
61
62 namespace ui {
63 class KeyEvent;
64 }
65
66 namespace blink {
67 class WebInputEvent;
68 class WebMouseEvent;
69 struct WebCompositionUnderline;
70 struct WebScreenInfo;
71 }
72
73 #if defined(OS_ANDROID)
74 namespace blink {
75 class WebLayer;
76 }
77 #endif
78
79 namespace content {
80 class BrowserAccessibilityManager;
81 class InputRouter;
82 class MockRenderWidgetHost;
83 class RenderWidgetHostDelegate;
84 class RenderWidgetHostViewBase;
85 class SyntheticGestureController;
86 class TimeoutMonitor;
87 class TouchEmulator;
88 class WebCursor;
89 struct EditCommand;
90
91 // This implements the RenderWidgetHost interface that is exposed to
92 // embedders of content, and adds things only visible to content.
93 class CONTENT_EXPORT RenderWidgetHostImpl
94     : virtual public RenderWidgetHost,
95       public InputRouterClient,
96       public InputAckHandler,
97       public TouchEmulatorClient,
98       public IPC::Listener {
99  public:
100   // routing_id can be MSG_ROUTING_NONE, in which case the next available
101   // routing id is taken from the RenderProcessHost.
102   // If this object outlives |delegate|, DetachDelegate() must be called when
103   // |delegate| goes away.
104   RenderWidgetHostImpl(RenderWidgetHostDelegate* delegate,
105                        RenderProcessHost* process,
106                        int routing_id,
107                        bool hidden);
108   virtual ~RenderWidgetHostImpl();
109
110   // Similar to RenderWidgetHost::FromID, but returning the Impl object.
111   static RenderWidgetHostImpl* FromID(int32 process_id, int32 routing_id);
112
113   // Returns all RenderWidgetHosts including swapped out ones for
114   // internal use. The public interface
115   // RendgerWidgetHost::GetRenderWidgetHosts only returns active ones.
116   static scoped_ptr<RenderWidgetHostIterator> GetAllRenderWidgetHosts();
117
118   // Use RenderWidgetHostImpl::From(rwh) to downcast a
119   // RenderWidgetHost to a RenderWidgetHostImpl.  Internally, this
120   // uses RenderWidgetHost::AsRenderWidgetHostImpl().
121   static RenderWidgetHostImpl* From(RenderWidgetHost* rwh);
122
123   void set_hung_renderer_delay_ms(const base::TimeDelta& timeout) {
124     hung_renderer_delay_ms_ = timeout.InMilliseconds();
125   }
126
127   // RenderWidgetHost implementation.
128   virtual void UpdateTextDirection(blink::WebTextDirection direction) OVERRIDE;
129   virtual void NotifyTextDirection() OVERRIDE;
130   virtual void Focus() OVERRIDE;
131   virtual void Blur() OVERRIDE;
132   virtual void SetActive(bool active) OVERRIDE;
133   virtual void CopyFromBackingStore(
134       const gfx::Rect& src_rect,
135       const gfx::Size& accelerated_dst_size,
136       const base::Callback<void(bool, const SkBitmap&)>& callback,
137       const SkColorType color_type) OVERRIDE;
138   virtual bool CanCopyFromBackingStore() OVERRIDE;
139 #if defined(OS_ANDROID)
140   virtual void LockBackingStore() OVERRIDE;
141   virtual void UnlockBackingStore() OVERRIDE;
142 #endif
143   virtual void ForwardMouseEvent(
144       const blink::WebMouseEvent& mouse_event) OVERRIDE;
145   virtual void ForwardWheelEvent(
146       const blink::WebMouseWheelEvent& wheel_event) OVERRIDE;
147   virtual void ForwardKeyboardEvent(
148       const NativeWebKeyboardEvent& key_event) OVERRIDE;
149   virtual const gfx::Vector2d& GetLastScrollOffset() const OVERRIDE;
150   virtual RenderProcessHost* GetProcess() const OVERRIDE;
151   virtual int GetRoutingID() const OVERRIDE;
152   virtual RenderWidgetHostView* GetView() const OVERRIDE;
153   virtual bool IsLoading() const OVERRIDE;
154   virtual bool IsRenderView() const OVERRIDE;
155   virtual void ResizeRectChanged(const gfx::Rect& new_rect) OVERRIDE;
156   virtual void RestartHangMonitorTimeout() OVERRIDE;
157   virtual void SetIgnoreInputEvents(bool ignore_input_events) OVERRIDE;
158   virtual void Stop() OVERRIDE;
159   virtual void WasResized() OVERRIDE;
160   virtual void AddKeyPressEventCallback(
161       const KeyPressEventCallback& callback) OVERRIDE;
162   virtual void RemoveKeyPressEventCallback(
163       const KeyPressEventCallback& callback) OVERRIDE;
164   virtual void AddMouseEventCallback(
165       const MouseEventCallback& callback) OVERRIDE;
166   virtual void RemoveMouseEventCallback(
167       const MouseEventCallback& callback) OVERRIDE;
168   virtual void GetWebScreenInfo(blink::WebScreenInfo* result) OVERRIDE;
169
170   virtual SkColorType PreferredReadbackFormat() OVERRIDE;
171
172   // Forces redraw in the renderer and when the update reaches the browser
173   // grabs snapshot from the compositor. Returns PNG-encoded snapshot.
174   void GetSnapshotFromBrowser(
175       const base::Callback<void(const unsigned char*,size_t)> callback);
176
177   const NativeWebKeyboardEvent* GetLastKeyboardEvent() const;
178
179   // Notification that the screen info has changed.
180   void NotifyScreenInfoChanged();
181
182   // Invalidates the cached screen info so that next resize request
183   // will carry the up to date screen info. Unlike
184   // |NotifyScreenInfoChanged|, this doesn't send a message to the renderer.
185   void InvalidateScreenInfo();
186
187   // Sets the View of this RenderWidgetHost.
188   void SetView(RenderWidgetHostViewBase* view);
189
190   int surface_id() const { return surface_id_; }
191
192   bool empty() const { return current_size_.IsEmpty(); }
193
194   // Called when a renderer object already been created for this host, and we
195   // just need to be attached to it. Used for window.open, <select> dropdown
196   // menus, and other times when the renderer initiates creating an object.
197   virtual void Init();
198
199   // Tells the renderer to die and then calls Destroy().
200   virtual void Shutdown();
201
202   // IPC::Listener
203   virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
204
205   // Sends a message to the corresponding object in the renderer.
206   virtual bool Send(IPC::Message* msg) OVERRIDE;
207
208   // Called to notify the RenderWidget that it has been hidden or restored from
209   // having been hidden.
210   void WasHidden();
211   void WasShown(const ui::LatencyInfo& latency_info);
212
213   // Returns true if the RenderWidget is hidden.
214   bool is_hidden() const { return is_hidden_; }
215
216   // Called to notify the RenderWidget that its associated native window
217   // got/lost focused.
218   virtual void GotFocus();
219   virtual void LostCapture();
220
221   // Called to notify the RenderWidget that it has lost the mouse lock.
222   virtual void LostMouseLock();
223
224   // Noifies the RenderWidget of the current mouse cursor visibility state.
225   void SendCursorVisibilityState(bool is_visible);
226
227   // Notifies the RenderWidgetHost that the View was destroyed.
228   void ViewDestroyed();
229
230   // Indicates if the page has finished loading.
231   void SetIsLoading(bool is_loading);
232
233 #if defined(OS_MACOSX)
234   // Pause for a moment to wait for pending repaint or resize messages sent to
235   // the renderer to arrive. If pending resize messages are for an old window
236   // size, then also pump through a new resize message if there is time.
237   void PauseForPendingResizeOrRepaints();
238
239   // Whether pausing may be useful.
240   bool CanPauseForPendingResizeOrRepaints();
241
242   // Wait for a surface matching the size of the widget's view, possibly
243   // blocking until the renderer sends a new frame.
244   void WaitForSurface();
245 #endif
246
247   bool resize_ack_pending_for_testing() { return resize_ack_pending_; }
248
249   // GPU accelerated version of GetBackingStore function. This will
250   // trigger a re-composite to the view. It may fail if a resize is pending, or
251   // if a composite has already been requested and not acked yet.
252   bool ScheduleComposite();
253
254   // Starts a hang monitor timeout. If there's already a hang monitor timeout
255   // the new one will only fire if it has a shorter delay than the time
256   // left on the existing timeouts.
257   void StartHangMonitorTimeout(base::TimeDelta delay);
258
259   // Stops all existing hang monitor timeouts and assumes the renderer is
260   // responsive.
261   void StopHangMonitorTimeout();
262
263   // Forwards the given message to the renderer. These are called by the view
264   // when it has received a message.
265   void ForwardGestureEventWithLatencyInfo(
266       const blink::WebGestureEvent& gesture_event,
267       const ui::LatencyInfo& ui_latency);
268   void ForwardTouchEventWithLatencyInfo(
269       const blink::WebTouchEvent& touch_event,
270       const ui::LatencyInfo& ui_latency);
271   void ForwardMouseEventWithLatencyInfo(
272       const blink::WebMouseEvent& mouse_event,
273       const ui::LatencyInfo& ui_latency);
274   void ForwardWheelEventWithLatencyInfo(
275       const blink::WebMouseWheelEvent& wheel_event,
276       const ui::LatencyInfo& ui_latency);
277
278   // Enables/disables touch emulation using mouse event. See TouchEmulator.
279   void SetTouchEventEmulationEnabled(bool enabled, bool allow_pinch);
280
281   // TouchEmulatorClient implementation.
282   virtual void ForwardGestureEvent(
283       const blink::WebGestureEvent& gesture_event) OVERRIDE;
284   virtual void ForwardEmulatedTouchEvent(
285       const blink::WebTouchEvent& touch_event) OVERRIDE;
286   virtual void SetCursor(const WebCursor& cursor) OVERRIDE;
287   virtual void ShowContextMenuAtPoint(const gfx::Point& point) OVERRIDE;
288
289   // Queues a synthetic gesture for testing purposes.  Invokes the on_complete
290   // callback when the gesture is finished running.
291   void QueueSyntheticGesture(
292       scoped_ptr<SyntheticGesture> synthetic_gesture,
293       const base::Callback<void(SyntheticGesture::Result)>& on_complete);
294
295   void CancelUpdateTextDirection();
296
297   // Called when a mouse click/gesture tap activates the renderer.
298   virtual void OnPointerEventActivate();
299
300   // Notifies the renderer whether or not the input method attached to this
301   // process is activated.
302   // When the input method is activated, a renderer process sends IPC messages
303   // to notify the status of its composition node. (This message is mainly used
304   // for notifying the position of the input cursor so that the browser can
305   // display input method windows under the cursor.)
306   void SetInputMethodActive(bool activate);
307
308   // Notifies the renderer changes of IME candidate window state.
309   void CandidateWindowShown();
310   void CandidateWindowUpdated();
311   void CandidateWindowHidden();
312
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.)
319
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
325   //   (on Windows);
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,
331       int selection_start,
332       int selection_end);
333
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
337   //   (on Windows);
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);
343
344   // Cancels an ongoing composition.
345   void ImeCancelComposition();
346
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;
350
351   bool ignore_input_events() const {
352     return ignore_input_events_;
353   }
354
355   bool input_method_active() const {
356     return input_method_active_;
357   }
358
359   // Whether forwarded WebInputEvents should be ignored.  True if either
360   // |ignore_input_events_| or |process_->IgnoreInputEvents()| is true.
361   bool IgnoreInputEvents() const;
362
363   // Event queries delegated to the |input_router_|.
364   bool ShouldForwardTouchEvent() const;
365
366   bool has_touch_handler() const { return has_touch_handler_; }
367
368   // Notification that the user has made some kind of input that could
369   // perform an action. See OnUserGesture for more details.
370   void StartUserGesture();
371
372   // Set the RenderView background transparency.
373   void SetBackgroundOpaque(bool opaque);
374
375   // Notifies the renderer that the next key event is bound to one or more
376   // pre-defined edit commands
377   void SetEditCommandsForNextKeyEvent(
378       const std::vector<EditCommand>& commands);
379
380   // Executes the edit command on the RenderView.
381   void ExecuteEditCommand(const std::string& command,
382                           const std::string& value);
383
384   // Tells the renderer to scroll the currently focused node into rect only if
385   // the currently focused node is a Text node (textfield, text area or content
386   // editable divs).
387   void ScrollFocusedEditableNodeIntoRect(const gfx::Rect& rect);
388
389   // Requests the renderer to move the caret selection towards the point.
390   void MoveCaret(const gfx::Point& point);
391
392   // Called when the reponse to a pending mouse lock request has arrived.
393   // Returns true if |allowed| is true and the mouse has been successfully
394   // locked.
395   bool GotResponseToLockMouseRequest(bool allowed);
396
397   // Tells the RenderWidget about the latest vsync parameters.
398   // Note: Make sure the timebase was obtained using
399   // base::TimeTicks::HighResNow. Using the non-high res timer will result in
400   // incorrect synchronization across processes.
401   virtual void UpdateVSyncParameters(base::TimeTicks timebase,
402                                      base::TimeDelta interval);
403
404   // Called by the view in response to AcceleratedSurfaceBuffersSwapped or
405   // AcceleratedSurfacePostSubBuffer.
406   static void AcknowledgeBufferPresent(
407       int32 route_id,
408       int gpu_host_id,
409       const AcceleratedSurfaceMsg_BufferPresented_Params& params);
410
411   // Called by the view in response to OnSwapCompositorFrame.
412   static void SendSwapCompositorFrameAck(
413       int32 route_id,
414       uint32 output_surface_id,
415       int renderer_host_id,
416       const cc::CompositorFrameAck& ack);
417
418   // Called by the view to return resources to the compositor.
419   static void SendReclaimCompositorResources(int32 route_id,
420                                              uint32 output_surface_id,
421                                              int renderer_host_id,
422                                              const cc::CompositorFrameAck& ack);
423
424   void set_allow_privileged_mouse_lock(bool allow) {
425     allow_privileged_mouse_lock_ = allow;
426   }
427
428   // Resets state variables related to tracking pending size and painting.
429   //
430   // We need to reset these flags when we want to repaint the contents of
431   // browser plugin in this RWH. Resetting these flags will ensure we ignore
432   // any previous pending acks that are not relevant upon repaint.
433   void ResetSizeAndRepaintPendingFlags();
434
435   void DetachDelegate();
436
437   // Update the renderer's cache of the screen rect of the view and window.
438   void SendScreenRects();
439
440   // Suppreses future char events until a keydown. See
441   // suppress_next_char_events_.
442   void SuppressNextCharEvents();
443
444   // Called by RenderWidgetHostView in response to OnSetNeedsFlushInput.
445   void FlushInput();
446
447   // InputRouterClient
448   virtual void SetNeedsFlush() OVERRIDE;
449
450   // Indicates whether the renderer drives the RenderWidgetHosts's size or the
451   // other way around.
452   bool should_auto_resize() { return should_auto_resize_; }
453
454   void ComputeTouchLatency(const ui::LatencyInfo& latency_info);
455   void FrameSwapped(const ui::LatencyInfo& latency_info);
456   void DidReceiveRendererFrame();
457
458   // Returns the ID that uniquely describes this component to the latency
459   // subsystem.
460   int64 GetLatencyComponentId();
461
462   static void CompositorFrameDrawn(
463       const std::vector<ui::LatencyInfo>& latency_info);
464
465   // Don't check whether we expected a resize ack during layout tests.
466   static void DisableResizeAckCheckForTesting();
467
468   void WindowSnapshotAsyncCallback(
469       int routing_id,
470       int snapshot_id,
471       gfx::Size snapshot_size,
472       scoped_refptr<base::RefCountedBytes> png_data);
473
474   // LatencyComponents generated in the renderer must have component IDs
475   // provided to them by the browser process. This function adds the correct
476   // component ID where necessary.
477   void AddLatencyInfoComponentIds(ui::LatencyInfo* latency_info);
478
479   InputRouter* input_router() { return input_router_.get(); }
480
481   // Get the BrowserAccessibilityManager for the root of the frame tree,
482   BrowserAccessibilityManager* GetRootBrowserAccessibilityManager();
483
484   // Get the BrowserAccessibilityManager for the root of the frame tree,
485   // or create it if it doesn't already exist.
486   BrowserAccessibilityManager* GetOrCreateRootBrowserAccessibilityManager();
487
488 #if defined(OS_WIN)
489   gfx::NativeViewAccessible GetParentNativeViewAccessible();
490 #endif
491
492  protected:
493   virtual RenderWidgetHostImpl* AsRenderWidgetHostImpl() OVERRIDE;
494
495   // Create a LatencyInfo struct with INPUT_EVENT_LATENCY_RWH_COMPONENT
496   // component if it is not already in |original|. And if |original| is
497   // not NULL, it is also merged into the resulting LatencyInfo.
498   ui::LatencyInfo CreateRWHLatencyInfoIfNotExist(
499       const ui::LatencyInfo* original, blink::WebInputEvent::Type type);
500
501   // Called when we receive a notification indicating that the renderer
502   // process has gone. This will reset our state so that our state will be
503   // consistent if a new renderer is created.
504   void RendererExited(base::TerminationStatus status, int exit_code);
505
506   // Retrieves an id the renderer can use to refer to its view.
507   // This is used for various IPC messages, including plugins.
508   gfx::NativeViewId GetNativeViewId() const;
509
510   // Retrieves an id for the surface that the renderer can draw to
511   // when accelerated compositing is enabled.
512   gfx::GLSurfaceHandle GetCompositingSurface();
513
514   // ---------------------------------------------------------------------------
515   // The following methods are overridden by RenderViewHost to send upwards to
516   // its delegate.
517
518   // Called when a mousewheel event was not processed by the renderer.
519   virtual void UnhandledWheelEvent(const blink::WebMouseWheelEvent& event) {}
520
521   // Notification that the user has made some kind of input that could
522   // perform an action. The gestures that count are 1) any mouse down
523   // event and 2) enter or space key presses.
524   virtual void OnUserGesture() {}
525
526   // Callbacks for notification when the renderer becomes unresponsive to user
527   // input events, and subsequently responsive again.
528   virtual void NotifyRendererUnresponsive() {}
529   virtual void NotifyRendererResponsive() {}
530
531   // Called when auto-resize resulted in the renderer size changing.
532   virtual void OnRenderAutoResized(const gfx::Size& new_size) {}
533
534   // ---------------------------------------------------------------------------
535
536   // RenderViewHost overrides this method to impose further restrictions on when
537   // to allow mouse lock.
538   // Once the request is approved or rejected, GotResponseToLockMouseRequest()
539   // will be called.
540   virtual void RequestToLockMouse(bool user_gesture,
541                                   bool last_unlocked_by_target);
542
543   void RejectMouseLockOrUnlockIfNecessary();
544   bool IsMouseLocked() const;
545
546   // RenderViewHost overrides this method to report when in fullscreen mode.
547   virtual bool IsFullscreen() const;
548
549   // Indicates if the render widget host should track the render widget's size
550   // as opposed to visa versa.
551   void SetShouldAutoResize(bool enable);
552
553   // Expose increment/decrement of the in-flight event count, so
554   // RenderViewHostImpl can account for in-flight beforeunload/unload events.
555   int increment_in_flight_event_count() { return ++in_flight_event_count_; }
556   int decrement_in_flight_event_count() { return --in_flight_event_count_; }
557
558   // The View associated with the RenderViewHost. The lifetime of this object
559   // is associated with the lifetime of the Render process. If the Renderer
560   // crashes, its View is destroyed and this pointer becomes NULL, even though
561   // render_view_host_ lives on to load another URL (creating a new View while
562   // doing so).
563   RenderWidgetHostViewBase* view_;
564
565   // true if a renderer has once been valid. We use this flag to display a sad
566   // tab only when we lose our renderer and not if a paint occurs during
567   // initialization.
568   bool renderer_initialized_;
569
570   // This value indicates how long to wait before we consider a renderer hung.
571   int hung_renderer_delay_ms_;
572
573  private:
574   friend class MockRenderWidgetHost;
575
576   // Tell this object to destroy itself.
577   void Destroy();
578
579   // Called by |hang_timeout_monitor_| on delayed response from the renderer.
580   void RendererIsUnresponsive();
581
582   // Called if we know the renderer is responsive. When we currently think the
583   // renderer is unresponsive, this will clear that state and call
584   // NotifyRendererResponsive.
585   void RendererIsResponsive();
586
587   // IPC message handlers
588   void OnRenderViewReady();
589   void OnRenderProcessGone(int status, int error_code);
590   void OnClose();
591   void OnUpdateScreenRectsAck();
592   void OnRequestMove(const gfx::Rect& pos);
593   void OnSetTooltipText(const base::string16& tooltip_text,
594                         blink::WebTextDirection text_direction_hint);
595   bool OnSwapCompositorFrame(const IPC::Message& message);
596   void OnFlingingStopped();
597   void OnUpdateRect(const ViewHostMsg_UpdateRect_Params& params);
598   void OnQueueSyntheticGesture(const SyntheticGesturePacket& gesture_packet);
599   virtual void OnFocus();
600   virtual void OnBlur();
601   void OnSetCursor(const WebCursor& cursor);
602   void OnSetTouchEventEmulationEnabled(bool enabled, bool allow_pinch);
603   void OnTextInputStateChanged(
604       const ViewHostMsg_TextInputState_Params& params);
605
606 #if defined(OS_MACOSX) || defined(USE_AURA)
607   void OnImeCompositionRangeChanged(
608       const gfx::Range& range,
609       const std::vector<gfx::Rect>& character_bounds);
610 #endif
611   void OnImeCancelComposition();
612   void OnLockMouse(bool user_gesture,
613                    bool last_unlocked_by_target,
614                    bool privileged);
615   void OnUnlockMouse();
616   void OnShowDisambiguationPopup(const gfx::Rect& rect,
617                                  const gfx::Size& size,
618                                  const cc::SharedBitmapId& id);
619 #if defined(OS_WIN)
620   void OnWindowlessPluginDummyWindowCreated(
621       gfx::NativeViewId dummy_activation_window);
622   void OnWindowlessPluginDummyWindowDestroyed(
623       gfx::NativeViewId dummy_activation_window);
624 #endif
625   void OnSelectionChanged(const base::string16& text,
626                           size_t offset,
627                           const gfx::Range& range);
628   void OnSelectionBoundsChanged(
629       const ViewHostMsg_SelectionBounds_Params& params);
630   void OnSnapshot(bool success, const SkBitmap& bitmap);
631
632   // Called (either immediately or asynchronously) after we're done with our
633   // BackingStore and can send an ACK to the renderer so it can paint onto it
634   // again.
635   void DidUpdateBackingStore(const ViewHostMsg_UpdateRect_Params& params,
636                              const base::TimeTicks& paint_start);
637
638   // Give key press listeners a chance to handle this key press. This allow
639   // widgets that don't have focus to still handle key presses.
640   bool KeyPressListenersHandleEvent(const NativeWebKeyboardEvent& event);
641
642   // InputRouterClient
643   virtual InputEventAckState FilterInputEvent(
644       const blink::WebInputEvent& event,
645       const ui::LatencyInfo& latency_info) OVERRIDE;
646   virtual void IncrementInFlightEventCount() OVERRIDE;
647   virtual void DecrementInFlightEventCount() OVERRIDE;
648   virtual void OnHasTouchEventHandlers(bool has_handlers) OVERRIDE;
649   virtual void DidFlush() OVERRIDE;
650   virtual void DidOverscroll(const DidOverscrollParams& params) OVERRIDE;
651
652   // InputAckHandler
653   virtual void OnKeyboardEventAck(const NativeWebKeyboardEvent& event,
654                                   InputEventAckState ack_result) OVERRIDE;
655   virtual void OnWheelEventAck(const MouseWheelEventWithLatencyInfo& event,
656                                InputEventAckState ack_result) OVERRIDE;
657   virtual void OnTouchEventAck(const TouchEventWithLatencyInfo& event,
658                                InputEventAckState ack_result) OVERRIDE;
659   virtual void OnGestureEventAck(const GestureEventWithLatencyInfo& event,
660                                  InputEventAckState ack_result) OVERRIDE;
661   virtual void OnUnexpectedEventAck(UnexpectedEventAckType type) OVERRIDE;
662
663   void OnSyntheticGestureCompleted(SyntheticGesture::Result result);
664
665   // Called when there is a new auto resize (using a post to avoid a stack
666   // which may get in recursive loops).
667   void DelayedAutoResized();
668
669   void WindowOldSnapshotReachedScreen(int snapshot_id);
670
671   void WindowSnapshotReachedScreen(int snapshot_id);
672
673   void OnSnapshotDataReceived(int snapshot_id,
674                               const unsigned char* png,
675                               size_t size);
676
677   void OnSnapshotDataReceivedAsync(
678       int snapshot_id,
679       scoped_refptr<base::RefCountedBytes> png_data);
680
681   // Our delegate, which wants to know mainly about keyboard events.
682   // It will remain non-NULL until DetachDelegate() is called.
683   RenderWidgetHostDelegate* delegate_;
684
685   // Created during construction but initialized during Init*(). Therefore, it
686   // is guaranteed never to be NULL, but its channel may be NULL if the
687   // renderer crashed, so you must always check that.
688   RenderProcessHost* process_;
689
690   // The ID of the corresponding object in the Renderer Instance.
691   int routing_id_;
692
693   // The ID of the surface corresponding to this render widget.
694   int surface_id_;
695
696   // Indicates whether a page is loading or not.
697   bool is_loading_;
698
699   // Indicates whether a page is hidden or not. It has to stay in sync with the
700   // most recent call to process_->WidgetRestored() / WidgetHidden().
701   bool is_hidden_;
702
703   // Indicates whether a page is fullscreen or not.
704   bool is_fullscreen_;
705
706   // Set if we are waiting for a repaint ack for the view.
707   bool repaint_ack_pending_;
708
709   // True when waiting for RESIZE_ACK.
710   bool resize_ack_pending_;
711
712   // Cached copy of the screen info so that it doesn't need to be updated every
713   // time the window is resized.
714   scoped_ptr<blink::WebScreenInfo> screen_info_;
715
716   // Set if screen_info_ may have changed and should be recomputed and force a
717   // resize message.
718   bool screen_info_out_of_date_;
719
720   // The current size of the RenderWidget.
721   gfx::Size current_size_;
722
723   // The size of the view's backing surface in non-DPI-adjusted pixels.
724   gfx::Size physical_backing_size_;
725
726   // The height of the physical backing surface that is overdrawn opaquely in
727   // the browser, for example by an on-screen-keyboard (in DPI-adjusted pixels).
728   float overdraw_bottom_height_;
729
730   // The size of the visible viewport, which may be smaller than the view if the
731   // view is partially occluded (e.g. by a virtual keyboard).  The size is in
732   // DPI-adjusted pixels.
733   gfx::Size visible_viewport_size_;
734
735   // The size we last sent as requested size to the renderer. |current_size_|
736   // is only updated once the resize message has been ack'd. This on the other
737   // hand is updated when the resize message is sent. This is very similar to
738   // |resize_ack_pending_|, but the latter is not set if the new size has width
739   // or height zero, which is why we need this too.
740   gfx::Size last_requested_size_;
741
742   // The next auto resize to send.
743   gfx::Size new_auto_size_;
744
745   // True if the render widget host should track the render widget's size as
746   // opposed to visa versa.
747   bool should_auto_resize_;
748
749   bool waiting_for_screen_rects_ack_;
750   gfx::Rect last_view_screen_rect_;
751   gfx::Rect last_window_screen_rect_;
752
753   // Keyboard event listeners.
754   std::vector<KeyPressEventCallback> key_press_event_callbacks_;
755
756   // Mouse event callbacks.
757   std::vector<MouseEventCallback> mouse_event_callbacks_;
758
759   // If true, then we should repaint when restoring even if we have a
760   // backingstore.  This flag is set to true if we receive a paint message
761   // while is_hidden_ to true.  Even though we tell the render widget to hide
762   // itself, a paint message could already be in flight at that point.
763   bool needs_repainting_on_restore_;
764
765   // This is true if the renderer is currently unresponsive.
766   bool is_unresponsive_;
767
768   // The following value indicates a time in the future when we would consider
769   // the renderer hung if it does not generate an appropriate response message.
770   base::Time time_when_considered_hung_;
771
772   // This value denotes the number of input events yet to be acknowledged
773   // by the renderer.
774   int in_flight_event_count_;
775
776   // This timer runs to check if time_when_considered_hung_ has past.
777   base::OneShotTimer<RenderWidgetHostImpl> hung_renderer_timer_;
778
779   // Flag to detect recursive calls to GetBackingStore().
780   bool in_get_backing_store_;
781
782   // Used for UMA histogram logging to measure the time for a repaint view
783   // operation to finish.
784   base::TimeTicks repaint_start_time_;
785
786   // Set to true if we shouldn't send input events from the render widget.
787   bool ignore_input_events_;
788
789   // Indicates whether IME is active.
790   bool input_method_active_;
791
792   // Set when we update the text direction of the selected input element.
793   bool text_direction_updated_;
794   blink::WebTextDirection text_direction_;
795
796   // Set when we cancel updating the text direction.
797   // This flag also ignores succeeding update requests until we call
798   // NotifyTextDirection().
799   bool text_direction_canceled_;
800
801   // Indicates if the next sequence of Char events should be suppressed or not.
802   // System may translate a RawKeyDown event into zero or more Char events,
803   // usually we send them to the renderer directly in sequence. However, If a
804   // RawKeyDown event was not handled by the renderer but was handled by
805   // our UnhandledKeyboardEvent() method, e.g. as an accelerator key, then we
806   // shall not send the following sequence of Char events, which was generated
807   // by this RawKeyDown event, to the renderer. Otherwise the renderer may
808   // handle the Char events and cause unexpected behavior.
809   // For example, pressing alt-2 may let the browser switch to the second tab,
810   // but the Char event generated by alt-2 may also activate a HTML element
811   // if its accesskey happens to be "2", then the user may get confused when
812   // switching back to the original tab, because the content may already be
813   // changed.
814   bool suppress_next_char_events_;
815
816   // The last scroll offset of the render widget.
817   gfx::Vector2d last_scroll_offset_;
818
819   bool pending_mouse_lock_request_;
820   bool allow_privileged_mouse_lock_;
821
822   // Keeps track of whether the webpage has any touch event handler. If it does,
823   // then touch events are sent to the renderer. Otherwise, the touch events are
824   // not sent to the renderer.
825   bool has_touch_handler_;
826
827   base::WeakPtrFactory<RenderWidgetHostImpl> weak_factory_;
828
829   scoped_ptr<SyntheticGestureController> synthetic_gesture_controller_;
830
831   scoped_ptr<TouchEmulator> touch_emulator_;
832
833   // Receives and handles all input events.
834   scoped_ptr<InputRouter> input_router_;
835
836   scoped_ptr<TimeoutMonitor> hang_monitor_timeout_;
837
838 #if defined(OS_WIN)
839   std::list<HWND> dummy_windows_for_activation_;
840 #endif
841
842   int64 last_input_number_;
843
844   int next_browser_snapshot_id_;
845   typedef std::map<int,
846       base::Callback<void(const unsigned char*, size_t)> > PendingSnapshotMap;
847   PendingSnapshotMap pending_browser_snapshots_;
848
849   DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostImpl);
850 };
851
852 }  // namespace content
853
854 #endif  // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_IMPL_H_