[Android WebView] Disable fallback ticks when paused or window invisible
[chromium-blink-merge.git] / android_webview / native / aw_contents.h
blob24dff4f6175323aedadaecffda8b7f17d65807c1
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 SetViewVisibility(JNIEnv* env, jobject obj, bool visible);
96 void SetWindowVisibility(JNIEnv* env, jobject obj, bool visible);
97 void SetIsPaused(JNIEnv* env, jobject obj, bool paused);
98 void OnAttachedToWindow(JNIEnv* env, jobject obj, int w, int h);
99 void OnDetachedFromWindow(JNIEnv* env, jobject obj);
100 base::android::ScopedJavaLocalRef<jbyteArray> GetOpaqueState(
101 JNIEnv* env, jobject obj);
102 jboolean RestoreFromOpaqueState(JNIEnv* env, jobject obj, jbyteArray state);
103 void FocusFirstNode(JNIEnv* env, jobject obj);
104 void SetBackgroundColor(JNIEnv* env, jobject obj, jint color);
105 bool OnDraw(JNIEnv* env,
106 jobject obj,
107 jobject canvas,
108 jboolean is_hardware_accelerated,
109 jint scroll_x,
110 jint scroll_y,
111 jint clip_left,
112 jint clip_top,
113 jint clip_right,
114 jint clip_bottom);
115 void SetGlobalVisibleRect(JNIEnv* env,
116 jobject obj,
117 jint visible_left,
118 jint visible_top,
119 jint visible_right,
120 jint visible_bottom);
121 jint GetAwDrawGLViewContext(JNIEnv* env, jobject obj);
122 jint CapturePicture(JNIEnv* env, jobject obj, int width, int height);
123 void EnableOnNewPicture(JNIEnv* env, jobject obj, jboolean enabled);
125 // Geolocation API support
126 void ShowGeolocationPrompt(const GURL& origin, base::Callback<void(bool)>);
127 void HideGeolocationPrompt(const GURL& origin);
128 void InvokeGeolocationCallback(JNIEnv* env,
129 jobject obj,
130 jboolean value,
131 jstring origin);
133 // Find-in-page API and related methods.
134 void FindAllAsync(JNIEnv* env, jobject obj, jstring search_string);
135 void FindNext(JNIEnv* env, jobject obj, jboolean forward);
136 void ClearMatches(JNIEnv* env, jobject obj);
137 FindHelper* GetFindHelper();
139 // FindHelper::Listener implementation.
140 virtual void OnFindResultReceived(int active_ordinal,
141 int match_count,
142 bool finished) OVERRIDE;
143 // IconHelper::Listener implementation.
144 virtual void OnReceivedIcon(const GURL& icon_url,
145 const SkBitmap& bitmap) OVERRIDE;
146 virtual void OnReceivedTouchIconUrl(const std::string& url,
147 const bool precomposed) OVERRIDE;
149 // AwRenderViewHostExtClient implementation.
150 virtual void OnWebLayoutPageScaleFactorChanged(
151 float page_scale_factor) OVERRIDE;
153 // BrowserViewRenderer::Client implementation.
154 virtual bool RequestDrawGL(jobject canvas) OVERRIDE;
155 virtual void PostInvalidate() OVERRIDE;
156 virtual void UpdateGlobalVisibleRect() OVERRIDE;
157 virtual void OnNewPicture() OVERRIDE;
158 virtual gfx::Point GetLocationOnScreen() OVERRIDE;
159 virtual void ScrollContainerViewTo(gfx::Vector2d new_value) OVERRIDE;
160 virtual void DidOverscroll(gfx::Vector2d overscroll_delta) OVERRIDE;
162 void ClearCache(JNIEnv* env, jobject obj, jboolean include_disk_files);
163 void SetPendingWebContentsForPopup(scoped_ptr<content::WebContents> pending);
164 jint ReleasePopupAwContents(JNIEnv* env, jobject obj);
166 void ScrollTo(JNIEnv* env, jobject obj, jint xPix, jint yPix);
167 void SetDipScale(JNIEnv* env, jobject obj, jfloat dipScale);
168 void SetDisplayedPageScaleFactor(JNIEnv* env,
169 jobject obj,
170 jfloat pageScaleFactor);
172 void SetSaveFormData(bool enabled);
174 // Sets the java delegate
175 void SetAwAutofillManagerDelegate(jobject delegate);
176 private:
177 void InitAutofillIfNecessary(bool enabled);
179 JavaObjectWeakGlobalRef java_ref_;
180 scoped_ptr<content::WebContents> web_contents_;
181 scoped_ptr<AwWebContentsDelegate> web_contents_delegate_;
182 scoped_ptr<AwContentsClientBridge> contents_client_bridge_;
183 scoped_ptr<AwRenderViewHostExt> render_view_host_ext_;
184 scoped_ptr<FindHelper> find_helper_;
185 scoped_ptr<IconHelper> icon_helper_;
186 scoped_ptr<AwContents> pending_contents_;
187 scoped_ptr<BrowserViewRenderer> browser_view_renderer_;
189 // GURL is supplied by the content layer as requesting frame.
190 // Callback is supplied by the content layer, and is invoked with the result
191 // from the permission prompt.
192 typedef std::pair<const GURL, base::Callback<void(bool)> > OriginCallback;
193 // The first element in the list is always the currently pending request.
194 std::list<OriginCallback> pending_geolocation_prompts_;
196 DISALLOW_COPY_AND_ASSIGN(AwContents);
199 bool RegisterAwContents(JNIEnv* env);
201 } // namespace android_webview
203 #endif // ANDROID_WEBVIEW_NATIVE_AW_CONTENTS_H_