IndexedDBFactory now ForceCloses databases.
[chromium-blink-merge.git] / content / browser / renderer_host / render_widget_host_impl.h
blob22dbdbe0084e419d51ec1af3a1f4b382b25cfe52
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 "content/browser/renderer_host/input/input_ack_handler.h"
27 #include "content/browser/renderer_host/input/input_router_client.h"
28 #include "content/common/browser_rendering_stats.h"
29 #include "content/common/input/synthetic_gesture_packet.h"
30 #include "content/common/view_message_enums.h"
31 #include "content/port/browser/event_with_latency_info.h"
32 #include "content/port/common/input_event_ack_state.h"
33 #include "content/public/browser/render_widget_host.h"
34 #include "content/public/common/page_zoom.h"
35 #include "ipc/ipc_listener.h"
36 #include "ui/base/ime/text_input_mode.h"
37 #include "ui/base/ime/text_input_type.h"
38 #include "ui/events/latency_info.h"
39 #include "ui/gfx/native_widget_types.h"
41 class WebCursor;
42 struct AcceleratedSurfaceMsg_BufferPresented_Params;
43 struct ViewHostMsg_CompositorSurfaceBuffersSwapped_Params;
44 struct ViewHostMsg_UpdateRect_Params;
45 struct ViewHostMsg_TextInputState_Params;
46 struct ViewHostMsg_BeginSmoothScroll_Params;
48 namespace base {
49 class TimeTicks;
52 namespace cc {
53 class CompositorFrame;
54 class CompositorFrameAck;
57 namespace gfx {
58 class Range;
61 namespace ui {
62 class KeyEvent;
65 namespace blink {
66 class WebInputEvent;
67 class WebMouseEvent;
68 struct WebCompositionUnderline;
69 struct WebScreenInfo;
72 #if defined(OS_ANDROID)
73 namespace blink {
74 class WebLayer;
76 #endif
78 namespace content {
79 class BackingStore;
80 class InputRouter;
81 class MockRenderWidgetHost;
82 class OverscrollController;
83 class RenderWidgetHostDelegate;
84 class RenderWidgetHostViewPort;
85 class SyntheticGestureController;
86 class TimeoutMonitor;
87 struct EditCommand;
89 // This implements the RenderWidgetHost interface that is exposed to
90 // embedders of content, and adds things only visible to content.
91 class CONTENT_EXPORT RenderWidgetHostImpl : virtual public RenderWidgetHost,
92 public InputRouterClient,
93 public InputAckHandler,
94 public IPC::Listener {
95 public:
96 // routing_id can be MSG_ROUTING_NONE, in which case the next available
97 // routing id is taken from the RenderProcessHost.
98 // If this object outlives |delegate|, DetachDelegate() must be called when
99 // |delegate| goes away.
100 RenderWidgetHostImpl(RenderWidgetHostDelegate* delegate,
101 RenderProcessHost* process,
102 int routing_id,
103 bool hidden);
104 virtual ~RenderWidgetHostImpl();
106 // Similar to RenderWidgetHost::FromID, but returning the Impl object.
107 static RenderWidgetHostImpl* FromID(int32 process_id, int32 routing_id);
109 // Returns all RenderWidgetHosts including swapped out ones for
110 // internal use. The public interface
111 // RendgerWidgetHost::GetRenderWidgetHosts only returns active ones.
112 static scoped_ptr<RenderWidgetHostIterator> GetAllRenderWidgetHosts();
114 // Use RenderWidgetHostImpl::From(rwh) to downcast a
115 // RenderWidgetHost to a RenderWidgetHostImpl. Internally, this
116 // uses RenderWidgetHost::AsRenderWidgetHostImpl().
117 static RenderWidgetHostImpl* From(RenderWidgetHost* rwh);
119 void set_hung_renderer_delay_ms(const base::TimeDelta& timeout) {
120 hung_renderer_delay_ms_ = timeout.InMilliseconds();
123 // RenderWidgetHost implementation.
124 virtual void Undo() OVERRIDE;
125 virtual void Redo() OVERRIDE;
126 virtual void Cut() OVERRIDE;
127 virtual void Copy() OVERRIDE;
128 virtual void CopyToFindPboard() OVERRIDE;
129 virtual void Paste() OVERRIDE;
130 virtual void PasteAndMatchStyle() OVERRIDE;
131 virtual void Delete() OVERRIDE;
132 virtual void SelectAll() OVERRIDE;
133 virtual void Unselect() OVERRIDE;
134 virtual void UpdateTextDirection(blink::WebTextDirection direction) OVERRIDE;
135 virtual void NotifyTextDirection() OVERRIDE;
136 virtual void Focus() OVERRIDE;
137 virtual void Blur() OVERRIDE;
138 virtual void SetActive(bool active) OVERRIDE;
139 virtual void CopyFromBackingStore(
140 const gfx::Rect& src_rect,
141 const gfx::Size& accelerated_dst_size,
142 const base::Callback<void(bool, const SkBitmap&)>& callback) OVERRIDE;
143 #if defined(TOOLKIT_GTK)
144 virtual bool CopyFromBackingStoreToGtkWindow(const gfx::Rect& dest_rect,
145 GdkWindow* target) OVERRIDE;
146 #elif defined(OS_MACOSX)
147 virtual gfx::Size GetBackingStoreSize() OVERRIDE;
148 virtual bool CopyFromBackingStoreToCGContext(const CGRect& dest_rect,
149 CGContextRef target) OVERRIDE;
150 #endif
151 virtual void EnableFullAccessibilityMode() OVERRIDE;
152 virtual void ForwardMouseEvent(
153 const blink::WebMouseEvent& mouse_event) OVERRIDE;
154 virtual void ForwardWheelEvent(
155 const blink::WebMouseWheelEvent& wheel_event) OVERRIDE;
156 virtual void ForwardKeyboardEvent(
157 const NativeWebKeyboardEvent& key_event) OVERRIDE;
158 virtual const gfx::Vector2d& GetLastScrollOffset() const OVERRIDE;
159 virtual RenderProcessHost* GetProcess() const OVERRIDE;
160 virtual int GetRoutingID() const OVERRIDE;
161 virtual RenderWidgetHostView* GetView() const OVERRIDE;
162 virtual bool IsLoading() const OVERRIDE;
163 virtual bool IsRenderView() const OVERRIDE;
164 virtual void PaintAtSize(TransportDIB::Handle dib_handle,
165 int tag,
166 const gfx::Size& page_size,
167 const gfx::Size& desired_size) OVERRIDE;
168 virtual void Replace(const base::string16& word) OVERRIDE;
169 virtual void ReplaceMisspelling(const base::string16& word) OVERRIDE;
170 virtual void ResizeRectChanged(const gfx::Rect& new_rect) OVERRIDE;
171 virtual void RestartHangMonitorTimeout() OVERRIDE;
172 virtual void SetIgnoreInputEvents(bool ignore_input_events) OVERRIDE;
173 virtual void Stop() OVERRIDE;
174 virtual void WasResized() OVERRIDE;
175 virtual void AddKeyPressEventCallback(
176 const KeyPressEventCallback& callback) OVERRIDE;
177 virtual void RemoveKeyPressEventCallback(
178 const KeyPressEventCallback& callback) OVERRIDE;
179 virtual void AddMouseEventCallback(
180 const MouseEventCallback& callback) OVERRIDE;
181 virtual void RemoveMouseEventCallback(
182 const MouseEventCallback& callback) OVERRIDE;
183 virtual void GetWebScreenInfo(blink::WebScreenInfo* result) OVERRIDE;
184 virtual void GetSnapshotFromRenderer(
185 const gfx::Rect& src_subrect,
186 const base::Callback<void(bool, const SkBitmap&)>& callback) OVERRIDE;
188 const NativeWebKeyboardEvent* GetLastKeyboardEvent() const;
190 // Notification that the screen info has changed.
191 void NotifyScreenInfoChanged();
193 // Invalidates the cached screen info so that next resize request
194 // will carry the up to date screen info. Unlike
195 // |NotifyScreenInfoChanged|, this doesn't send a message to the renderer.
196 void InvalidateScreenInfo();
198 // Sets the View of this RenderWidgetHost.
199 void SetView(RenderWidgetHostView* view);
201 int surface_id() const { return surface_id_; }
203 bool empty() const { return current_size_.IsEmpty(); }
205 // Called when a renderer object already been created for this host, and we
206 // just need to be attached to it. Used for window.open, <select> dropdown
207 // menus, and other times when the renderer initiates creating an object.
208 virtual void Init();
210 // Tells the renderer to die and then calls Destroy().
211 virtual void Shutdown();
213 // IPC::Listener
214 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
216 // Sends a message to the corresponding object in the renderer.
217 virtual bool Send(IPC::Message* msg) OVERRIDE;
219 // Called to notify the RenderWidget that it has been hidden or restored from
220 // having been hidden.
221 void WasHidden();
222 void WasShown();
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 // Called to notify the RenderWidget that it has lost the mouse lock.
233 virtual void LostMouseLock();
235 // Noifies the RenderWidget of the current mouse cursor visibility state.
236 void SendCursorVisibilityState(bool is_visible);
238 // Tells us whether the page is rendered directly via the GPU process.
239 bool is_accelerated_compositing_active() {
240 return is_accelerated_compositing_active_;
243 // Notifies the RenderWidgetHost that the View was destroyed.
244 void ViewDestroyed();
246 // Indicates if the page has finished loading.
247 void SetIsLoading(bool is_loading);
249 // Check for the existance of a BackingStore of the given |desired_size| and
250 // return it if it exists. If the BackingStore is GPU, true is returned and
251 // |*backing_store| is set to NULL.
252 bool TryGetBackingStore(const gfx::Size& desired_size,
253 BackingStore** backing_store);
255 // Get access to the widget's backing store matching the size of the widget's
256 // view. If you pass |force_create| as true, then GetBackingStore may block
257 // for the renderer to send a new frame. Otherwise, NULL will be returned if
258 // the backing store doesn't already exist. It will also return NULL if the
259 // backing store could not be created.
261 // Mac only: NULL may also be returned if the last frame was GPU accelerated.
262 // Call GetView()->HasAcceleratedSurface to determine if the last frame was
263 // accelerated.
264 BackingStore* GetBackingStore(bool force_create);
266 // Allocate a new backing store of the given size. Returns NULL on failure
267 // (for example, if we don't currently have a RenderWidgetHostView.)
268 BackingStore* AllocBackingStore(const gfx::Size& size);
270 // When a backing store does asynchronous painting, it will call this function
271 // when it is done with the DIB. We will then forward a message to the
272 // renderer to send another paint.
273 void DonePaintingToBackingStore();
275 // GPU accelerated version of GetBackingStore function. This will
276 // trigger a re-composite to the view. It may fail if a resize is pending, or
277 // if a composite has already been requested and not acked yet.
278 bool ScheduleComposite();
280 // Starts a hang monitor timeout. If there's already a hang monitor timeout
281 // the new one will only fire if it has a shorter delay than the time
282 // left on the existing timeouts.
283 void StartHangMonitorTimeout(base::TimeDelta delay);
285 // Stops all existing hang monitor timeouts and assumes the renderer is
286 // responsive.
287 void StopHangMonitorTimeout();
289 // Forwards the given message to the renderer. These are called by the view
290 // when it has received a message.
291 void ForwardGestureEvent(const blink::WebGestureEvent& gesture_event);
292 void ForwardGestureEventWithLatencyInfo(
293 const blink::WebGestureEvent& gesture_event,
294 const ui::LatencyInfo& ui_latency);
295 void ForwardTouchEventWithLatencyInfo(
296 const blink::WebTouchEvent& touch_event,
297 const ui::LatencyInfo& ui_latency);
298 void ForwardMouseEventWithLatencyInfo(
299 const MouseEventWithLatencyInfo& mouse_event);
300 void ForwardWheelEventWithLatencyInfo(
301 const MouseWheelEventWithLatencyInfo& wheel_event);
303 void CancelUpdateTextDirection();
305 // Called when a mouse click/gesture tap activates the renderer.
306 virtual void OnPointerEventActivate();
308 // Notifies the renderer whether or not the input method attached to this
309 // process is activated.
310 // When the input method is activated, a renderer process sends IPC messages
311 // to notify the status of its composition node. (This message is mainly used
312 // for notifying the position of the input cursor so that the browser can
313 // display input method windows under the cursor.)
314 void SetInputMethodActive(bool activate);
316 // Notifies the renderer changes of IME candidate window state.
317 void CandidateWindowShown();
318 void CandidateWindowUpdated();
319 void CandidateWindowHidden();
321 // Update the composition node of the renderer (or WebKit).
322 // WebKit has a special node (a composition node) for input method to change
323 // its text without affecting any other DOM nodes. When the input method
324 // (attached to the browser) updates its text, the browser sends IPC messages
325 // to update the composition node of the renderer.
326 // (Read the comments of each function for its detail.)
328 // Sets the text of the composition node.
329 // This function can also update the cursor position and mark the specified
330 // range in the composition node.
331 // A browser should call this function:
332 // * when it receives a WM_IME_COMPOSITION message with a GCS_COMPSTR flag
333 // (on Windows);
334 // * when it receives a "preedit_changed" signal of GtkIMContext (on Linux);
335 // * when markedText of NSTextInput is called (on Mac).
336 void ImeSetComposition(
337 const base::string16& text,
338 const std::vector<blink::WebCompositionUnderline>& underlines,
339 int selection_start,
340 int selection_end);
342 // Finishes an ongoing composition with the specified text.
343 // A browser should call this function:
344 // * when it receives a WM_IME_COMPOSITION message with a GCS_RESULTSTR flag
345 // (on Windows);
346 // * when it receives a "commit" signal of GtkIMContext (on Linux);
347 // * when insertText of NSTextInput is called (on Mac).
348 void ImeConfirmComposition(const base::string16& text,
349 const gfx::Range& replacement_range,
350 bool keep_selection);
352 // Cancels an ongoing composition.
353 void ImeCancelComposition();
355 // Deletes the current selection plus the specified number of characters
356 // before and after the selection or caret.
357 void ExtendSelectionAndDelete(size_t before, size_t after);
359 // This is for derived classes to give us access to the resizer rect.
360 // And to also expose it to the RenderWidgetHostView.
361 virtual gfx::Rect GetRootWindowResizerRect() const;
363 bool ignore_input_events() const {
364 return ignore_input_events_;
367 bool input_method_active() const {
368 return input_method_active_;
371 // Whether forwarded WebInputEvents should be ignored. True if either
372 // |ignore_input_events_| or |process_->IgnoreInputEvents()| is true.
373 bool IgnoreInputEvents() const;
375 // Event queries delegated to the |input_router_|.
376 bool ShouldForwardTouchEvent() 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.
385 void SetBackground(const SkBitmap& background);
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 // Gets the accessibility mode.
393 AccessibilityMode accessibility_mode() const {
394 return accessibility_mode_;
397 // Send a message to the renderer process to change the accessibility mode.
398 void SetAccessibilityMode(AccessibilityMode mode);
400 // Relay a request from assistive technology to perform the default action
401 // on a given node.
402 void AccessibilityDoDefaultAction(int object_id);
404 // Relay a request from assistive technology to set focus to a given node.
405 void AccessibilitySetFocus(int object_id);
407 // Relay a request from assistive technology to make a given object
408 // visible by scrolling as many scrollable containers as necessary.
409 // In addition, if it's not possible to make the entire object visible,
410 // scroll so that the |subfocus| rect is visible at least. The subfocus
411 // rect is in local coordinates of the object itself.
412 void AccessibilityScrollToMakeVisible(
413 int acc_obj_id, gfx::Rect subfocus);
415 // Relay a request from assistive technology to move a given object
416 // to a specific location, in the WebContents area coordinate space, i.e.
417 // (0, 0) is the top-left corner of the WebContents.
418 void AccessibilityScrollToPoint(int acc_obj_id, gfx::Point point);
420 // Relay a request from assistive technology to set text selection.
421 void AccessibilitySetTextSelection(
422 int acc_obj_id, int start_offset, int end_offset);
424 // Kill the renderer because we got a fatal accessibility error.
425 void FatalAccessibilityTreeError();
427 #if defined(OS_WIN) && defined(USE_AURA)
428 void SetParentNativeViewAccessible(
429 gfx::NativeViewAccessible accessible_parent);
430 gfx::NativeViewAccessible GetParentNativeViewAccessible() const;
431 #endif
433 // Executes the edit command on the RenderView.
434 void ExecuteEditCommand(const std::string& command,
435 const std::string& value);
437 // Tells the renderer to scroll the currently focused node into rect only if
438 // the currently focused node is a Text node (textfield, text area or content
439 // editable divs).
440 void ScrollFocusedEditableNodeIntoRect(const gfx::Rect& rect);
442 // Requests the renderer to select the region between two points.
443 void SelectRange(const gfx::Point& start, const gfx::Point& end);
445 // Requests the renderer to move the caret selection towards the point.
446 void MoveCaret(const gfx::Point& point);
448 // Called when the reponse to a pending mouse lock request has arrived.
449 // Returns true if |allowed| is true and the mouse has been successfully
450 // locked.
451 bool GotResponseToLockMouseRequest(bool allowed);
453 // Tells the RenderWidget about the latest vsync parameters.
454 // Note: Make sure the timebase was obtained using
455 // base::TimeTicks::HighResNow. Using the non-high res timer will result in
456 // incorrect synchronization across processes.
457 virtual void UpdateVSyncParameters(base::TimeTicks timebase,
458 base::TimeDelta interval);
460 // Called by the view in response to AcceleratedSurfaceBuffersSwapped or
461 // AcceleratedSurfacePostSubBuffer.
462 static void AcknowledgeBufferPresent(
463 int32 route_id,
464 int gpu_host_id,
465 const AcceleratedSurfaceMsg_BufferPresented_Params& params);
467 // Called by the view in response to OnSwapCompositorFrame.
468 static void SendSwapCompositorFrameAck(
469 int32 route_id,
470 uint32 output_surface_id,
471 int renderer_host_id,
472 const cc::CompositorFrameAck& ack);
474 // Called by the view to return resources to the compositor.
475 static void SendReclaimCompositorResources(int32 route_id,
476 uint32 output_surface_id,
477 int renderer_host_id,
478 const cc::CompositorFrameAck& ack);
480 // Called by the view in response to AcceleratedSurfaceBuffersSwapped for
481 // platforms that support deferred GPU process descheduling. This does
482 // nothing if the compositor thread is enabled.
483 // TODO(jbates) Once the compositor thread is always on, this can be removed.
484 void AcknowledgeSwapBuffersToRenderer();
486 bool is_threaded_compositing_enabled() const {
487 return is_threaded_compositing_enabled_;
490 #if defined(USE_AURA)
491 // Called by the view when the parent changes. If a parent isn't available,
492 // NULL is used.
493 void ParentChanged(gfx::NativeViewId new_parent);
494 #endif
496 // Signals that the compositing surface was updated, e.g. after a lost context
497 // event.
498 void CompositingSurfaceUpdated();
500 void set_allow_privileged_mouse_lock(bool allow) {
501 allow_privileged_mouse_lock_ = allow;
504 // Resets state variables related to tracking pending size and painting.
506 // We need to reset these flags when we want to repaint the contents of
507 // browser plugin in this RWH. Resetting these flags will ensure we ignore
508 // any previous pending acks that are not relevant upon repaint.
509 void ResetSizeAndRepaintPendingFlags();
511 void DetachDelegate();
513 // Update the renderer's cache of the screen rect of the view and window.
514 void SendScreenRects();
516 OverscrollController* overscroll_controller() const {
517 return overscroll_controller_.get();
520 // Sets whether the overscroll controller should be enabled for this page.
521 void SetOverscrollControllerEnabled(bool enabled);
523 // Suppreses future char events until a keydown. See
524 // suppress_next_char_events_.
525 void SuppressNextCharEvents();
527 // Called by RenderWidgetHostView in response to OnSetNeedsFlushInput.
528 void FlushInput();
530 // InputRouterClient
531 virtual void SetNeedsFlush() OVERRIDE;
533 // Indicates whether the renderer drives the RenderWidgetHosts's size or the
534 // other way around.
535 bool should_auto_resize() { return should_auto_resize_; }
537 void ComputeTouchLatency(const ui::LatencyInfo& latency_info);
538 void FrameSwapped(const ui::LatencyInfo& latency_info);
539 void DidReceiveRendererFrame();
541 // Returns the ID that uniquely describes this component to the latency
542 // subsystem.
543 int64 GetLatencyComponentId();
545 static void CompositorFrameDrawn(const ui::LatencyInfo& latency_info);
547 // Don't check whether we expected a resize ack during layout tests.
548 static void DisableResizeAckCheckForTesting();
550 protected:
551 virtual RenderWidgetHostImpl* AsRenderWidgetHostImpl() OVERRIDE;
553 // Create a LatencyInfo struct with INPUT_EVENT_LATENCY_RWH_COMPONENT
554 // component if it is not already in |original|. And if |original| is
555 // not NULL, it is also merged into the resulting LatencyInfo.
556 ui::LatencyInfo CreateRWHLatencyInfoIfNotExist(
557 const ui::LatencyInfo* original, blink::WebInputEvent::Type type);
559 // Called when we receive a notification indicating that the renderer
560 // process has gone. This will reset our state so that our state will be
561 // consistent if a new renderer is created.
562 void RendererExited(base::TerminationStatus status, int exit_code);
564 // Retrieves an id the renderer can use to refer to its view.
565 // This is used for various IPC messages, including plugins.
566 gfx::NativeViewId GetNativeViewId() const;
568 // Retrieves an id for the surface that the renderer can draw to
569 // when accelerated compositing is enabled.
570 gfx::GLSurfaceHandle GetCompositingSurface();
572 // ---------------------------------------------------------------------------
573 // The following methods are overridden by RenderViewHost to send upwards to
574 // its delegate.
576 // Called when a mousewheel event was not processed by the renderer.
577 virtual void UnhandledWheelEvent(const blink::WebMouseWheelEvent& event) {}
579 // Notification that the user has made some kind of input that could
580 // perform an action. The gestures that count are 1) any mouse down
581 // event and 2) enter or space key presses.
582 virtual void OnUserGesture() {}
584 // Callbacks for notification when the renderer becomes unresponsive to user
585 // input events, and subsequently responsive again.
586 virtual void NotifyRendererUnresponsive() {}
587 virtual void NotifyRendererResponsive() {}
589 // Called when auto-resize resulted in the renderer size changing.
590 virtual void OnRenderAutoResized(const gfx::Size& new_size) {}
592 // ---------------------------------------------------------------------------
594 // RenderViewHost overrides this method to impose further restrictions on when
595 // to allow mouse lock.
596 // Once the request is approved or rejected, GotResponseToLockMouseRequest()
597 // will be called.
598 virtual void RequestToLockMouse(bool user_gesture,
599 bool last_unlocked_by_target);
601 void RejectMouseLockOrUnlockIfNecessary();
602 bool IsMouseLocked() const;
604 // RenderViewHost overrides this method to report when in fullscreen mode.
605 virtual bool IsFullscreen() const;
607 // Indicates if the render widget host should track the render widget's size
608 // as opposed to visa versa.
609 void SetShouldAutoResize(bool enable);
611 // Expose increment/decrement of the in-flight event count, so
612 // RenderViewHostImpl can account for in-flight beforeunload/unload events.
613 int increment_in_flight_event_count() { return ++in_flight_event_count_; }
614 int decrement_in_flight_event_count() { return --in_flight_event_count_; }
616 // Returns whether an overscroll gesture is in progress.
617 bool IsInOverscrollGesture() const;
619 // The View associated with the RenderViewHost. The lifetime of this object
620 // is associated with the lifetime of the Render process. If the Renderer
621 // crashes, its View is destroyed and this pointer becomes NULL, even though
622 // render_view_host_ lives on to load another URL (creating a new View while
623 // doing so).
624 RenderWidgetHostViewPort* view_;
626 // true if a renderer has once been valid. We use this flag to display a sad
627 // tab only when we lose our renderer and not if a paint occurs during
628 // initialization.
629 bool renderer_initialized_;
631 // This value indicates how long to wait before we consider a renderer hung.
632 int hung_renderer_delay_ms_;
634 private:
635 friend class MockRenderWidgetHost;
637 // Tell this object to destroy itself.
638 void Destroy();
640 // Called by |hang_timeout_monitor_| on delayed response from the renderer.
641 void RendererIsUnresponsive();
643 // Called if we know the renderer is responsive. When we currently think the
644 // renderer is unresponsive, this will clear that state and call
645 // NotifyRendererResponsive.
646 void RendererIsResponsive();
648 // IPC message handlers
649 void OnRenderViewReady();
650 void OnRenderProcessGone(int status, int error_code);
651 void OnClose();
652 void OnUpdateScreenRectsAck();
653 void OnRequestMove(const gfx::Rect& pos);
654 void OnSetTooltipText(const base::string16& tooltip_text,
655 blink::WebTextDirection text_direction_hint);
656 void OnPaintAtSizeAck(int tag, const gfx::Size& size);
657 #if defined(OS_MACOSX)
658 void OnCompositorSurfaceBuffersSwapped(
659 const ViewHostMsg_CompositorSurfaceBuffersSwapped_Params& params);
660 #endif
661 bool OnSwapCompositorFrame(const IPC::Message& message);
662 void OnOverscrolled(gfx::Vector2dF accumulated_overscroll,
663 gfx::Vector2dF current_fling_velocity);
664 void OnUpdateRect(const ViewHostMsg_UpdateRect_Params& params);
665 void OnUpdateIsDelayed();
666 void OnQueueSyntheticGesture(const SyntheticGesturePacket& gesture_packet);
667 virtual void OnFocus();
668 virtual void OnBlur();
669 void OnSetCursor(const WebCursor& cursor);
670 void OnTextInputTypeChanged(ui::TextInputType type,
671 ui::TextInputMode input_mode,
672 bool can_compose_inline);
673 #if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA)
674 void OnImeCompositionRangeChanged(
675 const gfx::Range& range,
676 const std::vector<gfx::Rect>& character_bounds);
677 #endif
678 void OnImeCancelComposition();
679 void OnDidActivateAcceleratedCompositing(bool activated);
680 void OnLockMouse(bool user_gesture,
681 bool last_unlocked_by_target,
682 bool privileged);
683 void OnUnlockMouse();
684 void OnShowDisambiguationPopup(const gfx::Rect& rect,
685 const gfx::Size& size,
686 const TransportDIB::Id& id);
687 #if defined(OS_WIN)
688 void OnWindowlessPluginDummyWindowCreated(
689 gfx::NativeViewId dummy_activation_window);
690 void OnWindowlessPluginDummyWindowDestroyed(
691 gfx::NativeViewId dummy_activation_window);
692 #endif
693 void OnSnapshot(bool success, const SkBitmap& bitmap);
695 // Called (either immediately or asynchronously) after we're done with our
696 // BackingStore and can send an ACK to the renderer so it can paint onto it
697 // again.
698 void DidUpdateBackingStore(const ViewHostMsg_UpdateRect_Params& params,
699 const base::TimeTicks& paint_start);
701 // Paints the given bitmap to the current backing store at the given
702 // location. Returns true if the passed callback was asynchronously
703 // scheduled in the future (and thus the caller must manually synchronously
704 // call the callback function).
705 bool PaintBackingStoreRect(TransportDIB::Id bitmap,
706 const gfx::Rect& bitmap_rect,
707 const std::vector<gfx::Rect>& copy_rects,
708 const gfx::Size& view_size,
709 float scale_factor,
710 const base::Closure& completion_callback);
712 // Scrolls the given |clip_rect| in the backing by the given dx/dy amount. The
713 // |dib| and its corresponding location |bitmap_rect| in the backing store
714 // is the newly painted pixels by the renderer.
715 void ScrollBackingStoreRect(const gfx::Vector2d& delta,
716 const gfx::Rect& clip_rect,
717 const gfx::Size& view_size);
719 // Give key press listeners a chance to handle this key press. This allow
720 // widgets that don't have focus to still handle key presses.
721 bool KeyPressListenersHandleEvent(const NativeWebKeyboardEvent& event);
723 // InputRouterClient
724 virtual InputEventAckState FilterInputEvent(
725 const blink::WebInputEvent& event,
726 const ui::LatencyInfo& latency_info) OVERRIDE;
727 virtual void IncrementInFlightEventCount() OVERRIDE;
728 virtual void DecrementInFlightEventCount() OVERRIDE;
729 virtual void OnHasTouchEventHandlers(bool has_handlers) OVERRIDE;
730 virtual OverscrollController* GetOverscrollController() const OVERRIDE;
731 virtual void DidFlush() OVERRIDE;
733 // InputAckHandler
734 virtual void OnKeyboardEventAck(const NativeWebKeyboardEvent& event,
735 InputEventAckState ack_result) OVERRIDE;
736 virtual void OnWheelEventAck(const MouseWheelEventWithLatencyInfo& event,
737 InputEventAckState ack_result) OVERRIDE;
738 virtual void OnTouchEventAck(const TouchEventWithLatencyInfo& event,
739 InputEventAckState ack_result) OVERRIDE;
740 virtual void OnGestureEventAck(const GestureEventWithLatencyInfo& event,
741 InputEventAckState ack_result) OVERRIDE;
742 virtual void OnUnexpectedEventAck(UnexpectedEventAckType type) OVERRIDE;
744 // Called when there is a new auto resize (using a post to avoid a stack
745 // which may get in recursive loops).
746 void DelayedAutoResized();
748 void WindowSnapshotReachedScreen(int snapshot_id);
750 // Our delegate, which wants to know mainly about keyboard events.
751 // It will remain non-NULL until DetachDelegate() is called.
752 RenderWidgetHostDelegate* delegate_;
754 // Created during construction but initialized during Init*(). Therefore, it
755 // is guaranteed never to be NULL, but its channel may be NULL if the
756 // renderer crashed, so you must always check that.
757 RenderProcessHost* process_;
759 // The ID of the corresponding object in the Renderer Instance.
760 int routing_id_;
762 // The ID of the surface corresponding to this render widget.
763 int surface_id_;
765 // Indicates whether a page is loading or not.
766 bool is_loading_;
768 // Indicates whether a page is hidden or not.
769 bool is_hidden_;
771 // Indicates whether a page is fullscreen or not.
772 bool is_fullscreen_;
774 // True when a page is rendered directly via the GPU process.
775 bool is_accelerated_compositing_active_;
777 // True if threaded compositing is enabled on this view.
778 bool is_threaded_compositing_enabled_;
780 // Set if we are waiting for a repaint ack for the view.
781 bool repaint_ack_pending_;
783 // True when waiting for RESIZE_ACK.
784 bool resize_ack_pending_;
786 // Cached copy of the screen info so that it doesn't need to be updated every
787 // time the window is resized.
788 scoped_ptr<blink::WebScreenInfo> screen_info_;
790 // Set if screen_info_ may have changed and should be recomputed and force a
791 // resize message.
792 bool screen_info_out_of_date_;
794 // The current size of the RenderWidget.
795 gfx::Size current_size_;
797 // The size of the view's backing surface in non-DPI-adjusted pixels.
798 gfx::Size physical_backing_size_;
800 // The height of the physical backing surface that is overdrawn opaquely in
801 // the browser, for example by an on-screen-keyboard (in DPI-adjusted pixels).
802 float overdraw_bottom_height_;
804 // The size we last sent as requested size to the renderer. |current_size_|
805 // is only updated once the resize message has been ack'd. This on the other
806 // hand is updated when the resize message is sent. This is very similar to
807 // |resize_ack_pending_|, but the latter is not set if the new size has width
808 // or height zero, which is why we need this too.
809 gfx::Size last_requested_size_;
811 // The next auto resize to send.
812 gfx::Size new_auto_size_;
814 // True if the render widget host should track the render widget's size as
815 // opposed to visa versa.
816 bool should_auto_resize_;
818 bool waiting_for_screen_rects_ack_;
819 gfx::Rect last_view_screen_rect_;
820 gfx::Rect last_window_screen_rect_;
822 AccessibilityMode accessibility_mode_;
824 // Keyboard event listeners.
825 std::vector<KeyPressEventCallback> key_press_event_callbacks_;
827 // Mouse event callbacks.
828 std::vector<MouseEventCallback> mouse_event_callbacks_;
830 // If true, then we should repaint when restoring even if we have a
831 // backingstore. This flag is set to true if we receive a paint message
832 // while is_hidden_ to true. Even though we tell the render widget to hide
833 // itself, a paint message could already be in flight at that point.
834 bool needs_repainting_on_restore_;
836 // This is true if the renderer is currently unresponsive.
837 bool is_unresponsive_;
839 // The following value indicates a time in the future when we would consider
840 // the renderer hung if it does not generate an appropriate response message.
841 base::Time time_when_considered_hung_;
843 // This value denotes the number of input events yet to be acknowledged
844 // by the renderer.
845 int in_flight_event_count_;
847 // This timer runs to check if time_when_considered_hung_ has past.
848 base::OneShotTimer<RenderWidgetHostImpl> hung_renderer_timer_;
850 // Flag to detect recursive calls to GetBackingStore().
851 bool in_get_backing_store_;
853 // Flag to trigger the GetBackingStore method to abort early.
854 bool abort_get_backing_store_;
856 // Set when we call DidPaintRect/DidScrollRect on the view.
857 bool view_being_painted_;
859 // Used for UMA histogram logging to measure the time for a repaint view
860 // operation to finish.
861 base::TimeTicks repaint_start_time_;
863 // Set to true if we shouldn't send input events from the render widget.
864 bool ignore_input_events_;
866 // Indicates whether IME is active.
867 bool input_method_active_;
869 // Set when we update the text direction of the selected input element.
870 bool text_direction_updated_;
871 blink::WebTextDirection text_direction_;
873 // Set when we cancel updating the text direction.
874 // This flag also ignores succeeding update requests until we call
875 // NotifyTextDirection().
876 bool text_direction_canceled_;
878 // Indicates if the next sequence of Char events should be suppressed or not.
879 // System may translate a RawKeyDown event into zero or more Char events,
880 // usually we send them to the renderer directly in sequence. However, If a
881 // RawKeyDown event was not handled by the renderer but was handled by
882 // our UnhandledKeyboardEvent() method, e.g. as an accelerator key, then we
883 // shall not send the following sequence of Char events, which was generated
884 // by this RawKeyDown event, to the renderer. Otherwise the renderer may
885 // handle the Char events and cause unexpected behavior.
886 // For example, pressing alt-2 may let the browser switch to the second tab,
887 // but the Char event generated by alt-2 may also activate a HTML element
888 // if its accesskey happens to be "2", then the user may get confused when
889 // switching back to the original tab, because the content may already be
890 // changed.
891 bool suppress_next_char_events_;
893 // The last scroll offset of the render widget.
894 gfx::Vector2d last_scroll_offset_;
896 bool pending_mouse_lock_request_;
897 bool allow_privileged_mouse_lock_;
899 // Keeps track of whether the webpage has any touch event handler. If it does,
900 // then touch events are sent to the renderer. Otherwise, the touch events are
901 // not sent to the renderer.
902 bool has_touch_handler_;
904 base::WeakPtrFactory<RenderWidgetHostImpl> weak_factory_;
906 scoped_ptr<SyntheticGestureController> synthetic_gesture_controller_;
908 // Receives and handles all input events.
909 scoped_ptr<InputRouter> input_router_;
911 scoped_ptr<OverscrollController> overscroll_controller_;
913 scoped_ptr<TimeoutMonitor> hang_monitor_timeout_;
915 #if defined(OS_WIN)
916 std::list<HWND> dummy_windows_for_activation_;
917 #endif
919 // List of callbacks for pending snapshot requests to the renderer.
920 std::queue<base::Callback<void(bool, const SkBitmap&)> > pending_snapshots_;
922 int64 last_input_number_;
924 BrowserRenderingStats rendering_stats_;
926 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostImpl);
929 } // namespace content
931 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_IMPL_H_