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_ANDROID_CONTENT_VIEW_CORE_IMPL_H_
6 #define CONTENT_BROWSER_ANDROID_CONTENT_VIEW_CORE_IMPL_H_
10 #include "base/android/jni_helper.h"
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/i18n/rtl.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/process.h"
16 #include "content/browser/renderer_host/render_widget_host_view_android.h"
17 #include "content/browser/web_contents/web_contents_impl.h"
18 #include "content/public/browser/android/content_view_core.h"
19 #include "content/public/browser/notification_observer.h"
20 #include "content/public/browser/notification_registrar.h"
21 #include "googleurl/src/gurl.h"
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
23 #include "ui/gfx/rect.h"
32 class RenderWidgetHostViewAndroid
;
33 class SyncInputEventFilter
;
35 // TODO(jrg): this is a shell. Upstream the rest.
36 class ContentViewCoreImpl
: public ContentViewCore
,
37 public NotificationObserver
{
39 static ContentViewCoreImpl
* FromWebContents(WebContents
* web_contents
);
40 ContentViewCoreImpl(JNIEnv
* env
,
42 bool hardware_accelerated
,
43 bool input_events_delivered_at_vsync
,
44 WebContents
* web_contents
,
45 ui::WindowAndroid
* window_android
);
47 // ContentViewCore implementation.
48 virtual base::android::ScopedJavaLocalRef
<jobject
> GetJavaObject() OVERRIDE
;
49 virtual base::android::ScopedJavaLocalRef
<jobject
> GetContainerViewDelegate()
51 virtual WebContents
* GetWebContents() const OVERRIDE
;
52 virtual ui::WindowAndroid
* GetWindowAndroid() const OVERRIDE
;
53 virtual scoped_refptr
<cc::Layer
> GetLayer() const OVERRIDE
;
54 virtual void LoadUrl(NavigationController::LoadURLParams
& params
) OVERRIDE
;
55 virtual void OnWebPreferencesUpdated() OVERRIDE
;
56 virtual jint
GetCurrentRenderProcessId(JNIEnv
* env
, jobject obj
) OVERRIDE
;
57 virtual void ShowPastePopup(int x
, int y
) OVERRIDE
;
58 virtual unsigned int GetScaledContentTexture(
60 gfx::Size
* out_size
) OVERRIDE
;
61 virtual float GetDpiScale() const OVERRIDE
;
62 virtual void SetInputHandler(
63 WebKit::WebCompositorInputHandler
* input_handler
) OVERRIDE
;
64 virtual void AddFrameInfoCallback(
65 const UpdateFrameInfoCallback
& callback
) OVERRIDE
;
66 virtual void RemoveFrameInfoCallback(
67 const UpdateFrameInfoCallback
& callback
) OVERRIDE
;
69 // --------------------------------------------------------------------------
70 // Methods called from Java via JNI
71 // --------------------------------------------------------------------------
73 void OnJavaContentViewCoreDestroyed(JNIEnv
* env
, jobject obj
);
75 // Notifies the ContentViewCore that items were selected in the currently
76 // showing select popup.
77 void SelectPopupMenuItems(JNIEnv
* env
, jobject obj
, jintArray indices
);
80 JNIEnv
* env
, jobject obj
,
84 jint ua_override_option
,
85 jstring extra_headers
,
87 jstring base_url_for_data_url
,
88 jstring virtual_url_for_data_url
,
89 jboolean can_load_local_resources
);
90 void SetAllUserAgentOverridesInHistory(
93 jstring user_agent_override
);
94 base::android::ScopedJavaLocalRef
<jstring
> GetURL(JNIEnv
* env
, jobject
) const;
95 base::android::ScopedJavaLocalRef
<jstring
> GetTitle(
96 JNIEnv
* env
, jobject obj
) const;
97 jboolean
IsIncognito(JNIEnv
* env
, jobject obj
);
98 jboolean
Crashed(JNIEnv
* env
, jobject obj
) const { return tab_crashed_
; }
99 void SendOrientationChangeEvent(JNIEnv
* env
, jobject obj
, jint orientation
);
100 jboolean
SendTouchEvent(JNIEnv
* env
,
105 jboolean
SendMouseMoveEvent(JNIEnv
* env
,
110 jboolean
SendMouseWheelEvent(JNIEnv
* env
,
115 jfloat vertical_axis
);
116 void ScrollBegin(JNIEnv
* env
, jobject obj
, jlong time_ms
, jfloat x
, jfloat y
);
117 void ScrollEnd(JNIEnv
* env
, jobject obj
, jlong time_ms
);
118 void ScrollBy(JNIEnv
* env
, jobject obj
, jlong time_ms
,
119 jfloat x
, jfloat y
, jfloat dx
, jfloat dy
);
120 void FlingStart(JNIEnv
* env
, jobject obj
, jlong time_ms
,
121 jfloat x
, jfloat y
, jfloat vx
, jfloat vy
);
122 void FlingCancel(JNIEnv
* env
, jobject obj
, jlong time_ms
);
123 void SingleTap(JNIEnv
* env
, jobject obj
, jlong time_ms
,
125 jboolean disambiguation_popup_tap
);
126 void ShowPressState(JNIEnv
* env
, jobject obj
, jlong time_ms
,
128 void ShowPressCancel(JNIEnv
* env
, jobject obj
, jlong time_ms
,
130 void DoubleTap(JNIEnv
* env
, jobject obj
, jlong time_ms
,
131 jfloat x
, jfloat y
) ;
132 void LongPress(JNIEnv
* env
, jobject obj
, jlong time_ms
,
134 jboolean disambiguation_popup_tap
);
135 void LongTap(JNIEnv
* env
, jobject obj
, jlong time_ms
,
137 jboolean disambiguation_popup_tap
);
138 void PinchBegin(JNIEnv
* env
, jobject obj
, jlong time_ms
, jfloat x
, jfloat y
);
139 void PinchEnd(JNIEnv
* env
, jobject obj
, jlong time_ms
);
140 void PinchBy(JNIEnv
* env
, jobject obj
, jlong time_ms
,
143 void SelectBetweenCoordinates(JNIEnv
* env
, jobject obj
,
144 jfloat x1
, jfloat y1
,
145 jfloat x2
, jfloat y2
);
146 void MoveCaret(JNIEnv
* env
, jobject obj
, jfloat x
, jfloat y
);
148 jboolean
CanGoBack(JNIEnv
* env
, jobject obj
);
149 jboolean
CanGoForward(JNIEnv
* env
, jobject obj
);
150 jboolean
CanGoToOffset(JNIEnv
* env
, jobject obj
, jint offset
);
151 void GoBack(JNIEnv
* env
, jobject obj
);
152 void GoForward(JNIEnv
* env
, jobject obj
);
153 void GoToOffset(JNIEnv
* env
, jobject obj
, jint offset
);
154 void GoToNavigationIndex(JNIEnv
* env
, jobject obj
, jint index
);
155 void StopLoading(JNIEnv
* env
, jobject obj
);
156 void Reload(JNIEnv
* env
, jobject obj
);
157 void CancelPendingReload(JNIEnv
* env
, jobject obj
);
158 void ContinuePendingReload(JNIEnv
* env
, jobject obj
);
159 jboolean
NeedsReload(JNIEnv
* env
, jobject obj
);
160 void ClearHistory(JNIEnv
* env
, jobject obj
);
161 void EvaluateJavaScript(JNIEnv
* env
,
165 int GetNativeImeAdapter(JNIEnv
* env
, jobject obj
);
166 void SetFocus(JNIEnv
* env
, jobject obj
, jboolean focused
);
167 void ScrollFocusedEditableNodeIntoView(JNIEnv
* env
, jobject obj
);
168 void UndoScrollFocusedEditableNodeIntoView(JNIEnv
* env
, jobject obj
);
170 jint
GetBackgroundColor(JNIEnv
* env
, jobject obj
);
171 void SetBackgroundColor(JNIEnv
* env
, jobject obj
, jint color
);
172 void OnShow(JNIEnv
* env
, jobject obj
);
173 void OnHide(JNIEnv
* env
, jobject obj
);
174 void ClearSslPreferences(JNIEnv
* env
, jobject
/* obj */);
175 void SetUseDesktopUserAgent(JNIEnv
* env
,
178 jboolean reload_on_state_change
);
179 bool GetUseDesktopUserAgent(JNIEnv
* env
, jobject
/* obj */);
182 void AddJavascriptInterface(JNIEnv
* env
,
186 jclass safe_annotation_clazz
,
187 jobject retained_object_set
);
188 void RemoveJavascriptInterface(JNIEnv
* env
, jobject obj
, jstring name
);
189 int GetNavigationHistory(JNIEnv
* env
, jobject obj
, jobject context
);
190 void GetDirectedNavigationHistory(JNIEnv
* env
,
195 void UpdateVSyncParameters(JNIEnv
* env
, jobject obj
, jlong timebase_micros
,
196 jlong interval_micros
);
197 jboolean
PopulateBitmapFromCompositor(JNIEnv
* env
,
200 void WasResized(JNIEnv
* env
, jobject obj
);
201 jboolean
IsRenderWidgetHostViewReady(JNIEnv
* env
, jobject obj
);
202 void ExitFullscreen(JNIEnv
* env
, jobject obj
);
203 void UpdateTopControlsState(JNIEnv
* env
,
208 void ShowImeIfNeeded(JNIEnv
* env
, jobject obj
);
210 void ShowInterstitialPage(JNIEnv
* env
,
214 jboolean
IsShowingInterstitialPage(JNIEnv
* env
, jobject obj
);
216 void AttachExternalVideoSurface(JNIEnv
* env
,
220 void DetachExternalVideoSurface(JNIEnv
* env
, jobject obj
, jint player_id
);
222 // --------------------------------------------------------------------------
223 // Public methods that call to Java via JNI
224 // --------------------------------------------------------------------------
226 // Creates a popup menu with |items|.
227 // |multiple| defines if it should support multi-select.
228 // If not |multiple|, |selected_item| sets the initially selected item.
229 // Otherwise, item's "checked" flag selects it.
230 void ShowSelectPopupMenu(const std::vector
<WebMenuItem
>& items
,
236 // All sizes and offsets are in CSS pixels as cached by the renderer.
237 void UpdateFrameInfo(const gfx::Vector2dF
& scroll_offset
,
238 float page_scale_factor
,
239 const gfx::Vector2dF
& page_scale_factor_limits
,
240 const gfx::SizeF
& content_size
,
241 const gfx::SizeF
& viewport_size
,
242 const gfx::Vector2dF
& controls_offset
,
243 const gfx::Vector2dF
& content_offset
,
244 float overdraw_bottom_height
);
246 void UpdateImeAdapter(int native_ime_adapter
, int text_input_type
,
247 const std::string
& text
,
248 int selection_start
, int selection_end
,
249 int composition_start
, int composition_end
,
250 bool show_ime_if_needed
);
251 void ProcessImeBatchStateAck(bool is_begin
);
252 void SetTitle(const string16
& title
);
253 void OnBackgroundColorChanged(SkColor color
);
256 void ConfirmTouchEvent(InputEventAckState ack_result
);
257 void HasTouchEventHandlers(bool need_touch_events
);
258 void OnSelectionChanged(const std::string
& text
);
259 void OnSelectionBoundsChanged(
260 const ViewHostMsg_SelectionBounds_Params
& params
);
262 void StartContentIntent(const GURL
& content_url
);
264 // Shows the disambiguation popup
265 // |target_rect| --> window coordinates which |zoomed_bitmap| represents
266 // |zoomed_bitmap| --> magnified image of potential touch targets
267 void ShowDisambiguationPopup(
268 const gfx::Rect
& target_rect
, const SkBitmap
& zoomed_bitmap
);
270 void RequestExternalVideoSurface(int player_id
);
272 // --------------------------------------------------------------------------
273 // Methods called from native code
274 // --------------------------------------------------------------------------
276 gfx::Size
GetPhysicalBackingSize() const;
277 gfx::Size
GetViewportSizeDip() const;
278 gfx::Size
GetViewportSizeOffsetDip() const;
279 float GetOverdrawBottomHeightDip() const;
281 InputEventAckState
FilterInputEvent(const WebKit::WebInputEvent
& input_event
);
283 void AttachLayer(scoped_refptr
<cc::Layer
> layer
);
284 void RemoveLayer(scoped_refptr
<cc::Layer
> layer
);
287 class ContentViewUserData
;
289 friend class ContentViewUserData
;
290 virtual ~ContentViewCoreImpl();
292 // NotificationObserver implementation.
293 virtual void Observe(int type
,
294 const NotificationSource
& source
,
295 const NotificationDetails
& details
) OVERRIDE
;
297 // --------------------------------------------------------------------------
298 // Other private methods and data
299 // --------------------------------------------------------------------------
301 void InitWebContents();
303 RenderWidgetHostViewAndroid
* GetRenderWidgetHostViewAndroid();
305 float GetTouchPaddingDip();
307 WebKit::WebGestureEvent
MakeGestureEvent(
308 WebKit::WebInputEvent::Type type
, long time_ms
,
309 float xPix
, float yPix
) const;
311 gfx::Size
GetViewportSizePix() const;
312 gfx::Size
GetViewportSizeOffsetPix() const;
314 void UpdateVSyncFlagOnInputEvent(WebKit::WebInputEvent
* event
) const;
316 void DeleteScaledSnapshotTexture();
318 void SendGestureEvent(const WebKit::WebGestureEvent
& event
);
320 // A weak reference to the Java ContentViewCore object.
321 JavaObjectWeakGlobalRef java_ref_
;
323 NotificationRegistrar notification_registrar_
;
325 // Reference to the current WebContents used to determine how and what to
326 // display in the ContentViewCore.
327 WebContentsImpl
* web_contents_
;
329 // A compositor layer containing any layer that should be shown.
330 scoped_refptr
<cc::Layer
> root_layer_
;
332 // Whether the renderer backing this ContentViewCore has crashed.
335 // Whether input events will be consistently delivered at vsync time.
336 bool input_events_delivered_at_vsync_
;
338 // Device scale factor.
341 // The owning window that has a hold of main application activity.
342 ui::WindowAndroid
* window_android_
;
344 std::vector
<UpdateFrameInfoCallback
> update_frame_info_callbacks_
;
346 // Optional browser-side input event filtering.
347 scoped_ptr
<SyncInputEventFilter
> input_event_filter_
;
349 DISALLOW_COPY_AND_ASSIGN(ContentViewCoreImpl
);
352 bool RegisterContentViewCore(JNIEnv
* env
);
354 } // namespace content
356 #endif // CONTENT_BROWSER_ANDROID_CONTENT_VIEW_CORE_IMPL_H_