Clean up check for dependency_info.
[chromium-blink-merge.git] / content / browser / renderer_host / render_widget_host_impl.h
blob06d502f31d452a0cc087931c9e632733d1e6a441
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 void set_new_content_rendering_delay_for_testing(
120 const base::TimeDelta& delay) {
121 new_content_rendering_delay_ = delay;
124 // RenderWidgetHost implementation.
125 void UpdateTextDirection(blink::WebTextDirection direction) override;
126 void NotifyTextDirection() override;
127 void Focus() override;
128 void Blur() override;
129 void SetActive(bool active) override;
130 void CopyFromBackingStore(const gfx::Rect& src_rect,
131 const gfx::Size& accelerated_dst_size,
132 ReadbackRequestCallback& callback,
133 const SkColorType preferred_color_type) override;
134 bool CanCopyFromBackingStore() override;
135 #if defined(OS_ANDROID)
136 void LockBackingStore() override;
137 void UnlockBackingStore() override;
138 #endif
139 void ForwardMouseEvent(const blink::WebMouseEvent& mouse_event) override;
140 void ForwardWheelEvent(const blink::WebMouseWheelEvent& wheel_event) override;
141 void ForwardKeyboardEvent(const NativeWebKeyboardEvent& key_event) override;
142 RenderProcessHost* GetProcess() const override;
143 int GetRoutingID() const override;
144 RenderWidgetHostView* GetView() const override;
145 bool IsLoading() const override;
146 bool IsRenderView() const override;
147 void ResizeRectChanged(const gfx::Rect& new_rect) override;
148 void RestartHangMonitorTimeout() override;
149 void SetIgnoreInputEvents(bool ignore_input_events) override;
150 void WasResized() override;
151 void AddKeyPressEventCallback(const KeyPressEventCallback& callback) override;
152 void RemoveKeyPressEventCallback(
153 const KeyPressEventCallback& callback) override;
154 void AddMouseEventCallback(const MouseEventCallback& callback) override;
155 void RemoveMouseEventCallback(const MouseEventCallback& callback) override;
156 void GetWebScreenInfo(blink::WebScreenInfo* result) override;
157 bool GetScreenColorProfile(std::vector<char>* color_profile) override;
159 // Notification that the screen info has changed.
160 void NotifyScreenInfoChanged();
162 // Forces redraw in the renderer and when the update reaches the browser
163 // grabs snapshot from the compositor. Returns PNG-encoded snapshot.
164 using GetSnapshotFromBrowserCallback =
165 base::Callback<void(const unsigned char*, size_t)>;
166 void GetSnapshotFromBrowser(const GetSnapshotFromBrowserCallback& callback);
168 const NativeWebKeyboardEvent* GetLastKeyboardEvent() const;
170 // Sets the View of this RenderWidgetHost.
171 void SetView(RenderWidgetHostViewBase* view);
173 RenderWidgetHostDelegate* delegate() const { return delegate_; }
175 int surface_id() const { return surface_id_; }
177 bool empty() const { return current_size_.IsEmpty(); }
179 // Called when a renderer object already been created for this host, and we
180 // just need to be attached to it. Used for window.open, <select> dropdown
181 // menus, and other times when the renderer initiates creating an object.
182 virtual void Init();
184 // Initializes a RenderWidgetHost that is attached to a RenderFrameHost.
185 void InitForFrame();
187 // Signal whether this RenderWidgetHost is owned by a RenderFrameHost, in
188 // which case it does not do self-deletion.
189 void set_owned_by_render_frame_host(bool owned_by_rfh) {
190 owned_by_render_frame_host_ = owned_by_rfh;
193 // Tells the renderer to die and then calls Destroy().
194 virtual void Shutdown();
196 // IPC::Listener
197 bool OnMessageReceived(const IPC::Message& msg) override;
199 // Sends a message to the corresponding object in the renderer.
200 bool Send(IPC::Message* msg) override;
202 // Indicates if the page has finished loading.
203 virtual void SetIsLoading(bool is_loading);
205 // Called to notify the RenderWidget that it has been hidden or restored from
206 // having been hidden.
207 virtual void WasHidden();
208 virtual void WasShown(const ui::LatencyInfo& latency_info);
210 // Returns true if the RenderWidget is hidden.
211 bool is_hidden() const { return is_hidden_; }
213 // Called to notify the RenderWidget that its associated native window
214 // got/lost focused.
215 virtual void GotFocus();
216 virtual void LostCapture();
218 // Indicates whether the RenderWidgetHost thinks it is focused.
219 // This is different from RenderWidgetHostView::HasFocus() in the sense that
220 // it reflects what the renderer process knows: it saves the state that is
221 // sent/received.
222 // RenderWidgetHostView::HasFocus() is checking whether the view is focused so
223 // it is possible in some edge cases that a view was requested to be focused
224 // but it failed, thus HasFocus() returns false.
225 bool is_focused() const { return is_focused_; }
227 // Called to notify the RenderWidget that it has lost the mouse lock.
228 virtual void LostMouseLock();
230 // Noifies the RenderWidget of the current mouse cursor visibility state.
231 void SendCursorVisibilityState(bool is_visible);
233 // Notifies the RenderWidgetHost that the View was destroyed.
234 void ViewDestroyed();
236 #if defined(OS_MACOSX)
237 // Pause for a moment to wait for pending repaint or resize messages sent to
238 // the renderer to arrive. If pending resize messages are for an old window
239 // size, then also pump through a new resize message if there is time.
240 void PauseForPendingResizeOrRepaints();
242 // Whether pausing may be useful.
243 bool CanPauseForPendingResizeOrRepaints();
245 // Wait for a surface matching the size of the widget's view, possibly
246 // blocking until the renderer sends a new frame.
247 void WaitForSurface();
248 #endif
250 bool resize_ack_pending_for_testing() { return resize_ack_pending_; }
252 // GPU accelerated version of GetBackingStore function. This will
253 // trigger a re-composite to the view. It may fail if a resize is pending, or
254 // if a composite has already been requested and not acked yet.
255 bool ScheduleComposite();
257 // Starts a hang monitor timeout. If there's already a hang monitor timeout
258 // the new one will only fire if it has a shorter delay than the time
259 // left on the existing timeouts.
260 void StartHangMonitorTimeout(base::TimeDelta delay);
262 // Stops all existing hang monitor timeouts and assumes the renderer is
263 // responsive.
264 void StopHangMonitorTimeout();
266 // Starts the rendering timeout, which will clear displayed graphics if
267 // a new compositor frame is not received before it expires.
268 void StartNewContentRenderingTimeout();
270 // Stops the rendering timeout and prevents it from clearing any displayed
271 // graphics.
272 void StopNewContentRenderingTimeout();
274 // Forwards the given message to the renderer. These are called by the view
275 // when it has received a message.
276 void ForwardGestureEventWithLatencyInfo(
277 const blink::WebGestureEvent& gesture_event,
278 const ui::LatencyInfo& ui_latency);
279 void ForwardTouchEventWithLatencyInfo(
280 const blink::WebTouchEvent& touch_event,
281 const ui::LatencyInfo& ui_latency);
282 void ForwardMouseEventWithLatencyInfo(
283 const blink::WebMouseEvent& mouse_event,
284 const ui::LatencyInfo& ui_latency);
285 void ForwardWheelEventWithLatencyInfo(
286 const blink::WebMouseWheelEvent& wheel_event,
287 const ui::LatencyInfo& ui_latency);
289 // Enables/disables touch emulation using mouse event. See TouchEmulator.
290 void SetTouchEventEmulationEnabled(
291 bool enabled, ui::GestureProviderConfigType config_type);
293 // TouchEmulatorClient implementation.
294 void ForwardGestureEvent(
295 const blink::WebGestureEvent& gesture_event) override;
296 void ForwardEmulatedTouchEvent(
297 const blink::WebTouchEvent& touch_event) override;
298 void SetCursor(const WebCursor& cursor) override;
299 void ShowContextMenuAtPoint(const gfx::Point& point) override;
301 // Queues a synthetic gesture for testing purposes. Invokes the on_complete
302 // callback when the gesture is finished running.
303 void QueueSyntheticGesture(
304 scoped_ptr<SyntheticGesture> synthetic_gesture,
305 const base::Callback<void(SyntheticGesture::Result)>& on_complete);
307 void CancelUpdateTextDirection();
309 // Update the composition node of the renderer (or WebKit).
310 // WebKit has a special node (a composition node) for input method to change
311 // its text without affecting any other DOM nodes. When the input method
312 // (attached to the browser) updates its text, the browser sends IPC messages
313 // to update the composition node of the renderer.
314 // (Read the comments of each function for its detail.)
316 // Sets the text of the composition node.
317 // This function can also update the cursor position and mark the specified
318 // range in the composition node.
319 // A browser should call this function:
320 // * when it receives a WM_IME_COMPOSITION message with a GCS_COMPSTR flag
321 // (on Windows);
322 // * when it receives a "preedit_changed" signal of GtkIMContext (on Linux);
323 // * when markedText of NSTextInput is called (on Mac).
324 void ImeSetComposition(
325 const base::string16& text,
326 const std::vector<blink::WebCompositionUnderline>& underlines,
327 int selection_start,
328 int selection_end);
330 // Finishes an ongoing composition with the specified text.
331 // A browser should call this function:
332 // * when it receives a WM_IME_COMPOSITION message with a GCS_RESULTSTR flag
333 // (on Windows);
334 // * when it receives a "commit" signal of GtkIMContext (on Linux);
335 // * when insertText of NSTextInput is called (on Mac).
336 void ImeConfirmComposition(const base::string16& text,
337 const gfx::Range& replacement_range,
338 bool keep_selection);
340 // Cancels an ongoing composition.
341 void ImeCancelComposition();
343 // This is for derived classes to give us access to the resizer rect.
344 // And to also expose it to the RenderWidgetHostView.
345 virtual gfx::Rect GetRootWindowResizerRect() const;
347 bool ignore_input_events() const {
348 return ignore_input_events_;
351 // Whether forwarded WebInputEvents should be ignored. True if either
352 // |ignore_input_events_| or |process_->IgnoreInputEvents()| is true.
353 bool IgnoreInputEvents() const;
355 bool has_touch_handler() const { return has_touch_handler_; }
357 // Notification that the user has made some kind of input that could
358 // perform an action. See OnUserGesture for more details.
359 void StartUserGesture();
361 // Set the RenderView background transparency.
362 void SetBackgroundOpaque(bool opaque);
364 // Notifies the renderer that the next key event is bound to one or more
365 // pre-defined edit commands
366 void SetEditCommandsForNextKeyEvent(
367 const std::vector<EditCommand>& commands);
369 // Executes the edit command on the RenderView.
370 void ExecuteEditCommand(const std::string& command,
371 const std::string& value);
373 // Tells the renderer to scroll the currently focused node into rect only if
374 // the currently focused node is a Text node (textfield, text area or content
375 // editable divs).
376 void ScrollFocusedEditableNodeIntoRect(const gfx::Rect& rect);
378 // Requests the renderer to move the caret selection towards the point.
379 void MoveCaret(const gfx::Point& point);
381 // Called when the reponse to a pending mouse lock request has arrived.
382 // Returns true if |allowed| is true and the mouse has been successfully
383 // locked.
384 bool GotResponseToLockMouseRequest(bool allowed);
386 // Tells the RenderWidget about the latest vsync parameters.
387 virtual void UpdateVSyncParameters(base::TimeTicks timebase,
388 base::TimeDelta interval);
390 // Called by the view in response to OnSwapCompositorFrame.
391 static void SendSwapCompositorFrameAck(
392 int32_t route_id,
393 uint32_t output_surface_id,
394 int renderer_host_id,
395 const cc::CompositorFrameAck& ack);
397 // Called by the view to return resources to the compositor.
398 static void SendReclaimCompositorResources(int32_t route_id,
399 uint32_t output_surface_id,
400 int renderer_host_id,
401 const cc::CompositorFrameAck& ack);
403 void set_allow_privileged_mouse_lock(bool allow) {
404 allow_privileged_mouse_lock_ = allow;
407 // Resets state variables related to tracking pending size and painting.
409 // We need to reset these flags when we want to repaint the contents of
410 // browser plugin in this RWH. Resetting these flags will ensure we ignore
411 // any previous pending acks that are not relevant upon repaint.
412 void ResetSizeAndRepaintPendingFlags();
414 void DetachDelegate();
416 // Update the renderer's cache of the screen rect of the view and window.
417 void SendScreenRects();
419 // Suppreses future char events until a keydown. See
420 // suppress_next_char_events_.
421 void SuppressNextCharEvents();
423 // Called by the view in response to a flush request.
424 void FlushInput();
426 // Request a flush signal from the view.
427 void SetNeedsFlush();
429 // Indicates whether the renderer drives the RenderWidgetHosts's size or the
430 // other way around.
431 bool auto_resize_enabled() { return auto_resize_enabled_; }
433 // The minimum size of this renderer when auto-resize is enabled.
434 const gfx::Size& min_size_for_auto_resize() const {
435 return min_size_for_auto_resize_;
438 // The maximum size of this renderer when auto-resize is enabled.
439 const gfx::Size& max_size_for_auto_resize() const {
440 return max_size_for_auto_resize_;
443 void FrameSwapped(const ui::LatencyInfo& latency_info);
444 void DidReceiveRendererFrame();
446 // Returns the ID that uniquely describes this component to the latency
447 // subsystem.
448 int64_t GetLatencyComponentId() const;
450 static void CompositorFrameDrawn(
451 const std::vector<ui::LatencyInfo>& latency_info);
453 // Don't check whether we expected a resize ack during layout tests.
454 static void DisableResizeAckCheckForTesting();
456 InputRouter* input_router() { return input_router_.get(); }
458 // Get the BrowserAccessibilityManager for the root of the frame tree,
459 BrowserAccessibilityManager* GetRootBrowserAccessibilityManager();
461 // Get the BrowserAccessibilityManager for the root of the frame tree,
462 // or create it if it doesn't already exist.
463 BrowserAccessibilityManager* GetOrCreateRootBrowserAccessibilityManager();
465 void RejectMouseLockOrUnlockIfNecessary();
467 #if defined(OS_WIN)
468 gfx::NativeViewAccessible GetParentNativeViewAccessible();
469 #endif
471 void set_renderer_initialized(bool renderer_initialized) {
472 renderer_initialized_ = renderer_initialized;
475 protected:
476 RenderWidgetHostImpl* AsRenderWidgetHostImpl() override;
478 // Called when we receive a notification indicating that the renderer
479 // process has gone. This will reset our state so that our state will be
480 // consistent if a new renderer is created.
481 void RendererExited(base::TerminationStatus status, int exit_code);
483 // Retrieves an id the renderer can use to refer to its view.
484 // This is used for various IPC messages, including plugins.
485 gfx::NativeViewId GetNativeViewId() const;
487 // Retrieves an id for the surface that the renderer can draw to
488 // when accelerated compositing is enabled.
489 gfx::GLSurfaceHandle GetCompositingSurface();
491 // ---------------------------------------------------------------------------
492 // The following methods are overridden by RenderViewHost to send upwards to
493 // its delegate.
495 // Called when a mousewheel event was not processed by the renderer.
496 virtual void UnhandledWheelEvent(const blink::WebMouseWheelEvent& event) {}
498 // Notification that the user has made some kind of input that could
499 // perform an action. The gestures that count are 1) any mouse down
500 // event and 2) enter or space key presses.
501 virtual void OnUserGesture() {}
503 // Callbacks for notification when the renderer becomes unresponsive to user
504 // input events, and subsequently responsive again.
505 virtual void NotifyRendererUnresponsive() {}
506 virtual void NotifyRendererResponsive() {}
508 // Callback for notification that we failed to receive any rendered graphics
509 // from a newly loaded page. Used for testing.
510 virtual void NotifyNewContentRenderingTimeoutForTesting() {}
512 // Called when auto-resize resulted in the renderer size changing.
513 virtual void OnRenderAutoResized(const gfx::Size& new_size) {}
515 // ---------------------------------------------------------------------------
517 // RenderViewHost overrides this method to impose further restrictions on when
518 // to allow mouse lock.
519 // Once the request is approved or rejected, GotResponseToLockMouseRequest()
520 // will be called.
521 virtual void RequestToLockMouse(bool user_gesture,
522 bool last_unlocked_by_target);
524 bool IsMouseLocked() const;
526 // RenderViewHost overrides this method to report whether tab-initiated
527 // fullscreen was granted.
528 virtual bool IsFullscreenGranted() const;
530 virtual blink::WebDisplayMode GetDisplayMode() const;
532 // Indicates if the render widget host should track the render widget's size
533 // as opposed to visa versa.
534 void SetAutoResize(bool enable,
535 const gfx::Size& min_size,
536 const gfx::Size& max_size);
538 // Fills in the |resize_params| struct.
539 // Returns |false| if the update is redundant, |true| otherwise.
540 bool GetResizeParams(ViewMsg_Resize_Params* resize_params);
542 // Sets the |resize_params| that were sent to the renderer bundled with the
543 // request to create a new RenderWidget.
544 void SetInitialRenderSizeParams(const ViewMsg_Resize_Params& resize_params);
546 // Expose increment/decrement of the in-flight event count, so
547 // RenderViewHostImpl can account for in-flight beforeunload/unload events.
548 int increment_in_flight_event_count() { return ++in_flight_event_count_; }
549 int decrement_in_flight_event_count() {
550 DCHECK_GT(in_flight_event_count_, 0);
551 return --in_flight_event_count_;
554 bool renderer_initialized() const { return renderer_initialized_; }
556 // The View associated with the RenderViewHost. The lifetime of this object
557 // is associated with the lifetime of the Render process. If the Renderer
558 // crashes, its View is destroyed and this pointer becomes NULL, even though
559 // render_view_host_ lives on to load another URL (creating a new View while
560 // doing so).
561 RenderWidgetHostViewBase* view_;
563 // A weak pointer to the view. The above pointer should be weak, but changing
564 // that to be weak causes crashes on Android.
565 // TODO(ccameron): Fix this.
566 // http://crbug.com/404828
567 base::WeakPtr<RenderWidgetHostViewBase> view_weak_;
569 // This value indicates how long to wait before we consider a renderer hung.
570 base::TimeDelta hung_renderer_delay_;
572 // This value indicates how long to wait for a new compositor frame from a
573 // renderer process before clearing any previously displayed content.
574 base::TimeDelta new_content_rendering_delay_;
576 private:
577 friend class MockRenderWidgetHost;
579 // Tell this object to destroy itself.
580 void Destroy();
582 // Called by |hang_monitor_timeout_| on delayed response from the renderer.
583 void RendererIsUnresponsive();
585 // Called by |new_content_rendering_timeout_| if a renderer has loaded new
586 // content but failed to produce a compositor frame in a defined time.
587 void ClearDisplayedGraphics();
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();
594 // Routines used to send the RenderWidget its screen color profile.
595 void DispatchColorProfile();
596 void SendColorProfile();
598 // IPC message handlers
599 void OnRenderViewReady();
600 void OnRenderProcessGone(int status, int error_code);
601 void OnClose();
602 void OnUpdateScreenRectsAck();
603 void OnRequestMove(const gfx::Rect& pos);
604 void OnSetTooltipText(const base::string16& tooltip_text,
605 blink::WebTextDirection text_direction_hint);
606 bool OnSwapCompositorFrame(const IPC::Message& message);
607 void OnUpdateRect(const ViewHostMsg_UpdateRect_Params& params);
608 void OnQueueSyntheticGesture(const SyntheticGesturePacket& gesture_packet);
609 virtual void OnFocus();
610 virtual void OnBlur();
611 void OnSetCursor(const WebCursor& cursor);
612 void OnTextInputStateChanged(
613 const ViewHostMsg_TextInputState_Params& params);
615 void OnImeCompositionRangeChanged(
616 const gfx::Range& range,
617 const std::vector<gfx::Rect>& character_bounds);
618 void OnImeCancelComposition();
619 void OnLockMouse(bool user_gesture,
620 bool last_unlocked_by_target,
621 bool privileged);
622 void OnUnlockMouse();
623 void OnShowDisambiguationPopup(const gfx::Rect& rect_pixels,
624 const gfx::Size& size,
625 const cc::SharedBitmapId& id);
626 #if defined(OS_WIN)
627 void OnWindowlessPluginDummyWindowCreated(
628 gfx::NativeViewId dummy_activation_window);
629 void OnWindowlessPluginDummyWindowDestroyed(
630 gfx::NativeViewId dummy_activation_window);
631 #endif
632 void OnSelectionChanged(const base::string16& text,
633 size_t offset,
634 const gfx::Range& range);
635 void OnSelectionBoundsChanged(
636 const ViewHostMsg_SelectionBounds_Params& params);
637 void OnSnapshot(bool success, const SkBitmap& bitmap);
639 // Called (either immediately or asynchronously) after we're done with our
640 // BackingStore and can send an ACK to the renderer so it can paint onto it
641 // again.
642 void DidUpdateBackingStore(const ViewHostMsg_UpdateRect_Params& params,
643 const base::TimeTicks& paint_start);
645 // Give key press listeners a chance to handle this key press. This allow
646 // widgets that don't have focus to still handle key presses.
647 bool KeyPressListenersHandleEvent(const NativeWebKeyboardEvent& event);
649 // InputRouterClient
650 InputEventAckState FilterInputEvent(
651 const blink::WebInputEvent& event,
652 const ui::LatencyInfo& latency_info) override;
653 void IncrementInFlightEventCount() override;
654 void DecrementInFlightEventCount() override;
655 void OnHasTouchEventHandlers(bool has_handlers) override;
656 void DidFlush() override;
657 void DidOverscroll(const DidOverscrollParams& params) override;
658 void DidStopFlinging() override;
660 // InputAckHandler
661 void OnKeyboardEventAck(const NativeWebKeyboardEventWithLatencyInfo& event,
662 InputEventAckState ack_result) override;
663 void OnMouseEventAck(const MouseEventWithLatencyInfo& event,
664 InputEventAckState ack_result) override;
665 void OnWheelEventAck(const MouseWheelEventWithLatencyInfo& event,
666 InputEventAckState ack_result) override;
667 void OnTouchEventAck(const TouchEventWithLatencyInfo& event,
668 InputEventAckState ack_result) override;
669 void OnGestureEventAck(const GestureEventWithLatencyInfo& event,
670 InputEventAckState ack_result) override;
671 void OnUnexpectedEventAck(UnexpectedEventAckType type) override;
673 void OnSyntheticGestureCompleted(SyntheticGesture::Result result);
675 // Called when there is a new auto resize (using a post to avoid a stack
676 // which may get in recursive loops).
677 void DelayedAutoResized();
679 void WindowSnapshotReachedScreen(int snapshot_id);
681 void OnSnapshotDataReceived(int snapshot_id,
682 const unsigned char* png,
683 size_t size);
685 void OnSnapshotDataReceivedAsync(
686 int snapshot_id,
687 scoped_refptr<base::RefCountedBytes> png_data);
689 // true if a renderer has once been valid. We use this flag to display a sad
690 // tab only when we lose our renderer and not if a paint occurs during
691 // initialization.
692 bool renderer_initialized_;
694 // Our delegate, which wants to know mainly about keyboard events.
695 // It will remain non-NULL until DetachDelegate() is called.
696 RenderWidgetHostDelegate* delegate_;
698 // Created during construction and guaranteed never to be NULL, but its
699 // channel may be NULL if the renderer crashed, so one must always check that.
700 RenderProcessHost* const process_;
702 // The ID of the corresponding object in the Renderer Instance.
703 const int routing_id_;
705 // The ID of the surface corresponding to this render widget.
706 int surface_id_;
708 // Indicates whether a page is loading or not.
709 bool is_loading_;
711 // Indicates whether a page is hidden or not. It has to stay in sync with the
712 // most recent call to process_->WidgetRestored() / WidgetHidden().
713 bool is_hidden_;
715 // Set if we are waiting for a repaint ack for the view.
716 bool repaint_ack_pending_;
718 // True when waiting for RESIZE_ACK.
719 bool resize_ack_pending_;
721 // Set if the color profile should fetched and sent to the RenderWidget
722 // during the WasResized() resize message flow.
723 bool color_profile_out_of_date_;
725 // The current size of the RenderWidget.
726 gfx::Size current_size_;
728 // Resize information that was previously sent to the renderer.
729 scoped_ptr<ViewMsg_Resize_Params> old_resize_params_;
731 // The next auto resize to send.
732 gfx::Size new_auto_size_;
734 // True if the render widget host should track the render widget's size as
735 // opposed to visa versa.
736 bool auto_resize_enabled_;
738 // The minimum size for the render widget if auto-resize is enabled.
739 gfx::Size min_size_for_auto_resize_;
741 // The maximum size for the render widget if auto-resize is enabled.
742 gfx::Size max_size_for_auto_resize_;
744 bool waiting_for_screen_rects_ack_;
745 gfx::Rect last_view_screen_rect_;
746 gfx::Rect last_window_screen_rect_;
748 // Keyboard event listeners.
749 std::vector<KeyPressEventCallback> key_press_event_callbacks_;
751 // Mouse event callbacks.
752 std::vector<MouseEventCallback> mouse_event_callbacks_;
754 // If true, then we should repaint when restoring even if we have a
755 // backingstore. This flag is set to true if we receive a paint message
756 // while is_hidden_ to true. Even though we tell the render widget to hide
757 // itself, a paint message could already be in flight at that point.
758 bool needs_repainting_on_restore_;
760 // This is true if the renderer is currently unresponsive.
761 bool is_unresponsive_;
763 // This value denotes the number of input events yet to be acknowledged
764 // by the renderer.
765 int in_flight_event_count_;
767 // Flag to detect recursive calls to GetBackingStore().
768 bool in_get_backing_store_;
770 // Used for UMA histogram logging to measure the time for a repaint view
771 // operation to finish.
772 base::TimeTicks repaint_start_time_;
774 // Set to true if we shouldn't send input events from the render widget.
775 bool ignore_input_events_;
777 // Set when we update the text direction of the selected input element.
778 bool text_direction_updated_;
779 blink::WebTextDirection text_direction_;
781 // Set when we cancel updating the text direction.
782 // This flag also ignores succeeding update requests until we call
783 // NotifyTextDirection().
784 bool text_direction_canceled_;
786 // Indicates if the next sequence of Char events should be suppressed or not.
787 // System may translate a RawKeyDown event into zero or more Char events,
788 // usually we send them to the renderer directly in sequence. However, If a
789 // RawKeyDown event was not handled by the renderer but was handled by
790 // our UnhandledKeyboardEvent() method, e.g. as an accelerator key, then we
791 // shall not send the following sequence of Char events, which was generated
792 // by this RawKeyDown event, to the renderer. Otherwise the renderer may
793 // handle the Char events and cause unexpected behavior.
794 // For example, pressing alt-2 may let the browser switch to the second tab,
795 // but the Char event generated by alt-2 may also activate a HTML element
796 // if its accesskey happens to be "2", then the user may get confused when
797 // switching back to the original tab, because the content may already be
798 // changed.
799 bool suppress_next_char_events_;
801 bool pending_mouse_lock_request_;
802 bool allow_privileged_mouse_lock_;
804 // Keeps track of whether the webpage has any touch event handler. If it does,
805 // then touch events are sent to the renderer. Otherwise, the touch events are
806 // not sent to the renderer.
807 bool has_touch_handler_;
809 scoped_ptr<SyntheticGestureController> synthetic_gesture_controller_;
811 scoped_ptr<TouchEmulator> touch_emulator_;
813 // Receives and handles all input events.
814 scoped_ptr<InputRouter> input_router_;
816 scoped_ptr<TimeoutMonitor> hang_monitor_timeout_;
818 scoped_ptr<TimeoutMonitor> new_content_rendering_timeout_;
820 #if defined(OS_WIN)
821 std::list<HWND> dummy_windows_for_activation_;
822 #endif
824 RenderWidgetHostLatencyTracker latency_tracker_;
826 int next_browser_snapshot_id_;
827 using PendingSnapshotMap = std::map<int, GetSnapshotFromBrowserCallback>;
828 PendingSnapshotMap pending_browser_snapshots_;
830 // Indicates whether a RenderFramehost has ownership, in which case this
831 // object does not self destroy.
832 bool owned_by_render_frame_host_;
834 // Indicates whether this RenderWidgetHost thinks is focused. This is trying
835 // to match what the renderer process knows. It is different from
836 // RenderWidgetHostView::HasFocus in that in that the focus request may fail,
837 // causing HasFocus to return false when is_focused_ is true.
838 bool is_focused_;
840 base::WeakPtrFactory<RenderWidgetHostImpl> weak_factory_;
842 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostImpl);
845 } // namespace content
847 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_IMPL_H_