cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / content / browser / renderer_host / render_widget_host_impl.h
blob56ef44edfc80fe2b97256b5e65869543e0c92356
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 <list>
9 #include <map>
10 #include <string>
11 #include <utility>
12 #include <vector>
14 #include "base/callback.h"
15 #include "base/gtest_prod_util.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "base/memory/weak_ptr.h"
18 #include "base/observer_list.h"
19 #include "base/process/kill.h"
20 #include "base/strings/string16.h"
21 #include "base/time/time.h"
22 #include "base/timer/timer.h"
23 #include "build/build_config.h"
24 #include "cc/resources/shared_bitmap.h"
25 #include "content/browser/renderer_host/event_with_latency_info.h"
26 #include "content/browser/renderer_host/input/input_ack_handler.h"
27 #include "content/browser/renderer_host/input/input_router_client.h"
28 #include "content/browser/renderer_host/input/render_widget_host_latency_tracker.h"
29 #include "content/browser/renderer_host/input/synthetic_gesture.h"
30 #include "content/browser/renderer_host/input/touch_emulator_client.h"
31 #include "content/common/input/input_event_ack_state.h"
32 #include "content/common/input/synthetic_gesture_packet.h"
33 #include "content/common/view_message_enums.h"
34 #include "content/public/browser/readback_types.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 "third_party/WebKit/public/platform/WebDisplayMode.h"
39 #include "ui/base/ime/text_input_mode.h"
40 #include "ui/base/ime/text_input_type.h"
41 #include "ui/events/gesture_detection/gesture_provider_config_helper.h"
42 #include "ui/events/latency_info.h"
43 #include "ui/gfx/native_widget_types.h"
45 struct ViewHostMsg_SelectionBounds_Params;
46 struct ViewHostMsg_TextInputState_Params;
47 struct ViewHostMsg_UpdateRect_Params;
48 struct ViewMsg_Resize_Params;
50 namespace blink {
51 class WebInputEvent;
52 #if defined(OS_ANDROID)
53 class WebLayer;
54 #endif
55 class WebMouseEvent;
56 struct WebCompositionUnderline;
57 struct WebScreenInfo;
61 namespace cc {
62 class CompositorFrameAck;
65 namespace gfx {
66 class Range;
69 namespace content {
71 class BrowserAccessibilityManager;
72 class InputRouter;
73 class MockRenderWidgetHost;
74 class RenderWidgetHostDelegate;
75 class RenderWidgetHostViewBase;
76 class SyntheticGestureController;
77 class TimeoutMonitor;
78 class TouchEmulator;
79 class WebCursor;
80 struct EditCommand;
82 // This implements the RenderWidgetHost interface that is exposed to
83 // embedders of content, and adds things only visible to content.
84 class CONTENT_EXPORT RenderWidgetHostImpl
85 : virtual public RenderWidgetHost,
86 public InputRouterClient,
87 public InputAckHandler,
88 public TouchEmulatorClient,
89 public IPC::Listener {
90 public:
91 // routing_id can be MSG_ROUTING_NONE, in which case the next available
92 // routing id is taken from the RenderProcessHost.
93 // If this object outlives |delegate|, DetachDelegate() must be called when
94 // |delegate| goes away.
95 RenderWidgetHostImpl(RenderWidgetHostDelegate* delegate,
96 RenderProcessHost* process,
97 int32_t routing_id,
98 int32_t surface_id,
99 bool hidden);
100 ~RenderWidgetHostImpl() override;
102 // Similar to RenderWidgetHost::FromID, but returning the Impl object.
103 static RenderWidgetHostImpl* FromID(int32_t process_id, int32_t routing_id);
105 // Returns all RenderWidgetHosts including swapped out ones for
106 // internal use. The public interface
107 // RendgerWidgetHost::GetRenderWidgetHosts only returns active ones.
108 static scoped_ptr<RenderWidgetHostIterator> GetAllRenderWidgetHosts();
110 // Use RenderWidgetHostImpl::From(rwh) to downcast a
111 // RenderWidgetHost to a RenderWidgetHostImpl. Internally, this
112 // uses RenderWidgetHost::AsRenderWidgetHostImpl().
113 static RenderWidgetHostImpl* From(RenderWidgetHost* rwh);
115 void set_hung_renderer_delay(const base::TimeDelta& delay) {
116 hung_renderer_delay_ = delay;
119 // RenderWidgetHost implementation.
120 void UpdateTextDirection(blink::WebTextDirection direction) override;
121 void NotifyTextDirection() override;
122 void Focus() override;
123 void Blur() override;
124 void SetActive(bool active) override;
125 void CopyFromBackingStore(const gfx::Rect& src_rect,
126 const gfx::Size& accelerated_dst_size,
127 ReadbackRequestCallback& callback,
128 const SkColorType preferred_color_type) override;
129 bool CanCopyFromBackingStore() override;
130 #if defined(OS_ANDROID)
131 void LockBackingStore() override;
132 void UnlockBackingStore() override;
133 #endif
134 void ForwardMouseEvent(const blink::WebMouseEvent& mouse_event) override;
135 void ForwardWheelEvent(const blink::WebMouseWheelEvent& wheel_event) override;
136 void ForwardKeyboardEvent(const NativeWebKeyboardEvent& key_event) override;
137 RenderProcessHost* GetProcess() const override;
138 int GetRoutingID() const override;
139 RenderWidgetHostView* GetView() const override;
140 bool IsLoading() const override;
141 bool IsRenderView() const override;
142 void ResizeRectChanged(const gfx::Rect& new_rect) override;
143 void RestartHangMonitorTimeout() override;
144 void SetIgnoreInputEvents(bool ignore_input_events) override;
145 void WasResized() override;
146 void AddKeyPressEventCallback(const KeyPressEventCallback& callback) override;
147 void RemoveKeyPressEventCallback(
148 const KeyPressEventCallback& callback) override;
149 void AddMouseEventCallback(const MouseEventCallback& callback) override;
150 void RemoveMouseEventCallback(const MouseEventCallback& callback) override;
151 void GetWebScreenInfo(blink::WebScreenInfo* result) override;
152 bool GetScreenColorProfile(std::vector<char>* color_profile) override;
154 // Notification that the screen info has changed.
155 void NotifyScreenInfoChanged();
157 // Forces redraw in the renderer and when the update reaches the browser
158 // grabs snapshot from the compositor. Returns PNG-encoded snapshot.
159 using GetSnapshotFromBrowserCallback =
160 base::Callback<void(const unsigned char*, size_t)>;
161 void GetSnapshotFromBrowser(const GetSnapshotFromBrowserCallback& callback);
163 const NativeWebKeyboardEvent* GetLastKeyboardEvent() const;
165 // Sets the View of this RenderWidgetHost.
166 void SetView(RenderWidgetHostViewBase* view);
168 RenderWidgetHostDelegate* delegate() const { return delegate_; }
170 int surface_id() const { return surface_id_; }
172 bool empty() const { return current_size_.IsEmpty(); }
174 // Called when a renderer object already been created for this host, and we
175 // just need to be attached to it. Used for window.open, <select> dropdown
176 // menus, and other times when the renderer initiates creating an object.
177 virtual void Init();
179 // Initializes a RenderWidgetHost that is attached to a RenderFrameHost.
180 void InitForFrame();
182 // Signal whether this RenderWidgetHost is owned by a RenderFrameHost, in
183 // which case it does not do self-deletion.
184 void set_owned_by_render_frame_host(bool owned_by_rfh) {
185 owned_by_render_frame_host_ = owned_by_rfh;
188 // Tells the renderer to die and then calls Destroy().
189 virtual void Shutdown();
191 // IPC::Listener
192 bool OnMessageReceived(const IPC::Message& msg) override;
194 // Sends a message to the corresponding object in the renderer.
195 bool Send(IPC::Message* msg) override;
197 // Indicates if the page has finished loading.
198 virtual void SetIsLoading(bool is_loading);
200 // Called to notify the RenderWidget that it has been hidden or restored from
201 // having been hidden.
202 virtual void WasHidden();
203 virtual void WasShown(const ui::LatencyInfo& latency_info);
205 // Returns true if the RenderWidget is hidden.
206 bool is_hidden() const { return is_hidden_; }
208 // Called to notify the RenderWidget that its associated native window
209 // got/lost focused.
210 virtual void GotFocus();
211 virtual void LostCapture();
213 // Indicates whether the RenderWidgetHost thinks it is focused.
214 // This is different from RenderWidgetHostView::HasFocus() in the sense that
215 // it reflects what the renderer process knows: it saves the state that is
216 // sent/received.
217 // RenderWidgetHostView::HasFocus() is checking whether the view is focused so
218 // it is possible in some edge cases that a view was requested to be focused
219 // but it failed, thus HasFocus() returns false.
220 bool is_focused() const { return is_focused_; }
222 // Called to notify the RenderWidget that it has lost the mouse lock.
223 virtual void LostMouseLock();
225 // Noifies the RenderWidget of the current mouse cursor visibility state.
226 void SendCursorVisibilityState(bool is_visible);
228 // Notifies the RenderWidgetHost that the View was destroyed.
229 void ViewDestroyed();
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();
237 // Whether pausing may be useful.
238 bool CanPauseForPendingResizeOrRepaints();
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
245 bool resize_ack_pending_for_testing() { return resize_ack_pending_; }
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();
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);
257 // Stops all existing hang monitor timeouts and assumes the renderer is
258 // responsive.
259 void StopHangMonitorTimeout();
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);
276 // Enables/disables touch emulation using mouse event. See TouchEmulator.
277 void SetTouchEventEmulationEnabled(
278 bool enabled, ui::GestureProviderConfigType config_type);
280 // TouchEmulatorClient implementation.
281 void ForwardGestureEvent(
282 const blink::WebGestureEvent& gesture_event) override;
283 void ForwardEmulatedTouchEvent(
284 const blink::WebTouchEvent& touch_event) override;
285 void SetCursor(const WebCursor& cursor) override;
286 void ShowContextMenuAtPoint(const gfx::Point& point) override;
288 // Queues a synthetic gesture for testing purposes. Invokes the on_complete
289 // callback when the gesture is finished running.
290 void QueueSyntheticGesture(
291 scoped_ptr<SyntheticGesture> synthetic_gesture,
292 const base::Callback<void(SyntheticGesture::Result)>& on_complete);
294 void CancelUpdateTextDirection();
296 // Update the composition node of the renderer (or WebKit).
297 // WebKit has a special node (a composition node) for input method to change
298 // its text without affecting any other DOM nodes. When the input method
299 // (attached to the browser) updates its text, the browser sends IPC messages
300 // to update the composition node of the renderer.
301 // (Read the comments of each function for its detail.)
303 // Sets the text of the composition node.
304 // This function can also update the cursor position and mark the specified
305 // range in the composition node.
306 // A browser should call this function:
307 // * when it receives a WM_IME_COMPOSITION message with a GCS_COMPSTR flag
308 // (on Windows);
309 // * when it receives a "preedit_changed" signal of GtkIMContext (on Linux);
310 // * when markedText of NSTextInput is called (on Mac).
311 void ImeSetComposition(
312 const base::string16& text,
313 const std::vector<blink::WebCompositionUnderline>& underlines,
314 int selection_start,
315 int selection_end);
317 // Finishes an ongoing composition with the specified text.
318 // A browser should call this function:
319 // * when it receives a WM_IME_COMPOSITION message with a GCS_RESULTSTR flag
320 // (on Windows);
321 // * when it receives a "commit" signal of GtkIMContext (on Linux);
322 // * when insertText of NSTextInput is called (on Mac).
323 void ImeConfirmComposition(const base::string16& text,
324 const gfx::Range& replacement_range,
325 bool keep_selection);
327 // Cancels an ongoing composition.
328 void ImeCancelComposition();
330 // This is for derived classes to give us access to the resizer rect.
331 // And to also expose it to the RenderWidgetHostView.
332 virtual gfx::Rect GetRootWindowResizerRect() const;
334 bool ignore_input_events() const {
335 return ignore_input_events_;
338 // Whether forwarded WebInputEvents should be ignored. True if either
339 // |ignore_input_events_| or |process_->IgnoreInputEvents()| is true.
340 bool IgnoreInputEvents() const;
342 bool has_touch_handler() const { return has_touch_handler_; }
344 // Notification that the user has made some kind of input that could
345 // perform an action. See OnUserGesture for more details.
346 void StartUserGesture();
348 // Set the RenderView background transparency.
349 void SetBackgroundOpaque(bool opaque);
351 // Notifies the renderer that the next key event is bound to one or more
352 // pre-defined edit commands
353 void SetEditCommandsForNextKeyEvent(
354 const std::vector<EditCommand>& commands);
356 // Executes the edit command on the RenderView.
357 void ExecuteEditCommand(const std::string& command,
358 const std::string& value);
360 // Tells the renderer to scroll the currently focused node into rect only if
361 // the currently focused node is a Text node (textfield, text area or content
362 // editable divs).
363 void ScrollFocusedEditableNodeIntoRect(const gfx::Rect& rect);
365 // Requests the renderer to move the caret selection towards the point.
366 void MoveCaret(const gfx::Point& point);
368 // Called when the reponse to a pending mouse lock request has arrived.
369 // Returns true if |allowed| is true and the mouse has been successfully
370 // locked.
371 bool GotResponseToLockMouseRequest(bool allowed);
373 // Tells the RenderWidget about the latest vsync parameters.
374 virtual void UpdateVSyncParameters(base::TimeTicks timebase,
375 base::TimeDelta interval);
377 // Called by the view in response to OnSwapCompositorFrame.
378 static void SendSwapCompositorFrameAck(
379 int32_t route_id,
380 uint32_t output_surface_id,
381 int renderer_host_id,
382 const cc::CompositorFrameAck& ack);
384 // Called by the view to return resources to the compositor.
385 static void SendReclaimCompositorResources(int32_t route_id,
386 uint32_t output_surface_id,
387 int renderer_host_id,
388 const cc::CompositorFrameAck& ack);
390 void set_allow_privileged_mouse_lock(bool allow) {
391 allow_privileged_mouse_lock_ = allow;
394 // Resets state variables related to tracking pending size and painting.
396 // We need to reset these flags when we want to repaint the contents of
397 // browser plugin in this RWH. Resetting these flags will ensure we ignore
398 // any previous pending acks that are not relevant upon repaint.
399 void ResetSizeAndRepaintPendingFlags();
401 void DetachDelegate();
403 // Update the renderer's cache of the screen rect of the view and window.
404 void SendScreenRects();
406 // Suppreses future char events until a keydown. See
407 // suppress_next_char_events_.
408 void SuppressNextCharEvents();
410 // Called by the view in response to a flush request.
411 void FlushInput();
413 // Request a flush signal from the view.
414 void SetNeedsFlush();
416 // Indicates whether the renderer drives the RenderWidgetHosts's size or the
417 // other way around.
418 bool auto_resize_enabled() { return auto_resize_enabled_; }
420 // The minimum size of this renderer when auto-resize is enabled.
421 const gfx::Size& min_size_for_auto_resize() const {
422 return min_size_for_auto_resize_;
425 // The maximum size of this renderer when auto-resize is enabled.
426 const gfx::Size& max_size_for_auto_resize() const {
427 return max_size_for_auto_resize_;
430 void FrameSwapped(const ui::LatencyInfo& latency_info);
431 void DidReceiveRendererFrame();
433 // Returns the ID that uniquely describes this component to the latency
434 // subsystem.
435 int64_t GetLatencyComponentId() const;
437 static void CompositorFrameDrawn(
438 const std::vector<ui::LatencyInfo>& latency_info);
440 // Don't check whether we expected a resize ack during layout tests.
441 static void DisableResizeAckCheckForTesting();
443 InputRouter* input_router() { return input_router_.get(); }
445 // Get the BrowserAccessibilityManager for the root of the frame tree,
446 BrowserAccessibilityManager* GetRootBrowserAccessibilityManager();
448 // Get the BrowserAccessibilityManager for the root of the frame tree,
449 // or create it if it doesn't already exist.
450 BrowserAccessibilityManager* GetOrCreateRootBrowserAccessibilityManager();
452 void RejectMouseLockOrUnlockIfNecessary();
454 #if defined(OS_WIN)
455 gfx::NativeViewAccessible GetParentNativeViewAccessible();
456 #endif
458 void set_renderer_initialized(bool renderer_initialized) {
459 renderer_initialized_ = renderer_initialized;
462 protected:
463 RenderWidgetHostImpl* AsRenderWidgetHostImpl() override;
465 // Called when we receive a notification indicating that the renderer
466 // process has gone. This will reset our state so that our state will be
467 // consistent if a new renderer is created.
468 void RendererExited(base::TerminationStatus status, int exit_code);
470 // Retrieves an id the renderer can use to refer to its view.
471 // This is used for various IPC messages, including plugins.
472 gfx::NativeViewId GetNativeViewId() const;
474 // Retrieves an id for the surface that the renderer can draw to
475 // when accelerated compositing is enabled.
476 gfx::GLSurfaceHandle GetCompositingSurface();
478 // ---------------------------------------------------------------------------
479 // The following methods are overridden by RenderViewHost to send upwards to
480 // its delegate.
482 // Called when a mousewheel event was not processed by the renderer.
483 virtual void UnhandledWheelEvent(const blink::WebMouseWheelEvent& event) {}
485 // Notification that the user has made some kind of input that could
486 // perform an action. The gestures that count are 1) any mouse down
487 // event and 2) enter or space key presses.
488 virtual void OnUserGesture() {}
490 // Callbacks for notification when the renderer becomes unresponsive to user
491 // input events, and subsequently responsive again.
492 virtual void NotifyRendererUnresponsive() {}
493 virtual void NotifyRendererResponsive() {}
495 // Called when auto-resize resulted in the renderer size changing.
496 virtual void OnRenderAutoResized(const gfx::Size& new_size) {}
498 // ---------------------------------------------------------------------------
500 // RenderViewHost overrides this method to impose further restrictions on when
501 // to allow mouse lock.
502 // Once the request is approved or rejected, GotResponseToLockMouseRequest()
503 // will be called.
504 virtual void RequestToLockMouse(bool user_gesture,
505 bool last_unlocked_by_target);
507 bool IsMouseLocked() const;
509 // RenderViewHost overrides this method to report whether tab-initiated
510 // fullscreen was granted.
511 virtual bool IsFullscreenGranted() const;
513 virtual blink::WebDisplayMode GetDisplayMode() const;
515 // Indicates if the render widget host should track the render widget's size
516 // as opposed to visa versa.
517 void SetAutoResize(bool enable,
518 const gfx::Size& min_size,
519 const gfx::Size& max_size);
521 // Fills in the |resize_params| struct.
522 // Returns |false| if the update is redundant, |true| otherwise.
523 bool GetResizeParams(ViewMsg_Resize_Params* resize_params);
525 // Sets the |resize_params| that were sent to the renderer bundled with the
526 // request to create a new RenderWidget.
527 void SetInitialRenderSizeParams(const ViewMsg_Resize_Params& resize_params);
529 // Expose increment/decrement of the in-flight event count, so
530 // RenderViewHostImpl can account for in-flight beforeunload/unload events.
531 int increment_in_flight_event_count() { return ++in_flight_event_count_; }
532 int decrement_in_flight_event_count() {
533 DCHECK_GT(in_flight_event_count_, 0);
534 return --in_flight_event_count_;
537 bool renderer_initialized() const { return renderer_initialized_; }
539 // The View associated with the RenderViewHost. The lifetime of this object
540 // is associated with the lifetime of the Render process. If the Renderer
541 // crashes, its View is destroyed and this pointer becomes NULL, even though
542 // render_view_host_ lives on to load another URL (creating a new View while
543 // doing so).
544 RenderWidgetHostViewBase* view_;
546 // A weak pointer to the view. The above pointer should be weak, but changing
547 // that to be weak causes crashes on Android.
548 // TODO(ccameron): Fix this.
549 // http://crbug.com/404828
550 base::WeakPtr<RenderWidgetHostViewBase> view_weak_;
552 // This value indicates how long to wait before we consider a renderer hung.
553 base::TimeDelta hung_renderer_delay_;
555 private:
556 friend class MockRenderWidgetHost;
558 // Tell this object to destroy itself.
559 void Destroy();
561 // Called by |hang_monitor_timeout_| on delayed response from the renderer.
562 void RendererIsUnresponsive();
564 // Called if we know the renderer is responsive. When we currently think the
565 // renderer is unresponsive, this will clear that state and call
566 // NotifyRendererResponsive.
567 void RendererIsResponsive();
569 // Routines used to send the RenderWidget its screen color profile.
570 void DispatchColorProfile();
571 void SendColorProfile();
573 // IPC message handlers
574 void OnRenderViewReady();
575 void OnRenderProcessGone(int status, int error_code);
576 void OnClose();
577 void OnUpdateScreenRectsAck();
578 void OnRequestMove(const gfx::Rect& pos);
579 void OnSetTooltipText(const base::string16& tooltip_text,
580 blink::WebTextDirection text_direction_hint);
581 bool OnSwapCompositorFrame(const IPC::Message& message);
582 void OnUpdateRect(const ViewHostMsg_UpdateRect_Params& params);
583 void OnQueueSyntheticGesture(const SyntheticGesturePacket& gesture_packet);
584 virtual void OnFocus();
585 virtual void OnBlur();
586 void OnSetCursor(const WebCursor& cursor);
587 void OnTextInputStateChanged(
588 const ViewHostMsg_TextInputState_Params& params);
590 void OnImeCompositionRangeChanged(
591 const gfx::Range& range,
592 const std::vector<gfx::Rect>& character_bounds);
593 void OnImeCancelComposition();
594 void OnLockMouse(bool user_gesture,
595 bool last_unlocked_by_target,
596 bool privileged);
597 void OnUnlockMouse();
598 void OnShowDisambiguationPopup(const gfx::Rect& rect_pixels,
599 const gfx::Size& size,
600 const cc::SharedBitmapId& id);
601 #if defined(OS_WIN)
602 void OnWindowlessPluginDummyWindowCreated(
603 gfx::NativeViewId dummy_activation_window);
604 void OnWindowlessPluginDummyWindowDestroyed(
605 gfx::NativeViewId dummy_activation_window);
606 #endif
607 void OnSelectionChanged(const base::string16& text,
608 size_t offset,
609 const gfx::Range& range);
610 void OnSelectionBoundsChanged(
611 const ViewHostMsg_SelectionBounds_Params& params);
612 void OnSnapshot(bool success, const SkBitmap& bitmap);
614 // Called (either immediately or asynchronously) after we're done with our
615 // BackingStore and can send an ACK to the renderer so it can paint onto it
616 // again.
617 void DidUpdateBackingStore(const ViewHostMsg_UpdateRect_Params& params,
618 const base::TimeTicks& paint_start);
620 // Give key press listeners a chance to handle this key press. This allow
621 // widgets that don't have focus to still handle key presses.
622 bool KeyPressListenersHandleEvent(const NativeWebKeyboardEvent& event);
624 // InputRouterClient
625 InputEventAckState FilterInputEvent(
626 const blink::WebInputEvent& event,
627 const ui::LatencyInfo& latency_info) override;
628 void IncrementInFlightEventCount() override;
629 void DecrementInFlightEventCount() override;
630 void OnHasTouchEventHandlers(bool has_handlers) override;
631 void DidFlush() override;
632 void DidOverscroll(const DidOverscrollParams& params) override;
633 void DidStopFlinging() override;
635 // InputAckHandler
636 void OnKeyboardEventAck(const NativeWebKeyboardEventWithLatencyInfo& event,
637 InputEventAckState ack_result) override;
638 void OnMouseEventAck(const MouseEventWithLatencyInfo& event,
639 InputEventAckState ack_result) override;
640 void OnWheelEventAck(const MouseWheelEventWithLatencyInfo& event,
641 InputEventAckState ack_result) override;
642 void OnTouchEventAck(const TouchEventWithLatencyInfo& event,
643 InputEventAckState ack_result) override;
644 void OnGestureEventAck(const GestureEventWithLatencyInfo& event,
645 InputEventAckState ack_result) override;
646 void OnUnexpectedEventAck(UnexpectedEventAckType type) override;
648 void OnSyntheticGestureCompleted(SyntheticGesture::Result result);
650 // Called when there is a new auto resize (using a post to avoid a stack
651 // which may get in recursive loops).
652 void DelayedAutoResized();
654 void WindowSnapshotReachedScreen(int snapshot_id);
656 void OnSnapshotDataReceived(int snapshot_id,
657 const unsigned char* png,
658 size_t size);
660 void OnSnapshotDataReceivedAsync(
661 int snapshot_id,
662 scoped_refptr<base::RefCountedBytes> png_data);
664 // true if a renderer has once been valid. We use this flag to display a sad
665 // tab only when we lose our renderer and not if a paint occurs during
666 // initialization.
667 bool renderer_initialized_;
669 // Our delegate, which wants to know mainly about keyboard events.
670 // It will remain non-NULL until DetachDelegate() is called.
671 RenderWidgetHostDelegate* delegate_;
673 // Created during construction and guaranteed never to be NULL, but its
674 // channel may be NULL if the renderer crashed, so one must always check that.
675 RenderProcessHost* const process_;
677 // The ID of the corresponding object in the Renderer Instance.
678 const int routing_id_;
680 // The ID of the surface corresponding to this render widget.
681 int surface_id_;
683 // Indicates whether a page is loading or not.
684 bool is_loading_;
686 // Indicates whether a page is hidden or not. It has to stay in sync with the
687 // most recent call to process_->WidgetRestored() / WidgetHidden().
688 bool is_hidden_;
690 // Set if we are waiting for a repaint ack for the view.
691 bool repaint_ack_pending_;
693 // True when waiting for RESIZE_ACK.
694 bool resize_ack_pending_;
696 // Set if the color profile should fetched and sent to the RenderWidget
697 // during the WasResized() resize message flow.
698 bool color_profile_out_of_date_;
700 // The current size of the RenderWidget.
701 gfx::Size current_size_;
703 // Resize information that was previously sent to the renderer.
704 scoped_ptr<ViewMsg_Resize_Params> old_resize_params_;
706 // The next auto resize to send.
707 gfx::Size new_auto_size_;
709 // True if the render widget host should track the render widget's size as
710 // opposed to visa versa.
711 bool auto_resize_enabled_;
713 // The minimum size for the render widget if auto-resize is enabled.
714 gfx::Size min_size_for_auto_resize_;
716 // The maximum size for the render widget if auto-resize is enabled.
717 gfx::Size max_size_for_auto_resize_;
719 bool waiting_for_screen_rects_ack_;
720 gfx::Rect last_view_screen_rect_;
721 gfx::Rect last_window_screen_rect_;
723 // Keyboard event listeners.
724 std::vector<KeyPressEventCallback> key_press_event_callbacks_;
726 // Mouse event callbacks.
727 std::vector<MouseEventCallback> mouse_event_callbacks_;
729 // If true, then we should repaint when restoring even if we have a
730 // backingstore. This flag is set to true if we receive a paint message
731 // while is_hidden_ to true. Even though we tell the render widget to hide
732 // itself, a paint message could already be in flight at that point.
733 bool needs_repainting_on_restore_;
735 // This is true if the renderer is currently unresponsive.
736 bool is_unresponsive_;
738 // This value denotes the number of input events yet to be acknowledged
739 // by the renderer.
740 int in_flight_event_count_;
742 // Flag to detect recursive calls to GetBackingStore().
743 bool in_get_backing_store_;
745 // Used for UMA histogram logging to measure the time for a repaint view
746 // operation to finish.
747 base::TimeTicks repaint_start_time_;
749 // Set to true if we shouldn't send input events from the render widget.
750 bool ignore_input_events_;
752 // Set when we update the text direction of the selected input element.
753 bool text_direction_updated_;
754 blink::WebTextDirection text_direction_;
756 // Set when we cancel updating the text direction.
757 // This flag also ignores succeeding update requests until we call
758 // NotifyTextDirection().
759 bool text_direction_canceled_;
761 // Indicates if the next sequence of Char events should be suppressed or not.
762 // System may translate a RawKeyDown event into zero or more Char events,
763 // usually we send them to the renderer directly in sequence. However, If a
764 // RawKeyDown event was not handled by the renderer but was handled by
765 // our UnhandledKeyboardEvent() method, e.g. as an accelerator key, then we
766 // shall not send the following sequence of Char events, which was generated
767 // by this RawKeyDown event, to the renderer. Otherwise the renderer may
768 // handle the Char events and cause unexpected behavior.
769 // For example, pressing alt-2 may let the browser switch to the second tab,
770 // but the Char event generated by alt-2 may also activate a HTML element
771 // if its accesskey happens to be "2", then the user may get confused when
772 // switching back to the original tab, because the content may already be
773 // changed.
774 bool suppress_next_char_events_;
776 bool pending_mouse_lock_request_;
777 bool allow_privileged_mouse_lock_;
779 // Keeps track of whether the webpage has any touch event handler. If it does,
780 // then touch events are sent to the renderer. Otherwise, the touch events are
781 // not sent to the renderer.
782 bool has_touch_handler_;
784 scoped_ptr<SyntheticGestureController> synthetic_gesture_controller_;
786 scoped_ptr<TouchEmulator> touch_emulator_;
788 // Receives and handles all input events.
789 scoped_ptr<InputRouter> input_router_;
791 scoped_ptr<TimeoutMonitor> hang_monitor_timeout_;
793 #if defined(OS_WIN)
794 std::list<HWND> dummy_windows_for_activation_;
795 #endif
797 RenderWidgetHostLatencyTracker latency_tracker_;
799 int next_browser_snapshot_id_;
800 using PendingSnapshotMap = std::map<int, GetSnapshotFromBrowserCallback>;
801 PendingSnapshotMap pending_browser_snapshots_;
803 // Indicates whether a RenderFramehost has ownership, in which case this
804 // object does not self destroy.
805 bool owned_by_render_frame_host_;
807 // Indicates whether this RenderWidgetHost thinks is focused. This is trying
808 // to match what the renderer process knows. It is different from
809 // RenderWidgetHostView::HasFocus in that in that the focus request may fail,
810 // causing HasFocus to return false when is_focused_ is true.
811 bool is_focused_;
813 base::WeakPtrFactory<RenderWidgetHostImpl> weak_factory_;
815 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostImpl);
818 } // namespace content
820 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_IMPL_H_