OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef ANDROID_WEBVIEW_NATIVE_AW_CONTENTS_H_ | 5 #ifndef ANDROID_WEBVIEW_NATIVE_AW_CONTENTS_H_ |
6 #define ANDROID_WEBVIEW_NATIVE_AW_CONTENTS_H_ | 6 #define ANDROID_WEBVIEW_NATIVE_AW_CONTENTS_H_ |
7 | 7 |
8 #include <jni.h> | 8 #include <jni.h> |
9 #include <list> | 9 #include <list> |
10 #include <string> | 10 #include <string> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
| 13 #include "android_webview/browser/browser_view_renderer.h" |
13 #include "android_webview/browser/find_helper.h" | 14 #include "android_webview/browser/find_helper.h" |
14 #include "android_webview/browser/icon_helper.h" | 15 #include "android_webview/browser/icon_helper.h" |
15 #include "android_webview/browser/renderer_host/aw_render_view_host_ext.h" | 16 #include "android_webview/browser/renderer_host/aw_render_view_host_ext.h" |
16 #include "android_webview/public/browser/draw_gl.h" | |
17 #include "base/android/scoped_java_ref.h" | 17 #include "base/android/scoped_java_ref.h" |
18 #include "base/android/jni_helper.h" | 18 #include "base/android/jni_helper.h" |
19 #include "base/callback_forward.h" | 19 #include "base/callback_forward.h" |
20 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
21 #include "content/public/browser/android/compositor.h" | |
22 #include "content/public/browser/javascript_dialog_manager.h" | 21 #include "content/public/browser/javascript_dialog_manager.h" |
23 #include "skia/ext/refptr.h" | |
24 #include "third_party/skia/include/core/SkPicture.h" | |
25 | 22 |
26 typedef void* EGLContext; | |
27 class SkBitmap; | 23 class SkBitmap; |
28 class TabContents; | 24 class TabContents; |
29 | 25 |
30 namespace cc { | |
31 class Layer; | |
32 } | |
33 | |
34 namespace content { | 26 namespace content { |
35 class Compositor; | |
36 class WebContents; | 27 class WebContents; |
37 } | 28 } |
38 | 29 |
39 namespace android_webview { | 30 namespace android_webview { |
40 | 31 |
41 class AwContentsContainer; | 32 class AwContentsContainer; |
42 class AwWebContentsDelegate; | 33 class AwWebContentsDelegate; |
43 | 34 |
44 // Native side of java-class of same name. | 35 // Native side of java-class of same name. |
45 // Provides the ownership of and access to browser components required for | 36 // Provides the ownership of and access to browser components required for |
46 // WebView functionality; analogous to chrome's TabContents, but with a | 37 // WebView functionality; analogous to chrome's TabContents, but with a |
47 // level of indirection provided by the AwContentsContainer abstraction. | 38 // level of indirection provided by the AwContentsContainer abstraction. |
48 class AwContents : public FindHelper::Listener, | 39 class AwContents : public FindHelper::Listener, |
49 public IconHelper::Listener, | 40 public IconHelper::Listener, |
50 public content::Compositor::Client, | 41 public BrowserViewRenderer::Client { |
51 public AwRenderViewHostExt::Client { | |
52 public: | 42 public: |
53 enum OnNewPictureMode { | 43 enum OnNewPictureMode { |
54 kOnNewPictureDisabled = 0, | 44 kOnNewPictureDisabled = 0, |
55 kOnNewPictureEnabled, | 45 kOnNewPictureEnabled, |
56 kOnNewPictureInvalidationOnly, | 46 kOnNewPictureInvalidationOnly, |
57 }; | 47 }; |
58 | 48 |
59 // Returns the AwContents instance associated with |web_contents|, or NULL. | 49 // Returns the AwContents instance associated with |web_contents|, or NULL. |
60 static AwContents* FromWebContents(content::WebContents* web_contents); | 50 static AwContents* FromWebContents(content::WebContents* web_contents); |
61 | 51 |
62 // Returns the AwContents instance associated with with the given | 52 // Returns the AwContents instance associated with with the given |
63 // render_process_id and render_view_id, or NULL. | 53 // render_process_id and render_view_id, or NULL. |
64 static AwContents* FromID(int render_process_id, int render_view_id); | 54 static AwContents* FromID(int render_process_id, int render_view_id); |
65 | 55 |
66 AwContents(JNIEnv* env, | 56 AwContents(JNIEnv* env, |
67 jobject obj, | 57 jobject obj, |
68 jobject web_contents_delegate); | 58 jobject web_contents_delegate); |
69 virtual ~AwContents(); | 59 virtual ~AwContents(); |
70 | 60 |
71 AwRenderViewHostExt* render_view_host_ext() { | 61 AwRenderViewHostExt* render_view_host_ext() { |
72 return render_view_host_ext_.get(); | 62 return render_view_host_ext_.get(); |
73 } | 63 } |
74 | 64 |
75 void DrawGL(AwDrawGLInfo* draw_info); | |
76 bool DrawSW(JNIEnv* env, | |
77 jobject obj, | |
78 jobject canvas, | |
79 jint clip_x, | |
80 jint clip_y, | |
81 jint clip_w, | |
82 jint clip_h); | |
83 | |
84 void RunJavaScriptDialog( | 65 void RunJavaScriptDialog( |
85 content::JavaScriptMessageType message_type, | 66 content::JavaScriptMessageType message_type, |
86 const GURL& origin_url, | 67 const GURL& origin_url, |
87 const string16& message_text, | 68 const string16& message_text, |
88 const string16& default_prompt_text, | 69 const string16& default_prompt_text, |
89 const base::android::ScopedJavaLocalRef<jobject>& js_result); | 70 const base::android::ScopedJavaLocalRef<jobject>& js_result); |
90 | 71 |
91 void RunBeforeUnloadDialog( | 72 void RunBeforeUnloadDialog( |
92 const GURL& origin_url, | 73 const GURL& origin_url, |
93 const string16& message_text, | 74 const string16& message_text, |
(...skipping 26 matching lines...) Expand all Loading... |
120 void UpdateLastHitTestData(JNIEnv* env, jobject obj); | 101 void UpdateLastHitTestData(JNIEnv* env, jobject obj); |
121 void OnSizeChanged(JNIEnv* env, jobject obj, int w, int h, int ow, int oh); | 102 void OnSizeChanged(JNIEnv* env, jobject obj, int w, int h, int ow, int oh); |
122 void SetWindowViewVisibility(JNIEnv* env, jobject obj, | 103 void SetWindowViewVisibility(JNIEnv* env, jobject obj, |
123 bool window_visible, | 104 bool window_visible, |
124 bool view_visible); | 105 bool view_visible); |
125 void OnAttachedToWindow(JNIEnv* env, jobject obj, int w, int h); | 106 void OnAttachedToWindow(JNIEnv* env, jobject obj, int w, int h); |
126 void OnDetachedFromWindow(JNIEnv* env, jobject obj); | 107 void OnDetachedFromWindow(JNIEnv* env, jobject obj); |
127 base::android::ScopedJavaLocalRef<jbyteArray> GetOpaqueState( | 108 base::android::ScopedJavaLocalRef<jbyteArray> GetOpaqueState( |
128 JNIEnv* env, jobject obj); | 109 JNIEnv* env, jobject obj); |
129 jboolean RestoreFromOpaqueState(JNIEnv* env, jobject obj, jbyteArray state); | 110 jboolean RestoreFromOpaqueState(JNIEnv* env, jobject obj, jbyteArray state); |
| 111 void FocusFirstNode(JNIEnv* env, jobject obj); |
| 112 bool DrawSW(JNIEnv* env, |
| 113 jobject obj, |
| 114 jobject canvas, |
| 115 jint clip_x, |
| 116 jint clip_y, |
| 117 jint clip_w, |
| 118 jint clip_h); |
130 void SetScrollForHWFrame(JNIEnv* env, jobject obj, | 119 void SetScrollForHWFrame(JNIEnv* env, jobject obj, |
131 int scroll_x, int scroll_y); | 120 int scroll_x, int scroll_y); |
132 void FocusFirstNode(JNIEnv* env, jobject obj); | 121 jint GetAwDrawGLViewContext(JNIEnv* env, jobject obj); |
133 base::android::ScopedJavaLocalRef<jobject> CapturePicture(JNIEnv* env, | 122 base::android::ScopedJavaLocalRef<jobject> CapturePicture(JNIEnv* env, |
134 jobject obj); | 123 jobject obj); |
135 void EnableOnNewPicture(JNIEnv* env, | 124 void EnableOnNewPicture(JNIEnv* env, |
136 jobject obj, | 125 jobject obj, |
137 jboolean enabled, | 126 jboolean enabled, |
138 jboolean invalidation_only); | 127 jboolean invalidation_only); |
139 | 128 |
140 // Geolocation API support | 129 // Geolocation API support |
141 void ShowGeolocationPrompt(const GURL& origin, base::Callback<void(bool)>); | 130 void ShowGeolocationPrompt(const GURL& origin, base::Callback<void(bool)>); |
142 void HideGeolocationPrompt(const GURL& origin); | 131 void HideGeolocationPrompt(const GURL& origin); |
143 void InvokeGeolocationCallback(JNIEnv* env, | 132 void InvokeGeolocationCallback(JNIEnv* env, |
144 jobject obj, | 133 jobject obj, |
145 jboolean value, | 134 jboolean value, |
146 jstring origin); | 135 jstring origin); |
147 | 136 |
148 // Find-in-page API and related methods. | 137 // Find-in-page API and related methods. |
149 jint FindAllSync(JNIEnv* env, jobject obj, jstring search_string); | 138 jint FindAllSync(JNIEnv* env, jobject obj, jstring search_string); |
150 void FindAllAsync(JNIEnv* env, jobject obj, jstring search_string); | 139 void FindAllAsync(JNIEnv* env, jobject obj, jstring search_string); |
151 void FindNext(JNIEnv* env, jobject obj, jboolean forward); | 140 void FindNext(JNIEnv* env, jobject obj, jboolean forward); |
152 void ClearMatches(JNIEnv* env, jobject obj); | 141 void ClearMatches(JNIEnv* env, jobject obj); |
153 void ClearCache(JNIEnv* env, jobject obj, jboolean include_disk_files); | |
154 | |
155 FindHelper* GetFindHelper(); | 142 FindHelper* GetFindHelper(); |
156 | 143 |
157 // FindHelper::Listener implementation. | 144 // FindHelper::Listener implementation. |
158 virtual void OnFindResultReceived(int active_ordinal, | 145 virtual void OnFindResultReceived(int active_ordinal, |
159 int match_count, | 146 int match_count, |
160 bool finished) OVERRIDE; | 147 bool finished) OVERRIDE; |
161 // IconHelper::Listener implementation. | 148 // IconHelper::Listener implementation. |
162 virtual void OnReceivedIcon(const SkBitmap& bitmap) OVERRIDE; | 149 virtual void OnReceivedIcon(const SkBitmap& bitmap) OVERRIDE; |
163 virtual void OnReceivedTouchIconUrl(const std::string& url, | 150 virtual void OnReceivedTouchIconUrl(const std::string& url, |
164 const bool precomposed) OVERRIDE; | 151 const bool precomposed) OVERRIDE; |
165 | 152 |
166 // content::Compositor::Client implementation. | 153 // BrowserViewRenderer::Client implementation. |
167 virtual void ScheduleComposite() OVERRIDE; | 154 virtual void Invalidate() OVERRIDE; |
168 virtual void OnSwapBuffersCompleted() OVERRIDE; | 155 virtual void OnNewPicture( |
| 156 const base::android::JavaRef<jobject>& picture) OVERRIDE; |
169 | 157 |
| 158 void ClearCache(JNIEnv* env, jobject obj, jboolean include_disk_files); |
170 void SetPendingWebContentsForPopup(scoped_ptr<content::WebContents> pending); | 159 void SetPendingWebContentsForPopup(scoped_ptr<content::WebContents> pending); |
171 jint ReleasePopupWebContents(JNIEnv* env, jobject obj); | 160 jint ReleasePopupWebContents(JNIEnv* env, jobject obj); |
172 | 161 |
173 // AwRenderViewHostExt::Client implementation. | |
174 virtual void OnPictureUpdated(int process_id, int render_view_id) OVERRIDE; | |
175 | |
176 // Returns the latest locally available picture if any. | |
177 // If none is available will synchronously request the latest one | |
178 // and block until the result is received. | |
179 skia::RefPtr<SkPicture> GetLastCapturedPicture(); | |
180 | |
181 private: | 162 private: |
182 void Invalidate(); | |
183 void SetWebContents(content::WebContents* web_contents); | 163 void SetWebContents(content::WebContents* web_contents); |
184 void SetCompositorVisibility(bool visible); | |
185 void ResetCompositor(); | |
186 void AttachLayerTree(); | |
187 bool RenderSW(SkCanvas* canvas); | |
188 bool RenderPicture(SkCanvas* canvas); | |
189 | 164 |
190 JavaObjectWeakGlobalRef java_ref_; | 165 JavaObjectWeakGlobalRef java_ref_; |
191 scoped_ptr<content::WebContents> web_contents_; | 166 scoped_ptr<content::WebContents> web_contents_; |
192 scoped_ptr<AwWebContentsDelegate> web_contents_delegate_; | 167 scoped_ptr<AwWebContentsDelegate> web_contents_delegate_; |
193 scoped_ptr<AwRenderViewHostExt> render_view_host_ext_; | 168 scoped_ptr<AwRenderViewHostExt> render_view_host_ext_; |
194 scoped_ptr<FindHelper> find_helper_; | 169 scoped_ptr<FindHelper> find_helper_; |
195 scoped_ptr<IconHelper> icon_helper_; | 170 scoped_ptr<IconHelper> icon_helper_; |
196 scoped_ptr<content::WebContents> pending_contents_; | 171 scoped_ptr<content::WebContents> pending_contents_; |
| 172 scoped_ptr<BrowserViewRenderer> browser_view_renderer_; |
197 | 173 |
198 // GURL is supplied by the content layer as requesting frame. | 174 // GURL is supplied by the content layer as requesting frame. |
199 // Callback is supplied by the content layer, and is invoked with the result | 175 // Callback is supplied by the content layer, and is invoked with the result |
200 // from the permission prompt. | 176 // from the permission prompt. |
201 typedef std::pair<const GURL, base::Callback<void(bool)> > OriginCallback; | 177 typedef std::pair<const GURL, base::Callback<void(bool)> > OriginCallback; |
202 // The first element in the list is always the currently pending request. | 178 // The first element in the list is always the currently pending request. |
203 std::list<OriginCallback> pending_geolocation_prompts_; | 179 std::list<OriginCallback> pending_geolocation_prompts_; |
204 | 180 |
205 // Compositor-specific state. | |
206 scoped_ptr<content::Compositor> compositor_; | |
207 scoped_refptr<cc::Layer> scissor_clip_layer_; | |
208 scoped_refptr<cc::Layer> transform_layer_; | |
209 scoped_refptr<cc::Layer> view_clip_layer_; | |
210 gfx::Point hw_rendering_scroll_; | |
211 gfx::Size view_size_; | |
212 bool view_visible_; | |
213 bool compositor_visible_; | |
214 bool is_composite_pending_; | |
215 float dpi_scale_; | |
216 OnNewPictureMode on_new_picture_mode_; | |
217 | |
218 // Used only for detecting Android View System context changes. | |
219 // Not to be used between draw calls. | |
220 EGLContext last_frame_context_; | |
221 | |
222 DISALLOW_COPY_AND_ASSIGN(AwContents); | 181 DISALLOW_COPY_AND_ASSIGN(AwContents); |
223 }; | 182 }; |
224 | 183 |
225 bool RegisterAwContents(JNIEnv* env); | 184 bool RegisterAwContents(JNIEnv* env); |
226 | 185 |
227 } // namespace android_webview | 186 } // namespace android_webview |
228 | 187 |
229 #endif // ANDROID_WEBVIEW_NATIVE_AW_CONTENTS_H_ | 188 #endif // ANDROID_WEBVIEW_NATIVE_AW_CONTENTS_H_ |
OLD | NEW |