Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / android_webview / native / aw_contents.h
blob32a7429a40d347d6e12cdd39f28a19fad43233d1
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/aw_browser_permission_request_delegate.h"
14 #include "android_webview/browser/aw_message_port_message_filter.h"
15 #include "android_webview/browser/browser_view_renderer.h"
16 #include "android_webview/browser/browser_view_renderer_client.h"
17 #include "android_webview/browser/find_helper.h"
18 #include "android_webview/browser/gl_view_renderer_manager.h"
19 #include "android_webview/browser/icon_helper.h"
20 #include "android_webview/browser/renderer_host/aw_render_view_host_ext.h"
21 #include "android_webview/native/permission/permission_request_handler_client.h"
22 #include "base/android/jni_weak_ref.h"
23 #include "base/android/scoped_java_ref.h"
24 #include "base/callback_forward.h"
25 #include "base/memory/scoped_ptr.h"
27 class SkBitmap;
28 class TabContents;
29 struct AwDrawGLInfo;
31 namespace content {
32 class WebContents;
35 namespace android_webview {
37 class AwContentsContainer;
38 class AwContentsClientBridge;
39 class AwPdfExporter;
40 class AwWebContentsDelegate;
41 class HardwareRenderer;
42 class PermissionRequestHandler;
44 // Native side of java-class of same name.
45 // Provides the ownership of and access to browser components required for
46 // WebView functionality; analogous to chrome's TabContents, but with a
47 // level of indirection provided by the AwContentsContainer abstraction.
49 // Object lifetime:
50 // For most purposes the java and native objects can be considered to have
51 // 1:1 lifetime and relationship. The exception is the java instance that
52 // hosts a popup will be rebound to a second native instance (carrying the
53 // popup content) and discard the 'default' native instance it made on
54 // construction. A native instance is only bound to at most one Java peer over
55 // its entire lifetime - see Init() and SetPendingWebContentsForPopup() for the
56 // construction points, and SetJavaPeers() where these paths join.
57 class AwContents : public FindHelper::Listener,
58 public IconHelper::Listener,
59 public AwRenderViewHostExtClient,
60 public BrowserViewRendererClient,
61 public PermissionRequestHandlerClient,
62 public AwBrowserPermissionRequestDelegate {
63 public:
64 // Returns the AwContents instance associated with |web_contents|, or NULL.
65 static AwContents* FromWebContents(content::WebContents* web_contents);
67 // Returns the AwContents instance associated with with the given
68 // render_process_id and render_view_id, or NULL.
69 static AwContents* FromID(int render_process_id, int render_view_id);
71 static std::string GetLocale();
73 AwContents(scoped_ptr<content::WebContents> web_contents);
74 ~AwContents() override;
76 AwRenderViewHostExt* render_view_host_ext() {
77 return render_view_host_ext_.get();
80 // |handler| is an instance of
81 // org.chromium.android_webview.AwHttpAuthHandler.
82 bool OnReceivedHttpAuthRequest(const base::android::JavaRef<jobject>& handler,
83 const std::string& host,
84 const std::string& realm);
86 void SetOffscreenPreRaster(bool enabled);
88 // Methods called from Java.
89 void SetJavaPeers(JNIEnv* env,
90 jobject obj,
91 jobject aw_contents,
92 jobject web_contents_delegate,
93 jobject contents_client_bridge,
94 jobject io_thread_client,
95 jobject intercept_navigation_delegate);
96 base::android::ScopedJavaLocalRef<jobject> GetWebContents(JNIEnv* env,
97 jobject obj);
99 void Destroy(JNIEnv* env, jobject obj);
100 void DocumentHasImages(JNIEnv* env, jobject obj, jobject message);
101 void GenerateMHTML(JNIEnv* env, jobject obj, jstring jpath, jobject callback);
102 void CreatePdfExporter(JNIEnv* env, jobject obj, jobject pdfExporter);
103 void AddVisitedLinks(JNIEnv* env, jobject obj, jobjectArray jvisited_links);
104 base::android::ScopedJavaLocalRef<jbyteArray> GetCertificate(
105 JNIEnv* env, jobject obj);
106 void RequestNewHitTestDataAt(JNIEnv* env,
107 jobject obj,
108 jfloat x,
109 jfloat y,
110 jfloat touch_major);
111 void UpdateLastHitTestData(JNIEnv* env, jobject obj);
112 void OnSizeChanged(JNIEnv* env, jobject obj, int w, int h, int ow, int oh);
113 void SetViewVisibility(JNIEnv* env, jobject obj, bool visible);
114 void SetWindowVisibility(JNIEnv* env, jobject obj, bool visible);
115 void SetIsPaused(JNIEnv* env, jobject obj, bool paused);
116 void OnAttachedToWindow(JNIEnv* env, jobject obj, int w, int h);
117 void OnDetachedFromWindow(JNIEnv* env, jobject obj);
118 base::android::ScopedJavaLocalRef<jbyteArray> GetOpaqueState(
119 JNIEnv* env, jobject obj);
120 jboolean RestoreFromOpaqueState(JNIEnv* env, jobject obj, jbyteArray state);
121 void FocusFirstNode(JNIEnv* env, jobject obj);
122 void SetBackgroundColor(JNIEnv* env, jobject obj, jint color);
123 void OnComputeScroll(JNIEnv* env, jobject obj, jlong animation_time_millis);
124 bool OnDraw(JNIEnv* env,
125 jobject obj,
126 jobject canvas,
127 jboolean is_hardware_accelerated,
128 jint scroll_x,
129 jint scroll_y,
130 jint visible_left,
131 jint visible_top,
132 jint visible_right,
133 jint visible_bottom);
134 jlong GetAwDrawGLViewContext(JNIEnv* env, jobject obj);
135 jlong CapturePicture(JNIEnv* env, jobject obj, int width, int height);
136 void EnableOnNewPicture(JNIEnv* env, jobject obj, jboolean enabled);
137 void InsertVisualStateCallback(JNIEnv* env,
138 jobject obj,
139 long request_id,
140 jobject callback);
141 void ClearView(JNIEnv* env, jobject obj);
142 void SetExtraHeadersForUrl(JNIEnv* env, jobject obj,
143 jstring url, jstring extra_headers);
145 void InvokeGeolocationCallback(JNIEnv* env,
146 jobject obj,
147 jboolean value,
148 jstring origin);
150 // PermissionRequestHandlerClient implementation.
151 void OnPermissionRequest(base::android::ScopedJavaLocalRef<jobject> j_request,
152 AwPermissionRequest* request) override;
153 void OnPermissionRequestCanceled(AwPermissionRequest* request) override;
155 PermissionRequestHandler* GetPermissionRequestHandler() {
156 return permission_request_handler_.get();
159 void PreauthorizePermission(JNIEnv* env,
160 jobject obj,
161 jstring origin,
162 jlong resources);
164 // AwBrowserPermissionRequestDelegate implementation.
165 void RequestProtectedMediaIdentifierPermission(
166 const GURL& origin,
167 const base::Callback<void(bool)>& callback) override;
168 void CancelProtectedMediaIdentifierPermissionRequests(
169 const GURL& origin) override;
170 void RequestGeolocationPermission(
171 const GURL& origin,
172 const base::Callback<void(bool)>& callback) override;
173 void CancelGeolocationPermissionRequests(const GURL& origin) override;
174 void RequestMIDISysexPermission(
175 const GURL& origin,
176 const base::Callback<void(bool)>& callback) override;
177 void CancelMIDISysexPermissionRequests(const GURL& origin) override;
179 // Find-in-page API and related methods.
180 void FindAllAsync(JNIEnv* env, jobject obj, jstring search_string);
181 void FindNext(JNIEnv* env, jobject obj, jboolean forward);
182 void ClearMatches(JNIEnv* env, jobject obj);
183 FindHelper* GetFindHelper();
185 // Per WebView Cookie Policy
186 bool AllowThirdPartyCookies();
188 // FindHelper::Listener implementation.
189 void OnFindResultReceived(int active_ordinal,
190 int match_count,
191 bool finished) override;
192 // IconHelper::Listener implementation.
193 bool ShouldDownloadFavicon(const GURL& icon_url) override;
194 void OnReceivedIcon(const GURL& icon_url, const SkBitmap& bitmap) override;
195 void OnReceivedTouchIconUrl(const std::string& url,
196 const bool precomposed) override;
198 // AwRenderViewHostExtClient implementation.
199 void OnWebLayoutPageScaleFactorChanged(float page_scale_factor) override;
200 void OnWebLayoutContentsSizeChanged(const gfx::Size& contents_size) override;
202 // BrowserViewRendererClient implementation.
203 bool RequestDrawGL(bool wait_for_completion) override;
204 void PostInvalidate() override;
205 void DetachFunctorFromView() override;
206 void OnNewPicture() override;
207 gfx::Point GetLocationOnScreen() override;
208 void ScrollContainerViewTo(gfx::Vector2d new_value) override;
209 void UpdateScrollState(gfx::Vector2d max_scroll_offset,
210 gfx::SizeF contents_size_dip,
211 float page_scale_factor,
212 float min_page_scale_factor,
213 float max_page_scale_factor) override;
214 void DidOverscroll(gfx::Vector2d overscroll_delta,
215 gfx::Vector2dF overscroll_velocity) override;
217 void ParentDrawConstraintsUpdated(
218 const ParentCompositorDrawConstraints& draw_constraints) override {}
220 void ClearCache(JNIEnv* env, jobject obj, jboolean include_disk_files);
221 void SetPendingWebContentsForPopup(scoped_ptr<content::WebContents> pending);
222 jlong ReleasePopupAwContents(JNIEnv* env, jobject obj);
224 void ScrollTo(JNIEnv* env, jobject obj, jint x, jint y);
225 void SmoothScroll(JNIEnv* env,
226 jobject obj,
227 jint target_x,
228 jint target_y,
229 jlong duration_ms);
230 void SetDipScale(JNIEnv* env, jobject obj, jfloat dip_scale);
231 void SetSaveFormData(bool enabled);
233 // Sets the java client
234 void SetAwAutofillClient(jobject client);
236 void SetJsOnlineProperty(JNIEnv* env, jobject obj, jboolean network_up);
237 void TrimMemory(JNIEnv* env, jobject obj, jint level, jboolean visible);
239 scoped_refptr<AwMessagePortMessageFilter> GetMessagePortMessageFilter();
240 void PostMessageToFrame(JNIEnv* env, jobject obj, jstring frame_id,
241 jstring message, jstring target_origin, jintArray sent_ports);
242 void CreateMessageChannel(JNIEnv* env, jobject obj, jobjectArray ports);
244 void GrantFileSchemeAccesstoChildProcess(JNIEnv* env, jobject obj);
246 private:
247 void InitAutofillIfNecessary(bool enabled);
249 // Geolocation API support
250 void ShowGeolocationPrompt(const GURL& origin, base::Callback<void(bool)>);
251 void HideGeolocationPrompt(const GURL& origin);
253 void SetDipScaleInternal(float dip_scale);
255 JavaObjectWeakGlobalRef java_ref_;
256 scoped_ptr<AwWebContentsDelegate> web_contents_delegate_;
257 scoped_ptr<AwContentsClientBridge> contents_client_bridge_;
258 scoped_ptr<content::WebContents> web_contents_;
259 scoped_ptr<AwRenderViewHostExt> render_view_host_ext_;
260 scoped_ptr<FindHelper> find_helper_;
261 scoped_ptr<IconHelper> icon_helper_;
262 scoped_ptr<AwContents> pending_contents_;
263 BrowserViewRenderer browser_view_renderer_;
264 scoped_ptr<AwPdfExporter> pdf_exporter_;
265 scoped_ptr<PermissionRequestHandler> permission_request_handler_;
266 scoped_refptr<AwMessagePortMessageFilter> message_port_message_filter_;
268 // GURL is supplied by the content layer as requesting frame.
269 // Callback is supplied by the content layer, and is invoked with the result
270 // from the permission prompt.
271 typedef std::pair<const GURL, base::Callback<void(bool)> > OriginCallback;
272 // The first element in the list is always the currently pending request.
273 std::list<OriginCallback> pending_geolocation_prompts_;
275 GLViewRendererManager::Key renderer_manager_key_;
277 DISALLOW_COPY_AND_ASSIGN(AwContents);
280 bool RegisterAwContents(JNIEnv* env);
282 } // namespace android_webview
284 #endif // ANDROID_WEBVIEW_NATIVE_AW_CONTENTS_H_