#ifndef CONTENT_BROWSER_ANDROID_CONTENT_VIEW_CORE_IMPL_H_
#define CONTENT_BROWSER_ANDROID_CONTENT_VIEW_CORE_IMPL_H_
#include <vector>
#include "base/android/jni_android.h"
#include "base/android/jni_helper.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/i18n/rtl.h"
#include "base/memory/scoped_ptr.h"
#include "base/process/process.h"
#include "content/browser/renderer_host/render_widget_host_view_android.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/android/content_view_core.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/web_contents_observer.h"
#include "third_party/WebKit/public/web/WebInputEvent.h"
#include "ui/events/gesture_detection/filtered_gesture_provider.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/rect_f.h"
#include "url/gurl.h"
namespace ui {
class ViewAndroid;
class WindowAndroid;
}
namespace content {
class RenderWidgetHostViewAndroid;
struct MenuItem;
class ContentViewCoreImpl : public ContentViewCore,
public ui::GestureProviderClient,
public NotificationObserver,
public WebContentsObserver {
public:
static ContentViewCoreImpl* FromWebContents(WebContents* web_contents);
ContentViewCoreImpl(JNIEnv* env,
jobject obj,
WebContents* web_contents,
ui::ViewAndroid* view_android,
ui::WindowAndroid* window_android);
virtual base::android::ScopedJavaLocalRef<jobject> GetJavaObject() OVERRIDE;
virtual WebContents* GetWebContents() const OVERRIDE;
virtual ui::ViewAndroid* GetViewAndroid() const OVERRIDE;
virtual ui::WindowAndroid* GetWindowAndroid() const OVERRIDE;
virtual scoped_refptr<cc::Layer> GetLayer() const OVERRIDE;
virtual void LoadUrl(NavigationController::LoadURLParams& params) OVERRIDE;
virtual void ShowPastePopup(int x, int y) OVERRIDE;
virtual void GetScaledContentBitmap(
float scale,
jobject bitmap_config,
gfx::Rect src_subrect,
const base::Callback<void(bool, const SkBitmap&)>& result_callback)
OVERRIDE;
virtual float GetDpiScale() const OVERRIDE;
virtual void PauseVideo() OVERRIDE;
virtual void PauseOrResumeGeolocation(bool should_pause) OVERRIDE;
base::android::ScopedJavaLocalRef<jobject> GetWebContentsAndroid(JNIEnv* env,
jobject obj);
void OnJavaContentViewCoreDestroyed(JNIEnv* env, jobject obj);
void SelectPopupMenuItems(JNIEnv* env, jobject obj, jintArray indices);
void LoadUrl(
JNIEnv* env, jobject obj,
jstring url,
jint load_url_type,
jint transition_type,
jint ua_override_option,
jstring extra_headers,
jbyteArray post_data,
jstring base_url_for_data_url,
jstring virtual_url_for_data_url,
jboolean can_load_local_resources);
base::android::ScopedJavaLocalRef<jstring> GetURL(JNIEnv* env, jobject) const;
base::android::ScopedJavaLocalRef<jstring> GetTitle(
JNIEnv* env, jobject obj) const;
jboolean IsIncognito(JNIEnv* env, jobject obj);
void SendOrientationChangeEvent(JNIEnv* env, jobject obj, jint orientation);
jboolean OnTouchEvent(JNIEnv* env,
jobject obj,
jobject motion_event,
jlong time_ms,
jint android_action,
jint pointer_count,
jint history_size,
jint action_index,
jfloat pos_x_0,
jfloat pos_y_0,
jfloat pos_x_1,
jfloat pos_y_1,
jint pointer_id_0,
jint pointer_id_1,
jfloat touch_major_0,
jfloat touch_major_1);
jboolean SendMouseMoveEvent(JNIEnv* env,
jobject obj,
jlong time_ms,
jfloat x,
jfloat y);
jboolean SendMouseWheelEvent(JNIEnv* env,
jobject obj,
jlong time_ms,
jfloat x,
jfloat y,
jfloat vertical_axis);
void ScrollBegin(JNIEnv* env, jobject obj, jlong time_ms,
jfloat x, jfloat y, jfloat hintx, jfloat hinty);
void ScrollEnd(JNIEnv* env, jobject obj, jlong time_ms);
void ScrollBy(JNIEnv* env, jobject obj, jlong time_ms,
jfloat x, jfloat y, jfloat dx, jfloat dy);
void FlingStart(JNIEnv* env, jobject obj, jlong time_ms,
jfloat x, jfloat y, jfloat vx, jfloat vy);
void FlingCancel(JNIEnv* env, jobject obj, jlong time_ms);
void SingleTap(JNIEnv* env, jobject obj, jlong time_ms,
jfloat x, jfloat y);
void DoubleTap(JNIEnv* env, jobject obj, jlong time_ms,
jfloat x, jfloat y) ;
void LongPress(JNIEnv* env, jobject obj, jlong time_ms,
jfloat x, jfloat y);
void PinchBegin(JNIEnv* env, jobject obj, jlong time_ms, jfloat x, jfloat y);
void PinchEnd(JNIEnv* env, jobject obj, jlong time_ms);
void PinchBy(JNIEnv* env, jobject obj, jlong time_ms,
jfloat x, jfloat y, jfloat delta);
void SelectBetweenCoordinates(JNIEnv* env, jobject obj,
jfloat x1, jfloat y1,
jfloat x2, jfloat y2);
void MoveCaret(JNIEnv* env, jobject obj, jfloat x, jfloat y);
void ResetGestureDetectors(JNIEnv* env, jobject obj);
void IgnoreRemainingTouchEvents(JNIEnv* env, jobject obj);
void OnWindowFocusLost(JNIEnv* env, jobject obj);
void SetDoubleTapSupportForPageEnabled(JNIEnv* env,
jobject obj,
jboolean enabled);
void SetDoubleTapSupportEnabled(JNIEnv* env, jobject obj, jboolean enabled);
void SetMultiTouchZoomSupportEnabled(JNIEnv* env,
jobject obj,
jboolean enabled);
void LoadIfNecessary(JNIEnv* env, jobject obj);
void RequestRestoreLoad(JNIEnv* env, jobject obj);
void StopLoading(JNIEnv* env, jobject obj);
void Reload(JNIEnv* env, jobject obj, jboolean check_for_repost);
void ReloadIgnoringCache(JNIEnv* env, jobject obj, jboolean check_for_repost);
void CancelPendingReload(JNIEnv* env, jobject obj);
void ContinuePendingReload(JNIEnv* env, jobject obj);
void ClearHistory(JNIEnv* env, jobject obj);
void EvaluateJavaScript(JNIEnv* env,
jobject obj,
jstring script,
jobject callback,
jboolean start_renderer);
int GetNativeImeAdapter(JNIEnv* env, jobject obj);
void SetFocus(JNIEnv* env, jobject obj, jboolean focused);
void ScrollFocusedEditableNodeIntoView(JNIEnv* env, jobject obj);
jint GetBackgroundColor(JNIEnv* env, jobject obj);
void SetBackgroundColor(JNIEnv* env, jobject obj, jint color);
void OnShow(JNIEnv* env, jobject obj);
void OnHide(JNIEnv* env, jobject obj);
void ClearSslPreferences(JNIEnv* env, jobject );
void SetUseDesktopUserAgent(JNIEnv* env,
jobject ,
jboolean state,
jboolean reload_on_state_change);
bool GetUseDesktopUserAgent(JNIEnv* env, jobject );
void Show();
void Hide();
void SetAllowJavascriptInterfacesInspection(JNIEnv* env,
jobject obj,
jboolean allow);
void AddJavascriptInterface(JNIEnv* env,
jobject obj,
jobject object,
jstring name,
jclass safe_annotation_clazz,
jobject retained_object_set);
void RemoveJavascriptInterface(JNIEnv* env, jobject obj, jstring name);
int GetNavigationHistory(JNIEnv* env, jobject obj, jobject history);
void GetDirectedNavigationHistory(JNIEnv* env,
jobject obj,
jobject history,
jboolean is_forward,
jint max_entries);
base::android::ScopedJavaLocalRef<jstring>
GetOriginalUrlForActiveNavigationEntry(JNIEnv* env, jobject obj);
void UpdateVSyncParameters(JNIEnv* env, jobject obj, jlong timebase_micros,
jlong interval_micros);
void OnVSync(JNIEnv* env, jobject , jlong frame_time_micros);
jboolean OnAnimate(JNIEnv* env, jobject , jlong frame_time_micros);
void WasResized(JNIEnv* env, jobject obj);
jboolean IsRenderWidgetHostViewReady(JNIEnv* env, jobject obj);
void ExitFullscreen(JNIEnv* env, jobject obj);
void UpdateTopControlsState(JNIEnv* env,
jobject obj,
bool enable_hiding,
bool enable_showing,
bool animate);
void ShowImeIfNeeded(JNIEnv* env, jobject obj);
void ShowInterstitialPage(JNIEnv* env,
jobject obj,
jstring jurl,
jint delegate);
jboolean IsShowingInterstitialPage(JNIEnv* env, jobject obj);
void SetAccessibilityEnabled(JNIEnv* env, jobject obj, bool enabled);
void ExtractSmartClipData(JNIEnv* env,
jobject obj,
jint x,
jint y,
jint width,
jint height);
jint GetCurrentRenderProcessId(JNIEnv* env, jobject obj);
void OnSmartClipDataExtracted(const base::string16& result);
void ShowSelectPopupMenu(const std::vector<MenuItem>& items,
int selected_item,
bool multiple);
void OnTabCrashed();
void UpdateFrameInfo(const gfx::Vector2dF& scroll_offset,
float page_scale_factor,
const gfx::Vector2dF& page_scale_factor_limits,
const gfx::SizeF& content_size,
const gfx::SizeF& viewport_size,
const gfx::Vector2dF& controls_offset,
const gfx::Vector2dF& content_offset,
float overdraw_bottom_height);
void UpdateImeAdapter(long native_ime_adapter, int text_input_type,
const std::string& text,
int selection_start, int selection_end,
int composition_start, int composition_end,
bool show_ime_if_needed, bool require_ack);
void SetTitle(const base::string16& title);
void OnBackgroundColorChanged(SkColor color);
bool HasFocus();
void ConfirmTouchEvent(InputEventAckState ack_result);
void OnGestureEventAck(const blink::WebGestureEvent& event,
InputEventAckState ack_result);
bool FilterInputEvent(const blink::WebInputEvent& event);
void OnSelectionChanged(const std::string& text);
void OnSelectionBoundsChanged(
const ViewHostMsg_SelectionBounds_Params& params);
void OnSelectionRootBoundsChanged(const gfx::Rect& bounds);
void StartContentIntent(const GURL& content_url);
void ShowDisambiguationPopup(
const gfx::Rect& target_rect, const SkBitmap& zoomed_bitmap);
base::android::ScopedJavaLocalRef<jobject> CreateTouchEventSynthesizer();
base::android::ScopedJavaLocalRef<jobject> GetContentVideoViewClient();
base::android::ScopedJavaLocalRef<jobject> GetContext();
bool ShouldBlockMediaRequest(const GURL& url);
void DidStopFlinging();
gfx::Size GetPhysicalBackingSize() const;
gfx::Size GetViewportSizeDip() const;
gfx::Size GetViewportSizeOffsetDip() const;
float GetOverdrawBottomHeightDip() const;
void AttachLayer(scoped_refptr<cc::Layer> layer);
void RemoveLayer(scoped_refptr<cc::Layer> layer);
void AddBeginFrameSubscriber();
void RemoveBeginFrameSubscriber();
void SetNeedsAnimate();
private:
class ContentViewUserData;
friend class ContentViewUserData;
virtual ~ContentViewCoreImpl();
virtual void Observe(int type,
const NotificationSource& source,
const NotificationDetails& details) OVERRIDE;
virtual void RenderViewReady() OVERRIDE;
virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE;
virtual void OnGestureEvent(const ui::GestureEventData& gesture) OVERRIDE;
void InitWebContents();
RenderWidgetHostViewAndroid* GetRenderWidgetHostViewAndroid();
blink::WebGestureEvent MakeGestureEvent(
blink::WebInputEvent::Type type, int64 time_ms, float x, float y) const;
void SendBeginFrame(base::TimeTicks frame_time);
gfx::Size GetViewportSizePix() const;
gfx::Size GetViewportSizeOffsetPix() const;
void DeleteScaledSnapshotTexture();
bool OnMotionEvent(const ui::MotionEvent& event);
void SendGestureEvent(const blink::WebGestureEvent& event);
void SetFocusInternal(bool focused);
void SendOrientationChangeEventInternal();
void CancelActiveTouchSequenceIfNecessary();
float dpi_scale() const { return dpi_scale_; }
JavaObjectWeakGlobalRef java_ref_;
NotificationRegistrar notification_registrar_;
WebContentsImpl* web_contents_;
scoped_refptr<cc::Layer> root_layer_;
float dpi_scale_;
base::TimeDelta vsync_interval_;
base::TimeDelta expected_browser_composite_time_;
ui::ViewAndroid* view_android_;
ui::WindowAndroid* window_android_;
ui::FilteredGestureProvider gesture_provider_;
int device_orientation_;
bool geolocation_needs_pause_;
DISALLOW_COPY_AND_ASSIGN(ContentViewCoreImpl);
};
bool RegisterContentViewCore(JNIEnv* env);
}
#endif