// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_IMPL_H_ #define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_IMPL_H_ #include #include #include #include #include #include #include #include "base/callback.h" #include "base/gtest_prod_util.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "base/observer_list.h" #include "base/process/kill.h" #include "base/strings/string16.h" #include "base/time/time.h" #include "base/timer/timer.h" #include "build/build_config.h" #include "content/browser/renderer_host/input/input_ack_handler.h" #include "content/browser/renderer_host/input/input_router_client.h" #include "content/common/browser_rendering_stats.h" #include "content/common/input/synthetic_gesture_packet.h" #include "content/common/view_message_enums.h" #include "content/port/browser/event_with_latency_info.h" #include "content/port/common/input_event_ack_state.h" #include "content/public/browser/render_widget_host.h" #include "content/public/common/page_zoom.h" #include "ipc/ipc_listener.h" #include "ui/base/ime/text_input_mode.h" #include "ui/base/ime/text_input_type.h" #include "ui/events/latency_info.h" #include "ui/gfx/native_widget_types.h" class WebCursor; struct AcceleratedSurfaceMsg_BufferPresented_Params; struct ViewHostMsg_CompositorSurfaceBuffersSwapped_Params; struct ViewHostMsg_UpdateRect_Params; struct ViewHostMsg_TextInputState_Params; struct ViewHostMsg_BeginSmoothScroll_Params; namespace base { class TimeTicks; } namespace cc { class CompositorFrame; class CompositorFrameAck; } namespace gfx { class Range; } namespace ui { class KeyEvent; } namespace blink { class WebInputEvent; class WebMouseEvent; struct WebCompositionUnderline; struct WebScreenInfo; } #if defined(OS_ANDROID) namespace blink { class WebLayer; } #endif namespace content { class BackingStore; class InputRouter; class MockRenderWidgetHost; class OverscrollController; class RenderWidgetHostDelegate; class RenderWidgetHostViewPort; class SyntheticGestureController; class TimeoutMonitor; struct EditCommand; // This implements the RenderWidgetHost interface that is exposed to // embedders of content, and adds things only visible to content. class CONTENT_EXPORT RenderWidgetHostImpl : virtual public RenderWidgetHost, public InputRouterClient, public InputAckHandler, public IPC::Listener { public: // routing_id can be MSG_ROUTING_NONE, in which case the next available // routing id is taken from the RenderProcessHost. // If this object outlives |delegate|, DetachDelegate() must be called when // |delegate| goes away. RenderWidgetHostImpl(RenderWidgetHostDelegate* delegate, RenderProcessHost* process, int routing_id, bool hidden); virtual ~RenderWidgetHostImpl(); // Similar to RenderWidgetHost::FromID, but returning the Impl object. static RenderWidgetHostImpl* FromID(int32 process_id, int32 routing_id); // Returns all RenderWidgetHosts including swapped out ones for // internal use. The public interface // RendgerWidgetHost::GetRenderWidgetHosts only returns active ones. static scoped_ptr GetAllRenderWidgetHosts(); // Use RenderWidgetHostImpl::From(rwh) to downcast a // RenderWidgetHost to a RenderWidgetHostImpl. Internally, this // uses RenderWidgetHost::AsRenderWidgetHostImpl(). static RenderWidgetHostImpl* From(RenderWidgetHost* rwh); void set_hung_renderer_delay_ms(const base::TimeDelta& timeout) { hung_renderer_delay_ms_ = timeout.InMilliseconds(); } // RenderWidgetHost implementation. virtual void Undo() OVERRIDE; virtual void Redo() OVERRIDE; virtual void Cut() OVERRIDE; virtual void Copy() OVERRIDE; virtual void CopyToFindPboard() OVERRIDE; virtual void Paste() OVERRIDE; virtual void PasteAndMatchStyle() OVERRIDE; virtual void Delete() OVERRIDE; virtual void SelectAll() OVERRIDE; virtual void Unselect() OVERRIDE; virtual void UpdateTextDirection(blink::WebTextDirection direction) OVERRIDE; virtual void NotifyTextDirection() OVERRIDE; virtual void Focus() OVERRIDE; virtual void Blur() OVERRIDE; virtual void SetActive(bool active) OVERRIDE; virtual void CopyFromBackingStore( const gfx::Rect& src_rect, const gfx::Size& accelerated_dst_size, const base::Callback& callback) OVERRIDE; #if defined(TOOLKIT_GTK) virtual bool CopyFromBackingStoreToGtkWindow(const gfx::Rect& dest_rect, GdkWindow* target) OVERRIDE; #elif defined(OS_MACOSX) virtual gfx::Size GetBackingStoreSize() OVERRIDE; virtual bool CopyFromBackingStoreToCGContext(const CGRect& dest_rect, CGContextRef target) OVERRIDE; #endif virtual void EnableFullAccessibilityMode() OVERRIDE; virtual void ForwardMouseEvent( const blink::WebMouseEvent& mouse_event) OVERRIDE; virtual void ForwardWheelEvent( const blink::WebMouseWheelEvent& wheel_event) OVERRIDE; virtual void ForwardKeyboardEvent( const NativeWebKeyboardEvent& key_event) OVERRIDE; virtual const gfx::Vector2d& GetLastScrollOffset() const OVERRIDE; virtual RenderProcessHost* GetProcess() const OVERRIDE; virtual int GetRoutingID() const OVERRIDE; virtual RenderWidgetHostView* GetView() const OVERRIDE; virtual bool IsLoading() const OVERRIDE; virtual bool IsRenderView() const OVERRIDE; virtual void PaintAtSize(TransportDIB::Handle dib_handle, int tag, const gfx::Size& page_size, const gfx::Size& desired_size) OVERRIDE; virtual void Replace(const base::string16& word) OVERRIDE; virtual void ReplaceMisspelling(const base::string16& word) OVERRIDE; virtual void ResizeRectChanged(const gfx::Rect& new_rect) OVERRIDE; virtual void RestartHangMonitorTimeout() OVERRIDE; virtual void SetIgnoreInputEvents(bool ignore_input_events) OVERRIDE; virtual void Stop() OVERRIDE; virtual void WasResized() OVERRIDE; virtual void AddKeyPressEventCallback( const KeyPressEventCallback& callback) OVERRIDE; virtual void RemoveKeyPressEventCallback( const KeyPressEventCallback& callback) OVERRIDE; virtual void AddMouseEventCallback( const MouseEventCallback& callback) OVERRIDE; virtual void RemoveMouseEventCallback( const MouseEventCallback& callback) OVERRIDE; virtual void GetWebScreenInfo(blink::WebScreenInfo* result) OVERRIDE; virtual void GetSnapshotFromRenderer( const gfx::Rect& src_subrect, const base::Callback& callback) OVERRIDE; const NativeWebKeyboardEvent* GetLastKeyboardEvent() const; // Notification that the screen info has changed. void NotifyScreenInfoChanged(); // Invalidates the cached screen info so that next resize request // will carry the up to date screen info. Unlike // |NotifyScreenInfoChanged|, this doesn't send a message to the renderer. void InvalidateScreenInfo(); // Sets the View of this RenderWidgetHost. void SetView(RenderWidgetHostView* view); int surface_id() const { return surface_id_; } bool empty() const { return current_size_.IsEmpty(); } // Called when a renderer object already been created for this host, and we // just need to be attached to it. Used for window.open,