The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.webkit; |
| 18 | |
Ben Murdoch | f7093be | 2010-11-01 10:27:33 +0000 | [diff] [blame] | 19 | import android.app.ActivityManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | import android.content.Context; |
Derek Sollenberger | 9e28c4c | 2009-11-09 14:45:58 -0500 | [diff] [blame] | 21 | import android.content.pm.PackageManager.NameNotFoundException; |
Leon Scroggins | 70ca3c2 | 2009-10-02 15:58:55 -0400 | [diff] [blame] | 22 | import android.database.Cursor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | import android.graphics.Point; |
| 24 | import android.graphics.Rect; |
| 25 | import android.graphics.Region; |
Shimeng (Simon) Wang | bf01312 | 2010-10-05 16:59:05 -0700 | [diff] [blame] | 26 | import android.media.MediaFile; |
Kristian Monsen | 2032eee | 2011-05-23 14:25:27 +0100 | [diff] [blame] | 27 | import android.net.ProxyProperties; |
Leon Scroggins | 70ca3c2 | 2009-10-02 15:58:55 -0400 | [diff] [blame] | 28 | import android.net.Uri; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import android.os.Handler; |
| 30 | import android.os.Looper; |
| 31 | import android.os.Message; |
| 32 | import android.os.Process; |
Ben Murdoch | 65b4cda | 2010-05-28 11:07:15 +0100 | [diff] [blame] | 33 | import android.provider.MediaStore; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | import android.util.Log; |
| 35 | import android.util.SparseBooleanArray; |
| 36 | import android.view.KeyEvent; |
Huahui Wu | 0904c0d | 2011-01-07 17:30:53 -0800 | [diff] [blame] | 37 | import android.view.MotionEvent; |
Patrick Scott | fb6aecb | 2009-07-17 16:38:07 -0400 | [diff] [blame] | 38 | import android.view.SurfaceView; |
Derek Sollenberger | 0b3a5d6 | 2009-09-08 18:31:40 -0400 | [diff] [blame] | 39 | import android.view.View; |
Steve Block | dc82a29 | 2010-10-06 14:34:15 +0100 | [diff] [blame] | 40 | import android.webkit.DeviceMotionService; |
Steve Block | 1be7339 | 2010-10-15 16:31:01 +0100 | [diff] [blame] | 41 | import android.webkit.DeviceMotionAndOrientationManager; |
Steve Block | c43565b | 2010-08-11 13:12:37 +0100 | [diff] [blame] | 42 | import android.webkit.DeviceOrientationService; |
Steve Block | 808751f | 2011-01-04 14:26:27 +0000 | [diff] [blame] | 43 | import android.webkit.JniUtil; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | |
| 45 | import java.util.ArrayList; |
Nicolas Roard | 6c24b4d | 2009-09-22 18:44:52 +0100 | [diff] [blame] | 46 | import java.util.Collection; |
Andrei Popescu | 4950b2b | 2009-09-03 13:56:07 +0100 | [diff] [blame] | 47 | import java.util.Map; |
Andrei Popescu | 59e2ad9 | 2009-07-28 13:38:06 +0100 | [diff] [blame] | 48 | import java.util.Set; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | |
| 50 | import junit.framework.Assert; |
| 51 | |
Dounia Berrada | 940a198 | 2011-04-27 13:53:13 -0700 | [diff] [blame] | 52 | /** |
| 53 | * @hide |
| 54 | */ |
| 55 | public final class WebViewCore { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | |
| 57 | private static final String LOGTAG = "webcore"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | |
| 59 | static { |
Ben Murdoch | 492bbe3 | 2011-09-01 03:27:26 +0100 | [diff] [blame] | 60 | // Load libwebcore and libchromium_net during static initialization. |
| 61 | // This happens in the zygote process so they will be shared read-only |
| 62 | // across all app processes. |
Jean-Baptiste Queru | c0e9504 | 2011-01-31 15:43:19 -0800 | [diff] [blame] | 63 | try { |
| 64 | System.loadLibrary("webcore"); |
Ben Murdoch | 492bbe3 | 2011-09-01 03:27:26 +0100 | [diff] [blame] | 65 | System.loadLibrary("chromium_net"); |
Jean-Baptiste Queru | c0e9504 | 2011-01-31 15:43:19 -0800 | [diff] [blame] | 66 | } catch (UnsatisfiedLinkError e) { |
Ben Murdoch | 492bbe3 | 2011-09-01 03:27:26 +0100 | [diff] [blame] | 67 | Log.e(LOGTAG, "Unable to load native support libraries."); |
Jean-Baptiste Queru | c0e9504 | 2011-01-31 15:43:19 -0800 | [diff] [blame] | 68 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | /* |
| 72 | * WebViewCore always executes in the same thread as the native webkit. |
| 73 | */ |
| 74 | |
| 75 | // The WebView that corresponds to this WebViewCore. |
| 76 | private WebView mWebView; |
| 77 | // Proxy for handling callbacks from native code |
| 78 | private final CallbackProxy mCallbackProxy; |
| 79 | // Settings object for maintaining all settings |
| 80 | private final WebSettings mSettings; |
| 81 | // Context for initializing the BrowserFrame with the proper assets. |
| 82 | private final Context mContext; |
| 83 | // The pointer to a native view object. |
| 84 | private int mNativeClass; |
| 85 | // The BrowserFrame is an interface to the native Frame component. |
| 86 | private BrowserFrame mBrowserFrame; |
Andrei Popescu | 4950b2b | 2009-09-03 13:56:07 +0100 | [diff] [blame] | 87 | // Custom JS interfaces to add during the initialization. |
| 88 | private Map<String, Object> mJavascriptInterfaces; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | /* |
| 90 | * range is from 200 to 10,000. 0 is a special value means device-width. -1 |
| 91 | * means undefined. |
| 92 | */ |
| 93 | private int mViewportWidth = -1; |
| 94 | |
| 95 | /* |
| 96 | * range is from 200 to 10,000. 0 is a special value means device-height. -1 |
| 97 | * means undefined. |
| 98 | */ |
| 99 | private int mViewportHeight = -1; |
| 100 | |
| 101 | /* |
| 102 | * scale in percent, range is from 1 to 1000. 0 means undefined. |
| 103 | */ |
| 104 | private int mViewportInitialScale = 0; |
| 105 | |
| 106 | /* |
| 107 | * scale in percent, range is from 1 to 1000. 0 means undefined. |
| 108 | */ |
| 109 | private int mViewportMinimumScale = 0; |
| 110 | |
| 111 | /* |
| 112 | * scale in percent, range is from 1 to 1000. 0 means undefined. |
| 113 | */ |
| 114 | private int mViewportMaximumScale = 0; |
| 115 | |
| 116 | private boolean mViewportUserScalable = true; |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 117 | |
Grace Kloba | 408cf85 | 2009-09-20 16:34:44 -0700 | [diff] [blame] | 118 | /* |
| 119 | * range is from 70 to 400. |
| 120 | * 0 is a special value means device-dpi. The default scale factor will be |
| 121 | * always 100. |
| 122 | * -1 means undefined. The default scale factor will be |
| 123 | * WebView.DEFAULT_SCALE_PERCENT. |
| 124 | */ |
| 125 | private int mViewportDensityDpi = -1; |
| 126 | |
Mangesh Ghiware | f0e96d5 | 2011-10-26 17:23:54 -0700 | [diff] [blame] | 127 | private boolean mIsRestored = false; |
Shimeng (Simon) Wang | 5d8e7a4 | 2011-01-07 15:51:06 -0800 | [diff] [blame] | 128 | private float mRestoredScale = 0; |
| 129 | private float mRestoredTextWrapScale = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | private int mRestoredX = 0; |
| 131 | private int mRestoredY = 0; |
| 132 | |
Steve Block | 1be7339 | 2010-10-15 16:31:01 +0100 | [diff] [blame] | 133 | private DeviceMotionAndOrientationManager mDeviceMotionAndOrientationManager = |
| 134 | new DeviceMotionAndOrientationManager(this); |
Steve Block | dc82a29 | 2010-10-06 14:34:15 +0100 | [diff] [blame] | 135 | private DeviceMotionService mDeviceMotionService; |
Steve Block | c43565b | 2010-08-11 13:12:37 +0100 | [diff] [blame] | 136 | private DeviceOrientationService mDeviceOrientationService; |
Steve Block | f4a705f | 2010-08-11 13:08:24 +0100 | [diff] [blame] | 137 | |
Ben Murdoch | f7093be | 2010-11-01 10:27:33 +0000 | [diff] [blame] | 138 | private int mLowMemoryUsageThresholdMb; |
| 139 | private int mHighMemoryUsageThresholdMb; |
Shimeng (Simon) Wang | 7c1bcfd | 2011-01-24 14:38:46 -0800 | [diff] [blame] | 140 | private int mHighUsageDeltaMb; |
Ben Murdoch | f7093be | 2010-11-01 10:27:33 +0000 | [diff] [blame] | 141 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | // The thread name used to identify the WebCore thread and for use in |
| 143 | // debugging other classes that require operation within the WebCore thread. |
| 144 | /* package */ static final String THREAD_NAME = "WebViewCoreThread"; |
| 145 | |
Andrei Popescu | 4950b2b | 2009-09-03 13:56:07 +0100 | [diff] [blame] | 146 | public WebViewCore(Context context, WebView w, CallbackProxy proxy, |
| 147 | Map<String, Object> javascriptInterfaces) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | // No need to assign this in the WebCore thread. |
| 149 | mCallbackProxy = proxy; |
| 150 | mWebView = w; |
Andrei Popescu | 4950b2b | 2009-09-03 13:56:07 +0100 | [diff] [blame] | 151 | mJavascriptInterfaces = javascriptInterfaces; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 152 | // This context object is used to initialize the WebViewCore during |
| 153 | // subwindow creation. |
| 154 | mContext = context; |
| 155 | |
| 156 | // We need to wait for the initial thread creation before sending |
| 157 | // a message to the WebCore thread. |
| 158 | // XXX: This is the only time the UI thread will wait for the WebCore |
| 159 | // thread! |
| 160 | synchronized (WebViewCore.class) { |
| 161 | if (sWebCoreHandler == null) { |
| 162 | // Create a global thread and start it. |
| 163 | Thread t = new Thread(new WebCoreThread()); |
| 164 | t.setName(THREAD_NAME); |
| 165 | t.start(); |
| 166 | try { |
| 167 | WebViewCore.class.wait(); |
| 168 | } catch (InterruptedException e) { |
| 169 | Log.e(LOGTAG, "Caught exception while waiting for thread " + |
| 170 | "creation."); |
| 171 | Log.e(LOGTAG, Log.getStackTraceString(e)); |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | // Create an EventHub to handle messages before and after the thread is |
| 176 | // ready. |
| 177 | mEventHub = new EventHub(); |
| 178 | // Create a WebSettings object for maintaining all settings |
Grace Kloba | 0d8b77c | 2009-06-25 11:20:51 -0700 | [diff] [blame] | 179 | mSettings = new WebSettings(mContext, mWebView); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 180 | // The WebIconDatabase needs to be initialized within the UI thread so |
| 181 | // just request the instance here. |
| 182 | WebIconDatabase.getInstance(); |
Nicolas Roard | 6c24b4d | 2009-09-22 18:44:52 +0100 | [diff] [blame] | 183 | // Create the WebStorage singleton and the UI handler |
| 184 | WebStorage.getInstance().createUIHandler(); |
| 185 | // Create the UI handler for GeolocationPermissions |
| 186 | GeolocationPermissions.getInstance().createUIHandler(); |
Ben Murdoch | f7093be | 2010-11-01 10:27:33 +0000 | [diff] [blame] | 187 | |
| 188 | // Get the memory class of the current device. V8 will use these values |
| 189 | // to GC more effectively. |
| 190 | ActivityManager manager = (ActivityManager) mContext.getSystemService( |
| 191 | Context.ACTIVITY_SERVICE); |
| 192 | ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo(); |
| 193 | manager.getMemoryInfo(memInfo); |
| 194 | |
| 195 | // Allow us to use up to our memory class value before V8's GC kicks in. |
| 196 | // These values have been determined by experimentation. |
Shimeng (Simon) Wang | 7c1bcfd | 2011-01-24 14:38:46 -0800 | [diff] [blame] | 197 | mLowMemoryUsageThresholdMb = manager.getLargeMemoryClass(); |
Shimeng (Simon) Wang | 7114f3b | 2011-01-26 10:34:26 -0800 | [diff] [blame] | 198 | mHighMemoryUsageThresholdMb = (int) (mLowMemoryUsageThresholdMb * 1.5); |
Shimeng (Simon) Wang | 7c1bcfd | 2011-01-24 14:38:46 -0800 | [diff] [blame] | 199 | // Avoid constant V8 GC when memory usage equals to working set estimate. |
Shimeng (Simon) Wang | 7114f3b | 2011-01-26 10:34:26 -0800 | [diff] [blame] | 200 | mHighUsageDeltaMb = mLowMemoryUsageThresholdMb / 32; |
Ben Murdoch | f7093be | 2010-11-01 10:27:33 +0000 | [diff] [blame] | 201 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 202 | // Send a message to initialize the WebViewCore. |
| 203 | Message init = sWebCoreHandler.obtainMessage( |
| 204 | WebCoreThread.INITIALIZE, this); |
| 205 | sWebCoreHandler.sendMessage(init); |
| 206 | } |
| 207 | |
| 208 | /* Initialize private data within the WebCore thread. |
| 209 | */ |
| 210 | private void initialize() { |
| 211 | /* Initialize our private BrowserFrame class to handle all |
| 212 | * frame-related functions. We need to create a new view which |
| 213 | * in turn creates a C level FrameView and attaches it to the frame. |
| 214 | */ |
| 215 | mBrowserFrame = new BrowserFrame(mContext, this, mCallbackProxy, |
Andrei Popescu | 4950b2b | 2009-09-03 13:56:07 +0100 | [diff] [blame] | 216 | mSettings, mJavascriptInterfaces); |
| 217 | mJavascriptInterfaces = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 218 | // Sync the native settings and also create the WebCore thread handler. |
| 219 | mSettings.syncSettingsAndCreateHandler(mBrowserFrame); |
| 220 | // Create the handler and transfer messages for the IconDatabase |
| 221 | WebIconDatabase.getInstance().createHandler(); |
Nicolas Roard | 11e8fe5 | 2009-05-11 15:04:16 +0100 | [diff] [blame] | 222 | // Create the handler for WebStorage |
| 223 | WebStorage.getInstance().createHandler(); |
Steve Block | 0ac031b | 2009-07-28 11:53:20 +0100 | [diff] [blame] | 224 | // Create the handler for GeolocationPermissions. |
| 225 | GeolocationPermissions.getInstance().createHandler(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 226 | // The transferMessages call will transfer all pending messages to the |
| 227 | // WebCore thread handler. |
| 228 | mEventHub.transferMessages(); |
| 229 | |
| 230 | // Send a message back to WebView to tell it that we have set up the |
| 231 | // WebCore thread. |
| 232 | if (mWebView != null) { |
| 233 | Message.obtain(mWebView.mPrivateHandler, |
| 234 | WebView.WEBCORE_INITIALIZED_MSG_ID, |
| 235 | mNativeClass, 0).sendToTarget(); |
| 236 | } |
| 237 | |
| 238 | } |
| 239 | |
| 240 | /* Handle the initialization of WebViewCore during subwindow creation. This |
| 241 | * method is called from the WebCore thread but it is called before the |
| 242 | * INITIALIZE message can be handled. |
| 243 | */ |
| 244 | /* package */ void initializeSubwindow() { |
| 245 | // Go ahead and initialize the core components. |
| 246 | initialize(); |
| 247 | // Remove the INITIALIZE method so we don't try to initialize twice. |
| 248 | sWebCoreHandler.removeMessages(WebCoreThread.INITIALIZE, this); |
| 249 | } |
| 250 | |
| 251 | /* Get the BrowserFrame component. This is used for subwindow creation and |
| 252 | * is called only from BrowserFrame in the WebCore thread. */ |
Mathew Inwood | e7821cd | 2011-07-08 17:26:46 +0100 | [diff] [blame] | 253 | /* package */ synchronized BrowserFrame getBrowserFrame() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 254 | return mBrowserFrame; |
| 255 | } |
| 256 | |
| 257 | //------------------------------------------------------------------------- |
| 258 | // Common methods |
| 259 | //------------------------------------------------------------------------- |
| 260 | |
| 261 | /** |
| 262 | * Causes all timers to pause. This applies to all WebViews in the current |
| 263 | * app process. |
| 264 | */ |
| 265 | public static void pauseTimers() { |
| 266 | if (BrowserFrame.sJavaBridge == null) { |
| 267 | throw new IllegalStateException( |
| 268 | "No WebView has been created in this process!"); |
| 269 | } |
| 270 | BrowserFrame.sJavaBridge.pause(); |
| 271 | } |
| 272 | |
| 273 | /** |
| 274 | * Resume all timers. This applies to all WebViews in the current process. |
| 275 | */ |
| 276 | public static void resumeTimers() { |
| 277 | if (BrowserFrame.sJavaBridge == null) { |
| 278 | throw new IllegalStateException( |
| 279 | "No WebView has been created in this process!"); |
| 280 | } |
| 281 | BrowserFrame.sJavaBridge.resume(); |
| 282 | } |
| 283 | |
| 284 | public WebSettings getSettings() { |
| 285 | return mSettings; |
| 286 | } |
| 287 | |
Shimeng (Simon) Wang | bf01312 | 2010-10-05 16:59:05 -0700 | [diff] [blame] | 288 | /* |
| 289 | * Given mimeType, check whether it's supported in Android media framework. |
| 290 | * mimeType could be such as "audio/ogg" and "video/mp4". |
| 291 | */ |
Iain Merrick | 4e7665d | 2010-10-27 10:15:14 +0100 | [diff] [blame] | 292 | /* package */ static boolean isSupportedMediaMimeType(String mimeType) { |
| 293 | int fileType = MediaFile.getFileTypeForMimeType(mimeType); |
Andreas Huber | 5dffd0e | 2010-11-15 08:54:40 -0800 | [diff] [blame] | 294 | return MediaFile.isAudioFileType(fileType) |
| 295 | || MediaFile.isVideoFileType(fileType) |
Shimeng (Simon) Wang | b394d9a | 2010-11-17 17:55:06 -0800 | [diff] [blame] | 296 | || MediaFile.isPlayListFileType(fileType) |
| 297 | // The following is not in Media framework, but it's supported. |
| 298 | || (mimeType != null && mimeType.startsWith("video/m4v")); |
Shimeng (Simon) Wang | bf01312 | 2010-10-05 16:59:05 -0700 | [diff] [blame] | 299 | } |
Iain Merrick | 4e7665d | 2010-10-27 10:15:14 +0100 | [diff] [blame] | 300 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 301 | /** |
Ben Murdoch | 6262ae5 | 2009-04-17 13:21:53 +0100 | [diff] [blame] | 302 | * Add an error message to the client's console. |
| 303 | * @param message The message to add |
| 304 | * @param lineNumber the line on which the error occurred |
| 305 | * @param sourceID the filename of the source that caused the error. |
Ben Murdoch | 3141e0a | 2010-01-28 15:06:32 +0000 | [diff] [blame] | 306 | * @param msgLevel the log level of this message. This is a value casted to int |
| 307 | * from WebCore::MessageLevel in WebCore/page/Console.h. |
Ben Murdoch | 6262ae5 | 2009-04-17 13:21:53 +0100 | [diff] [blame] | 308 | */ |
Ben Murdoch | 3141e0a | 2010-01-28 15:06:32 +0000 | [diff] [blame] | 309 | protected void addMessageToConsole(String message, int lineNumber, String sourceID, |
| 310 | int msgLevel) { |
| 311 | mCallbackProxy.addMessageToConsole(message, lineNumber, sourceID, msgLevel); |
Ben Murdoch | 6262ae5 | 2009-04-17 13:21:53 +0100 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 315 | * Invoke a javascript alert. |
| 316 | * @param message The message displayed in the alert. |
| 317 | */ |
| 318 | protected void jsAlert(String url, String message) { |
| 319 | mCallbackProxy.onJsAlert(url, message); |
| 320 | } |
| 321 | |
Leon Scroggins | f2e17a8 | 2010-09-24 15:58:50 -0400 | [diff] [blame] | 322 | /** |
| 323 | * Called by JNI. Send a message to the UI thread to hide the soft keyboard |
| 324 | * if the node pointed to by nodePointer is still in focus. |
| 325 | * @param nodePointer The node which just blurred. |
| 326 | */ |
| 327 | private void formDidBlur(int nodePointer) { |
| 328 | if (mWebView == null) return; |
| 329 | Message.obtain(mWebView.mPrivateHandler, WebView.FORM_DID_BLUR, |
| 330 | nodePointer, 0).sendToTarget(); |
| 331 | } |
Leon Scroggins | 70ca3c2 | 2009-10-02 15:58:55 -0400 | [diff] [blame] | 332 | |
| 333 | /** |
| 334 | * Called by JNI. Open a file chooser to upload a file. |
Ben Murdoch | 4ae32f5 | 2010-05-18 14:30:39 +0100 | [diff] [blame] | 335 | * @param acceptType The value of the 'accept' attribute of the |
| 336 | * input tag associated with this file picker. |
Ben Murdoch | cc749de | 2010-05-18 12:37:00 +0100 | [diff] [blame] | 337 | * @return String version of the URI. |
Leon Scroggins | 70ca3c2 | 2009-10-02 15:58:55 -0400 | [diff] [blame] | 338 | */ |
Ben Murdoch | 4ae32f5 | 2010-05-18 14:30:39 +0100 | [diff] [blame] | 339 | private String openFileChooser(String acceptType) { |
| 340 | Uri uri = mCallbackProxy.openFileChooser(acceptType); |
Ben Murdoch | cc749de | 2010-05-18 12:37:00 +0100 | [diff] [blame] | 341 | if (uri != null) { |
Ben Murdoch | 65b4cda | 2010-05-28 11:07:15 +0100 | [diff] [blame] | 342 | String filePath = ""; |
| 343 | // Note - querying for MediaStore.Images.Media.DATA |
| 344 | // seems to work for all content URIs, not just images |
Ben Murdoch | cc749de | 2010-05-18 12:37:00 +0100 | [diff] [blame] | 345 | Cursor cursor = mContext.getContentResolver().query( |
| 346 | uri, |
Ben Murdoch | 65b4cda | 2010-05-28 11:07:15 +0100 | [diff] [blame] | 347 | new String[] { MediaStore.Images.Media.DATA }, |
Ben Murdoch | cc749de | 2010-05-18 12:37:00 +0100 | [diff] [blame] | 348 | null, null, null); |
| 349 | if (cursor != null) { |
| 350 | try { |
| 351 | if (cursor.moveToNext()) { |
Ben Murdoch | 65b4cda | 2010-05-28 11:07:15 +0100 | [diff] [blame] | 352 | filePath = cursor.getString(0); |
Ben Murdoch | cc749de | 2010-05-18 12:37:00 +0100 | [diff] [blame] | 353 | } |
| 354 | } finally { |
| 355 | cursor.close(); |
Leon Scroggins | 70ca3c2 | 2009-10-02 15:58:55 -0400 | [diff] [blame] | 356 | } |
Ben Murdoch | cc749de | 2010-05-18 12:37:00 +0100 | [diff] [blame] | 357 | } else { |
Ben Murdoch | 65b4cda | 2010-05-28 11:07:15 +0100 | [diff] [blame] | 358 | filePath = uri.getLastPathSegment(); |
Leon Scroggins | 70ca3c2 | 2009-10-02 15:58:55 -0400 | [diff] [blame] | 359 | } |
Ben Murdoch | cc749de | 2010-05-18 12:37:00 +0100 | [diff] [blame] | 360 | String uriString = uri.toString(); |
Ben Murdoch | 65b4cda | 2010-05-28 11:07:15 +0100 | [diff] [blame] | 361 | BrowserFrame.sJavaBridge.storeFilePathForContentUri(filePath, uriString); |
Ben Murdoch | cc749de | 2010-05-18 12:37:00 +0100 | [diff] [blame] | 362 | return uriString; |
Leon Scroggins | 70ca3c2 | 2009-10-02 15:58:55 -0400 | [diff] [blame] | 363 | } |
Ben Murdoch | cc749de | 2010-05-18 12:37:00 +0100 | [diff] [blame] | 364 | return ""; |
Leon Scroggins | 70ca3c2 | 2009-10-02 15:58:55 -0400 | [diff] [blame] | 365 | } |
| 366 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 367 | /** |
Andrei Popescu | 59e2ad9 | 2009-07-28 13:38:06 +0100 | [diff] [blame] | 368 | * Notify the browser that the origin has exceeded it's database quota. |
Ben Murdoch | 7df1985 | 2009-04-22 13:07:58 +0100 | [diff] [blame] | 369 | * @param url The URL that caused the overflow. |
| 370 | * @param databaseIdentifier The identifier of the database. |
| 371 | * @param currentQuota The current quota for the origin. |
Ben Murdoch | d497d87 | 2009-08-25 19:32:54 +0100 | [diff] [blame] | 372 | * @param estimatedSize The estimated size of the database. |
Ben Murdoch | 7df1985 | 2009-04-22 13:07:58 +0100 | [diff] [blame] | 373 | */ |
| 374 | protected void exceededDatabaseQuota(String url, |
| 375 | String databaseIdentifier, |
Ben Murdoch | d497d87 | 2009-08-25 19:32:54 +0100 | [diff] [blame] | 376 | long currentQuota, |
| 377 | long estimatedSize) { |
Ben Murdoch | 7df1985 | 2009-04-22 13:07:58 +0100 | [diff] [blame] | 378 | // Inform the callback proxy of the quota overflow. Send an object |
| 379 | // that encapsulates a call to the nativeSetDatabaseQuota method to |
| 380 | // awaken the sleeping webcore thread when a decision from the |
| 381 | // client to allow or deny quota is available. |
| 382 | mCallbackProxy.onExceededDatabaseQuota(url, databaseIdentifier, |
Ben Murdoch | d497d87 | 2009-08-25 19:32:54 +0100 | [diff] [blame] | 383 | currentQuota, estimatedSize, getUsedQuota(), |
| 384 | new WebStorage.QuotaUpdater() { |
| 385 | public void updateQuota(long quota) { |
| 386 | nativeSetNewStorageLimit(quota); |
| 387 | } |
| 388 | }); |
Ben Murdoch | 7df1985 | 2009-04-22 13:07:58 +0100 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | /** |
Andrei Popescu | 59e2ad9 | 2009-07-28 13:38:06 +0100 | [diff] [blame] | 392 | * Notify the browser that the appcache has exceeded its max size. |
| 393 | * @param spaceNeeded is the amount of disk space that would be needed |
| 394 | * in order for the last appcache operation to succeed. |
| 395 | */ |
| 396 | protected void reachedMaxAppCacheSize(long spaceNeeded) { |
| 397 | mCallbackProxy.onReachedMaxAppCacheSize(spaceNeeded, getUsedQuota(), |
| 398 | new WebStorage.QuotaUpdater() { |
| 399 | public void updateQuota(long quota) { |
| 400 | nativeSetNewStorageLimit(quota); |
| 401 | } |
| 402 | }); |
| 403 | } |
| 404 | |
Leon Clarke | 194e345 | 2009-09-28 11:42:12 +0100 | [diff] [blame] | 405 | protected void populateVisitedLinks() { |
| 406 | ValueCallback callback = new ValueCallback<String[]>() { |
| 407 | public void onReceiveValue(String[] value) { |
| 408 | sendMessage(EventHub.POPULATE_VISITED_LINKS, (Object)value); |
| 409 | } |
| 410 | }; |
| 411 | mCallbackProxy.getVisitedHistory(callback); |
Leon Clarke | 9c8d886 | 2009-09-24 15:20:10 +0100 | [diff] [blame] | 412 | } |
| 413 | |
Andrei Popescu | 59e2ad9 | 2009-07-28 13:38:06 +0100 | [diff] [blame] | 414 | /** |
Steve Block | 4faee09 | 2009-07-28 18:20:50 +0100 | [diff] [blame] | 415 | * Shows a prompt to ask the user to set the Geolocation permission state |
| 416 | * for the given origin. |
| 417 | * @param origin The origin for which Geolocation permissions are |
| 418 | * requested. |
| 419 | */ |
| 420 | protected void geolocationPermissionsShowPrompt(String origin) { |
| 421 | mCallbackProxy.onGeolocationPermissionsShowPrompt(origin, |
| 422 | new GeolocationPermissions.Callback() { |
| 423 | public void invoke(String origin, boolean allow, boolean remember) { |
| 424 | GeolocationPermissionsData data = new GeolocationPermissionsData(); |
| 425 | data.mOrigin = origin; |
| 426 | data.mAllow = allow; |
| 427 | data.mRemember = remember; |
| 428 | // Marshall to WebCore thread. |
| 429 | sendMessage(EventHub.GEOLOCATION_PERMISSIONS_PROVIDE, data); |
| 430 | } |
| 431 | }); |
| 432 | } |
| 433 | |
| 434 | /** |
| 435 | * Hides the Geolocation permissions prompt. |
| 436 | */ |
| 437 | protected void geolocationPermissionsHidePrompt() { |
| 438 | mCallbackProxy.onGeolocationPermissionsHidePrompt(); |
| 439 | } |
| 440 | |
| 441 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 442 | * Invoke a javascript confirm dialog. |
| 443 | * @param message The message displayed in the dialog. |
| 444 | * @return True if the user confirmed or false if the user cancelled. |
| 445 | */ |
| 446 | protected boolean jsConfirm(String url, String message) { |
| 447 | return mCallbackProxy.onJsConfirm(url, message); |
| 448 | } |
| 449 | |
| 450 | /** |
| 451 | * Invoke a javascript prompt dialog. |
| 452 | * @param message The message to be displayed in the dialog. |
| 453 | * @param defaultValue The default value in the prompt input. |
| 454 | * @return The input from the user or null to indicate the user cancelled |
| 455 | * the dialog. |
| 456 | */ |
| 457 | protected String jsPrompt(String url, String message, String defaultValue) { |
| 458 | return mCallbackProxy.onJsPrompt(url, message, defaultValue); |
| 459 | } |
| 460 | |
| 461 | /** |
| 462 | * Invoke a javascript before unload dialog. |
| 463 | * @param url The url that is requesting the dialog. |
| 464 | * @param message The message displayed in the dialog. |
| 465 | * @return True if the user confirmed or false if the user cancelled. False |
| 466 | * will cancel the navigation. |
| 467 | */ |
| 468 | protected boolean jsUnload(String url, String message) { |
| 469 | return mCallbackProxy.onJsBeforeUnload(url, message); |
| 470 | } |
| 471 | |
Guang Zhu | 81e4143 | 2009-05-08 16:09:55 -0700 | [diff] [blame] | 472 | /** |
| 473 | * |
| 474 | * Callback to notify that a JavaScript execution timeout has occured. |
| 475 | * @return True if the JavaScript execution should be interrupted. False |
| 476 | * will continue the execution. |
| 477 | */ |
| 478 | protected boolean jsInterrupt() { |
| 479 | return mCallbackProxy.onJsTimeout(); |
| 480 | } |
| 481 | |
Ben Murdoch | 6312de2 | 2010-06-29 19:20:11 +0100 | [diff] [blame] | 482 | /** |
| 483 | * Notify the webview that this is an installable web app. |
| 484 | */ |
| 485 | protected void setInstallableWebApp() { |
| 486 | mCallbackProxy.setInstallableWebApp(); |
| 487 | } |
| 488 | |
Nicolas Roard | 0e778a1 | 2011-03-11 14:29:05 -0800 | [diff] [blame] | 489 | /** |
| 490 | * Notify the webview that we want to display the video layer fullscreen. |
| 491 | */ |
Teng-Hui Zhu | 10ab654 | 2011-03-16 16:42:32 -0700 | [diff] [blame] | 492 | protected void enterFullscreenForVideoLayer(int layerId, String url) { |
Nicolas Roard | 0e778a1 | 2011-03-11 14:29:05 -0800 | [diff] [blame] | 493 | if (mWebView == null) return; |
Teng-Hui Zhu | 10ab654 | 2011-03-16 16:42:32 -0700 | [diff] [blame] | 494 | Message message = Message.obtain(mWebView.mPrivateHandler, |
| 495 | WebView.ENTER_FULLSCREEN_VIDEO, layerId, 0); |
| 496 | message.obj = url; |
| 497 | message.sendToTarget(); |
Nicolas Roard | 0e778a1 | 2011-03-11 14:29:05 -0800 | [diff] [blame] | 498 | } |
| 499 | |
Ben Murdoch | a62b963 | 2011-12-05 14:51:00 +0000 | [diff] [blame] | 500 | /** |
| 501 | * Clear the picture set. To be called only on the WebCore thread. |
| 502 | */ |
| 503 | /* package */ void clearContent() { |
| 504 | nativeClearContent(); |
| 505 | } |
| 506 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 507 | //------------------------------------------------------------------------- |
| 508 | // JNI methods |
| 509 | //------------------------------------------------------------------------- |
| 510 | |
Cary Clark | 3e399de | 2009-06-17 10:00:57 -0400 | [diff] [blame] | 511 | static native String nativeFindAddress(String addr, boolean caseInsensitive); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 512 | |
| 513 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 514 | * Empty the picture set. |
| 515 | */ |
| 516 | private native void nativeClearContent(); |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 517 | |
Cary Clark | 75796bb | 2010-08-24 14:59:58 -0400 | [diff] [blame] | 518 | private native void nativeContentInvalidateAll(); |
| 519 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 520 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 521 | * Redraw a portion of the picture set. The Point wh returns the |
| 522 | * width and height of the overall picture. |
| 523 | */ |
Grace Kloba | 8abd50b | 2010-07-08 15:02:14 -0700 | [diff] [blame] | 524 | private native int nativeRecordContent(Region invalRegion, Point wh); |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 525 | |
Nicolas Roard | fb7bc34 | 2010-11-01 15:08:03 -0700 | [diff] [blame] | 526 | /** |
| 527 | * Update the layers' content |
| 528 | */ |
Chris Craik | d0051c0 | 2011-11-29 10:26:10 -0800 | [diff] [blame] | 529 | private native boolean nativeUpdateLayers(int nativeClass, int baseLayer); |
| 530 | |
| 531 | /** |
| 532 | * Notify webkit that animations have begun (on the hardware accelerated content) |
| 533 | */ |
| 534 | private native void nativeNotifyAnimationStarted(int nativeClass); |
Nicolas Roard | fb7bc34 | 2010-11-01 15:08:03 -0700 | [diff] [blame] | 535 | |
Cary Clark | 5da9aeb | 2009-10-06 17:40:53 -0400 | [diff] [blame] | 536 | private native boolean nativeFocusBoundsChanged(); |
| 537 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 538 | /** |
Grace Kloba | 8abd50b | 2010-07-08 15:02:14 -0700 | [diff] [blame] | 539 | * Splits slow parts of the picture set. Called from the webkit thread after |
| 540 | * WebView.nativeDraw() returns content to be split. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 541 | */ |
Grace Kloba | 8abd50b | 2010-07-08 15:02:14 -0700 | [diff] [blame] | 542 | private native void nativeSplitContent(int content); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 543 | |
| 544 | private native boolean nativeKey(int keyCode, int unichar, |
Cary Clark | 215b72c | 2009-06-26 14:38:43 -0400 | [diff] [blame] | 545 | int repeatCount, boolean isShift, boolean isAlt, boolean isSym, |
| 546 | boolean isDown); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 547 | |
Leon Scroggins | b45a263 | 2011-01-12 14:11:24 -0500 | [diff] [blame] | 548 | private native void nativeClick(int framePtr, int nodePtr, boolean fake); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 549 | |
| 550 | private native void nativeSendListBoxChoices(boolean[] choices, int size); |
| 551 | |
| 552 | private native void nativeSendListBoxChoice(int choice); |
| 553 | |
Kristian Monsen | 64decc6 | 2011-08-25 20:32:24 +0100 | [diff] [blame] | 554 | private native void nativeCloseIdleConnections(); |
| 555 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 556 | /* Tell webkit what its width and height are, for the purposes |
| 557 | of layout/line-breaking. These coordinates are in document space, |
| 558 | which is the same as View coords unless we have zoomed the document |
| 559 | (see nativeSetZoom). |
Grace Kloba | e80cbcc | 2010-05-28 18:07:50 -0700 | [diff] [blame] | 560 | textWrapWidth is used by layout to wrap column around. If viewport uses |
| 561 | fixed size, textWrapWidth can be different from width with zooming. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 562 | should this be called nativeSetViewPortSize? |
| 563 | */ |
Grace Kloba | e80cbcc | 2010-05-28 18:07:50 -0700 | [diff] [blame] | 564 | private native void nativeSetSize(int width, int height, int textWrapWidth, |
| 565 | float scale, int screenWidth, int screenHeight, int anchorX, |
Grace Kloba | 3a0def2 | 2010-01-23 21:11:54 -0800 | [diff] [blame] | 566 | int anchorY, boolean ignoreHeight); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 567 | |
| 568 | private native int nativeGetContentMinPrefWidth(); |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 569 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 570 | // Start: functions that deal with text editing |
Cary Clark | 2f1d60c | 2009-06-03 08:05:53 -0400 | [diff] [blame] | 571 | private native void nativeReplaceTextfieldText( |
Leon Scroggins | 43488fc | 2009-07-06 14:32:49 -0400 | [diff] [blame] | 572 | int oldStart, int oldEnd, String replace, int newStart, int newEnd, |
| 573 | int textGeneration); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 574 | |
Cary Clark | 2f1d60c | 2009-06-03 08:05:53 -0400 | [diff] [blame] | 575 | private native void passToJs(int gen, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 576 | String currentText, int keyCode, int keyValue, boolean down, |
| 577 | boolean cap, boolean fn, boolean sym); |
| 578 | |
Leon Scroggins | 8cdad88 | 2009-06-30 08:47:04 -0400 | [diff] [blame] | 579 | private native void nativeSetFocusControllerActive(boolean active); |
Leon Scroggins | 63dda1c | 2009-04-15 13:25:00 -0400 | [diff] [blame] | 580 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 581 | private native void nativeSaveDocumentState(int frame); |
| 582 | |
Leon Scroggins | 47fabbf | 2009-12-08 16:57:26 -0500 | [diff] [blame] | 583 | private native void nativeMoveFocus(int framePtr, int nodePointer); |
Cary Clark | ed56eda | 2009-06-18 09:48:47 -0400 | [diff] [blame] | 584 | private native void nativeMoveMouse(int framePtr, int x, int y); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 585 | |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 586 | private native void nativeMoveMouseIfLatest(int moveGeneration, |
Cary Clark | ed56eda | 2009-06-18 09:48:47 -0400 | [diff] [blame] | 587 | int framePtr, int x, int y); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 588 | |
Cary Clark | e41bb53 | 2010-11-30 15:59:59 -0500 | [diff] [blame] | 589 | private native String nativeRetrieveHref(int x, int y); |
| 590 | private native String nativeRetrieveAnchorText(int x, int y); |
Cary Clark | 861368a | 2010-12-15 11:24:37 -0500 | [diff] [blame] | 591 | private native String nativeRetrieveImageSource(int x, int y); |
Leon Scroggins | b611213 | 2011-02-24 12:35:50 -0500 | [diff] [blame] | 592 | private native void nativeStopPaintingCaret(); |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 593 | private native void nativeTouchUp(int touchGeneration, |
Leon Scroggins | 22e883d | 2011-01-31 10:54:19 -0500 | [diff] [blame] | 594 | int framePtr, int nodePtr, int x, int y); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 595 | |
Huahui Wu | e838a42 | 2011-01-13 16:03:43 -0800 | [diff] [blame] | 596 | private native boolean nativeHandleTouchEvent(int action, int[] idArray, |
Huahui Wu | 2d3ef37 | 2011-03-13 18:13:42 -0700 | [diff] [blame] | 597 | int[] xArray, int[] yArray, int count, int actionIndex, int metaState); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 598 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 599 | private native void nativeUpdateFrameCache(); |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 600 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 601 | private native void nativeSetBackgroundColor(int color); |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 602 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 603 | private native void nativeDumpDomTree(boolean useFile); |
| 604 | |
| 605 | private native void nativeDumpRenderTree(boolean useFile); |
| 606 | |
| 607 | private native void nativeDumpNavTree(); |
| 608 | |
Feng Qian | b308137 | 2009-06-29 15:55:18 -0700 | [diff] [blame] | 609 | private native void nativeSetJsFlags(String flags); |
| 610 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 611 | /** |
| 612 | * Delete text from start to end in the focused textfield. If there is no |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 613 | * focus, or if start == end, silently fail. If start and end are out of |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 614 | * order, swap them. |
| 615 | * @param start Beginning of selection to delete. |
| 616 | * @param end End of selection to delete. |
Leon Scroggins | 43488fc | 2009-07-06 14:32:49 -0400 | [diff] [blame] | 617 | * @param textGeneration Text generation number when delete was pressed. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 618 | */ |
Leon Scroggins | 43488fc | 2009-07-06 14:32:49 -0400 | [diff] [blame] | 619 | private native void nativeDeleteSelection(int start, int end, |
| 620 | int textGeneration); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 621 | |
| 622 | /** |
| 623 | * Set the selection to (start, end) in the focused textfield. If start and |
| 624 | * end are out of order, swap them. |
| 625 | * @param start Beginning of selection. |
| 626 | * @param end End of selection. |
| 627 | */ |
Cary Clark | 2f1d60c | 2009-06-03 08:05:53 -0400 | [diff] [blame] | 628 | private native void nativeSetSelection(int start, int end); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 629 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 630 | // Register a scheme to be treated as local scheme so that it can access |
| 631 | // local asset files for resources |
| 632 | private native void nativeRegisterURLSchemeAsLocal(String scheme); |
| 633 | |
Ben Murdoch | 7df1985 | 2009-04-22 13:07:58 +0100 | [diff] [blame] | 634 | /* |
| 635 | * Inform webcore that the user has decided whether to allow or deny new |
Andrei Popescu | 59e2ad9 | 2009-07-28 13:38:06 +0100 | [diff] [blame] | 636 | * quota for the current origin or more space for the app cache, and that |
| 637 | * the main thread should wake up now. |
| 638 | * @param limit Is the new quota for an origin or new app cache max size. |
Ben Murdoch | 7df1985 | 2009-04-22 13:07:58 +0100 | [diff] [blame] | 639 | */ |
Andrei Popescu | 59e2ad9 | 2009-07-28 13:38:06 +0100 | [diff] [blame] | 640 | private native void nativeSetNewStorageLimit(long limit); |
Ben Murdoch | 7df1985 | 2009-04-22 13:07:58 +0100 | [diff] [blame] | 641 | |
Steve Block | 4faee09 | 2009-07-28 18:20:50 +0100 | [diff] [blame] | 642 | /** |
| 643 | * Provide WebCore with a Geolocation permission state for the specified |
| 644 | * origin. |
| 645 | * @param origin The origin for which Geolocation permissions are provided. |
| 646 | * @param allow Whether Geolocation permissions are allowed. |
| 647 | * @param remember Whether this decision should be remembered beyond the |
| 648 | * life of the current page. |
| 649 | */ |
| 650 | private native void nativeGeolocationPermissionsProvide(String origin, boolean allow, boolean remember); |
| 651 | |
Leon Clarke | 194e345 | 2009-09-28 11:42:12 +0100 | [diff] [blame] | 652 | /** |
| 653 | * Provide WebCore with the previously visted links from the history database |
| 654 | */ |
Svetoslav Ganov | da35551 | 2010-05-12 22:04:44 -0700 | [diff] [blame] | 655 | private native void nativeProvideVisitedHistory(String[] history); |
| 656 | |
| 657 | /** |
| 658 | * Modifies the current selection. |
| 659 | * |
Svetoslav Ganov | c93fb65 | 2011-01-05 18:52:05 -0800 | [diff] [blame] | 660 | * Note: Accessibility support. |
| 661 | * |
Svetoslav Ganov | da35551 | 2010-05-12 22:04:44 -0700 | [diff] [blame] | 662 | * @param direction The direction in which to alter the selection. |
| 663 | * @param granularity The granularity of the selection modification. |
| 664 | * |
| 665 | * @return The selection string. |
| 666 | */ |
Svetoslav Ganov | 585f13f8d | 2010-08-10 07:59:15 -0700 | [diff] [blame] | 667 | private native String nativeModifySelection(int direction, int granularity); |
Leon Clarke | 194e345 | 2009-09-28 11:42:12 +0100 | [diff] [blame] | 668 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 669 | // EventHub for processing messages |
| 670 | private final EventHub mEventHub; |
| 671 | // WebCore thread handler |
| 672 | private static Handler sWebCoreHandler; |
| 673 | // Class for providing Handler creation inside the WebCore thread. |
| 674 | private static class WebCoreThread implements Runnable { |
| 675 | // Message id for initializing a new WebViewCore. |
| 676 | private static final int INITIALIZE = 0; |
| 677 | private static final int REDUCE_PRIORITY = 1; |
| 678 | private static final int RESUME_PRIORITY = 2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 679 | |
| 680 | public void run() { |
| 681 | Looper.prepare(); |
| 682 | Assert.assertNull(sWebCoreHandler); |
| 683 | synchronized (WebViewCore.class) { |
| 684 | sWebCoreHandler = new Handler() { |
| 685 | @Override |
| 686 | public void handleMessage(Message msg) { |
| 687 | switch (msg.what) { |
| 688 | case INITIALIZE: |
| 689 | WebViewCore core = (WebViewCore) msg.obj; |
| 690 | core.initialize(); |
| 691 | break; |
| 692 | |
| 693 | case REDUCE_PRIORITY: |
| 694 | // 3 is an adjustable number. |
| 695 | Process.setThreadPriority( |
| 696 | Process.THREAD_PRIORITY_DEFAULT + 3 * |
| 697 | Process.THREAD_PRIORITY_LESS_FAVORABLE); |
| 698 | break; |
| 699 | |
| 700 | case RESUME_PRIORITY: |
| 701 | Process.setThreadPriority( |
| 702 | Process.THREAD_PRIORITY_DEFAULT); |
| 703 | break; |
Kristian Monsen | 4190aab | 2010-12-16 18:39:21 +0000 | [diff] [blame] | 704 | |
| 705 | case EventHub.ADD_PACKAGE_NAME: |
| 706 | if (BrowserFrame.sJavaBridge == null) { |
| 707 | throw new IllegalStateException( |
| 708 | "No WebView has been created in this process!"); |
| 709 | } |
| 710 | BrowserFrame.sJavaBridge.addPackageName((String) msg.obj); |
| 711 | break; |
| 712 | |
| 713 | case EventHub.REMOVE_PACKAGE_NAME: |
| 714 | if (BrowserFrame.sJavaBridge == null) { |
| 715 | throw new IllegalStateException( |
| 716 | "No WebView has been created in this process!"); |
| 717 | } |
| 718 | BrowserFrame.sJavaBridge.removePackageName((String) msg.obj); |
| 719 | break; |
Kristian Monsen | 41e7e6f | 2010-12-21 12:51:11 +0000 | [diff] [blame] | 720 | |
| 721 | case EventHub.PROXY_CHANGED: |
| 722 | if (BrowserFrame.sJavaBridge == null) { |
| 723 | throw new IllegalStateException( |
| 724 | "No WebView has been created in this process!"); |
| 725 | } |
Kristian Monsen | 2032eee | 2011-05-23 14:25:27 +0100 | [diff] [blame] | 726 | BrowserFrame.sJavaBridge.updateProxy((ProxyProperties)msg.obj); |
Kristian Monsen | 41e7e6f | 2010-12-21 12:51:11 +0000 | [diff] [blame] | 727 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 728 | } |
| 729 | } |
| 730 | }; |
| 731 | WebViewCore.class.notify(); |
| 732 | } |
| 733 | Looper.loop(); |
| 734 | } |
| 735 | } |
| 736 | |
Cary Clark | ded054c | 2009-06-15 10:26:08 -0400 | [diff] [blame] | 737 | static class BaseUrlData { |
| 738 | String mBaseUrl; |
| 739 | String mData; |
| 740 | String mMimeType; |
| 741 | String mEncoding; |
Leon Scroggins | 1bb1a91 | 2010-03-23 15:39:46 -0400 | [diff] [blame] | 742 | String mHistoryUrl; |
Cary Clark | ded054c | 2009-06-15 10:26:08 -0400 | [diff] [blame] | 743 | } |
| 744 | |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 745 | static class CursorData { |
| 746 | CursorData() {} |
| 747 | CursorData(int frame, int node, int x, int y) { |
| 748 | mFrame = frame; |
Leon Scroggins | 47fabbf | 2009-12-08 16:57:26 -0500 | [diff] [blame] | 749 | mNode = node; |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 750 | mX = x; |
| 751 | mY = y; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 752 | } |
| 753 | int mMoveGeneration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 754 | int mFrame; |
Leon Scroggins | 47fabbf | 2009-12-08 16:57:26 -0500 | [diff] [blame] | 755 | int mNode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 756 | int mX; |
| 757 | int mY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 758 | } |
| 759 | |
Cary Clark | ded054c | 2009-06-15 10:26:08 -0400 | [diff] [blame] | 760 | static class JSInterfaceData { |
| 761 | Object mObject; |
| 762 | String mInterfaceName; |
| 763 | } |
| 764 | |
| 765 | static class JSKeyData { |
| 766 | String mCurrentText; |
| 767 | KeyEvent mEvent; |
| 768 | } |
| 769 | |
Cary Clark | 1cb97ee | 2009-12-11 12:10:36 -0500 | [diff] [blame] | 770 | static class MotionUpData { |
| 771 | int mFrame; |
| 772 | int mNode; |
| 773 | Rect mBounds; |
| 774 | int mX; |
| 775 | int mY; |
| 776 | } |
| 777 | |
Grace Kloba | d0d9bc2 | 2010-01-26 18:08:28 -0800 | [diff] [blame] | 778 | static class GetUrlData { |
| 779 | String mUrl; |
| 780 | Map<String, String> mExtraHeaders; |
| 781 | } |
| 782 | |
Cary Clark | ded054c | 2009-06-15 10:26:08 -0400 | [diff] [blame] | 783 | static class PostUrlData { |
| 784 | String mUrl; |
| 785 | byte[] mPostData; |
| 786 | } |
| 787 | |
| 788 | static class ReplaceTextData { |
| 789 | String mReplace; |
| 790 | int mNewStart; |
| 791 | int mNewEnd; |
Leon Scroggins | 43488fc | 2009-07-06 14:32:49 -0400 | [diff] [blame] | 792 | int mTextGeneration; |
Cary Clark | ded054c | 2009-06-15 10:26:08 -0400 | [diff] [blame] | 793 | } |
| 794 | |
Leon Scroggins | 6679f2f | 2009-08-12 18:48:10 -0400 | [diff] [blame] | 795 | static class TextSelectionData { |
| 796 | public TextSelectionData(int start, int end) { |
| 797 | mStart = start; |
| 798 | mEnd = end; |
| 799 | } |
| 800 | int mStart; |
| 801 | int mEnd; |
| 802 | } |
| 803 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 804 | static class TouchUpData { |
| 805 | int mMoveGeneration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 806 | int mFrame; |
| 807 | int mNode; |
| 808 | int mX; |
| 809 | int mY; |
Patrick Scott | cfa734a | 2011-02-22 11:19:02 -0500 | [diff] [blame] | 810 | int mNativeLayer; |
| 811 | Rect mNativeLayerRect = new Rect(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 812 | } |
| 813 | |
Grace Kloba | 178db41 | 2010-05-18 22:22:23 -0700 | [diff] [blame] | 814 | static class TouchHighlightData { |
| 815 | int mX; |
| 816 | int mY; |
| 817 | int mSlop; |
John Reck | 335f454 | 2011-08-25 18:25:09 -0700 | [diff] [blame] | 818 | int mNativeLayer; |
| 819 | Rect mNativeLayerRect; |
Grace Kloba | 178db41 | 2010-05-18 22:22:23 -0700 | [diff] [blame] | 820 | } |
| 821 | |
Ben Murdoch | db8d19c | 2010-10-29 11:44:17 +0100 | [diff] [blame] | 822 | static class AutoFillData { |
| 823 | public AutoFillData() { |
| 824 | mQueryId = WebTextView.FORM_NOT_AUTOFILLABLE; |
| 825 | mPreview = ""; |
| 826 | } |
| 827 | |
| 828 | public AutoFillData(int queryId, String preview) { |
| 829 | mQueryId = queryId; |
| 830 | mPreview = preview; |
| 831 | } |
| 832 | |
| 833 | public int getQueryId() { |
| 834 | return mQueryId; |
| 835 | } |
| 836 | |
| 837 | public String getPreviewString() { |
| 838 | return mPreview; |
| 839 | } |
| 840 | |
| 841 | private int mQueryId; |
| 842 | private String mPreview; |
| 843 | } |
| 844 | |
Grace Kloba | 5f68d6f | 2009-12-08 18:42:54 -0800 | [diff] [blame] | 845 | // mAction of TouchEventData can be MotionEvent.getAction() which uses the |
| 846 | // last two bytes or one of the following values |
| 847 | static final int ACTION_LONGPRESS = 0x100; |
| 848 | static final int ACTION_DOUBLETAP = 0x200; |
| 849 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 850 | static class TouchEventData { |
Grace Kloba | 5f68d6f | 2009-12-08 18:42:54 -0800 | [diff] [blame] | 851 | int mAction; |
Huahui Wu | e838a42 | 2011-01-13 16:03:43 -0800 | [diff] [blame] | 852 | int[] mIds; // Ids of the touch points |
Huahui Wu | 41865f4 | 2010-09-02 13:41:41 -0700 | [diff] [blame] | 853 | Point[] mPoints; |
Huahui Wu | 88b869a | 2011-03-17 17:42:12 -0700 | [diff] [blame] | 854 | Point[] mPointsInView; // the point coordinates in view axis. |
Huahui Wu | 2d3ef37 | 2011-03-13 18:13:42 -0700 | [diff] [blame] | 855 | int mActionIndex; // Associated pointer index for ACTION_POINTER_DOWN/UP |
Ben Murdoch | 8a032a3 | 2010-02-02 18:20:11 +0000 | [diff] [blame] | 856 | int mMetaState; |
Grace Kloba | c2242f2 | 2010-03-05 14:00:26 -0800 | [diff] [blame] | 857 | boolean mReprocess; |
Huahui Wu | 0904c0d | 2011-01-07 17:30:53 -0800 | [diff] [blame] | 858 | MotionEvent mMotionEvent; |
Patrick Scott | cfa734a | 2011-02-22 11:19:02 -0500 | [diff] [blame] | 859 | int mNativeLayer; |
| 860 | Rect mNativeLayerRect = new Rect(); |
Adam Powell | 4fb35d4 | 2011-03-03 17:54:55 -0800 | [diff] [blame] | 861 | long mSequence; |
| 862 | boolean mNativeResult; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 863 | } |
| 864 | |
Steve Block | 4faee09 | 2009-07-28 18:20:50 +0100 | [diff] [blame] | 865 | static class GeolocationPermissionsData { |
| 866 | String mOrigin; |
| 867 | boolean mAllow; |
| 868 | boolean mRemember; |
| 869 | } |
| 870 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 871 | static final String[] HandlerDebugString = { |
Leon Scroggins | 200c13d | 2010-05-14 15:35:42 -0400 | [diff] [blame] | 872 | "REVEAL_SELECTION", // 96 |
Leon Scroggins | 3a50339 | 2010-01-06 17:04:38 -0500 | [diff] [blame] | 873 | "REQUEST_LABEL", // 97 |
Cary Clark | 77d98f4 | 2009-07-31 09:40:38 -0400 | [diff] [blame] | 874 | "UPDATE_FRAME_CACHE_IF_LOADING", // = 98 |
Leon Scroggins | 72543e1 | 2009-07-23 15:29:45 -0400 | [diff] [blame] | 875 | "SCROLL_TEXT_INPUT", // = 99 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 876 | "LOAD_URL", // = 100; |
| 877 | "STOP_LOADING", // = 101; |
| 878 | "RELOAD", // = 102; |
| 879 | "KEY_DOWN", // = 103; |
| 880 | "KEY_UP", // = 104; |
| 881 | "VIEW_SIZE_CHANGED", // = 105; |
| 882 | "GO_BACK_FORWARD", // = 106; |
| 883 | "SET_SCROLL_OFFSET", // = 107; |
| 884 | "RESTORE_STATE", // = 108; |
| 885 | "PAUSE_TIMERS", // = 109; |
| 886 | "RESUME_TIMERS", // = 110; |
| 887 | "CLEAR_CACHE", // = 111; |
| 888 | "CLEAR_HISTORY", // = 112; |
| 889 | "SET_SELECTION", // = 113; |
| 890 | "REPLACE_TEXT", // = 114; |
| 891 | "PASS_TO_JS", // = 115; |
| 892 | "SET_GLOBAL_BOUNDS", // = 116; |
| 893 | "UPDATE_CACHE_AND_TEXT_ENTRY", // = 117; |
| 894 | "CLICK", // = 118; |
Grace Kloba | a72cc09 | 2009-04-02 08:50:17 -0700 | [diff] [blame] | 895 | "SET_NETWORK_STATE", // = 119; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 896 | "DOC_HAS_IMAGES", // = 120; |
Leon Scroggins | b45a263 | 2011-01-12 14:11:24 -0500 | [diff] [blame] | 897 | "FAKE_CLICK", // = 121; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 898 | "DELETE_SELECTION", // = 122; |
| 899 | "LISTBOX_CHOICES", // = 123; |
| 900 | "SINGLE_LISTBOX_CHOICE", // = 124; |
Grace Kloba | b3230cb | 2009-04-13 14:04:23 -0700 | [diff] [blame] | 901 | "MESSAGE_RELAY", // = 125; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 902 | "SET_BACKGROUND_COLOR", // = 126; |
Leon Scroggins | 47fabbf | 2009-12-08 16:57:26 -0500 | [diff] [blame] | 903 | "SET_MOVE_FOCUS", // = 127 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 904 | "SAVE_DOCUMENT_STATE", // = 128; |
Cary Clark | 57d2c3a | 2009-12-23 13:57:15 -0500 | [diff] [blame] | 905 | "129", // = 129; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 906 | "WEBKIT_DRAW", // = 130; |
Patrick Scott | fa8be1c | 2011-02-02 14:09:34 -0500 | [diff] [blame] | 907 | "131", // = 131; |
Grace Kloba | 5753430 | 2009-05-22 18:55:02 -0700 | [diff] [blame] | 908 | "POST_URL", // = 132; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 909 | "SPLIT_PICTURE_SET", // = 133; |
| 910 | "CLEAR_CONTENT", // = 134; |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 911 | "SET_MOVE_MOUSE", // = 135; |
| 912 | "SET_MOVE_MOUSE_IF_LATEST", // = 136; |
Leon Scroggins | 1c7f8c5 | 2009-06-05 13:49:26 -0400 | [diff] [blame] | 913 | "REQUEST_CURSOR_HREF", // = 137; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 914 | "ADD_JS_INTERFACE", // = 138; |
| 915 | "LOAD_DATA", // = 139; |
| 916 | "TOUCH_UP", // = 140; |
| 917 | "TOUCH_EVENT", // = 141; |
Leon Scroggins | 8cdad88 | 2009-06-30 08:47:04 -0400 | [diff] [blame] | 918 | "SET_ACTIVE", // = 142; |
Mike Reed | d205d5b | 2009-05-27 11:02:29 -0400 | [diff] [blame] | 919 | "ON_PAUSE", // = 143 |
| 920 | "ON_RESUME", // = 144 |
Derek Sollenberger | e0155e9 | 2009-06-10 15:35:45 -0400 | [diff] [blame] | 921 | "FREE_MEMORY", // = 145 |
Cary Clark | 1cb97ee | 2009-12-11 12:10:36 -0500 | [diff] [blame] | 922 | "VALID_NODE_BOUNDS", // = 146 |
Elliott Slaughter | b48fdbe | 2010-06-30 11:39:52 -0700 | [diff] [blame] | 923 | "SAVE_WEBARCHIVE", // = 147 |
Nicolas Roard | fb7bc34 | 2010-11-01 15:08:03 -0700 | [diff] [blame] | 924 | "WEBKIT_DRAW_LAYERS", // = 148; |
Steve Block | 689a342 | 2010-12-07 18:18:26 +0000 | [diff] [blame] | 925 | "REMOVE_JS_INTERFACE", // = 149; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 926 | }; |
| 927 | |
Dounia Berrada | 940a198 | 2011-04-27 13:53:13 -0700 | [diff] [blame] | 928 | /** |
| 929 | * @hide |
| 930 | */ |
| 931 | public class EventHub { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 932 | // Message Ids |
Leon Scroggins | 200c13d | 2010-05-14 15:35:42 -0400 | [diff] [blame] | 933 | static final int REVEAL_SELECTION = 96; |
Leon Scroggins | 3a50339 | 2010-01-06 17:04:38 -0500 | [diff] [blame] | 934 | static final int REQUEST_LABEL = 97; |
Cary Clark | 77d98f4 | 2009-07-31 09:40:38 -0400 | [diff] [blame] | 935 | static final int UPDATE_FRAME_CACHE_IF_LOADING = 98; |
Leon Scroggins | 72543e1 | 2009-07-23 15:29:45 -0400 | [diff] [blame] | 936 | static final int SCROLL_TEXT_INPUT = 99; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 937 | static final int LOAD_URL = 100; |
| 938 | static final int STOP_LOADING = 101; |
| 939 | static final int RELOAD = 102; |
| 940 | static final int KEY_DOWN = 103; |
| 941 | static final int KEY_UP = 104; |
| 942 | static final int VIEW_SIZE_CHANGED = 105; |
| 943 | static final int GO_BACK_FORWARD = 106; |
| 944 | static final int SET_SCROLL_OFFSET = 107; |
| 945 | static final int RESTORE_STATE = 108; |
| 946 | static final int PAUSE_TIMERS = 109; |
| 947 | static final int RESUME_TIMERS = 110; |
| 948 | static final int CLEAR_CACHE = 111; |
| 949 | static final int CLEAR_HISTORY = 112; |
| 950 | static final int SET_SELECTION = 113; |
| 951 | static final int REPLACE_TEXT = 114; |
| 952 | static final int PASS_TO_JS = 115; |
| 953 | static final int SET_GLOBAL_BOUNDS = 116; |
| 954 | static final int UPDATE_CACHE_AND_TEXT_ENTRY = 117; |
| 955 | static final int CLICK = 118; |
Grace Kloba | a72cc09 | 2009-04-02 08:50:17 -0700 | [diff] [blame] | 956 | static final int SET_NETWORK_STATE = 119; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 957 | static final int DOC_HAS_IMAGES = 120; |
Leon Scroggins | b45a263 | 2011-01-12 14:11:24 -0500 | [diff] [blame] | 958 | static final int FAKE_CLICK = 121; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 959 | static final int DELETE_SELECTION = 122; |
| 960 | static final int LISTBOX_CHOICES = 123; |
| 961 | static final int SINGLE_LISTBOX_CHOICE = 124; |
Dounia Berrada | 940a198 | 2011-04-27 13:53:13 -0700 | [diff] [blame] | 962 | public static final int MESSAGE_RELAY = 125; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 963 | static final int SET_BACKGROUND_COLOR = 126; |
Leon Scroggins | 47fabbf | 2009-12-08 16:57:26 -0500 | [diff] [blame] | 964 | static final int SET_MOVE_FOCUS = 127; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 965 | static final int SAVE_DOCUMENT_STATE = 128; |
Cary Clark | 57d2c3a | 2009-12-23 13:57:15 -0500 | [diff] [blame] | 966 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 967 | static final int WEBKIT_DRAW = 130; |
Grace Kloba | 5753430 | 2009-05-22 18:55:02 -0700 | [diff] [blame] | 968 | static final int POST_URL = 132; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 969 | static final int SPLIT_PICTURE_SET = 133; |
| 970 | static final int CLEAR_CONTENT = 134; |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 971 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 972 | // UI nav messages |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 973 | static final int SET_MOVE_MOUSE = 135; |
| 974 | static final int SET_MOVE_MOUSE_IF_LATEST = 136; |
Leon Scroggins | 1c7f8c5 | 2009-06-05 13:49:26 -0400 | [diff] [blame] | 975 | static final int REQUEST_CURSOR_HREF = 137; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 976 | static final int ADD_JS_INTERFACE = 138; |
| 977 | static final int LOAD_DATA = 139; |
| 978 | |
| 979 | // motion |
| 980 | static final int TOUCH_UP = 140; |
| 981 | // message used to pass UI touch events to WebCore |
| 982 | static final int TOUCH_EVENT = 141; |
| 983 | |
Leon Scroggins | fa03cde | 2009-06-15 15:48:46 -0400 | [diff] [blame] | 984 | // Used to tell the focus controller not to draw the blinking cursor, |
| 985 | // based on whether the WebView has focus and whether the WebView's |
| 986 | // cursor matches the webpage's focus. |
Leon Scroggins | 8cdad88 | 2009-06-30 08:47:04 -0400 | [diff] [blame] | 987 | static final int SET_ACTIVE = 142; |
Leon Scroggins | 63dda1c | 2009-04-15 13:25:00 -0400 | [diff] [blame] | 988 | |
Derek Sollenberger | e0155e9 | 2009-06-10 15:35:45 -0400 | [diff] [blame] | 989 | // lifecycle activities for just this DOM (unlike pauseTimers, which |
Mike Reed | d205d5b | 2009-05-27 11:02:29 -0400 | [diff] [blame] | 990 | // is global) |
| 991 | static final int ON_PAUSE = 143; |
| 992 | static final int ON_RESUME = 144; |
Derek Sollenberger | e0155e9 | 2009-06-10 15:35:45 -0400 | [diff] [blame] | 993 | static final int FREE_MEMORY = 145; |
Cary Clark | 1cb97ee | 2009-12-11 12:10:36 -0500 | [diff] [blame] | 994 | static final int VALID_NODE_BOUNDS = 146; |
Mike Reed | d205d5b | 2009-05-27 11:02:29 -0400 | [diff] [blame] | 995 | |
Elliott Slaughter | b48fdbe | 2010-06-30 11:39:52 -0700 | [diff] [blame] | 996 | // Load and save web archives |
| 997 | static final int SAVE_WEBARCHIVE = 147; |
| 998 | |
Nicolas Roard | fb7bc34 | 2010-11-01 15:08:03 -0700 | [diff] [blame] | 999 | // Update layers |
| 1000 | static final int WEBKIT_DRAW_LAYERS = 148; |
| 1001 | |
Steve Block | 689a342 | 2010-12-07 18:18:26 +0000 | [diff] [blame] | 1002 | static final int REMOVE_JS_INTERFACE = 149; |
| 1003 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1004 | // Network-based messaging |
| 1005 | static final int CLEAR_SSL_PREF_TABLE = 150; |
| 1006 | |
| 1007 | // Test harness messages |
| 1008 | static final int REQUEST_EXT_REPRESENTATION = 160; |
| 1009 | static final int REQUEST_DOC_AS_TEXT = 161; |
| 1010 | |
| 1011 | // debugging |
| 1012 | static final int DUMP_DOMTREE = 170; |
| 1013 | static final int DUMP_RENDERTREE = 171; |
| 1014 | static final int DUMP_NAVTREE = 172; |
| 1015 | |
Andrei Popescu | 5e7bb0a | 2010-02-01 22:32:16 +0000 | [diff] [blame] | 1016 | static final int SET_JS_FLAGS = 174; |
Chris Craik | 555c55e | 2011-07-28 15:39:43 -0700 | [diff] [blame] | 1017 | static final int CONTENT_INVALIDATE_ALL = 175; |
Steve Block | 4faee09 | 2009-07-28 18:20:50 +0100 | [diff] [blame] | 1018 | // Geolocation |
| 1019 | static final int GEOLOCATION_PERMISSIONS_PROVIDE = 180; |
Feng Qian | b308137 | 2009-06-29 15:55:18 -0700 | [diff] [blame] | 1020 | |
Leon Clarke | 194e345 | 2009-09-28 11:42:12 +0100 | [diff] [blame] | 1021 | static final int POPULATE_VISITED_LINKS = 181; |
| 1022 | |
Grace Kloba | 11438c3 | 2009-12-16 11:39:12 -0800 | [diff] [blame] | 1023 | static final int HIDE_FULLSCREEN = 182; |
| 1024 | |
Andrei Popescu | f5dba88 | 2010-01-12 22:42:41 +0000 | [diff] [blame] | 1025 | static final int SET_NETWORK_TYPE = 183; |
| 1026 | |
Andrei Popescu | a6d747d | 2010-02-11 13:19:21 +0000 | [diff] [blame] | 1027 | // navigator.isApplicationInstalled() |
| 1028 | static final int ADD_PACKAGE_NAMES = 184; |
| 1029 | static final int ADD_PACKAGE_NAME = 185; |
| 1030 | static final int REMOVE_PACKAGE_NAME = 186; |
| 1031 | |
Grace Kloba | 178db41 | 2010-05-18 22:22:23 -0700 | [diff] [blame] | 1032 | static final int GET_TOUCH_HIGHLIGHT_RECTS = 187; |
Grace Kloba | 178db41 | 2010-05-18 22:22:23 -0700 | [diff] [blame] | 1033 | |
Svetoslav Ganov | da35551 | 2010-05-12 22:04:44 -0700 | [diff] [blame] | 1034 | // accessibility support |
| 1035 | static final int MODIFY_SELECTION = 190; |
| 1036 | |
Steve Block | 68dede3 | 2010-08-04 10:28:46 +0100 | [diff] [blame] | 1037 | static final int USE_MOCK_DEVICE_ORIENTATION = 191; |
| 1038 | |
Ben Murdoch | 62275a4 | 2010-09-07 11:27:28 +0100 | [diff] [blame] | 1039 | static final int AUTOFILL_FORM = 192; |
| 1040 | |
Kristian Monsen | 41e7e6f | 2010-12-21 12:51:11 +0000 | [diff] [blame] | 1041 | static final int PROXY_CHANGED = 193; |
| 1042 | |
Narayan Kamath | 9497c5f | 2011-02-22 12:05:34 +0000 | [diff] [blame] | 1043 | static final int EXECUTE_JS = 194; |
| 1044 | |
Derek Sollenberger | 281432c | 2011-08-22 14:05:49 -0400 | [diff] [blame] | 1045 | static final int PLUGIN_SURFACE_READY = 195; |
| 1046 | |
Chris Craik | d0051c0 | 2011-11-29 10:26:10 -0800 | [diff] [blame] | 1047 | static final int NOTIFY_ANIMATION_STARTED = 196; |
| 1048 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1049 | // private message ids |
| 1050 | private static final int DESTROY = 200; |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 1051 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1052 | // Private handler for WebCore messages. |
| 1053 | private Handler mHandler; |
| 1054 | // Message queue for containing messages before the WebCore thread is |
| 1055 | // ready. |
| 1056 | private ArrayList<Message> mMessages = new ArrayList<Message>(); |
| 1057 | // Flag for blocking messages. This is used during DESTROY to avoid |
| 1058 | // posting more messages to the EventHub or to WebView's event handler. |
| 1059 | private boolean mBlockMessages; |
John Reck | 45576fa | 2011-09-01 11:45:35 -0700 | [diff] [blame] | 1060 | private boolean mDestroying; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1061 | |
| 1062 | private int mTid; |
| 1063 | private int mSavedPriority; |
| 1064 | |
| 1065 | /** |
| 1066 | * Prevent other classes from creating an EventHub. |
| 1067 | */ |
| 1068 | private EventHub() {} |
| 1069 | |
Leon Scroggins | 200c13d | 2010-05-14 15:35:42 -0400 | [diff] [blame] | 1070 | private static final int FIRST_PACKAGE_MSG_ID = REVEAL_SELECTION; |
| 1071 | private static final int LAST_PACKAGE_MSG_ID = VALID_NODE_BOUNDS; |
| 1072 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1073 | /** |
| 1074 | * Transfer all messages to the newly created webcore thread handler. |
| 1075 | */ |
| 1076 | private void transferMessages() { |
| 1077 | mTid = Process.myTid(); |
| 1078 | mSavedPriority = Process.getThreadPriority(mTid); |
| 1079 | |
| 1080 | mHandler = new Handler() { |
| 1081 | @Override |
| 1082 | public void handleMessage(Message msg) { |
Derek Sollenberger | 2e5c150 | 2009-06-03 10:44:42 -0400 | [diff] [blame] | 1083 | if (DebugFlags.WEB_VIEW_CORE) { |
Leon Scroggins | 200c13d | 2010-05-14 15:35:42 -0400 | [diff] [blame] | 1084 | Log.v(LOGTAG, (msg.what < FIRST_PACKAGE_MSG_ID |
| 1085 | || msg.what > LAST_PACKAGE_MSG_ID |
| 1086 | ? Integer.toString(msg.what) |
Leon Scroggins | 72543e1 | 2009-07-23 15:29:45 -0400 | [diff] [blame] | 1087 | : HandlerDebugString[msg.what |
Leon Scroggins | 200c13d | 2010-05-14 15:35:42 -0400 | [diff] [blame] | 1088 | - FIRST_PACKAGE_MSG_ID]) |
Cary Clark | 243ea06 | 2009-06-25 10:49:32 -0400 | [diff] [blame] | 1089 | + " arg1=" + msg.arg1 + " arg2=" + msg.arg2 |
| 1090 | + " obj=" + msg.obj); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1091 | } |
John Reck | 45576fa | 2011-09-01 11:45:35 -0700 | [diff] [blame] | 1092 | if (mWebView == null || mNativeClass == 0) { |
| 1093 | if (DebugFlags.WEB_VIEW_CORE) { |
| 1094 | Log.w(LOGTAG, "Rejecting message " + msg.what |
| 1095 | + " because we are destroyed"); |
| 1096 | } |
| 1097 | return; |
| 1098 | } |
| 1099 | if (mDestroying == true |
John Reck | 00d5bf7 | 2011-07-21 09:46:17 -0700 | [diff] [blame] | 1100 | && msg.what != EventHub.RESUME_TIMERS |
John Reck | 45576fa | 2011-09-01 11:45:35 -0700 | [diff] [blame] | 1101 | && msg.what != EventHub.PAUSE_TIMERS |
| 1102 | && msg.what != EventHub.DESTROY) { |
John Reck | 00d5bf7 | 2011-07-21 09:46:17 -0700 | [diff] [blame] | 1103 | if (DebugFlags.WEB_VIEW_CORE) { |
| 1104 | Log.v(LOGTAG, "Rejecting message " + msg.what |
John Reck | 45576fa | 2011-09-01 11:45:35 -0700 | [diff] [blame] | 1105 | + " because we are being destroyed"); |
John Reck | 00d5bf7 | 2011-07-21 09:46:17 -0700 | [diff] [blame] | 1106 | } |
| 1107 | return; |
| 1108 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1109 | switch (msg.what) { |
| 1110 | case WEBKIT_DRAW: |
| 1111 | webkitDraw(); |
| 1112 | break; |
| 1113 | |
Nicolas Roard | fb7bc34 | 2010-11-01 15:08:03 -0700 | [diff] [blame] | 1114 | case WEBKIT_DRAW_LAYERS: |
| 1115 | webkitDrawLayers(); |
| 1116 | break; |
| 1117 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1118 | case DESTROY: |
| 1119 | // Time to take down the world. Cancel all pending |
| 1120 | // loads and destroy the native view and frame. |
Cary Clark | 674a844 | 2009-09-15 16:25:43 -0400 | [diff] [blame] | 1121 | synchronized (WebViewCore.this) { |
| 1122 | mBrowserFrame.destroy(); |
| 1123 | mBrowserFrame = null; |
Andrei Popescu | dee76be | 2009-09-22 18:28:21 +0100 | [diff] [blame] | 1124 | mSettings.onDestroyed(); |
Cary Clark | 674a844 | 2009-09-15 16:25:43 -0400 | [diff] [blame] | 1125 | mNativeClass = 0; |
Ben Murdoch | 3dba1e4 | 2009-09-22 15:50:30 +0100 | [diff] [blame] | 1126 | mWebView = null; |
Cary Clark | 674a844 | 2009-09-15 16:25:43 -0400 | [diff] [blame] | 1127 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1128 | break; |
| 1129 | |
Leon Scroggins | 200c13d | 2010-05-14 15:35:42 -0400 | [diff] [blame] | 1130 | case REVEAL_SELECTION: |
| 1131 | nativeRevealSelection(); |
| 1132 | break; |
| 1133 | |
Leon Scroggins | 3a50339 | 2010-01-06 17:04:38 -0500 | [diff] [blame] | 1134 | case REQUEST_LABEL: |
| 1135 | if (mWebView != null) { |
| 1136 | int nodePointer = msg.arg2; |
| 1137 | String label = nativeRequestLabel(msg.arg1, |
| 1138 | nodePointer); |
| 1139 | if (label != null && label.length() > 0) { |
| 1140 | Message.obtain(mWebView.mPrivateHandler, |
| 1141 | WebView.RETURN_LABEL, nodePointer, |
| 1142 | 0, label).sendToTarget(); |
| 1143 | } |
| 1144 | } |
| 1145 | break; |
| 1146 | |
Cary Clark | 77d98f4 | 2009-07-31 09:40:38 -0400 | [diff] [blame] | 1147 | case UPDATE_FRAME_CACHE_IF_LOADING: |
| 1148 | nativeUpdateFrameCacheIfLoading(); |
| 1149 | break; |
| 1150 | |
Leon Scroggins | 72543e1 | 2009-07-23 15:29:45 -0400 | [diff] [blame] | 1151 | case SCROLL_TEXT_INPUT: |
Leon Scroggins | 22e883d | 2011-01-31 10:54:19 -0500 | [diff] [blame] | 1152 | float xPercent; |
| 1153 | if (msg.obj == null) { |
| 1154 | xPercent = 0f; |
| 1155 | } else { |
| 1156 | xPercent = ((Float) msg.obj).floatValue(); |
| 1157 | } |
| 1158 | nativeScrollFocusedTextInput(xPercent, msg.arg2); |
Leon Scroggins | 72543e1 | 2009-07-23 15:29:45 -0400 | [diff] [blame] | 1159 | break; |
| 1160 | |
Grace Kloba | d0d9bc2 | 2010-01-26 18:08:28 -0800 | [diff] [blame] | 1161 | case LOAD_URL: { |
Kristian Monsen | 8517305 | 2010-12-08 15:29:29 +0000 | [diff] [blame] | 1162 | CookieManager.getInstance().waitForCookieOperationsToComplete(); |
Grace Kloba | d0d9bc2 | 2010-01-26 18:08:28 -0800 | [diff] [blame] | 1163 | GetUrlData param = (GetUrlData) msg.obj; |
| 1164 | loadUrl(param.mUrl, param.mExtraHeaders); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1165 | break; |
Grace Kloba | d0d9bc2 | 2010-01-26 18:08:28 -0800 | [diff] [blame] | 1166 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1167 | |
Grace Kloba | 5753430 | 2009-05-22 18:55:02 -0700 | [diff] [blame] | 1168 | case POST_URL: { |
Kristian Monsen | 8517305 | 2010-12-08 15:29:29 +0000 | [diff] [blame] | 1169 | CookieManager.getInstance().waitForCookieOperationsToComplete(); |
Cary Clark | ded054c | 2009-06-15 10:26:08 -0400 | [diff] [blame] | 1170 | PostUrlData param = (PostUrlData) msg.obj; |
| 1171 | mBrowserFrame.postUrl(param.mUrl, param.mPostData); |
Grace Kloba | 5753430 | 2009-05-22 18:55:02 -0700 | [diff] [blame] | 1172 | break; |
| 1173 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1174 | case LOAD_DATA: |
Kristian Monsen | 8517305 | 2010-12-08 15:29:29 +0000 | [diff] [blame] | 1175 | CookieManager.getInstance().waitForCookieOperationsToComplete(); |
Cary Clark | ded054c | 2009-06-15 10:26:08 -0400 | [diff] [blame] | 1176 | BaseUrlData loadParams = (BaseUrlData) msg.obj; |
| 1177 | String baseUrl = loadParams.mBaseUrl; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1178 | if (baseUrl != null) { |
| 1179 | int i = baseUrl.indexOf(':'); |
| 1180 | if (i > 0) { |
Steve Block | ae32857 | 2011-06-08 18:58:51 +0100 | [diff] [blame] | 1181 | // In 1.0, WebView.loadDataWithBaseURL() could access local |
| 1182 | // asset files using 'file' scheme URLs as long as the data is |
| 1183 | // valid. Later versions of WebKit have tightened the |
| 1184 | // restriction around when pages can access such local URLs. |
| 1185 | // To maintain compatibility with 1.0, we register the scheme of |
| 1186 | // the baseUrl to be considered local, as long as it is not |
| 1187 | // http(s)/ftp(s)/about/javascript. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1188 | String scheme = baseUrl.substring(0, i); |
| 1189 | if (!scheme.startsWith("http") && |
| 1190 | !scheme.startsWith("ftp") && |
| 1191 | !scheme.startsWith("about") && |
| 1192 | !scheme.startsWith("javascript")) { |
| 1193 | nativeRegisterURLSchemeAsLocal(scheme); |
| 1194 | } |
| 1195 | } |
| 1196 | } |
| 1197 | mBrowserFrame.loadData(baseUrl, |
Cary Clark | ded054c | 2009-06-15 10:26:08 -0400 | [diff] [blame] | 1198 | loadParams.mData, |
| 1199 | loadParams.mMimeType, |
| 1200 | loadParams.mEncoding, |
Leon Scroggins | 1bb1a91 | 2010-03-23 15:39:46 -0400 | [diff] [blame] | 1201 | loadParams.mHistoryUrl); |
John Reck | fb2b9b2 | 2011-08-25 15:38:33 -0700 | [diff] [blame] | 1202 | nativeContentInvalidateAll(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1203 | break; |
| 1204 | |
| 1205 | case STOP_LOADING: |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 1206 | // If the WebCore has committed the load, but not |
| 1207 | // finished the first layout yet, we need to set |
| 1208 | // first layout done to trigger the interpreted side sync |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1209 | // up with native side |
| 1210 | if (mBrowserFrame.committed() |
| 1211 | && !mBrowserFrame.firstLayoutDone()) { |
| 1212 | mBrowserFrame.didFirstLayout(); |
| 1213 | } |
| 1214 | // Do this after syncing up the layout state. |
| 1215 | stopLoading(); |
| 1216 | break; |
| 1217 | |
| 1218 | case RELOAD: |
| 1219 | mBrowserFrame.reload(false); |
| 1220 | break; |
| 1221 | |
| 1222 | case KEY_DOWN: |
| 1223 | key((KeyEvent) msg.obj, true); |
| 1224 | break; |
| 1225 | |
| 1226 | case KEY_UP: |
| 1227 | key((KeyEvent) msg.obj, false); |
| 1228 | break; |
| 1229 | |
Leon Scroggins | b45a263 | 2011-01-12 14:11:24 -0500 | [diff] [blame] | 1230 | case FAKE_CLICK: |
| 1231 | nativeClick(msg.arg1, msg.arg2, true); |
| 1232 | break; |
| 1233 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1234 | case CLICK: |
Leon Scroggins | b45a263 | 2011-01-12 14:11:24 -0500 | [diff] [blame] | 1235 | nativeClick(msg.arg1, msg.arg2, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1236 | break; |
| 1237 | |
Grace Kloba | ef347ef | 2009-07-30 11:20:32 -0700 | [diff] [blame] | 1238 | case VIEW_SIZE_CHANGED: { |
Shimeng (Simon) Wang | 48fc909 | 2011-02-03 14:29:54 -0800 | [diff] [blame] | 1239 | viewSizeChanged((WebView.ViewSizeData) msg.obj); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1240 | break; |
Grace Kloba | ef347ef | 2009-07-30 11:20:32 -0700 | [diff] [blame] | 1241 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1242 | case SET_SCROLL_OFFSET: |
| 1243 | // note: these are in document coordinates |
| 1244 | // (inv-zoom) |
Cary Clark | ed56eda | 2009-06-18 09:48:47 -0400 | [diff] [blame] | 1245 | Point pt = (Point) msg.obj; |
Patrick Scott | fa8be1c | 2011-02-02 14:09:34 -0500 | [diff] [blame] | 1246 | nativeSetScrollOffset(msg.arg1, msg.arg2 == 1, |
| 1247 | pt.x, pt.y); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1248 | break; |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 1249 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1250 | case SET_GLOBAL_BOUNDS: |
| 1251 | Rect r = (Rect) msg.obj; |
| 1252 | nativeSetGlobalBounds(r.left, r.top, r.width(), |
| 1253 | r.height()); |
| 1254 | break; |
| 1255 | |
| 1256 | case GO_BACK_FORWARD: |
| 1257 | // If it is a standard load and the load is not |
| 1258 | // committed yet, we interpret BACK as RELOAD |
| 1259 | if (!mBrowserFrame.committed() && msg.arg1 == -1 && |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 1260 | (mBrowserFrame.loadType() == |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1261 | BrowserFrame.FRAME_LOADTYPE_STANDARD)) { |
| 1262 | mBrowserFrame.reload(true); |
| 1263 | } else { |
| 1264 | mBrowserFrame.goBackOrForward(msg.arg1); |
| 1265 | } |
| 1266 | break; |
| 1267 | |
| 1268 | case RESTORE_STATE: |
| 1269 | stopLoading(); |
| 1270 | restoreState(msg.arg1); |
| 1271 | break; |
| 1272 | |
| 1273 | case PAUSE_TIMERS: |
| 1274 | mSavedPriority = Process.getThreadPriority(mTid); |
| 1275 | Process.setThreadPriority(mTid, |
| 1276 | Process.THREAD_PRIORITY_BACKGROUND); |
| 1277 | pauseTimers(); |
Steve Block | 808751f | 2011-01-04 14:26:27 +0000 | [diff] [blame] | 1278 | if (!JniUtil.useChromiumHttpStack()) { |
| 1279 | WebViewWorker.getHandler().sendEmptyMessage( |
| 1280 | WebViewWorker.MSG_PAUSE_CACHE_TRANSACTION); |
Kristian Monsen | 64decc6 | 2011-08-25 20:32:24 +0100 | [diff] [blame] | 1281 | } else { |
| 1282 | nativeCloseIdleConnections(); |
Steve Block | 808751f | 2011-01-04 14:26:27 +0000 | [diff] [blame] | 1283 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1284 | break; |
| 1285 | |
| 1286 | case RESUME_TIMERS: |
| 1287 | Process.setThreadPriority(mTid, mSavedPriority); |
| 1288 | resumeTimers(); |
Steve Block | 808751f | 2011-01-04 14:26:27 +0000 | [diff] [blame] | 1289 | if (!JniUtil.useChromiumHttpStack()) { |
| 1290 | WebViewWorker.getHandler().sendEmptyMessage( |
| 1291 | WebViewWorker.MSG_RESUME_CACHE_TRANSACTION); |
| 1292 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1293 | break; |
| 1294 | |
Mike Reed | d205d5b | 2009-05-27 11:02:29 -0400 | [diff] [blame] | 1295 | case ON_PAUSE: |
| 1296 | nativePause(); |
| 1297 | break; |
| 1298 | |
| 1299 | case ON_RESUME: |
| 1300 | nativeResume(); |
| 1301 | break; |
| 1302 | |
Derek Sollenberger | e0155e9 | 2009-06-10 15:35:45 -0400 | [diff] [blame] | 1303 | case FREE_MEMORY: |
| 1304 | clearCache(false); |
| 1305 | nativeFreeMemory(); |
| 1306 | break; |
| 1307 | |
Grace Kloba | a72cc09 | 2009-04-02 08:50:17 -0700 | [diff] [blame] | 1308 | case SET_NETWORK_STATE: |
| 1309 | if (BrowserFrame.sJavaBridge == null) { |
| 1310 | throw new IllegalStateException("No WebView " + |
| 1311 | "has been created in this process!"); |
| 1312 | } |
| 1313 | BrowserFrame.sJavaBridge |
| 1314 | .setNetworkOnLine(msg.arg1 == 1); |
| 1315 | break; |
| 1316 | |
Andrei Popescu | f5dba88 | 2010-01-12 22:42:41 +0000 | [diff] [blame] | 1317 | case SET_NETWORK_TYPE: |
| 1318 | if (BrowserFrame.sJavaBridge == null) { |
| 1319 | throw new IllegalStateException("No WebView " + |
| 1320 | "has been created in this process!"); |
| 1321 | } |
| 1322 | Map<String, String> map = (Map<String, String>) msg.obj; |
| 1323 | BrowserFrame.sJavaBridge |
| 1324 | .setNetworkType(map.get("type"), map.get("subtype")); |
| 1325 | break; |
| 1326 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1327 | case CLEAR_CACHE: |
Derek Sollenberger | e0155e9 | 2009-06-10 15:35:45 -0400 | [diff] [blame] | 1328 | clearCache(msg.arg1 == 1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1329 | break; |
| 1330 | |
| 1331 | case CLEAR_HISTORY: |
| 1332 | mCallbackProxy.getBackForwardList(). |
| 1333 | close(mBrowserFrame.mNativeFrame); |
| 1334 | break; |
| 1335 | |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 1336 | case REPLACE_TEXT: |
Cary Clark | ded054c | 2009-06-15 10:26:08 -0400 | [diff] [blame] | 1337 | ReplaceTextData rep = (ReplaceTextData) msg.obj; |
| 1338 | nativeReplaceTextfieldText(msg.arg1, msg.arg2, |
Leon Scroggins | 43488fc | 2009-07-06 14:32:49 -0400 | [diff] [blame] | 1339 | rep.mReplace, rep.mNewStart, rep.mNewEnd, |
| 1340 | rep.mTextGeneration); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1341 | break; |
| 1342 | |
| 1343 | case PASS_TO_JS: { |
Cary Clark | ded054c | 2009-06-15 10:26:08 -0400 | [diff] [blame] | 1344 | JSKeyData jsData = (JSKeyData) msg.obj; |
| 1345 | KeyEvent evt = jsData.mEvent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1346 | int keyCode = evt.getKeyCode(); |
| 1347 | int keyValue = evt.getUnicodeChar(); |
| 1348 | int generation = msg.arg1; |
Cary Clark | 2f1d60c | 2009-06-03 08:05:53 -0400 | [diff] [blame] | 1349 | passToJs(generation, |
Cary Clark | ded054c | 2009-06-15 10:26:08 -0400 | [diff] [blame] | 1350 | jsData.mCurrentText, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1351 | keyCode, |
| 1352 | keyValue, |
| 1353 | evt.isDown(), |
| 1354 | evt.isShiftPressed(), evt.isAltPressed(), |
| 1355 | evt.isSymPressed()); |
| 1356 | break; |
| 1357 | } |
| 1358 | |
| 1359 | case SAVE_DOCUMENT_STATE: { |
Leon Scroggins | 1c7f8c5 | 2009-06-05 13:49:26 -0400 | [diff] [blame] | 1360 | CursorData cDat = (CursorData) msg.obj; |
| 1361 | nativeSaveDocumentState(cDat.mFrame); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1362 | break; |
| 1363 | } |
| 1364 | |
| 1365 | case CLEAR_SSL_PREF_TABLE: |
Kristian Monsen | d9151bf | 2011-09-14 16:29:23 +0100 | [diff] [blame] | 1366 | if (JniUtil.useChromiumHttpStack()) { |
| 1367 | // FIXME: This will not work for connections currently in use, as |
| 1368 | // they cache the certificate responses. See http://b/5324235. |
| 1369 | SslCertLookupTable.getInstance().clear(); |
| 1370 | nativeCloseIdleConnections(); |
| 1371 | } else { |
| 1372 | Network.getInstance(mContext).clearUserSslPrefTable(); |
| 1373 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1374 | break; |
| 1375 | |
| 1376 | case TOUCH_UP: |
| 1377 | TouchUpData touchUpData = (TouchUpData) msg.obj; |
Patrick Scott | cfa734a | 2011-02-22 11:19:02 -0500 | [diff] [blame] | 1378 | if (touchUpData.mNativeLayer != 0) { |
| 1379 | nativeScrollLayer(touchUpData.mNativeLayer, |
| 1380 | touchUpData.mNativeLayerRect); |
| 1381 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1382 | nativeTouchUp(touchUpData.mMoveGeneration, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1383 | touchUpData.mFrame, touchUpData.mNode, |
Leon Scroggins | 22e883d | 2011-01-31 10:54:19 -0500 | [diff] [blame] | 1384 | touchUpData.mX, touchUpData.mY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1385 | break; |
| 1386 | |
| 1387 | case TOUCH_EVENT: { |
| 1388 | TouchEventData ted = (TouchEventData) msg.obj; |
Huahui Wu | 41865f4 | 2010-09-02 13:41:41 -0700 | [diff] [blame] | 1389 | final int count = ted.mPoints.length; |
| 1390 | int[] xArray = new int[count]; |
| 1391 | int[] yArray = new int[count]; |
| 1392 | for (int c = 0; c < count; c++) { |
| 1393 | xArray[c] = ted.mPoints[c].x; |
| 1394 | yArray[c] = ted.mPoints[c].y; |
| 1395 | } |
Patrick Scott | cfa734a | 2011-02-22 11:19:02 -0500 | [diff] [blame] | 1396 | if (ted.mNativeLayer != 0) { |
| 1397 | nativeScrollLayer(ted.mNativeLayer, |
| 1398 | ted.mNativeLayerRect); |
| 1399 | } |
Adam Powell | 4fb35d4 | 2011-03-03 17:54:55 -0800 | [diff] [blame] | 1400 | ted.mNativeResult = nativeHandleTouchEvent(ted.mAction, ted.mIds, |
Huahui Wu | 2d3ef37 | 2011-03-13 18:13:42 -0700 | [diff] [blame] | 1401 | xArray, yArray, count, ted.mActionIndex, ted.mMetaState); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1402 | Message.obtain( |
| 1403 | mWebView.mPrivateHandler, |
Grace Kloba | c2242f2 | 2010-03-05 14:00:26 -0800 | [diff] [blame] | 1404 | WebView.PREVENT_TOUCH_ID, |
| 1405 | ted.mAction, |
Adam Powell | 4fb35d4 | 2011-03-03 17:54:55 -0800 | [diff] [blame] | 1406 | ted.mNativeResult ? 1 : 0, |
| 1407 | ted).sendToTarget(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1408 | break; |
| 1409 | } |
| 1410 | |
Leon Scroggins | 8cdad88 | 2009-06-30 08:47:04 -0400 | [diff] [blame] | 1411 | case SET_ACTIVE: |
| 1412 | nativeSetFocusControllerActive(msg.arg1 == 1); |
Leon Scroggins | 63dda1c | 2009-04-15 13:25:00 -0400 | [diff] [blame] | 1413 | break; |
| 1414 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1415 | case ADD_JS_INTERFACE: |
Cary Clark | ded054c | 2009-06-15 10:26:08 -0400 | [diff] [blame] | 1416 | JSInterfaceData jsData = (JSInterfaceData) msg.obj; |
| 1417 | mBrowserFrame.addJavascriptInterface(jsData.mObject, |
| 1418 | jsData.mInterfaceName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1419 | break; |
| 1420 | |
Steve Block | 689a342 | 2010-12-07 18:18:26 +0000 | [diff] [blame] | 1421 | case REMOVE_JS_INTERFACE: |
| 1422 | jsData = (JSInterfaceData) msg.obj; |
| 1423 | mBrowserFrame.removeJavascriptInterface( |
| 1424 | jsData.mInterfaceName); |
| 1425 | break; |
| 1426 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1427 | case REQUEST_EXT_REPRESENTATION: |
| 1428 | mBrowserFrame.externalRepresentation( |
| 1429 | (Message) msg.obj); |
| 1430 | break; |
| 1431 | |
| 1432 | case REQUEST_DOC_AS_TEXT: |
| 1433 | mBrowserFrame.documentAsText((Message) msg.obj); |
| 1434 | break; |
| 1435 | |
Leon Scroggins | 47fabbf | 2009-12-08 16:57:26 -0500 | [diff] [blame] | 1436 | case SET_MOVE_FOCUS: |
| 1437 | CursorData focusData = (CursorData) msg.obj; |
| 1438 | nativeMoveFocus(focusData.mFrame, focusData.mNode); |
| 1439 | break; |
| 1440 | |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 1441 | case SET_MOVE_MOUSE: |
Leon Scroggins | 1c7f8c5 | 2009-06-05 13:49:26 -0400 | [diff] [blame] | 1442 | CursorData cursorData = (CursorData) msg.obj; |
| 1443 | nativeMoveMouse(cursorData.mFrame, |
Cary Clark | ed56eda | 2009-06-18 09:48:47 -0400 | [diff] [blame] | 1444 | cursorData.mX, cursorData.mY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1445 | break; |
| 1446 | |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 1447 | case SET_MOVE_MOUSE_IF_LATEST: |
Leon Scroggins | 1c7f8c5 | 2009-06-05 13:49:26 -0400 | [diff] [blame] | 1448 | CursorData cData = (CursorData) msg.obj; |
| 1449 | nativeMoveMouseIfLatest(cData.mMoveGeneration, |
Cary Clark | ed56eda | 2009-06-18 09:48:47 -0400 | [diff] [blame] | 1450 | cData.mFrame, |
| 1451 | cData.mX, cData.mY); |
Leon Scroggins | b611213 | 2011-02-24 12:35:50 -0500 | [diff] [blame] | 1452 | if (msg.arg1 == 1) { |
| 1453 | nativeStopPaintingCaret(); |
| 1454 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1455 | break; |
| 1456 | |
Leon Scroggins | 1c7f8c5 | 2009-06-05 13:49:26 -0400 | [diff] [blame] | 1457 | case REQUEST_CURSOR_HREF: { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1458 | Message hrefMsg = (Message) msg.obj; |
Ben Murdoch | 0a784a5 | 2009-11-17 18:13:02 +0000 | [diff] [blame] | 1459 | hrefMsg.getData().putString("url", |
| 1460 | nativeRetrieveHref(msg.arg1, msg.arg2)); |
| 1461 | hrefMsg.getData().putString("title", |
| 1462 | nativeRetrieveAnchorText(msg.arg1, msg.arg2)); |
Cary Clark | 861368a | 2010-12-15 11:24:37 -0500 | [diff] [blame] | 1463 | hrefMsg.getData().putString("src", |
| 1464 | nativeRetrieveImageSource(msg.arg1, msg.arg2)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1465 | hrefMsg.sendToTarget(); |
| 1466 | break; |
| 1467 | } |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 1468 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1469 | case UPDATE_CACHE_AND_TEXT_ENTRY: |
| 1470 | nativeUpdateFrameCache(); |
| 1471 | // FIXME: this should provide a minimal rectangle |
| 1472 | if (mWebView != null) { |
| 1473 | mWebView.postInvalidate(); |
| 1474 | } |
| 1475 | sendUpdateTextEntry(); |
| 1476 | break; |
| 1477 | |
| 1478 | case DOC_HAS_IMAGES: |
| 1479 | Message imageResult = (Message) msg.obj; |
| 1480 | imageResult.arg1 = |
| 1481 | mBrowserFrame.documentHasImages() ? 1 : 0; |
| 1482 | imageResult.sendToTarget(); |
| 1483 | break; |
| 1484 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1485 | case DELETE_SELECTION: |
Leon Scroggins | 6679f2f | 2009-08-12 18:48:10 -0400 | [diff] [blame] | 1486 | TextSelectionData deleteSelectionData |
| 1487 | = (TextSelectionData) msg.obj; |
Leon Scroggins | 43488fc | 2009-07-06 14:32:49 -0400 | [diff] [blame] | 1488 | nativeDeleteSelection(deleteSelectionData.mStart, |
Leon Scroggins | 6679f2f | 2009-08-12 18:48:10 -0400 | [diff] [blame] | 1489 | deleteSelectionData.mEnd, msg.arg1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1490 | break; |
| 1491 | |
| 1492 | case SET_SELECTION: |
Cary Clark | 2f1d60c | 2009-06-03 08:05:53 -0400 | [diff] [blame] | 1493 | nativeSetSelection(msg.arg1, msg.arg2); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1494 | break; |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 1495 | |
Svetoslav Ganov | da35551 | 2010-05-12 22:04:44 -0700 | [diff] [blame] | 1496 | case MODIFY_SELECTION: |
Svetoslav Ganov | c93fb65 | 2011-01-05 18:52:05 -0800 | [diff] [blame] | 1497 | String modifiedSelectionString = nativeModifySelection(msg.arg1, |
| 1498 | msg.arg2); |
Svetoslav Ganov | 585f13f8d | 2010-08-10 07:59:15 -0700 | [diff] [blame] | 1499 | mWebView.mPrivateHandler.obtainMessage(WebView.SELECTION_STRING_CHANGED, |
Svetoslav Ganov | c93fb65 | 2011-01-05 18:52:05 -0800 | [diff] [blame] | 1500 | modifiedSelectionString).sendToTarget(); |
| 1501 | break; |
| 1502 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1503 | case LISTBOX_CHOICES: |
| 1504 | SparseBooleanArray choices = (SparseBooleanArray) |
| 1505 | msg.obj; |
| 1506 | int choicesSize = msg.arg1; |
| 1507 | boolean[] choicesArray = new boolean[choicesSize]; |
| 1508 | for (int c = 0; c < choicesSize; c++) { |
| 1509 | choicesArray[c] = choices.get(c); |
| 1510 | } |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 1511 | nativeSendListBoxChoices(choicesArray, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1512 | choicesSize); |
| 1513 | break; |
| 1514 | |
| 1515 | case SINGLE_LISTBOX_CHOICE: |
| 1516 | nativeSendListBoxChoice(msg.arg1); |
| 1517 | break; |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 1518 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1519 | case SET_BACKGROUND_COLOR: |
| 1520 | nativeSetBackgroundColor(msg.arg1); |
| 1521 | break; |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 1522 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1523 | case DUMP_DOMTREE: |
| 1524 | nativeDumpDomTree(msg.arg1 == 1); |
| 1525 | break; |
| 1526 | |
| 1527 | case DUMP_RENDERTREE: |
| 1528 | nativeDumpRenderTree(msg.arg1 == 1); |
| 1529 | break; |
| 1530 | |
| 1531 | case DUMP_NAVTREE: |
| 1532 | nativeDumpNavTree(); |
| 1533 | break; |
| 1534 | |
Feng Qian | b308137 | 2009-06-29 15:55:18 -0700 | [diff] [blame] | 1535 | case SET_JS_FLAGS: |
| 1536 | nativeSetJsFlags((String)msg.obj); |
Feng Qian | 706cee4 | 2009-08-03 16:01:42 -0700 | [diff] [blame] | 1537 | break; |
Steve Block | 4faee09 | 2009-07-28 18:20:50 +0100 | [diff] [blame] | 1538 | |
Chris Craik | 555c55e | 2011-07-28 15:39:43 -0700 | [diff] [blame] | 1539 | case CONTENT_INVALIDATE_ALL: |
| 1540 | nativeContentInvalidateAll(); |
| 1541 | break; |
| 1542 | |
Elliott Slaughter | b48fdbe | 2010-06-30 11:39:52 -0700 | [diff] [blame] | 1543 | case SAVE_WEBARCHIVE: |
| 1544 | WebView.SaveWebArchiveMessage saveMessage = |
| 1545 | (WebView.SaveWebArchiveMessage)msg.obj; |
| 1546 | saveMessage.mResultFile = |
| 1547 | saveWebArchive(saveMessage.mBasename, saveMessage.mAutoname); |
| 1548 | mWebView.mPrivateHandler.obtainMessage( |
| 1549 | WebView.SAVE_WEBARCHIVE_FINISHED, saveMessage).sendToTarget(); |
| 1550 | break; |
| 1551 | |
Steve Block | 4faee09 | 2009-07-28 18:20:50 +0100 | [diff] [blame] | 1552 | case GEOLOCATION_PERMISSIONS_PROVIDE: |
| 1553 | GeolocationPermissionsData data = |
| 1554 | (GeolocationPermissionsData) msg.obj; |
| 1555 | nativeGeolocationPermissionsProvide(data.mOrigin, |
| 1556 | data.mAllow, data.mRemember); |
Feng Qian | b308137 | 2009-06-29 15:55:18 -0700 | [diff] [blame] | 1557 | break; |
| 1558 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1559 | case SPLIT_PICTURE_SET: |
Grace Kloba | 8abd50b | 2010-07-08 15:02:14 -0700 | [diff] [blame] | 1560 | nativeSplitContent(msg.arg1); |
| 1561 | mWebView.mPrivateHandler.obtainMessage( |
| 1562 | WebView.REPLACE_BASE_CONTENT, msg.arg1, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1563 | mSplitPictureIsScheduled = false; |
| 1564 | break; |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 1565 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1566 | case CLEAR_CONTENT: |
| 1567 | // Clear the view so that onDraw() will draw nothing |
| 1568 | // but white background |
| 1569 | // (See public method WebView.clearView) |
Ben Murdoch | a62b963 | 2011-12-05 14:51:00 +0000 | [diff] [blame] | 1570 | clearContent(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1571 | break; |
Grace Kloba | b3230cb | 2009-04-13 14:04:23 -0700 | [diff] [blame] | 1572 | |
| 1573 | case MESSAGE_RELAY: |
Patrick Scott | fa8be1c | 2011-02-02 14:09:34 -0500 | [diff] [blame] | 1574 | ((Message) msg.obj).sendToTarget(); |
Grace Kloba | b3230cb | 2009-04-13 14:04:23 -0700 | [diff] [blame] | 1575 | break; |
Leon Clarke | 194e345 | 2009-09-28 11:42:12 +0100 | [diff] [blame] | 1576 | |
| 1577 | case POPULATE_VISITED_LINKS: |
| 1578 | nativeProvideVisitedHistory((String[])msg.obj); |
| 1579 | break; |
Cary Clark | 1cb97ee | 2009-12-11 12:10:36 -0500 | [diff] [blame] | 1580 | |
| 1581 | case VALID_NODE_BOUNDS: { |
| 1582 | MotionUpData motionUpData = (MotionUpData) msg.obj; |
Cary Clark | bad0c54 | 2010-01-11 14:58:21 -0500 | [diff] [blame] | 1583 | if (!nativeValidNodeAndBounds( |
Cary Clark | 1cb97ee | 2009-12-11 12:10:36 -0500 | [diff] [blame] | 1584 | motionUpData.mFrame, motionUpData.mNode, |
Cary Clark | bad0c54 | 2010-01-11 14:58:21 -0500 | [diff] [blame] | 1585 | motionUpData.mBounds)) { |
| 1586 | nativeUpdateFrameCache(); |
| 1587 | } |
Cary Clark | 1cb97ee | 2009-12-11 12:10:36 -0500 | [diff] [blame] | 1588 | Message message = mWebView.mPrivateHandler |
| 1589 | .obtainMessage(WebView.DO_MOTION_UP, |
Cary Clark | bad0c54 | 2010-01-11 14:58:21 -0500 | [diff] [blame] | 1590 | motionUpData.mX, motionUpData.mY); |
Cary Clark | 1cb97ee | 2009-12-11 12:10:36 -0500 | [diff] [blame] | 1591 | mWebView.mPrivateHandler.sendMessageAtFrontOfQueue( |
| 1592 | message); |
| 1593 | break; |
| 1594 | } |
Grace Kloba | 11438c3 | 2009-12-16 11:39:12 -0800 | [diff] [blame] | 1595 | |
| 1596 | case HIDE_FULLSCREEN: |
| 1597 | nativeFullScreenPluginHidden(msg.arg1); |
| 1598 | break; |
Andrei Popescu | a6d747d | 2010-02-11 13:19:21 +0000 | [diff] [blame] | 1599 | |
Derek Sollenberger | 281432c | 2011-08-22 14:05:49 -0400 | [diff] [blame] | 1600 | case PLUGIN_SURFACE_READY: |
| 1601 | nativePluginSurfaceReady(); |
| 1602 | break; |
| 1603 | |
Chris Craik | d0051c0 | 2011-11-29 10:26:10 -0800 | [diff] [blame] | 1604 | case NOTIFY_ANIMATION_STARTED: |
| 1605 | nativeNotifyAnimationStarted(mNativeClass); |
| 1606 | break; |
| 1607 | |
Andrei Popescu | a6d747d | 2010-02-11 13:19:21 +0000 | [diff] [blame] | 1608 | case ADD_PACKAGE_NAMES: |
| 1609 | if (BrowserFrame.sJavaBridge == null) { |
| 1610 | throw new IllegalStateException("No WebView " + |
| 1611 | "has been created in this process!"); |
| 1612 | } |
| 1613 | BrowserFrame.sJavaBridge.addPackageNames( |
| 1614 | (Set<String>) msg.obj); |
| 1615 | break; |
| 1616 | |
Grace Kloba | 178db41 | 2010-05-18 22:22:23 -0700 | [diff] [blame] | 1617 | case GET_TOUCH_HIGHLIGHT_RECTS: |
| 1618 | TouchHighlightData d = (TouchHighlightData) msg.obj; |
John Reck | 335f454 | 2011-08-25 18:25:09 -0700 | [diff] [blame] | 1619 | if (d.mNativeLayer != 0) { |
| 1620 | nativeScrollLayer(d.mNativeLayer, |
| 1621 | d.mNativeLayerRect); |
| 1622 | } |
Grace Kloba | 178db41 | 2010-05-18 22:22:23 -0700 | [diff] [blame] | 1623 | ArrayList<Rect> rects = nativeGetTouchHighlightRects |
| 1624 | (d.mX, d.mY, d.mSlop); |
| 1625 | mWebView.mPrivateHandler.obtainMessage( |
| 1626 | WebView.SET_TOUCH_HIGHLIGHT_RECTS, rects) |
| 1627 | .sendToTarget(); |
| 1628 | break; |
| 1629 | |
Steve Block | 68dede3 | 2010-08-04 10:28:46 +0100 | [diff] [blame] | 1630 | case USE_MOCK_DEVICE_ORIENTATION: |
| 1631 | useMockDeviceOrientation(); |
| 1632 | break; |
Ben Murdoch | 62275a4 | 2010-09-07 11:27:28 +0100 | [diff] [blame] | 1633 | |
| 1634 | case AUTOFILL_FORM: |
| 1635 | nativeAutoFillForm(msg.arg1); |
Ben Murdoch | 961d55f | 2010-12-02 13:58:24 +0000 | [diff] [blame] | 1636 | mWebView.mPrivateHandler.obtainMessage(WebView.AUTOFILL_COMPLETE, null) |
| 1637 | .sendToTarget(); |
Ben Murdoch | 62275a4 | 2010-09-07 11:27:28 +0100 | [diff] [blame] | 1638 | break; |
Narayan Kamath | 9497c5f | 2011-02-22 12:05:34 +0000 | [diff] [blame] | 1639 | |
| 1640 | case EXECUTE_JS: |
| 1641 | if (msg.obj instanceof String) { |
| 1642 | if (DebugFlags.WEB_VIEW_CORE) { |
| 1643 | Log.d(LOGTAG, "Executing JS : " + msg.obj); |
| 1644 | } |
| 1645 | mBrowserFrame.stringByEvaluatingJavaScriptFromString((String) msg.obj); |
| 1646 | } |
| 1647 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1648 | } |
| 1649 | } |
| 1650 | }; |
| 1651 | // Take all queued messages and resend them to the new handler. |
| 1652 | synchronized (this) { |
| 1653 | int size = mMessages.size(); |
| 1654 | for (int i = 0; i < size; i++) { |
| 1655 | mHandler.sendMessage(mMessages.get(i)); |
| 1656 | } |
| 1657 | mMessages = null; |
| 1658 | } |
| 1659 | } |
| 1660 | |
| 1661 | /** |
| 1662 | * Send a message internally to the queue or to the handler |
| 1663 | */ |
| 1664 | private synchronized void sendMessage(Message msg) { |
| 1665 | if (mBlockMessages) { |
| 1666 | return; |
| 1667 | } |
| 1668 | if (mMessages != null) { |
| 1669 | mMessages.add(msg); |
| 1670 | } else { |
| 1671 | mHandler.sendMessage(msg); |
| 1672 | } |
| 1673 | } |
| 1674 | |
| 1675 | private synchronized void removeMessages(int what) { |
| 1676 | if (mBlockMessages) { |
| 1677 | return; |
| 1678 | } |
| 1679 | if (what == EventHub.WEBKIT_DRAW) { |
| 1680 | mDrawIsScheduled = false; |
| 1681 | } |
| 1682 | if (mMessages != null) { |
Steve Block | 7b65a3e | 2011-08-30 13:52:51 +0100 | [diff] [blame] | 1683 | Throwable throwable = new Throwable( |
| 1684 | "EventHub.removeMessages(int what = " + what + ") is not supported " + |
| 1685 | "before the WebViewCore is set up."); |
| 1686 | Log.w(LOGTAG, Log.getStackTraceString(throwable)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1687 | } else { |
| 1688 | mHandler.removeMessages(what); |
| 1689 | } |
| 1690 | } |
| 1691 | |
| 1692 | private synchronized void sendMessageDelayed(Message msg, long delay) { |
| 1693 | if (mBlockMessages) { |
| 1694 | return; |
| 1695 | } |
| 1696 | mHandler.sendMessageDelayed(msg, delay); |
| 1697 | } |
| 1698 | |
| 1699 | /** |
| 1700 | * Send a message internally to the front of the queue. |
| 1701 | */ |
| 1702 | private synchronized void sendMessageAtFrontOfQueue(Message msg) { |
| 1703 | if (mBlockMessages) { |
| 1704 | return; |
| 1705 | } |
| 1706 | if (mMessages != null) { |
| 1707 | mMessages.add(0, msg); |
| 1708 | } else { |
| 1709 | mHandler.sendMessageAtFrontOfQueue(msg); |
| 1710 | } |
| 1711 | } |
| 1712 | |
| 1713 | /** |
| 1714 | * Remove all the messages. |
| 1715 | */ |
| 1716 | private synchronized void removeMessages() { |
| 1717 | // reset mDrawIsScheduled flag as WEBKIT_DRAW may be removed |
| 1718 | mDrawIsScheduled = false; |
| 1719 | mSplitPictureIsScheduled = false; |
| 1720 | if (mMessages != null) { |
| 1721 | mMessages.clear(); |
| 1722 | } else { |
| 1723 | mHandler.removeCallbacksAndMessages(null); |
| 1724 | } |
| 1725 | } |
| 1726 | |
| 1727 | /** |
| 1728 | * Block sending messages to the EventHub. |
| 1729 | */ |
| 1730 | private synchronized void blockMessages() { |
| 1731 | mBlockMessages = true; |
| 1732 | } |
| 1733 | } |
| 1734 | |
| 1735 | //------------------------------------------------------------------------- |
| 1736 | // Methods called by host activity (in the same thread) |
| 1737 | //------------------------------------------------------------------------- |
| 1738 | |
| 1739 | void stopLoading() { |
Derek Sollenberger | 2e5c150 | 2009-06-03 10:44:42 -0400 | [diff] [blame] | 1740 | if (DebugFlags.WEB_VIEW_CORE) Log.v(LOGTAG, "CORE stopLoading"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1741 | if (mBrowserFrame != null) { |
| 1742 | mBrowserFrame.stopLoading(); |
| 1743 | } |
| 1744 | } |
| 1745 | |
| 1746 | //------------------------------------------------------------------------- |
| 1747 | // Methods called by WebView |
| 1748 | // If it refers to local variable, it needs synchronized(). |
| 1749 | // If it needs WebCore, it has to send message. |
| 1750 | //------------------------------------------------------------------------- |
| 1751 | |
Dounia Berrada | 940a198 | 2011-04-27 13:53:13 -0700 | [diff] [blame] | 1752 | /** |
| 1753 | * @hide |
| 1754 | */ |
| 1755 | public void sendMessage(Message msg) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1756 | mEventHub.sendMessage(msg); |
| 1757 | } |
| 1758 | |
| 1759 | void sendMessage(int what) { |
| 1760 | mEventHub.sendMessage(Message.obtain(null, what)); |
| 1761 | } |
| 1762 | |
| 1763 | void sendMessage(int what, Object obj) { |
| 1764 | mEventHub.sendMessage(Message.obtain(null, what, obj)); |
| 1765 | } |
| 1766 | |
| 1767 | void sendMessage(int what, int arg1) { |
| 1768 | // just ignore the second argument (make it 0) |
| 1769 | mEventHub.sendMessage(Message.obtain(null, what, arg1, 0)); |
| 1770 | } |
| 1771 | |
| 1772 | void sendMessage(int what, int arg1, int arg2) { |
| 1773 | mEventHub.sendMessage(Message.obtain(null, what, arg1, arg2)); |
| 1774 | } |
| 1775 | |
| 1776 | void sendMessage(int what, int arg1, Object obj) { |
| 1777 | // just ignore the second argument (make it 0) |
| 1778 | mEventHub.sendMessage(Message.obtain(null, what, arg1, 0, obj)); |
| 1779 | } |
| 1780 | |
| 1781 | void sendMessage(int what, int arg1, int arg2, Object obj) { |
| 1782 | mEventHub.sendMessage(Message.obtain(null, what, arg1, arg2, obj)); |
| 1783 | } |
| 1784 | |
Cary Clark | 1cb97ee | 2009-12-11 12:10:36 -0500 | [diff] [blame] | 1785 | void sendMessageAtFrontOfQueue(int what, Object obj) { |
| 1786 | mEventHub.sendMessageAtFrontOfQueue(Message.obtain( |
| 1787 | null, what, obj)); |
| 1788 | } |
| 1789 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1790 | void sendMessageDelayed(int what, Object obj, long delay) { |
| 1791 | mEventHub.sendMessageDelayed(Message.obtain(null, what, obj), delay); |
| 1792 | } |
| 1793 | |
| 1794 | void removeMessages(int what) { |
| 1795 | mEventHub.removeMessages(what); |
| 1796 | } |
| 1797 | |
| 1798 | void removeMessages() { |
| 1799 | mEventHub.removeMessages(); |
| 1800 | } |
| 1801 | |
| 1802 | /** |
John Reck | 00d5bf7 | 2011-07-21 09:46:17 -0700 | [diff] [blame] | 1803 | * Sends a DESTROY message to WebCore. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1804 | * Called from UI thread. |
| 1805 | */ |
| 1806 | void destroy() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1807 | synchronized (mEventHub) { |
John Reck | 00d5bf7 | 2011-07-21 09:46:17 -0700 | [diff] [blame] | 1808 | // Do not call removeMessages as then we risk removing PAUSE_TIMERS |
| 1809 | // or RESUME_TIMERS messages, which we must still handle as they |
| 1810 | // are per process. DESTROY will instead trigger a white list in |
| 1811 | // mEventHub, skipping any remaining messages in the queue |
John Reck | 45576fa | 2011-09-01 11:45:35 -0700 | [diff] [blame] | 1812 | mEventHub.mDestroying = true; |
| 1813 | mEventHub.sendMessage( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1814 | Message.obtain(null, EventHub.DESTROY)); |
| 1815 | mEventHub.blockMessages(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1816 | } |
| 1817 | } |
| 1818 | |
| 1819 | //------------------------------------------------------------------------- |
| 1820 | // WebViewCore private methods |
| 1821 | //------------------------------------------------------------------------- |
| 1822 | |
Derek Sollenberger | e0155e9 | 2009-06-10 15:35:45 -0400 | [diff] [blame] | 1823 | private void clearCache(boolean includeDiskFiles) { |
| 1824 | mBrowserFrame.clearCache(); |
Kristian Monsen | cedb3a7 | 2011-01-20 12:42:16 +0000 | [diff] [blame] | 1825 | if (includeDiskFiles) { |
Derek Sollenberger | e0155e9 | 2009-06-10 15:35:45 -0400 | [diff] [blame] | 1826 | CacheManager.removeAllCacheFiles(); |
| 1827 | } |
| 1828 | } |
| 1829 | |
Grace Kloba | d0d9bc2 | 2010-01-26 18:08:28 -0800 | [diff] [blame] | 1830 | private void loadUrl(String url, Map<String, String> extraHeaders) { |
Derek Sollenberger | 2e5c150 | 2009-06-03 10:44:42 -0400 | [diff] [blame] | 1831 | if (DebugFlags.WEB_VIEW_CORE) Log.v(LOGTAG, " CORE loadUrl " + url); |
Grace Kloba | d0d9bc2 | 2010-01-26 18:08:28 -0800 | [diff] [blame] | 1832 | mBrowserFrame.loadUrl(url, extraHeaders); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1833 | } |
| 1834 | |
Elliott Slaughter | b48fdbe | 2010-06-30 11:39:52 -0700 | [diff] [blame] | 1835 | private String saveWebArchive(String filename, boolean autoname) { |
| 1836 | if (DebugFlags.WEB_VIEW_CORE) { |
| 1837 | Log.v(LOGTAG, " CORE saveWebArchive " + filename + " " + autoname); |
| 1838 | } |
| 1839 | return mBrowserFrame.saveWebArchive(filename, autoname); |
| 1840 | } |
| 1841 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1842 | private void key(KeyEvent evt, boolean isDown) { |
Derek Sollenberger | 2e5c150 | 2009-06-03 10:44:42 -0400 | [diff] [blame] | 1843 | if (DebugFlags.WEB_VIEW_CORE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1844 | Log.v(LOGTAG, "CORE key at " + System.currentTimeMillis() + ", " |
| 1845 | + evt); |
| 1846 | } |
Leon Scroggins | e322567 | 2009-06-03 15:53:13 -0400 | [diff] [blame] | 1847 | int keyCode = evt.getKeyCode(); |
Derek Sollenberger | ff0f973 | 2010-08-06 11:50:49 -0400 | [diff] [blame] | 1848 | int unicodeChar = evt.getUnicodeChar(); |
| 1849 | |
| 1850 | if (keyCode == KeyEvent.KEYCODE_UNKNOWN && evt.getCharacters() != null |
| 1851 | && evt.getCharacters().length() > 0) { |
| 1852 | // we should only receive individual complex characters |
| 1853 | unicodeChar = evt.getCharacters().codePointAt(0); |
| 1854 | } |
| 1855 | |
| 1856 | if (!nativeKey(keyCode, unicodeChar, evt.getRepeatCount(), evt.isShiftPressed(), |
| 1857 | evt.isAltPressed(), evt.isSymPressed(), |
Leon Scroggins | e322567 | 2009-06-03 15:53:13 -0400 | [diff] [blame] | 1858 | isDown) && keyCode != KeyEvent.KEYCODE_ENTER) { |
Cary Clark | 215b72c | 2009-06-26 14:38:43 -0400 | [diff] [blame] | 1859 | if (keyCode >= KeyEvent.KEYCODE_DPAD_UP |
| 1860 | && keyCode <= KeyEvent.KEYCODE_DPAD_RIGHT) { |
| 1861 | if (DebugFlags.WEB_VIEW_CORE) { |
Leon Scroggins | 9ab32b6 | 2010-05-03 14:19:50 +0100 | [diff] [blame] | 1862 | Log.v(LOGTAG, "key: arrow unused by page: " + keyCode); |
Cary Clark | 215b72c | 2009-06-26 14:38:43 -0400 | [diff] [blame] | 1863 | } |
| 1864 | if (mWebView != null && evt.isDown()) { |
| 1865 | Message.obtain(mWebView.mPrivateHandler, |
Leon Scroggins | 9ab32b6 | 2010-05-03 14:19:50 +0100 | [diff] [blame] | 1866 | WebView.UNHANDLED_NAV_KEY, keyCode, |
| 1867 | 0).sendToTarget(); |
Cary Clark | 215b72c | 2009-06-26 14:38:43 -0400 | [diff] [blame] | 1868 | } |
| 1869 | return; |
| 1870 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1871 | // bubble up the event handling |
Leon Scroggins | e322567 | 2009-06-03 15:53:13 -0400 | [diff] [blame] | 1872 | // but do not bubble up the ENTER key, which would open the search |
| 1873 | // bar without any text. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1874 | mCallbackProxy.onUnhandledKeyEvent(evt); |
| 1875 | } |
| 1876 | } |
| 1877 | |
| 1878 | // These values are used to avoid requesting a layout based on old values |
| 1879 | private int mCurrentViewWidth = 0; |
| 1880 | private int mCurrentViewHeight = 0; |
Grace Kloba | ef347ef | 2009-07-30 11:20:32 -0700 | [diff] [blame] | 1881 | private float mCurrentViewScale = 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1882 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1883 | // notify webkit that our virtual view size changed size (after inv-zoom) |
Shimeng (Simon) Wang | 48fc909 | 2011-02-03 14:29:54 -0800 | [diff] [blame] | 1884 | private void viewSizeChanged(WebView.ViewSizeData data) { |
| 1885 | int w = data.mWidth; |
| 1886 | int h = data.mHeight; |
| 1887 | int textwrapWidth = data.mTextWrapWidth; |
| 1888 | float scale = data.mScale; |
Grace Kloba | ef347ef | 2009-07-30 11:20:32 -0700 | [diff] [blame] | 1889 | if (DebugFlags.WEB_VIEW_CORE) { |
| 1890 | Log.v(LOGTAG, "viewSizeChanged w=" + w + "; h=" + h |
| 1891 | + "; textwrapWidth=" + textwrapWidth + "; scale=" + scale); |
| 1892 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1893 | if (w == 0) { |
| 1894 | Log.w(LOGTAG, "skip viewSizeChanged as w is 0"); |
| 1895 | return; |
| 1896 | } |
Shimeng (Simon) Wang | 24a252e | 2011-05-24 15:00:52 -0700 | [diff] [blame] | 1897 | int width = calculateWindowWidth(w); |
Shimeng (Simon) Wang | a0cc864 | 2011-02-03 10:24:03 -0800 | [diff] [blame] | 1898 | int height = h; |
| 1899 | if (width != w) { |
Shimeng (Simon) Wang | 48fc909 | 2011-02-03 14:29:54 -0800 | [diff] [blame] | 1900 | float heightWidthRatio = data.mHeightWidthRatio; |
Shimeng (Simon) Wang | a0cc864 | 2011-02-03 10:24:03 -0800 | [diff] [blame] | 1901 | float ratio = (heightWidthRatio > 0) ? heightWidthRatio : (float) h / w; |
| 1902 | height = Math.round(ratio * width); |
| 1903 | } |
Shimeng (Simon) Wang | 48fc909 | 2011-02-03 14:29:54 -0800 | [diff] [blame] | 1904 | nativeSetSize(width, height, textwrapWidth, scale, w, |
| 1905 | data.mActualViewHeight > 0 ? data.mActualViewHeight : h, |
| 1906 | data.mAnchorX, data.mAnchorY, data.mIgnoreHeight); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1907 | // Remember the current width and height |
| 1908 | boolean needInvalidate = (mCurrentViewWidth == 0); |
| 1909 | mCurrentViewWidth = w; |
| 1910 | mCurrentViewHeight = h; |
Grace Kloba | ef347ef | 2009-07-30 11:20:32 -0700 | [diff] [blame] | 1911 | mCurrentViewScale = scale; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1912 | if (needInvalidate) { |
| 1913 | // ensure {@link #webkitDraw} is called as we were blocking in |
| 1914 | // {@link #contentDraw} when mCurrentViewWidth is 0 |
Derek Sollenberger | 2e5c150 | 2009-06-03 10:44:42 -0400 | [diff] [blame] | 1915 | if (DebugFlags.WEB_VIEW_CORE) Log.v(LOGTAG, "viewSizeChanged"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1916 | contentDraw(); |
| 1917 | } |
| 1918 | mEventHub.sendMessage(Message.obtain(null, |
| 1919 | EventHub.UPDATE_CACHE_AND_TEXT_ENTRY)); |
| 1920 | } |
| 1921 | |
Shimeng (Simon) Wang | f7107d7 | 2011-02-18 15:27:28 -0800 | [diff] [blame] | 1922 | // Calculate width to be used in webkit window. |
Shimeng (Simon) Wang | 24a252e | 2011-05-24 15:00:52 -0700 | [diff] [blame] | 1923 | private int calculateWindowWidth(int viewWidth) { |
Shimeng (Simon) Wang | f7107d7 | 2011-02-18 15:27:28 -0800 | [diff] [blame] | 1924 | int width = viewWidth; |
| 1925 | if (mSettings.getUseWideViewPort()) { |
| 1926 | if (mViewportWidth == -1) { |
Shimeng (Simon) Wang | 24a252e | 2011-05-24 15:00:52 -0700 | [diff] [blame] | 1927 | // Fixed viewport width. |
| 1928 | width = WebView.DEFAULT_VIEWPORT_WIDTH; |
Shimeng (Simon) Wang | f7107d7 | 2011-02-18 15:27:28 -0800 | [diff] [blame] | 1929 | } else if (mViewportWidth > 0) { |
Shimeng (Simon) Wang | 24a252e | 2011-05-24 15:00:52 -0700 | [diff] [blame] | 1930 | // Use website specified or desired fixed viewport width. |
| 1931 | width = mViewportWidth; |
Shimeng (Simon) Wang | f7107d7 | 2011-02-18 15:27:28 -0800 | [diff] [blame] | 1932 | } else { |
Shimeng (Simon) Wang | 24a252e | 2011-05-24 15:00:52 -0700 | [diff] [blame] | 1933 | // For mobile web site. |
Shimeng (Simon) Wang | 82a0770 | 2011-06-09 15:57:11 -0700 | [diff] [blame] | 1934 | width = Math.round(mWebView.getViewWidth() / mWebView.getDefaultZoomScale()); |
Shimeng (Simon) Wang | f7107d7 | 2011-02-18 15:27:28 -0800 | [diff] [blame] | 1935 | } |
| 1936 | } |
| 1937 | return width; |
| 1938 | } |
| 1939 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1940 | private void sendUpdateTextEntry() { |
| 1941 | if (mWebView != null) { |
| 1942 | Message.obtain(mWebView.mPrivateHandler, |
| 1943 | WebView.UPDATE_TEXT_ENTRY_MSG_ID).sendToTarget(); |
| 1944 | } |
| 1945 | } |
| 1946 | |
Andrei Popescu | 59e2ad9 | 2009-07-28 13:38:06 +0100 | [diff] [blame] | 1947 | // Utility method for exceededDatabaseQuota and reachedMaxAppCacheSize |
| 1948 | // callbacks. Computes the sum of database quota for all origins. |
| 1949 | private long getUsedQuota() { |
| 1950 | WebStorage webStorage = WebStorage.getInstance(); |
Nicolas Roard | 6c24b4d | 2009-09-22 18:44:52 +0100 | [diff] [blame] | 1951 | Collection<WebStorage.Origin> origins = webStorage.getOriginsSync(); |
| 1952 | |
Andrei Popescu | 59e2ad9 | 2009-07-28 13:38:06 +0100 | [diff] [blame] | 1953 | if (origins == null) { |
| 1954 | return 0; |
| 1955 | } |
| 1956 | long usedQuota = 0; |
Nicolas Roard | 6c24b4d | 2009-09-22 18:44:52 +0100 | [diff] [blame] | 1957 | for (WebStorage.Origin website : origins) { |
| 1958 | usedQuota += website.getQuota(); |
Andrei Popescu | 59e2ad9 | 2009-07-28 13:38:06 +0100 | [diff] [blame] | 1959 | } |
| 1960 | return usedQuota; |
| 1961 | } |
| 1962 | |
Grace Kloba | 8abd50b | 2010-07-08 15:02:14 -0700 | [diff] [blame] | 1963 | // called from UI thread |
| 1964 | void splitContent(int content) { |
| 1965 | if (!mSplitPictureIsScheduled) { |
| 1966 | mSplitPictureIsScheduled = true; |
| 1967 | sendMessage(EventHub.SPLIT_PICTURE_SET, content, 0); |
| 1968 | } |
| 1969 | } |
| 1970 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1971 | // Used to avoid posting more than one draw message. |
| 1972 | private boolean mDrawIsScheduled; |
Nicolas Roard | fb7bc34 | 2010-11-01 15:08:03 -0700 | [diff] [blame] | 1973 | private boolean mDrawLayersIsScheduled; |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 1974 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1975 | // Used to avoid posting more than one split picture message. |
| 1976 | private boolean mSplitPictureIsScheduled; |
| 1977 | |
Grace Kloba | a7bc87c | 2010-01-29 14:56:25 -0800 | [diff] [blame] | 1978 | // Used to suspend drawing. |
| 1979 | private boolean mDrawIsPaused; |
| 1980 | |
Derek Sollenberger | b983c89 | 2010-06-28 08:38:28 -0400 | [diff] [blame] | 1981 | // mInitialViewState is set by didFirstLayout() and then reset in the |
| 1982 | // next webkitDraw after passing the state to the UI thread. |
| 1983 | private ViewState mInitialViewState = null; |
Shimeng (Simon) Wang | 72a1d2e | 2011-06-30 13:36:53 -0700 | [diff] [blame] | 1984 | private boolean mFirstLayoutForNonStandardLoad; |
Grace Kloba | ef347ef | 2009-07-30 11:20:32 -0700 | [diff] [blame] | 1985 | |
Derek Sollenberger | b983c89 | 2010-06-28 08:38:28 -0400 | [diff] [blame] | 1986 | static class ViewState { |
Grace Kloba | ef347ef | 2009-07-30 11:20:32 -0700 | [diff] [blame] | 1987 | float mMinScale; |
| 1988 | float mMaxScale; |
| 1989 | float mViewScale; |
| 1990 | float mTextWrapScale; |
Grace Kloba | 408cf85 | 2009-09-20 16:34:44 -0700 | [diff] [blame] | 1991 | float mDefaultScale; |
Grace Kloba | ef347ef | 2009-07-30 11:20:32 -0700 | [diff] [blame] | 1992 | int mScrollX; |
| 1993 | int mScrollY; |
Leon Scroggins | b235926 | 2009-08-19 16:19:26 -0400 | [diff] [blame] | 1994 | boolean mMobileSite; |
Shimeng (Simon) Wang | 96fcb87 | 2010-11-24 16:01:12 -0800 | [diff] [blame] | 1995 | boolean mIsRestored; |
George Mount | e263bc1 | 2011-10-31 13:49:03 -0700 | [diff] [blame] | 1996 | boolean mShouldStartScrolledRight; |
Grace Kloba | ef347ef | 2009-07-30 11:20:32 -0700 | [diff] [blame] | 1997 | } |
| 1998 | |
| 1999 | static class DrawData { |
| 2000 | DrawData() { |
Grace Kloba | 8abd50b | 2010-07-08 15:02:14 -0700 | [diff] [blame] | 2001 | mBaseLayer = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2002 | mInvalRegion = new Region(); |
Derek Sollenberger | 7e6bf6f | 2010-10-28 09:33:47 -0400 | [diff] [blame] | 2003 | mContentSize = new Point(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2004 | } |
Grace Kloba | 8abd50b | 2010-07-08 15:02:14 -0700 | [diff] [blame] | 2005 | int mBaseLayer; |
Grace Kloba | ef347ef | 2009-07-30 11:20:32 -0700 | [diff] [blame] | 2006 | Region mInvalRegion; |
Derek Sollenberger | 7e6bf6f | 2010-10-28 09:33:47 -0400 | [diff] [blame] | 2007 | // view size that was used by webkit during the most recent layout |
| 2008 | Point mViewSize; |
| 2009 | Point mContentSize; |
Grace Kloba | 188bf8d | 2010-04-07 11:30:19 -0700 | [diff] [blame] | 2010 | int mMinPrefWidth; |
Derek Sollenberger | b983c89 | 2010-06-28 08:38:28 -0400 | [diff] [blame] | 2011 | // only non-null if it is for the first picture set after the first layout |
| 2012 | ViewState mViewState; |
Shimeng (Simon) Wang | 72a1d2e | 2011-06-30 13:36:53 -0700 | [diff] [blame] | 2013 | boolean mFirstLayoutForNonStandardLoad; |
Cary Clark | 5da9aeb | 2009-10-06 17:40:53 -0400 | [diff] [blame] | 2014 | boolean mFocusSizeChanged; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2015 | } |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 2016 | |
Nicolas Roard | dc221e0 | 2011-10-04 17:57:59 -0700 | [diff] [blame] | 2017 | DrawData mLastDrawData = null; |
| 2018 | |
Nicolas Roard | fb7bc34 | 2010-11-01 15:08:03 -0700 | [diff] [blame] | 2019 | // Only update the layers' content, not the base surface |
| 2020 | // PictureSet. |
| 2021 | private void webkitDrawLayers() { |
| 2022 | mDrawLayersIsScheduled = false; |
Nicolas Roard | dc221e0 | 2011-10-04 17:57:59 -0700 | [diff] [blame] | 2023 | if (mDrawIsScheduled || mLastDrawData == null) { |
Nicolas Roard | fb7bc34 | 2010-11-01 15:08:03 -0700 | [diff] [blame] | 2024 | removeMessages(EventHub.WEBKIT_DRAW); |
| 2025 | webkitDraw(); |
| 2026 | return; |
| 2027 | } |
Nicolas Roard | dc221e0 | 2011-10-04 17:57:59 -0700 | [diff] [blame] | 2028 | // Directly update the layers we last passed to the UI side |
Chris Craik | d0051c0 | 2011-11-29 10:26:10 -0800 | [diff] [blame] | 2029 | if (nativeUpdateLayers(mNativeClass, mLastDrawData.mBaseLayer)) { |
Nicolas Roard | dc221e0 | 2011-10-04 17:57:59 -0700 | [diff] [blame] | 2030 | // If anything more complex than position has been touched, let's do a full draw |
| 2031 | webkitDraw(); |
Nicolas Roard | dc221e0 | 2011-10-04 17:57:59 -0700 | [diff] [blame] | 2032 | } |
Nicolas Roard | dee7b1b | 2011-10-06 17:12:40 -0700 | [diff] [blame] | 2033 | mWebView.mPrivateHandler.removeMessages(WebView.INVAL_RECT_MSG_ID); |
| 2034 | mWebView.mPrivateHandler.sendMessageAtFrontOfQueue(mWebView.mPrivateHandler |
| 2035 | .obtainMessage(WebView.INVAL_RECT_MSG_ID)); |
Nicolas Roard | fb7bc34 | 2010-11-01 15:08:03 -0700 | [diff] [blame] | 2036 | } |
| 2037 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2038 | private void webkitDraw() { |
| 2039 | mDrawIsScheduled = false; |
| 2040 | DrawData draw = new DrawData(); |
Derek Sollenberger | 2e5c150 | 2009-06-03 10:44:42 -0400 | [diff] [blame] | 2041 | if (DebugFlags.WEB_VIEW_CORE) Log.v(LOGTAG, "webkitDraw start"); |
Derek Sollenberger | 7e6bf6f | 2010-10-28 09:33:47 -0400 | [diff] [blame] | 2042 | draw.mBaseLayer = nativeRecordContent(draw.mInvalRegion, draw.mContentSize); |
Grace Kloba | 8abd50b | 2010-07-08 15:02:14 -0700 | [diff] [blame] | 2043 | if (draw.mBaseLayer == 0) { |
John Reck | 1c1e6df | 2011-06-24 11:07:09 -0700 | [diff] [blame] | 2044 | if (mWebView != null && !mWebView.isPaused()) { |
| 2045 | if (DebugFlags.WEB_VIEW_CORE) Log.v(LOGTAG, "webkitDraw abort, resending draw message"); |
| 2046 | mEventHub.sendMessage(Message.obtain(null, EventHub.WEBKIT_DRAW)); |
| 2047 | } else { |
| 2048 | if (DebugFlags.WEB_VIEW_CORE) Log.v(LOGTAG, "webkitDraw abort, webview paused"); |
| 2049 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2050 | return; |
| 2051 | } |
Nicolas Roard | dc221e0 | 2011-10-04 17:57:59 -0700 | [diff] [blame] | 2052 | mLastDrawData = draw; |
Nicolas Roard | fb7bc34 | 2010-11-01 15:08:03 -0700 | [diff] [blame] | 2053 | webkitDraw(draw); |
| 2054 | } |
| 2055 | |
| 2056 | private void webkitDraw(DrawData draw) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2057 | if (mWebView != null) { |
Cary Clark | 5da9aeb | 2009-10-06 17:40:53 -0400 | [diff] [blame] | 2058 | draw.mFocusSizeChanged = nativeFocusBoundsChanged(); |
Derek Sollenberger | 7e6bf6f | 2010-10-28 09:33:47 -0400 | [diff] [blame] | 2059 | draw.mViewSize = new Point(mCurrentViewWidth, mCurrentViewHeight); |
Grace Kloba | 188bf8d | 2010-04-07 11:30:19 -0700 | [diff] [blame] | 2060 | if (mSettings.getUseWideViewPort()) { |
| 2061 | draw.mMinPrefWidth = Math.max( |
| 2062 | mViewportWidth == -1 ? WebView.DEFAULT_VIEWPORT_WIDTH |
| 2063 | : (mViewportWidth == 0 ? mCurrentViewWidth |
| 2064 | : mViewportWidth), |
| 2065 | nativeGetContentMinPrefWidth()); |
| 2066 | } |
Derek Sollenberger | b983c89 | 2010-06-28 08:38:28 -0400 | [diff] [blame] | 2067 | if (mInitialViewState != null) { |
| 2068 | draw.mViewState = mInitialViewState; |
| 2069 | mInitialViewState = null; |
Grace Kloba | ef347ef | 2009-07-30 11:20:32 -0700 | [diff] [blame] | 2070 | } |
Shimeng (Simon) Wang | 72a1d2e | 2011-06-30 13:36:53 -0700 | [diff] [blame] | 2071 | if (mFirstLayoutForNonStandardLoad) { |
| 2072 | draw.mFirstLayoutForNonStandardLoad = true; |
| 2073 | mFirstLayoutForNonStandardLoad = false; |
| 2074 | } |
Derek Sollenberger | 2e5c150 | 2009-06-03 10:44:42 -0400 | [diff] [blame] | 2075 | if (DebugFlags.WEB_VIEW_CORE) Log.v(LOGTAG, "webkitDraw NEW_PICTURE_MSG_ID"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2076 | Message.obtain(mWebView.mPrivateHandler, |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 2077 | WebView.NEW_PICTURE_MSG_ID, draw).sendToTarget(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2078 | } |
| 2079 | } |
| 2080 | |
Grace Kloba | a7bc87c | 2010-01-29 14:56:25 -0800 | [diff] [blame] | 2081 | static void reducePriority() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2082 | // remove the pending REDUCE_PRIORITY and RESUME_PRIORITY messages |
| 2083 | sWebCoreHandler.removeMessages(WebCoreThread.REDUCE_PRIORITY); |
| 2084 | sWebCoreHandler.removeMessages(WebCoreThread.RESUME_PRIORITY); |
| 2085 | sWebCoreHandler.sendMessageAtFrontOfQueue(sWebCoreHandler |
| 2086 | .obtainMessage(WebCoreThread.REDUCE_PRIORITY)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2087 | } |
| 2088 | |
Grace Kloba | a7bc87c | 2010-01-29 14:56:25 -0800 | [diff] [blame] | 2089 | static void resumePriority() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2090 | // remove the pending REDUCE_PRIORITY and RESUME_PRIORITY messages |
| 2091 | sWebCoreHandler.removeMessages(WebCoreThread.REDUCE_PRIORITY); |
| 2092 | sWebCoreHandler.removeMessages(WebCoreThread.RESUME_PRIORITY); |
| 2093 | sWebCoreHandler.sendMessageAtFrontOfQueue(sWebCoreHandler |
| 2094 | .obtainMessage(WebCoreThread.RESUME_PRIORITY)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2095 | } |
| 2096 | |
Kristian Monsen | d4819a7 | 2010-12-16 17:42:57 +0000 | [diff] [blame] | 2097 | static void sendStaticMessage(int messageType, Object argument) { |
| 2098 | if (sWebCoreHandler == null) |
| 2099 | return; |
| 2100 | |
| 2101 | sWebCoreHandler.sendMessage(sWebCoreHandler.obtainMessage(messageType, argument)); |
| 2102 | } |
| 2103 | |
Grace Kloba | a7bc87c | 2010-01-29 14:56:25 -0800 | [diff] [blame] | 2104 | static void pauseUpdatePicture(WebViewCore core) { |
| 2105 | // Note: there is one possible failure mode. If pauseUpdatePicture() is |
| 2106 | // called from UI thread while WEBKIT_DRAW is just pulled out of the |
| 2107 | // queue in WebCore thread to be executed. Then update won't be blocked. |
| 2108 | if (core != null) { |
Grace Kloba | f9b731d | 2010-06-21 19:23:57 -0700 | [diff] [blame] | 2109 | if (!core.getSettings().enableSmoothTransition()) return; |
| 2110 | |
Grace Kloba | a7bc87c | 2010-01-29 14:56:25 -0800 | [diff] [blame] | 2111 | synchronized (core) { |
John Reck | 2f4d30a | 2011-09-13 15:50:41 -0700 | [diff] [blame] | 2112 | if (core.mNativeClass == 0) { |
| 2113 | Log.w(LOGTAG, "Cannot pauseUpdatePicture, core destroyed or not initialized!"); |
| 2114 | return; |
| 2115 | } |
Chris Craik | 58d94af | 2011-08-18 11:42:13 -0700 | [diff] [blame] | 2116 | core.nativeSetIsPaused(true); |
Grace Kloba | a7bc87c | 2010-01-29 14:56:25 -0800 | [diff] [blame] | 2117 | core.mDrawIsPaused = true; |
Grace Kloba | a7bc87c | 2010-01-29 14:56:25 -0800 | [diff] [blame] | 2118 | } |
| 2119 | } |
| 2120 | |
| 2121 | } |
| 2122 | |
| 2123 | static void resumeUpdatePicture(WebViewCore core) { |
| 2124 | if (core != null) { |
Grace Kloba | f9b731d | 2010-06-21 19:23:57 -0700 | [diff] [blame] | 2125 | // if mDrawIsPaused is true, ignore the setting, continue to resume |
Chris Craik | 58d94af | 2011-08-18 11:42:13 -0700 | [diff] [blame] | 2126 | if (!core.mDrawIsPaused) |
| 2127 | return; |
Grace Kloba | f9b731d | 2010-06-21 19:23:57 -0700 | [diff] [blame] | 2128 | |
Grace Kloba | a7bc87c | 2010-01-29 14:56:25 -0800 | [diff] [blame] | 2129 | synchronized (core) { |
John Reck | 2f4d30a | 2011-09-13 15:50:41 -0700 | [diff] [blame] | 2130 | if (core.mNativeClass == 0) { |
| 2131 | Log.w(LOGTAG, "Cannot resumeUpdatePicture, core destroyed!"); |
| 2132 | return; |
| 2133 | } |
Chris Craik | 58d94af | 2011-08-18 11:42:13 -0700 | [diff] [blame] | 2134 | core.nativeSetIsPaused(false); |
Grace Kloba | a7bc87c | 2010-01-29 14:56:25 -0800 | [diff] [blame] | 2135 | core.mDrawIsPaused = false; |
Cary Clark | 75796bb | 2010-08-24 14:59:58 -0400 | [diff] [blame] | 2136 | // always redraw on resume to reenable gif animations |
| 2137 | core.mDrawIsScheduled = false; |
Grace Kloba | a7bc87c | 2010-01-29 14:56:25 -0800 | [diff] [blame] | 2138 | } |
| 2139 | } |
| 2140 | } |
| 2141 | |
Adam Powell | e00e8a78 | 2011-09-11 17:48:42 -0700 | [diff] [blame] | 2142 | static boolean isUpdatePicturePaused(WebViewCore core) { |
| 2143 | return core != null ? core.mDrawIsPaused : false; |
| 2144 | } |
| 2145 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2146 | ////////////////////////////////////////////////////////////////////////// |
| 2147 | |
| 2148 | private void restoreState(int index) { |
| 2149 | WebBackForwardList list = mCallbackProxy.getBackForwardList(); |
| 2150 | int size = list.getSize(); |
| 2151 | for (int i = 0; i < size; i++) { |
| 2152 | list.getItemAtIndex(i).inflate(mBrowserFrame.mNativeFrame); |
| 2153 | } |
| 2154 | mBrowserFrame.mLoadInitFromJava = true; |
| 2155 | list.restoreIndex(mBrowserFrame.mNativeFrame, index); |
| 2156 | mBrowserFrame.mLoadInitFromJava = false; |
| 2157 | } |
| 2158 | |
| 2159 | //------------------------------------------------------------------------- |
| 2160 | // Implement abstract methods in WebViewCore, native WebKit callback part |
| 2161 | //------------------------------------------------------------------------- |
| 2162 | |
| 2163 | // called from JNI or WebView thread |
| 2164 | /* package */ void contentDraw() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2165 | synchronized (this) { |
John Reck | 00d5bf7 | 2011-07-21 09:46:17 -0700 | [diff] [blame] | 2166 | if (mWebView == null || mBrowserFrame == null) { |
| 2167 | // We were destroyed |
| 2168 | return; |
| 2169 | } |
| 2170 | // don't update the Picture until we have an initial width and finish |
| 2171 | // the first layout |
| 2172 | if (mCurrentViewWidth == 0 || !mBrowserFrame.firstLayoutDone()) { |
| 2173 | return; |
| 2174 | } |
| 2175 | // only fire an event if this is our first request |
Grace Kloba | 3f40bd4 | 2009-12-07 14:47:28 -0800 | [diff] [blame] | 2176 | if (mDrawIsScheduled) return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2177 | mDrawIsScheduled = true; |
| 2178 | mEventHub.sendMessage(Message.obtain(null, EventHub.WEBKIT_DRAW)); |
| 2179 | } |
| 2180 | } |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 2181 | |
Nicolas Roard | fb7bc34 | 2010-11-01 15:08:03 -0700 | [diff] [blame] | 2182 | // called from JNI |
| 2183 | void layersDraw() { |
| 2184 | synchronized (this) { |
| 2185 | if (mDrawLayersIsScheduled) return; |
| 2186 | mDrawLayersIsScheduled = true; |
| 2187 | mEventHub.sendMessage(Message.obtain(null, EventHub.WEBKIT_DRAW_LAYERS)); |
| 2188 | } |
| 2189 | } |
| 2190 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2191 | // called by JNI |
Patrick Scott | fa8be1c | 2011-02-02 14:09:34 -0500 | [diff] [blame] | 2192 | private void contentScrollTo(int x, int y, boolean animate, |
| 2193 | boolean onlyIfImeIsShowing) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2194 | if (!mBrowserFrame.firstLayoutDone()) { |
| 2195 | /* |
| 2196 | * WebKit restore state will be called before didFirstLayout(), |
| 2197 | * remember the position as it has to be applied after restoring |
| 2198 | * zoom factor which is controlled by screenWidth. |
| 2199 | */ |
| 2200 | mRestoredX = x; |
| 2201 | mRestoredY = y; |
| 2202 | return; |
| 2203 | } |
| 2204 | if (mWebView != null) { |
Grace Kloba | b3230cb | 2009-04-13 14:04:23 -0700 | [diff] [blame] | 2205 | Message msg = Message.obtain(mWebView.mPrivateHandler, |
Patrick Scott | fa8be1c | 2011-02-02 14:09:34 -0500 | [diff] [blame] | 2206 | WebView.SCROLL_TO_MSG_ID, animate ? 1 : 0, |
| 2207 | onlyIfImeIsShowing ? 1 : 0, new Point(x, y)); |
Grace Kloba | b3230cb | 2009-04-13 14:04:23 -0700 | [diff] [blame] | 2208 | if (mDrawIsScheduled) { |
| 2209 | mEventHub.sendMessage(Message.obtain(null, |
| 2210 | EventHub.MESSAGE_RELAY, msg)); |
| 2211 | } else { |
| 2212 | msg.sendToTarget(); |
| 2213 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2214 | } |
| 2215 | } |
| 2216 | |
| 2217 | // called by JNI |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2218 | private void sendNotifyProgressFinished() { |
| 2219 | sendUpdateTextEntry(); |
Steve Block | 808751f | 2011-01-04 14:26:27 +0000 | [diff] [blame] | 2220 | if (!JniUtil.useChromiumHttpStack()) { |
| 2221 | // as CacheManager can behave based on database transaction, we need to |
| 2222 | // call tick() to trigger endTransaction |
| 2223 | WebViewWorker.getHandler().removeMessages( |
| 2224 | WebViewWorker.MSG_CACHE_TRANSACTION_TICKER); |
| 2225 | WebViewWorker.getHandler().sendEmptyMessage( |
| 2226 | WebViewWorker.MSG_CACHE_TRANSACTION_TICKER); |
| 2227 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2228 | contentDraw(); |
| 2229 | } |
| 2230 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2231 | /* Called by JNI. The coordinates are in doc coordinates, so they need to |
| 2232 | be scaled before they can be used by the view system, which happens |
| 2233 | in WebView since it (and its thread) know the current scale factor. |
| 2234 | */ |
| 2235 | private void sendViewInvalidate(int left, int top, int right, int bottom) { |
| 2236 | if (mWebView != null) { |
| 2237 | Message.obtain(mWebView.mPrivateHandler, |
| 2238 | WebView.INVAL_RECT_MSG_ID, |
| 2239 | new Rect(left, top, right, bottom)).sendToTarget(); |
| 2240 | } |
| 2241 | } |
| 2242 | |
Nicolas Roard | 3886333 | 2010-01-04 19:30:55 +0000 | [diff] [blame] | 2243 | private static boolean mRepaintScheduled = false; |
| 2244 | |
| 2245 | /* |
| 2246 | * Called by the WebView thread |
| 2247 | */ |
| 2248 | /* package */ void signalRepaintDone() { |
| 2249 | mRepaintScheduled = false; |
| 2250 | } |
| 2251 | |
Steve Block | 85aa944 | 2011-09-28 12:20:12 +0100 | [diff] [blame] | 2252 | // Gets the WebView corresponding to this WebViewCore. Note that the |
| 2253 | // WebView object must only be used on the UI thread. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2254 | /* package */ WebView getWebView() { |
| 2255 | return mWebView; |
| 2256 | } |
| 2257 | |
| 2258 | private native void setViewportSettingsFromNative(); |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 2259 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2260 | // called by JNI |
Grace Kloba | 45dee41 | 2009-04-06 10:47:26 -0700 | [diff] [blame] | 2261 | private void didFirstLayout(boolean standardLoad) { |
Grace Kloba | ef347ef | 2009-07-30 11:20:32 -0700 | [diff] [blame] | 2262 | if (DebugFlags.WEB_VIEW_CORE) { |
| 2263 | Log.v(LOGTAG, "didFirstLayout standardLoad =" + standardLoad); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2264 | } |
| 2265 | |
| 2266 | mBrowserFrame.didFirstLayout(); |
| 2267 | |
Grace Kloba | 7a02d6e | 2009-08-18 10:10:51 -0700 | [diff] [blame] | 2268 | if (mWebView == null) return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2269 | |
Mangesh Ghiware | f0e96d5 | 2011-10-26 17:23:54 -0700 | [diff] [blame] | 2270 | boolean updateViewState = standardLoad || mIsRestored; |
Derek Sollenberger | b983c89 | 2010-06-28 08:38:28 -0400 | [diff] [blame] | 2271 | setupViewport(updateViewState); |
Grace Kloba | 9a67c82 | 2009-12-20 11:33:58 -0800 | [diff] [blame] | 2272 | // if updateRestoreState is true, ViewManager.postReadyToDrawAll() will |
Derek Sollenberger | b983c89 | 2010-06-28 08:38:28 -0400 | [diff] [blame] | 2273 | // be called after the WebView updates its state. If updateRestoreState |
Grace Kloba | 9a67c82 | 2009-12-20 11:33:58 -0800 | [diff] [blame] | 2274 | // is false, start to draw now as it is ready. |
Derek Sollenberger | b983c89 | 2010-06-28 08:38:28 -0400 | [diff] [blame] | 2275 | if (!updateViewState) { |
Grace Kloba | 9a67c82 | 2009-12-20 11:33:58 -0800 | [diff] [blame] | 2276 | mWebView.mViewManager.postReadyToDrawAll(); |
| 2277 | } |
Grace Kloba | ef347ef | 2009-07-30 11:20:32 -0700 | [diff] [blame] | 2278 | |
Grace Kloba | 178db41 | 2010-05-18 22:22:23 -0700 | [diff] [blame] | 2279 | // remove the touch highlight when moving to a new page |
John Reck | 335f454 | 2011-08-25 18:25:09 -0700 | [diff] [blame] | 2280 | if (WebView.USE_WEBKIT_RINGS || getSettings().supportTouchOnly()) { |
| 2281 | mWebView.mPrivateHandler.sendEmptyMessage( |
| 2282 | WebView.SET_TOUCH_HIGHLIGHT_RECTS); |
Grace Kloba | 178db41 | 2010-05-18 22:22:23 -0700 | [diff] [blame] | 2283 | } |
| 2284 | |
Grace Kloba | 7a02d6e | 2009-08-18 10:10:51 -0700 | [diff] [blame] | 2285 | // reset the scroll position, the restored offset and scales |
Patrick Scott | fa8be1c | 2011-02-02 14:09:34 -0500 | [diff] [blame] | 2286 | mRestoredX = mRestoredY = 0; |
Mangesh Ghiware | f0e96d5 | 2011-10-26 17:23:54 -0700 | [diff] [blame] | 2287 | mIsRestored = false; |
Shimeng (Simon) Wang | 5d8e7a4 | 2011-01-07 15:51:06 -0800 | [diff] [blame] | 2288 | mRestoredScale = mRestoredTextWrapScale = 0; |
Grace Kloba | 7a02d6e | 2009-08-18 10:10:51 -0700 | [diff] [blame] | 2289 | } |
| 2290 | |
| 2291 | // called by JNI |
| 2292 | private void updateViewport() { |
Shimeng (Simon) Wang | 56bd434 | 2011-07-07 15:26:22 -0700 | [diff] [blame] | 2293 | // Update viewport asap to make sure we get correct one. |
| 2294 | setupViewport(true); |
Grace Kloba | 7a02d6e | 2009-08-18 10:10:51 -0700 | [diff] [blame] | 2295 | } |
| 2296 | |
Derek Sollenberger | b983c89 | 2010-06-28 08:38:28 -0400 | [diff] [blame] | 2297 | private void setupViewport(boolean updateViewState) { |
John Reck | d4324aa | 2011-07-08 11:22:38 -0700 | [diff] [blame] | 2298 | if (mWebView == null || mSettings == null) { |
| 2299 | // We've been destroyed or are being destroyed, return early |
| 2300 | return; |
| 2301 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2302 | // set the viewport settings from WebKit |
| 2303 | setViewportSettingsFromNative(); |
| 2304 | |
Mangesh Ghiware | ca4d54c | 2011-10-31 14:41:38 -0700 | [diff] [blame] | 2305 | // clamp initial scale |
| 2306 | if (mViewportInitialScale > 0) { |
| 2307 | if (mViewportMinimumScale > 0) { |
| 2308 | mViewportInitialScale = Math.max(mViewportInitialScale, |
| 2309 | mViewportMinimumScale); |
| 2310 | } |
| 2311 | if (mViewportMaximumScale > 0) { |
| 2312 | mViewportInitialScale = Math.min(mViewportInitialScale, |
| 2313 | mViewportMaximumScale); |
| 2314 | } |
| 2315 | } |
| 2316 | |
John Reck | 7818aaa | 2011-04-26 16:57:46 -0700 | [diff] [blame] | 2317 | if (mSettings.forceUserScalable()) { |
| 2318 | mViewportUserScalable = true; |
| 2319 | if (mViewportInitialScale > 0) { |
| 2320 | if (mViewportMinimumScale > 0) { |
| 2321 | mViewportMinimumScale = Math.min(mViewportMinimumScale, |
| 2322 | mViewportInitialScale / 2); |
| 2323 | } |
| 2324 | if (mViewportMaximumScale > 0) { |
| 2325 | mViewportMaximumScale = Math.max(mViewportMaximumScale, |
| 2326 | mViewportInitialScale * 2); |
| 2327 | } |
| 2328 | } else { |
| 2329 | if (mViewportMinimumScale > 0) { |
| 2330 | mViewportMinimumScale = Math.min(mViewportMinimumScale, 50); |
| 2331 | } |
| 2332 | if (mViewportMaximumScale > 0) { |
| 2333 | mViewportMaximumScale = Math.max(mViewportMaximumScale, 200); |
| 2334 | } |
| 2335 | } |
| 2336 | } |
| 2337 | |
Grace Kloba | 408cf85 | 2009-09-20 16:34:44 -0700 | [diff] [blame] | 2338 | // adjust the default scale to match the densityDpi |
| 2339 | float adjust = 1.0f; |
| 2340 | if (mViewportDensityDpi == -1) { |
Derek Sollenberger | 03e4891 | 2010-05-18 17:03:42 -0400 | [diff] [blame] | 2341 | // convert default zoom scale to a integer (percentage) to avoid any |
| 2342 | // issues with floating point comparisons |
| 2343 | if (mWebView != null && (int)(mWebView.getDefaultZoomScale() * 100) != 100) { |
| 2344 | adjust = mWebView.getDefaultZoomScale(); |
Grace Kloba | 0d8b77c | 2009-06-25 11:20:51 -0700 | [diff] [blame] | 2345 | } |
Grace Kloba | 408cf85 | 2009-09-20 16:34:44 -0700 | [diff] [blame] | 2346 | } else if (mViewportDensityDpi > 0) { |
| 2347 | adjust = (float) mContext.getResources().getDisplayMetrics().densityDpi |
| 2348 | / mViewportDensityDpi; |
| 2349 | } |
Mangesh Ghiware | e832b63 | 2011-11-16 11:46:39 -0800 | [diff] [blame] | 2350 | if (adjust != mWebView.getDefaultZoomScale()) { |
Mangesh Ghiware | 31f263d | 2011-11-21 16:54:20 -0800 | [diff] [blame] | 2351 | Message.obtain(mWebView.mPrivateHandler, |
| 2352 | WebView.UPDATE_ZOOM_DENSITY, adjust).sendToTarget(); |
Mangesh Ghiware | e832b63 | 2011-11-16 11:46:39 -0800 | [diff] [blame] | 2353 | } |
Grace Kloba | 408cf85 | 2009-09-20 16:34:44 -0700 | [diff] [blame] | 2354 | int defaultScale = (int) (adjust * 100); |
| 2355 | |
| 2356 | if (mViewportInitialScale > 0) { |
| 2357 | mViewportInitialScale *= adjust; |
| 2358 | } |
| 2359 | if (mViewportMinimumScale > 0) { |
| 2360 | mViewportMinimumScale *= adjust; |
| 2361 | } |
| 2362 | if (mViewportMaximumScale > 0) { |
| 2363 | mViewportMaximumScale *= adjust; |
Grace Kloba | 0d8b77c | 2009-06-25 11:20:51 -0700 | [diff] [blame] | 2364 | } |
| 2365 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2366 | // infer the values if they are not defined. |
| 2367 | if (mViewportWidth == 0) { |
| 2368 | if (mViewportInitialScale == 0) { |
Grace Kloba | 408cf85 | 2009-09-20 16:34:44 -0700 | [diff] [blame] | 2369 | mViewportInitialScale = defaultScale; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2370 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2371 | } |
| 2372 | if (mViewportUserScalable == false) { |
Grace Kloba | 408cf85 | 2009-09-20 16:34:44 -0700 | [diff] [blame] | 2373 | mViewportInitialScale = defaultScale; |
| 2374 | mViewportMinimumScale = defaultScale; |
| 2375 | mViewportMaximumScale = defaultScale; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2376 | } |
Grace Kloba | f53c186 | 2009-09-21 16:26:11 -0700 | [diff] [blame] | 2377 | if (mViewportMinimumScale > mViewportInitialScale |
| 2378 | && mViewportInitialScale != 0) { |
| 2379 | mViewportMinimumScale = mViewportInitialScale; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2380 | } |
Grace Kloba | f53c186 | 2009-09-21 16:26:11 -0700 | [diff] [blame] | 2381 | if (mViewportMaximumScale > 0 |
| 2382 | && mViewportMaximumScale < mViewportInitialScale) { |
| 2383 | mViewportMaximumScale = mViewportInitialScale; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2384 | } |
Grace Kloba | 408cf85 | 2009-09-20 16:34:44 -0700 | [diff] [blame] | 2385 | if (mViewportWidth < 0 && mViewportInitialScale == defaultScale) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2386 | mViewportWidth = 0; |
| 2387 | } |
| 2388 | |
Grace Kloba | 7a02d6e | 2009-08-18 10:10:51 -0700 | [diff] [blame] | 2389 | // if mViewportWidth is 0, it means device-width, always update. |
Derek Sollenberger | b983c89 | 2010-06-28 08:38:28 -0400 | [diff] [blame] | 2390 | if (mViewportWidth != 0 && !updateViewState) { |
Shimeng (Simon) Wang | 72a1d2e | 2011-06-30 13:36:53 -0700 | [diff] [blame] | 2391 | // For non standard load, since updateViewState will be false. |
| 2392 | mFirstLayoutForNonStandardLoad = true; |
Derek Sollenberger | b983c89 | 2010-06-28 08:38:28 -0400 | [diff] [blame] | 2393 | ViewState viewState = new ViewState(); |
| 2394 | viewState.mMinScale = mViewportMinimumScale / 100.0f; |
| 2395 | viewState.mMaxScale = mViewportMaximumScale / 100.0f; |
| 2396 | viewState.mDefaultScale = adjust; |
Grace Kloba | 769ed21 | 2010-01-27 10:52:47 -0800 | [diff] [blame] | 2397 | // as mViewportWidth is not 0, it is not mobile site. |
Derek Sollenberger | b983c89 | 2010-06-28 08:38:28 -0400 | [diff] [blame] | 2398 | viewState.mMobileSite = false; |
Grace Kloba | 188bf8d | 2010-04-07 11:30:19 -0700 | [diff] [blame] | 2399 | // for non-mobile site, we don't need minPrefWidth, set it as 0 |
Derek Sollenberger | b983c89 | 2010-06-28 08:38:28 -0400 | [diff] [blame] | 2400 | viewState.mScrollX = 0; |
George Mount | e263bc1 | 2011-10-31 13:49:03 -0700 | [diff] [blame] | 2401 | viewState.mShouldStartScrolledRight = false; |
Grace Kloba | 769ed21 | 2010-01-27 10:52:47 -0800 | [diff] [blame] | 2402 | Message.obtain(mWebView.mPrivateHandler, |
Derek Sollenberger | b983c89 | 2010-06-28 08:38:28 -0400 | [diff] [blame] | 2403 | WebView.UPDATE_ZOOM_RANGE, viewState).sendToTarget(); |
Grace Kloba | 769ed21 | 2010-01-27 10:52:47 -0800 | [diff] [blame] | 2404 | return; |
| 2405 | } |
Grace Kloba | 7a02d6e | 2009-08-18 10:10:51 -0700 | [diff] [blame] | 2406 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2407 | // now notify webview |
Grace Kloba | 6ed525e | 2009-09-17 15:31:12 -0700 | [diff] [blame] | 2408 | // webViewWidth refers to the width in the view system |
| 2409 | int webViewWidth; |
| 2410 | // viewportWidth refers to the width in the document system |
| 2411 | int viewportWidth = mCurrentViewWidth; |
| 2412 | if (viewportWidth == 0) { |
| 2413 | // this may happen when WebView just starts. This is not perfect as |
| 2414 | // we call WebView method from WebCore thread. But not perfect |
| 2415 | // reference is better than no reference. |
| 2416 | webViewWidth = mWebView.getViewWidth(); |
Grace Kloba | 408cf85 | 2009-09-20 16:34:44 -0700 | [diff] [blame] | 2417 | viewportWidth = (int) (webViewWidth / adjust); |
Grace Kloba | 6ed525e | 2009-09-17 15:31:12 -0700 | [diff] [blame] | 2418 | if (viewportWidth == 0) { |
Shimeng (Simon) Wang | a6c5d38 | 2011-07-19 11:06:06 -0700 | [diff] [blame] | 2419 | if (DebugFlags.WEB_VIEW_CORE) { |
| 2420 | Log.v(LOGTAG, "Can't get the viewWidth yet"); |
| 2421 | } |
Grace Kloba | 6ed525e | 2009-09-17 15:31:12 -0700 | [diff] [blame] | 2422 | } |
| 2423 | } else { |
| 2424 | webViewWidth = Math.round(viewportWidth * mCurrentViewScale); |
| 2425 | } |
Derek Sollenberger | b983c89 | 2010-06-28 08:38:28 -0400 | [diff] [blame] | 2426 | mInitialViewState = new ViewState(); |
| 2427 | mInitialViewState.mMinScale = mViewportMinimumScale / 100.0f; |
| 2428 | mInitialViewState.mMaxScale = mViewportMaximumScale / 100.0f; |
| 2429 | mInitialViewState.mDefaultScale = adjust; |
| 2430 | mInitialViewState.mScrollX = mRestoredX; |
| 2431 | mInitialViewState.mScrollY = mRestoredY; |
George Mount | e263bc1 | 2011-10-31 13:49:03 -0700 | [diff] [blame] | 2432 | mInitialViewState.mShouldStartScrolledRight = (mRestoredX == 0) |
| 2433 | && (mRestoredY == 0) |
| 2434 | && (mBrowserFrame != null) |
| 2435 | && mBrowserFrame.getShouldStartScrolledRight(); |
| 2436 | |
Derek Sollenberger | b983c89 | 2010-06-28 08:38:28 -0400 | [diff] [blame] | 2437 | mInitialViewState.mMobileSite = (0 == mViewportWidth); |
Mangesh Ghiware | f0e96d5 | 2011-10-26 17:23:54 -0700 | [diff] [blame] | 2438 | if (mIsRestored) { |
Shimeng (Simon) Wang | 96fcb87 | 2010-11-24 16:01:12 -0800 | [diff] [blame] | 2439 | mInitialViewState.mIsRestored = true; |
Shimeng (Simon) Wang | 5d8e7a4 | 2011-01-07 15:51:06 -0800 | [diff] [blame] | 2440 | mInitialViewState.mViewScale = mRestoredScale; |
Mangesh Ghiware | e59e301 | 2011-11-03 13:21:18 -0700 | [diff] [blame] | 2441 | if (mRestoredTextWrapScale > 0) { |
| 2442 | mInitialViewState.mTextWrapScale = mRestoredTextWrapScale; |
| 2443 | } else { |
| 2444 | mInitialViewState.mTextWrapScale = mInitialViewState.mViewScale; |
| 2445 | } |
Grace Kloba | ef347ef | 2009-07-30 11:20:32 -0700 | [diff] [blame] | 2446 | } else { |
| 2447 | if (mViewportInitialScale > 0) { |
Derek Sollenberger | b983c89 | 2010-06-28 08:38:28 -0400 | [diff] [blame] | 2448 | mInitialViewState.mViewScale = mInitialViewState.mTextWrapScale = |
Grace Kloba | ef347ef | 2009-07-30 11:20:32 -0700 | [diff] [blame] | 2449 | mViewportInitialScale / 100.0f; |
Shimeng (Simon) Wang | 9c64bae | 2010-10-22 10:52:57 -0700 | [diff] [blame] | 2450 | } else if (mViewportWidth > 0 && mViewportWidth < webViewWidth && |
Shimeng (Simon) Wang | b30381d | 2011-06-22 17:44:27 -0700 | [diff] [blame] | 2451 | !getSettings().getUseFixedViewport()) { |
Derek Sollenberger | b983c89 | 2010-06-28 08:38:28 -0400 | [diff] [blame] | 2452 | mInitialViewState.mViewScale = mInitialViewState.mTextWrapScale = |
Grace Kloba | ef347ef | 2009-07-30 11:20:32 -0700 | [diff] [blame] | 2453 | (float) webViewWidth / mViewportWidth; |
| 2454 | } else { |
Derek Sollenberger | b983c89 | 2010-06-28 08:38:28 -0400 | [diff] [blame] | 2455 | mInitialViewState.mTextWrapScale = adjust; |
Shimeng (Simon) Wang | 56bd434 | 2011-07-07 15:26:22 -0700 | [diff] [blame] | 2456 | if (mSettings.getUseWideViewPort()) { |
| 2457 | // 0 will trigger WebView to turn on zoom overview mode |
| 2458 | mInitialViewState.mViewScale = 0; |
| 2459 | } else { |
| 2460 | mInitialViewState.mViewScale = adjust; |
| 2461 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2462 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2463 | } |
Grace Kloba | ef347ef | 2009-07-30 11:20:32 -0700 | [diff] [blame] | 2464 | |
| 2465 | if (mWebView.mHeightCanMeasure) { |
| 2466 | // Trick to ensure that the Picture has the exact height for the |
| 2467 | // content by forcing to layout with 0 height after the page is |
| 2468 | // ready, which is indicated by didFirstLayout. This is essential to |
| 2469 | // get rid of the white space in the GMail which uses WebView for |
| 2470 | // message view. |
| 2471 | mWebView.mLastHeightSent = 0; |
| 2472 | // Send a negative scale to indicate that WebCore should reuse |
| 2473 | // the current scale |
| 2474 | WebView.ViewSizeData data = new WebView.ViewSizeData(); |
| 2475 | data.mWidth = mWebView.mLastWidthSent; |
| 2476 | data.mHeight = 0; |
| 2477 | // if mHeightCanMeasure is true, getUseWideViewPort() can't be |
| 2478 | // true. It is safe to use mWidth for mTextWrapWidth. |
| 2479 | data.mTextWrapWidth = data.mWidth; |
| 2480 | data.mScale = -1.0f; |
Cary Clark | 6d45acc | 2009-08-27 15:42:57 -0400 | [diff] [blame] | 2481 | data.mIgnoreHeight = false; |
Grace Kloba | 3a0def2 | 2010-01-23 21:11:54 -0800 | [diff] [blame] | 2482 | data.mAnchorX = data.mAnchorY = 0; |
Grace Kloba | 0d03b91 | 2009-09-27 17:46:31 -0700 | [diff] [blame] | 2483 | // send VIEW_SIZE_CHANGED to the front of the queue so that we can |
| 2484 | // avoid pushing the wrong picture to the WebView side. If there is |
| 2485 | // a VIEW_SIZE_CHANGED in the queue, probably from WebView side, |
| 2486 | // ignore it as we have a new size. If we leave VIEW_SIZE_CHANGED |
| 2487 | // in the queue, as mLastHeightSent has been updated here, we may |
| 2488 | // miss the requestLayout in WebView side after the new picture. |
| 2489 | mEventHub.removeMessages(EventHub.VIEW_SIZE_CHANGED); |
Grace Kloba | ef347ef | 2009-07-30 11:20:32 -0700 | [diff] [blame] | 2490 | mEventHub.sendMessageAtFrontOfQueue(Message.obtain(null, |
| 2491 | EventHub.VIEW_SIZE_CHANGED, data)); |
Shimeng (Simon) Wang | 56bd434 | 2011-07-07 15:26:22 -0700 | [diff] [blame] | 2492 | } else { |
Grace Kloba | 6ed525e | 2009-09-17 15:31:12 -0700 | [diff] [blame] | 2493 | if (viewportWidth == 0) { |
Grace Kloba | 7a02d6e | 2009-08-18 10:10:51 -0700 | [diff] [blame] | 2494 | // Trick to ensure VIEW_SIZE_CHANGED will be sent from WebView |
| 2495 | // to WebViewCore |
| 2496 | mWebView.mLastWidthSent = 0; |
| 2497 | } else { |
| 2498 | WebView.ViewSizeData data = new WebView.ViewSizeData(); |
| 2499 | // mViewScale as 0 means it is in zoom overview mode. So we don't |
| 2500 | // know the exact scale. If mRestoredScale is non-zero, use it; |
| 2501 | // otherwise just use mTextWrapScale as the initial scale. |
Shimeng (Simon) Wang | 7606464 | 2011-02-22 15:31:02 -0800 | [diff] [blame] | 2502 | float tentativeScale = mInitialViewState.mViewScale; |
| 2503 | if (tentativeScale == 0) { |
| 2504 | // The following tries to figure out more correct view scale |
| 2505 | // and text wrap scale to be sent to webkit, by using some |
| 2506 | // knowledge from web settings and zoom manager. |
| 2507 | |
| 2508 | // Calculated window width will be used to guess the scale |
| 2509 | // in zoom overview mode. |
| 2510 | tentativeScale = mInitialViewState.mTextWrapScale; |
| 2511 | int tentativeViewWidth = Math.round(webViewWidth / tentativeScale); |
Shimeng (Simon) Wang | 24a252e | 2011-05-24 15:00:52 -0700 | [diff] [blame] | 2512 | int windowWidth = calculateWindowWidth(tentativeViewWidth); |
Shimeng (Simon) Wang | 7606464 | 2011-02-22 15:31:02 -0800 | [diff] [blame] | 2513 | // In viewport setup time, since no content width is known, we assume |
| 2514 | // the windowWidth will be the content width, to get a more likely |
| 2515 | // zoom overview scale. |
| 2516 | data.mScale = (float) webViewWidth / windowWidth; |
| 2517 | if (!mSettings.getLoadWithOverviewMode()) { |
| 2518 | // If user choose non-overview mode. |
| 2519 | data.mScale = Math.max(data.mScale, tentativeScale); |
| 2520 | } |
Shimeng (Simon) Wang | 24a252e | 2011-05-24 15:00:52 -0700 | [diff] [blame] | 2521 | if (mSettings.isNarrowColumnLayout()) { |
Shimeng (Simon) Wang | 7606464 | 2011-02-22 15:31:02 -0800 | [diff] [blame] | 2522 | // In case of automatic text reflow in fixed view port mode. |
| 2523 | mInitialViewState.mTextWrapScale = |
Mangesh Ghiware | 66b2ff8 | 2011-12-08 13:43:55 -0800 | [diff] [blame] | 2524 | mWebView.computeReadingLevelScale(data.mScale); |
Shimeng (Simon) Wang | 7606464 | 2011-02-22 15:31:02 -0800 | [diff] [blame] | 2525 | } |
| 2526 | } else { |
| 2527 | // Scale is given such as when page is restored, use it. |
| 2528 | data.mScale = tentativeScale; |
| 2529 | } |
Cary Clark | 35155c1 | 2009-10-29 15:34:00 -0400 | [diff] [blame] | 2530 | if (DebugFlags.WEB_VIEW_CORE) { |
| 2531 | Log.v(LOGTAG, "setupViewport" |
| 2532 | + " mRestoredScale=" + mRestoredScale |
Derek Sollenberger | b983c89 | 2010-06-28 08:38:28 -0400 | [diff] [blame] | 2533 | + " mViewScale=" + mInitialViewState.mViewScale |
| 2534 | + " mTextWrapScale=" + mInitialViewState.mTextWrapScale |
Shimeng (Simon) Wang | 7606464 | 2011-02-22 15:31:02 -0800 | [diff] [blame] | 2535 | + " data.mScale= " + data.mScale |
Cary Clark | 35155c1 | 2009-10-29 15:34:00 -0400 | [diff] [blame] | 2536 | ); |
| 2537 | } |
Grace Kloba | 7a02d6e | 2009-08-18 10:10:51 -0700 | [diff] [blame] | 2538 | data.mWidth = Math.round(webViewWidth / data.mScale); |
Ben Murdoch | d1bee05 | 2010-03-05 11:30:07 +0000 | [diff] [blame] | 2539 | // We may get a call here when mCurrentViewHeight == 0 if webcore completes the |
| 2540 | // first layout before we sync our webview dimensions to it. In that case, we |
| 2541 | // request the real height of the webview. This is not a perfect solution as we |
| 2542 | // are calling a WebView method from the WebCore thread. But this is preferable |
| 2543 | // to syncing an incorrect height. |
| 2544 | data.mHeight = mCurrentViewHeight == 0 ? |
| 2545 | Math.round(mWebView.getViewHeight() / data.mScale) |
Shimeng (Simon) Wang | f7107d7 | 2011-02-18 15:27:28 -0800 | [diff] [blame] | 2546 | : Math.round((float) mCurrentViewHeight * data.mWidth / viewportWidth); |
Grace Kloba | 7a02d6e | 2009-08-18 10:10:51 -0700 | [diff] [blame] | 2547 | data.mTextWrapWidth = Math.round(webViewWidth |
Derek Sollenberger | b983c89 | 2010-06-28 08:38:28 -0400 | [diff] [blame] | 2548 | / mInitialViewState.mTextWrapScale); |
Cary Clark | 6d45acc | 2009-08-27 15:42:57 -0400 | [diff] [blame] | 2549 | data.mIgnoreHeight = false; |
Grace Kloba | 3a0def2 | 2010-01-23 21:11:54 -0800 | [diff] [blame] | 2550 | data.mAnchorX = data.mAnchorY = 0; |
Grace Kloba | 0d03b91 | 2009-09-27 17:46:31 -0700 | [diff] [blame] | 2551 | // send VIEW_SIZE_CHANGED to the front of the queue so that we |
| 2552 | // can avoid pushing the wrong picture to the WebView side. |
| 2553 | mEventHub.removeMessages(EventHub.VIEW_SIZE_CHANGED); |
Shimeng (Simon) Wang | 7606464 | 2011-02-22 15:31:02 -0800 | [diff] [blame] | 2554 | // Let webkit know the scale and inner width/height immediately |
| 2555 | // in viewport setup time to avoid wrong information. |
| 2556 | viewSizeChanged(data); |
Grace Kloba | 7a02d6e | 2009-08-18 10:10:51 -0700 | [diff] [blame] | 2557 | } |
Grace Kloba | ef347ef | 2009-07-30 11:20:32 -0700 | [diff] [blame] | 2558 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2559 | } |
| 2560 | |
| 2561 | // called by JNI |
Shimeng (Simon) Wang | 5d8e7a4 | 2011-01-07 15:51:06 -0800 | [diff] [blame] | 2562 | private void restoreScale(float scale, float textWrapScale) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2563 | if (mBrowserFrame.firstLayoutDone() == false) { |
Mangesh Ghiware | e832b63 | 2011-11-16 11:46:39 -0800 | [diff] [blame] | 2564 | mIsRestored = true; |
Mangesh Ghiware | f0e96d5 | 2011-10-26 17:23:54 -0700 | [diff] [blame] | 2565 | mRestoredScale = scale; |
Mangesh Ghiware | e59e301 | 2011-11-03 13:21:18 -0700 | [diff] [blame] | 2566 | if (mSettings.getUseWideViewPort()) { |
| 2567 | mRestoredTextWrapScale = textWrapScale; |
| 2568 | } |
Grace Kloba | 8b97e4b | 2009-07-28 13:11:38 -0700 | [diff] [blame] | 2569 | } |
| 2570 | } |
| 2571 | |
| 2572 | // called by JNI |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2573 | private void needTouchEvents(boolean need) { |
| 2574 | if (mWebView != null) { |
| 2575 | Message.obtain(mWebView.mPrivateHandler, |
| 2576 | WebView.WEBCORE_NEED_TOUCH_EVENTS, need ? 1 : 0, 0) |
| 2577 | .sendToTarget(); |
| 2578 | } |
| 2579 | } |
| 2580 | |
| 2581 | // called by JNI |
| 2582 | private void updateTextfield(int ptr, boolean changeToPassword, |
| 2583 | String text, int textGeneration) { |
| 2584 | if (mWebView != null) { |
| 2585 | Message msg = Message.obtain(mWebView.mPrivateHandler, |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 2586 | WebView.UPDATE_TEXTFIELD_TEXT_MSG_ID, ptr, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2587 | textGeneration, text); |
| 2588 | msg.getData().putBoolean("password", changeToPassword); |
| 2589 | msg.sendToTarget(); |
| 2590 | } |
| 2591 | } |
| 2592 | |
Cary Clark | 243ea06 | 2009-06-25 10:49:32 -0400 | [diff] [blame] | 2593 | // called by JNI |
Leon Scroggins | 6679f2f | 2009-08-12 18:48:10 -0400 | [diff] [blame] | 2594 | private void updateTextSelection(int pointer, int start, int end, |
| 2595 | int textGeneration) { |
| 2596 | if (mWebView != null) { |
| 2597 | Message.obtain(mWebView.mPrivateHandler, |
| 2598 | WebView.UPDATE_TEXT_SELECTION_MSG_ID, pointer, textGeneration, |
| 2599 | new TextSelectionData(start, end)).sendToTarget(); |
| 2600 | } |
| 2601 | } |
| 2602 | |
| 2603 | // called by JNI |
Cary Clark | 243ea06 | 2009-06-25 10:49:32 -0400 | [diff] [blame] | 2604 | private void clearTextEntry() { |
| 2605 | if (mWebView == null) return; |
| 2606 | Message.obtain(mWebView.mPrivateHandler, |
| 2607 | WebView.CLEAR_TEXT_ENTRY).sendToTarget(); |
| 2608 | } |
| 2609 | |
Leon Scroggins | 5de6389 | 2009-10-29 09:48:43 -0400 | [diff] [blame] | 2610 | // called by JNI |
| 2611 | private void sendFindAgain() { |
| 2612 | if (mWebView == null) return; |
| 2613 | Message.obtain(mWebView.mPrivateHandler, |
| 2614 | WebView.FIND_AGAIN).sendToTarget(); |
| 2615 | } |
| 2616 | |
Cary Clark | 77d98f4 | 2009-07-31 09:40:38 -0400 | [diff] [blame] | 2617 | private native void nativeUpdateFrameCacheIfLoading(); |
Leon Scroggins | 200c13d | 2010-05-14 15:35:42 -0400 | [diff] [blame] | 2618 | private native void nativeRevealSelection(); |
Leon Scroggins | 3a50339 | 2010-01-06 17:04:38 -0500 | [diff] [blame] | 2619 | private native String nativeRequestLabel(int framePtr, int nodePtr); |
Leon Scroggins | 72543e1 | 2009-07-23 15:29:45 -0400 | [diff] [blame] | 2620 | /** |
Cary Clark | eaa18de | 2009-09-28 12:50:42 -0400 | [diff] [blame] | 2621 | * Scroll the focused textfield to (xPercent, y) in document space |
Leon Scroggins | 72543e1 | 2009-07-23 15:29:45 -0400 | [diff] [blame] | 2622 | */ |
Cary Clark | eaa18de | 2009-09-28 12:50:42 -0400 | [diff] [blame] | 2623 | private native void nativeScrollFocusedTextInput(float xPercent, int y); |
Leon Scroggins | 72543e1 | 2009-07-23 15:29:45 -0400 | [diff] [blame] | 2624 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2625 | // these must be in document space (i.e. not scaled/zoomed). |
Patrick Scott | fa8be1c | 2011-02-02 14:09:34 -0500 | [diff] [blame] | 2626 | private native void nativeSetScrollOffset(int gen, boolean sendScrollEvent, int dx, int dy); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2627 | |
| 2628 | private native void nativeSetGlobalBounds(int x, int y, int w, int h); |
| 2629 | |
| 2630 | // called by JNI |
Leon Scroggins | a8da173 | 2009-10-19 19:04:30 -0400 | [diff] [blame] | 2631 | private void requestListBox(String[] array, int[] enabledArray, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2632 | int[] selectedArray) { |
| 2633 | if (mWebView != null) { |
| 2634 | mWebView.requestListBox(array, enabledArray, selectedArray); |
| 2635 | } |
| 2636 | } |
| 2637 | |
| 2638 | // called by JNI |
Leon Scroggins | a8da173 | 2009-10-19 19:04:30 -0400 | [diff] [blame] | 2639 | private void requestListBox(String[] array, int[] enabledArray, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2640 | int selection) { |
| 2641 | if (mWebView != null) { |
| 2642 | mWebView.requestListBox(array, enabledArray, selection); |
| 2643 | } |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 2644 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2645 | } |
Mike Reed | d205d5b | 2009-05-27 11:02:29 -0400 | [diff] [blame] | 2646 | |
Derek Sollenberger | 4c41e8d | 2009-06-29 13:49:27 -0400 | [diff] [blame] | 2647 | // called by JNI |
Leon Scroggins | b415779 | 2010-03-18 12:42:33 -0400 | [diff] [blame] | 2648 | private void requestKeyboardWithSelection(int pointer, int selStart, |
| 2649 | int selEnd, int textGeneration) { |
Derek Sollenberger | 4c41e8d | 2009-06-29 13:49:27 -0400 | [diff] [blame] | 2650 | if (mWebView != null) { |
| 2651 | Message.obtain(mWebView.mPrivateHandler, |
Leon Scroggins | b415779 | 2010-03-18 12:42:33 -0400 | [diff] [blame] | 2652 | WebView.REQUEST_KEYBOARD_WITH_SELECTION_MSG_ID, pointer, |
| 2653 | textGeneration, new TextSelectionData(selStart, selEnd)) |
| 2654 | .sendToTarget(); |
| 2655 | } |
| 2656 | } |
| 2657 | |
| 2658 | // called by JNI |
| 2659 | private void requestKeyboard(boolean showKeyboard) { |
| 2660 | if (mWebView != null) { |
| 2661 | Message.obtain(mWebView.mPrivateHandler, |
| 2662 | WebView.REQUEST_KEYBOARD, showKeyboard ? 1 : 0, 0) |
Derek Sollenberger | 4c41e8d | 2009-06-29 13:49:27 -0400 | [diff] [blame] | 2663 | .sendToTarget(); |
| 2664 | } |
| 2665 | } |
| 2666 | |
Ben Murdoch | db8d19c | 2010-10-29 11:44:17 +0100 | [diff] [blame] | 2667 | private void setWebTextViewAutoFillable(int queryId, String preview) { |
Ben Murdoch | 62275a4 | 2010-09-07 11:27:28 +0100 | [diff] [blame] | 2668 | if (mWebView != null) { |
Ben Murdoch | db8d19c | 2010-10-29 11:44:17 +0100 | [diff] [blame] | 2669 | Message.obtain(mWebView.mPrivateHandler, WebView.SET_AUTOFILLABLE, |
| 2670 | new AutoFillData(queryId, preview)) |
| 2671 | .sendToTarget(); |
Ben Murdoch | 62275a4 | 2010-09-07 11:27:28 +0100 | [diff] [blame] | 2672 | } |
| 2673 | } |
| 2674 | |
Steve Block | 85aa944 | 2011-09-28 12:20:12 +0100 | [diff] [blame] | 2675 | Context getContext() { |
Derek Sollenberger | 7c5bf46 | 2010-01-11 12:50:51 -0500 | [diff] [blame] | 2676 | return mContext; |
| 2677 | } |
| 2678 | |
| 2679 | // called by JNI |
Derek Sollenberger | f3196cd | 2011-01-27 17:33:14 -0500 | [diff] [blame] | 2680 | private void keepScreenOn(boolean screenOn) { |
| 2681 | if (mWebView != null) { |
| 2682 | Message message = mWebView.mPrivateHandler.obtainMessage(WebView.SCREEN_ON); |
| 2683 | message.arg1 = screenOn ? 1 : 0; |
| 2684 | message.sendToTarget(); |
| 2685 | } |
| 2686 | } |
| 2687 | |
| 2688 | // called by JNI |
Derek Sollenberger | 9e28c4c | 2009-11-09 14:45:58 -0500 | [diff] [blame] | 2689 | private Class<?> getPluginClass(String libName, String clsName) { |
John Reck | 7818aaa | 2011-04-26 16:57:46 -0700 | [diff] [blame] | 2690 | |
Derek Sollenberger | 9e28c4c | 2009-11-09 14:45:58 -0500 | [diff] [blame] | 2691 | if (mWebView == null) { |
| 2692 | return null; |
| 2693 | } |
John Reck | 7818aaa | 2011-04-26 16:57:46 -0700 | [diff] [blame] | 2694 | |
Derek Sollenberger | cb37e71 | 2009-11-24 14:58:09 -0500 | [diff] [blame] | 2695 | PluginManager pluginManager = PluginManager.getInstance(null); |
| 2696 | |
| 2697 | String pkgName = pluginManager.getPluginsAPKName(libName); |
Derek Sollenberger | 9e28c4c | 2009-11-09 14:45:58 -0500 | [diff] [blame] | 2698 | if (pkgName == null) { |
| 2699 | Log.w(LOGTAG, "Unable to resolve " + libName + " to a plugin APK"); |
| 2700 | return null; |
| 2701 | } |
John Reck | 7818aaa | 2011-04-26 16:57:46 -0700 | [diff] [blame] | 2702 | |
Derek Sollenberger | 9e28c4c | 2009-11-09 14:45:58 -0500 | [diff] [blame] | 2703 | try { |
Derek Sollenberger | cb37e71 | 2009-11-24 14:58:09 -0500 | [diff] [blame] | 2704 | return pluginManager.getPluginClass(pkgName, clsName); |
Derek Sollenberger | 9e28c4c | 2009-11-09 14:45:58 -0500 | [diff] [blame] | 2705 | } catch (NameNotFoundException e) { |
| 2706 | Log.e(LOGTAG, "Unable to find plugin classloader for the apk (" + pkgName + ")"); |
| 2707 | } catch (ClassNotFoundException e) { |
| 2708 | Log.e(LOGTAG, "Unable to find plugin class (" + clsName + |
| 2709 | ") in the apk (" + pkgName + ")"); |
| 2710 | } |
| 2711 | |
Derek Sollenberger | cb37e71 | 2009-11-24 14:58:09 -0500 | [diff] [blame] | 2712 | return null; |
Derek Sollenberger | 9e28c4c | 2009-11-09 14:45:58 -0500 | [diff] [blame] | 2713 | } |
Derek Sollenberger | cb37e71 | 2009-11-24 14:58:09 -0500 | [diff] [blame] | 2714 | |
Derek Sollenberger | 51ef573 | 2009-12-07 16:15:13 -0500 | [diff] [blame] | 2715 | // called by JNI. PluginWidget function to launch a full-screen view using a |
| 2716 | // View object provided by the plugin class. |
Derek Sollenberger | 7ab3d67 | 2011-06-01 14:45:05 -0400 | [diff] [blame] | 2717 | private void showFullScreenPlugin(ViewManager.ChildView childView, int orientation, int npp) { |
Derek Sollenberger | 7c5bf46 | 2010-01-11 12:50:51 -0500 | [diff] [blame] | 2718 | if (mWebView == null) { |
Derek Sollenberger | 51ef573 | 2009-12-07 16:15:13 -0500 | [diff] [blame] | 2719 | return; |
| 2720 | } |
| 2721 | |
Derek Sollenberger | c28ff44 | 2010-03-09 17:38:49 -0500 | [diff] [blame] | 2722 | Message message = mWebView.mPrivateHandler.obtainMessage(WebView.SHOW_FULLSCREEN); |
| 2723 | message.obj = childView.mView; |
Derek Sollenberger | 7ab3d67 | 2011-06-01 14:45:05 -0400 | [diff] [blame] | 2724 | message.arg1 = orientation; |
| 2725 | message.arg2 = npp; |
Derek Sollenberger | c28ff44 | 2010-03-09 17:38:49 -0500 | [diff] [blame] | 2726 | message.sendToTarget(); |
Derek Sollenberger | 51ef573 | 2009-12-07 16:15:13 -0500 | [diff] [blame] | 2727 | } |
| 2728 | |
Grace Kloba | 11438c3 | 2009-12-16 11:39:12 -0800 | [diff] [blame] | 2729 | // called by JNI |
Derek Sollenberger | 51ef573 | 2009-12-07 16:15:13 -0500 | [diff] [blame] | 2730 | private void hideFullScreenPlugin() { |
| 2731 | if (mWebView == null) { |
| 2732 | return; |
| 2733 | } |
Grace Kloba | 11438c3 | 2009-12-16 11:39:12 -0800 | [diff] [blame] | 2734 | mWebView.mPrivateHandler.obtainMessage(WebView.HIDE_FULLSCREEN) |
| 2735 | .sendToTarget(); |
| 2736 | } |
Derek Sollenberger | 51ef573 | 2009-12-07 16:15:13 -0500 | [diff] [blame] | 2737 | |
Derek Sollenberger | 36a4f23 | 2011-01-04 16:05:43 -0500 | [diff] [blame] | 2738 | private ViewManager.ChildView createSurface(View pluginView) { |
Patrick Scott | fb6aecb | 2009-07-17 16:38:07 -0400 | [diff] [blame] | 2739 | if (mWebView == null) { |
| 2740 | return null; |
| 2741 | } |
Derek Sollenberger | c0b8a96 | 2009-09-22 14:08:09 -0400 | [diff] [blame] | 2742 | |
Derek Sollenberger | 7c5bf46 | 2010-01-11 12:50:51 -0500 | [diff] [blame] | 2743 | if (pluginView == null) { |
| 2744 | Log.e(LOGTAG, "Attempted to add an empty plugin view to the view hierarchy"); |
Derek Sollenberger | 0b3a5d6 | 2009-09-08 18:31:40 -0400 | [diff] [blame] | 2745 | return null; |
| 2746 | } |
Derek Sollenberger | c0b8a96 | 2009-09-22 14:08:09 -0400 | [diff] [blame] | 2747 | |
Derek Sollenberger | 7c5bf46 | 2010-01-11 12:50:51 -0500 | [diff] [blame] | 2748 | // ensures the view system knows the view can redraw itself |
Derek Sollenberger | 42d00fb | 2009-12-01 15:19:42 -0500 | [diff] [blame] | 2749 | pluginView.setWillNotDraw(false); |
Derek Sollenberger | c0b8a96 | 2009-09-22 14:08:09 -0400 | [diff] [blame] | 2750 | |
Derek Sollenberger | 2120cd6 | 2010-02-23 16:52:45 -0500 | [diff] [blame] | 2751 | if(pluginView instanceof SurfaceView) |
| 2752 | ((SurfaceView)pluginView).setZOrderOnTop(true); |
| 2753 | |
Derek Sollenberger | 0b3a5d6 | 2009-09-08 18:31:40 -0400 | [diff] [blame] | 2754 | ViewManager.ChildView view = mWebView.mViewManager.createView(); |
| 2755 | view.mView = pluginView; |
Derek Sollenberger | 36a4f23 | 2011-01-04 16:05:43 -0500 | [diff] [blame] | 2756 | return view; |
| 2757 | } |
John Reck | 7818aaa | 2011-04-26 16:57:46 -0700 | [diff] [blame] | 2758 | |
Derek Sollenberger | 36a4f23 | 2011-01-04 16:05:43 -0500 | [diff] [blame] | 2759 | // called by JNI. PluginWidget functions for creating an embedded View for |
| 2760 | // the surface drawing model. |
| 2761 | private ViewManager.ChildView addSurface(View pluginView, int x, int y, |
| 2762 | int width, int height) { |
| 2763 | ViewManager.ChildView view = createSurface(pluginView); |
Derek Sollenberger | 0b3a5d6 | 2009-09-08 18:31:40 -0400 | [diff] [blame] | 2764 | view.attachView(x, y, width, height); |
| 2765 | return view; |
Patrick Scott | fb6aecb | 2009-07-17 16:38:07 -0400 | [diff] [blame] | 2766 | } |
Derek Sollenberger | cb37e71 | 2009-11-24 14:58:09 -0500 | [diff] [blame] | 2767 | |
Derek Sollenberger | 3dafca1 | 2009-10-13 11:38:25 -0400 | [diff] [blame] | 2768 | private void updateSurface(ViewManager.ChildView childView, int x, int y, |
| 2769 | int width, int height) { |
| 2770 | childView.attachView(x, y, width, height); |
| 2771 | } |
| 2772 | |
Derek Sollenberger | 0b3a5d6 | 2009-09-08 18:31:40 -0400 | [diff] [blame] | 2773 | private void destroySurface(ViewManager.ChildView childView) { |
| 2774 | childView.removeView(); |
Patrick Scott | fb6aecb | 2009-07-17 16:38:07 -0400 | [diff] [blame] | 2775 | } |
| 2776 | |
Grace Kloba | 3a0def2 | 2010-01-23 21:11:54 -0800 | [diff] [blame] | 2777 | // called by JNI |
| 2778 | static class ShowRectData { |
| 2779 | int mLeft; |
| 2780 | int mTop; |
| 2781 | int mWidth; |
| 2782 | int mHeight; |
| 2783 | int mContentWidth; |
| 2784 | int mContentHeight; |
| 2785 | float mXPercentInDoc; |
| 2786 | float mXPercentInView; |
| 2787 | float mYPercentInDoc; |
| 2788 | float mYPercentInView; |
| 2789 | } |
| 2790 | |
| 2791 | private void showRect(int left, int top, int width, int height, |
| 2792 | int contentWidth, int contentHeight, float xPercentInDoc, |
| 2793 | float xPercentInView, float yPercentInDoc, float yPercentInView) { |
| 2794 | if (mWebView != null) { |
| 2795 | ShowRectData data = new ShowRectData(); |
| 2796 | data.mLeft = left; |
| 2797 | data.mTop = top; |
| 2798 | data.mWidth = width; |
| 2799 | data.mHeight = height; |
| 2800 | data.mContentWidth = contentWidth; |
| 2801 | data.mContentHeight = contentHeight; |
| 2802 | data.mXPercentInDoc = xPercentInDoc; |
| 2803 | data.mXPercentInView = xPercentInView; |
| 2804 | data.mYPercentInDoc = yPercentInDoc; |
| 2805 | data.mYPercentInView = yPercentInView; |
| 2806 | Message.obtain(mWebView.mPrivateHandler, WebView.SHOW_RECT_MSG_ID, |
| 2807 | data).sendToTarget(); |
| 2808 | } |
| 2809 | } |
| 2810 | |
Grace Kloba | e8300a1 | 2010-03-12 13:32:55 -0800 | [diff] [blame] | 2811 | // called by JNI |
| 2812 | private void centerFitRect(int x, int y, int width, int height) { |
| 2813 | if (mWebView == null) { |
| 2814 | return; |
| 2815 | } |
| 2816 | mWebView.mPrivateHandler.obtainMessage(WebView.CENTER_FIT_RECT, |
| 2817 | new Rect(x, y, x + width, y + height)).sendToTarget(); |
| 2818 | } |
| 2819 | |
Grace Kloba | 50004bc | 2010-04-13 22:58:51 -0700 | [diff] [blame] | 2820 | // called by JNI |
| 2821 | private void setScrollbarModes(int hMode, int vMode) { |
| 2822 | if (mWebView == null) { |
| 2823 | return; |
| 2824 | } |
| 2825 | mWebView.mPrivateHandler.obtainMessage(WebView.SET_SCROLLBAR_MODES, |
| 2826 | hMode, vMode).sendToTarget(); |
| 2827 | } |
| 2828 | |
Svetoslav Ganov | 9504f57 | 2011-01-14 11:38:17 -0800 | [diff] [blame] | 2829 | // called by JNI |
| 2830 | @SuppressWarnings("unused") |
| 2831 | private void selectAt(int x, int y) { |
| 2832 | if (mWebView != null) { |
| 2833 | mWebView.mPrivateHandler.obtainMessage(WebView.SELECT_AT, x, y).sendToTarget(); |
| 2834 | } |
| 2835 | } |
| 2836 | |
Steve Block | 68dede3 | 2010-08-04 10:28:46 +0100 | [diff] [blame] | 2837 | private void useMockDeviceOrientation() { |
Steve Block | 1be7339 | 2010-10-15 16:31:01 +0100 | [diff] [blame] | 2838 | mDeviceMotionAndOrientationManager.useMock(); |
Steve Block | f4a705f | 2010-08-11 13:08:24 +0100 | [diff] [blame] | 2839 | } |
| 2840 | |
| 2841 | public void setMockDeviceOrientation(boolean canProvideAlpha, double alpha, |
| 2842 | boolean canProvideBeta, double beta, boolean canProvideGamma, double gamma) { |
Steve Block | 1be7339 | 2010-10-15 16:31:01 +0100 | [diff] [blame] | 2843 | mDeviceMotionAndOrientationManager.setMockOrientation(canProvideAlpha, alpha, |
| 2844 | canProvideBeta, beta, canProvideGamma, gamma); |
Steve Block | 68dede3 | 2010-08-04 10:28:46 +0100 | [diff] [blame] | 2845 | } |
| 2846 | |
Steve Block | dc82a29 | 2010-10-06 14:34:15 +0100 | [diff] [blame] | 2847 | protected DeviceMotionService getDeviceMotionService() { |
| 2848 | if (mDeviceMotionService == null) { |
| 2849 | mDeviceMotionService = |
Steve Block | 1be7339 | 2010-10-15 16:31:01 +0100 | [diff] [blame] | 2850 | new DeviceMotionService(mDeviceMotionAndOrientationManager, mContext); |
Steve Block | dc82a29 | 2010-10-06 14:34:15 +0100 | [diff] [blame] | 2851 | } |
| 2852 | return mDeviceMotionService; |
| 2853 | } |
| 2854 | |
Steve Block | c43565b | 2010-08-11 13:12:37 +0100 | [diff] [blame] | 2855 | protected DeviceOrientationService getDeviceOrientationService() { |
| 2856 | if (mDeviceOrientationService == null) { |
Steve Block | bb9db22 | 2010-08-18 11:12:07 +0100 | [diff] [blame] | 2857 | mDeviceOrientationService = |
Steve Block | 1be7339 | 2010-10-15 16:31:01 +0100 | [diff] [blame] | 2858 | new DeviceOrientationService(mDeviceMotionAndOrientationManager, mContext); |
Steve Block | c43565b | 2010-08-11 13:12:37 +0100 | [diff] [blame] | 2859 | } |
| 2860 | return mDeviceOrientationService; |
| 2861 | } |
| 2862 | |
Chris Craik | 58d94af | 2011-08-18 11:42:13 -0700 | [diff] [blame] | 2863 | private native void nativeSetIsPaused(boolean isPaused); |
Mike Reed | d205d5b | 2009-05-27 11:02:29 -0400 | [diff] [blame] | 2864 | private native void nativePause(); |
| 2865 | private native void nativeResume(); |
Derek Sollenberger | e0155e9 | 2009-06-10 15:35:45 -0400 | [diff] [blame] | 2866 | private native void nativeFreeMemory(); |
Derek Sollenberger | b6ddc7a | 2009-12-08 15:41:46 -0500 | [diff] [blame] | 2867 | private native void nativeFullScreenPluginHidden(int npp); |
Derek Sollenberger | 281432c | 2011-08-22 14:05:49 -0400 | [diff] [blame] | 2868 | private native void nativePluginSurfaceReady(); |
Cary Clark | 1cb97ee | 2009-12-11 12:10:36 -0500 | [diff] [blame] | 2869 | private native boolean nativeValidNodeAndBounds(int frame, int node, |
| 2870 | Rect bounds); |
| 2871 | |
Grace Kloba | 178db41 | 2010-05-18 22:22:23 -0700 | [diff] [blame] | 2872 | private native ArrayList<Rect> nativeGetTouchHighlightRects(int x, int y, |
| 2873 | int slop); |
Ben Murdoch | 62275a4 | 2010-09-07 11:27:28 +0100 | [diff] [blame] | 2874 | |
| 2875 | private native void nativeAutoFillForm(int queryId); |
Patrick Scott | cfa734a | 2011-02-22 11:19:02 -0500 | [diff] [blame] | 2876 | private native void nativeScrollLayer(int layer, Rect rect); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2877 | } |