Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / content / browser / renderer_host / render_widget_host_impl.h
blob331e84f297c5f51f053ebe8209463a12794c90a9
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 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 SkColorType PreferredReadbackFormat() override;
168 // Forces redraw in the renderer and when the update reaches the browser
169 // grabs snapshot from the compositor. Returns PNG-encoded snapshot.
170 void GetSnapshotFromBrowser(
171 const base::Callback<void(const unsigned char*,size_t)> callback);
173 const NativeWebKeyboardEvent* GetLastKeyboardEvent() const;
175 // Notification that the screen info has changed.
176 void NotifyScreenInfoChanged();
178 // Invalidates the cached screen info so that next resize request
179 // will carry the up to date screen info. Unlike
180 // |NotifyScreenInfoChanged|, this doesn't send a message to the renderer.
181 void InvalidateScreenInfo();
183 // Sets the View of this RenderWidgetHost.
184 void SetView(RenderWidgetHostViewBase* view);
186 int surface_id() const { return surface_id_; }
188 bool empty() const { return current_size_.IsEmpty(); }
190 // Called when a renderer object already been created for this host, and we
191 // just need to be attached to it. Used for window.open, <select> dropdown
192 // menus, and other times when the renderer initiates creating an object.
193 virtual void Init();
195 // Initializes a RenderWidgetHost that is attached to a RenderFrameHost.
196 void InitForFrame();
198 // Signal whether this RenderWidgetHost is owned by a RenderFrameHost, in
199 // which case it does not do self-deletion.
200 void set_owned_by_render_frame_host(bool owned_by_rfh) {
201 owned_by_render_frame_host_ = owned_by_rfh;
204 // Called by RenderFrameHost before destroying this object.
205 void Cleanup();
207 // Tells the renderer to die and then calls Destroy().
208 virtual void Shutdown();
210 // IPC::Listener
211 bool OnMessageReceived(const IPC::Message& msg) override;
213 // Sends a message to the corresponding object in the renderer.
214 bool Send(IPC::Message* msg) override;
216 // Indicates if the page has finished loading.
217 virtual void SetIsLoading(bool is_loading);
219 // Called to notify the RenderWidget that it has been hidden or restored from
220 // having been hidden.
221 virtual void WasHidden();
222 virtual void WasShown(const ui::LatencyInfo& latency_info);
224 // Returns true if the RenderWidget is hidden.
225 bool is_hidden() const { return is_hidden_; }
227 // Called to notify the RenderWidget that its associated native window
228 // got/lost focused.
229 virtual void GotFocus();
230 virtual void LostCapture();
232 // Indicates whether the RenderWidgetHost thinks it is focused.
233 // This is different from RenderWidgetHostView::HasFocus() in the sense that
234 // it reflects what the renderer process knows: it saves the state that is
235 // sent/received.
236 // RenderWidgetHostView::HasFocus() is checking whether the view is focused so
237 // it is possible in some edge cases that a view was requested to be focused
238 // but it failed, thus HasFocus() returns false.
239 bool is_focused() const { return is_focused_; }
241 // Called to notify the RenderWidget that it has lost the mouse lock.
242 virtual void LostMouseLock();
244 // Noifies the RenderWidget of the current mouse cursor visibility state.
245 void SendCursorVisibilityState(bool is_visible);
247 // Notifies the RenderWidgetHost that the View was destroyed.
248 void ViewDestroyed();
250 #if defined(OS_MACOSX)
251 // Pause for a moment to wait for pending repaint or resize messages sent to
252 // the renderer to arrive. If pending resize messages are for an old window
253 // size, then also pump through a new resize message if there is time.
254 void PauseForPendingResizeOrRepaints();
256 // Whether pausing may be useful.
257 bool CanPauseForPendingResizeOrRepaints();
259 // Wait for a surface matching the size of the widget's view, possibly
260 // blocking until the renderer sends a new frame.
261 void WaitForSurface();
262 #endif
264 bool resize_ack_pending_for_testing() { return resize_ack_pending_; }
266 // GPU accelerated version of GetBackingStore function. This will
267 // trigger a re-composite to the view. It may fail if a resize is pending, or
268 // if a composite has already been requested and not acked yet.
269 bool ScheduleComposite();
271 // Starts a hang monitor timeout. If there's already a hang monitor timeout
272 // the new one will only fire if it has a shorter delay than the time
273 // left on the existing timeouts.
274 void StartHangMonitorTimeout(base::TimeDelta delay);
276 // Stops all existing hang monitor timeouts and assumes the renderer is
277 // responsive.
278 void StopHangMonitorTimeout();
280 // Forwards the given message to the renderer. These are called by the view
281 // when it has received a message.
282 void ForwardGestureEventWithLatencyInfo(
283 const blink::WebGestureEvent& gesture_event,
284 const ui::LatencyInfo& ui_latency);
285 void ForwardTouchEventWithLatencyInfo(
286 const blink::WebTouchEvent& touch_event,
287 const ui::LatencyInfo& ui_latency);
288 void ForwardMouseEventWithLatencyInfo(
289 const blink::WebMouseEvent& mouse_event,
290 const ui::LatencyInfo& ui_latency);
291 void ForwardWheelEventWithLatencyInfo(
292 const blink::WebMouseWheelEvent& wheel_event,
293 const ui::LatencyInfo& ui_latency);
295 // Enables/disables touch emulation using mouse event. See TouchEmulator.
296 void SetTouchEventEmulationEnabled(
297 bool enabled, ui::GestureProviderConfigType config_type);
299 // TouchEmulatorClient implementation.
300 void ForwardGestureEvent(
301 const blink::WebGestureEvent& gesture_event) override;
302 void ForwardEmulatedTouchEvent(
303 const blink::WebTouchEvent& touch_event) override;
304 void SetCursor(const WebCursor& cursor) override;
305 void ShowContextMenuAtPoint(const gfx::Point& point) override;
307 // Queues a synthetic gesture for testing purposes. Invokes the on_complete
308 // callback when the gesture is finished running.
309 void QueueSyntheticGesture(
310 scoped_ptr<SyntheticGesture> synthetic_gesture,
311 const base::Callback<void(SyntheticGesture::Result)>& on_complete);
313 void CancelUpdateTextDirection();
315 // Notifies the renderer whether or not the input method attached to this
316 // process is activated.
317 // When the input method is activated, a renderer process sends IPC messages
318 // to notify the status of its composition node. (This message is mainly used
319 // for notifying the position of the input cursor so that the browser can
320 // display input method windows under the cursor.)
321 void SetInputMethodActive(bool activate);
323 // Notifies the renderer changes of IME candidate window state.
324 void CandidateWindowShown();
325 void CandidateWindowUpdated();
326 void CandidateWindowHidden();
328 // Update the composition node of the renderer (or WebKit).
329 // WebKit has a special node (a composition node) for input method to change
330 // its text without affecting any other DOM nodes. When the input method
331 // (attached to the browser) updates its text, the browser sends IPC messages
332 // to update the composition node of the renderer.
333 // (Read the comments of each function for its detail.)
335 // Sets the text of the composition node.
336 // This function can also update the cursor position and mark the specified
337 // range in the composition node.
338 // A browser should call this function:
339 // * when it receives a WM_IME_COMPOSITION message with a GCS_COMPSTR flag
340 // (on Windows);
341 // * when it receives a "preedit_changed" signal of GtkIMContext (on Linux);
342 // * when markedText of NSTextInput is called (on Mac).
343 void ImeSetComposition(
344 const base::string16& text,
345 const std::vector<blink::WebCompositionUnderline>& underlines,
346 int selection_start,
347 int selection_end);
349 // Finishes an ongoing composition with the specified text.
350 // A browser should call this function:
351 // * when it receives a WM_IME_COMPOSITION message with a GCS_RESULTSTR flag
352 // (on Windows);
353 // * when it receives a "commit" signal of GtkIMContext (on Linux);
354 // * when insertText of NSTextInput is called (on Mac).
355 void ImeConfirmComposition(const base::string16& text,
356 const gfx::Range& replacement_range,
357 bool keep_selection);
359 // Cancels an ongoing composition.
360 void ImeCancelComposition();
362 // This is for derived classes to give us access to the resizer rect.
363 // And to also expose it to the RenderWidgetHostView.
364 virtual gfx::Rect GetRootWindowResizerRect() const;
366 bool ignore_input_events() const {
367 return ignore_input_events_;
370 bool input_method_active() const {
371 return input_method_active_;
374 // Whether forwarded WebInputEvents should be ignored. True if either
375 // |ignore_input_events_| or |process_->IgnoreInputEvents()| is true.
376 bool IgnoreInputEvents() const;
378 bool has_touch_handler() const { return has_touch_handler_; }
380 // Notification that the user has made some kind of input that could
381 // perform an action. See OnUserGesture for more details.
382 void StartUserGesture();
384 // Set the RenderView background transparency.
385 void SetBackgroundOpaque(bool opaque);
387 // Notifies the renderer that the next key event is bound to one or more
388 // pre-defined edit commands
389 void SetEditCommandsForNextKeyEvent(
390 const std::vector<EditCommand>& commands);
392 // Executes the edit command on the RenderView.
393 void ExecuteEditCommand(const std::string& command,
394 const std::string& value);
396 // Tells the renderer to scroll the currently focused node into rect only if
397 // the currently focused node is a Text node (textfield, text area or content
398 // editable divs).
399 void ScrollFocusedEditableNodeIntoRect(const gfx::Rect& rect);
401 // Requests the renderer to move the caret selection towards the point.
402 void MoveCaret(const gfx::Point& point);
404 // Called when the reponse to a pending mouse lock request has arrived.
405 // Returns true if |allowed| is true and the mouse has been successfully
406 // locked.
407 bool GotResponseToLockMouseRequest(bool allowed);
409 // Tells the RenderWidget about the latest vsync parameters.
410 virtual void UpdateVSyncParameters(base::TimeTicks timebase,
411 base::TimeDelta interval);
413 // Called by the view in response to OnSwapCompositorFrame.
414 static void SendSwapCompositorFrameAck(
415 int32 route_id,
416 uint32 output_surface_id,
417 int renderer_host_id,
418 const cc::CompositorFrameAck& ack);
420 // Called by the view to return resources to the compositor.
421 static void SendReclaimCompositorResources(int32 route_id,
422 uint32 output_surface_id,
423 int renderer_host_id,
424 const cc::CompositorFrameAck& ack);
426 void set_allow_privileged_mouse_lock(bool allow) {
427 allow_privileged_mouse_lock_ = allow;
430 // Resets state variables related to tracking pending size and painting.
432 // We need to reset these flags when we want to repaint the contents of
433 // browser plugin in this RWH. Resetting these flags will ensure we ignore
434 // any previous pending acks that are not relevant upon repaint.
435 void ResetSizeAndRepaintPendingFlags();
437 void DetachDelegate();
439 // Update the renderer's cache of the screen rect of the view and window.
440 void SendScreenRects();
442 // Suppreses future char events until a keydown. See
443 // suppress_next_char_events_.
444 void SuppressNextCharEvents();
446 // Called by the view in response to a flush request.
447 void FlushInput();
449 // Request a flush signal from the view.
450 void SetNeedsFlush();
452 // Indicates whether the renderer drives the RenderWidgetHosts's size or the
453 // other way around.
454 bool auto_resize_enabled() { return auto_resize_enabled_; }
456 // The minimum size of this renderer when auto-resize is enabled.
457 const gfx::Size& min_size_for_auto_resize() const {
458 return min_size_for_auto_resize_;
461 // The maximum size of this renderer when auto-resize is enabled.
462 const gfx::Size& max_size_for_auto_resize() const {
463 return max_size_for_auto_resize_;
466 void FrameSwapped(const ui::LatencyInfo& latency_info);
467 void DidReceiveRendererFrame();
469 // Returns the ID that uniquely describes this component to the latency
470 // subsystem.
471 int64 GetLatencyComponentId() const;
473 base::TimeDelta GetEstimatedBrowserCompositeTime() const;
475 static void CompositorFrameDrawn(
476 const std::vector<ui::LatencyInfo>& latency_info);
478 // Don't check whether we expected a resize ack during layout tests.
479 static void DisableResizeAckCheckForTesting();
481 InputRouter* input_router() { return input_router_.get(); }
483 // Get the BrowserAccessibilityManager for the root of the frame tree,
484 BrowserAccessibilityManager* GetRootBrowserAccessibilityManager();
486 // Get the BrowserAccessibilityManager for the root of the frame tree,
487 // or create it if it doesn't already exist.
488 BrowserAccessibilityManager* GetOrCreateRootBrowserAccessibilityManager();
490 void RejectMouseLockOrUnlockIfNecessary();
492 #if defined(OS_WIN)
493 gfx::NativeViewAccessible GetParentNativeViewAccessible();
494 #endif
496 protected:
497 RenderWidgetHostImpl* AsRenderWidgetHostImpl() override;
499 // Called when we receive a notification indicating that the renderer
500 // process has gone. This will reset our state so that our state will be
501 // consistent if a new renderer is created.
502 void RendererExited(base::TerminationStatus status, int exit_code);
504 // Retrieves an id the renderer can use to refer to its view.
505 // This is used for various IPC messages, including plugins.
506 gfx::NativeViewId GetNativeViewId() const;
508 // Retrieves an id for the surface that the renderer can draw to
509 // when accelerated compositing is enabled.
510 gfx::GLSurfaceHandle GetCompositingSurface();
512 // ---------------------------------------------------------------------------
513 // The following methods are overridden by RenderViewHost to send upwards to
514 // its delegate.
516 // Called when a mousewheel event was not processed by the renderer.
517 virtual void UnhandledWheelEvent(const blink::WebMouseWheelEvent& event) {}
519 // Notification that the user has made some kind of input that could
520 // perform an action. The gestures that count are 1) any mouse down
521 // event and 2) enter or space key presses.
522 virtual void OnUserGesture() {}
524 // Callbacks for notification when the renderer becomes unresponsive to user
525 // input events, and subsequently responsive again.
526 virtual void NotifyRendererUnresponsive() {}
527 virtual void NotifyRendererResponsive() {}
529 // Called when auto-resize resulted in the renderer size changing.
530 virtual void OnRenderAutoResized(const gfx::Size& new_size) {}
532 // ---------------------------------------------------------------------------
534 // RenderViewHost overrides this method to impose further restrictions on when
535 // to allow mouse lock.
536 // Once the request is approved or rejected, GotResponseToLockMouseRequest()
537 // will be called.
538 virtual void RequestToLockMouse(bool user_gesture,
539 bool last_unlocked_by_target);
541 bool IsMouseLocked() const;
543 // RenderViewHost overrides this method to report whether tab-initiated
544 // fullscreen was granted.
545 virtual bool IsFullscreenGranted() const;
547 virtual blink::WebDisplayMode GetDisplayMode() const;
549 // Indicates if the render widget host should track the render widget's size
550 // as opposed to visa versa.
551 void SetAutoResize(bool enable,
552 const gfx::Size& min_size,
553 const gfx::Size& max_size);
555 // Fills in the |resize_params| struct.
556 // Returns |false| if the update is redundant, |true| otherwise.
557 bool GetResizeParams(ViewMsg_Resize_Params* resize_params);
559 // Sets the |resize_params| that were sent to the renderer bundled with the
560 // request to create a new RenderWidget.
561 void SetInitialRenderSizeParams(const ViewMsg_Resize_Params& resize_params);
563 // Expose increment/decrement of the in-flight event count, so
564 // RenderViewHostImpl can account for in-flight beforeunload/unload events.
565 int increment_in_flight_event_count() { return ++in_flight_event_count_; }
566 int decrement_in_flight_event_count() {
567 DCHECK_GT(in_flight_event_count_, 0);
568 return --in_flight_event_count_;
571 void set_renderer_initialized(bool renderer_initialized) {
572 renderer_initialized_ = renderer_initialized;
575 bool renderer_initialized() const { return renderer_initialized_; }
577 // The View associated with the RenderViewHost. The lifetime of this object
578 // is associated with the lifetime of the Render process. If the Renderer
579 // crashes, its View is destroyed and this pointer becomes NULL, even though
580 // render_view_host_ lives on to load another URL (creating a new View while
581 // doing so).
582 RenderWidgetHostViewBase* view_;
584 // A weak pointer to the view. The above pointer should be weak, but changing
585 // that to be weak causes crashes on Android.
586 // TODO(ccameron): Fix this.
587 // http://crbug.com/404828
588 base::WeakPtr<RenderWidgetHostViewBase> view_weak_;
590 // This value indicates how long to wait before we consider a renderer hung.
591 base::TimeDelta hung_renderer_delay_;
593 private:
594 friend class MockRenderWidgetHost;
596 // Tell this object to destroy itself.
597 void Destroy();
599 // Called by |hang_monitor_timeout_| on delayed response from the renderer.
600 void RendererIsUnresponsive();
602 // Called if we know the renderer is responsive. When we currently think the
603 // renderer is unresponsive, this will clear that state and call
604 // NotifyRendererResponsive.
605 void RendererIsResponsive();
607 // IPC message handlers
608 void OnRenderViewReady();
609 void OnRenderProcessGone(int status, int error_code);
610 void OnClose();
611 void OnUpdateScreenRectsAck();
612 void OnRequestMove(const gfx::Rect& pos);
613 void OnSetTooltipText(const base::string16& tooltip_text,
614 blink::WebTextDirection text_direction_hint);
615 bool OnSwapCompositorFrame(const IPC::Message& message);
616 void OnUpdateRect(const ViewHostMsg_UpdateRect_Params& params);
617 void OnQueueSyntheticGesture(const SyntheticGesturePacket& gesture_packet);
618 virtual void OnFocus();
619 virtual void OnBlur();
620 void OnSetCursor(const WebCursor& cursor);
621 void OnTextInputTypeChanged(ui::TextInputType type,
622 ui::TextInputMode input_mode,
623 bool can_compose_inline,
624 int flags);
626 void OnImeCompositionRangeChanged(
627 const gfx::Range& range,
628 const std::vector<gfx::Rect>& character_bounds);
629 void OnImeCancelComposition();
630 void OnLockMouse(bool user_gesture,
631 bool last_unlocked_by_target,
632 bool privileged);
633 void OnUnlockMouse();
634 void OnShowDisambiguationPopup(const gfx::Rect& rect_pixels,
635 const gfx::Size& size,
636 const cc::SharedBitmapId& id);
637 #if defined(OS_WIN)
638 void OnWindowlessPluginDummyWindowCreated(
639 gfx::NativeViewId dummy_activation_window);
640 void OnWindowlessPluginDummyWindowDestroyed(
641 gfx::NativeViewId dummy_activation_window);
642 #endif
643 void OnSelectionChanged(const base::string16& text,
644 size_t offset,
645 const gfx::Range& range);
646 void OnSelectionBoundsChanged(
647 const ViewHostMsg_SelectionBounds_Params& params);
648 void OnSnapshot(bool success, const SkBitmap& bitmap);
650 // Called (either immediately or asynchronously) after we're done with our
651 // BackingStore and can send an ACK to the renderer so it can paint onto it
652 // again.
653 void DidUpdateBackingStore(const ViewHostMsg_UpdateRect_Params& params,
654 const base::TimeTicks& paint_start);
656 // Give key press listeners a chance to handle this key press. This allow
657 // widgets that don't have focus to still handle key presses.
658 bool KeyPressListenersHandleEvent(const NativeWebKeyboardEvent& event);
660 // InputRouterClient
661 InputEventAckState FilterInputEvent(
662 const blink::WebInputEvent& event,
663 const ui::LatencyInfo& latency_info) override;
664 void IncrementInFlightEventCount() override;
665 void DecrementInFlightEventCount() override;
666 void OnHasTouchEventHandlers(bool has_handlers) override;
667 void DidFlush() override;
668 void DidOverscroll(const DidOverscrollParams& params) override;
669 void DidStopFlinging() override;
671 // InputAckHandler
672 void OnKeyboardEventAck(const NativeWebKeyboardEvent& event,
673 InputEventAckState ack_result) override;
674 void OnWheelEventAck(const MouseWheelEventWithLatencyInfo& event,
675 InputEventAckState ack_result) override;
676 void OnTouchEventAck(const TouchEventWithLatencyInfo& event,
677 InputEventAckState ack_result) override;
678 void OnGestureEventAck(const GestureEventWithLatencyInfo& event,
679 InputEventAckState ack_result) override;
680 void OnUnexpectedEventAck(UnexpectedEventAckType type) override;
682 void OnSyntheticGestureCompleted(SyntheticGesture::Result result);
684 // Called when there is a new auto resize (using a post to avoid a stack
685 // which may get in recursive loops).
686 void DelayedAutoResized();
688 void WindowSnapshotReachedScreen(int snapshot_id);
690 void OnSnapshotDataReceived(int snapshot_id,
691 const unsigned char* png,
692 size_t size);
694 void OnSnapshotDataReceivedAsync(
695 int snapshot_id,
696 scoped_refptr<base::RefCountedBytes> png_data);
698 // true if a renderer has once been valid. We use this flag to display a sad
699 // tab only when we lose our renderer and not if a paint occurs during
700 // initialization.
701 bool renderer_initialized_;
703 // Our delegate, which wants to know mainly about keyboard events.
704 // It will remain non-NULL until DetachDelegate() is called.
705 RenderWidgetHostDelegate* delegate_;
707 // Created during construction but initialized during Init*(). Therefore, it
708 // is guaranteed never to be NULL, but its channel may be NULL if the
709 // renderer crashed, so you must always check that.
710 RenderProcessHost* process_;
712 // The ID of the corresponding object in the Renderer Instance.
713 int routing_id_;
715 // The ID of the surface corresponding to this render widget.
716 int surface_id_;
718 // Indicates whether a page is loading or not.
719 bool is_loading_;
721 // Indicates whether a page is hidden or not. It has to stay in sync with the
722 // most recent call to process_->WidgetRestored() / WidgetHidden().
723 bool is_hidden_;
725 // Set if we are waiting for a repaint ack for the view.
726 bool repaint_ack_pending_;
728 // True when waiting for RESIZE_ACK.
729 bool resize_ack_pending_;
731 // Cached copy of the screen info so that it doesn't need to be updated every
732 // time the window is resized.
733 scoped_ptr<blink::WebScreenInfo> screen_info_;
735 // Set if screen_info_ may have changed and should be recomputed and force a
736 // resize message.
737 bool screen_info_out_of_date_;
739 // The current size of the RenderWidget.
740 gfx::Size current_size_;
742 // Resize information that was previously sent to the renderer.
743 scoped_ptr<ViewMsg_Resize_Params> old_resize_params_;
745 // The next auto resize to send.
746 gfx::Size new_auto_size_;
748 // True if the render widget host should track the render widget's size as
749 // opposed to visa versa.
750 bool auto_resize_enabled_;
752 // The minimum size for the render widget if auto-resize is enabled.
753 gfx::Size min_size_for_auto_resize_;
755 // The maximum size for the render widget if auto-resize is enabled.
756 gfx::Size max_size_for_auto_resize_;
758 bool waiting_for_screen_rects_ack_;
759 gfx::Rect last_view_screen_rect_;
760 gfx::Rect last_window_screen_rect_;
762 // Keyboard event listeners.
763 std::vector<KeyPressEventCallback> key_press_event_callbacks_;
765 // Mouse event callbacks.
766 std::vector<MouseEventCallback> mouse_event_callbacks_;
768 // If true, then we should repaint when restoring even if we have a
769 // backingstore. This flag is set to true if we receive a paint message
770 // while is_hidden_ to true. Even though we tell the render widget to hide
771 // itself, a paint message could already be in flight at that point.
772 bool needs_repainting_on_restore_;
774 // This is true if the renderer is currently unresponsive.
775 bool is_unresponsive_;
777 // This value denotes the number of input events yet to be acknowledged
778 // by the renderer.
779 int in_flight_event_count_;
781 // Flag to detect recursive calls to GetBackingStore().
782 bool in_get_backing_store_;
784 // Used for UMA histogram logging to measure the time for a repaint view
785 // operation to finish.
786 base::TimeTicks repaint_start_time_;
788 // Set to true if we shouldn't send input events from the render widget.
789 bool ignore_input_events_;
791 // Indicates whether IME is active.
792 bool input_method_active_;
794 // Set when we update the text direction of the selected input element.
795 bool text_direction_updated_;
796 blink::WebTextDirection text_direction_;
798 // Set when we cancel updating the text direction.
799 // This flag also ignores succeeding update requests until we call
800 // NotifyTextDirection().
801 bool text_direction_canceled_;
803 // Indicates if the next sequence of Char events should be suppressed or not.
804 // System may translate a RawKeyDown event into zero or more Char events,
805 // usually we send them to the renderer directly in sequence. However, If a
806 // RawKeyDown event was not handled by the renderer but was handled by
807 // our UnhandledKeyboardEvent() method, e.g. as an accelerator key, then we
808 // shall not send the following sequence of Char events, which was generated
809 // by this RawKeyDown event, to the renderer. Otherwise the renderer may
810 // handle the Char events and cause unexpected behavior.
811 // For example, pressing alt-2 may let the browser switch to the second tab,
812 // but the Char event generated by alt-2 may also activate a HTML element
813 // if its accesskey happens to be "2", then the user may get confused when
814 // switching back to the original tab, because the content may already be
815 // changed.
816 bool suppress_next_char_events_;
818 bool pending_mouse_lock_request_;
819 bool allow_privileged_mouse_lock_;
821 // Keeps track of whether the webpage has any touch event handler. If it does,
822 // then touch events are sent to the renderer. Otherwise, the touch events are
823 // not sent to the renderer.
824 bool has_touch_handler_;
826 scoped_ptr<SyntheticGestureController> synthetic_gesture_controller_;
828 scoped_ptr<TouchEmulator> touch_emulator_;
830 // Receives and handles all input events.
831 scoped_ptr<InputRouter> input_router_;
833 scoped_ptr<TimeoutMonitor> hang_monitor_timeout_;
835 #if defined(OS_WIN)
836 std::list<HWND> dummy_windows_for_activation_;
837 #endif
839 RenderWidgetHostLatencyTracker latency_tracker_;
841 int next_browser_snapshot_id_;
842 typedef std::map<int,
843 base::Callback<void(const unsigned char*, size_t)> > PendingSnapshotMap;
844 PendingSnapshotMap pending_browser_snapshots_;
846 // Indicates whether a RenderFramehost has ownership, in which case this
847 // object does not self destroy.
848 bool owned_by_render_frame_host_;
850 // Indicates whether this RenderWidgetHost thinks is focused. This is trying
851 // to match what the renderer process knows. It is different from
852 // RenderWidgetHostView::HasFocus in that in that the focus request may fail,
853 // causing HasFocus to return false when is_focused_ is true.
854 bool is_focused_;
856 base::WeakPtrFactory<RenderWidgetHostImpl> weak_factory_;
858 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostImpl);
861 } // namespace content
863 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_IMPL_H_