Make launcherSearchProvider API white-listed on stable and public on dev.
[chromium-blink-merge.git] / android_webview / native / aw_contents.h
blob30d252a866e8f7d9f66fdafc643d9567a6cf044a
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(base::android::ScopedJavaLocalRef<jobject> j_request,
149 AwPermissionRequest* request) override;
150 void OnPermissionRequestCanceled(AwPermissionRequest* request) override;
152 PermissionRequestHandler* GetPermissionRequestHandler() {
153 return permission_request_handler_.get();
156 void PreauthorizePermission(JNIEnv* env,
157 jobject obj,
158 jstring origin,
159 jlong resources);
161 // AwBrowserPermissionRequestDelegate implementation.
162 void RequestProtectedMediaIdentifierPermission(
163 const GURL& origin,
164 const base::Callback<void(bool)>& callback) override;
165 void CancelProtectedMediaIdentifierPermissionRequests(
166 const GURL& origin) override;
167 void RequestGeolocationPermission(
168 const GURL& origin,
169 const base::Callback<void(bool)>& callback) override;
170 void CancelGeolocationPermissionRequests(const GURL& origin) override;
172 // Find-in-page API and related methods.
173 void FindAllAsync(JNIEnv* env, jobject obj, jstring search_string);
174 void FindNext(JNIEnv* env, jobject obj, jboolean forward);
175 void ClearMatches(JNIEnv* env, jobject obj);
176 FindHelper* GetFindHelper();
178 // Per WebView Cookie Policy
179 bool AllowThirdPartyCookies();
181 // FindHelper::Listener implementation.
182 void OnFindResultReceived(int active_ordinal,
183 int match_count,
184 bool finished) override;
185 // IconHelper::Listener implementation.
186 bool ShouldDownloadFavicon(const GURL& icon_url) override;
187 void OnReceivedIcon(const GURL& icon_url, const SkBitmap& bitmap) override;
188 void OnReceivedTouchIconUrl(const std::string& url,
189 const bool precomposed) override;
191 // AwRenderViewHostExtClient implementation.
192 void OnWebLayoutPageScaleFactorChanged(float page_scale_factor) override;
193 void OnWebLayoutContentsSizeChanged(const gfx::Size& contents_size) override;
195 // BrowserViewRendererClient implementation.
196 bool RequestDrawGL(bool wait_for_completion) override;
197 void PostInvalidate() override;
198 void DetachFunctorFromView() override;
199 void OnNewPicture() override;
200 gfx::Point GetLocationOnScreen() override;
201 void ScrollContainerViewTo(gfx::Vector2d new_value) override;
202 bool IsFlingActive() const override;
203 void UpdateScrollState(gfx::Vector2d max_scroll_offset,
204 gfx::SizeF contents_size_dip,
205 float page_scale_factor,
206 float min_page_scale_factor,
207 float max_page_scale_factor) override;
208 void DidOverscroll(gfx::Vector2d overscroll_delta) override;
209 void ParentDrawConstraintsUpdated(
210 const ParentCompositorDrawConstraints& draw_constraints) override {}
212 void ClearCache(JNIEnv* env, jobject obj, jboolean include_disk_files);
213 void SetPendingWebContentsForPopup(scoped_ptr<content::WebContents> pending);
214 jlong ReleasePopupAwContents(JNIEnv* env, jobject obj);
216 void ScrollTo(JNIEnv* env, jobject obj, jint x, jint y);
217 void SetDipScale(JNIEnv* env, jobject obj, jfloat dip_scale);
218 void SetSaveFormData(bool enabled);
220 // Sets the java client
221 void SetAwAutofillClient(jobject client);
223 void SetJsOnlineProperty(JNIEnv* env, jobject obj, jboolean network_up);
224 void TrimMemory(JNIEnv* env, jobject obj, jint level, jboolean visible);
226 scoped_refptr<AwMessagePortMessageFilter> GetMessagePortMessageFilter();
227 void PostMessageToFrame(JNIEnv* env, jobject obj, jstring frame_id,
228 jstring message, jstring target_origin, jintArray sent_ports);
229 void CreateMessageChannel(JNIEnv* env, jobject obj, jobjectArray ports);
231 private:
232 void InitDataReductionProxyIfNecessary();
233 void InitAutofillIfNecessary(bool enabled);
235 // Geolocation API support
236 void ShowGeolocationPrompt(const GURL& origin, base::Callback<void(bool)>);
237 void HideGeolocationPrompt(const GURL& origin);
239 void SetDipScaleInternal(float dip_scale);
241 JavaObjectWeakGlobalRef java_ref_;
242 scoped_ptr<AwWebContentsDelegate> web_contents_delegate_;
243 scoped_ptr<AwContentsClientBridge> contents_client_bridge_;
244 scoped_ptr<content::WebContents> web_contents_;
245 scoped_ptr<AwRenderViewHostExt> render_view_host_ext_;
246 scoped_ptr<FindHelper> find_helper_;
247 scoped_ptr<IconHelper> icon_helper_;
248 scoped_ptr<AwContents> pending_contents_;
249 BrowserViewRenderer browser_view_renderer_;
250 scoped_ptr<AwPdfExporter> pdf_exporter_;
251 scoped_ptr<PermissionRequestHandler> permission_request_handler_;
252 scoped_refptr<AwMessagePortMessageFilter> message_port_message_filter_;
254 // GURL is supplied by the content layer as requesting frame.
255 // Callback is supplied by the content layer, and is invoked with the result
256 // from the permission prompt.
257 typedef std::pair<const GURL, base::Callback<void(bool)> > OriginCallback;
258 // The first element in the list is always the currently pending request.
259 std::list<OriginCallback> pending_geolocation_prompts_;
261 GLViewRendererManager::Key renderer_manager_key_;
263 DISALLOW_COPY_AND_ASSIGN(AwContents);
266 bool RegisterAwContents(JNIEnv* env);
268 } // namespace android_webview
270 #endif // ANDROID_WEBVIEW_NATIVE_AW_CONTENTS_H_