[Chromoting] Run jscompile over JS for HTML files (GN-only)
[chromium-blink-merge.git] / content / browser / renderer_host / render_widget_host_impl.h
blob4e89686898e6a92a36234f6254679308e355a3e8
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/render_widget_host_latency_tracker.h"
31 #include "content/browser/renderer_host/input/synthetic_gesture.h"
32 #include "content/browser/renderer_host/input/touch_emulator_client.h"
33 #include "content/common/input/input_event_ack_state.h"
34 #include "content/common/input/synthetic_gesture_packet.h"
35 #include "content/common/view_message_enums.h"
36 #include "content/public/browser/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 "third_party/WebKit/public/platform/WebDisplayMode.h"
41 #include "ui/base/ime/text_input_mode.h"
42 #include "ui/base/ime/text_input_type.h"
43 #include "ui/events/gesture_detection/gesture_provider_config_helper.h"
44 #include "ui/events/latency_info.h"
45 #include "ui/gfx/native_widget_types.h"
47 struct AcceleratedSurfaceMsg_BufferPresented_Params;
48 struct ViewHostMsg_BeginSmoothScroll_Params;
49 struct ViewHostMsg_SelectionBounds_Params;
50 struct ViewHostMsg_TextInputState_Params;
51 struct ViewHostMsg_UpdateRect_Params;
52 struct ViewMsg_Resize_Params;
54 namespace base {
55 class TimeTicks;
58 namespace cc {
59 class CompositorFrame;
60 class CompositorFrameAck;
63 namespace gfx {
64 class Range;
67 namespace ui {
68 class KeyEvent;
71 namespace blink {
72 class WebInputEvent;
73 class WebMouseEvent;
74 struct WebCompositionUnderline;
75 struct WebScreenInfo;
78 #if defined(OS_ANDROID)
79 namespace blink {
80 class WebLayer;
82 #endif
84 namespace content {
85 class BrowserAccessibilityManager;
86 class InputRouter;
87 class MockRenderWidgetHost;
88 class RenderWidgetHostDelegate;
89 class RenderWidgetHostViewBase;
90 class SyntheticGestureController;
91 class TimeoutMonitor;
92 class TouchEmulator;
93 class WebCursor;
94 struct EditCommand;
96 // This implements the RenderWidgetHost interface that is exposed to
97 // embedders of content, and adds things only visible to content.
98 class CONTENT_EXPORT RenderWidgetHostImpl
99 : virtual public RenderWidgetHost,
100 public InputRouterClient,
101 public InputAckHandler,
102 public TouchEmulatorClient,
103 public IPC::Listener {
104 public:
105 // routing_id can be MSG_ROUTING_NONE, in which case the next available
106 // routing id is taken from the RenderProcessHost.
107 // If this object outlives |delegate|, DetachDelegate() must be called when
108 // |delegate| goes away.
109 RenderWidgetHostImpl(RenderWidgetHostDelegate* delegate,
110 RenderProcessHost* process,
111 int routing_id,
112 bool hidden);
113 ~RenderWidgetHostImpl() override;
115 // Similar to RenderWidgetHost::FromID, but returning the Impl object.
116 static RenderWidgetHostImpl* FromID(int32 process_id, int32 routing_id);
118 // Returns all RenderWidgetHosts including swapped out ones for
119 // internal use. The public interface
120 // RendgerWidgetHost::GetRenderWidgetHosts only returns active ones.
121 static scoped_ptr<RenderWidgetHostIterator> GetAllRenderWidgetHosts();
123 // Use RenderWidgetHostImpl::From(rwh) to downcast a
124 // RenderWidgetHost to a RenderWidgetHostImpl. Internally, this
125 // uses RenderWidgetHost::AsRenderWidgetHostImpl().
126 static RenderWidgetHostImpl* From(RenderWidgetHost* rwh);
128 void set_hung_renderer_delay(const base::TimeDelta& delay) {
129 hung_renderer_delay_ = delay;
132 // RenderWidgetHost implementation.
133 void UpdateTextDirection(blink::WebTextDirection direction) override;
134 void NotifyTextDirection() override;
135 void Focus() override;
136 void Blur() override;
137 void SetActive(bool active) override;
138 void CopyFromBackingStore(const gfx::Rect& src_rect,
139 const gfx::Size& accelerated_dst_size,
140 ReadbackRequestCallback& callback,
141 const SkColorType preferred_color_type) override;
142 bool CanCopyFromBackingStore() override;
143 #if defined(OS_ANDROID)
144 void LockBackingStore() override;
145 void UnlockBackingStore() override;
146 #endif
147 void ForwardMouseEvent(const blink::WebMouseEvent& mouse_event) override;
148 void ForwardWheelEvent(const blink::WebMouseWheelEvent& wheel_event) override;
149 void ForwardKeyboardEvent(const NativeWebKeyboardEvent& key_event) override;
150 RenderProcessHost* GetProcess() const override;
151 int GetRoutingID() const override;
152 RenderWidgetHostView* GetView() const override;
153 bool IsLoading() const override;
154 bool IsRenderView() const override;
155 void ResizeRectChanged(const gfx::Rect& new_rect) override;
156 void RestartHangMonitorTimeout() override;
157 void SetIgnoreInputEvents(bool ignore_input_events) override;
158 void WasResized() override;
159 void AddKeyPressEventCallback(const KeyPressEventCallback& callback) override;
160 void RemoveKeyPressEventCallback(
161 const KeyPressEventCallback& callback) override;
162 void AddMouseEventCallback(const MouseEventCallback& callback) override;
163 void RemoveMouseEventCallback(const MouseEventCallback& callback) override;
164 void GetWebScreenInfo(blink::WebScreenInfo* result) override;
166 // Forces redraw in the renderer and when the update reaches the browser
167 // grabs snapshot from the compositor. Returns PNG-encoded snapshot.
168 void GetSnapshotFromBrowser(
169 const base::Callback<void(const unsigned char*,size_t)> callback);
171 const NativeWebKeyboardEvent* GetLastKeyboardEvent() const;
173 // Notification that the screen info has changed.
174 void NotifyScreenInfoChanged();
176 // Sets the View of this RenderWidgetHost.
177 void SetView(RenderWidgetHostViewBase* view);
179 int surface_id() const { return surface_id_; }
181 bool empty() const { return current_size_.IsEmpty(); }
183 // Called when a renderer object already been created for this host, and we
184 // just need to be attached to it. Used for window.open, <select> dropdown
185 // menus, and other times when the renderer initiates creating an object.
186 virtual void Init();
188 // Initializes a RenderWidgetHost that is attached to a RenderFrameHost.
189 void InitForFrame();
191 // Signal whether this RenderWidgetHost is owned by a RenderFrameHost, in
192 // which case it does not do self-deletion.
193 void set_owned_by_render_frame_host(bool owned_by_rfh) {
194 owned_by_render_frame_host_ = owned_by_rfh;
197 // Tells the renderer to die and then calls Destroy().
198 virtual void Shutdown();
200 // IPC::Listener
201 bool OnMessageReceived(const IPC::Message& msg) override;
203 // Sends a message to the corresponding object in the renderer.
204 bool Send(IPC::Message* msg) override;
206 // Indicates if the page has finished loading.
207 virtual void SetIsLoading(bool is_loading);
209 // Called to notify the RenderWidget that it has been hidden or restored from
210 // having been hidden.
211 virtual void WasHidden();
212 virtual void WasShown(const ui::LatencyInfo& latency_info);
214 // Returns true if the RenderWidget is hidden.
215 bool is_hidden() const { return is_hidden_; }
217 // Called to notify the RenderWidget that its associated native window
218 // got/lost focused.
219 virtual void GotFocus();
220 virtual void LostCapture();
222 // Indicates whether the RenderWidgetHost thinks it is focused.
223 // This is different from RenderWidgetHostView::HasFocus() in the sense that
224 // it reflects what the renderer process knows: it saves the state that is
225 // sent/received.
226 // RenderWidgetHostView::HasFocus() is checking whether the view is focused so
227 // it is possible in some edge cases that a view was requested to be focused
228 // but it failed, thus HasFocus() returns false.
229 bool is_focused() const { return is_focused_; }
231 // Called to notify the RenderWidget that it has lost the mouse lock.
232 virtual void LostMouseLock();
234 // Noifies the RenderWidget of the current mouse cursor visibility state.
235 void SendCursorVisibilityState(bool is_visible);
237 // Notifies the RenderWidgetHost that the View was destroyed.
238 void ViewDestroyed();
240 #if defined(OS_MACOSX)
241 // Pause for a moment to wait for pending repaint or resize messages sent to
242 // the renderer to arrive. If pending resize messages are for an old window
243 // size, then also pump through a new resize message if there is time.
244 void PauseForPendingResizeOrRepaints();
246 // Whether pausing may be useful.
247 bool CanPauseForPendingResizeOrRepaints();
249 // Wait for a surface matching the size of the widget's view, possibly
250 // blocking until the renderer sends a new frame.
251 void WaitForSurface();
252 #endif
254 bool resize_ack_pending_for_testing() { return resize_ack_pending_; }
256 // GPU accelerated version of GetBackingStore function. This will
257 // trigger a re-composite to the view. It may fail if a resize is pending, or
258 // if a composite has already been requested and not acked yet.
259 bool ScheduleComposite();
261 // Starts a hang monitor timeout. If there's already a hang monitor timeout
262 // the new one will only fire if it has a shorter delay than the time
263 // left on the existing timeouts.
264 void StartHangMonitorTimeout(base::TimeDelta delay);
266 // Stops all existing hang monitor timeouts and assumes the renderer is
267 // responsive.
268 void StopHangMonitorTimeout();
270 // Forwards the given message to the renderer. These are called by the view
271 // when it has received a message.
272 void ForwardGestureEventWithLatencyInfo(
273 const blink::WebGestureEvent& gesture_event,
274 const ui::LatencyInfo& ui_latency);
275 void ForwardTouchEventWithLatencyInfo(
276 const blink::WebTouchEvent& touch_event,
277 const ui::LatencyInfo& ui_latency);
278 void ForwardMouseEventWithLatencyInfo(
279 const blink::WebMouseEvent& mouse_event,
280 const ui::LatencyInfo& ui_latency);
281 void ForwardWheelEventWithLatencyInfo(
282 const blink::WebMouseWheelEvent& wheel_event,
283 const ui::LatencyInfo& ui_latency);
285 // Enables/disables touch emulation using mouse event. See TouchEmulator.
286 void SetTouchEventEmulationEnabled(
287 bool enabled, ui::GestureProviderConfigType config_type);
289 // TouchEmulatorClient implementation.
290 void ForwardGestureEvent(
291 const blink::WebGestureEvent& gesture_event) override;
292 void ForwardEmulatedTouchEvent(
293 const blink::WebTouchEvent& touch_event) override;
294 void SetCursor(const WebCursor& cursor) override;
295 void ShowContextMenuAtPoint(const gfx::Point& point) override;
297 // Queues a synthetic gesture for testing purposes. Invokes the on_complete
298 // callback when the gesture is finished running.
299 void QueueSyntheticGesture(
300 scoped_ptr<SyntheticGesture> synthetic_gesture,
301 const base::Callback<void(SyntheticGesture::Result)>& on_complete);
303 void CancelUpdateTextDirection();
305 // Notifies the renderer whether or not the input method attached to this
306 // process is activated.
307 // When the input method is activated, a renderer process sends IPC messages
308 // to notify the status of its composition node. (This message is mainly used
309 // for notifying the position of the input cursor so that the browser can
310 // display input method windows under the cursor.)
311 void SetInputMethodActive(bool activate);
313 // Notifies the renderer changes of IME candidate window state.
314 void CandidateWindowShown();
315 void CandidateWindowUpdated();
316 void CandidateWindowHidden();
318 // Update the composition node of the renderer (or WebKit).
319 // WebKit has a special node (a composition node) for input method to change
320 // its text without affecting any other DOM nodes. When the input method
321 // (attached to the browser) updates its text, the browser sends IPC messages
322 // to update the composition node of the renderer.
323 // (Read the comments of each function for its detail.)
325 // Sets the text of the composition node.
326 // This function can also update the cursor position and mark the specified
327 // range in the composition node.
328 // A browser should call this function:
329 // * when it receives a WM_IME_COMPOSITION message with a GCS_COMPSTR flag
330 // (on Windows);
331 // * when it receives a "preedit_changed" signal of GtkIMContext (on Linux);
332 // * when markedText of NSTextInput is called (on Mac).
333 void ImeSetComposition(
334 const base::string16& text,
335 const std::vector<blink::WebCompositionUnderline>& underlines,
336 int selection_start,
337 int selection_end);
339 // Finishes an ongoing composition with the specified text.
340 // A browser should call this function:
341 // * when it receives a WM_IME_COMPOSITION message with a GCS_RESULTSTR flag
342 // (on Windows);
343 // * when it receives a "commit" signal of GtkIMContext (on Linux);
344 // * when insertText of NSTextInput is called (on Mac).
345 void ImeConfirmComposition(const base::string16& text,
346 const gfx::Range& replacement_range,
347 bool keep_selection);
349 // Cancels an ongoing composition.
350 void ImeCancelComposition();
352 // This is for derived classes to give us access to the resizer rect.
353 // And to also expose it to the RenderWidgetHostView.
354 virtual gfx::Rect GetRootWindowResizerRect() const;
356 bool ignore_input_events() const {
357 return ignore_input_events_;
360 bool input_method_active() const {
361 return input_method_active_;
364 // Whether forwarded WebInputEvents should be ignored. True if either
365 // |ignore_input_events_| or |process_->IgnoreInputEvents()| is true.
366 bool IgnoreInputEvents() const;
368 bool has_touch_handler() const { return has_touch_handler_; }
370 // Notification that the user has made some kind of input that could
371 // perform an action. See OnUserGesture for more details.
372 void StartUserGesture();
374 // Set the RenderView background transparency.
375 void SetBackgroundOpaque(bool opaque);
377 // Notifies the renderer that the next key event is bound to one or more
378 // pre-defined edit commands
379 void SetEditCommandsForNextKeyEvent(
380 const std::vector<EditCommand>& commands);
382 // Executes the edit command on the RenderView.
383 void ExecuteEditCommand(const std::string& command,
384 const std::string& value);
386 // Tells the renderer to scroll the currently focused node into rect only if
387 // the currently focused node is a Text node (textfield, text area or content
388 // editable divs).
389 void ScrollFocusedEditableNodeIntoRect(const gfx::Rect& rect);
391 // Requests the renderer to move the caret selection towards the point.
392 void MoveCaret(const gfx::Point& point);
394 // Called when the reponse to a pending mouse lock request has arrived.
395 // Returns true if |allowed| is true and the mouse has been successfully
396 // locked.
397 bool GotResponseToLockMouseRequest(bool allowed);
399 // Tells the RenderWidget about the latest vsync parameters.
400 virtual void UpdateVSyncParameters(base::TimeTicks timebase,
401 base::TimeDelta interval);
403 // Called by the view in response to OnSwapCompositorFrame.
404 static void SendSwapCompositorFrameAck(
405 int32 route_id,
406 uint32 output_surface_id,
407 int renderer_host_id,
408 const cc::CompositorFrameAck& ack);
410 // Called by the view to return resources to the compositor.
411 static void SendReclaimCompositorResources(int32 route_id,
412 uint32 output_surface_id,
413 int renderer_host_id,
414 const cc::CompositorFrameAck& ack);
416 void set_allow_privileged_mouse_lock(bool allow) {
417 allow_privileged_mouse_lock_ = allow;
420 // Resets state variables related to tracking pending size and painting.
422 // We need to reset these flags when we want to repaint the contents of
423 // browser plugin in this RWH. Resetting these flags will ensure we ignore
424 // any previous pending acks that are not relevant upon repaint.
425 void ResetSizeAndRepaintPendingFlags();
427 void DetachDelegate();
429 // Update the renderer's cache of the screen rect of the view and window.
430 void SendScreenRects();
432 // Suppreses future char events until a keydown. See
433 // suppress_next_char_events_.
434 void SuppressNextCharEvents();
436 // Called by the view in response to a flush request.
437 void FlushInput();
439 // Request a flush signal from the view.
440 void SetNeedsFlush();
442 // Indicates whether the renderer drives the RenderWidgetHosts's size or the
443 // other way around.
444 bool auto_resize_enabled() { return auto_resize_enabled_; }
446 // The minimum size of this renderer when auto-resize is enabled.
447 const gfx::Size& min_size_for_auto_resize() const {
448 return min_size_for_auto_resize_;
451 // The maximum size of this renderer when auto-resize is enabled.
452 const gfx::Size& max_size_for_auto_resize() const {
453 return max_size_for_auto_resize_;
456 void FrameSwapped(const ui::LatencyInfo& latency_info);
457 void DidReceiveRendererFrame();
459 // Returns the ID that uniquely describes this component to the latency
460 // subsystem.
461 int64 GetLatencyComponentId() const;
463 base::TimeDelta GetEstimatedBrowserCompositeTime() const;
465 static void CompositorFrameDrawn(
466 const std::vector<ui::LatencyInfo>& latency_info);
468 // Don't check whether we expected a resize ack during layout tests.
469 static void DisableResizeAckCheckForTesting();
471 InputRouter* input_router() { return input_router_.get(); }
473 // Get the BrowserAccessibilityManager for the root of the frame tree,
474 BrowserAccessibilityManager* GetRootBrowserAccessibilityManager();
476 // Get the BrowserAccessibilityManager for the root of the frame tree,
477 // or create it if it doesn't already exist.
478 BrowserAccessibilityManager* GetOrCreateRootBrowserAccessibilityManager();
480 void RejectMouseLockOrUnlockIfNecessary();
482 #if defined(OS_WIN)
483 gfx::NativeViewAccessible GetParentNativeViewAccessible();
484 #endif
486 protected:
487 RenderWidgetHostImpl* AsRenderWidgetHostImpl() override;
489 // Called when we receive a notification indicating that the renderer
490 // process has gone. This will reset our state so that our state will be
491 // consistent if a new renderer is created.
492 void RendererExited(base::TerminationStatus status, int exit_code);
494 // Retrieves an id the renderer can use to refer to its view.
495 // This is used for various IPC messages, including plugins.
496 gfx::NativeViewId GetNativeViewId() const;
498 // Retrieves an id for the surface that the renderer can draw to
499 // when accelerated compositing is enabled.
500 gfx::GLSurfaceHandle GetCompositingSurface();
502 // ---------------------------------------------------------------------------
503 // The following methods are overridden by RenderViewHost to send upwards to
504 // its delegate.
506 // Called when a mousewheel event was not processed by the renderer.
507 virtual void UnhandledWheelEvent(const blink::WebMouseWheelEvent& event) {}
509 // Notification that the user has made some kind of input that could
510 // perform an action. The gestures that count are 1) any mouse down
511 // event and 2) enter or space key presses.
512 virtual void OnUserGesture() {}
514 // Callbacks for notification when the renderer becomes unresponsive to user
515 // input events, and subsequently responsive again.
516 virtual void NotifyRendererUnresponsive() {}
517 virtual void NotifyRendererResponsive() {}
519 // Called when auto-resize resulted in the renderer size changing.
520 virtual void OnRenderAutoResized(const gfx::Size& new_size) {}
522 // ---------------------------------------------------------------------------
524 // RenderViewHost overrides this method to impose further restrictions on when
525 // to allow mouse lock.
526 // Once the request is approved or rejected, GotResponseToLockMouseRequest()
527 // will be called.
528 virtual void RequestToLockMouse(bool user_gesture,
529 bool last_unlocked_by_target);
531 bool IsMouseLocked() const;
533 // RenderViewHost overrides this method to report whether tab-initiated
534 // fullscreen was granted.
535 virtual bool IsFullscreenGranted() const;
537 virtual blink::WebDisplayMode GetDisplayMode() const;
539 // Indicates if the render widget host should track the render widget's size
540 // as opposed to visa versa.
541 void SetAutoResize(bool enable,
542 const gfx::Size& min_size,
543 const gfx::Size& max_size);
545 // Fills in the |resize_params| struct.
546 // Returns |false| if the update is redundant, |true| otherwise.
547 bool GetResizeParams(ViewMsg_Resize_Params* resize_params);
549 // Sets the |resize_params| that were sent to the renderer bundled with the
550 // request to create a new RenderWidget.
551 void SetInitialRenderSizeParams(const ViewMsg_Resize_Params& resize_params);
553 // Expose increment/decrement of the in-flight event count, so
554 // RenderViewHostImpl can account for in-flight beforeunload/unload events.
555 int increment_in_flight_event_count() { return ++in_flight_event_count_; }
556 int decrement_in_flight_event_count() {
557 DCHECK_GT(in_flight_event_count_, 0);
558 return --in_flight_event_count_;
561 void set_renderer_initialized(bool renderer_initialized) {
562 renderer_initialized_ = renderer_initialized;
565 bool renderer_initialized() const { return renderer_initialized_; }
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 // This value indicates how long to wait before we consider a renderer hung.
581 base::TimeDelta hung_renderer_delay_;
583 private:
584 friend class MockRenderWidgetHost;
586 // Tell this object to destroy itself.
587 void Destroy();
589 // Called by |hang_monitor_timeout_| on delayed response from the renderer.
590 void RendererIsUnresponsive();
592 // Called if we know the renderer is responsive. When we currently think the
593 // renderer is unresponsive, this will clear that state and call
594 // NotifyRendererResponsive.
595 void RendererIsResponsive();
597 // IPC message handlers
598 void OnRenderViewReady();
599 void OnRenderProcessGone(int status, int error_code);
600 void OnClose();
601 void OnUpdateScreenRectsAck();
602 void OnRequestMove(const gfx::Rect& pos);
603 void OnSetTooltipText(const base::string16& tooltip_text,
604 blink::WebTextDirection text_direction_hint);
605 bool OnSwapCompositorFrame(const IPC::Message& message);
606 void OnUpdateRect(const ViewHostMsg_UpdateRect_Params& params);
607 void OnQueueSyntheticGesture(const SyntheticGesturePacket& gesture_packet);
608 virtual void OnFocus();
609 virtual void OnBlur();
610 void OnSetCursor(const WebCursor& cursor);
611 void OnTextInputTypeChanged(ui::TextInputType type,
612 ui::TextInputMode input_mode,
613 bool can_compose_inline,
614 int flags);
616 void OnImeCompositionRangeChanged(
617 const gfx::Range& range,
618 const std::vector<gfx::Rect>& character_bounds);
619 void OnImeCancelComposition();
620 void OnLockMouse(bool user_gesture,
621 bool last_unlocked_by_target,
622 bool privileged);
623 void OnUnlockMouse();
624 void OnShowDisambiguationPopup(const gfx::Rect& rect_pixels,
625 const gfx::Size& size,
626 const cc::SharedBitmapId& id);
627 #if defined(OS_WIN)
628 void OnWindowlessPluginDummyWindowCreated(
629 gfx::NativeViewId dummy_activation_window);
630 void OnWindowlessPluginDummyWindowDestroyed(
631 gfx::NativeViewId dummy_activation_window);
632 #endif
633 void OnSelectionChanged(const base::string16& text,
634 size_t offset,
635 const gfx::Range& range);
636 void OnSelectionBoundsChanged(
637 const ViewHostMsg_SelectionBounds_Params& params);
638 void OnSnapshot(bool success, const SkBitmap& bitmap);
640 // Called (either immediately or asynchronously) after we're done with our
641 // BackingStore and can send an ACK to the renderer so it can paint onto it
642 // again.
643 void DidUpdateBackingStore(const ViewHostMsg_UpdateRect_Params& params,
644 const base::TimeTicks& paint_start);
646 // Give key press listeners a chance to handle this key press. This allow
647 // widgets that don't have focus to still handle key presses.
648 bool KeyPressListenersHandleEvent(const NativeWebKeyboardEvent& event);
650 // InputRouterClient
651 InputEventAckState FilterInputEvent(
652 const blink::WebInputEvent& event,
653 const ui::LatencyInfo& latency_info) override;
654 void IncrementInFlightEventCount() override;
655 void DecrementInFlightEventCount() override;
656 void OnHasTouchEventHandlers(bool has_handlers) override;
657 void DidFlush() override;
658 void DidOverscroll(const DidOverscrollParams& params) override;
659 void DidStopFlinging() override;
661 // InputAckHandler
662 void OnKeyboardEventAck(const NativeWebKeyboardEvent& event,
663 InputEventAckState ack_result) override;
664 void OnWheelEventAck(const MouseWheelEventWithLatencyInfo& event,
665 InputEventAckState ack_result) override;
666 void OnTouchEventAck(const TouchEventWithLatencyInfo& event,
667 InputEventAckState ack_result) override;
668 void OnGestureEventAck(const GestureEventWithLatencyInfo& event,
669 InputEventAckState ack_result) override;
670 void OnUnexpectedEventAck(UnexpectedEventAckType type) override;
672 void OnSyntheticGestureCompleted(SyntheticGesture::Result result);
674 // Called when there is a new auto resize (using a post to avoid a stack
675 // which may get in recursive loops).
676 void DelayedAutoResized();
678 void WindowSnapshotReachedScreen(int snapshot_id);
680 void OnSnapshotDataReceived(int snapshot_id,
681 const unsigned char* png,
682 size_t size);
684 void OnSnapshotDataReceivedAsync(
685 int snapshot_id,
686 scoped_refptr<base::RefCountedBytes> png_data);
688 // true if a renderer has once been valid. We use this flag to display a sad
689 // tab only when we lose our renderer and not if a paint occurs during
690 // initialization.
691 bool renderer_initialized_;
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 // The current size of the RenderWidget.
722 gfx::Size current_size_;
724 // Resize information that was previously sent to the renderer.
725 scoped_ptr<ViewMsg_Resize_Params> old_resize_params_;
727 // The next auto resize to send.
728 gfx::Size new_auto_size_;
730 // True if the render widget host should track the render widget's size as
731 // opposed to visa versa.
732 bool auto_resize_enabled_;
734 // The minimum size for the render widget if auto-resize is enabled.
735 gfx::Size min_size_for_auto_resize_;
737 // The maximum size for the render widget if auto-resize is enabled.
738 gfx::Size max_size_for_auto_resize_;
740 bool waiting_for_screen_rects_ack_;
741 gfx::Rect last_view_screen_rect_;
742 gfx::Rect last_window_screen_rect_;
744 // Keyboard event listeners.
745 std::vector<KeyPressEventCallback> key_press_event_callbacks_;
747 // Mouse event callbacks.
748 std::vector<MouseEventCallback> mouse_event_callbacks_;
750 // If true, then we should repaint when restoring even if we have a
751 // backingstore. This flag is set to true if we receive a paint message
752 // while is_hidden_ to true. Even though we tell the render widget to hide
753 // itself, a paint message could already be in flight at that point.
754 bool needs_repainting_on_restore_;
756 // This is true if the renderer is currently unresponsive.
757 bool is_unresponsive_;
759 // This value denotes the number of input events yet to be acknowledged
760 // by the renderer.
761 int in_flight_event_count_;
763 // Flag to detect recursive calls to GetBackingStore().
764 bool in_get_backing_store_;
766 // Used for UMA histogram logging to measure the time for a repaint view
767 // operation to finish.
768 base::TimeTicks repaint_start_time_;
770 // Set to true if we shouldn't send input events from the render widget.
771 bool ignore_input_events_;
773 // Indicates whether IME is active.
774 bool input_method_active_;
776 // Set when we update the text direction of the selected input element.
777 bool text_direction_updated_;
778 blink::WebTextDirection text_direction_;
780 // Set when we cancel updating the text direction.
781 // This flag also ignores succeeding update requests until we call
782 // NotifyTextDirection().
783 bool text_direction_canceled_;
785 // Indicates if the next sequence of Char events should be suppressed or not.
786 // System may translate a RawKeyDown event into zero or more Char events,
787 // usually we send them to the renderer directly in sequence. However, If a
788 // RawKeyDown event was not handled by the renderer but was handled by
789 // our UnhandledKeyboardEvent() method, e.g. as an accelerator key, then we
790 // shall not send the following sequence of Char events, which was generated
791 // by this RawKeyDown event, to the renderer. Otherwise the renderer may
792 // handle the Char events and cause unexpected behavior.
793 // For example, pressing alt-2 may let the browser switch to the second tab,
794 // but the Char event generated by alt-2 may also activate a HTML element
795 // if its accesskey happens to be "2", then the user may get confused when
796 // switching back to the original tab, because the content may already be
797 // changed.
798 bool suppress_next_char_events_;
800 bool pending_mouse_lock_request_;
801 bool allow_privileged_mouse_lock_;
803 // Keeps track of whether the webpage has any touch event handler. If it does,
804 // then touch events are sent to the renderer. Otherwise, the touch events are
805 // not sent to the renderer.
806 bool has_touch_handler_;
808 scoped_ptr<SyntheticGestureController> synthetic_gesture_controller_;
810 scoped_ptr<TouchEmulator> touch_emulator_;
812 // Receives and handles all input events.
813 scoped_ptr<InputRouter> input_router_;
815 scoped_ptr<TimeoutMonitor> hang_monitor_timeout_;
817 #if defined(OS_WIN)
818 std::list<HWND> dummy_windows_for_activation_;
819 #endif
821 RenderWidgetHostLatencyTracker latency_tracker_;
823 int next_browser_snapshot_id_;
824 typedef std::map<int,
825 base::Callback<void(const unsigned char*, size_t)> > PendingSnapshotMap;
826 PendingSnapshotMap pending_browser_snapshots_;
828 // Indicates whether a RenderFramehost has ownership, in which case this
829 // object does not self destroy.
830 bool owned_by_render_frame_host_;
832 // Indicates whether this RenderWidgetHost thinks is focused. This is trying
833 // to match what the renderer process knows. It is different from
834 // RenderWidgetHostView::HasFocus in that in that the focus request may fail,
835 // causing HasFocus to return false when is_focused_ is true.
836 bool is_focused_;
838 base::WeakPtrFactory<RenderWidgetHostImpl> weak_factory_;
840 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostImpl);
843 } // namespace content
845 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_IMPL_H_