Give names to all utility processes.
[chromium-blink-merge.git] / content / browser / renderer_host / render_widget_host_impl.h
blobbea0bfad580daf6ab52c8b925920a69c268f91d0
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/resources/shared_bitmap.h"
27 #include "content/browser/renderer_host/event_with_latency_info.h"
28 #include "content/browser/renderer_host/input/input_ack_handler.h"
29 #include "content/browser/renderer_host/input/input_router_client.h"
30 #include "content/browser/renderer_host/input/synthetic_gesture.h"
31 #include "content/browser/renderer_host/input/touch_emulator_client.h"
32 #include "content/browser/renderer_host/render_widget_host_latency_tracker.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/readback_types.h"
37 #include "content/public/browser/render_widget_host.h"
38 #include "content/public/common/page_zoom.h"
39 #include "ipc/ipc_listener.h"
40 #include "ui/base/ime/text_input_mode.h"
41 #include "ui/base/ime/text_input_type.h"
42 #include "ui/events/gesture_detection/gesture_provider_config_helper.h"
43 #include "ui/events/latency_info.h"
44 #include "ui/gfx/native_widget_types.h"
46 struct AcceleratedSurfaceMsg_BufferPresented_Params;
47 struct ViewHostMsg_BeginSmoothScroll_Params;
48 struct ViewHostMsg_SelectionBounds_Params;
49 struct ViewHostMsg_TextInputState_Params;
50 struct ViewHostMsg_UpdateRect_Params;
51 struct ViewMsg_Resize_Params;
53 namespace base {
54 class TimeTicks;
57 namespace cc {
58 class CompositorFrame;
59 class CompositorFrameAck;
62 namespace gfx {
63 class Range;
66 namespace ui {
67 class KeyEvent;
70 namespace blink {
71 class WebInputEvent;
72 class WebMouseEvent;
73 struct WebCompositionUnderline;
74 struct WebScreenInfo;
77 #if defined(OS_ANDROID)
78 namespace blink {
79 class WebLayer;
81 #endif
83 namespace content {
84 class BrowserAccessibilityManager;
85 class InputRouter;
86 class MockRenderWidgetHost;
87 class RenderWidgetHostDelegate;
88 class RenderWidgetHostViewBase;
89 class SyntheticGestureController;
90 class TimeoutMonitor;
91 class TouchEmulator;
92 class WebCursor;
93 struct EditCommand;
95 // This implements the RenderWidgetHost interface that is exposed to
96 // embedders of content, and adds things only visible to content.
97 class CONTENT_EXPORT RenderWidgetHostImpl
98 : virtual public RenderWidgetHost,
99 public InputRouterClient,
100 public InputAckHandler,
101 public TouchEmulatorClient,
102 public IPC::Listener {
103 public:
104 // routing_id can be MSG_ROUTING_NONE, in which case the next available
105 // routing id is taken from the RenderProcessHost.
106 // If this object outlives |delegate|, DetachDelegate() must be called when
107 // |delegate| goes away.
108 RenderWidgetHostImpl(RenderWidgetHostDelegate* delegate,
109 RenderProcessHost* process,
110 int routing_id,
111 bool hidden);
112 ~RenderWidgetHostImpl() override;
114 // Similar to RenderWidgetHost::FromID, but returning the Impl object.
115 static RenderWidgetHostImpl* FromID(int32 process_id, int32 routing_id);
117 // Returns all RenderWidgetHosts including swapped out ones for
118 // internal use. The public interface
119 // RendgerWidgetHost::GetRenderWidgetHosts only returns active ones.
120 static scoped_ptr<RenderWidgetHostIterator> GetAllRenderWidgetHosts();
122 // Use RenderWidgetHostImpl::From(rwh) to downcast a
123 // RenderWidgetHost to a RenderWidgetHostImpl. Internally, this
124 // uses RenderWidgetHost::AsRenderWidgetHostImpl().
125 static RenderWidgetHostImpl* From(RenderWidgetHost* rwh);
127 void set_hung_renderer_delay(const base::TimeDelta& delay) {
128 hung_renderer_delay_ = delay;
131 // RenderWidgetHost implementation.
132 void UpdateTextDirection(blink::WebTextDirection direction) override;
133 void NotifyTextDirection() override;
134 void Focus() override;
135 void Blur() override;
136 void SetActive(bool active) override;
137 void CopyFromBackingStore(const gfx::Rect& src_rect,
138 const gfx::Size& accelerated_dst_size,
139 ReadbackRequestCallback& callback,
140 const SkColorType color_type) override;
141 bool CanCopyFromBackingStore() override;
142 #if defined(OS_ANDROID)
143 void LockBackingStore() override;
144 void UnlockBackingStore() override;
145 #endif
146 void ForwardMouseEvent(const blink::WebMouseEvent& mouse_event) override;
147 void ForwardWheelEvent(const blink::WebMouseWheelEvent& wheel_event) override;
148 void ForwardKeyboardEvent(const NativeWebKeyboardEvent& key_event) override;
149 RenderProcessHost* GetProcess() const override;
150 int GetRoutingID() const override;
151 RenderWidgetHostView* GetView() const override;
152 bool IsLoading() const override;
153 bool IsRenderView() const override;
154 void ResizeRectChanged(const gfx::Rect& new_rect) override;
155 void RestartHangMonitorTimeout() override;
156 void SetIgnoreInputEvents(bool ignore_input_events) override;
157 void WasResized() override;
158 void AddKeyPressEventCallback(const KeyPressEventCallback& callback) override;
159 void RemoveKeyPressEventCallback(
160 const KeyPressEventCallback& callback) override;
161 void AddMouseEventCallback(const MouseEventCallback& callback) override;
162 void RemoveMouseEventCallback(const MouseEventCallback& callback) override;
163 void GetWebScreenInfo(blink::WebScreenInfo* result) override;
165 SkColorType PreferredReadbackFormat() override;
167 // Forces redraw in the renderer and when the update reaches the browser
168 // grabs snapshot from the compositor. Returns PNG-encoded snapshot.
169 void GetSnapshotFromBrowser(
170 const base::Callback<void(const unsigned char*,size_t)> callback);
172 const NativeWebKeyboardEvent* GetLastKeyboardEvent() const;
174 // Notification that the screen info has changed.
175 void NotifyScreenInfoChanged();
177 // Invalidates the cached screen info so that next resize request
178 // will carry the up to date screen info. Unlike
179 // |NotifyScreenInfoChanged|, this doesn't send a message to the renderer.
180 void InvalidateScreenInfo();
182 // Sets the View of this RenderWidgetHost.
183 void SetView(RenderWidgetHostViewBase* view);
185 int surface_id() const { return surface_id_; }
187 bool empty() const { return current_size_.IsEmpty(); }
189 // Called when a renderer object already been created for this host, and we
190 // just need to be attached to it. Used for window.open, <select> dropdown
191 // menus, and other times when the renderer initiates creating an object.
192 virtual void Init();
194 // Initializes a RenderWidgetHost that is attached to a RenderFrameHost.
195 void InitForFrame();
197 // Signal whether this RenderWidgetHost is owned by a RenderFrameHost, in
198 // which case it does not do self-deletion.
199 void set_owned_by_render_frame_host(bool owned_by_rfh) {
200 owned_by_render_frame_host_ = owned_by_rfh;
203 // Called by RenderFrameHost before destroying this object.
204 void Cleanup();
206 // Tells the renderer to die and then calls Destroy().
207 virtual void Shutdown();
209 // IPC::Listener
210 bool OnMessageReceived(const IPC::Message& msg) override;
212 // Sends a message to the corresponding object in the renderer.
213 bool Send(IPC::Message* msg) override;
215 // Indicates if the page has finished loading.
216 virtual void SetIsLoading(bool is_loading);
218 // Called to notify the RenderWidget that it has been hidden or restored from
219 // having been hidden.
220 virtual void WasHidden();
221 virtual void WasShown(const ui::LatencyInfo& latency_info);
223 // Returns true if the RenderWidget is hidden.
224 bool is_hidden() const { return is_hidden_; }
226 // Called to notify the RenderWidget that its associated native window
227 // got/lost focused.
228 virtual void GotFocus();
229 virtual void LostCapture();
231 // Indicates whether the RenderWidgetHost thinks it is focused.
232 // This is different from RenderWidgetHostView::HasFocus() in the sense that
233 // it reflects what the renderer process knows: it saves the state that is
234 // sent/received.
235 // RenderWidgetHostView::HasFocus() is checking whether the view is focused so
236 // it is possible in some edge cases that a view was requested to be focused
237 // but it failed, thus HasFocus() returns false.
238 bool is_focused() const { return is_focused_; }
240 // Called to notify the RenderWidget that it has lost the mouse lock.
241 virtual void LostMouseLock();
243 // Noifies the RenderWidget of the current mouse cursor visibility state.
244 void SendCursorVisibilityState(bool is_visible);
246 // Notifies the RenderWidgetHost that the View was destroyed.
247 void ViewDestroyed();
249 #if defined(OS_MACOSX)
250 // Pause for a moment to wait for pending repaint or resize messages sent to
251 // the renderer to arrive. If pending resize messages are for an old window
252 // size, then also pump through a new resize message if there is time.
253 void PauseForPendingResizeOrRepaints();
255 // Whether pausing may be useful.
256 bool CanPauseForPendingResizeOrRepaints();
258 // Wait for a surface matching the size of the widget's view, possibly
259 // blocking until the renderer sends a new frame.
260 void WaitForSurface();
261 #endif
263 bool resize_ack_pending_for_testing() { return resize_ack_pending_; }
265 // GPU accelerated version of GetBackingStore function. This will
266 // trigger a re-composite to the view. It may fail if a resize is pending, or
267 // if a composite has already been requested and not acked yet.
268 bool ScheduleComposite();
270 // Starts a hang monitor timeout. If there's already a hang monitor timeout
271 // the new one will only fire if it has a shorter delay than the time
272 // left on the existing timeouts.
273 void StartHangMonitorTimeout(base::TimeDelta delay);
275 // Stops all existing hang monitor timeouts and assumes the renderer is
276 // responsive.
277 void StopHangMonitorTimeout();
279 // Forwards the given message to the renderer. These are called by the view
280 // when it has received a message.
281 void ForwardGestureEventWithLatencyInfo(
282 const blink::WebGestureEvent& gesture_event,
283 const ui::LatencyInfo& ui_latency);
284 void ForwardTouchEventWithLatencyInfo(
285 const blink::WebTouchEvent& touch_event,
286 const ui::LatencyInfo& ui_latency);
287 void ForwardMouseEventWithLatencyInfo(
288 const blink::WebMouseEvent& mouse_event,
289 const ui::LatencyInfo& ui_latency);
290 void ForwardWheelEventWithLatencyInfo(
291 const blink::WebMouseWheelEvent& wheel_event,
292 const ui::LatencyInfo& ui_latency);
294 // Enables/disables touch emulation using mouse event. See TouchEmulator.
295 void SetTouchEventEmulationEnabled(
296 bool enabled, ui::GestureProviderConfigType config_type);
298 // TouchEmulatorClient implementation.
299 void ForwardGestureEvent(
300 const blink::WebGestureEvent& gesture_event) override;
301 void ForwardEmulatedTouchEvent(
302 const blink::WebTouchEvent& touch_event) override;
303 void SetCursor(const WebCursor& cursor) override;
304 void ShowContextMenuAtPoint(const gfx::Point& point) override;
306 // Queues a synthetic gesture for testing purposes. Invokes the on_complete
307 // callback when the gesture is finished running.
308 void QueueSyntheticGesture(
309 scoped_ptr<SyntheticGesture> synthetic_gesture,
310 const base::Callback<void(SyntheticGesture::Result)>& on_complete);
312 void CancelUpdateTextDirection();
314 // Notifies the renderer whether or not the input method attached to this
315 // process is activated.
316 // When the input method is activated, a renderer process sends IPC messages
317 // to notify the status of its composition node. (This message is mainly used
318 // for notifying the position of the input cursor so that the browser can
319 // display input method windows under the cursor.)
320 void SetInputMethodActive(bool activate);
322 // Notifies the renderer changes of IME candidate window state.
323 void CandidateWindowShown();
324 void CandidateWindowUpdated();
325 void CandidateWindowHidden();
327 // Update the composition node of the renderer (or WebKit).
328 // WebKit has a special node (a composition node) for input method to change
329 // its text without affecting any other DOM nodes. When the input method
330 // (attached to the browser) updates its text, the browser sends IPC messages
331 // to update the composition node of the renderer.
332 // (Read the comments of each function for its detail.)
334 // Sets the text of the composition node.
335 // This function can also update the cursor position and mark the specified
336 // range in the composition node.
337 // A browser should call this function:
338 // * when it receives a WM_IME_COMPOSITION message with a GCS_COMPSTR flag
339 // (on Windows);
340 // * when it receives a "preedit_changed" signal of GtkIMContext (on Linux);
341 // * when markedText of NSTextInput is called (on Mac).
342 void ImeSetComposition(
343 const base::string16& text,
344 const std::vector<blink::WebCompositionUnderline>& underlines,
345 int selection_start,
346 int selection_end);
348 // Finishes an ongoing composition with the specified text.
349 // A browser should call this function:
350 // * when it receives a WM_IME_COMPOSITION message with a GCS_RESULTSTR flag
351 // (on Windows);
352 // * when it receives a "commit" signal of GtkIMContext (on Linux);
353 // * when insertText of NSTextInput is called (on Mac).
354 void ImeConfirmComposition(const base::string16& text,
355 const gfx::Range& replacement_range,
356 bool keep_selection);
358 // Cancels an ongoing composition.
359 void ImeCancelComposition();
361 // This is for derived classes to give us access to the resizer rect.
362 // And to also expose it to the RenderWidgetHostView.
363 virtual gfx::Rect GetRootWindowResizerRect() const;
365 bool ignore_input_events() const {
366 return ignore_input_events_;
369 bool input_method_active() const {
370 return input_method_active_;
373 // Whether forwarded WebInputEvents should be ignored. True if either
374 // |ignore_input_events_| or |process_->IgnoreInputEvents()| is true.
375 bool IgnoreInputEvents() const;
377 bool has_touch_handler() const { return has_touch_handler_; }
379 // Notification that the user has made some kind of input that could
380 // perform an action. See OnUserGesture for more details.
381 void StartUserGesture();
383 // Set the RenderView background transparency.
384 void SetBackgroundOpaque(bool opaque);
386 // Notifies the renderer that the next key event is bound to one or more
387 // pre-defined edit commands
388 void SetEditCommandsForNextKeyEvent(
389 const std::vector<EditCommand>& commands);
391 // Executes the edit command on the RenderView.
392 void ExecuteEditCommand(const std::string& command,
393 const std::string& value);
395 // Tells the renderer to scroll the currently focused node into rect only if
396 // the currently focused node is a Text node (textfield, text area or content
397 // editable divs).
398 void ScrollFocusedEditableNodeIntoRect(const gfx::Rect& rect);
400 // Requests the renderer to move the caret selection towards the point.
401 void MoveCaret(const gfx::Point& point);
403 // Called when the reponse to a pending mouse lock request has arrived.
404 // Returns true if |allowed| is true and the mouse has been successfully
405 // locked.
406 bool GotResponseToLockMouseRequest(bool allowed);
408 // Tells the RenderWidget about the latest vsync parameters.
409 virtual void UpdateVSyncParameters(base::TimeTicks timebase,
410 base::TimeDelta interval);
412 // Called by the view in response to OnSwapCompositorFrame.
413 static void SendSwapCompositorFrameAck(
414 int32 route_id,
415 uint32 output_surface_id,
416 int renderer_host_id,
417 const cc::CompositorFrameAck& ack);
419 // Called by the view to return resources to the compositor.
420 static void SendReclaimCompositorResources(int32 route_id,
421 uint32 output_surface_id,
422 int renderer_host_id,
423 const cc::CompositorFrameAck& ack);
425 void set_allow_privileged_mouse_lock(bool allow) {
426 allow_privileged_mouse_lock_ = allow;
429 // Resets state variables related to tracking pending size and painting.
431 // We need to reset these flags when we want to repaint the contents of
432 // browser plugin in this RWH. Resetting these flags will ensure we ignore
433 // any previous pending acks that are not relevant upon repaint.
434 void ResetSizeAndRepaintPendingFlags();
436 void DetachDelegate();
438 // Update the renderer's cache of the screen rect of the view and window.
439 void SendScreenRects();
441 // Suppreses future char events until a keydown. See
442 // suppress_next_char_events_.
443 void SuppressNextCharEvents();
445 // Called by the view in response to a flush request.
446 void FlushInput();
448 // Request a flush signal from the view.
449 void SetNeedsFlush();
451 // Indicates whether the renderer drives the RenderWidgetHosts's size or the
452 // other way around.
453 bool auto_resize_enabled() { return auto_resize_enabled_; }
455 // The minimum size of this renderer when auto-resize is enabled.
456 const gfx::Size& min_size_for_auto_resize() const {
457 return min_size_for_auto_resize_;
460 // The maximum size of this renderer when auto-resize is enabled.
461 const gfx::Size& max_size_for_auto_resize() const {
462 return max_size_for_auto_resize_;
465 void FrameSwapped(const ui::LatencyInfo& latency_info);
466 void DidReceiveRendererFrame();
468 // Returns the ID that uniquely describes this component to the latency
469 // subsystem.
470 int64 GetLatencyComponentId() const;
472 base::TimeDelta GetEstimatedBrowserCompositeTime() const;
474 static void CompositorFrameDrawn(
475 const std::vector<ui::LatencyInfo>& latency_info);
477 // Don't check whether we expected a resize ack during layout tests.
478 static void DisableResizeAckCheckForTesting();
480 InputRouter* input_router() { return input_router_.get(); }
482 // Get the BrowserAccessibilityManager for the root of the frame tree,
483 BrowserAccessibilityManager* GetRootBrowserAccessibilityManager();
485 // Get the BrowserAccessibilityManager for the root of the frame tree,
486 // or create it if it doesn't already exist.
487 BrowserAccessibilityManager* GetOrCreateRootBrowserAccessibilityManager();
489 void RejectMouseLockOrUnlockIfNecessary();
491 #if defined(OS_WIN)
492 gfx::NativeViewAccessible GetParentNativeViewAccessible();
493 #endif
495 protected:
496 RenderWidgetHostImpl* AsRenderWidgetHostImpl() override;
498 // Called when we receive a notification indicating that the renderer
499 // process has gone. This will reset our state so that our state will be
500 // consistent if a new renderer is created.
501 void RendererExited(base::TerminationStatus status, int exit_code);
503 // Retrieves an id the renderer can use to refer to its view.
504 // This is used for various IPC messages, including plugins.
505 gfx::NativeViewId GetNativeViewId() const;
507 // Retrieves an id for the surface that the renderer can draw to
508 // when accelerated compositing is enabled.
509 gfx::GLSurfaceHandle GetCompositingSurface();
511 // ---------------------------------------------------------------------------
512 // The following methods are overridden by RenderViewHost to send upwards to
513 // its delegate.
515 // Called when a mousewheel event was not processed by the renderer.
516 virtual void UnhandledWheelEvent(const blink::WebMouseWheelEvent& event) {}
518 // Notification that the user has made some kind of input that could
519 // perform an action. The gestures that count are 1) any mouse down
520 // event and 2) enter or space key presses.
521 virtual void OnUserGesture() {}
523 // Callbacks for notification when the renderer becomes unresponsive to user
524 // input events, and subsequently responsive again.
525 virtual void NotifyRendererUnresponsive() {}
526 virtual void NotifyRendererResponsive() {}
528 // Called when auto-resize resulted in the renderer size changing.
529 virtual void OnRenderAutoResized(const gfx::Size& new_size) {}
531 // ---------------------------------------------------------------------------
533 // RenderViewHost overrides this method to impose further restrictions on when
534 // to allow mouse lock.
535 // Once the request is approved or rejected, GotResponseToLockMouseRequest()
536 // will be called.
537 virtual void RequestToLockMouse(bool user_gesture,
538 bool last_unlocked_by_target);
540 bool IsMouseLocked() const;
542 // RenderViewHost overrides this method to report when in fullscreen mode.
543 virtual bool IsFullscreen() const;
545 // Indicates if the render widget host should track the render widget's size
546 // as opposed to visa versa.
547 void SetAutoResize(bool enable,
548 const gfx::Size& min_size,
549 const gfx::Size& max_size);
551 // Fills in the |resize_params| struct.
552 // Returns |false| if the update is redundant, |true| otherwise.
553 bool GetResizeParams(ViewMsg_Resize_Params* resize_params);
555 // Sets the |resize_params| that were sent to the renderer bundled with the
556 // request to create a new RenderWidget.
557 void SetInitialRenderSizeParams(const ViewMsg_Resize_Params& resize_params);
559 // Expose increment/decrement of the in-flight event count, so
560 // RenderViewHostImpl can account for in-flight beforeunload/unload events.
561 int increment_in_flight_event_count() { return ++in_flight_event_count_; }
562 int decrement_in_flight_event_count() {
563 DCHECK_GT(in_flight_event_count_, 0);
564 return --in_flight_event_count_;
567 // The View associated with the RenderViewHost. The lifetime of this object
568 // is associated with the lifetime of the Render process. If the Renderer
569 // crashes, its View is destroyed and this pointer becomes NULL, even though
570 // render_view_host_ lives on to load another URL (creating a new View while
571 // doing so).
572 RenderWidgetHostViewBase* view_;
574 // A weak pointer to the view. The above pointer should be weak, but changing
575 // that to be weak causes crashes on Android.
576 // TODO(ccameron): Fix this.
577 // http://crbug.com/404828
578 base::WeakPtr<RenderWidgetHostViewBase> view_weak_;
580 // true if a renderer has once been valid. We use this flag to display a sad
581 // tab only when we lose our renderer and not if a paint occurs during
582 // initialization.
583 bool renderer_initialized_;
585 // This value indicates how long to wait before we consider a renderer hung.
586 base::TimeDelta hung_renderer_delay_;
588 private:
589 friend class MockRenderWidgetHost;
591 // Tell this object to destroy itself.
592 void Destroy();
594 // Called by |hang_monitor_timeout_| on delayed response from the renderer.
595 void RendererIsUnresponsive();
597 // Called if we know the renderer is responsive. When we currently think the
598 // renderer is unresponsive, this will clear that state and call
599 // NotifyRendererResponsive.
600 void RendererIsResponsive();
602 // IPC message handlers
603 void OnRenderViewReady();
604 void OnRenderProcessGone(int status, int error_code);
605 void OnClose();
606 void OnUpdateScreenRectsAck();
607 void OnRequestMove(const gfx::Rect& pos);
608 void OnSetTooltipText(const base::string16& tooltip_text,
609 blink::WebTextDirection text_direction_hint);
610 bool OnSwapCompositorFrame(const IPC::Message& message);
611 void OnUpdateRect(const ViewHostMsg_UpdateRect_Params& params);
612 void OnQueueSyntheticGesture(const SyntheticGesturePacket& gesture_packet);
613 virtual void OnFocus();
614 virtual void OnBlur();
615 void OnSetCursor(const WebCursor& cursor);
616 void OnTextInputTypeChanged(ui::TextInputType type,
617 ui::TextInputMode input_mode,
618 bool can_compose_inline,
619 int flags);
621 void OnImeCompositionRangeChanged(
622 const gfx::Range& range,
623 const std::vector<gfx::Rect>& character_bounds);
624 void OnImeCancelComposition();
625 void OnLockMouse(bool user_gesture,
626 bool last_unlocked_by_target,
627 bool privileged);
628 void OnUnlockMouse();
629 void OnShowDisambiguationPopup(const gfx::Rect& rect_pixels,
630 const gfx::Size& size,
631 const cc::SharedBitmapId& id);
632 #if defined(OS_WIN)
633 void OnWindowlessPluginDummyWindowCreated(
634 gfx::NativeViewId dummy_activation_window);
635 void OnWindowlessPluginDummyWindowDestroyed(
636 gfx::NativeViewId dummy_activation_window);
637 #endif
638 void OnSelectionChanged(const base::string16& text,
639 size_t offset,
640 const gfx::Range& range);
641 void OnSelectionBoundsChanged(
642 const ViewHostMsg_SelectionBounds_Params& params);
643 void OnSnapshot(bool success, const SkBitmap& bitmap);
645 // Called (either immediately or asynchronously) after we're done with our
646 // BackingStore and can send an ACK to the renderer so it can paint onto it
647 // again.
648 void DidUpdateBackingStore(const ViewHostMsg_UpdateRect_Params& params,
649 const base::TimeTicks& paint_start);
651 // Give key press listeners a chance to handle this key press. This allow
652 // widgets that don't have focus to still handle key presses.
653 bool KeyPressListenersHandleEvent(const NativeWebKeyboardEvent& event);
655 // InputRouterClient
656 InputEventAckState FilterInputEvent(
657 const blink::WebInputEvent& event,
658 const ui::LatencyInfo& latency_info) override;
659 void IncrementInFlightEventCount() override;
660 void DecrementInFlightEventCount() override;
661 void OnHasTouchEventHandlers(bool has_handlers) override;
662 void DidFlush() override;
663 void DidOverscroll(const DidOverscrollParams& params) override;
664 void DidStopFlinging() override;
666 // InputAckHandler
667 void OnKeyboardEventAck(const NativeWebKeyboardEvent& event,
668 InputEventAckState ack_result) override;
669 void OnWheelEventAck(const MouseWheelEventWithLatencyInfo& event,
670 InputEventAckState ack_result) override;
671 void OnTouchEventAck(const TouchEventWithLatencyInfo& event,
672 InputEventAckState ack_result) override;
673 void OnGestureEventAck(const GestureEventWithLatencyInfo& event,
674 InputEventAckState ack_result) override;
675 void OnUnexpectedEventAck(UnexpectedEventAckType type) override;
677 void OnSyntheticGestureCompleted(SyntheticGesture::Result result);
679 // Called when there is a new auto resize (using a post to avoid a stack
680 // which may get in recursive loops).
681 void DelayedAutoResized();
683 void WindowSnapshotReachedScreen(int snapshot_id);
685 void OnSnapshotDataReceived(int snapshot_id,
686 const unsigned char* png,
687 size_t size);
689 void OnSnapshotDataReceivedAsync(
690 int snapshot_id,
691 scoped_refptr<base::RefCountedBytes> png_data);
693 // Our delegate, which wants to know mainly about keyboard events.
694 // It will remain non-NULL until DetachDelegate() is called.
695 RenderWidgetHostDelegate* delegate_;
697 // Created during construction but initialized during Init*(). Therefore, it
698 // is guaranteed never to be NULL, but its channel may be NULL if the
699 // renderer crashed, so you must always check that.
700 RenderProcessHost* process_;
702 // The ID of the corresponding object in the Renderer Instance.
703 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 // Cached copy of the screen info so that it doesn't need to be updated every
722 // time the window is resized.
723 scoped_ptr<blink::WebScreenInfo> screen_info_;
725 // Set if screen_info_ may have changed and should be recomputed and force a
726 // resize message.
727 bool screen_info_out_of_date_;
729 // The current size of the RenderWidget.
730 gfx::Size current_size_;
732 // Resize information that was previously sent to the renderer.
733 scoped_ptr<ViewMsg_Resize_Params> old_resize_params_;
735 // The next auto resize to send.
736 gfx::Size new_auto_size_;
738 // True if the render widget host should track the render widget's size as
739 // opposed to visa versa.
740 bool auto_resize_enabled_;
742 // The minimum size for the render widget if auto-resize is enabled.
743 gfx::Size min_size_for_auto_resize_;
745 // The maximum size for the render widget if auto-resize is enabled.
746 gfx::Size max_size_for_auto_resize_;
748 bool waiting_for_screen_rects_ack_;
749 gfx::Rect last_view_screen_rect_;
750 gfx::Rect last_window_screen_rect_;
752 // Keyboard event listeners.
753 std::vector<KeyPressEventCallback> key_press_event_callbacks_;
755 // Mouse event callbacks.
756 std::vector<MouseEventCallback> mouse_event_callbacks_;
758 // If true, then we should repaint when restoring even if we have a
759 // backingstore. This flag is set to true if we receive a paint message
760 // while is_hidden_ to true. Even though we tell the render widget to hide
761 // itself, a paint message could already be in flight at that point.
762 bool needs_repainting_on_restore_;
764 // This is true if the renderer is currently unresponsive.
765 bool is_unresponsive_;
767 // This value denotes the number of input events yet to be acknowledged
768 // by the renderer.
769 int in_flight_event_count_;
771 // Flag to detect recursive calls to GetBackingStore().
772 bool in_get_backing_store_;
774 // Used for UMA histogram logging to measure the time for a repaint view
775 // operation to finish.
776 base::TimeTicks repaint_start_time_;
778 // Set to true if we shouldn't send input events from the render widget.
779 bool ignore_input_events_;
781 // Indicates whether IME is active.
782 bool input_method_active_;
784 // Set when we update the text direction of the selected input element.
785 bool text_direction_updated_;
786 blink::WebTextDirection text_direction_;
788 // Set when we cancel updating the text direction.
789 // This flag also ignores succeeding update requests until we call
790 // NotifyTextDirection().
791 bool text_direction_canceled_;
793 // Indicates if the next sequence of Char events should be suppressed or not.
794 // System may translate a RawKeyDown event into zero or more Char events,
795 // usually we send them to the renderer directly in sequence. However, If a
796 // RawKeyDown event was not handled by the renderer but was handled by
797 // our UnhandledKeyboardEvent() method, e.g. as an accelerator key, then we
798 // shall not send the following sequence of Char events, which was generated
799 // by this RawKeyDown event, to the renderer. Otherwise the renderer may
800 // handle the Char events and cause unexpected behavior.
801 // For example, pressing alt-2 may let the browser switch to the second tab,
802 // but the Char event generated by alt-2 may also activate a HTML element
803 // if its accesskey happens to be "2", then the user may get confused when
804 // switching back to the original tab, because the content may already be
805 // changed.
806 bool suppress_next_char_events_;
808 bool pending_mouse_lock_request_;
809 bool allow_privileged_mouse_lock_;
811 // Keeps track of whether the webpage has any touch event handler. If it does,
812 // then touch events are sent to the renderer. Otherwise, the touch events are
813 // not sent to the renderer.
814 bool has_touch_handler_;
816 scoped_ptr<SyntheticGestureController> synthetic_gesture_controller_;
818 scoped_ptr<TouchEmulator> touch_emulator_;
820 // Receives and handles all input events.
821 scoped_ptr<InputRouter> input_router_;
823 scoped_ptr<TimeoutMonitor> hang_monitor_timeout_;
825 #if defined(OS_WIN)
826 std::list<HWND> dummy_windows_for_activation_;
827 #endif
829 RenderWidgetHostLatencyTracker latency_tracker_;
831 int next_browser_snapshot_id_;
832 typedef std::map<int,
833 base::Callback<void(const unsigned char*, size_t)> > PendingSnapshotMap;
834 PendingSnapshotMap pending_browser_snapshots_;
836 // Indicates whether a RenderFramehost has ownership, in which case this
837 // object does not self destroy.
838 bool owned_by_render_frame_host_;
840 // Indicates whether this RenderWidgetHost thinks is focused. This is trying
841 // to match what the renderer process knows. It is different from
842 // RenderWidgetHostView::HasFocus in that in that the focus request may fail,
843 // causing HasFocus to return false when is_focused_ is true.
844 bool is_focused_;
846 base::WeakPtrFactory<RenderWidgetHostImpl> weak_factory_;
848 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostImpl);
851 } // namespace content
853 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_IMPL_H_