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