Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / content / browser / renderer_host / render_widget_host_view_android.h
blobdef6e9152a33d74fde5ff0de3ee8c59c88a0db28
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/output/begin_frame_args.h"
19 #include "cc/surfaces/surface_factory_client.h"
20 #include "cc/surfaces/surface_id.h"
21 #include "content/browser/accessibility/browser_accessibility_manager.h"
22 #include "content/browser/renderer_host/delegated_frame_evictor.h"
23 #include "content/browser/renderer_host/ime_adapter_android.h"
24 #include "content/browser/renderer_host/input/stylus_text_selector.h"
25 #include "content/browser/renderer_host/render_widget_host_view_base.h"
26 #include "content/common/content_export.h"
27 #include "content/public/browser/readback_types.h"
28 #include "gpu/command_buffer/common/mailbox.h"
29 #include "third_party/skia/include/core/SkColor.h"
30 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
31 #include "ui/android/window_android_observer.h"
32 #include "ui/events/gesture_detection/filtered_gesture_provider.h"
33 #include "ui/gfx/geometry/size.h"
34 #include "ui/gfx/geometry/vector2d_f.h"
35 #include "ui/touch_selection/touch_selection_controller.h"
37 struct ViewHostMsg_TextInputState_Params;
39 namespace cc {
40 class CopyOutputResult;
41 class DelegatedFrameProvider;
42 class DelegatedRendererLayer;
43 class Layer;
44 class SurfaceFactory;
45 class SurfaceIdAllocator;
46 enum class SurfaceDrawStatus;
49 namespace blink {
50 class WebExternalTextureLayer;
51 class WebTouchEvent;
52 class WebMouseEvent;
55 namespace content {
56 class ContentViewCoreImpl;
57 class OverscrollControllerAndroid;
58 class RenderWidgetHost;
59 class RenderWidgetHostImpl;
60 struct DidOverscrollParams;
61 struct NativeWebKeyboardEvent;
63 class ReadbackRequest {
64 public:
65 explicit ReadbackRequest(float scale,
66 SkColorType color_type,
67 gfx::Rect src_subrect,
68 ReadbackRequestCallback& result_callback);
69 ~ReadbackRequest();
70 float GetScale() { return scale_; }
71 SkColorType GetColorFormat() { return color_type_; }
72 const gfx::Rect GetCaptureRect() { return src_subrect_; }
73 ReadbackRequestCallback& GetResultCallback() { return result_callback_; }
75 private:
76 ReadbackRequest();
77 float scale_;
78 SkColorType color_type_;
79 gfx::Rect src_subrect_;
80 ReadbackRequestCallback result_callback_;
83 // -----------------------------------------------------------------------------
84 // See comments in render_widget_host_view.h about this class and its members.
85 // -----------------------------------------------------------------------------
86 class CONTENT_EXPORT RenderWidgetHostViewAndroid
87 : public RenderWidgetHostViewBase,
88 public cc::DelegatedFrameResourceCollectionClient,
89 public cc::SurfaceFactoryClient,
90 public ui::GestureProviderClient,
91 public ui::WindowAndroidObserver,
92 public DelegatedFrameEvictorClient,
93 public StylusTextSelectorClient,
94 public ui::TouchSelectionControllerClient {
95 public:
96 RenderWidgetHostViewAndroid(RenderWidgetHostImpl* widget,
97 ContentViewCoreImpl* content_view_core);
98 ~RenderWidgetHostViewAndroid() override;
100 // RenderWidgetHostView implementation.
101 bool OnMessageReceived(const IPC::Message& msg) override;
102 void InitAsChild(gfx::NativeView parent_view) override;
103 void InitAsPopup(RenderWidgetHostView* parent_host_view,
104 const gfx::Rect& pos) override;
105 void InitAsFullscreen(RenderWidgetHostView* reference_host_view) override;
106 RenderWidgetHost* GetRenderWidgetHost() const override;
107 void SetSize(const gfx::Size& size) override;
108 void SetBounds(const gfx::Rect& rect) override;
109 gfx::Vector2dF GetLastScrollOffset() const override;
110 gfx::NativeView GetNativeView() const override;
111 gfx::NativeViewId GetNativeViewId() const override;
112 gfx::NativeViewAccessible GetNativeViewAccessible() override;
113 void MovePluginWindows(const std::vector<WebPluginGeometry>& moves) override;
114 void Focus() override;
115 void Blur() override;
116 bool HasFocus() const override;
117 bool IsSurfaceAvailableForCopy() const override;
118 void Show() override;
119 void Hide() override;
120 bool IsShowing() override;
121 gfx::Rect GetViewBounds() const override;
122 gfx::Size GetPhysicalBackingSize() const override;
123 bool DoTopControlsShrinkBlinkSize() const override;
124 float GetTopControlsHeight() const override;
125 void UpdateCursor(const WebCursor& cursor) override;
126 void SetIsLoading(bool is_loading) override;
127 void TextInputTypeChanged(ui::TextInputType type,
128 ui::TextInputMode input_mode,
129 bool can_compose_inline,
130 int flags) override;
131 void ImeCancelComposition() override;
132 void ImeCompositionRangeChanged(
133 const gfx::Range& range,
134 const std::vector<gfx::Rect>& character_bounds) override;
135 void FocusedNodeChanged(bool is_editable_node) override;
136 void RenderProcessGone(base::TerminationStatus status,
137 int error_code) override;
138 void Destroy() override;
139 void SetTooltipText(const base::string16& tooltip_text) override;
140 void SelectionChanged(const base::string16& text,
141 size_t offset,
142 const gfx::Range& range) override;
143 void SelectionBoundsChanged(
144 const ViewHostMsg_SelectionBounds_Params& params) override;
145 void AcceleratedSurfaceInitialized(int route_id) override;
146 bool HasAcceleratedSurface(const gfx::Size& desired_size) override;
147 void SetBackgroundColor(SkColor color) override;
148 void CopyFromCompositingSurface(const gfx::Rect& src_subrect,
149 const gfx::Size& dst_size,
150 ReadbackRequestCallback& callback,
151 const SkColorType color_type) override;
152 void CopyFromCompositingSurfaceToVideoFrame(
153 const gfx::Rect& src_subrect,
154 const scoped_refptr<media::VideoFrame>& target,
155 const base::Callback<void(bool)>& callback) override;
156 bool CanCopyToVideoFrame() const override;
157 void GetScreenInfo(blink::WebScreenInfo* results) override;
158 gfx::Rect GetBoundsInRootWindow() override;
159 gfx::GLSurfaceHandle GetCompositingSurface() override;
160 void ProcessAckedTouchEvent(const TouchEventWithLatencyInfo& touch,
161 InputEventAckState ack_result) override;
162 InputEventAckState FilterInputEvent(
163 const blink::WebInputEvent& input_event) override;
164 void OnSetNeedsFlushInput() override;
165 void GestureEventAck(const blink::WebGestureEvent& event,
166 InputEventAckState ack_result) override;
167 BrowserAccessibilityManager* CreateBrowserAccessibilityManager(
168 BrowserAccessibilityDelegate* delegate) override;
169 bool LockMouse() override;
170 void UnlockMouse() override;
171 void OnSwapCompositorFrame(uint32 output_surface_id,
172 scoped_ptr<cc::CompositorFrame> frame) override;
173 void DidOverscroll(const DidOverscrollParams& params) override;
174 void DidStopFlinging() override;
175 void ShowDisambiguationPopup(const gfx::Rect& rect_pixels,
176 const SkBitmap& zoomed_bitmap) override;
177 scoped_ptr<SyntheticGestureTarget> CreateSyntheticGestureTarget() override;
178 void LockCompositingSurface() override;
179 void UnlockCompositingSurface() override;
180 void OnTextSurroundingSelectionResponse(const base::string16& content,
181 size_t start_offset,
182 size_t end_offset) override;
183 void OnDidNavigateMainFrameToNewPage() override;
185 // cc::DelegatedFrameResourceCollectionClient implementation.
186 void UnusedResourcesAreAvailable() override;
188 // cc::SurfaceFactoryClient implementation.
189 void ReturnResources(const cc::ReturnedResourceArray& resources) override;
191 // ui::GestureProviderClient implementation.
192 void OnGestureEvent(const ui::GestureEventData& gesture) override;
194 // ui::WindowAndroidObserver implementation.
195 void OnCompositingDidCommit() override;
196 void OnRootWindowVisibilityChanged(bool visible) override;
197 void OnAttachCompositor() override;
198 void OnDetachCompositor() override;
199 void OnVSync(base::TimeTicks frame_time,
200 base::TimeDelta vsync_period) override;
201 void OnAnimate(base::TimeTicks begin_frame_time) override;
202 void OnActivityPaused() override;
203 void OnActivityResumed() override;
205 // DelegatedFrameEvictor implementation
206 void EvictDelegatedFrame() override;
208 SkColorType PreferredReadbackFormat() override;
210 // StylusTextSelectorClient implementation.
211 void OnStylusSelectBegin(float x0, float y0, float x1, float y1) override;
212 void OnStylusSelectUpdate(float x, float y) override;
213 void OnStylusSelectEnd() override;
214 void OnStylusSelectTap(base::TimeTicks time, float x, float y) override;
216 // ui::TouchSelectionControllerClient implementation.
217 bool SupportsAnimation() const override;
218 void SetNeedsAnimate() override;
219 void MoveCaret(const gfx::PointF& position) override;
220 void MoveRangeSelectionExtent(const gfx::PointF& extent) override;
221 void SelectBetweenCoordinates(const gfx::PointF& base,
222 const gfx::PointF& extent) override;
223 void OnSelectionEvent(ui::SelectionEventType event) override;
224 scoped_ptr<ui::TouchHandleDrawable> CreateDrawable() override;
226 // Non-virtual methods
227 void SetContentViewCore(ContentViewCoreImpl* content_view_core);
228 SkColor GetCachedBackgroundColor() const;
229 void SendKeyEvent(const NativeWebKeyboardEvent& event);
230 void SendMouseEvent(const blink::WebMouseEvent& event);
231 void SendMouseWheelEvent(const blink::WebMouseWheelEvent& event);
232 void SendGestureEvent(const blink::WebGestureEvent& event);
234 void OnTextInputStateChanged(const ViewHostMsg_TextInputState_Params& params);
235 void OnDidChangeBodyBackgroundColor(SkColor color);
236 void OnStartContentIntent(const GURL& content_url);
237 void OnSetNeedsBeginFrames(bool enabled);
238 void OnSmartClipDataExtracted(const base::string16& text,
239 const base::string16& html,
240 const gfx::Rect rect);
242 bool OnTouchEvent(const ui::MotionEvent& event);
243 bool OnTouchHandleEvent(const ui::MotionEvent& event);
244 void ResetGestureDetection();
245 void SetDoubleTapSupportEnabled(bool enabled);
246 void SetMultiTouchZoomSupportEnabled(bool enabled);
248 long GetNativeImeAdapter();
250 void WasResized();
252 void GetScaledContentBitmap(float scale,
253 SkColorType color_type,
254 gfx::Rect src_subrect,
255 ReadbackRequestCallback& result_callback);
257 scoped_refptr<cc::Layer> CreateDelegatedLayer() const;
259 bool HasValidFrame() const;
261 void MoveCaret(const gfx::Point& point);
262 void DismissTextHandles();
263 void SetTextHandlesTemporarilyHidden(bool hidden);
264 void OnShowingPastePopup(const gfx::PointF& point);
265 void OnShowUnhandledTapUIIfNeeded(int x_dip, int y_dip);
267 void SynchronousFrameMetadata(
268 const cc::CompositorFrameMetadata& frame_metadata);
270 void SetOverlayVideoMode(bool enabled);
272 typedef base::Callback<
273 void(const base::string16& content, int start_offset, int end_offset)>
274 TextSurroundingSelectionCallback;
275 void SetTextSurroundingSelectionCallback(
276 const TextSurroundingSelectionCallback& callback);
278 static void OnContextLost();
280 private:
281 void RunAckCallbacks(cc::SurfaceDrawStatus status);
283 void DestroyDelegatedContent();
284 void CheckOutputSurfaceChanged(uint32 output_surface_id);
285 void SubmitFrame(scoped_ptr<cc::DelegatedFrameData> frame_data);
286 void SwapDelegatedFrame(uint32 output_surface_id,
287 scoped_ptr<cc::DelegatedFrameData> frame_data);
288 void SendDelegatedFrameAck(uint32 output_surface_id);
289 void SendReturnedDelegatedResources(uint32 output_surface_id);
291 void OnFrameMetadataUpdated(
292 const cc::CompositorFrameMetadata& frame_metadata);
293 void ComputeContentsSize(const cc::CompositorFrameMetadata& frame_metadata);
295 void ShowInternal();
296 void HideInternal(bool hide_frontbuffer, bool stop_observing_root_window);
297 void AttachLayers();
298 void RemoveLayers();
300 // Called after async screenshot task completes. Scales and crops the result
301 // of the copy.
302 static void PrepareTextureCopyOutputResult(
303 const gfx::Size& dst_size_in_pixel,
304 const SkColorType color_type,
305 const base::TimeTicks& start_time,
306 ReadbackRequestCallback& callback,
307 scoped_ptr<cc::CopyOutputResult> result);
308 static void PrepareTextureCopyOutputResultForDelegatedReadback(
309 const gfx::Size& dst_size_in_pixel,
310 const SkColorType color_type,
311 const base::TimeTicks& start_time,
312 scoped_refptr<cc::Layer> readback_layer,
313 ReadbackRequestCallback& callback,
314 scoped_ptr<cc::CopyOutputResult> result);
316 // DevTools ScreenCast support for Android WebView.
317 void SynchronousCopyContents(const gfx::Rect& src_subrect_in_pixel,
318 const gfx::Size& dst_size_in_pixel,
319 ReadbackRequestCallback& callback,
320 const SkColorType color_type);
322 // If we have locks on a frame during a ContentViewCore swap or a context
323 // lost, the frame is no longer valid and we can safely release all the locks.
324 // Use this method to release all the locks.
325 void ReleaseLocksOnSurface();
327 // Drop any incoming frames from the renderer when there are locks on the
328 // current frame.
329 void RetainFrame(uint32 output_surface_id,
330 scoped_ptr<cc::CompositorFrame> frame);
332 void InternalSwapCompositorFrame(uint32 output_surface_id,
333 scoped_ptr<cc::CompositorFrame> frame);
334 void OnLostResources();
336 enum VSyncRequestType {
337 FLUSH_INPUT = 1 << 0,
338 BEGIN_FRAME = 1 << 1,
339 PERSISTENT_BEGIN_FRAME = 1 << 2
341 void RequestVSyncUpdate(uint32 requests);
342 void StartObservingRootWindow();
343 void StopObservingRootWindow();
344 void SendBeginFrame(base::TimeTicks frame_time, base::TimeDelta vsync_period);
345 bool Animate(base::TimeTicks frame_time);
347 // Handles all unprocessed and pending readback requests.
348 void AbortPendingReadbackRequests();
350 // The model object.
351 RenderWidgetHostImpl* host_;
353 bool use_surfaces_;
355 // Used to control action dispatch at the next |OnVSync()| call.
356 uint32 outstanding_vsync_requests_;
358 bool is_showing_;
360 // ContentViewCoreImpl is our interface to the view system.
361 ContentViewCoreImpl* content_view_core_;
363 ImeAdapterAndroid ime_adapter_android_;
365 // Body background color of the underlying document.
366 SkColor cached_background_color_;
368 scoped_refptr<cc::DelegatedFrameResourceCollection> resource_collection_;
369 scoped_refptr<cc::DelegatedFrameProvider> frame_provider_;
370 scoped_refptr<cc::Layer> layer_;
372 scoped_ptr<cc::SurfaceIdAllocator> id_allocator_;
373 scoped_ptr<cc::SurfaceFactory> surface_factory_;
374 cc::SurfaceId surface_id_;
375 gfx::Size current_surface_size_;
376 cc::ReturnedResourceArray surface_returned_resources_;
378 // The most recent texture size that was pushed to the texture layer.
379 gfx::Size texture_size_in_layer_;
381 // The most recent content size that was pushed to the texture layer.
382 gfx::Size content_size_in_layer_;
384 // The output surface id of the last received frame.
385 uint32_t last_output_surface_id_;
388 std::queue<base::Closure> ack_callbacks_;
390 // Used to control and render overscroll-related effects.
391 scoped_ptr<OverscrollControllerAndroid> overscroll_controller_;
393 // Provides gesture synthesis given a stream of touch events (derived from
394 // Android MotionEvent's) and touch event acks.
395 ui::FilteredGestureProvider gesture_provider_;
397 // Handles gesture based text selection
398 StylusTextSelector stylus_text_selector_;
400 // Manages selection handle rendering and manipulation.
401 // This will always be NULL if |content_view_core_| is NULL.
402 scoped_ptr<ui::TouchSelectionController> selection_controller_;
404 int accelerated_surface_route_id_;
406 // Size to use if we have no backing ContentViewCore
407 gfx::Size default_size_;
409 const bool using_browser_compositor_;
411 scoped_ptr<DelegatedFrameEvictor> frame_evictor_;
413 size_t locks_on_frame_count_;
414 bool observing_root_window_;
416 struct LastFrameInfo {
417 LastFrameInfo(uint32 output_id,
418 scoped_ptr<cc::CompositorFrame> output_frame);
419 ~LastFrameInfo();
420 uint32 output_surface_id;
421 scoped_ptr<cc::CompositorFrame> frame;
424 scoped_ptr<LastFrameInfo> last_frame_info_;
426 TextSurroundingSelectionCallback text_surrounding_selection_callback_;
428 // List of readbackrequests waiting for arrival of a valid frame.
429 std::queue<ReadbackRequest> readbacks_waiting_for_frame_;
431 // The last scroll offset of the view.
432 gfx::Vector2dF last_scroll_offset_;
434 base::WeakPtrFactory<RenderWidgetHostViewAndroid> weak_ptr_factory_;
436 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAndroid);
439 } // namespace content
441 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_ANDROID_H_