IndexedDBFactory now ForceCloses databases.
[chromium-blink-merge.git] / content / browser / renderer_host / render_widget_host_view_android.h
blob107e5c6c0bcaf42b94df511fd6ff658e616f3743
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_VIEW_ANDROID_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_ANDROID_H_
8 #include <map>
9 #include <queue>
11 #include "base/callback.h"
12 #include "base/compiler_specific.h"
13 #include "base/i18n/rtl.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "base/process/process.h"
17 #include "cc/layers/delegated_frame_resource_collection.h"
18 #include "cc/layers/texture_layer_client.h"
19 #include "cc/output/begin_frame_args.h"
20 #include "content/browser/accessibility/browser_accessibility_manager.h"
21 #include "content/browser/renderer_host/delegated_frame_evictor.h"
22 #include "content/browser/renderer_host/image_transport_factory_android.h"
23 #include "content/browser/renderer_host/ime_adapter_android.h"
24 #include "content/browser/renderer_host/render_widget_host_view_base.h"
25 #include "gpu/command_buffer/common/mailbox.h"
26 #include "third_party/skia/include/core/SkColor.h"
27 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
28 #include "ui/base/android/window_android_observer.h"
29 #include "ui/gfx/size.h"
30 #include "ui/gfx/vector2d_f.h"
32 struct ViewHostMsg_TextInputState_Params;
34 struct GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params;
35 struct GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params;
37 namespace cc {
38 class CopyOutputResult;
39 class DelegatedFrameProvider;
40 class DelegatedRendererLayer;
41 class Layer;
42 class SingleReleaseCallback;
43 class TextureLayer;
46 namespace blink {
47 class WebExternalTextureLayer;
48 class WebTouchEvent;
49 class WebMouseEvent;
52 namespace content {
53 class ContentViewCoreImpl;
54 class OverscrollGlow;
55 class RenderWidgetHost;
56 class RenderWidgetHostImpl;
57 struct NativeWebKeyboardEvent;
59 // -----------------------------------------------------------------------------
60 // See comments in render_widget_host_view.h about this class and its members.
61 // -----------------------------------------------------------------------------
62 class RenderWidgetHostViewAndroid
63 : public RenderWidgetHostViewBase,
64 public BrowserAccessibilityDelegate,
65 public cc::DelegatedFrameResourceCollectionClient,
66 public ImageTransportFactoryAndroidObserver,
67 public ui::WindowAndroidObserver,
68 public DelegatedFrameEvictorClient {
69 public:
70 RenderWidgetHostViewAndroid(RenderWidgetHostImpl* widget,
71 ContentViewCoreImpl* content_view_core);
72 virtual ~RenderWidgetHostViewAndroid();
74 // RenderWidgetHostView implementation.
75 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
76 virtual void InitAsChild(gfx::NativeView parent_view) OVERRIDE;
77 virtual void InitAsPopup(RenderWidgetHostView* parent_host_view,
78 const gfx::Rect& pos) OVERRIDE;
79 virtual void InitAsFullscreen(
80 RenderWidgetHostView* reference_host_view) OVERRIDE;
81 virtual RenderWidgetHost* GetRenderWidgetHost() const OVERRIDE;
82 virtual void WasShown() OVERRIDE;
83 virtual void WasHidden() OVERRIDE;
84 virtual void SetSize(const gfx::Size& size) OVERRIDE;
85 virtual void SetBounds(const gfx::Rect& rect) OVERRIDE;
86 virtual gfx::NativeView GetNativeView() const OVERRIDE;
87 virtual gfx::NativeViewId GetNativeViewId() const OVERRIDE;
88 virtual gfx::NativeViewAccessible GetNativeViewAccessible() OVERRIDE;
89 virtual void MovePluginWindows(
90 const gfx::Vector2d& scroll_offset,
91 const std::vector<WebPluginGeometry>& moves) OVERRIDE;
92 virtual void Focus() OVERRIDE;
93 virtual void Blur() OVERRIDE;
94 virtual bool HasFocus() const OVERRIDE;
95 virtual bool IsSurfaceAvailableForCopy() const OVERRIDE;
96 virtual void Show() OVERRIDE;
97 virtual void Hide() OVERRIDE;
98 virtual bool IsShowing() OVERRIDE;
99 virtual gfx::Rect GetViewBounds() const OVERRIDE;
100 virtual gfx::Size GetPhysicalBackingSize() const OVERRIDE;
101 virtual float GetOverdrawBottomHeight() const OVERRIDE;
102 virtual void UpdateCursor(const WebCursor& cursor) OVERRIDE;
103 virtual void SetIsLoading(bool is_loading) OVERRIDE;
104 virtual void TextInputTypeChanged(ui::TextInputType type,
105 ui::TextInputMode input_mode,
106 bool can_compose_inline) OVERRIDE;
107 virtual void ImeCancelComposition() OVERRIDE;
108 virtual void DidUpdateBackingStore(
109 const gfx::Rect& scroll_rect,
110 const gfx::Vector2d& scroll_delta,
111 const std::vector<gfx::Rect>& copy_rects,
112 const std::vector<ui::LatencyInfo>& latency_info) OVERRIDE;
113 virtual void RenderProcessGone(base::TerminationStatus status,
114 int error_code) OVERRIDE;
115 virtual void Destroy() OVERRIDE;
116 virtual void SetTooltipText(const base::string16& tooltip_text) OVERRIDE;
117 virtual void SelectionChanged(const base::string16& text,
118 size_t offset,
119 const gfx::Range& range) OVERRIDE;
120 virtual void SelectionBoundsChanged(
121 const ViewHostMsg_SelectionBounds_Params& params) OVERRIDE;
122 virtual void ScrollOffsetChanged() OVERRIDE;
123 virtual BackingStore* AllocBackingStore(const gfx::Size& size) OVERRIDE;
124 virtual void OnAcceleratedCompositingStateChange() OVERRIDE;
125 virtual void AcceleratedSurfaceInitialized(int host_id,
126 int route_id) OVERRIDE;
127 virtual void AcceleratedSurfaceBuffersSwapped(
128 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params,
129 int gpu_host_id) OVERRIDE;
130 virtual void AcceleratedSurfacePostSubBuffer(
131 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params,
132 int gpu_host_id) OVERRIDE;
133 virtual void AcceleratedSurfaceSuspend() OVERRIDE;
134 virtual void AcceleratedSurfaceRelease() OVERRIDE;
135 virtual bool HasAcceleratedSurface(const gfx::Size& desired_size) OVERRIDE;
136 virtual void SetBackground(const SkBitmap& background) OVERRIDE;
137 virtual void CopyFromCompositingSurface(
138 const gfx::Rect& src_subrect,
139 const gfx::Size& dst_size,
140 const base::Callback<void(bool, const SkBitmap&)>& callback) OVERRIDE;
141 virtual void CopyFromCompositingSurfaceToVideoFrame(
142 const gfx::Rect& src_subrect,
143 const scoped_refptr<media::VideoFrame>& target,
144 const base::Callback<void(bool)>& callback) OVERRIDE;
145 virtual bool CanCopyToVideoFrame() const OVERRIDE;
146 virtual void GetScreenInfo(blink::WebScreenInfo* results) OVERRIDE;
147 virtual gfx::Rect GetBoundsInRootWindow() OVERRIDE;
148 virtual gfx::GLSurfaceHandle GetCompositingSurface() OVERRIDE;
149 virtual void ProcessAckedTouchEvent(const TouchEventWithLatencyInfo& touch,
150 InputEventAckState ack_result) OVERRIDE;
151 virtual void SetHasHorizontalScrollbar(
152 bool has_horizontal_scrollbar) OVERRIDE;
153 virtual void SetScrollOffsetPinning(
154 bool is_pinned_to_left, bool is_pinned_to_right) OVERRIDE;
155 virtual void UnhandledWheelEvent(
156 const blink::WebMouseWheelEvent& event) OVERRIDE;
157 virtual InputEventAckState FilterInputEvent(
158 const blink::WebInputEvent& input_event) OVERRIDE;
159 virtual void OnSetNeedsFlushInput() OVERRIDE;
160 virtual void GestureEventAck(int gesture_event_type,
161 InputEventAckState ack_result) OVERRIDE;
162 virtual void CreateBrowserAccessibilityManagerIfNeeded() OVERRIDE;
163 virtual bool LockMouse() OVERRIDE;
164 virtual void UnlockMouse() OVERRIDE;
165 virtual void HasTouchEventHandlers(bool need_touch_events) OVERRIDE;
166 virtual void OnSwapCompositorFrame(
167 uint32 output_surface_id,
168 scoped_ptr<cc::CompositorFrame> frame) OVERRIDE;
169 virtual void OnOverscrolled(gfx::Vector2dF accumulated_overscroll,
170 gfx::Vector2dF current_fling_velocity) OVERRIDE;
171 virtual void ShowDisambiguationPopup(const gfx::Rect& target_rect,
172 const SkBitmap& zoomed_bitmap) OVERRIDE;
173 virtual scoped_ptr<SyntheticGestureTarget> CreateSyntheticGestureTarget()
174 OVERRIDE;
176 // Implementation of BrowserAccessibilityDelegate:
177 virtual void SetAccessibilityFocus(int acc_obj_id) OVERRIDE;
178 virtual void AccessibilityDoDefaultAction(int acc_obj_id) OVERRIDE;
179 virtual void AccessibilityScrollToMakeVisible(
180 int acc_obj_id, gfx::Rect subfocus) OVERRIDE;
181 virtual void AccessibilityScrollToPoint(
182 int acc_obj_id, gfx::Point point) OVERRIDE;
183 virtual void AccessibilitySetTextSelection(
184 int acc_obj_id, int start_offset, int end_offset) OVERRIDE;
185 virtual gfx::Point GetLastTouchEventLocation() const OVERRIDE;
186 virtual void FatalAccessibilityTreeError() OVERRIDE;
188 // cc::DelegatedFrameResourceCollectionClient implementation.
189 virtual void UnusedResourcesAreAvailable() OVERRIDE;
191 // ui::WindowAndroidObserver implementation.
192 virtual void OnCompositingDidCommit() OVERRIDE;
193 virtual void OnAttachCompositor() OVERRIDE {}
194 virtual void OnDetachCompositor() OVERRIDE;
196 // ImageTransportFactoryAndroidObserver implementation.
197 virtual void OnLostResources() OVERRIDE;
199 // DelegatedFrameEvictor implementation
200 virtual void EvictDelegatedFrame() OVERRIDE;
202 // Non-virtual methods
203 void SetContentViewCore(ContentViewCoreImpl* content_view_core);
204 SkColor GetCachedBackgroundColor() const;
205 void SendKeyEvent(const NativeWebKeyboardEvent& event);
206 void SendTouchEvent(const blink::WebTouchEvent& event);
207 void SendMouseEvent(const blink::WebMouseEvent& event);
208 void SendMouseWheelEvent(const blink::WebMouseWheelEvent& event);
209 void SendGestureEvent(const blink::WebGestureEvent& event);
210 void SendBeginFrame(const cc::BeginFrameArgs& args);
212 void OnTextInputStateChanged(const ViewHostMsg_TextInputState_Params& params);
213 void OnDidChangeBodyBackgroundColor(SkColor color);
214 void OnStartContentIntent(const GURL& content_url);
215 void OnSetNeedsBeginFrame(bool enabled);
216 void OnSmartClipDataExtracted(const base::string16& result);
218 void LockResources();
219 void UnlockResources();
221 int GetNativeImeAdapter();
223 void WasResized();
225 blink::WebGLId GetScaledContentTexture(float scale, gfx::Size* out_size);
226 bool PopulateBitmapWithContents(jobject jbitmap);
228 bool HasValidFrame() const;
230 // Select all text between the given coordinates.
231 void SelectRange(const gfx::Point& start, const gfx::Point& end);
233 void MoveCaret(const gfx::Point& point);
235 void RequestContentClipping(const gfx::Rect& clipping,
236 const gfx::Size& content_size);
238 // Returns true when animation ticks are still needed. This avoids a separate
239 // round-trip for requesting follow-up animation.
240 bool Animate(base::TimeTicks frame_time);
242 void SynchronousFrameMetadata(
243 const cc::CompositorFrameMetadata& frame_metadata);
245 void SetOverlayVideoMode(bool enabled);
247 private:
248 void BuffersSwapped(const gpu::Mailbox& mailbox,
249 uint32_t output_surface_id,
250 const base::Closure& ack_callback);
252 void RunAckCallbacks();
254 void DestroyDelegatedContent();
255 void SwapDelegatedFrame(uint32 output_surface_id,
256 scoped_ptr<cc::DelegatedFrameData> frame_data);
257 void SendDelegatedFrameAck(uint32 output_surface_id);
259 void UpdateContentViewCoreFrameMetadata(
260 const cc::CompositorFrameMetadata& frame_metadata);
261 void ComputeContentsSize(const cc::CompositorFrameMetadata& frame_metadata);
262 void ResetClipping();
263 void ClipContents(const gfx::Rect& clipping, const gfx::Size& content_size);
265 void AttachLayers();
266 void RemoveLayers();
268 void UpdateAnimationSize(const cc::CompositorFrameMetadata& frame_metadata);
270 // Called after async screenshot task completes. Scales and crops the result
271 // of the copy.
272 static void PrepareTextureCopyOutputResult(
273 const gfx::Size& dst_size_in_pixel,
274 const base::Callback<void(bool, const SkBitmap&)>& callback,
275 scoped_ptr<cc::CopyOutputResult> result);
276 static void PrepareBitmapCopyOutputResult(
277 const gfx::Size& dst_size_in_pixel,
278 const base::Callback<void(bool, const SkBitmap&)>& callback,
279 scoped_ptr<cc::CopyOutputResult> result);
281 // DevTools ScreenCast support for Android WebView.
282 void SynchronousCopyContents(
283 const gfx::Rect& src_subrect_in_pixel,
284 const gfx::Size& dst_size_in_pixel,
285 const base::Callback<void(bool, const SkBitmap&)>& callback);
287 // The model object.
288 RenderWidgetHostImpl* host_;
290 // Used to track whether this render widget needs a BeginFrame.
291 bool needs_begin_frame_;
293 // Whether or not this widget is potentially attached to the view hierarchy.
294 // This view may not actually be attached if this is true, but it should be
295 // treated as such, because as soon as a ContentViewCore is set the layer
296 // will be attached automatically.
297 bool are_layers_attached_;
299 // ContentViewCoreImpl is our interface to the view system.
300 ContentViewCoreImpl* content_view_core_;
302 ImeAdapterAndroid ime_adapter_android_;
304 // Body background color of the underlying document.
305 SkColor cached_background_color_;
307 // The texture layer for this view when using browser-side compositing.
308 scoped_refptr<cc::TextureLayer> texture_layer_;
310 scoped_refptr<cc::DelegatedFrameResourceCollection> resource_collection_;
311 scoped_refptr<cc::DelegatedFrameProvider> frame_provider_;
312 scoped_refptr<cc::DelegatedRendererLayer> delegated_renderer_layer_;
314 // The layer used for rendering the contents of this view.
315 // It is either owned by texture_layer_ or surface_texture_transport_
316 // depending on the mode.
317 scoped_refptr<cc::Layer> layer_;
319 // The most recent texture id that was pushed to the texture layer.
320 unsigned int texture_id_in_layer_;
322 // The most recent texture size that was pushed to the texture layer.
323 gfx::Size texture_size_in_layer_;
325 // The most recent content size that was pushed to the texture layer.
326 gfx::Size content_size_in_layer_;
328 // The mailbox of the previously received frame.
329 gpu::Mailbox current_mailbox_;
331 // The output surface id of the last received frame.
332 uint32_t last_output_surface_id_;
334 base::WeakPtrFactory<RenderWidgetHostViewAndroid> weak_ptr_factory_;
336 std::queue<base::Closure> ack_callbacks_;
338 const bool overscroll_effect_enabled_;
339 // Used to render overscroll overlays.
340 // Note: |overscroll_effect_| will never be NULL, even if it's never enabled.
341 scoped_ptr<OverscrollGlow> overscroll_effect_;
343 bool flush_input_requested_;
345 int accelerated_surface_route_id_;
347 // Size to use if we have no backing ContentViewCore
348 gfx::Size default_size_;
350 const bool using_synchronous_compositor_;
352 scoped_ptr<DelegatedFrameEvictor> frame_evictor_;
354 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAndroid);
357 } // namespace content
359 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_ANDROID_H_