Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(573)

Side by Side Diff: content/public/android/java/src/org/chromium/content/browser/ContentView.java

Issue 10696173: Revert "Revert 146000 - Split out ContentViewCore from ContentView for embedders." (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase number deux Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 package org.chromium.content.browser; 5 package org.chromium.content.browser;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.content.res.Configuration;
9 import android.graphics.Canvas;
8 import android.util.AttributeSet; 10 import android.util.AttributeSet;
9 import android.util.Log; 11 import android.view.KeyEvent;
12 import android.view.MotionEvent;
10 import android.view.View; 13 import android.view.View;
11 import android.webkit.DownloadListener; 14 import android.webkit.DownloadListener;
12 import android.widget.FrameLayout; 15 import android.widget.FrameLayout;
13 16
14 import org.chromium.base.CalledByNative; 17 /**
15 import org.chromium.base.JNINamespace; 18 * The containing view for {@link ContentViewCore} that exists in the Android UI hierarchy and
16 import org.chromium.base.WeakContext; 19 * exposes the various {@link View} functionality to it.
17 import org.chromium.content.app.AppResource; 20 *
18 import org.chromium.content.common.TraceEvent; 21 * TODO(joth): Remove any methods overrides from this class that were added for WebView
19 22 * compatibility.
20 @JNINamespace("content") 23 */
21 public class ContentView extends FrameLayout { 24 public class ContentView extends FrameLayout implements ContentViewCore.Internal AccessDelegate {
22 25
23 // The following constants match the ones in chrome/common/page_transition_t ypes.h. 26 // The following constants match the ones in chrome/common/page_transition_t ypes.h.
24 // Add more if you need them. 27 // Add more if you need them.
25 public static final int PAGE_TRANSITION_LINK = 0; 28 public static final int PAGE_TRANSITION_LINK = 0;
26 public static final int PAGE_TRANSITION_TYPED = 1; 29 public static final int PAGE_TRANSITION_TYPED = 1;
27 public static final int PAGE_TRANSITION_AUTO_BOOKMARK = 2; 30 public static final int PAGE_TRANSITION_AUTO_BOOKMARK = 2;
28 public static final int PAGE_TRANSITION_START_PAGE = 6; 31 public static final int PAGE_TRANSITION_START_PAGE = 6;
29 32
30 private static final String TAG = "ContentView"; 33 /** Translate the find selection into a normal selection. */
34 public static final int FIND_SELECTION_ACTION_KEEP_SELECTION =
35 ContentViewCore.FIND_SELECTION_ACTION_KEEP_SELECTION;
36 /** Clear the find selection. */
37 public static final int FIND_SELECTION_ACTION_CLEAR_SELECTION =
38 ContentViewCore.FIND_SELECTION_ACTION_CLEAR_SELECTION;
39 /** Focus and click the selected node (for links). */
40 public static final int FIND_SELECTION_ACTION_ACTIVATE_SELECTION =
41 ContentViewCore.FIND_SELECTION_ACTION_ACTIVATE_SELECTION;
31 42
32 // Personality of the ContentView.
33 private int mPersonality;
34 // Used when ContentView implements a standalone View. 43 // Used when ContentView implements a standalone View.
35 public static final int PERSONALITY_VIEW = 0; 44 public static final int PERSONALITY_VIEW = ContentViewCore.PERSONALITY_VIEW;
36 // Used for Chrome. 45 // Used for Chrome.
37 public static final int PERSONALITY_CHROME = 1; 46 public static final int PERSONALITY_CHROME = ContentViewCore.PERSONALITY_CHR OME;
38 47
39 /** 48 /**
40 * Automatically decide the number of renderer processes to use based on dev ice memory class. 49 * Automatically decide the number of renderer processes to use based on dev ice memory class.
41 * */ 50 * */
42 public static final int MAX_RENDERERS_AUTOMATIC = AndroidBrowserProcess.MAX_ RENDERERS_AUTOMATIC; 51 public static final int MAX_RENDERERS_AUTOMATIC = AndroidBrowserProcess.MAX_ RENDERERS_AUTOMATIC;
43 /** 52 /**
44 * Use single-process mode that runs the renderer on a separate thread in th e main application. 53 * Use single-process mode that runs the renderer on a separate thread in th e main application.
45 */ 54 */
46 public static final int MAX_RENDERERS_SINGLE_PROCESS = 55 public static final int MAX_RENDERERS_SINGLE_PROCESS =
47 AndroidBrowserProcess.MAX_RENDERERS_SINGLE_PROCESS; 56 AndroidBrowserProcess.MAX_RENDERERS_SINGLE_PROCESS;
48 57 /**
49 // Used to avoid enabling zooming in / out in WebView zoom controls 58 * Cap on the maximum number of renderer processes that can be requested.
50 // if resulting zooming will produce little visible difference. 59 */
51 private static float WEBVIEW_ZOOM_CONTROLS_EPSILON = 0.007f; 60 public static final int MAX_RENDERERS_LIMIT = AndroidBrowserProcess.MAX_REND ERERS_LIMIT;
52
53 // content_view_client.cc depends on ContentView.java holding a ref to the c urrent client
54 // instance since the native side only holds a weak pointer to the client. W e chose this
55 // solution over the managed object owning the C++ object's memory since it' s a lot simpler
56 // in terms of clean up.
57 private ContentViewClient mContentViewClient;
58
59 private ContentSettings mContentSettings;
60
61 // Native pointer to C++ ContentView object which will be set by nativeInit( )
62 private int mNativeContentView = 0;
63
64 private ZoomManager mZoomManager;
65
66 // Cached page scale factor from native
67 private float mNativePageScaleFactor = 1.0f;
68 private float mNativeMinimumScale = 1.0f;
69 private float mNativeMaximumScale = 1.0f;
70
71 // TODO(klobag): this is to avoid a bug in GestureDetector. With multi-touch ,
72 // mAlwaysInTapRegion is not reset. So when the last finger is up, onSingleT apUp()
73 // will be mistakenly fired.
74 private boolean mIgnoreSingleTap;
75
76 // The legacy webview DownloadListener.
77 private DownloadListener mDownloadListener;
78 // ContentViewDownloadDelegate adds support for authenticated downloads
79 // and POST downloads. Embedders should prefer ContentViewDownloadDelegate
80 // over DownloadListener.
81 private ContentViewDownloadDelegate mDownloadDelegate;
82 61
83 /** 62 /**
84 * Enable multi-process ContentView. This should be called by the applicatio n before 63 * Enable multi-process ContentView. This should be called by the applicatio n before
85 * constructing any ContentView instances. If enabled, ContentView will run renderers in 64 * constructing any ContentView instances. If enabled, ContentView will run renderers in
86 * separate processes up to the number of processes specified by maxRenderPr ocesses. If this is 65 * separate processes up to the number of processes specified by maxRenderPr ocesses. If this is
87 * not called then the default is to run the renderer in the main applicatio n on a separate 66 * not called then the default is to run the renderer in the main applicatio n on a separate
88 * thread. 67 * thread.
89 * 68 *
90 * @param context Context used to obtain the application context. 69 * @param context Context used to obtain the application context.
91 * @param maxRendererProcesses Limit on the number of renderers to use. Each tab runs in its own 70 * @param maxRendererProcesses Limit on the number of renderers to use. Each tab runs in its own
92 * process until the maximum number of processes is reached. The special val ue of 71 * process until the maximum number of processes is reached. The special val ue of
93 * MAX_RENDERERS_SINGLE_PROCESS requests single-process mode where the rende rer will run in the 72 * MAX_RENDERERS_SINGLE_PROCESS requests single-process mode where the rende rer will run in the
94 * application process in a separate thread. If the special value MAX_RENDER ERS_AUTOMATIC is 73 * application process in a separate thread. If the special value MAX_RENDER ERS_AUTOMATIC is
95 * used then the number of renderers will be determined based on the device memory class. The 74 * used then the number of renderers will be determined based on the device memory class. The
96 * maximum number of allowed renderers is capped by MAX_RENDERERS_LIMIT. 75 * maximum number of allowed renderers is capped by MAX_RENDERERS_LIMIT.
97 */ 76 */
98 public static void enableMultiProcess(Context context, int maxRendererProces ses) { 77 public static void enableMultiProcess(Context context, int maxRendererProces ses) {
99 AndroidBrowserProcess.initContentViewProcess(context, maxRendererProcess es); 78 ContentViewCore.enableMultiProcess(context, maxRendererProcesses);
100 } 79 }
101 80
81 /**
82 * Initialize the process as the platform browser. This must be called befor e accessing
83 * ContentView in order to treat this as a Chromium browser process.
84 *
85 * @param context Context used to obtain the application context.
86 * @param maxRendererProcesses Same as ContentView.enableMultiProcess()
87 * @hide Only used by the platform browser.
88 */
89 public static void initChromiumBrowserProcess(Context context, int maxRender erProcesses) {
90 ContentViewCore.initChromiumBrowserProcess(context, maxRendererProcesses );
91 }
92
93 private ContentViewCore mContentViewCore;
94
102 public ContentView(Context context, int nativeWebContents, int personality) { 95 public ContentView(Context context, int nativeWebContents, int personality) {
103 this(context, nativeWebContents, null, android.R.attr.webViewStyle, pers onality); 96 this(context, nativeWebContents, null, android.R.attr.webViewStyle, pers onality);
104 } 97 }
105 98
99 public ContentView(Context context, int nativeWebContents, AttributeSet attr s) {
100 // TODO(klobag): use the WebViewStyle as the default style for now. It e nables scrollbar.
101 // When ContentView is moved to framework, we can define its own style i n the res.
102 this(context, nativeWebContents, attrs, android.R.attr.webViewStyle);
103 }
104
105 public ContentView(Context context, int nativeWebContents, AttributeSet attr s, int defStyle) {
106 this(context, nativeWebContents, attrs, defStyle, PERSONALITY_VIEW);
107 }
108
106 private ContentView(Context context, int nativeWebContents, AttributeSet att rs, int defStyle, 109 private ContentView(Context context, int nativeWebContents, AttributeSet att rs, int defStyle,
107 int personality) { 110 int personality) {
108 super(context, attrs, defStyle); 111 super(context, attrs, defStyle);
109 112
110 WeakContext.initializeWeakContext(context); 113 mContentViewCore = new ContentViewCore(context, this, this, nativeWebCon tents, personality);
111 // By default, ContentView will initialize single process mode. The call to
112 // initContentViewProcess below is ignored if either the ContentView hos t called
113 // enableMultiProcess() or the platform browser called initChromiumBrows erProcess().
114 AndroidBrowserProcess.initContentViewProcess(context, MAX_RENDERERS_SING LE_PROCESS);
115
116 initialize(context, nativeWebContents, personality);
117 } 114 }
118 115
119 // TODO(jrg): incomplete; upstream the rest of this method. 116 /**
120 private void initialize(Context context, int nativeWebContents, int personal ity) { 117 * @return The core component of the ContentView that handles JNI communicat ion. Should only be
121 mNativeContentView = nativeInit(nativeWebContents); 118 * used for passing to native.
122 119 */
123 mPersonality = personality; 120 public ContentViewCore getContentViewCore() {
124 mContentSettings = new ContentSettings(this, mNativeContentView); 121 return mContentViewCore;
125
126 initGestureDetectors(context);
127
128 Log.i(TAG, "mNativeContentView=0x"+ Integer.toHexString(mNativeContentVi ew));
129 } 122 }
130 123
131 /** 124 /**
132 * @return Whether the configured personality of this ContentView is {@link #PERSONALITY_VIEW}. 125 * @return Whether the configured personality of this ContentView is {@link #PERSONALITY_VIEW}.
133 */ 126 */
134 boolean isPersonalityView() { 127 boolean isPersonalityView() {
135 switch (mPersonality) { 128 return mContentViewCore.isPersonalityView();
136 case PERSONALITY_VIEW:
137 return true;
138 case PERSONALITY_CHROME:
139 return false;
140 default:
141 Log.e(TAG, "Unknown ContentView personality: " + mPersonality);
142 return false;
143 }
144 } 129 }
145 130
146
147 /** 131 /**
148 * Destroy the internal state of the WebView. This method may only be called 132 * Destroy the internal state of the WebView. This method may only be called
149 * after the WebView has been removed from the view system. No other methods 133 * after the WebView has been removed from the view system. No other methods
150 * may be called on this WebView after this method has been called. 134 * may be called on this WebView after this method has been called.
151 */ 135 */
152 // TODO(jrg): incomplete; upstream the rest of this method.
153 public void destroy() { 136 public void destroy() {
154 if (mNativeContentView != 0) { 137 mContentViewCore.destroy();
155 nativeDestroy(mNativeContentView);
156 mNativeContentView = 0;
157 }
158 if (mContentSettings != null) {
159 mContentSettings.destroy();
160 mContentSettings = null;
161 }
162 } 138 }
163 139
164 /** 140 /**
165 * Returns true initially, false after destroy() has been called. 141 * Returns true initially, false after destroy() has been called.
166 * It is illegal to call any other public method after destroy(). 142 * It is illegal to call any other public method after destroy().
167 */ 143 */
168 public boolean isAlive() { 144 public boolean isAlive() {
169 return mNativeContentView != 0; 145 return mContentViewCore.isAlive();
146 }
147
148 /**
149 * For internal use. Throws IllegalStateException if mNativeContentView is 0 .
150 * Use this to ensure we get a useful Java stack trace, rather than a native
151 * crash dump, from use-after-destroy bugs in Java code.
152 */
153 void checkIsAlive() throws IllegalStateException {
154 mContentViewCore.checkIsAlive();
170 } 155 }
171 156
172 public void setContentViewClient(ContentViewClient client) { 157 public void setContentViewClient(ContentViewClient client) {
173 if (client == null) { 158 mContentViewCore.setContentViewClient(client);
174 throw new IllegalArgumentException("The client can't be null.");
175 }
176 mContentViewClient = client;
177 if (mNativeContentView != 0) {
178 nativeSetClient(mNativeContentView, mContentViewClient);
179 }
180 } 159 }
181 160
182 ContentViewClient getContentViewClient() { 161 ContentViewClient getContentViewClient() {
183 if (mContentViewClient == null) { 162 return mContentViewCore.getContentViewClient();
184 // We use the Null Object pattern to avoid having to perform a null check in this class.
185 // We create it lazily because most of the time a client will be set almost immediately
186 // after ContentView is created.
187 mContentViewClient = new ContentViewClient();
188 // We don't set the native ContentViewClient pointer here on purpose . The native
189 // implementation doesn't mind a null delegate and using one is bett er than passing a
190 // Null Object, since we cut down on the number of JNI calls.
191 }
192 return mContentViewClient;
193 } 163 }
194 164
195 /** 165 /**
196 * Load url without fixing up the url string. Consumers of ContentView are r esponsible for 166 * Load url without fixing up the url string. Consumers of ContentView are r esponsible for
197 * ensuring the URL passed in is properly formatted (i.e. the scheme has bee n added if left 167 * ensuring the URL passed in is properly formatted (i.e. the scheme has bee n added if left
198 * off during user input). 168 * off during user input).
199 * 169 *
200 * @param url The url to load. 170 * @param url The url to load.
201 */ 171 */
202 public void loadUrlWithoutUrlSanitization(String url) { 172 public void loadUrlWithoutUrlSanitization(String url) {
203 loadUrlWithoutUrlSanitization(url, PAGE_TRANSITION_TYPED); 173 loadUrlWithoutUrlSanitization(url, PAGE_TRANSITION_TYPED);
204 } 174 }
205 175
206 /** 176 /**
207 * Load url without fixing up the url string. Consumers of ContentView are r esponsible for 177 * Load url without fixing up the url string. Consumers of ContentView are r esponsible for
208 * ensuring the URL passed in is properly formatted (i.e. the scheme has bee n added if left 178 * ensuring the URL passed in is properly formatted (i.e. the scheme has bee n added if left
209 * off during user input). 179 * off during user input).
210 * 180 *
211 * @param url The url to load. 181 * @param url The url to load.
212 * @param pageTransition Page transition id that describes the action that l ed to this 182 * @param pageTransition Page transition id that describes the action that l ed to this
213 * navigation. It is important for ranking URLs in the history so the 183 * navigation. It is important for ranking URLs in the history so the
214 * omnibox can report suggestions correctly. 184 * omnibox can report suggestions correctly.
215 */ 185 */
216 public void loadUrlWithoutUrlSanitization(String url, int pageTransition) { 186 public void loadUrlWithoutUrlSanitization(String url, int pageTransition) {
217 if (mNativeContentView != 0) { 187 mContentViewCore.loadUrlWithoutUrlSanitization(url, pageTransition);
218 if (isPersonalityView()) {
219 nativeLoadUrlWithoutUrlSanitizationWithUserAgentOverride(
220 mNativeContentView,
221 url,
222 pageTransition,
223 mContentSettings.getUserAgentString());
224 } else {
225 // Chrome stores overridden UA strings in navigation history
226 // items, so they stay the same on going back / forward.
227 nativeLoadUrlWithoutUrlSanitization(
228 mNativeContentView,
229 url,
230 pageTransition);
231 }
232 }
233 } 188 }
234 189
235 void setAllUserAgentOverridesInHistory() { 190 void setAllUserAgentOverridesInHistory() {
236 // TODO(tedchoc): Pass user agent override down to native. 191 mContentViewCore.setAllUserAgentOverridesInHistory();
237 } 192 }
238 193
239 /** 194 /**
240 * Stops loading the current web contents. 195 * Stops loading the current web contents.
241 */ 196 */
242 public void stopLoading() { 197 public void stopLoading() {
243 if (mNativeContentView != 0) nativeStopLoading(mNativeContentView); 198 mContentViewCore.stopLoading();
244 } 199 }
245 200
246 /** 201 /**
247 * Get the URL of the current page. 202 * Get the URL of the current page.
248 * 203 *
249 * @return The URL of the current page. 204 * @return The URL of the current page.
250 */ 205 */
251 public String getUrl() { 206 public String getUrl() {
252 if (mNativeContentView != 0) return nativeGetURL(mNativeContentView); 207 return mContentViewCore.getUrl();
253 return null;
254 } 208 }
255 209
256 /** 210 /**
257 * Get the title of the current page. 211 * Get the title of the current page.
258 * 212 *
259 * @return The title of the current page. 213 * @return The title of the current page.
260 */ 214 */
261 public String getTitle() { 215 public String getTitle() {
262 if (mNativeContentView != 0) return nativeGetTitle(mNativeContentView); 216 return mContentViewCore.getTitle();
263 return null;
264 } 217 }
265 218
266 /** 219 /**
267 * @return The load progress of current web contents (range is 0 - 100). 220 * @return The load progress of current web contents (range is 0 - 100).
268 */ 221 */
269 public int getProgress() { 222 public int getProgress() {
270 if (mNativeContentView != 0) { 223 return mContentViewCore.getProgress();
271 return (int) (100.0 * nativeGetLoadProgress(mNativeContentView));
272 }
273 return 100;
274 } 224 }
275 225
276 /** 226 /**
277 * @return Whether the current WebContents has a previous navigation entry. 227 * @return Whether the current WebContents has a previous navigation entry.
278 */ 228 */
279 public boolean canGoBack() { 229 public boolean canGoBack() {
280 return mNativeContentView != 0 && nativeCanGoBack(mNativeContentView); 230 return mContentViewCore.canGoBack();
281 } 231 }
282 232
283 /** 233 /**
284 * @return Whether the current WebContents has a navigation entry after the current one. 234 * @return Whether the current WebContents has a navigation entry after the current one.
285 */ 235 */
286 public boolean canGoForward() { 236 public boolean canGoForward() {
287 return mNativeContentView != 0 && nativeCanGoForward(mNativeContentView) ; 237 return mContentViewCore.canGoForward();
288 } 238 }
289 239
290 /** 240 /**
291 * @param offset The offset into the navigation history. 241 * @param offset The offset into the navigation history.
292 * @return Whether we can move in history by given offset 242 * @return Whether we can move in history by given offset
293 */ 243 */
294 public boolean canGoToOffset(int offset) { 244 public boolean canGoToOffset(int offset) {
295 return mNativeContentView != 0 && nativeCanGoToOffset(mNativeContentView , offset); 245 return mContentViewCore.canGoToOffset(offset);
296 } 246 }
297 247
298 /** 248 /**
299 * Navigates to the specified offset from the "current entry". Does nothing if the offset is out 249 * Navigates to the specified offset from the "current entry". Does nothing if the offset is out
300 * of bounds. 250 * of bounds.
301 * @param offset The offset into the navigation history. 251 * @param offset The offset into the navigation history.
302 */ 252 */
303 public void goToOffset(int offset) { 253 public void goToOffset(int offset) {
304 if (mNativeContentView != 0) nativeGoToOffset(mNativeContentView, offset ); 254 mContentViewCore.goToOffset(offset);
305 } 255 }
306 256
307 /** 257 /**
308 * Goes to the navigation entry before the current one. 258 * Goes to the navigation entry before the current one.
309 */ 259 */
310 public void goBack() { 260 public void goBack() {
311 if (mNativeContentView != 0) nativeGoBack(mNativeContentView); 261 mContentViewCore.goBack();
312 } 262 }
313 263
314 /** 264 /**
315 * Goes to the navigation entry following the current one. 265 * Goes to the navigation entry following the current one.
316 */ 266 */
317 public void goForward() { 267 public void goForward() {
318 if (mNativeContentView != 0) nativeGoForward(mNativeContentView); 268 mContentViewCore.goForward();
319 } 269 }
320 270
321 /** 271 /**
322 * Reload the current page. 272 * Reload the current page.
323 */ 273 */
324 public void reload() { 274 public void reload() {
325 if (mNativeContentView != 0) nativeReload(mNativeContentView); 275 mContentViewCore.reload();
326 } 276 }
327 277
328 /** 278 /**
329 * Clears the WebView's page history in both the backwards and forwards 279 * Clears the WebView's page history in both the backwards and forwards
330 * directions. 280 * directions.
331 */ 281 */
332 public void clearHistory() { 282 public void clearHistory() {
333 if (mNativeContentView != 0) nativeClearHistory(mNativeContentView); 283 mContentViewCore.clearHistory();
334 } 284 }
335 285
336 /** 286 /**
337 * Start pinch zoom. You must call {@link #pinchEnd} to stop. 287 * Start pinch zoom. You must call {@link #pinchEnd} to stop.
338 */ 288 */
339 void pinchBegin(long timeMs, int x, int y) { 289 void pinchBegin(long timeMs, int x, int y) {
340 if (mNativeContentView != 0) { 290 mContentViewCore.pinchBegin(timeMs, x, y);
341 // TODO(tedchoc): Pass pinch begin to native.
342 }
343 } 291 }
344 292
345 /** 293 /**
346 * Stop pinch zoom. 294 * Stop pinch zoom.
347 */ 295 */
348 void pinchEnd(long timeMs) { 296 void pinchEnd(long timeMs) {
349 if (mNativeContentView != 0) { 297 mContentViewCore.pinchEnd(timeMs);
350 // TODO(tedchoc): Pass pinch end to native.
351 }
352 } 298 }
353 299
354 void setIgnoreSingleTap(boolean value) { 300 void setIgnoreSingleTap(boolean value) {
355 mIgnoreSingleTap = value; 301 mContentViewCore.setIgnoreSingleTap(value);
356 } 302 }
357 303
358 /** 304 /**
359 * Modify the ContentView magnification level. The effect of calling this 305 * Modify the ContentView magnification level. The effect of calling this
360 * method is exactly as after "pinch zoom". 306 * method is exactly as after "pinch zoom".
361 * 307 *
362 * @param timeMs The event time in milliseconds. 308 * @param timeMs The event time in milliseconds.
363 * @param delta The ratio of the new magnification level over the current 309 * @param delta The ratio of the new magnification level over the current
364 * magnification level. 310 * magnification level.
365 * @param anchorX The magnification anchor (X) in the current view 311 * @param anchorX The magnification anchor (X) in the current view
366 * coordinate. 312 * coordinate.
367 * @param anchorY The magnification anchor (Y) in the current view 313 * @param anchorY The magnification anchor (Y) in the current view
368 * coordinate. 314 * coordinate.
369 */ 315 */
370 void pinchBy(long timeMs, int anchorX, int anchorY, float delta) { 316 void pinchBy(long timeMs, int anchorX, int anchorY, float delta) {
371 if (mNativeContentView != 0) { 317 mContentViewCore.pinchBy(timeMs, anchorX, anchorY, delta);
372 // TODO(tedchoc): Pass pinch by to native.
373 }
374 } 318 }
375 319
376 /** 320 /**
377 * Return the ContentSettings object used to control the settings for this 321 * Return the ContentSettings object used to control the settings for this
378 * WebView. 322 * WebView.
379 * 323 *
380 * Note that when ContentView is used in the PERSONALITY_CHROME role, 324 * Note that when ContentView is used in the PERSONALITY_CHROME role,
381 * ContentSettings can only be used for retrieving settings values. For 325 * ContentSettings can only be used for retrieving settings values. For
382 * modifications, ChromeNativePreferences is to be used. 326 * modifications, ChromeNativePreferences is to be used.
383 * @return A ContentSettings object that can be used to control this WebView 's 327 * @return A ContentSettings object that can be used to control this WebView 's
384 * settings. 328 * settings.
385 */ 329 */
386 public ContentSettings getContentSettings() { 330 public ContentSettings getContentSettings() {
387 return mContentSettings; 331 return mContentViewCore.getContentSettings();
388 } 332 }
389 333
390 private void initGestureDetectors(final Context context) { 334 // FrameLayout overrides.
391 try { 335
392 TraceEvent.begin(); 336 // Needed by ContentViewCore.InternalAccessDelegate
393 // TODO(tedchoc): Upstream the rest of the initialization. 337 @Override
394 mZoomManager = new ZoomManager(context, this); 338 public boolean drawChild(Canvas canvas, View child, long drawingTime) {
395 mZoomManager.updateMultiTouchSupport(); 339 return super.drawChild(canvas, child, drawingTime);
396 } finally { 340 }
397 TraceEvent.end(); 341
398 } 342 // Needed by ContentViewCore.InternalAccessDelegate
343 @Override
344 public void onScrollChanged(int l, int t, int oldl, int oldt) {
345 super.onScrollChanged(l, t, oldl, oldt);
346 }
347
348 // End FrameLayout overrides.
349
350 @Override
351 public boolean awakenScrollBars(int startDelay, boolean invalidate) {
352 return mContentViewCore.awakenScrollBars(startDelay, invalidate);
353 }
354
355 @Override
356 public boolean awakenScrollBars() {
357 return super.awakenScrollBars();
399 } 358 }
400 359
401 void updateMultiTouchZoomSupport() { 360 void updateMultiTouchZoomSupport() {
402 mZoomManager.updateMultiTouchSupport(); 361 mContentViewCore.updateMultiTouchZoomSupport();
403 } 362 }
404 363
405 public boolean isMultiTouchZoomSupported() { 364 public boolean isMultiTouchZoomSupported() {
406 return mZoomManager.isMultiTouchZoomSupported(); 365 return mContentViewCore.isMultiTouchZoomSupported();
407 } 366 }
408 367
409 /** 368 /**
410 * Register the listener to be used when content can not be handled by the 369 * Register the listener to be used when content can not be handled by the
411 * rendering engine, and should be downloaded instead. This will replace the 370 * rendering engine, and should be downloaded instead. This will replace the
412 * current listener. 371 * current listener.
413 * @param listener An implementation of DownloadListener. 372 * @param listener An implementation of DownloadListener.
414 */ 373 */
415 // TODO(nileshagrawal): decide if setDownloadDelegate will be public API. If so, 374 // TODO(nileshagrawal): decide if setDownloadDelegate will be public API. If so,
416 // this method should be deprecated and the javadoc should make reference to the 375 // this method should be deprecated and the javadoc should make reference to the
417 // fact that a ContentViewDownloadDelegate will be used in preference to a 376 // fact that a ContentViewDownloadDelegate will be used in preference to a
418 // DownloadListener. 377 // DownloadListener.
419 public void setDownloadListener(DownloadListener listener) { 378 public void setDownloadListener(DownloadListener listener) {
420 mDownloadListener = listener; 379 mContentViewCore.setDownloadListener(listener);
421 } 380 }
422 381
423 // Called by DownloadController. 382 // Called by DownloadController.
424 DownloadListener downloadListener() { 383 DownloadListener downloadListener() {
425 return mDownloadListener; 384 return mContentViewCore.downloadListener();
426 } 385 }
427 386
428 /** 387 /**
429 * Register the delegate to be used when content can not be handled by 388 * Register the delegate to be used when content can not be handled by
430 * the rendering engine, and should be downloaded instead. This will replace 389 * the rendering engine, and should be downloaded instead. This will replace
431 * the current delegate or existing DownloadListner. 390 * the current delegate or existing DownloadListner.
432 * Embedders should prefer this over the legacy DownloadListener. 391 * Embedders should prefer this over the legacy DownloadListener.
433 * @param listener An implementation of ContentViewDownloadDelegate. 392 * @param listener An implementation of ContentViewDownloadDelegate.
434 */ 393 */
435 public void setDownloadDelegate(ContentViewDownloadDelegate delegate) { 394 public void setDownloadDelegate(ContentViewDownloadDelegate delegate) {
436 mDownloadDelegate = delegate; 395 mContentViewCore.setDownloadDelegate(delegate);
437 } 396 }
438 397
439 // Called by DownloadController. 398 // Called by DownloadController.
440 ContentViewDownloadDelegate getDownloadDelegate() { 399 ContentViewDownloadDelegate getDownloadDelegate() {
441 return mDownloadDelegate; 400 return mContentViewCore.getDownloadDelegate();
442 } 401 }
443 402
444 /** 403 /**
445 * @return Whether the native ContentView has crashed. 404 * @return Whether the native ContentView has crashed.
446 */ 405 */
447 public boolean isCrashed() { 406 public boolean isCrashed() {
448 if (mNativeContentView == 0) return false; 407 return mContentViewCore.isCrashed();
449 return nativeCrashed(mNativeContentView);
450 } 408 }
451 409
452 /** 410 /**
453 * @return Whether a reload happens when this ContentView is activated. 411 * @return Whether a reload happens when this ContentView is activated.
454 */ 412 */
455 public boolean needsReload() { 413 public boolean needsReload() {
456 return mNativeContentView != 0 && nativeNeedsReload(mNativeContentView); 414 return mContentViewCore.needsReload();
457 } 415 }
458 416
459 /** 417 /**
460 * Checks whether the WebView can be zoomed in. 418 * Checks whether the WebView can be zoomed in.
461 * 419 *
462 * @return True if the WebView can be zoomed in. 420 * @return True if the WebView can be zoomed in.
463 */ 421 */
464 // This method uses the term 'zoom' for legacy reasons, but relates 422 // This method uses the term 'zoom' for legacy reasons, but relates
465 // to what chrome calls the 'page scale factor'. 423 // to what chrome calls the 'page scale factor'.
466 public boolean canZoomIn() { 424 public boolean canZoomIn() {
467 return mNativeMaximumScale - mNativePageScaleFactor > WEBVIEW_ZOOM_CONTR OLS_EPSILON; 425 return mContentViewCore.canZoomIn();
468 } 426 }
469 427
470 /** 428 /**
471 * Checks whether the WebView can be zoomed out. 429 * Checks whether the WebView can be zoomed out.
472 * 430 *
473 * @return True if the WebView can be zoomed out. 431 * @return True if the WebView can be zoomed out.
474 */ 432 */
475 // This method uses the term 'zoom' for legacy reasons, but relates 433 // This method uses the term 'zoom' for legacy reasons, but relates
476 // to what chrome calls the 'page scale factor'. 434 // to what chrome calls the 'page scale factor'.
477 public boolean canZoomOut() { 435 public boolean canZoomOut() {
478 return mNativePageScaleFactor - mNativeMinimumScale > WEBVIEW_ZOOM_CONTR OLS_EPSILON; 436 return mContentViewCore.canZoomOut();
479 } 437 }
480 438
481 /** 439 /**
482 * Zooms in the WebView by 25% (or less if that would result in zooming in 440 * Zooms in the WebView by 25% (or less if that would result in zooming in
483 * more than possible). 441 * more than possible).
484 * 442 *
485 * @return True if there was a zoom change, false otherwise. 443 * @return True if there was a zoom change, false otherwise.
486 */ 444 */
487 // This method uses the term 'zoom' for legacy reasons, but relates 445 // This method uses the term 'zoom' for legacy reasons, but relates
488 // to what chrome calls the 'page scale factor'. 446 // to what chrome calls the 'page scale factor'.
489 public boolean zoomIn() { 447 public boolean zoomIn() {
490 if (!canZoomIn()) { 448 return mContentViewCore.zoomIn();
491 return false;
492 }
493
494 if (mNativeContentView == 0) {
495 return false;
496 }
497
498 long timeMs = System.currentTimeMillis();
499 int x = getWidth() / 2;
500 int y = getHeight() / 2;
501 float delta = 1.25f;
502
503 pinchBegin(timeMs, x, y);
504 pinchBy(timeMs, x, y, delta);
505 pinchEnd(timeMs);
506
507 return true;
508 } 449 }
509 450
510 /** 451 /**
511 * Zooms out the WebView by 20% (or less if that would result in zooming out 452 * Zooms out the WebView by 20% (or less if that would result in zooming out
512 * more than possible). 453 * more than possible).
513 * 454 *
514 * @return True if there was a zoom change, false otherwise. 455 * @return True if there was a zoom change, false otherwise.
515 */ 456 */
516 // This method uses the term 'zoom' for legacy reasons, but relates 457 // This method uses the term 'zoom' for legacy reasons, but relates
517 // to what chrome calls the 'page scale factor'. 458 // to what chrome calls the 'page scale factor'.
518 public boolean zoomOut() { 459 public boolean zoomOut() {
519 if (!canZoomOut()) { 460 return mContentViewCore.zoomOut();
520 return false;
521 }
522
523 if (mNativeContentView == 0) {
524 return false;
525 }
526
527 long timeMs = System.currentTimeMillis();
528 int x = getWidth() / 2;
529 int y = getHeight() / 2;
530 float delta = 0.8f;
531
532 pinchBegin(timeMs, x, y);
533 pinchBy(timeMs, x, y, delta);
534 pinchEnd(timeMs);
535
536 return true;
537 } 461 }
538 462
539 // Invokes the graphical zoom picker widget for this ContentView. 463 // Invokes the graphical zoom picker widget for this ContentView.
540 public void invokeZoomPicker() { 464 public void invokeZoomPicker() {
541 if (mContentSettings.supportZoom()) { 465 mContentViewCore.invokeZoomPicker();
542 mZoomManager.invokeZoomPicker();
543 }
544 } 466 }
545 467
546 // Unlike legacy WebView getZoomControls which returns external zoom control s, 468 // Unlike legacy WebView getZoomControls which returns external zoom control s,
547 // this method returns built-in zoom controls. This method is used in tests. 469 // this method returns built-in zoom controls. This method is used in tests.
548 public View getZoomControlsForTest() { 470 public View getZoomControlsForTest() {
549 return mZoomManager.getZoomControlsViewForTest(); 471 return mContentViewCore.getZoomControlsForTest();
550 } 472 }
551 473
552 @CalledByNative 474 //////////////////////////////////////////////////////////////////////////// ///////////////////
553 private void startContentIntent(String contentUrl) { 475 // Start Implementation of ContentViewCore.InternalAccessDelega te //
554 getContentViewClient().onStartContentIntent(getContext(), contentUrl); 476 //////////////////////////////////////////////////////////////////////////// ///////////////////
477
478 @Override
479 public boolean super_onKeyUp(int keyCode, KeyEvent event) {
480 return super.onKeyUp(keyCode, event);
555 } 481 }
556 482
483 @Override
484 public boolean super_dispatchKeyEventPreIme(KeyEvent event) {
485 return super.dispatchKeyEventPreIme(event);
486 }
557 487
558 /** 488 @Override
559 * Initialize the ContentView native side. 489 public boolean super_dispatchKeyEvent(KeyEvent event) {
560 * Should be called with a valid native WebContents. 490 return super.dispatchKeyEvent(event);
561 * If nativeInitProcess is never called, the first time this method is calle d, nativeInitProcess 491 }
562 * will be called implicitly with the default settings.
563 * @param webContentsPtr the ContentView does not create a new native WebCon tents and uses
564 * the provided one.
565 * @return a native pointer to the native ContentView object.
566 */
567 private native int nativeInit(int webContentsPtr);
568 492
569 private native void nativeDestroy(int nativeContentViewImpl); 493 @Override
494 public boolean super_onGenericMotionEvent(MotionEvent event) {
495 return super.onGenericMotionEvent(event);
496 }
570 497
571 private native void nativeLoadUrlWithoutUrlSanitization(int nativeContentVie wImpl, 498 @Override
572 String url, int pageTransition); 499 public void super_onConfigurationChanged(Configuration newConfig) {
573 private native void nativeLoadUrlWithoutUrlSanitizationWithUserAgentOverride ( 500 super.onConfigurationChanged(newConfig);
574 int nativeContentViewImpl, String url, int pageTransition, String us erAgentOverride); 501 }
575 502
576 private native String nativeGetURL(int nativeContentViewImpl); 503 @Override
504 public boolean super_awakenScrollBars(int startDelay, boolean invalidate) {
505 return super.awakenScrollBars(startDelay, invalidate);
506 }
577 507
578 private native String nativeGetTitle(int nativeContentViewImpl); 508 //////////////////////////////////////////////////////////////////////////// ///////////////////
579 509 // End Implementation of ContentViewCore.InternalAccessDelega te //
580 private native double nativeGetLoadProgress(int nativeContentViewImpl); 510 //////////////////////////////////////////////////////////////////////////// ///////////////////
581
582 private native boolean nativeIsIncognito(int nativeContentViewImpl);
583
584 // Returns true if the native side crashed so that java side can draw a sad tab.
585 private native boolean nativeCrashed(int nativeContentViewImpl);
586
587 private native boolean nativeCanGoBack(int nativeContentViewImpl);
588
589 private native boolean nativeCanGoForward(int nativeContentViewImpl);
590
591 private native boolean nativeCanGoToOffset(int nativeContentViewImpl, int of fset);
592
593 private native void nativeGoToOffset(int nativeContentViewImpl, int offset);
594
595 private native void nativeGoBack(int nativeContentViewImpl);
596
597 private native void nativeGoForward(int nativeContentViewImpl);
598
599 private native void nativeStopLoading(int nativeContentViewImpl);
600
601 private native void nativeReload(int nativeContentViewImpl);
602
603 private native void nativeSetClient(int nativeContentViewImpl, ContentViewCl ient client);
604
605 private native boolean nativeNeedsReload(int nativeContentViewImpl);
606
607 private native void nativeClearHistory(int nativeContentViewImpl);
608 } 511 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698