GPU workaround to simulate Out of Memory errors with large textures
[chromium-blink-merge.git] / android_webview / native / aw_contents.h
blob7e769804923d4a7229b2435f6e2be982a38d757b
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 AwContents(scoped_ptr<content::WebContents> web_contents);
72 ~AwContents() override;
74 AwRenderViewHostExt* render_view_host_ext() {
75 return render_view_host_ext_.get();
78 // |handler| is an instance of
79 // org.chromium.android_webview.AwHttpAuthHandler.
80 bool OnReceivedHttpAuthRequest(const base::android::JavaRef<jobject>& handler,
81 const std::string& host,
82 const std::string& realm);
84 void SetOffscreenPreRaster(bool enabled);
86 // Methods called from Java.
87 void SetJavaPeers(JNIEnv* env,
88 jobject obj,
89 jobject aw_contents,
90 jobject web_contents_delegate,
91 jobject contents_client_bridge,
92 jobject io_thread_client,
93 jobject intercept_navigation_delegate);
94 base::android::ScopedJavaLocalRef<jobject> GetWebContents(JNIEnv* env,
95 jobject obj);
97 void Destroy(JNIEnv* env, jobject obj);
98 void DocumentHasImages(JNIEnv* env, jobject obj, jobject message);
99 void GenerateMHTML(JNIEnv* env, jobject obj, jstring jpath, jobject callback);
100 void CreatePdfExporter(JNIEnv* env, jobject obj, jobject pdfExporter);
101 void AddVisitedLinks(JNIEnv* env, jobject obj, jobjectArray jvisited_links);
102 base::android::ScopedJavaLocalRef<jbyteArray> GetCertificate(
103 JNIEnv* env, jobject obj);
104 void RequestNewHitTestDataAt(JNIEnv* env,
105 jobject obj,
106 jfloat x,
107 jfloat y,
108 jfloat touch_major);
109 void UpdateLastHitTestData(JNIEnv* env, jobject obj);
110 void OnSizeChanged(JNIEnv* env, jobject obj, int w, int h, int ow, int oh);
111 void SetViewVisibility(JNIEnv* env, jobject obj, bool visible);
112 void SetWindowVisibility(JNIEnv* env, jobject obj, bool visible);
113 void SetIsPaused(JNIEnv* env, jobject obj, bool paused);
114 void OnAttachedToWindow(JNIEnv* env, jobject obj, int w, int h);
115 void OnDetachedFromWindow(JNIEnv* env, jobject obj);
116 base::android::ScopedJavaLocalRef<jbyteArray> GetOpaqueState(
117 JNIEnv* env, jobject obj);
118 jboolean RestoreFromOpaqueState(JNIEnv* env, jobject obj, jbyteArray state);
119 void FocusFirstNode(JNIEnv* env, jobject obj);
120 void SetBackgroundColor(JNIEnv* env, jobject obj, jint color);
121 bool OnDraw(JNIEnv* env,
122 jobject obj,
123 jobject canvas,
124 jboolean is_hardware_accelerated,
125 jint scroll_x,
126 jint scroll_y,
127 jint visible_left,
128 jint visible_top,
129 jint visible_right,
130 jint visible_bottom);
131 jlong GetAwDrawGLViewContext(JNIEnv* env, jobject obj);
132 jlong CapturePicture(JNIEnv* env, jobject obj, int width, int height);
133 void EnableOnNewPicture(JNIEnv* env, jobject obj, jboolean enabled);
134 void InsertVisualStateCallback(JNIEnv* env,
135 jobject obj,
136 long request_id,
137 jobject callback);
138 void ClearView(JNIEnv* env, jobject obj);
139 void SetExtraHeadersForUrl(JNIEnv* env, jobject obj,
140 jstring url, jstring extra_headers);
142 void InvokeGeolocationCallback(JNIEnv* env,
143 jobject obj,
144 jboolean value,
145 jstring origin);
147 // PermissionRequestHandlerClient implementation.
148 void OnPermissionRequest(AwPermissionRequest* request) override;
149 void OnPermissionRequestCanceled(AwPermissionRequest* request) override;
151 PermissionRequestHandler* GetPermissionRequestHandler() {
152 return permission_request_handler_.get();
155 void PreauthorizePermission(JNIEnv* env,
156 jobject obj,
157 jstring origin,
158 jlong resources);
160 // AwBrowserPermissionRequestDelegate implementation.
161 void RequestProtectedMediaIdentifierPermission(
162 const GURL& origin,
163 const base::Callback<void(bool)>& callback) override;
164 void CancelProtectedMediaIdentifierPermissionRequests(
165 const GURL& origin) override;
166 void RequestGeolocationPermission(
167 const GURL& origin,
168 const base::Callback<void(bool)>& callback) override;
169 void CancelGeolocationPermissionRequests(const GURL& origin) override;
171 // Find-in-page API and related methods.
172 void FindAllAsync(JNIEnv* env, jobject obj, jstring search_string);
173 void FindNext(JNIEnv* env, jobject obj, jboolean forward);
174 void ClearMatches(JNIEnv* env, jobject obj);
175 FindHelper* GetFindHelper();
177 // Per WebView Cookie Policy
178 bool AllowThirdPartyCookies();
180 // FindHelper::Listener implementation.
181 void OnFindResultReceived(int active_ordinal,
182 int match_count,
183 bool finished) override;
184 // IconHelper::Listener implementation.
185 bool ShouldDownloadFavicon(const GURL& icon_url) override;
186 void OnReceivedIcon(const GURL& icon_url, const SkBitmap& bitmap) override;
187 void OnReceivedTouchIconUrl(const std::string& url,
188 const bool precomposed) override;
190 // AwRenderViewHostExtClient implementation.
191 void OnWebLayoutPageScaleFactorChanged(float page_scale_factor) override;
192 void OnWebLayoutContentsSizeChanged(const gfx::Size& contents_size) override;
194 // BrowserViewRendererClient implementation.
195 bool RequestDrawGL(bool wait_for_completion) override;
196 void PostInvalidate() override;
197 void DetachFunctorFromView() override;
198 void OnNewPicture() override;
199 gfx::Point GetLocationOnScreen() override;
200 void ScrollContainerViewTo(gfx::Vector2d new_value) override;
201 bool IsFlingActive() const override;
202 void UpdateScrollState(gfx::Vector2d max_scroll_offset,
203 gfx::SizeF contents_size_dip,
204 float page_scale_factor,
205 float min_page_scale_factor,
206 float max_page_scale_factor) override;
207 void DidOverscroll(gfx::Vector2d overscroll_delta) override;
208 void ParentDrawConstraintsUpdated(
209 const ParentCompositorDrawConstraints& draw_constraints) override {}
211 void ClearCache(JNIEnv* env, jobject obj, jboolean include_disk_files);
212 void SetPendingWebContentsForPopup(scoped_ptr<content::WebContents> pending);
213 jlong ReleasePopupAwContents(JNIEnv* env, jobject obj);
215 void ScrollTo(JNIEnv* env, jobject obj, jint x, jint y);
216 void SetDipScale(JNIEnv* env, jobject obj, jfloat dip_scale);
217 void SetSaveFormData(bool enabled);
219 // Sets the java client
220 void SetAwAutofillClient(jobject client);
222 void SetJsOnlineProperty(JNIEnv* env, jobject obj, jboolean network_up);
223 void TrimMemory(JNIEnv* env, jobject obj, jint level, jboolean visible);
225 scoped_refptr<AwMessagePortMessageFilter> GetMessagePortMessageFilter();
226 void PostMessageToFrame(JNIEnv* env, jobject obj, jstring frame_id,
227 jstring message, jstring target_origin, jintArray sent_ports);
228 void CreateMessageChannel(JNIEnv* env, jobject obj, jobjectArray ports);
230 private:
231 void InitDataReductionProxyIfNecessary();
232 void InitAutofillIfNecessary(bool enabled);
234 // Geolocation API support
235 void ShowGeolocationPrompt(const GURL& origin, base::Callback<void(bool)>);
236 void HideGeolocationPrompt(const GURL& origin);
238 JavaObjectWeakGlobalRef java_ref_;
239 scoped_ptr<AwWebContentsDelegate> web_contents_delegate_;
240 scoped_ptr<AwContentsClientBridge> contents_client_bridge_;
241 scoped_ptr<content::WebContents> web_contents_;
242 scoped_ptr<AwRenderViewHostExt> render_view_host_ext_;
243 scoped_ptr<FindHelper> find_helper_;
244 scoped_ptr<IconHelper> icon_helper_;
245 scoped_ptr<AwContents> pending_contents_;
246 BrowserViewRenderer browser_view_renderer_;
247 scoped_ptr<AwPdfExporter> pdf_exporter_;
248 scoped_ptr<PermissionRequestHandler> permission_request_handler_;
249 scoped_refptr<AwMessagePortMessageFilter> message_port_message_filter_;
251 // GURL is supplied by the content layer as requesting frame.
252 // Callback is supplied by the content layer, and is invoked with the result
253 // from the permission prompt.
254 typedef std::pair<const GURL, base::Callback<void(bool)> > OriginCallback;
255 // The first element in the list is always the currently pending request.
256 std::list<OriginCallback> pending_geolocation_prompts_;
258 GLViewRendererManager::Key renderer_manager_key_;
260 DISALLOW_COPY_AND_ASSIGN(AwContents);
263 bool RegisterAwContents(JNIEnv* env);
265 } // namespace android_webview
267 #endif // ANDROID_WEBVIEW_NATIVE_AW_CONTENTS_H_