[Android WebView] Handle clip size smaller than visible rect
[chromium-blink-merge.git] / android_webview / native / aw_contents.h
blob270201a0b7cdeed070f1f30fba73be0d8d433a91
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 ANDROID_WEBVIEW_NATIVE_AW_CONTENTS_H_
6 #define ANDROID_WEBVIEW_NATIVE_AW_CONTENTS_H_
8 #include <jni.h>
9 #include <list>
10 #include <string>
11 #include <utility>
13 #include "android_webview/browser/browser_view_renderer.h"
14 #include "android_webview/browser/find_helper.h"
15 #include "android_webview/browser/icon_helper.h"
16 #include "android_webview/browser/renderer_host/aw_render_view_host_ext.h"
17 #include "base/android/scoped_java_ref.h"
18 #include "base/android/jni_helper.h"
19 #include "base/callback_forward.h"
20 #include "base/memory/scoped_ptr.h"
22 class SkBitmap;
23 class TabContents;
25 namespace content {
26 class WebContents;
29 namespace android_webview {
31 class AwContentsContainer;
32 class AwContentsClientBridge;
33 class AwWebContentsDelegate;
35 // Native side of java-class of same name.
36 // Provides the ownership of and access to browser components required for
37 // WebView functionality; analogous to chrome's TabContents, but with a
38 // level of indirection provided by the AwContentsContainer abstraction.
40 // Object lifetime:
41 // For most purposes the java and native objects can be considered to have
42 // 1:1 lifetime and relationship. The exception is the java instance that
43 // hosts a popup will be rebound to a second native instance (carrying the
44 // popup content) and discard the 'default' native instance it made on
45 // construction. A native instance is only bound to at most one Java peer over
46 // its entire lifetime - see Init() and SetPendingWebContentsForPopup() for the
47 // construction points, and SetJavaPeers() where these paths join.
48 class AwContents : public FindHelper::Listener,
49 public IconHelper::Listener,
50 public AwRenderViewHostExtClient,
51 public BrowserViewRenderer::Client {
52 public:
53 // Returns the AwContents instance associated with |web_contents|, or NULL.
54 static AwContents* FromWebContents(content::WebContents* web_contents);
56 // Returns the AwContents instance associated with with the given
57 // render_process_id and render_view_id, or NULL.
58 static AwContents* FromID(int render_process_id, int render_view_id);
60 AwContents(scoped_ptr<content::WebContents> web_contents);
61 virtual ~AwContents();
63 AwRenderViewHostExt* render_view_host_ext() {
64 return render_view_host_ext_.get();
67 void PerformLongClick();
69 // |handler| is an instance of
70 // org.chromium.android_webview.AwHttpAuthHandler.
71 bool OnReceivedHttpAuthRequest(const base::android::JavaRef<jobject>& handler,
72 const std::string& host,
73 const std::string& realm);
75 // Methods called from Java.
76 void SetJavaPeers(JNIEnv* env,
77 jobject obj,
78 jobject aw_contents,
79 jobject web_contents_delegate,
80 jobject contents_client_bridge,
81 jobject io_thread_client,
82 jobject intercept_navigation_delegate);
83 jint GetWebContents(JNIEnv* env, jobject obj);
84 jint GetAwContentsClientBridge(JNIEnv* env, jobject obj);
86 void Destroy(JNIEnv* env, jobject obj);
87 void DocumentHasImages(JNIEnv* env, jobject obj, jobject message);
88 void GenerateMHTML(JNIEnv* env, jobject obj, jstring jpath, jobject callback);
89 void AddVisitedLinks(JNIEnv* env, jobject obj, jobjectArray jvisited_links);
90 base::android::ScopedJavaLocalRef<jbyteArray> GetCertificate(
91 JNIEnv* env, jobject obj);
92 void RequestNewHitTestDataAt(JNIEnv* env, jobject obj, jint x, jint y);
93 void UpdateLastHitTestData(JNIEnv* env, jobject obj);
94 void OnSizeChanged(JNIEnv* env, jobject obj, int w, int h, int ow, int oh);
95 void SetVisibility(JNIEnv* env, jobject obj, bool visible);
96 void OnAttachedToWindow(JNIEnv* env, jobject obj, int w, int h);
97 void OnDetachedFromWindow(JNIEnv* env, jobject obj);
98 base::android::ScopedJavaLocalRef<jbyteArray> GetOpaqueState(
99 JNIEnv* env, jobject obj);
100 jboolean RestoreFromOpaqueState(JNIEnv* env, jobject obj, jbyteArray state);
101 void FocusFirstNode(JNIEnv* env, jobject obj);
102 void SetBackgroundColor(JNIEnv* env, jobject obj, jint color);
103 bool OnDraw(JNIEnv* env,
104 jobject obj,
105 jobject canvas,
106 jboolean is_hardware_accelerated,
107 jint scroll_x,
108 jint scroll_y,
109 jint clip_left,
110 jint clip_top,
111 jint clip_right,
112 jint clip_bottom);
113 void SetGlobalVisibleRect(JNIEnv* env,
114 jobject obj,
115 jint visible_left,
116 jint visible_top,
117 jint visible_right,
118 jint visible_bottom);
119 jint GetAwDrawGLViewContext(JNIEnv* env, jobject obj);
120 base::android::ScopedJavaLocalRef<jobject> CapturePicture(JNIEnv* env,
121 jobject obj,
122 int width,
123 int height);
124 void EnableOnNewPicture(JNIEnv* env, jobject obj, jboolean enabled);
126 // Geolocation API support
127 void ShowGeolocationPrompt(const GURL& origin, base::Callback<void(bool)>);
128 void HideGeolocationPrompt(const GURL& origin);
129 void InvokeGeolocationCallback(JNIEnv* env,
130 jobject obj,
131 jboolean value,
132 jstring origin);
134 // Find-in-page API and related methods.
135 void FindAllAsync(JNIEnv* env, jobject obj, jstring search_string);
136 void FindNext(JNIEnv* env, jobject obj, jboolean forward);
137 void ClearMatches(JNIEnv* env, jobject obj);
138 FindHelper* GetFindHelper();
140 // FindHelper::Listener implementation.
141 virtual void OnFindResultReceived(int active_ordinal,
142 int match_count,
143 bool finished) OVERRIDE;
144 // IconHelper::Listener implementation.
145 virtual void OnReceivedIcon(const GURL& icon_url,
146 const SkBitmap& bitmap) OVERRIDE;
147 virtual void OnReceivedTouchIconUrl(const std::string& url,
148 const bool precomposed) OVERRIDE;
150 // AwRenderViewHostExtClient implementation.
151 virtual void OnWebLayoutPageScaleFactorChanged(
152 float page_scale_factor) OVERRIDE;
154 // BrowserViewRenderer::Client implementation.
155 virtual bool RequestDrawGL(jobject canvas) OVERRIDE;
156 virtual void PostInvalidate() OVERRIDE;
157 virtual void UpdateGlobalVisibleRect() OVERRIDE;
158 virtual void OnNewPicture() OVERRIDE;
159 virtual gfx::Point GetLocationOnScreen() OVERRIDE;
160 virtual void ScrollContainerViewTo(gfx::Vector2d new_value) OVERRIDE;
161 virtual void DidOverscroll(gfx::Vector2d overscroll_delta) OVERRIDE;
163 void ClearCache(JNIEnv* env, jobject obj, jboolean include_disk_files);
164 void SetPendingWebContentsForPopup(scoped_ptr<content::WebContents> pending);
165 jint ReleasePopupAwContents(JNIEnv* env, jobject obj);
167 void ScrollTo(JNIEnv* env, jobject obj, jint xPix, jint yPix);
168 void SetDipScale(JNIEnv* env, jobject obj, jfloat dipScale);
169 void SetDisplayedPageScaleFactor(JNIEnv* env,
170 jobject obj,
171 jfloat pageScaleFactor);
173 void SetSaveFormData(bool enabled);
175 // Sets the java delegate
176 void SetAwAutofillManagerDelegate(jobject delegate);
177 private:
178 void InitAutofillIfNecessary(bool enabled);
180 JavaObjectWeakGlobalRef java_ref_;
181 scoped_ptr<content::WebContents> web_contents_;
182 scoped_ptr<AwWebContentsDelegate> web_contents_delegate_;
183 scoped_ptr<AwContentsClientBridge> contents_client_bridge_;
184 scoped_ptr<AwRenderViewHostExt> render_view_host_ext_;
185 scoped_ptr<FindHelper> find_helper_;
186 scoped_ptr<IconHelper> icon_helper_;
187 scoped_ptr<AwContents> pending_contents_;
188 scoped_ptr<BrowserViewRenderer> browser_view_renderer_;
190 // GURL is supplied by the content layer as requesting frame.
191 // Callback is supplied by the content layer, and is invoked with the result
192 // from the permission prompt.
193 typedef std::pair<const GURL, base::Callback<void(bool)> > OriginCallback;
194 // The first element in the list is always the currently pending request.
195 std::list<OriginCallback> pending_geolocation_prompts_;
197 DISALLOW_COPY_AND_ASSIGN(AwContents);
200 bool RegisterAwContents(JNIEnv* env);
202 } // namespace android_webview
204 #endif // ANDROID_WEBVIEW_NATIVE_AW_CONTENTS_H_