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