// 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 "cc/base/rolling_time_delta_history.h" #include "cc/resources/shared_bitmap.h" #include "content/browser/renderer_host/event_with_latency_info.h" #include "content/browser/renderer_host/input/input_ack_handler.h" #include "content/browser/renderer_host/input/input_router_client.h" #include "content/browser/renderer_host/input/synthetic_gesture.h" #include "content/browser/renderer_host/input/touch_emulator_client.h" #include "content/common/input/input_event_ack_state.h" #include "content/common/input/synthetic_gesture_packet.h" #include "content/common/view_message_enums.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" struct AcceleratedSurfaceMsg_BufferPresented_Params; struct ViewHostMsg_BeginSmoothScroll_Params; struct ViewHostMsg_SelectionBounds_Params; struct ViewHostMsg_TextInputState_Params; struct ViewHostMsg_UpdateRect_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 BrowserAccessibilityManager; class InputRouter; class MockRenderWidgetHost; class RenderWidgetHostDelegate; class RenderWidgetHostViewBase; class SyntheticGestureController; class TimeoutMonitor; class TouchEmulator; class WebCursor; 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 TouchEmulatorClient, 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); ~RenderWidgetHostImpl() override; // 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. void UpdateTextDirection(blink::WebTextDirection direction) override; void NotifyTextDirection() override; void Focus() override; void Blur() override; void SetActive(bool active) override; void CopyFromBackingStore( const gfx::Rect& src_rect, const gfx::Size& accelerated_dst_size, const base::Callback& callback, const SkColorType color_type) override; bool CanCopyFromBackingStore() override; #if defined(OS_ANDROID) virtual void LockBackingStore() override; virtual void UnlockBackingStore() override; #endif void ForwardMouseEvent(const blink::WebMouseEvent& mouse_event) override; void ForwardWheelEvent(const blink::WebMouseWheelEvent& wheel_event) override; void ForwardKeyboardEvent(const NativeWebKeyboardEvent& key_event) override; RenderProcessHost* GetProcess() const override; int GetRoutingID() const override; RenderWidgetHostView* GetView() const override; bool IsLoading() const override; bool IsRenderView() const override; void ResizeRectChanged(const gfx::Rect& new_rect) override; void RestartHangMonitorTimeout() override; void SetIgnoreInputEvents(bool ignore_input_events) override; void WasResized() override; void AddKeyPressEventCallback(const KeyPressEventCallback& callback) override; void RemoveKeyPressEventCallback( const KeyPressEventCallback& callback) override; void AddMouseEventCallback(const MouseEventCallback& callback) override; void RemoveMouseEventCallback(const MouseEventCallback& callback) override; void GetWebScreenInfo(blink::WebScreenInfo* result) override; SkColorType PreferredReadbackFormat() override; // Forces redraw in the renderer and when the update reaches the browser // grabs snapshot from the compositor. Returns PNG-encoded snapshot. void GetSnapshotFromBrowser( const base::Callback callback); 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(RenderWidgetHostViewBase* 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,