DevTools: cut host and port from webSocketDebuggerUrl in addition to ws:// prefix
[chromium-blink-merge.git] / content / browser / renderer_host / render_widget_host_view_android.h
blobf1ac9870e165296110da68308930f37fc68f7cf2
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 // -----------------------------------------------------------------------------
64 // See comments in render_widget_host_view.h about this class and its members.
65 // -----------------------------------------------------------------------------
66 class CONTENT_EXPORT RenderWidgetHostViewAndroid
67 : public RenderWidgetHostViewBase,
68 public cc::DelegatedFrameResourceCollectionClient,
69 public cc::SurfaceFactoryClient,
70 public ui::GestureProviderClient,
71 public ui::WindowAndroidObserver,
72 public DelegatedFrameEvictorClient,
73 public StylusTextSelectorClient,
74 public ui::TouchSelectionControllerClient {
75 public:
76 RenderWidgetHostViewAndroid(RenderWidgetHostImpl* widget,
77 ContentViewCoreImpl* content_view_core);
78 ~RenderWidgetHostViewAndroid() override;
80 void Blur();
82 // RenderWidgetHostView implementation.
83 bool OnMessageReceived(const IPC::Message& msg) override;
84 void InitAsChild(gfx::NativeView parent_view) override;
85 void InitAsPopup(RenderWidgetHostView* parent_host_view,
86 const gfx::Rect& pos) override;
87 void InitAsFullscreen(RenderWidgetHostView* reference_host_view) override;
88 RenderWidgetHost* GetRenderWidgetHost() const override;
89 void SetSize(const gfx::Size& size) override;
90 void SetBounds(const gfx::Rect& rect) override;
91 gfx::Vector2dF GetLastScrollOffset() const override;
92 gfx::NativeView GetNativeView() const override;
93 gfx::NativeViewId GetNativeViewId() const override;
94 gfx::NativeViewAccessible GetNativeViewAccessible() override;
95 void MovePluginWindows(const std::vector<WebPluginGeometry>& moves) override;
96 void Focus() override;
97 bool HasFocus() const override;
98 bool IsSurfaceAvailableForCopy() const override;
99 void Show() override;
100 void Hide() override;
101 bool IsShowing() override;
102 gfx::Rect GetViewBounds() const override;
103 gfx::Size GetPhysicalBackingSize() const override;
104 bool DoTopControlsShrinkBlinkSize() const override;
105 float GetTopControlsHeight() const override;
106 void UpdateCursor(const WebCursor& cursor) override;
107 void SetIsLoading(bool is_loading) override;
108 void TextInputTypeChanged(ui::TextInputType type,
109 ui::TextInputMode input_mode,
110 bool can_compose_inline,
111 int flags) override;
112 void ImeCancelComposition() override;
113 void ImeCompositionRangeChanged(
114 const gfx::Range& range,
115 const std::vector<gfx::Rect>& character_bounds) override;
116 void FocusedNodeChanged(bool is_editable_node) override;
117 void RenderProcessGone(base::TerminationStatus status,
118 int error_code) override;
119 void Destroy() override;
120 void SetTooltipText(const base::string16& tooltip_text) override;
121 void SelectionChanged(const base::string16& text,
122 size_t offset,
123 const gfx::Range& range) override;
124 void SelectionBoundsChanged(
125 const ViewHostMsg_SelectionBounds_Params& params) override;
126 void AcceleratedSurfaceInitialized(int route_id) override;
127 bool HasAcceleratedSurface(const gfx::Size& desired_size) override;
128 void SetBackgroundColor(SkColor color) override;
129 void CopyFromCompositingSurface(
130 const gfx::Rect& src_subrect,
131 const gfx::Size& dst_size,
132 ReadbackRequestCallback& callback,
133 const SkColorType preferred_color_type) override;
134 void CopyFromCompositingSurfaceToVideoFrame(
135 const gfx::Rect& src_subrect,
136 const scoped_refptr<media::VideoFrame>& target,
137 const base::Callback<void(bool)>& callback) override;
138 bool CanCopyToVideoFrame() const override;
139 void GetScreenInfo(blink::WebScreenInfo* results) override;
140 gfx::Rect GetBoundsInRootWindow() override;
141 gfx::GLSurfaceHandle GetCompositingSurface() override;
142 void ProcessAckedTouchEvent(const TouchEventWithLatencyInfo& touch,
143 InputEventAckState ack_result) override;
144 InputEventAckState FilterInputEvent(
145 const blink::WebInputEvent& input_event) override;
146 void OnSetNeedsFlushInput() override;
147 void GestureEventAck(const blink::WebGestureEvent& event,
148 InputEventAckState ack_result) override;
149 BrowserAccessibilityManager* CreateBrowserAccessibilityManager(
150 BrowserAccessibilityDelegate* delegate) override;
151 bool LockMouse() override;
152 void UnlockMouse() override;
153 void OnSwapCompositorFrame(uint32 output_surface_id,
154 scoped_ptr<cc::CompositorFrame> frame) override;
155 void DidOverscroll(const DidOverscrollParams& params) override;
156 void DidStopFlinging() override;
157 uint32_t GetSurfaceIdNamespace() override;
158 void ShowDisambiguationPopup(const gfx::Rect& rect_pixels,
159 const SkBitmap& zoomed_bitmap) override;
160 scoped_ptr<SyntheticGestureTarget> CreateSyntheticGestureTarget() override;
161 void LockCompositingSurface() override;
162 void UnlockCompositingSurface() override;
163 void OnTextSurroundingSelectionResponse(const base::string16& content,
164 size_t start_offset,
165 size_t end_offset) override;
166 void OnDidNavigateMainFrameToNewPage() override;
168 // cc::DelegatedFrameResourceCollectionClient implementation.
169 void UnusedResourcesAreAvailable() override;
171 // cc::SurfaceFactoryClient implementation.
172 void ReturnResources(const cc::ReturnedResourceArray& resources) override;
174 // ui::GestureProviderClient implementation.
175 void OnGestureEvent(const ui::GestureEventData& gesture) override;
177 // ui::WindowAndroidObserver implementation.
178 void OnCompositingDidCommit() override;
179 void OnRootWindowVisibilityChanged(bool visible) override;
180 void OnAttachCompositor() override;
181 void OnDetachCompositor() override;
182 void OnVSync(base::TimeTicks frame_time,
183 base::TimeDelta vsync_period) override;
184 void OnAnimate(base::TimeTicks begin_frame_time) override;
185 void OnActivityPaused() override;
186 void OnActivityResumed() override;
188 // DelegatedFrameEvictor implementation
189 void EvictDelegatedFrame() override;
191 // StylusTextSelectorClient implementation.
192 void OnStylusSelectBegin(float x0, float y0, float x1, float y1) override;
193 void OnStylusSelectUpdate(float x, float y) override;
194 void OnStylusSelectEnd() override;
195 void OnStylusSelectTap(base::TimeTicks time, float x, float y) override;
197 // ui::TouchSelectionControllerClient implementation.
198 bool SupportsAnimation() const override;
199 void SetNeedsAnimate() override;
200 void MoveCaret(const gfx::PointF& position) override;
201 void MoveRangeSelectionExtent(const gfx::PointF& extent) override;
202 void SelectBetweenCoordinates(const gfx::PointF& base,
203 const gfx::PointF& extent) override;
204 void OnSelectionEvent(ui::SelectionEventType event) override;
205 scoped_ptr<ui::TouchHandleDrawable> CreateDrawable() override;
207 // Non-virtual methods
208 void SetContentViewCore(ContentViewCoreImpl* content_view_core);
209 SkColor GetCachedBackgroundColor() const;
210 void SendKeyEvent(const NativeWebKeyboardEvent& event);
211 void SendMouseEvent(const blink::WebMouseEvent& event);
212 void SendMouseWheelEvent(const blink::WebMouseWheelEvent& event);
213 void SendGestureEvent(const blink::WebGestureEvent& event);
215 void OnTextInputStateChanged(const ViewHostMsg_TextInputState_Params& params);
216 void OnDidChangeBodyBackgroundColor(SkColor color);
217 void OnStartContentIntent(const GURL& content_url);
218 void OnSetNeedsBeginFrames(bool enabled);
219 void OnSmartClipDataExtracted(const base::string16& text,
220 const base::string16& html,
221 const gfx::Rect rect);
223 bool OnTouchEvent(const ui::MotionEvent& event);
224 bool OnTouchHandleEvent(const ui::MotionEvent& event);
225 void ResetGestureDetection();
226 void SetDoubleTapSupportEnabled(bool enabled);
227 void SetMultiTouchZoomSupportEnabled(bool enabled);
229 long GetNativeImeAdapter();
231 void WasResized();
233 void GetScaledContentBitmap(float scale,
234 SkColorType preferred_color_type,
235 gfx::Rect src_subrect,
236 ReadbackRequestCallback& result_callback);
238 scoped_refptr<cc::Layer> CreateDelegatedLayer() const;
240 bool HasValidFrame() const;
242 void MoveCaret(const gfx::Point& point);
243 void DismissTextHandles();
244 void SetTextHandlesTemporarilyHidden(bool hidden);
245 void OnShowingPastePopup(const gfx::PointF& point);
246 void OnShowUnhandledTapUIIfNeeded(int x_dip, int y_dip);
248 void SynchronousFrameMetadata(
249 const cc::CompositorFrameMetadata& frame_metadata);
251 void SetOverlayVideoMode(bool enabled);
253 typedef base::Callback<
254 void(const base::string16& content, int start_offset, int end_offset)>
255 TextSurroundingSelectionCallback;
256 void SetTextSurroundingSelectionCallback(
257 const TextSurroundingSelectionCallback& callback);
259 static void OnContextLost();
261 private:
262 void RunAckCallbacks(cc::SurfaceDrawStatus status);
264 void DestroyDelegatedContent();
265 void CheckOutputSurfaceChanged(uint32 output_surface_id);
266 void SubmitFrame(scoped_ptr<cc::DelegatedFrameData> frame_data);
267 void SwapDelegatedFrame(uint32 output_surface_id,
268 scoped_ptr<cc::DelegatedFrameData> frame_data);
269 void SendDelegatedFrameAck(uint32 output_surface_id);
270 void SendReturnedDelegatedResources(uint32 output_surface_id);
272 void OnFrameMetadataUpdated(
273 const cc::CompositorFrameMetadata& frame_metadata);
274 void ComputeContentsSize(const cc::CompositorFrameMetadata& frame_metadata);
276 void ShowInternal();
277 void HideInternal(bool hide_frontbuffer, bool stop_observing_root_window);
278 void AttachLayers();
279 void RemoveLayers();
281 // Called after async screenshot task completes. Scales and crops the result
282 // of the copy.
283 static void PrepareTextureCopyOutputResult(
284 const gfx::Size& dst_size_in_pixel,
285 SkColorType color_type,
286 const base::TimeTicks& start_time,
287 ReadbackRequestCallback& callback,
288 scoped_ptr<cc::CopyOutputResult> result);
289 static void PrepareTextureCopyOutputResultForDelegatedReadback(
290 const gfx::Size& dst_size_in_pixel,
291 SkColorType color_type,
292 const base::TimeTicks& start_time,
293 scoped_refptr<cc::Layer> readback_layer,
294 ReadbackRequestCallback& callback,
295 scoped_ptr<cc::CopyOutputResult> result);
297 // DevTools ScreenCast support for Android WebView.
298 void SynchronousCopyContents(const gfx::Rect& src_subrect_in_pixel,
299 const gfx::Size& dst_size_in_pixel,
300 ReadbackRequestCallback& callback,
301 const SkColorType color_type);
303 // If we have locks on a frame during a ContentViewCore swap or a context
304 // lost, the frame is no longer valid and we can safely release all the locks.
305 // Use this method to release all the locks.
306 void ReleaseLocksOnSurface();
308 // Drop any incoming frames from the renderer when there are locks on the
309 // current frame.
310 void RetainFrame(uint32 output_surface_id,
311 scoped_ptr<cc::CompositorFrame> frame);
313 void InternalSwapCompositorFrame(uint32 output_surface_id,
314 scoped_ptr<cc::CompositorFrame> frame);
315 void OnLostResources();
317 enum VSyncRequestType {
318 FLUSH_INPUT = 1 << 0,
319 BEGIN_FRAME = 1 << 1,
320 PERSISTENT_BEGIN_FRAME = 1 << 2
322 void RequestVSyncUpdate(uint32 requests);
323 void StartObservingRootWindow();
324 void StopObservingRootWindow();
325 void SendBeginFrame(base::TimeTicks frame_time, base::TimeDelta vsync_period);
326 bool Animate(base::TimeTicks frame_time);
327 void RequestDisallowInterceptTouchEvent();
329 // The model object.
330 RenderWidgetHostImpl* host_;
332 bool use_surfaces_;
334 // Used to control action dispatch at the next |OnVSync()| call.
335 uint32 outstanding_vsync_requests_;
337 bool is_showing_;
339 // ContentViewCoreImpl is our interface to the view system.
340 ContentViewCoreImpl* content_view_core_;
342 // Cache the WindowAndroid instance exposed by ContentViewCore to avoid
343 // calling into ContentViewCore when it is being detached from the
344 // WebContents during destruction. The WindowAndroid has stronger lifetime
345 // guarantees, and should be safe to use for observer detachment.
346 // This will be non-null iff |content_view_core_| is non-null.
347 ui::WindowAndroid* content_view_core_window_android_;
349 ImeAdapterAndroid ime_adapter_android_;
351 // Body background color of the underlying document.
352 SkColor cached_background_color_;
354 scoped_refptr<cc::DelegatedFrameResourceCollection> resource_collection_;
355 scoped_refptr<cc::DelegatedFrameProvider> frame_provider_;
356 scoped_refptr<cc::Layer> layer_;
358 scoped_ptr<cc::SurfaceIdAllocator> id_allocator_;
359 scoped_ptr<cc::SurfaceFactory> surface_factory_;
360 cc::SurfaceId surface_id_;
361 gfx::Size current_surface_size_;
362 cc::ReturnedResourceArray surface_returned_resources_;
364 // The most recent texture size that was pushed to the texture layer.
365 gfx::Size texture_size_in_layer_;
367 // The most recent content size that was pushed to the texture layer.
368 gfx::Size content_size_in_layer_;
370 // The output surface id of the last received frame.
371 uint32_t last_output_surface_id_;
374 std::queue<base::Closure> ack_callbacks_;
376 // Used to control and render overscroll-related effects.
377 scoped_ptr<OverscrollControllerAndroid> overscroll_controller_;
379 // Provides gesture synthesis given a stream of touch events (derived from
380 // Android MotionEvent's) and touch event acks.
381 ui::FilteredGestureProvider gesture_provider_;
383 // Handles gesture based text selection
384 StylusTextSelector stylus_text_selector_;
386 // Manages selection handle rendering and manipulation.
387 // This will always be NULL if |content_view_core_| is NULL.
388 scoped_ptr<ui::TouchSelectionController> selection_controller_;
390 int accelerated_surface_route_id_;
392 // Size to use if we have no backing ContentViewCore
393 gfx::Size default_size_;
395 const bool using_browser_compositor_;
397 scoped_ptr<DelegatedFrameEvictor> frame_evictor_;
399 size_t locks_on_frame_count_;
400 bool observing_root_window_;
402 struct LastFrameInfo {
403 LastFrameInfo(uint32 output_id,
404 scoped_ptr<cc::CompositorFrame> output_frame);
405 ~LastFrameInfo();
406 uint32 output_surface_id;
407 scoped_ptr<cc::CompositorFrame> frame;
410 scoped_ptr<LastFrameInfo> last_frame_info_;
412 TextSurroundingSelectionCallback text_surrounding_selection_callback_;
414 // The last scroll offset of the view.
415 gfx::Vector2dF last_scroll_offset_;
417 base::WeakPtrFactory<RenderWidgetHostViewAndroid> weak_ptr_factory_;
419 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAndroid);
422 } // namespace content
424 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_ANDROID_H_