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