// 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 "base/callback.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/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/render_widget_host_latency_tracker.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/readback_types.h" #include "content/public/browser/render_widget_host.h" #include "content/public/common/page_zoom.h" #include "ipc/ipc_listener.h" #include "third_party/WebKit/public/platform/WebDisplayMode.h" #include "ui/base/ime/text_input_mode.h" #include "ui/base/ime/text_input_type.h" #include "ui/events/gesture_detection/gesture_provider_config_helper.h" #include "ui/events/latency_info.h" #include "ui/gfx/native_widget_types.h" struct ViewHostMsg_SelectionBounds_Params; struct ViewHostMsg_TextInputState_Params; struct ViewHostMsg_UpdateRect_Params; struct ViewMsg_Resize_Params; namespace blink { class WebInputEvent; #if defined(OS_ANDROID) class WebLayer; #endif class WebMouseEvent; struct WebCompositionUnderline; struct WebScreenInfo; } namespace cc { class CompositorFrameAck; } namespace gfx { class Range; } 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 : public RenderWidgetHost, public InputRouterClient, public InputAckHandler, public TouchEmulatorClient, public IPC::Listener { public: // |routing_id| must not be MSG_ROUTING_NONE. // If this object outlives |delegate|, DetachDelegate() must be called when // |delegate| goes away. RenderWidgetHostImpl(RenderWidgetHostDelegate* delegate, RenderProcessHost* process, int32_t routing_id, bool hidden); ~RenderWidgetHostImpl() override; // Similar to RenderWidgetHost::FromID, but returning the Impl object. static RenderWidgetHostImpl* FromID(int32_t process_id, int32_t 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(const base::TimeDelta& delay) { hung_renderer_delay_ = delay; } void set_new_content_rendering_delay_for_testing( const base::TimeDelta& delay) { new_content_rendering_delay_ = delay; } // 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 ReadbackRequestCallback& callback, const SkColorType preferred_color_type) override; bool CanCopyFromBackingStore() override; #if defined(OS_ANDROID) void LockBackingStore() override; 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; bool GetScreenColorProfile(std::vector* color_profile) override; // Notification that the screen info has changed. void NotifyScreenInfoChanged(); // Forces redraw in the renderer and when the update reaches the browser // grabs snapshot from the compositor. Returns PNG-encoded snapshot. using GetSnapshotFromBrowserCallback = base::Callback; void GetSnapshotFromBrowser(const GetSnapshotFromBrowserCallback& callback); const NativeWebKeyboardEvent* GetLastKeyboardEvent() const; // Sets the View of this RenderWidgetHost. void SetView(RenderWidgetHostViewBase* view); RenderWidgetHostDelegate* delegate() const { return delegate_; } 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,