The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 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 | |
Raphael | 30df237 | 2010-03-06 10:09:54 -0800 | [diff] [blame] | 19 | import android.annotation.Widget; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | import android.content.Context; |
Cary Clark | c5cd5e9 | 2010-11-22 15:20:02 -0500 | [diff] [blame] | 21 | import android.content.res.Configuration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import android.graphics.Bitmap; |
| 23 | import android.graphics.Canvas; |
John Reck | a5408e6 | 2012-03-16 14:18:44 -0700 | [diff] [blame] | 24 | import android.graphics.Paint; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | import android.graphics.Picture; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | import android.graphics.Rect; |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 27 | import android.graphics.drawable.Drawable; |
Adam Powell | 9d32d24 | 2010-03-29 16:02:07 -0700 | [diff] [blame] | 28 | import android.net.http.SslCertificate; |
Kristian Monsen | b5cd8c0 | 2013-04-09 17:57:37 -0700 | [diff] [blame] | 29 | import android.os.Build; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | import android.os.Bundle; |
Steve Block | 08d584c | 2011-05-17 19:05:03 +0100 | [diff] [blame] | 31 | import android.os.Looper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | import android.os.Message; |
Steve Block | 08d584c | 2011-05-17 19:05:03 +0100 | [diff] [blame] | 33 | import android.os.StrictMode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | import android.util.AttributeSet; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | import android.util.Log; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | import android.view.KeyEvent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import android.view.MotionEvent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | import android.view.View; |
John Reck | 926cf56 | 2012-06-14 10:00:31 -0700 | [diff] [blame] | 39 | import android.view.ViewDebug; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | import android.view.ViewGroup; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | import android.view.ViewTreeObserver; |
Svetoslav Ganov | d9ee72f | 2011-10-05 22:26:05 -0700 | [diff] [blame] | 42 | import android.view.accessibility.AccessibilityEvent; |
Svetoslav Ganov | d9ee72f | 2011-10-05 22:26:05 -0700 | [diff] [blame] | 43 | import android.view.accessibility.AccessibilityNodeInfo; |
Ben Murdoch | e3f9071 | 2013-06-05 14:19:48 +0100 | [diff] [blame] | 44 | import android.view.accessibility.AccessibilityNodeProvider; |
Derek Sollenberger | 7cabb03 | 2010-01-21 10:37:38 -0500 | [diff] [blame] | 45 | import android.view.inputmethod.EditorInfo; |
| 46 | import android.view.inputmethod.InputConnection; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | import android.widget.AbsoluteLayout; |
Steve Block | f95d490 | 2011-06-09 11:53:26 +0100 | [diff] [blame] | 48 | |
John Reck | 926cf56 | 2012-06-14 10:00:31 -0700 | [diff] [blame] | 49 | import java.io.BufferedWriter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | import java.io.File; |
Andrei Popescu | 4950b2b | 2009-09-03 13:56:07 +0100 | [diff] [blame] | 51 | import java.util.Map; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | |
| 53 | /** |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 54 | * <p>A View that displays web pages. This class is the basis upon which you |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | * can roll your own web browser or simply display some online content within your Activity. |
| 56 | * It uses the WebKit rendering engine to display |
| 57 | * web pages and includes methods to navigate forward and backward |
| 58 | * through a history, zoom in and out, perform text searches and more.</p> |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 59 | * <p>To enable the built-in zoom, set |
| 60 | * {@link #getSettings() WebSettings}.{@link WebSettings#setBuiltInZoomControls(boolean)} |
Steve Block | b838aef | 2012-04-23 18:22:15 +0100 | [diff] [blame] | 61 | * (introduced in API level {@link android.os.Build.VERSION_CODES#CUPCAKE}). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | * <p>Note that, in order for your Activity to access the Internet and load web pages |
Scott Main | 8b3cea0 | 2010-05-14 14:12:43 -0700 | [diff] [blame] | 63 | * in a WebView, you must add the {@code INTERNET} permissions to your |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | * Android Manifest file:</p> |
| 65 | * <pre><uses-permission android:name="android.permission.INTERNET" /></pre> |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 66 | * |
Scott Main | 8b3cea0 | 2010-05-14 14:12:43 -0700 | [diff] [blame] | 67 | * <p>This must be a child of the <a |
Ben Dodson | 4e8620f | 2010-08-25 10:55:47 -0700 | [diff] [blame] | 68 | * href="{@docRoot}guide/topics/manifest/manifest-element.html">{@code <manifest>}</a> |
Scott Main | 8b3cea0 | 2010-05-14 14:12:43 -0700 | [diff] [blame] | 69 | * element.</p> |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 70 | * |
Scott Main | 4c359b7 | 2012-07-24 15:51:27 -0700 | [diff] [blame] | 71 | * <p>For more information, read |
| 72 | * <a href="{@docRoot}guide/webapps/webview.html">Building Web Apps in WebView</a>.</p> |
Scott Main | 41ec653 | 2010-08-19 16:57:07 -0700 | [diff] [blame] | 73 | * |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 74 | * <h3>Basic usage</h3> |
| 75 | * |
| 76 | * <p>By default, a WebView provides no browser-like widgets, does not |
Scott Main | 8b3cea0 | 2010-05-14 14:12:43 -0700 | [diff] [blame] | 77 | * enable JavaScript and web page errors are ignored. If your goal is only |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 78 | * to display some HTML as a part of your UI, this is probably fine; |
| 79 | * the user won't need to interact with the web page beyond reading |
| 80 | * it, and the web page won't need to interact with the user. If you |
Scott Main | 8b3cea0 | 2010-05-14 14:12:43 -0700 | [diff] [blame] | 81 | * actually want a full-blown web browser, then you probably want to |
| 82 | * invoke the Browser application with a URL Intent rather than show it |
| 83 | * with a WebView. For example: |
| 84 | * <pre> |
| 85 | * Uri uri = Uri.parse("http://www.example.com"); |
| 86 | * Intent intent = new Intent(Intent.ACTION_VIEW, uri); |
| 87 | * startActivity(intent); |
| 88 | * </pre> |
| 89 | * <p>See {@link android.content.Intent} for more information.</p> |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 90 | * |
Ben Dodson | 4e8620f | 2010-08-25 10:55:47 -0700 | [diff] [blame] | 91 | * <p>To provide a WebView in your own Activity, include a {@code <WebView>} in your layout, |
Scott Main | 8b3cea0 | 2010-05-14 14:12:43 -0700 | [diff] [blame] | 92 | * or set the entire Activity window as a WebView during {@link |
| 93 | * android.app.Activity#onCreate(Bundle) onCreate()}:</p> |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 94 | * <pre class="prettyprint"> |
| 95 | * WebView webview = new WebView(this); |
| 96 | * setContentView(webview); |
Scott Main | 8b3cea0 | 2010-05-14 14:12:43 -0700 | [diff] [blame] | 97 | * </pre> |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 98 | * |
Scott Main | 8b3cea0 | 2010-05-14 14:12:43 -0700 | [diff] [blame] | 99 | * <p>Then load the desired web page:</p> |
Scott Main | e3b9f8b | 2010-05-18 08:41:36 -0700 | [diff] [blame] | 100 | * <pre> |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 101 | * // Simplest usage: note that an exception will NOT be thrown |
| 102 | * // if there is an error loading this page (see below). |
| 103 | * webview.loadUrl("http://slashdot.org/"); |
| 104 | * |
Scott Main | 8b3cea0 | 2010-05-14 14:12:43 -0700 | [diff] [blame] | 105 | * // OR, you can also load from an HTML string: |
Scott Main | e3b9f8b | 2010-05-18 08:41:36 -0700 | [diff] [blame] | 106 | * String summary = "<html><body>You scored <b>192</b> points.</body></html>"; |
Steve Block | f95d490 | 2011-06-09 11:53:26 +0100 | [diff] [blame] | 107 | * webview.loadData(summary, "text/html", null); |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 108 | * // ... although note that there are restrictions on what this HTML can do. |
Scott Main | 8b3cea0 | 2010-05-14 14:12:43 -0700 | [diff] [blame] | 109 | * // See the JavaDocs for {@link #loadData(String,String,String) loadData()} and {@link |
| 110 | * #loadDataWithBaseURL(String,String,String,String,String) loadDataWithBaseURL()} for more info. |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 111 | * </pre> |
| 112 | * |
| 113 | * <p>A WebView has several customization points where you can add your |
| 114 | * own behavior. These are:</p> |
| 115 | * |
| 116 | * <ul> |
| 117 | * <li>Creating and setting a {@link android.webkit.WebChromeClient} subclass. |
| 118 | * This class is called when something that might impact a |
| 119 | * browser UI happens, for instance, progress updates and |
Scott Main | 8b3cea0 | 2010-05-14 14:12:43 -0700 | [diff] [blame] | 120 | * JavaScript alerts are sent here (see <a |
| 121 | * href="{@docRoot}guide/developing/debug-tasks.html#DebuggingWebPages">Debugging Tasks</a>). |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 122 | * </li> |
| 123 | * <li>Creating and setting a {@link android.webkit.WebViewClient} subclass. |
| 124 | * It will be called when things happen that impact the |
| 125 | * rendering of the content, eg, errors or form submissions. You |
Scott Main | 8b3cea0 | 2010-05-14 14:12:43 -0700 | [diff] [blame] | 126 | * can also intercept URL loading here (via {@link |
| 127 | * android.webkit.WebViewClient#shouldOverrideUrlLoading(WebView,String) |
| 128 | * shouldOverrideUrlLoading()}).</li> |
| 129 | * <li>Modifying the {@link android.webkit.WebSettings}, such as |
| 130 | * enabling JavaScript with {@link android.webkit.WebSettings#setJavaScriptEnabled(boolean) |
| 131 | * setJavaScriptEnabled()}. </li> |
Steve Block | 4cd73c5 | 2011-11-09 13:06:52 +0000 | [diff] [blame] | 132 | * <li>Injecting Java objects into the WebView using the |
| 133 | * {@link android.webkit.WebView#addJavascriptInterface} method. This |
| 134 | * method allows you to inject Java objects into a page's JavaScript |
| 135 | * context, so that they can be accessed by JavaScript in the page.</li> |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 136 | * </ul> |
| 137 | * |
| 138 | * <p>Here's a more complicated example, showing error handling, |
| 139 | * settings, and progress notification:</p> |
| 140 | * |
| 141 | * <pre class="prettyprint"> |
| 142 | * // Let's display the progress in the activity title bar, like the |
| 143 | * // browser app does. |
| 144 | * getWindow().requestFeature(Window.FEATURE_PROGRESS); |
| 145 | * |
| 146 | * webview.getSettings().setJavaScriptEnabled(true); |
| 147 | * |
| 148 | * final Activity activity = this; |
| 149 | * webview.setWebChromeClient(new WebChromeClient() { |
| 150 | * public void onProgressChanged(WebView view, int progress) { |
| 151 | * // Activities and WebViews measure progress with different scales. |
| 152 | * // The progress meter will automatically disappear when we reach 100% |
| 153 | * activity.setProgress(progress * 1000); |
| 154 | * } |
| 155 | * }); |
| 156 | * webview.setWebViewClient(new WebViewClient() { |
| 157 | * public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { |
| 158 | * Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show(); |
| 159 | * } |
| 160 | * }); |
| 161 | * |
| 162 | * webview.loadUrl("http://slashdot.org/"); |
| 163 | * </pre> |
| 164 | * |
| 165 | * <h3>Cookie and window management</h3> |
| 166 | * |
| 167 | * <p>For obvious security reasons, your application has its own |
Scott Main | 8b3cea0 | 2010-05-14 14:12:43 -0700 | [diff] [blame] | 168 | * cache, cookie store etc.—it does not share the Browser |
Steve Block | c723e35 | 2012-08-14 14:48:05 +0100 | [diff] [blame] | 169 | * application's data. |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 170 | * </p> |
| 171 | * |
| 172 | * <p>By default, requests by the HTML to open new windows are |
| 173 | * ignored. This is true whether they be opened by JavaScript or by |
| 174 | * the target attribute on a link. You can customize your |
Scott Main | 8b3cea0 | 2010-05-14 14:12:43 -0700 | [diff] [blame] | 175 | * {@link WebChromeClient} to provide your own behaviour for opening multiple windows, |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 176 | * and render them in whatever manner you want.</p> |
| 177 | * |
Scott Main | 8b3cea0 | 2010-05-14 14:12:43 -0700 | [diff] [blame] | 178 | * <p>The standard behavior for an Activity is to be destroyed and |
| 179 | * recreated when the device orientation or any other configuration changes. This will cause |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 180 | * the WebView to reload the current page. If you don't want that, you |
Scott Main | 8b3cea0 | 2010-05-14 14:12:43 -0700 | [diff] [blame] | 181 | * can set your Activity to handle the {@code orientation} and {@code keyboardHidden} |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 182 | * changes, and then just leave the WebView alone. It'll automatically |
Scott Main | 8b3cea0 | 2010-05-14 14:12:43 -0700 | [diff] [blame] | 183 | * re-orient itself as appropriate. Read <a |
| 184 | * href="{@docRoot}guide/topics/resources/runtime-changes.html">Handling Runtime Changes</a> for |
| 185 | * more information about how to handle configuration changes during runtime.</p> |
| 186 | * |
| 187 | * |
| 188 | * <h3>Building web pages to support different screen densities</h3> |
| 189 | * |
| 190 | * <p>The screen density of a device is based on the screen resolution. A screen with low density |
| 191 | * has fewer available pixels per inch, where a screen with high density |
Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 192 | * has more — sometimes significantly more — pixels per inch. The density of a |
Scott Main | 8b3cea0 | 2010-05-14 14:12:43 -0700 | [diff] [blame] | 193 | * screen is important because, other things being equal, a UI element (such as a button) whose |
| 194 | * height and width are defined in terms of screen pixels will appear larger on the lower density |
| 195 | * screen and smaller on the higher density screen. |
| 196 | * For simplicity, Android collapses all actual screen densities into three generalized densities: |
| 197 | * high, medium, and low.</p> |
| 198 | * <p>By default, WebView scales a web page so that it is drawn at a size that matches the default |
| 199 | * appearance on a medium density screen. So, it applies 1.5x scaling on a high density screen |
| 200 | * (because its pixels are smaller) and 0.75x scaling on a low density screen (because its pixels |
| 201 | * are bigger). |
Steve Block | b838aef | 2012-04-23 18:22:15 +0100 | [diff] [blame] | 202 | * Starting with API level {@link android.os.Build.VERSION_CODES#ECLAIR}, WebView supports DOM, CSS, |
| 203 | * and meta tag features to help you (as a web developer) target screens with different screen |
| 204 | * densities.</p> |
Scott Main | 8b3cea0 | 2010-05-14 14:12:43 -0700 | [diff] [blame] | 205 | * <p>Here's a summary of the features you can use to handle different screen densities:</p> |
| 206 | * <ul> |
| 207 | * <li>The {@code window.devicePixelRatio} DOM property. The value of this property specifies the |
| 208 | * default scaling factor used for the current device. For example, if the value of {@code |
| 209 | * window.devicePixelRatio} is "1.0", then the device is considered a medium density (mdpi) device |
| 210 | * and default scaling is not applied to the web page; if the value is "1.5", then the device is |
| 211 | * considered a high density device (hdpi) and the page content is scaled 1.5x; if the |
| 212 | * value is "0.75", then the device is considered a low density device (ldpi) and the content is |
Jonathan Dixon | 89f48e9 | 2013-02-27 16:42:48 -0800 | [diff] [blame] | 213 | * scaled 0.75x.</li> |
Scott Main | 8b3cea0 | 2010-05-14 14:12:43 -0700 | [diff] [blame] | 214 | * <li>The {@code -webkit-device-pixel-ratio} CSS media query. Use this to specify the screen |
| 215 | * densities for which this style sheet is to be used. The corresponding value should be either |
| 216 | * "0.75", "1", or "1.5", to indicate that the styles are for devices with low density, medium |
| 217 | * density, or high density screens, respectively. For example: |
| 218 | * <pre> |
| 219 | * <link rel="stylesheet" media="screen and (-webkit-device-pixel-ratio:1.5)" href="hdpi.css" /></pre> |
| 220 | * <p>The {@code hdpi.css} stylesheet is only used for devices with a screen pixel ration of 1.5, |
| 221 | * which is the high density pixel ratio.</p> |
| 222 | * </li> |
Scott Main | 8b3cea0 | 2010-05-14 14:12:43 -0700 | [diff] [blame] | 223 | * |
Teng-Hui Zhu | 50ba5a2 | 2012-01-11 15:57:21 -0800 | [diff] [blame] | 224 | * <h3>HTML5 Video support</h3> |
| 225 | * |
| 226 | * <p>In order to support inline HTML5 video in your application, you need to have hardware |
| 227 | * acceleration turned on, and set a {@link android.webkit.WebChromeClient}. For full screen support, |
| 228 | * implementations of {@link WebChromeClient#onShowCustomView(View, WebChromeClient.CustomViewCallback)} |
| 229 | * and {@link WebChromeClient#onHideCustomView()} are required, |
| 230 | * {@link WebChromeClient#getVideoLoadingProgressView()} is optional. |
| 231 | * </p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 232 | */ |
Steve Block | 406aeb2 | 2012-04-23 18:17:19 +0100 | [diff] [blame] | 233 | // Implementation notes. |
| 234 | // The WebView is a thin API class that delegates its public API to a backend WebViewProvider |
| 235 | // class instance. WebView extends {@link AbsoluteLayout} for backward compatibility reasons. |
| 236 | // Methods are delegated to the provider implementation: all public API methods introduced in this |
| 237 | // file are fully delegated, whereas public and protected methods from the View base classes are |
| 238 | // only delegated where a specific need exists for them to do so. |
Raphael | 30df237 | 2010-03-06 10:09:54 -0800 | [diff] [blame] | 239 | @Widget |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 240 | public class WebView extends AbsoluteLayout |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 241 | implements ViewTreeObserver.OnGlobalFocusChangeListener, |
John Reck | 926cf56 | 2012-06-14 10:00:31 -0700 | [diff] [blame] | 242 | ViewGroup.OnHierarchyChangeListener, ViewDebug.HierarchyHandler { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 243 | |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 244 | private static final String LOGTAG = "webview_proxy"; |
Nicolas Roard | 12c18e6 | 2010-10-13 20:14:31 -0700 | [diff] [blame] | 245 | |
Kristian Monsen | b5cd8c0 | 2013-04-09 17:57:37 -0700 | [diff] [blame] | 246 | // Throwing an exception for incorrect thread usage if the |
| 247 | // build target is JB MR2 or newer. Defaults to false, and is |
| 248 | // set in the WebView constructor. |
| 249 | private static Boolean sEnforceThreadChecking = false; |
| 250 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 251 | /** |
| 252 | * Transportation object for returning WebView across thread boundaries. |
| 253 | */ |
| 254 | public class WebViewTransport { |
| 255 | private WebView mWebview; |
| 256 | |
| 257 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 258 | * Sets the WebView to the transportation object. |
| 259 | * |
| 260 | * @param webview the WebView to transport |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 261 | */ |
| 262 | public synchronized void setWebView(WebView webview) { |
| 263 | mWebview = webview; |
| 264 | } |
| 265 | |
| 266 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 267 | * Gets the WebView object. |
| 268 | * |
| 269 | * @return the transported WebView object |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 270 | */ |
| 271 | public synchronized WebView getWebView() { |
| 272 | return mWebview; |
| 273 | } |
| 274 | } |
| 275 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 276 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 277 | * URI scheme for telephone number. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 278 | */ |
| 279 | public static final String SCHEME_TEL = "tel:"; |
| 280 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 281 | * URI scheme for email address. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 282 | */ |
| 283 | public static final String SCHEME_MAILTO = "mailto:"; |
| 284 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 285 | * URI scheme for map address. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 286 | */ |
| 287 | public static final String SCHEME_GEO = "geo:0,0?q="; |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 288 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 289 | /** |
Victoria Lease | d405a43 | 2012-03-22 15:53:48 -0700 | [diff] [blame] | 290 | * Interface to listen for find results. |
Victoria Lease | d405a43 | 2012-03-22 15:53:48 -0700 | [diff] [blame] | 291 | */ |
| 292 | public interface FindListener { |
| 293 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 294 | * Notifies the listener about progress made by a find operation. |
Victoria Lease | d405a43 | 2012-03-22 15:53:48 -0700 | [diff] [blame] | 295 | * |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 296 | * @param activeMatchOrdinal the zero-based ordinal of the currently selected match |
Selim Gurun | 92b81a3 | 2012-08-21 17:32:35 -0700 | [diff] [blame] | 297 | * @param numberOfMatches how many matches have been found |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 298 | * @param isDoneCounting whether the find operation has actually completed. The listener |
| 299 | * may be notified multiple times while the |
| 300 | * operation is underway, and the numberOfMatches |
| 301 | * value should not be considered final unless |
| 302 | * isDoneCounting is true. |
Victoria Lease | d405a43 | 2012-03-22 15:53:48 -0700 | [diff] [blame] | 303 | */ |
Selim Gurun | 92b81a3 | 2012-08-21 17:32:35 -0700 | [diff] [blame] | 304 | public void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches, |
Victoria Lease | d405a43 | 2012-03-22 15:53:48 -0700 | [diff] [blame] | 305 | boolean isDoneCounting); |
| 306 | } |
| 307 | |
| 308 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 309 | * Interface to listen for new pictures as they change. |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 310 | * |
Kristian Monsen | fc77165 | 2011-05-10 16:44:05 +0100 | [diff] [blame] | 311 | * @deprecated This interface is now obsolete. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 312 | */ |
Kristian Monsen | fc77165 | 2011-05-10 16:44:05 +0100 | [diff] [blame] | 313 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 314 | public interface PictureListener { |
| 315 | /** |
Steve Block | 72498ed | 2012-07-17 15:57:25 +0100 | [diff] [blame] | 316 | * Used to provide notification that the WebView's picture has changed. |
| 317 | * See {@link WebView#capturePicture} for details of the picture. |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 318 | * |
| 319 | * @param view the WebView that owns the picture |
Ben Murdoch | 52643e0 | 2013-02-26 12:01:00 +0000 | [diff] [blame] | 320 | * @param picture the new picture. Applications targeting |
| 321 | * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2} or above |
| 322 | * will always receive a null Picture. |
Steve Block | 72498ed | 2012-07-17 15:57:25 +0100 | [diff] [blame] | 323 | * @deprecated Deprecated due to internal changes. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 324 | */ |
Kristian Monsen | fc77165 | 2011-05-10 16:44:05 +0100 | [diff] [blame] | 325 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 326 | public void onNewPicture(WebView view, Picture picture); |
| 327 | } |
| 328 | |
Jonathan Dixon | 19644b6 | 2011-12-21 14:21:36 +0000 | [diff] [blame] | 329 | public static class HitTestResult { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 330 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 331 | * Default HitTestResult, where the target is unknown. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 332 | */ |
| 333 | public static final int UNKNOWN_TYPE = 0; |
| 334 | /** |
Steve Block | 1854ddb | 2011-04-19 12:18:19 +0100 | [diff] [blame] | 335 | * @deprecated This type is no longer used. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 336 | */ |
Steve Block | 1854ddb | 2011-04-19 12:18:19 +0100 | [diff] [blame] | 337 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 338 | public static final int ANCHOR_TYPE = 1; |
| 339 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 340 | * HitTestResult for hitting a phone number. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 341 | */ |
| 342 | public static final int PHONE_TYPE = 2; |
| 343 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 344 | * HitTestResult for hitting a map address. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 345 | */ |
| 346 | public static final int GEO_TYPE = 3; |
| 347 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 348 | * HitTestResult for hitting an email address. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 349 | */ |
| 350 | public static final int EMAIL_TYPE = 4; |
| 351 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 352 | * HitTestResult for hitting an HTML::img tag. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 353 | */ |
| 354 | public static final int IMAGE_TYPE = 5; |
| 355 | /** |
Steve Block | 1854ddb | 2011-04-19 12:18:19 +0100 | [diff] [blame] | 356 | * @deprecated This type is no longer used. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 357 | */ |
Steve Block | 1854ddb | 2011-04-19 12:18:19 +0100 | [diff] [blame] | 358 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 359 | public static final int IMAGE_ANCHOR_TYPE = 6; |
| 360 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 361 | * HitTestResult for hitting a HTML::a tag with src=http. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 362 | */ |
| 363 | public static final int SRC_ANCHOR_TYPE = 7; |
| 364 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 365 | * HitTestResult for hitting a HTML::a tag with src=http + HTML::img. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 366 | */ |
| 367 | public static final int SRC_IMAGE_ANCHOR_TYPE = 8; |
| 368 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 369 | * HitTestResult for hitting an edit text area. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 370 | */ |
| 371 | public static final int EDIT_TEXT_TYPE = 9; |
| 372 | |
| 373 | private int mType; |
| 374 | private String mExtra; |
| 375 | |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 376 | /** |
| 377 | * @hide Only for use by WebViewProvider implementations |
| 378 | */ |
| 379 | public HitTestResult() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 380 | mType = UNKNOWN_TYPE; |
| 381 | } |
| 382 | |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 383 | /** |
| 384 | * @hide Only for use by WebViewProvider implementations |
| 385 | */ |
| 386 | public void setType(int type) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 387 | mType = type; |
| 388 | } |
| 389 | |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 390 | /** |
| 391 | * @hide Only for use by WebViewProvider implementations |
| 392 | */ |
| 393 | public void setExtra(String extra) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 394 | mExtra = extra; |
| 395 | } |
| 396 | |
Jonathan Dixon | e230e54 | 2011-12-21 10:57:00 +0000 | [diff] [blame] | 397 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 398 | * Gets the type of the hit test result. See the XXX_TYPE constants |
| 399 | * defined in this class. |
| 400 | * |
| 401 | * @return the type of the hit test result |
Jonathan Dixon | e230e54 | 2011-12-21 10:57:00 +0000 | [diff] [blame] | 402 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 403 | public int getType() { |
| 404 | return mType; |
| 405 | } |
| 406 | |
Jonathan Dixon | e230e54 | 2011-12-21 10:57:00 +0000 | [diff] [blame] | 407 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 408 | * Gets additional type-dependant information about the result. See |
| 409 | * {@link WebView#getHitTestResult()} for details. May either be null |
| 410 | * or contain extra information about this result. |
| 411 | * |
| 412 | * @return additional type-dependant information about the result |
Jonathan Dixon | e230e54 | 2011-12-21 10:57:00 +0000 | [diff] [blame] | 413 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 414 | public String getExtra() { |
| 415 | return mExtra; |
| 416 | } |
| 417 | } |
| 418 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 419 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 420 | * Constructs a new WebView with a Context object. |
| 421 | * |
| 422 | * @param context a Context object used to access application assets |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 423 | */ |
| 424 | public WebView(Context context) { |
| 425 | this(context, null); |
| 426 | } |
| 427 | |
| 428 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 429 | * Constructs a new WebView with layout parameters. |
| 430 | * |
| 431 | * @param context a Context object used to access application assets |
| 432 | * @param attrs an AttributeSet passed to our parent |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 433 | */ |
| 434 | public WebView(Context context, AttributeSet attrs) { |
| 435 | this(context, attrs, com.android.internal.R.attr.webViewStyle); |
| 436 | } |
| 437 | |
| 438 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 439 | * Constructs a new WebView with layout parameters and a default style. |
| 440 | * |
| 441 | * @param context a Context object used to access application assets |
| 442 | * @param attrs an AttributeSet passed to our parent |
| 443 | * @param defStyle the default style resource ID |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 444 | */ |
| 445 | public WebView(Context context, AttributeSet attrs, int defStyle) { |
Elliott Slaughter | f21d2e3 | 2010-07-14 18:08:54 -0700 | [diff] [blame] | 446 | this(context, attrs, defStyle, false); |
| 447 | } |
| 448 | |
| 449 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 450 | * Constructs a new WebView with layout parameters and a default style. |
| 451 | * |
| 452 | * @param context a Context object used to access application assets |
| 453 | * @param attrs an AttributeSet passed to our parent |
| 454 | * @param defStyle the default style resource ID |
| 455 | * @param privateBrowsing whether this WebView will be initialized in |
| 456 | * private mode |
Kristian Monsen | 5cc2351 | 2012-08-09 15:33:08 -0400 | [diff] [blame] | 457 | * |
| 458 | * @deprecated Private browsing is no longer supported directly via |
| 459 | * WebView and will be removed in a future release. Prefer using |
| 460 | * {@link WebSettings}, {@link WebViewDatabase}, {@link CookieManager} |
| 461 | * and {@link WebStorage} for fine-grained control of privacy data. |
Elliott Slaughter | f21d2e3 | 2010-07-14 18:08:54 -0700 | [diff] [blame] | 462 | */ |
Kristian Monsen | 5cc2351 | 2012-08-09 15:33:08 -0400 | [diff] [blame] | 463 | @Deprecated |
Elliott Slaughter | f21d2e3 | 2010-07-14 18:08:54 -0700 | [diff] [blame] | 464 | public WebView(Context context, AttributeSet attrs, int defStyle, |
| 465 | boolean privateBrowsing) { |
| 466 | this(context, attrs, defStyle, null, privateBrowsing); |
Andrei Popescu | 4950b2b | 2009-09-03 13:56:07 +0100 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 470 | * Constructs a new WebView with layout parameters, a default style and a set |
| 471 | * of custom Javscript interfaces to be added to this WebView at initialization |
Romain Guy | 01d0fbf | 2009-12-01 14:52:19 -0800 | [diff] [blame] | 472 | * time. This guarantees that these interfaces will be available when the JS |
Andrei Popescu | 4950b2b | 2009-09-03 13:56:07 +0100 | [diff] [blame] | 473 | * context is initialized. |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 474 | * |
| 475 | * @param context a Context object used to access application assets |
| 476 | * @param attrs an AttributeSet passed to our parent |
| 477 | * @param defStyle the default style resource ID |
| 478 | * @param javaScriptInterfaces a Map of interface names, as keys, and |
| 479 | * object implementing those interfaces, as |
| 480 | * values |
| 481 | * @param privateBrowsing whether this WebView will be initialized in |
| 482 | * private mode |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 483 | * @hide This is used internally by dumprendertree, as it requires the javaScript interfaces to |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 484 | * be added synchronously, before a subsequent loadUrl call takes effect. |
Andrei Popescu | 4950b2b | 2009-09-03 13:56:07 +0100 | [diff] [blame] | 485 | */ |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 486 | @SuppressWarnings("deprecation") // for super() call into deprecated base class constructor. |
Andrei Popescu | 4950b2b | 2009-09-03 13:56:07 +0100 | [diff] [blame] | 487 | protected WebView(Context context, AttributeSet attrs, int defStyle, |
Steve Block | 81f19ff | 2010-11-01 13:23:24 +0000 | [diff] [blame] | 488 | Map<String, Object> javaScriptInterfaces, boolean privateBrowsing) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 489 | super(context, attrs, defStyle); |
Kristian Monsen | 87af731 | 2011-09-09 02:12:51 +0100 | [diff] [blame] | 490 | if (context == null) { |
| 491 | throw new IllegalArgumentException("Invalid context argument"); |
| 492 | } |
Kristian Monsen | b5cd8c0 | 2013-04-09 17:57:37 -0700 | [diff] [blame] | 493 | sEnforceThreadChecking = context.getApplicationInfo().targetSdkVersion >= |
| 494 | Build.VERSION_CODES.JELLY_BEAN_MR2; |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 495 | checkThread(); |
Kristian Monsen | 87af731 | 2011-09-09 02:12:51 +0100 | [diff] [blame] | 496 | |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 497 | ensureProviderCreated(); |
| 498 | mProvider.init(javaScriptInterfaces, privateBrowsing); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 502 | * Specifies whether the horizontal scrollbar has overlay style. |
| 503 | * |
| 504 | * @param overlay true if horizontal scrollbar should have overlay style |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 505 | */ |
| 506 | public void setHorizontalScrollbarOverlay(boolean overlay) { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 507 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 508 | mProvider.setHorizontalScrollbarOverlay(overlay); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 512 | * Specifies whether the vertical scrollbar has overlay style. |
| 513 | * |
| 514 | * @param overlay true if vertical scrollbar should have overlay style |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 515 | */ |
| 516 | public void setVerticalScrollbarOverlay(boolean overlay) { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 517 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 518 | mProvider.setVerticalScrollbarOverlay(overlay); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 522 | * Gets whether horizontal scrollbar has overlay style. |
| 523 | * |
| 524 | * @return true if horizontal scrollbar has overlay style |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 525 | */ |
| 526 | public boolean overlayHorizontalScrollbar() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 527 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 528 | return mProvider.overlayHorizontalScrollbar(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 532 | * Gets whether vertical scrollbar has overlay style. |
| 533 | * |
| 534 | * @return true if vertical scrollbar has overlay style |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 535 | */ |
| 536 | public boolean overlayVerticalScrollbar() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 537 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 538 | return mProvider.overlayVerticalScrollbar(); |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 539 | } |
| 540 | |
Michael Kolb | e54f665 | 2011-03-16 09:11:51 -0700 | [diff] [blame] | 541 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 542 | * Gets the visible height (in pixels) of the embedded title bar (if any). |
Michael Kolb | 73980a9 | 2010-08-05 16:32:51 -0700 | [diff] [blame] | 543 | * |
Michael Kolb | 24e53b0 | 2011-03-16 12:52:04 -0700 | [diff] [blame] | 544 | * @deprecated This method is now obsolete. |
Kristian Monsen | f491258 | 2012-08-16 15:26:24 -0400 | [diff] [blame] | 545 | * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 546 | */ |
Michael Kolb | 73980a9 | 2010-08-05 16:32:51 -0700 | [diff] [blame] | 547 | public int getVisibleTitleHeight() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 548 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 549 | return mProvider.getVisibleTitleHeight(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 553 | * Gets the SSL certificate for the main top-level page or null if there is |
| 554 | * no certificate (the site is not secure). |
| 555 | * |
| 556 | * @return the SSL certificate for the main top-level page |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 557 | */ |
| 558 | public SslCertificate getCertificate() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 559 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 560 | return mProvider.getCertificate(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | /** |
| 564 | * Sets the SSL certificate for the main top-level page. |
Kristian Monsen | 5cc2351 | 2012-08-09 15:33:08 -0400 | [diff] [blame] | 565 | * |
| 566 | * @deprecated Calling this function has no useful effect, and will be |
| 567 | * ignored in future releases. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 568 | */ |
Kristian Monsen | 5cc2351 | 2012-08-09 15:33:08 -0400 | [diff] [blame] | 569 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 570 | public void setCertificate(SslCertificate certificate) { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 571 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 572 | mProvider.setCertificate(certificate); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | //------------------------------------------------------------------------- |
| 576 | // Methods called by activity |
| 577 | //------------------------------------------------------------------------- |
| 578 | |
| 579 | /** |
Steve Block | 32fe410 | 2012-07-17 16:29:11 +0100 | [diff] [blame] | 580 | * Sets a username and password pair for the specified host. This data is |
| 581 | * used by the Webview to autocomplete username and password fields in web |
| 582 | * forms. Note that this is unrelated to the credentials used for HTTP |
| 583 | * authentication. |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 584 | * |
Selim Gurun | 38915fd | 2013-04-04 17:14:29 +0000 | [diff] [blame] | 585 | * @param host the host that required the credentials |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 586 | * @param username the username for the given host |
| 587 | * @param password the password for the given host |
Steve Block | 32fe410 | 2012-07-17 16:29:11 +0100 | [diff] [blame] | 588 | * @see WebViewDatabase#clearUsernamePassword |
| 589 | * @see WebViewDatabase#hasUsernamePassword |
Jonathan Dixon | 835b1fc | 2013-02-25 12:29:33 -0800 | [diff] [blame] | 590 | * @deprecated Saving passwords in WebView will not be supported in future versions. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 591 | */ |
Jonathan Dixon | 835b1fc | 2013-02-25 12:29:33 -0800 | [diff] [blame] | 592 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 593 | public void savePassword(String host, String username, String password) { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 594 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 595 | mProvider.savePassword(host, username, password); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | /** |
Steve Block | 46ce1db | 2012-07-17 16:43:00 +0100 | [diff] [blame] | 599 | * Stores HTTP authentication credentials for a given host and realm. This |
| 600 | * method is intended to be used with |
| 601 | * {@link WebViewClient#onReceivedHttpAuthRequest}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 602 | * |
Steve Block | 46ce1db | 2012-07-17 16:43:00 +0100 | [diff] [blame] | 603 | * @param host the host to which the credentials apply |
| 604 | * @param realm the realm to which the credentials apply |
| 605 | * @param username the username |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 606 | * @param password the password |
Jonathan Dixon | 47aaba3 | 2012-11-30 16:32:17 -0800 | [diff] [blame] | 607 | * @see #getHttpAuthUsernamePassword |
Steve Block | 46ce1db | 2012-07-17 16:43:00 +0100 | [diff] [blame] | 608 | * @see WebViewDatabase#hasHttpAuthUsernamePassword |
| 609 | * @see WebViewDatabase#clearHttpAuthUsernamePassword |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 610 | */ |
| 611 | public void setHttpAuthUsernamePassword(String host, String realm, |
| 612 | String username, String password) { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 613 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 614 | mProvider.setHttpAuthUsernamePassword(host, realm, username, password); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | /** |
Steve Block | 46ce1db | 2012-07-17 16:43:00 +0100 | [diff] [blame] | 618 | * Retrieves HTTP authentication credentials for a given host and realm. |
| 619 | * This method is intended to be used with |
| 620 | * {@link WebViewClient#onReceivedHttpAuthRequest}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 621 | * |
Steve Block | 46ce1db | 2012-07-17 16:43:00 +0100 | [diff] [blame] | 622 | * @param host the host to which the credentials apply |
| 623 | * @param realm the realm to which the credentials apply |
| 624 | * @return the credentials as a String array, if found. The first element |
| 625 | * is the username and the second element is the password. Null if |
| 626 | * no credentials are found. |
Jonathan Dixon | 47aaba3 | 2012-11-30 16:32:17 -0800 | [diff] [blame] | 627 | * @see #setHttpAuthUsernamePassword |
Steve Block | 46ce1db | 2012-07-17 16:43:00 +0100 | [diff] [blame] | 628 | * @see WebViewDatabase#hasHttpAuthUsernamePassword |
| 629 | * @see WebViewDatabase#clearHttpAuthUsernamePassword |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 630 | */ |
| 631 | public String[] getHttpAuthUsernamePassword(String host, String realm) { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 632 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 633 | return mProvider.getHttpAuthUsernamePassword(host, realm); |
Leon Scroggins | 05919f2 | 2010-09-14 17:22:36 -0400 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 637 | * Destroys the internal state of this WebView. This method should be called |
| 638 | * after this WebView has been removed from the view system. No other |
| 639 | * methods may be called on this WebView after destroy. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 640 | */ |
| 641 | public void destroy() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 642 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 643 | mProvider.destroy(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | /** |
| 647 | * Enables platform notifications of data state and proxy changes. |
Kristian Monsen | cbb59db | 2011-05-09 16:04:34 +0100 | [diff] [blame] | 648 | * Notifications are enabled by default. |
Kristian Monsen | fc77165 | 2011-05-10 16:44:05 +0100 | [diff] [blame] | 649 | * |
| 650 | * @deprecated This method is now obsolete. |
Kristian Monsen | f491258 | 2012-08-16 15:26:24 -0400 | [diff] [blame] | 651 | * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 652 | */ |
Kristian Monsen | fc77165 | 2011-05-10 16:44:05 +0100 | [diff] [blame] | 653 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 654 | public static void enablePlatformNotifications() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 655 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 656 | getFactory().getStatics().setPlatformNotificationsEnabled(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | /** |
Kristian Monsen | cbb59db | 2011-05-09 16:04:34 +0100 | [diff] [blame] | 660 | * Disables platform notifications of data state and proxy changes. |
| 661 | * Notifications are enabled by default. |
Kristian Monsen | fc77165 | 2011-05-10 16:44:05 +0100 | [diff] [blame] | 662 | * |
| 663 | * @deprecated This method is now obsolete. |
Kristian Monsen | f491258 | 2012-08-16 15:26:24 -0400 | [diff] [blame] | 664 | * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 665 | */ |
Kristian Monsen | fc77165 | 2011-05-10 16:44:05 +0100 | [diff] [blame] | 666 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 667 | public static void disablePlatformNotifications() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 668 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 669 | getFactory().getStatics().setPlatformNotificationsEnabled(false); |
Feng Qian | b308137 | 2009-06-29 15:55:18 -0700 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 673 | * Informs WebView of the network state. This is used to set |
Steve Block | 81f19ff | 2010-11-01 13:23:24 +0000 | [diff] [blame] | 674 | * the JavaScript property window.navigator.isOnline and |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 675 | * generates the online/offline event as specified in HTML5, sec. 5.7.7 |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 676 | * |
| 677 | * @param networkUp a boolean indicating if network is available |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 678 | */ |
| 679 | public void setNetworkAvailable(boolean networkUp) { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 680 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 681 | mProvider.setNetworkAvailable(networkUp); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 685 | * Saves the state of this WebView used in |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 686 | * {@link android.app.Activity#onSaveInstanceState}. Please note that this |
| 687 | * method no longer stores the display data for this WebView. The previous |
| 688 | * behavior could potentially leak files if {@link #restoreState} was never |
Kristian Monsen | f491258 | 2012-08-16 15:26:24 -0400 | [diff] [blame] | 689 | * called. |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 690 | * |
| 691 | * @param outState the Bundle to store this WebView's state |
| 692 | * @return the same copy of the back/forward list used to save the state. If |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 693 | * saveState fails, the returned list will be null. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 694 | */ |
| 695 | public WebBackForwardList saveState(Bundle outState) { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 696 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 697 | return mProvider.saveState(outState); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 701 | * Saves the current display data to the Bundle given. Used in conjunction |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 702 | * with {@link #saveState}. |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 703 | * @param b a Bundle to store the display data |
| 704 | * @param dest the file to store the serialized picture data. Will be |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 705 | * overwritten with this WebView's picture data. |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 706 | * @return true if the picture was successfully saved |
Kristian Monsen | fc77165 | 2011-05-10 16:44:05 +0100 | [diff] [blame] | 707 | * @deprecated This method is now obsolete. |
Kristian Monsen | f491258 | 2012-08-16 15:26:24 -0400 | [diff] [blame] | 708 | * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 709 | */ |
Kristian Monsen | fc77165 | 2011-05-10 16:44:05 +0100 | [diff] [blame] | 710 | @Deprecated |
Patrick Scott | da9a22b | 2010-04-08 08:32:52 -0400 | [diff] [blame] | 711 | public boolean savePicture(Bundle b, final File dest) { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 712 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 713 | return mProvider.savePicture(b, dest); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 717 | * Restores the display data that was saved in {@link #savePicture}. Used in |
| 718 | * conjunction with {@link #restoreState}. Note that this will not work if |
| 719 | * this WebView is hardware accelerated. |
John Reck | 2df8f42 | 2011-09-22 19:50:41 -0700 | [diff] [blame] | 720 | * |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 721 | * @param b a Bundle containing the saved display data |
| 722 | * @param src the file where the picture data was stored |
| 723 | * @return true if the picture was successfully restored |
Kristian Monsen | fc77165 | 2011-05-10 16:44:05 +0100 | [diff] [blame] | 724 | * @deprecated This method is now obsolete. |
Kristian Monsen | f491258 | 2012-08-16 15:26:24 -0400 | [diff] [blame] | 725 | * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 726 | */ |
Kristian Monsen | fc77165 | 2011-05-10 16:44:05 +0100 | [diff] [blame] | 727 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 728 | public boolean restorePicture(Bundle b, File src) { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 729 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 730 | return mProvider.restorePicture(b, src); |
John Reck | 95b7d6f | 2011-06-03 15:23:43 -0700 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | /** |
Steve Block | 4249906 | 2012-07-17 15:34:46 +0100 | [diff] [blame] | 734 | * Restores the state of this WebView from the given Bundle. This method is |
| 735 | * intended for use in {@link android.app.Activity#onRestoreInstanceState} |
| 736 | * and should be called to restore the state of this WebView. If |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 737 | * it is called after this WebView has had a chance to build state (load |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 738 | * pages, create a back/forward list, etc.) there may be undesirable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 739 | * side-effects. Please note that this method no longer restores the |
Kristian Monsen | f491258 | 2012-08-16 15:26:24 -0400 | [diff] [blame] | 740 | * display data for this WebView. |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 741 | * |
| 742 | * @param inState the incoming Bundle of state |
| 743 | * @return the restored back/forward list or null if restoreState failed |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 744 | */ |
| 745 | public WebBackForwardList restoreState(Bundle inState) { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 746 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 747 | return mProvider.restoreState(inState); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 751 | * Loads the given URL with the specified additional HTTP headers. |
| 752 | * |
| 753 | * @param url the URL of the resource to load |
| 754 | * @param additionalHttpHeaders the additional headers to be used in the |
Steve Block | f71dea0 | 2011-08-01 12:29:14 +0100 | [diff] [blame] | 755 | * HTTP request for this URL, specified as a map from name to |
| 756 | * value. Note that if this map contains any of the headers |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 757 | * that are set by default by this WebView, such as those |
Steve Block | f71dea0 | 2011-08-01 12:29:14 +0100 | [diff] [blame] | 758 | * controlling caching, accept types or the User-Agent, their |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 759 | * values may be overriden by this WebView's defaults. |
Grace Kloba | d0d9bc2 | 2010-01-26 18:08:28 -0800 | [diff] [blame] | 760 | */ |
Steve Block | f71dea0 | 2011-08-01 12:29:14 +0100 | [diff] [blame] | 761 | public void loadUrl(String url, Map<String, String> additionalHttpHeaders) { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 762 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 763 | mProvider.loadUrl(url, additionalHttpHeaders); |
Grace Kloba | d0d9bc2 | 2010-01-26 18:08:28 -0800 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 767 | * Loads the given URL. |
| 768 | * |
| 769 | * @param url the URL of the resource to load |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 770 | */ |
| 771 | public void loadUrl(String url) { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 772 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 773 | mProvider.loadUrl(url); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 777 | * Loads the URL with postData using "POST" method into this WebView. If url |
| 778 | * is not a network URL, it will be loaded with {link |
Grace Kloba | 5753430 | 2009-05-22 18:55:02 -0700 | [diff] [blame] | 779 | * {@link #loadUrl(String)} instead. |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 780 | * |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 781 | * @param url the URL of the resource to load |
| 782 | * @param postData the data will be passed to "POST" request |
Grace Kloba | 5753430 | 2009-05-22 18:55:02 -0700 | [diff] [blame] | 783 | */ |
| 784 | public void postUrl(String url, byte[] postData) { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 785 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 786 | mProvider.postUrl(url, postData); |
Grace Kloba | 5753430 | 2009-05-22 18:55:02 -0700 | [diff] [blame] | 787 | } |
| 788 | |
| 789 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 790 | * Loads the given data into this WebView using a 'data' scheme URL. |
Steve Block | b28b22a | 2011-07-04 13:01:25 +0100 | [diff] [blame] | 791 | * <p> |
| 792 | * Note that JavaScript's same origin policy means that script running in a |
| 793 | * page loaded using this method will be unable to access content loaded |
| 794 | * using any scheme other than 'data', including 'http(s)'. To avoid this |
| 795 | * restriction, use {@link |
| 796 | * #loadDataWithBaseURL(String,String,String,String,String) |
| 797 | * loadDataWithBaseURL()} with an appropriate base URL. |
Steve Block | f95d490 | 2011-06-09 11:53:26 +0100 | [diff] [blame] | 798 | * <p> |
Steve Block | 27f3e32 | 2012-07-23 10:45:59 +0100 | [diff] [blame] | 799 | * The encoding parameter specifies whether the data is base64 or URL |
| 800 | * encoded. If the data is base64 encoded, the value of the encoding |
| 801 | * parameter must be 'base64'. For all other values of the parameter, |
| 802 | * including null, it is assumed that the data uses ASCII encoding for |
Steve Block | f95d490 | 2011-06-09 11:53:26 +0100 | [diff] [blame] | 803 | * octets inside the range of safe URL characters and use the standard %xx |
Steve Block | 27f3e32 | 2012-07-23 10:45:59 +0100 | [diff] [blame] | 804 | * hex encoding of URLs for octets outside that range. For example, '#', |
| 805 | * '%', '\', '?' should be replaced by %23, %25, %27, %3f respectively. |
Steve Block | b19c787 | 2011-10-10 14:09:44 +0100 | [diff] [blame] | 806 | * <p> |
| 807 | * The 'data' scheme URL formed by this method uses the default US-ASCII |
| 808 | * charset. If you need need to set a different charset, you should form a |
Steve Block | 33f962b | 2011-10-11 14:49:47 +0100 | [diff] [blame] | 809 | * 'data' scheme URL which explicitly specifies a charset parameter in the |
| 810 | * mediatype portion of the URL and call {@link #loadUrl(String)} instead. |
| 811 | * Note that the charset obtained from the mediatype portion of a data URL |
| 812 | * always overrides that specified in the HTML or XML document itself. |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 813 | * |
| 814 | * @param data a String of data in the given encoding |
| 815 | * @param mimeType the MIME type of the data, e.g. 'text/html' |
| 816 | * @param encoding the encoding of the data |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 817 | */ |
| 818 | public void loadData(String data, String mimeType, String encoding) { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 819 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 820 | mProvider.loadData(data, mimeType, encoding); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 824 | * Loads the given data into this WebView, using baseUrl as the base URL for |
Steve Block | b28b22a | 2011-07-04 13:01:25 +0100 | [diff] [blame] | 825 | * the content. The base URL is used both to resolve relative URLs and when |
| 826 | * applying JavaScript's same origin policy. The historyUrl is used for the |
| 827 | * history entry. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 828 | * <p> |
Steve Block | ae32857 | 2011-06-08 18:58:51 +0100 | [diff] [blame] | 829 | * Note that content specified in this way can access local device files |
| 830 | * (via 'file' scheme URLs) only if baseUrl specifies a scheme other than |
| 831 | * 'http', 'https', 'ftp', 'ftps', 'about' or 'javascript'. |
Steve Block | e482d89 | 2011-07-01 13:57:32 +0100 | [diff] [blame] | 832 | * <p> |
| 833 | * If the base URL uses the data scheme, this method is equivalent to |
| 834 | * calling {@link #loadData(String,String,String) loadData()} and the |
| 835 | * historyUrl is ignored. |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 836 | * |
| 837 | * @param baseUrl the URL to use as the page's base URL. If null defaults to |
| 838 | * 'about:blank'. |
| 839 | * @param data a String of data in the given encoding |
| 840 | * @param mimeType the MIMEType of the data, e.g. 'text/html'. If null, |
| 841 | * defaults to 'text/html'. |
| 842 | * @param encoding the encoding of the data |
| 843 | * @param historyUrl the URL to use as the history entry. If null defaults |
Ben Murdoch | 95afb3b | 2013-02-25 19:18:19 +0000 | [diff] [blame] | 844 | * to 'about:blank'. If non-null, this must be a valid URL. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 845 | */ |
| 846 | public void loadDataWithBaseURL(String baseUrl, String data, |
Leon Scroggins | 1bb1a91 | 2010-03-23 15:39:46 -0400 | [diff] [blame] | 847 | String mimeType, String encoding, String historyUrl) { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 848 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 849 | mProvider.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, historyUrl); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | /** |
Ben Murdoch | a5cdd51 | 2013-07-17 16:25:07 +0100 | [diff] [blame] | 853 | * Asynchronously evaluates JavaScript in the context of the currently displayed page. |
| 854 | * If non-null, |resultCallback| will be invoked with any result returned from that |
| 855 | * execution. This method must be called on the UI thread and the callback will |
| 856 | * be made on the UI thread. |
| 857 | * |
| 858 | * @param script the JavaScript to execute. |
| 859 | * @param resultCallback A callback to be invoked when the script execution |
| 860 | * completes with the result of the execution (if any). |
| 861 | * May be null if no notificaion of the result is required. |
| 862 | * @hide pending API council approval and CTS test coverage. |
| 863 | */ |
| 864 | public void evaluateJavascript(String script, ValueCallback<String> resultCallback) { |
| 865 | checkThread(); |
| 866 | mProvider.evaluateJavaScript(script, resultCallback); |
| 867 | } |
| 868 | |
| 869 | /** |
Elliott Slaughter | b48fdbe | 2010-06-30 11:39:52 -0700 | [diff] [blame] | 870 | * Saves the current view as a web archive. |
| 871 | * |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 872 | * @param filename the filename where the archive should be placed |
Elliott Slaughter | b48fdbe | 2010-06-30 11:39:52 -0700 | [diff] [blame] | 873 | */ |
| 874 | public void saveWebArchive(String filename) { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 875 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 876 | mProvider.saveWebArchive(filename); |
Elliott Slaughter | b48fdbe | 2010-06-30 11:39:52 -0700 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | /** |
| 880 | * Saves the current view as a web archive. |
| 881 | * |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 882 | * @param basename the filename where the archive should be placed |
| 883 | * @param autoname if false, takes basename to be a file. If true, basename |
Elliott Slaughter | b48fdbe | 2010-06-30 11:39:52 -0700 | [diff] [blame] | 884 | * is assumed to be a directory in which a filename will be |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 885 | * chosen according to the URL of the current page. |
| 886 | * @param callback called after the web archive has been saved. The |
Elliott Slaughter | b48fdbe | 2010-06-30 11:39:52 -0700 | [diff] [blame] | 887 | * parameter for onReceiveValue will either be the filename |
| 888 | * under which the file was saved, or null if saving the |
| 889 | * file failed. |
| 890 | */ |
| 891 | public void saveWebArchive(String basename, boolean autoname, ValueCallback<String> callback) { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 892 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 893 | mProvider.saveWebArchive(basename, autoname, callback); |
Elliott Slaughter | b48fdbe | 2010-06-30 11:39:52 -0700 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 897 | * Stops the current load. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 898 | */ |
| 899 | public void stopLoading() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 900 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 901 | mProvider.stopLoading(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 902 | } |
| 903 | |
| 904 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 905 | * Reloads the current URL. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 906 | */ |
| 907 | public void reload() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 908 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 909 | mProvider.reload(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 913 | * Gets whether this WebView has a back history item. |
| 914 | * |
| 915 | * @return true iff this WebView has a back history item |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 916 | */ |
| 917 | public boolean canGoBack() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 918 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 919 | return mProvider.canGoBack(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 923 | * Goes back in the history of this WebView. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 924 | */ |
| 925 | public void goBack() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 926 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 927 | mProvider.goBack(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 931 | * Gets whether this WebView has a forward history item. |
| 932 | * |
| 933 | * @return true iff this Webview has a forward history item |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 934 | */ |
| 935 | public boolean canGoForward() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 936 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 937 | return mProvider.canGoForward(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 941 | * Goes forward in the history of this WebView. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 942 | */ |
| 943 | public void goForward() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 944 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 945 | mProvider.goForward(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 949 | * Gets whether the page can go back or forward the given |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 950 | * number of steps. |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 951 | * |
| 952 | * @param steps the negative or positive number of steps to move the |
| 953 | * history |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 954 | */ |
| 955 | public boolean canGoBackOrForward(int steps) { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 956 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 957 | return mProvider.canGoBackOrForward(steps); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 961 | * Goes to the history item that is the number of steps away from |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 962 | * the current item. Steps is negative if backward and positive |
| 963 | * if forward. |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 964 | * |
| 965 | * @param steps the number of steps to take back or forward in the back |
| 966 | * forward list |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 967 | */ |
| 968 | public void goBackOrForward(int steps) { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 969 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 970 | mProvider.goBackOrForward(steps); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 971 | } |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 972 | |
Elliott Slaughter | f21d2e3 | 2010-07-14 18:08:54 -0700 | [diff] [blame] | 973 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 974 | * Gets whether private browsing is enabled in this WebView. |
Elliott Slaughter | f21d2e3 | 2010-07-14 18:08:54 -0700 | [diff] [blame] | 975 | */ |
Elliott Slaughter | 7c2d135 | 2010-08-20 15:57:18 -0700 | [diff] [blame] | 976 | public boolean isPrivateBrowsingEnabled() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 977 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 978 | return mProvider.isPrivateBrowsingEnabled(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 979 | } |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 980 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 981 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 982 | * Scrolls the contents of this WebView up by half the view size. |
| 983 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 984 | * @param top true to jump to the top of the page |
| 985 | * @return true if the page was scrolled |
| 986 | */ |
| 987 | public boolean pageUp(boolean top) { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 988 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 989 | return mProvider.pageUp(top); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 990 | } |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 991 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 992 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 993 | * Scrolls the contents of this WebView down by half the page size. |
| 994 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 995 | * @param bottom true to jump to bottom of page |
| 996 | * @return true if the page was scrolled |
| 997 | */ |
| 998 | public boolean pageDown(boolean bottom) { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 999 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1000 | return mProvider.pageDown(bottom); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1004 | * Clears this WebView so that onDraw() will draw nothing but white background, |
| 1005 | * and onMeasure() will return 0 if MeasureSpec is not MeasureSpec.EXACTLY. |
Jonathan Dixon | 835b1fc | 2013-02-25 12:29:33 -0800 | [diff] [blame] | 1006 | * @deprecated Use WebView.loadUrl("about:blank") to reliably reset the view state |
| 1007 | * and release page resources (including any running JavaScript). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1008 | */ |
Jonathan Dixon | 835b1fc | 2013-02-25 12:29:33 -0800 | [diff] [blame] | 1009 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1010 | public void clearView() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1011 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1012 | mProvider.clearView(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1013 | } |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 1014 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1015 | /** |
Steve Block | 72498ed | 2012-07-17 15:57:25 +0100 | [diff] [blame] | 1016 | * Gets a new picture that captures the current contents of this WebView. |
| 1017 | * The picture is of the entire document being displayed, and is not |
| 1018 | * limited to the area currently displayed by this WebView. Also, the |
| 1019 | * picture is a static copy and is unaffected by later changes to the |
| 1020 | * content being displayed. |
| 1021 | * <p> |
| 1022 | * Note that due to internal changes, for API levels between |
| 1023 | * {@link android.os.Build.VERSION_CODES#HONEYCOMB} and |
| 1024 | * {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH} inclusive, the |
| 1025 | * picture does not include fixed position elements or scrollable divs. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1026 | * |
Steve Block | 72498ed | 2012-07-17 15:57:25 +0100 | [diff] [blame] | 1027 | * @return a picture that captures the current contents of this WebView |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1028 | */ |
| 1029 | public Picture capturePicture() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1030 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1031 | return mProvider.capturePicture(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1032 | } |
| 1033 | |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 1034 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1035 | * Gets the current scale of this WebView. |
| 1036 | * |
| 1037 | * @return the current scale |
Kristian Monsen | 5cc2351 | 2012-08-09 15:33:08 -0400 | [diff] [blame] | 1038 | * |
| 1039 | * @deprecated This method is prone to inaccuracy due to race conditions |
| 1040 | * between the web rendering and UI threads; prefer |
| 1041 | * {@link WebViewClient#onScaleChanged}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1042 | */ |
Kristian Monsen | 5cc2351 | 2012-08-09 15:33:08 -0400 | [diff] [blame] | 1043 | @Deprecated |
John Reck | 926cf56 | 2012-06-14 10:00:31 -0700 | [diff] [blame] | 1044 | @ViewDebug.ExportedProperty(category = "webview") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1045 | public float getScale() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1046 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1047 | return mProvider.getScale(); |
Mangesh Ghiware | b5f9fc3 | 2011-08-31 17:49:07 -0700 | [diff] [blame] | 1048 | } |
| 1049 | |
| 1050 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1051 | * Sets the initial scale for this WebView. 0 means default. If |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1052 | * {@link WebSettings#getUseWideViewPort()} is true, it zooms out all the |
| 1053 | * way. Otherwise it starts with 100%. If initial scale is greater than 0, |
Mangesh Ghiware | e832b63 | 2011-11-16 11:46:39 -0800 | [diff] [blame] | 1054 | * WebView starts with this value as initial scale. |
| 1055 | * Please note that unlike the scale properties in the viewport meta tag, |
| 1056 | * this method doesn't take the screen density into account. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1057 | * |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1058 | * @param scaleInPercent the initial scale in percent |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1059 | */ |
| 1060 | public void setInitialScale(int scaleInPercent) { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1061 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1062 | mProvider.setInitialScale(scaleInPercent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1066 | * Invokes the graphical zoom picker widget for this WebView. This will |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1067 | * result in the zoom widget appearing on the screen to control the zoom |
| 1068 | * level of this WebView. |
| 1069 | */ |
| 1070 | public void invokeZoomPicker() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1071 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1072 | mProvider.invokeZoomPicker(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1073 | } |
| 1074 | |
| 1075 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1076 | * Gets a HitTestResult based on the current cursor node. If a HTML::a |
| 1077 | * tag is found and the anchor has a non-JavaScript URL, the HitTestResult |
| 1078 | * type is set to SRC_ANCHOR_TYPE and the URL is set in the "extra" field. |
| 1079 | * If the anchor does not have a URL or if it is a JavaScript URL, the type |
| 1080 | * will be UNKNOWN_TYPE and the URL has to be retrieved through |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1081 | * {@link #requestFocusNodeHref} asynchronously. If a HTML::img tag is |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1082 | * found, the HitTestResult type is set to IMAGE_TYPE and the URL is set in |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1083 | * the "extra" field. A type of |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1084 | * SRC_IMAGE_ANCHOR_TYPE indicates an anchor with a URL that has an image as |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1085 | * a child node. If a phone number is found, the HitTestResult type is set |
| 1086 | * to PHONE_TYPE and the phone number is set in the "extra" field of |
| 1087 | * HitTestResult. If a map address is found, the HitTestResult type is set |
| 1088 | * to GEO_TYPE and the address is set in the "extra" field of HitTestResult. |
| 1089 | * If an email address is found, the HitTestResult type is set to EMAIL_TYPE |
| 1090 | * and the email is set in the "extra" field of HitTestResult. Otherwise, |
| 1091 | * HitTestResult type is set to UNKNOWN_TYPE. |
| 1092 | */ |
| 1093 | public HitTestResult getHitTestResult() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1094 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1095 | return mProvider.getHitTestResult(); |
Cary Clark | b849134 | 2010-11-29 16:23:19 -0500 | [diff] [blame] | 1096 | } |
| 1097 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1098 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1099 | * Requests the anchor or image element URL at the last tapped point. |
Cary Clark | 861368a | 2010-12-15 11:24:37 -0500 | [diff] [blame] | 1100 | * If hrefMsg is null, this method returns immediately and does not |
| 1101 | * dispatch hrefMsg to its target. If the tapped point hits an image, |
| 1102 | * an anchor, or an image in an anchor, the message associates |
| 1103 | * strings in named keys in its data. The value paired with the key |
| 1104 | * may be an empty string. |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 1105 | * |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1106 | * @param hrefMsg the message to be dispatched with the result of the |
| 1107 | * request. The message data contains three keys. "url" |
| 1108 | * returns the anchor's href attribute. "title" returns the |
| 1109 | * anchor's text. "src" returns the image's src attribute. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1110 | */ |
| 1111 | public void requestFocusNodeHref(Message hrefMsg) { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1112 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1113 | mProvider.requestFocusNodeHref(hrefMsg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1114 | } |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 1115 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1116 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1117 | * Requests the URL of the image last touched by the user. msg will be sent |
| 1118 | * to its target with a String representing the URL as its object. |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 1119 | * |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1120 | * @param msg the message to be dispatched with the result of the request |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1121 | * as the data member with "url" as key. The result can be null. |
| 1122 | */ |
| 1123 | public void requestImageRef(Message msg) { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1124 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1125 | mProvider.requestImageRef(msg); |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 1126 | } |
| 1127 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1128 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1129 | * Gets the URL for the current page. This is not always the same as the URL |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1130 | * passed to WebViewClient.onPageStarted because although the load for |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1131 | * that URL has begun, the current page may not have changed. |
| 1132 | * |
| 1133 | * @return the URL for the current page |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1134 | */ |
John Reck | 926cf56 | 2012-06-14 10:00:31 -0700 | [diff] [blame] | 1135 | @ViewDebug.ExportedProperty(category = "webview") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1136 | public String getUrl() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1137 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1138 | return mProvider.getUrl(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1139 | } |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 1140 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1141 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1142 | * Gets the original URL for the current page. This is not always the same |
| 1143 | * as the URL passed to WebViewClient.onPageStarted because although the |
| 1144 | * load for that URL has begun, the current page may not have changed. |
| 1145 | * Also, there may have been redirects resulting in a different URL to that |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1146 | * originally requested. |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1147 | * |
| 1148 | * @return the URL that was originally requested for the current page |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1149 | */ |
John Reck | 926cf56 | 2012-06-14 10:00:31 -0700 | [diff] [blame] | 1150 | @ViewDebug.ExportedProperty(category = "webview") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1151 | public String getOriginalUrl() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1152 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1153 | return mProvider.getOriginalUrl(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1157 | * Gets the title for the current page. This is the title of the current page |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1158 | * until WebViewClient.onReceivedTitle is called. |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1159 | * |
| 1160 | * @return the title for the current page |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1161 | */ |
John Reck | 926cf56 | 2012-06-14 10:00:31 -0700 | [diff] [blame] | 1162 | @ViewDebug.ExportedProperty(category = "webview") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1163 | public String getTitle() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1164 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1165 | return mProvider.getTitle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1166 | } |
| 1167 | |
| 1168 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1169 | * Gets the favicon for the current page. This is the favicon of the current |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1170 | * page until WebViewClient.onReceivedIcon is called. |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1171 | * |
| 1172 | * @return the favicon for the current page |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1173 | */ |
| 1174 | public Bitmap getFavicon() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1175 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1176 | return mProvider.getFavicon(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1177 | } |
| 1178 | |
| 1179 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1180 | * Gets the touch icon URL for the apple-touch-icon <link> element, or |
Ben Murdoch | 372dfc8 | 2010-07-01 15:56:01 +0100 | [diff] [blame] | 1181 | * a URL on this site's server pointing to the standard location of a |
| 1182 | * touch icon. |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1183 | * |
Patrick Scott | 2ba1262 | 2009-08-04 13:20:05 -0400 | [diff] [blame] | 1184 | * @hide |
| 1185 | */ |
| 1186 | public String getTouchIconUrl() { |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1187 | return mProvider.getTouchIconUrl(); |
Patrick Scott | 2ba1262 | 2009-08-04 13:20:05 -0400 | [diff] [blame] | 1188 | } |
| 1189 | |
| 1190 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1191 | * Gets the progress for the current page. |
| 1192 | * |
| 1193 | * @return the progress for the current page between 0 and 100 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1194 | */ |
| 1195 | public int getProgress() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1196 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1197 | return mProvider.getProgress(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1198 | } |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 1199 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1200 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1201 | * Gets the height of the HTML content. |
| 1202 | * |
| 1203 | * @return the height of the HTML content |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1204 | */ |
John Reck | 926cf56 | 2012-06-14 10:00:31 -0700 | [diff] [blame] | 1205 | @ViewDebug.ExportedProperty(category = "webview") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1206 | public int getContentHeight() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1207 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1208 | return mProvider.getContentHeight(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1209 | } |
| 1210 | |
| 1211 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1212 | * Gets the width of the HTML content. |
| 1213 | * |
| 1214 | * @return the width of the HTML content |
Leon Scroggins | ea96d1e | 2009-09-23 13:41:01 -0400 | [diff] [blame] | 1215 | * @hide |
| 1216 | */ |
John Reck | 926cf56 | 2012-06-14 10:00:31 -0700 | [diff] [blame] | 1217 | @ViewDebug.ExportedProperty(category = "webview") |
Leon Scroggins | ea96d1e | 2009-09-23 13:41:01 -0400 | [diff] [blame] | 1218 | public int getContentWidth() { |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1219 | return mProvider.getContentWidth(); |
John Reck | 9b90d55 | 2011-06-14 15:19:17 -0700 | [diff] [blame] | 1220 | } |
| 1221 | |
| 1222 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1223 | * Pauses all layout, parsing, and JavaScript timers for all WebViews. This |
| 1224 | * is a global requests, not restricted to just this WebView. This can be |
Mike Reed | d205d5b | 2009-05-27 11:02:29 -0400 | [diff] [blame] | 1225 | * useful if the application has been paused. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1226 | */ |
| 1227 | public void pauseTimers() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1228 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1229 | mProvider.pauseTimers(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1230 | } |
| 1231 | |
| 1232 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1233 | * Resumes all layout, parsing, and JavaScript timers for all WebViews. |
Mike Reed | d205d5b | 2009-05-27 11:02:29 -0400 | [diff] [blame] | 1234 | * This will resume dispatching all timers. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1235 | */ |
| 1236 | public void resumeTimers() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1237 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1238 | mProvider.resumeTimers(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1239 | } |
| 1240 | |
| 1241 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1242 | * Pauses any extra processing associated with this WebView and its |
| 1243 | * associated DOM, plugins, JavaScript etc. For example, if this WebView is |
| 1244 | * taken offscreen, this could be called to reduce unnecessary CPU or |
| 1245 | * network traffic. When this WebView is again "active", call onResume(). |
Steve Block | 81f19ff | 2010-11-01 13:23:24 +0000 | [diff] [blame] | 1246 | * Note that this differs from pauseTimers(), which affects all WebViews. |
Mike Reed | d205d5b | 2009-05-27 11:02:29 -0400 | [diff] [blame] | 1247 | */ |
| 1248 | public void onPause() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1249 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1250 | mProvider.onPause(); |
Mike Reed | d205d5b | 2009-05-27 11:02:29 -0400 | [diff] [blame] | 1251 | } |
| 1252 | |
| 1253 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1254 | * Resumes a WebView after a previous call to onPause(). |
Mike Reed | d205d5b | 2009-05-27 11:02:29 -0400 | [diff] [blame] | 1255 | */ |
| 1256 | public void onResume() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1257 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1258 | mProvider.onResume(); |
Mike Reed | d205d5b | 2009-05-27 11:02:29 -0400 | [diff] [blame] | 1259 | } |
| 1260 | |
| 1261 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1262 | * Gets whether this WebView is paused, meaning onPause() was called. |
| 1263 | * Calling onResume() sets the paused state back to false. |
| 1264 | * |
Mike Reed | d205d5b | 2009-05-27 11:02:29 -0400 | [diff] [blame] | 1265 | * @hide |
| 1266 | */ |
| 1267 | public boolean isPaused() { |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1268 | return mProvider.isPaused(); |
Mike Reed | d205d5b | 2009-05-27 11:02:29 -0400 | [diff] [blame] | 1269 | } |
| 1270 | |
| 1271 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1272 | * Informs this WebView that memory is low so that it can free any available |
| 1273 | * memory. |
Derek Sollenberger | e0155e9 | 2009-06-10 15:35:45 -0400 | [diff] [blame] | 1274 | */ |
| 1275 | public void freeMemory() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1276 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1277 | mProvider.freeMemory(); |
Derek Sollenberger | e0155e9 | 2009-06-10 15:35:45 -0400 | [diff] [blame] | 1278 | } |
| 1279 | |
| 1280 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1281 | * Clears the resource cache. Note that the cache is per-application, so |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 1282 | * this will clear the cache for all WebViews used. |
| 1283 | * |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1284 | * @param includeDiskFiles if false, only the RAM cache is cleared |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1285 | */ |
| 1286 | public void clearCache(boolean includeDiskFiles) { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1287 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1288 | mProvider.clearCache(includeDiskFiles); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1289 | } |
| 1290 | |
| 1291 | /** |
Steve Block | 219dfa4 | 2012-07-20 10:31:21 +0100 | [diff] [blame] | 1292 | * Removes the autocomplete popup from the currently focused form field, if |
| 1293 | * present. Note this only affects the display of the autocomplete popup, |
| 1294 | * it does not remove any saved form data from this WebView's store. To do |
| 1295 | * that, use {@link WebViewDatabase#clearFormData}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1296 | */ |
| 1297 | public void clearFormData() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1298 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1299 | mProvider.clearFormData(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1300 | } |
| 1301 | |
| 1302 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1303 | * Tells this WebView to clear its internal back/forward list. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1304 | */ |
| 1305 | public void clearHistory() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1306 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1307 | mProvider.clearHistory(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1308 | } |
| 1309 | |
| 1310 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1311 | * Clears the SSL preferences table stored in response to proceeding with |
| 1312 | * SSL certificate errors. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1313 | */ |
| 1314 | public void clearSslPreferences() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1315 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1316 | mProvider.clearSslPreferences(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1317 | } |
| 1318 | |
| 1319 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1320 | * Gets the WebBackForwardList for this WebView. This contains the |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1321 | * back/forward list for use in querying each item in the history stack. |
| 1322 | * This is a copy of the private WebBackForwardList so it contains only a |
| 1323 | * snapshot of the current state. Multiple calls to this method may return |
| 1324 | * different objects. The object returned from this method will not be |
| 1325 | * updated to reflect any new state. |
| 1326 | */ |
| 1327 | public WebBackForwardList copyBackForwardList() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1328 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1329 | return mProvider.copyBackForwardList(); |
| 1330 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1331 | } |
| 1332 | |
Victoria Lease | abeb6a7 | 2012-03-05 16:29:12 -0800 | [diff] [blame] | 1333 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1334 | * Registers the listener to be notified as find-on-page operations |
| 1335 | * progress. This will replace the current listener. |
Victoria Lease | abeb6a7 | 2012-03-05 16:29:12 -0800 | [diff] [blame] | 1336 | * |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1337 | * @param listener an implementation of {@link FindListener} |
Victoria Lease | abeb6a7 | 2012-03-05 16:29:12 -0800 | [diff] [blame] | 1338 | */ |
| 1339 | public void setFindListener(FindListener listener) { |
| 1340 | checkThread(); |
Ben Murdoch | 52c9f7f | 2013-01-18 00:50:37 +0000 | [diff] [blame] | 1341 | setupFindListenerIfNeeded(); |
| 1342 | mFindListener.mUserFindListener = listener; |
Victoria Lease | abeb6a7 | 2012-03-05 16:29:12 -0800 | [diff] [blame] | 1343 | } |
| 1344 | |
| 1345 | /** |
Kristian Monsen | f491258 | 2012-08-16 15:26:24 -0400 | [diff] [blame] | 1346 | * Highlights and scrolls to the next match found by |
Victoria Lease | 0b8413b | 2012-03-26 13:04:10 -0700 | [diff] [blame] | 1347 | * {@link #findAllAsync}, wrapping around page boundaries as necessary. |
Kristian Monsen | f491258 | 2012-08-16 15:26:24 -0400 | [diff] [blame] | 1348 | * Notifies any registered {@link FindListener}. If {@link #findAllAsync(String)} |
| 1349 | * has not been called yet, or if {@link #clearMatches} has been called since the |
| 1350 | * last find operation, this function does nothing. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1351 | * |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1352 | * @param forward the direction to search |
Victoria Lease | 0b8413b | 2012-03-26 13:04:10 -0700 | [diff] [blame] | 1353 | * @see #setFindListener |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1354 | */ |
| 1355 | public void findNext(boolean forward) { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1356 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1357 | mProvider.findNext(forward); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1358 | } |
| 1359 | |
Victoria Lease | abeb6a7 | 2012-03-05 16:29:12 -0800 | [diff] [blame] | 1360 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1361 | * Finds all instances of find on the page and highlights them. |
Victoria Lease | 0b8413b | 2012-03-26 13:04:10 -0700 | [diff] [blame] | 1362 | * Notifies any registered {@link FindListener}. |
Victoria Lease | abeb6a7 | 2012-03-05 16:29:12 -0800 | [diff] [blame] | 1363 | * |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1364 | * @param find the string to find |
| 1365 | * @return the number of occurances of the String "find" that were found |
Victoria Lease | 0b8413b | 2012-03-26 13:04:10 -0700 | [diff] [blame] | 1366 | * @deprecated {@link #findAllAsync} is preferred. |
| 1367 | * @see #setFindListener |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1368 | */ |
Jonathan Dixon | 9f21c1c | 2012-04-12 11:14:20 +0100 | [diff] [blame] | 1369 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1370 | public int findAll(String find) { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1371 | checkThread(); |
Jonathan Dixon | 9f21c1c | 2012-04-12 11:14:20 +0100 | [diff] [blame] | 1372 | StrictMode.noteSlowCall("findAll blocks UI: prefer findAllAsync"); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1373 | return mProvider.findAll(find); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1374 | } |
| 1375 | |
Cary Clark | 3403eb3 | 2010-03-03 10:05:16 -0500 | [diff] [blame] | 1376 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1377 | * Finds all instances of find on the page and highlights them, |
Victoria Lease | 0b8413b | 2012-03-26 13:04:10 -0700 | [diff] [blame] | 1378 | * asynchronously. Notifies any registered {@link FindListener}. |
Kristian Monsen | f491258 | 2012-08-16 15:26:24 -0400 | [diff] [blame] | 1379 | * Successive calls to this will cancel any pending searches. |
Victoria Lease | abeb6a7 | 2012-03-05 16:29:12 -0800 | [diff] [blame] | 1380 | * |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1381 | * @param find the string to find. |
Victoria Lease | 0b8413b | 2012-03-26 13:04:10 -0700 | [diff] [blame] | 1382 | * @see #setFindListener |
Victoria Lease | abeb6a7 | 2012-03-05 16:29:12 -0800 | [diff] [blame] | 1383 | */ |
| 1384 | public void findAllAsync(String find) { |
| 1385 | checkThread(); |
| 1386 | mProvider.findAllAsync(find); |
| 1387 | } |
| 1388 | |
| 1389 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1390 | * Starts an ActionMode for finding text in this WebView. Only works if this |
| 1391 | * WebView is attached to the view system. |
| 1392 | * |
| 1393 | * @param text if non-null, will be the initial text to search for. |
Leon Scroggins | fe026bd | 2010-08-24 14:16:09 -0400 | [diff] [blame] | 1394 | * Otherwise, the last String searched for in this WebView will |
| 1395 | * be used to start. |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1396 | * @param showIme if true, show the IME, assuming the user will begin typing. |
| 1397 | * If false and text is non-null, perform a find all. |
| 1398 | * @return true if the find dialog is shown, false otherwise |
Jonathan Dixon | 835b1fc | 2013-02-25 12:29:33 -0800 | [diff] [blame] | 1399 | * @deprecated This method does not work reliably on all Android versions; |
| 1400 | * implementing a custom find dialog using WebView.findAllAsync() |
| 1401 | * provides a more robust solution. |
Cary Clark | de023c1 | 2010-03-03 10:05:16 -0500 | [diff] [blame] | 1402 | */ |
Jonathan Dixon | 835b1fc | 2013-02-25 12:29:33 -0800 | [diff] [blame] | 1403 | @Deprecated |
Leon Scroggins | 571354f | 2011-01-04 10:12:41 -0500 | [diff] [blame] | 1404 | public boolean showFindDialog(String text, boolean showIme) { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1405 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1406 | return mProvider.showFindDialog(text, showIme); |
Leon Scroggins | fe026bd | 2010-08-24 14:16:09 -0400 | [diff] [blame] | 1407 | } |
| 1408 | |
| 1409 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1410 | * Gets the first substring consisting of the address of a physical |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1411 | * location. Currently, only addresses in the United States are detected, |
| 1412 | * and consist of: |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1413 | * <ul> |
| 1414 | * <li>a house number</li> |
| 1415 | * <li>a street name</li> |
| 1416 | * <li>a street type (Road, Circle, etc), either spelled out or |
| 1417 | * abbreviated</li> |
| 1418 | * <li>a city name</li> |
| 1419 | * <li>a state or territory, either spelled out or two-letter abbr</li> |
| 1420 | * <li>an optional 5 digit or 9 digit zip code</li> |
| 1421 | * </ul> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1422 | * All names must be correctly capitalized, and the zip code, if present, |
| 1423 | * must be valid for the state. The street type must be a standard USPS |
| 1424 | * spelling or abbreviation. The state or territory must also be spelled |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 1425 | * or abbreviated using USPS standards. The house number may not exceed |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1426 | * five digits. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1427 | * |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1428 | * @param addr the string to search for addresses |
| 1429 | * @return the address, or if no address is found, null |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1430 | */ |
| 1431 | public static String findAddress(String addr) { |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1432 | return getFactory().getStatics().findAddress(addr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1433 | } |
| 1434 | |
Victoria Lease | 0b8413b | 2012-03-26 13:04:10 -0700 | [diff] [blame] | 1435 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1436 | * Clears the highlighting surrounding text matches created by |
Kristian Monsen | f491258 | 2012-08-16 15:26:24 -0400 | [diff] [blame] | 1437 | * {@link #findAllAsync}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1438 | */ |
| 1439 | public void clearMatches() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1440 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1441 | mProvider.clearMatches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1442 | } |
| 1443 | |
| 1444 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1445 | * Queries the document to see if it contains any image references. The |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1446 | * message object will be dispatched with arg1 being set to 1 if images |
| 1447 | * were found and 0 if the document does not reference any images. |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1448 | * |
| 1449 | * @param response the message that will be dispatched with the result |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1450 | */ |
| 1451 | public void documentHasImages(Message response) { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1452 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1453 | mProvider.documentHasImages(response); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1454 | } |
| 1455 | |
| 1456 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1457 | * Sets the WebViewClient that will receive various notifications and |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1458 | * requests. This will replace the current handler. |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1459 | * |
| 1460 | * @param client an implementation of WebViewClient |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1461 | */ |
| 1462 | public void setWebViewClient(WebViewClient client) { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1463 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1464 | mProvider.setWebViewClient(client); |
Grace Kloba | 94ab3b6 | 2009-10-07 18:00:19 -0700 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1468 | * Registers the interface to be used when content can not be handled by |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1469 | * the rendering engine, and should be downloaded instead. This will replace |
| 1470 | * the current handler. |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1471 | * |
| 1472 | * @param listener an implementation of DownloadListener |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1473 | */ |
| 1474 | public void setDownloadListener(DownloadListener listener) { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1475 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1476 | mProvider.setDownloadListener(listener); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1477 | } |
| 1478 | |
| 1479 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1480 | * Sets the chrome handler. This is an implementation of WebChromeClient for |
Steve Block | 81f19ff | 2010-11-01 13:23:24 +0000 | [diff] [blame] | 1481 | * use in handling JavaScript dialogs, favicons, titles, and the progress. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1482 | * This will replace the current handler. |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1483 | * |
| 1484 | * @param client an implementation of WebChromeClient |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1485 | */ |
| 1486 | public void setWebChromeClient(WebChromeClient client) { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1487 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1488 | mProvider.setWebChromeClient(client); |
Patrick Scott | 0b2e84b | 2010-03-02 08:58:44 -0500 | [diff] [blame] | 1489 | } |
| 1490 | |
| 1491 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1492 | * Sets the Picture listener. This is an interface used to receive |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1493 | * notifications of a new Picture. |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1494 | * |
| 1495 | * @param listener an implementation of WebView.PictureListener |
Kristian Monsen | fc77165 | 2011-05-10 16:44:05 +0100 | [diff] [blame] | 1496 | * @deprecated This method is now obsolete. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1497 | */ |
Kristian Monsen | fc77165 | 2011-05-10 16:44:05 +0100 | [diff] [blame] | 1498 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1499 | public void setPictureListener(PictureListener listener) { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1500 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1501 | mProvider.setPictureListener(listener); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1502 | } |
| 1503 | |
| 1504 | /** |
Steve Block | 3aa800b | 2012-04-24 13:01:34 +0100 | [diff] [blame] | 1505 | * Injects the supplied Java object into this WebView. The object is |
| 1506 | * injected into the JavaScript context of the main frame, using the |
Selim Gurun | e91d5be | 2012-09-11 16:11:22 -0700 | [diff] [blame] | 1507 | * supplied name. This allows the Java object's methods to be |
Selim Gurun | b4c02e6 | 2012-09-12 13:36:21 -0700 | [diff] [blame] | 1508 | * accessed from JavaScript. For applications targeted to API |
| 1509 | * level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} |
Selim Gurun | e91d5be | 2012-09-11 16:11:22 -0700 | [diff] [blame] | 1510 | * and above, only public methods that are annotated with |
| 1511 | * {@link android.webkit.JavascriptInterface} can be accessed from JavaScript. |
Selim Gurun | b4c02e6 | 2012-09-12 13:36:21 -0700 | [diff] [blame] | 1512 | * For applications targeted to API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN} or below, |
Selim Gurun | e91d5be | 2012-09-11 16:11:22 -0700 | [diff] [blame] | 1513 | * all public methods (including the inherited ones) can be accessed, see the |
Selim Gurun | b4c02e6 | 2012-09-12 13:36:21 -0700 | [diff] [blame] | 1514 | * important security note below for implications. |
| 1515 | * <p> Note that injected objects will not |
Steve Block | 3aa800b | 2012-04-24 13:01:34 +0100 | [diff] [blame] | 1516 | * appear in JavaScript until the page is next (re)loaded. For example: |
Selim Gurun | e91d5be | 2012-09-11 16:11:22 -0700 | [diff] [blame] | 1517 | * <pre> |
| 1518 | * class JsObject { |
| 1519 | * {@literal @}JavascriptInterface |
| 1520 | * public String toString() { return "injectedObject"; } |
| 1521 | * } |
| 1522 | * webView.addJavascriptInterface(new JsObject(), "injectedObject"); |
Steve Block | 4cd73c5 | 2011-11-09 13:06:52 +0000 | [diff] [blame] | 1523 | * webView.loadData("<!DOCTYPE html><title></title>", "text/html", null); |
| 1524 | * webView.loadUrl("javascript:alert(injectedObject.toString())");</pre> |
Steve Block | 3aa800b | 2012-04-24 13:01:34 +0100 | [diff] [blame] | 1525 | * <p> |
| 1526 | * <strong>IMPORTANT:</strong> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1527 | * <ul> |
Steve Block | 3aa800b | 2012-04-24 13:01:34 +0100 | [diff] [blame] | 1528 | * <li> This method can be used to allow JavaScript to control the host |
| 1529 | * application. This is a powerful feature, but also presents a security |
Selim Gurun | b4c02e6 | 2012-09-12 13:36:21 -0700 | [diff] [blame] | 1530 | * risk for applications targeted to API level |
Selim Gurun | e91d5be | 2012-09-11 16:11:22 -0700 | [diff] [blame] | 1531 | * {@link android.os.Build.VERSION_CODES#JELLY_BEAN} or below, because |
| 1532 | * JavaScript could use reflection to access an |
Steve Block | 3aa800b | 2012-04-24 13:01:34 +0100 | [diff] [blame] | 1533 | * injected object's public fields. Use of this method in a WebView |
| 1534 | * containing untrusted content could allow an attacker to manipulate the |
| 1535 | * host application in unintended ways, executing Java code with the |
| 1536 | * permissions of the host application. Use extreme care when using this |
| 1537 | * method in a WebView which could contain untrusted content.</li> |
Steve Block | 4cd73c5 | 2011-11-09 13:06:52 +0000 | [diff] [blame] | 1538 | * <li> JavaScript interacts with Java object on a private, background |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1539 | * thread of this WebView. Care is therefore required to maintain thread |
Steve Block | 4cd73c5 | 2011-11-09 13:06:52 +0000 | [diff] [blame] | 1540 | * safety.</li> |
Selim Gurun | e91d5be | 2012-09-11 16:11:22 -0700 | [diff] [blame] | 1541 | * <li> The Java object's fields are not accessible.</li> |
Steve Block | 3aa800b | 2012-04-24 13:01:34 +0100 | [diff] [blame] | 1542 | * </ul> |
| 1543 | * |
| 1544 | * @param object the Java object to inject into this WebView's JavaScript |
Steve Block | 4cd73c5 | 2011-11-09 13:06:52 +0000 | [diff] [blame] | 1545 | * context. Null values are ignored. |
Steve Block | 3aa800b | 2012-04-24 13:01:34 +0100 | [diff] [blame] | 1546 | * @param name the name used to expose the object in JavaScript |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1547 | */ |
Steve Block | 4cd73c5 | 2011-11-09 13:06:52 +0000 | [diff] [blame] | 1548 | public void addJavascriptInterface(Object object, String name) { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1549 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1550 | mProvider.addJavascriptInterface(object, name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1551 | } |
| 1552 | |
| 1553 | /** |
Steve Block | 3aa800b | 2012-04-24 13:01:34 +0100 | [diff] [blame] | 1554 | * Removes a previously injected Java object from this WebView. Note that |
| 1555 | * the removal will not be reflected in JavaScript until the page is next |
| 1556 | * (re)loaded. See {@link #addJavascriptInterface}. |
| 1557 | * |
| 1558 | * @param name the name used to expose the object in JavaScript |
Steve Block | 689a342 | 2010-12-07 18:18:26 +0000 | [diff] [blame] | 1559 | */ |
Steve Block | 3aa800b | 2012-04-24 13:01:34 +0100 | [diff] [blame] | 1560 | public void removeJavascriptInterface(String name) { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1561 | checkThread(); |
Steve Block | 3aa800b | 2012-04-24 13:01:34 +0100 | [diff] [blame] | 1562 | mProvider.removeJavascriptInterface(name); |
Steve Block | 689a342 | 2010-12-07 18:18:26 +0000 | [diff] [blame] | 1563 | } |
| 1564 | |
| 1565 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1566 | * Gets the WebSettings object used to control the settings for this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1567 | * WebView. |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1568 | * |
| 1569 | * @return a WebSettings object that can be used to control this WebView's |
| 1570 | * settings |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1571 | */ |
| 1572 | public WebSettings getSettings() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1573 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1574 | return mProvider.getSettings(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1575 | } |
| 1576 | |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1577 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1578 | * Gets the list of currently loaded plugins. |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1579 | * |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1580 | * @return the list of currently loaded plugins |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1581 | * @deprecated This was used for Gears, which has been deprecated. |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1582 | * @hide |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1583 | */ |
Andrei Popescu | 385df69 | 2009-08-13 11:59:57 +0100 | [diff] [blame] | 1584 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1585 | public static synchronized PluginList getPluginList() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1586 | checkThread(); |
Grace Kloba | bb245ea | 2009-11-10 13:13:24 -0800 | [diff] [blame] | 1587 | return new PluginList(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1588 | } |
| 1589 | |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1590 | /** |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1591 | * @deprecated This was used for Gears, which has been deprecated. |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1592 | * @hide |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1593 | */ |
Andrei Popescu | 385df69 | 2009-08-13 11:59:57 +0100 | [diff] [blame] | 1594 | @Deprecated |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1595 | public void refreshPlugins(boolean reloadOpenPages) { |
| 1596 | checkThread(); |
| 1597 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1598 | |
Cary Clark | 966641a | 2010-03-04 08:41:56 -0500 | [diff] [blame] | 1599 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1600 | * Puts this WebView into text selection mode. Do not rely on this |
| 1601 | * functionality; it will be deprecated in the future. |
| 1602 | * |
Kristian Monsen | fc77165 | 2011-05-10 16:44:05 +0100 | [diff] [blame] | 1603 | * @deprecated This method is now obsolete. |
Kristian Monsen | f491258 | 2012-08-16 15:26:24 -0400 | [diff] [blame] | 1604 | * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} |
Cary Clark | 966641a | 2010-03-04 08:41:56 -0500 | [diff] [blame] | 1605 | */ |
Kristian Monsen | fc77165 | 2011-05-10 16:44:05 +0100 | [diff] [blame] | 1606 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1607 | public void emulateShiftHeld() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1608 | checkThread(); |
Steve Howard | 16bd937 | 2010-04-12 14:46:09 -0700 | [diff] [blame] | 1609 | } |
| 1610 | |
Leon Scroggins | a57632f | 2009-11-16 10:51:12 -0500 | [diff] [blame] | 1611 | /** |
| 1612 | * @deprecated WebView no longer needs to implement |
| 1613 | * ViewGroup.OnHierarchyChangeListener. This method does nothing now. |
| 1614 | */ |
George Mount | fab67a1 | 2012-01-05 09:58:53 -0800 | [diff] [blame] | 1615 | @Override |
Jonathan Dixon | e230e54 | 2011-12-21 10:57:00 +0000 | [diff] [blame] | 1616 | // Cannot add @hide as this can always be accessed via the interface. |
Leon Scroggins | a57632f | 2009-11-16 10:51:12 -0500 | [diff] [blame] | 1617 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1618 | public void onChildViewAdded(View parent, View child) {} |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 1619 | |
Leon Scroggins | a57632f | 2009-11-16 10:51:12 -0500 | [diff] [blame] | 1620 | /** |
| 1621 | * @deprecated WebView no longer needs to implement |
| 1622 | * ViewGroup.OnHierarchyChangeListener. This method does nothing now. |
| 1623 | */ |
George Mount | fab67a1 | 2012-01-05 09:58:53 -0800 | [diff] [blame] | 1624 | @Override |
Jonathan Dixon | e230e54 | 2011-12-21 10:57:00 +0000 | [diff] [blame] | 1625 | // Cannot add @hide as this can always be accessed via the interface. |
Leon Scroggins | a57632f | 2009-11-16 10:51:12 -0500 | [diff] [blame] | 1626 | @Deprecated |
| 1627 | public void onChildViewRemoved(View p, View child) {} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1628 | |
| 1629 | /** |
| 1630 | * @deprecated WebView should not have implemented |
Gilles Debunne | 0e7d652d | 2011-02-22 15:26:14 -0800 | [diff] [blame] | 1631 | * ViewTreeObserver.OnGlobalFocusChangeListener. This method does nothing now. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1632 | */ |
George Mount | fab67a1 | 2012-01-05 09:58:53 -0800 | [diff] [blame] | 1633 | @Override |
Jonathan Dixon | e230e54 | 2011-12-21 10:57:00 +0000 | [diff] [blame] | 1634 | // Cannot add @hide as this can always be accessed via the interface. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1635 | @Deprecated |
| 1636 | public void onGlobalFocusChanged(View oldFocus, View newFocus) { |
| 1637 | } |
| 1638 | |
Kristian Monsen | 5cc2351 | 2012-08-09 15:33:08 -0400 | [diff] [blame] | 1639 | /** |
| 1640 | * @deprecated Only the default case, true, will be supported in a future version. |
| 1641 | */ |
| 1642 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1643 | public void setMapTrackballToArrowKeys(boolean setMap) { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1644 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1645 | mProvider.setMapTrackballToArrowKeys(setMap); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1646 | } |
| 1647 | |
Derek Sollenberger | 03e4891 | 2010-05-18 17:03:42 -0400 | [diff] [blame] | 1648 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1649 | public void flingScroll(int vx, int vy) { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1650 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1651 | mProvider.flingScroll(vx, vy); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1652 | } |
| 1653 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1654 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1655 | * Gets the zoom controls for this WebView, as a separate View. The caller |
| 1656 | * is responsible for inserting this View into the layout hierarchy. |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1657 | * <p/> |
Steve Block | b838aef | 2012-04-23 18:22:15 +0100 | [diff] [blame] | 1658 | * API level {@link android.os.Build.VERSION_CODES#CUPCAKE} introduced |
| 1659 | * built-in zoom mechanisms for the WebView, as opposed to these separate |
| 1660 | * zoom controls. The built-in mechanisms are preferred and can be enabled |
| 1661 | * using {@link WebSettings#setBuiltInZoomControls}. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1662 | * |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1663 | * @deprecated the built-in zoom mechanisms are preferred |
Steve Block | b838aef | 2012-04-23 18:22:15 +0100 | [diff] [blame] | 1664 | * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1665 | */ |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1666 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1667 | public View getZoomControls() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1668 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1669 | return mProvider.getZoomControls(); |
Mangesh Ghiware | faab93d | 2011-09-21 13:58:47 -0700 | [diff] [blame] | 1670 | } |
| 1671 | |
| 1672 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1673 | * Gets whether this WebView can be zoomed in. |
| 1674 | * |
| 1675 | * @return true if this WebView can be zoomed in |
Kristian Monsen | 5cc2351 | 2012-08-09 15:33:08 -0400 | [diff] [blame] | 1676 | * |
| 1677 | * @deprecated This method is prone to inaccuracy due to race conditions |
| 1678 | * between the web rendering and UI threads; prefer |
| 1679 | * {@link WebViewClient#onScaleChanged}. |
Grace Kloba | 6164ef1 | 2010-06-01 15:59:13 -0700 | [diff] [blame] | 1680 | */ |
Kristian Monsen | 5cc2351 | 2012-08-09 15:33:08 -0400 | [diff] [blame] | 1681 | @Deprecated |
Grace Kloba | 6164ef1 | 2010-06-01 15:59:13 -0700 | [diff] [blame] | 1682 | public boolean canZoomIn() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1683 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1684 | return mProvider.canZoomIn(); |
Grace Kloba | 6164ef1 | 2010-06-01 15:59:13 -0700 | [diff] [blame] | 1685 | } |
| 1686 | |
| 1687 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1688 | * Gets whether this WebView can be zoomed out. |
| 1689 | * |
| 1690 | * @return true if this WebView can be zoomed out |
Kristian Monsen | 5cc2351 | 2012-08-09 15:33:08 -0400 | [diff] [blame] | 1691 | * |
| 1692 | * @deprecated This method is prone to inaccuracy due to race conditions |
| 1693 | * between the web rendering and UI threads; prefer |
| 1694 | * {@link WebViewClient#onScaleChanged}. |
Grace Kloba | 6164ef1 | 2010-06-01 15:59:13 -0700 | [diff] [blame] | 1695 | */ |
Kristian Monsen | 5cc2351 | 2012-08-09 15:33:08 -0400 | [diff] [blame] | 1696 | @Deprecated |
Grace Kloba | 6164ef1 | 2010-06-01 15:59:13 -0700 | [diff] [blame] | 1697 | public boolean canZoomOut() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1698 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1699 | return mProvider.canZoomOut(); |
Grace Kloba | 6164ef1 | 2010-06-01 15:59:13 -0700 | [diff] [blame] | 1700 | } |
| 1701 | |
| 1702 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1703 | * Performs zoom in in this WebView. |
| 1704 | * |
| 1705 | * @return true if zoom in succeeds, false if no zoom changes |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1706 | */ |
| 1707 | public boolean zoomIn() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1708 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1709 | return mProvider.zoomIn(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1710 | } |
| 1711 | |
| 1712 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1713 | * Performs zoom out in this WebView. |
| 1714 | * |
| 1715 | * @return true if zoom out succeeds, false if no zoom changes |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1716 | */ |
| 1717 | public boolean zoomOut() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1718 | checkThread(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1719 | return mProvider.zoomOut(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1720 | } |
| 1721 | |
Kristian Monsen | fc77165 | 2011-05-10 16:44:05 +0100 | [diff] [blame] | 1722 | /** |
| 1723 | * @deprecated This method is now obsolete. |
Kristian Monsen | f491258 | 2012-08-16 15:26:24 -0400 | [diff] [blame] | 1724 | * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} |
Kristian Monsen | fc77165 | 2011-05-10 16:44:05 +0100 | [diff] [blame] | 1725 | */ |
| 1726 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1727 | public void debugDump() { |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1728 | checkThread(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1729 | } |
Cary Clark | d6982c9 | 2009-05-29 11:02:22 -0400 | [diff] [blame] | 1730 | |
John Reck | 926cf56 | 2012-06-14 10:00:31 -0700 | [diff] [blame] | 1731 | /** |
John Reck | f236115 | 2012-06-14 15:23:22 -0700 | [diff] [blame] | 1732 | * See {@link ViewDebug.HierarchyHandler#dumpViewHierarchyWithProperties(BufferedWriter, int)} |
John Reck | 926cf56 | 2012-06-14 10:00:31 -0700 | [diff] [blame] | 1733 | * @hide |
| 1734 | */ |
| 1735 | @Override |
| 1736 | public void dumpViewHierarchyWithProperties(BufferedWriter out, int level) { |
| 1737 | mProvider.dumpViewHierarchyWithProperties(out, level); |
| 1738 | } |
| 1739 | |
| 1740 | /** |
| 1741 | * See {@link ViewDebug.HierarchyHandler#findHierarchyView(String, int)} |
| 1742 | * @hide |
| 1743 | */ |
| 1744 | @Override |
| 1745 | public View findHierarchyView(String className, int hashCode) { |
| 1746 | return mProvider.findHierarchyView(className, hashCode); |
| 1747 | } |
| 1748 | |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1749 | //------------------------------------------------------------------------- |
| 1750 | // Interface for WebView providers |
| 1751 | //------------------------------------------------------------------------- |
| 1752 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1753 | /** |
Steve Block | 4e584df | 2012-04-24 23:12:47 +0100 | [diff] [blame] | 1754 | * Gets the WebViewProvider. Used by providers to obtain the underlying |
| 1755 | * implementation, e.g. when the appliction responds to |
| 1756 | * WebViewClient.onCreateWindow() request. |
Mike Reed | efe2c72 | 2009-10-14 09:42:02 -0400 | [diff] [blame] | 1757 | * |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1758 | * @hide WebViewProvider is not public API. |
Mike Reed | efe2c72 | 2009-10-14 09:42:02 -0400 | [diff] [blame] | 1759 | */ |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1760 | public WebViewProvider getWebViewProvider() { |
| 1761 | return mProvider; |
Mike Reed | efe2c72 | 2009-10-14 09:42:02 -0400 | [diff] [blame] | 1762 | } |
| 1763 | |
| 1764 | /** |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1765 | * Callback interface, allows the provider implementation to access non-public methods |
| 1766 | * and fields, and make super-class calls in this WebView instance. |
| 1767 | * @hide Only for use by WebViewProvider implementations |
Teng-Hui Zhu | 661e8b1 | 2011-03-02 15:09:34 -0800 | [diff] [blame] | 1768 | */ |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1769 | public class PrivateAccess { |
| 1770 | // ---- Access to super-class methods ---- |
| 1771 | public int super_getScrollBarStyle() { |
| 1772 | return WebView.super.getScrollBarStyle(); |
| 1773 | } |
| 1774 | |
| 1775 | public void super_scrollTo(int scrollX, int scrollY) { |
| 1776 | WebView.super.scrollTo(scrollX, scrollY); |
| 1777 | } |
| 1778 | |
| 1779 | public void super_computeScroll() { |
| 1780 | WebView.super.computeScroll(); |
| 1781 | } |
| 1782 | |
alanv | eebebc9 | 2012-06-15 18:59:11 -0700 | [diff] [blame] | 1783 | public boolean super_onHoverEvent(MotionEvent event) { |
| 1784 | return WebView.super.onHoverEvent(event); |
| 1785 | } |
| 1786 | |
alanv | 448902d | 2012-05-16 20:27:47 -0700 | [diff] [blame] | 1787 | public boolean super_performAccessibilityAction(int action, Bundle arguments) { |
| 1788 | return WebView.super.performAccessibilityAction(action, arguments); |
| 1789 | } |
| 1790 | |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1791 | public boolean super_performLongClick() { |
| 1792 | return WebView.super.performLongClick(); |
| 1793 | } |
| 1794 | |
| 1795 | public boolean super_setFrame(int left, int top, int right, int bottom) { |
| 1796 | return WebView.super.setFrame(left, top, right, bottom); |
| 1797 | } |
| 1798 | |
| 1799 | public boolean super_dispatchKeyEvent(KeyEvent event) { |
| 1800 | return WebView.super.dispatchKeyEvent(event); |
| 1801 | } |
| 1802 | |
| 1803 | public boolean super_onGenericMotionEvent(MotionEvent event) { |
| 1804 | return WebView.super.onGenericMotionEvent(event); |
| 1805 | } |
| 1806 | |
| 1807 | public boolean super_requestFocus(int direction, Rect previouslyFocusedRect) { |
| 1808 | return WebView.super.requestFocus(direction, previouslyFocusedRect); |
| 1809 | } |
| 1810 | |
| 1811 | public void super_setLayoutParams(ViewGroup.LayoutParams params) { |
| 1812 | WebView.super.setLayoutParams(params); |
| 1813 | } |
| 1814 | |
| 1815 | // ---- Access to non-public methods ---- |
| 1816 | public void overScrollBy(int deltaX, int deltaY, |
| 1817 | int scrollX, int scrollY, |
| 1818 | int scrollRangeX, int scrollRangeY, |
| 1819 | int maxOverScrollX, int maxOverScrollY, |
| 1820 | boolean isTouchEvent) { |
| 1821 | WebView.this.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX, scrollRangeY, |
| 1822 | maxOverScrollX, maxOverScrollY, isTouchEvent); |
| 1823 | } |
| 1824 | |
| 1825 | public void awakenScrollBars(int duration) { |
| 1826 | WebView.this.awakenScrollBars(duration); |
| 1827 | } |
| 1828 | |
| 1829 | public void awakenScrollBars(int duration, boolean invalidate) { |
| 1830 | WebView.this.awakenScrollBars(duration, invalidate); |
| 1831 | } |
| 1832 | |
| 1833 | public float getVerticalScrollFactor() { |
| 1834 | return WebView.this.getVerticalScrollFactor(); |
| 1835 | } |
| 1836 | |
| 1837 | public float getHorizontalScrollFactor() { |
| 1838 | return WebView.this.getHorizontalScrollFactor(); |
| 1839 | } |
| 1840 | |
| 1841 | public void setMeasuredDimension(int measuredWidth, int measuredHeight) { |
| 1842 | WebView.this.setMeasuredDimension(measuredWidth, measuredHeight); |
| 1843 | } |
| 1844 | |
| 1845 | public void onScrollChanged(int l, int t, int oldl, int oldt) { |
| 1846 | WebView.this.onScrollChanged(l, t, oldl, oldt); |
| 1847 | } |
| 1848 | |
| 1849 | public int getHorizontalScrollbarHeight() { |
| 1850 | return WebView.this.getHorizontalScrollbarHeight(); |
| 1851 | } |
| 1852 | |
| 1853 | // ---- Access to (non-public) fields ---- |
| 1854 | /** Raw setter for the scroll X value, without invoking onScrollChanged handlers etc. */ |
| 1855 | public void setScrollXRaw(int scrollX) { |
| 1856 | WebView.this.mScrollX = scrollX; |
| 1857 | } |
| 1858 | |
| 1859 | /** Raw setter for the scroll Y value, without invoking onScrollChanged handlers etc. */ |
| 1860 | public void setScrollYRaw(int scrollY) { |
| 1861 | WebView.this.mScrollY = scrollY; |
| 1862 | } |
| 1863 | |
Teng-Hui Zhu | 661e8b1 | 2011-03-02 15:09:34 -0800 | [diff] [blame] | 1864 | } |
| 1865 | |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1866 | //------------------------------------------------------------------------- |
Ben Murdoch | 52c9f7f | 2013-01-18 00:50:37 +0000 | [diff] [blame] | 1867 | // Package-private internal stuff |
| 1868 | //------------------------------------------------------------------------- |
| 1869 | |
| 1870 | // Only used by android.webkit.FindActionModeCallback. |
| 1871 | void setFindDialogFindListener(FindListener listener) { |
| 1872 | checkThread(); |
| 1873 | setupFindListenerIfNeeded(); |
| 1874 | mFindListener.mFindDialogFindListener = listener; |
| 1875 | } |
| 1876 | |
| 1877 | // Only used by android.webkit.FindActionModeCallback. |
| 1878 | void notifyFindDialogDismissed() { |
| 1879 | checkThread(); |
| 1880 | mProvider.notifyFindDialogDismissed(); |
| 1881 | } |
| 1882 | |
| 1883 | //------------------------------------------------------------------------- |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1884 | // Private internal stuff |
| 1885 | //------------------------------------------------------------------------- |
| 1886 | |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1887 | private WebViewProvider mProvider; |
| 1888 | |
Ben Murdoch | 52c9f7f | 2013-01-18 00:50:37 +0000 | [diff] [blame] | 1889 | /** |
| 1890 | * In addition to the FindListener that the user may set via the WebView.setFindListener |
| 1891 | * API, FindActionModeCallback will register it's own FindListener. We keep them separate |
| 1892 | * via this class so that that the two FindListeners can potentially exist at once. |
| 1893 | */ |
| 1894 | private class FindListenerDistributor implements FindListener { |
| 1895 | private FindListener mFindDialogFindListener; |
| 1896 | private FindListener mUserFindListener; |
| 1897 | |
| 1898 | @Override |
| 1899 | public void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches, |
| 1900 | boolean isDoneCounting) { |
| 1901 | if (mFindDialogFindListener != null) { |
| 1902 | mFindDialogFindListener.onFindResultReceived(activeMatchOrdinal, numberOfMatches, |
| 1903 | isDoneCounting); |
| 1904 | } |
| 1905 | |
| 1906 | if (mUserFindListener != null) { |
| 1907 | mUserFindListener.onFindResultReceived(activeMatchOrdinal, numberOfMatches, |
| 1908 | isDoneCounting); |
| 1909 | } |
| 1910 | } |
| 1911 | } |
| 1912 | private FindListenerDistributor mFindListener; |
| 1913 | |
| 1914 | private void setupFindListenerIfNeeded() { |
| 1915 | if (mFindListener == null) { |
| 1916 | mFindListener = new FindListenerDistributor(); |
| 1917 | mProvider.setFindListener(mFindListener); |
| 1918 | } |
| 1919 | } |
| 1920 | |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1921 | private void ensureProviderCreated() { |
| 1922 | checkThread(); |
| 1923 | if (mProvider == null) { |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1924 | // As this can get called during the base class constructor chain, pass the minimum |
| 1925 | // number of dependencies here; the rest are deferred to init(). |
| 1926 | mProvider = getFactory().createWebView(this, new PrivateAccess()); |
| 1927 | } |
Ben Murdoch | ecbc65c | 2010-01-13 10:54:56 +0000 | [diff] [blame] | 1928 | } |
| 1929 | |
Jonathan Dixon | 951fcab | 2012-08-20 16:37:15 -0700 | [diff] [blame] | 1930 | private static synchronized WebViewFactoryProvider getFactory() { |
Jonathan Dixon | d3101b1 | 2012-04-12 20:51:51 +0100 | [diff] [blame] | 1931 | return WebViewFactory.getProvider(); |
Ben Murdoch | 1708ad5 | 2010-11-11 15:56:16 +0000 | [diff] [blame] | 1932 | } |
| 1933 | |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1934 | private static void checkThread() { |
Steve Block | 08d584c | 2011-05-17 19:05:03 +0100 | [diff] [blame] | 1935 | if (Looper.myLooper() != Looper.getMainLooper()) { |
Steve Block | 7a01d94 | 2011-09-26 12:30:31 +0100 | [diff] [blame] | 1936 | Throwable throwable = new Throwable( |
| 1937 | "Warning: A WebView method was called on thread '" + |
Steve Block | 08d584c | 2011-05-17 19:05:03 +0100 | [diff] [blame] | 1938 | Thread.currentThread().getName() + "'. " + |
| 1939 | "All WebView methods must be called on the UI thread. " + |
| 1940 | "Future versions of WebView may not support use on other threads."); |
Steve Block | 7a01d94 | 2011-09-26 12:30:31 +0100 | [diff] [blame] | 1941 | Log.w(LOGTAG, Log.getStackTraceString(throwable)); |
| 1942 | StrictMode.onWebViewMethodCalledOnWrongThread(throwable); |
Kristian Monsen | b5cd8c0 | 2013-04-09 17:57:37 -0700 | [diff] [blame] | 1943 | |
| 1944 | if (sEnforceThreadChecking) { |
| 1945 | throw new RuntimeException(throwable); |
| 1946 | } |
Steve Block | 51b0891 | 2011-04-27 15:04:48 +0100 | [diff] [blame] | 1947 | } |
| 1948 | } |
| 1949 | |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1950 | //------------------------------------------------------------------------- |
| 1951 | // Override View methods |
| 1952 | //------------------------------------------------------------------------- |
| 1953 | |
| 1954 | // TODO: Add a test that enumerates all methods in ViewDelegte & ScrollDelegate, and ensures |
| 1955 | // there's a corresponding override (or better, caller) for each of them in here. |
| 1956 | |
| 1957 | @Override |
| 1958 | protected void onAttachedToWindow() { |
| 1959 | super.onAttachedToWindow(); |
| 1960 | mProvider.getViewDelegate().onAttachedToWindow(); |
Chris Craik | 555c55e | 2011-07-28 15:39:43 -0700 | [diff] [blame] | 1961 | } |
| 1962 | |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1963 | @Override |
| 1964 | protected void onDetachedFromWindow() { |
| 1965 | mProvider.getViewDelegate().onDetachedFromWindow(); |
| 1966 | super.onDetachedFromWindow(); |
Chris Craik | 555c55e | 2011-07-28 15:39:43 -0700 | [diff] [blame] | 1967 | } |
| 1968 | |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1969 | @Override |
| 1970 | public void setLayoutParams(ViewGroup.LayoutParams params) { |
| 1971 | mProvider.getViewDelegate().setLayoutParams(params); |
Chris Craik | 445ab74 | 2011-07-13 13:19:37 -0700 | [diff] [blame] | 1972 | } |
| 1973 | |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1974 | @Override |
| 1975 | public void setOverScrollMode(int mode) { |
| 1976 | super.setOverScrollMode(mode); |
Martin Kosiba | 5ee743e | 2012-12-21 12:39:50 +0000 | [diff] [blame] | 1977 | // This method may be called in the constructor chain, before the WebView provider is |
| 1978 | // created. |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1979 | ensureProviderCreated(); |
| 1980 | mProvider.getViewDelegate().setOverScrollMode(mode); |
Chris Craik | 445ab74 | 2011-07-13 13:19:37 -0700 | [diff] [blame] | 1981 | } |
| 1982 | |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1983 | @Override |
| 1984 | public void setScrollBarStyle(int style) { |
| 1985 | mProvider.getViewDelegate().setScrollBarStyle(style); |
| 1986 | super.setScrollBarStyle(style); |
George Mount | 3d09531 | 2012-01-10 11:24:02 -0800 | [diff] [blame] | 1987 | } |
| 1988 | |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1989 | @Override |
| 1990 | protected int computeHorizontalScrollRange() { |
| 1991 | return mProvider.getScrollDelegate().computeHorizontalScrollRange(); |
John Reck | 5528d7c | 2012-02-28 11:29:29 -0800 | [diff] [blame] | 1992 | } |
| 1993 | |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1994 | @Override |
| 1995 | protected int computeHorizontalScrollOffset() { |
| 1996 | return mProvider.getScrollDelegate().computeHorizontalScrollOffset(); |
| 1997 | } |
Grace Kloba | 8abd50b | 2010-07-08 15:02:14 -0700 | [diff] [blame] | 1998 | |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 1999 | @Override |
| 2000 | protected int computeVerticalScrollRange() { |
| 2001 | return mProvider.getScrollDelegate().computeVerticalScrollRange(); |
| 2002 | } |
Patrick Scott | a3ebcc9 | 2010-07-16 11:52:22 -0400 | [diff] [blame] | 2003 | |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 2004 | @Override |
| 2005 | protected int computeVerticalScrollOffset() { |
| 2006 | return mProvider.getScrollDelegate().computeVerticalScrollOffset(); |
| 2007 | } |
Ben Murdoch | fa148f6 | 2011-02-01 20:51:27 +0000 | [diff] [blame] | 2008 | |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 2009 | @Override |
| 2010 | protected int computeVerticalScrollExtent() { |
| 2011 | return mProvider.getScrollDelegate().computeVerticalScrollExtent(); |
| 2012 | } |
| 2013 | |
| 2014 | @Override |
| 2015 | public void computeScroll() { |
| 2016 | mProvider.getScrollDelegate().computeScroll(); |
| 2017 | } |
| 2018 | |
| 2019 | @Override |
| 2020 | public boolean onHoverEvent(MotionEvent event) { |
| 2021 | return mProvider.getViewDelegate().onHoverEvent(event); |
| 2022 | } |
| 2023 | |
| 2024 | @Override |
| 2025 | public boolean onTouchEvent(MotionEvent event) { |
| 2026 | return mProvider.getViewDelegate().onTouchEvent(event); |
| 2027 | } |
| 2028 | |
| 2029 | @Override |
| 2030 | public boolean onGenericMotionEvent(MotionEvent event) { |
| 2031 | return mProvider.getViewDelegate().onGenericMotionEvent(event); |
| 2032 | } |
| 2033 | |
| 2034 | @Override |
| 2035 | public boolean onTrackballEvent(MotionEvent event) { |
| 2036 | return mProvider.getViewDelegate().onTrackballEvent(event); |
| 2037 | } |
| 2038 | |
| 2039 | @Override |
| 2040 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 2041 | return mProvider.getViewDelegate().onKeyDown(keyCode, event); |
| 2042 | } |
| 2043 | |
| 2044 | @Override |
| 2045 | public boolean onKeyUp(int keyCode, KeyEvent event) { |
| 2046 | return mProvider.getViewDelegate().onKeyUp(keyCode, event); |
| 2047 | } |
| 2048 | |
| 2049 | @Override |
| 2050 | public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) { |
| 2051 | return mProvider.getViewDelegate().onKeyMultiple(keyCode, repeatCount, event); |
| 2052 | } |
| 2053 | |
| 2054 | /* |
| 2055 | TODO: These are not currently implemented in WebViewClassic, but it seems inconsistent not |
| 2056 | to be delegating them too. |
| 2057 | |
| 2058 | @Override |
| 2059 | public boolean onKeyPreIme(int keyCode, KeyEvent event) { |
| 2060 | return mProvider.getViewDelegate().onKeyPreIme(keyCode, event); |
| 2061 | } |
| 2062 | @Override |
| 2063 | public boolean onKeyLongPress(int keyCode, KeyEvent event) { |
| 2064 | return mProvider.getViewDelegate().onKeyLongPress(keyCode, event); |
| 2065 | } |
| 2066 | @Override |
| 2067 | public boolean onKeyShortcut(int keyCode, KeyEvent event) { |
| 2068 | return mProvider.getViewDelegate().onKeyShortcut(keyCode, event); |
| 2069 | } |
| 2070 | */ |
| 2071 | |
Ben Murdoch | e3f9071 | 2013-06-05 14:19:48 +0100 | [diff] [blame] | 2072 | @Override |
| 2073 | public AccessibilityNodeProvider getAccessibilityNodeProvider() { |
| 2074 | AccessibilityNodeProvider provider = |
| 2075 | mProvider.getViewDelegate().getAccessibilityNodeProvider(); |
| 2076 | return provider == null ? super.getAccessibilityNodeProvider() : provider; |
| 2077 | } |
| 2078 | |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 2079 | @Deprecated |
| 2080 | @Override |
| 2081 | public boolean shouldDelayChildPressedState() { |
| 2082 | return mProvider.getViewDelegate().shouldDelayChildPressedState(); |
| 2083 | } |
| 2084 | |
| 2085 | @Override |
| 2086 | public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { |
| 2087 | super.onInitializeAccessibilityNodeInfo(info); |
alanv | ea07721 | 2012-03-30 14:59:42 -0700 | [diff] [blame] | 2088 | info.setClassName(WebView.class.getName()); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 2089 | mProvider.getViewDelegate().onInitializeAccessibilityNodeInfo(info); |
| 2090 | } |
| 2091 | |
| 2092 | @Override |
| 2093 | public void onInitializeAccessibilityEvent(AccessibilityEvent event) { |
| 2094 | super.onInitializeAccessibilityEvent(event); |
alanv | ea07721 | 2012-03-30 14:59:42 -0700 | [diff] [blame] | 2095 | event.setClassName(WebView.class.getName()); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 2096 | mProvider.getViewDelegate().onInitializeAccessibilityEvent(event); |
| 2097 | } |
| 2098 | |
alanv | 448902d | 2012-05-16 20:27:47 -0700 | [diff] [blame] | 2099 | @Override |
| 2100 | public boolean performAccessibilityAction(int action, Bundle arguments) { |
| 2101 | return mProvider.getViewDelegate().performAccessibilityAction(action, arguments); |
| 2102 | } |
| 2103 | |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 2104 | /** @hide */ |
| 2105 | @Override |
| 2106 | protected void onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar, |
| 2107 | int l, int t, int r, int b) { |
| 2108 | mProvider.getViewDelegate().onDrawVerticalScrollBar(canvas, scrollBar, l, t, r, b); |
| 2109 | } |
| 2110 | |
| 2111 | @Override |
| 2112 | protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) { |
| 2113 | mProvider.getViewDelegate().onOverScrolled(scrollX, scrollY, clampedX, clampedY); |
| 2114 | } |
| 2115 | |
| 2116 | @Override |
| 2117 | protected void onWindowVisibilityChanged(int visibility) { |
| 2118 | super.onWindowVisibilityChanged(visibility); |
| 2119 | mProvider.getViewDelegate().onWindowVisibilityChanged(visibility); |
| 2120 | } |
| 2121 | |
| 2122 | @Override |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 2123 | protected void onDraw(Canvas canvas) { |
| 2124 | mProvider.getViewDelegate().onDraw(canvas); |
| 2125 | } |
| 2126 | |
| 2127 | @Override |
| 2128 | public boolean performLongClick() { |
| 2129 | return mProvider.getViewDelegate().performLongClick(); |
| 2130 | } |
| 2131 | |
| 2132 | @Override |
| 2133 | protected void onConfigurationChanged(Configuration newConfig) { |
| 2134 | mProvider.getViewDelegate().onConfigurationChanged(newConfig); |
| 2135 | } |
| 2136 | |
| 2137 | @Override |
| 2138 | public InputConnection onCreateInputConnection(EditorInfo outAttrs) { |
| 2139 | return mProvider.getViewDelegate().onCreateInputConnection(outAttrs); |
| 2140 | } |
| 2141 | |
| 2142 | @Override |
| 2143 | protected void onVisibilityChanged(View changedView, int visibility) { |
| 2144 | super.onVisibilityChanged(changedView, visibility); |
Martin Kosiba | 5ee743e | 2012-12-21 12:39:50 +0000 | [diff] [blame] | 2145 | // This method may be called in the constructor chain, before the WebView provider is |
| 2146 | // created. |
| 2147 | ensureProviderCreated(); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 2148 | mProvider.getViewDelegate().onVisibilityChanged(changedView, visibility); |
| 2149 | } |
| 2150 | |
| 2151 | @Override |
| 2152 | public void onWindowFocusChanged(boolean hasWindowFocus) { |
| 2153 | mProvider.getViewDelegate().onWindowFocusChanged(hasWindowFocus); |
| 2154 | super.onWindowFocusChanged(hasWindowFocus); |
| 2155 | } |
| 2156 | |
| 2157 | @Override |
| 2158 | protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) { |
| 2159 | mProvider.getViewDelegate().onFocusChanged(focused, direction, previouslyFocusedRect); |
| 2160 | super.onFocusChanged(focused, direction, previouslyFocusedRect); |
| 2161 | } |
| 2162 | |
| 2163 | /** @hide */ |
| 2164 | @Override |
| 2165 | protected boolean setFrame(int left, int top, int right, int bottom) { |
| 2166 | return mProvider.getViewDelegate().setFrame(left, top, right, bottom); |
| 2167 | } |
| 2168 | |
| 2169 | @Override |
| 2170 | protected void onSizeChanged(int w, int h, int ow, int oh) { |
| 2171 | super.onSizeChanged(w, h, ow, oh); |
| 2172 | mProvider.getViewDelegate().onSizeChanged(w, h, ow, oh); |
| 2173 | } |
| 2174 | |
| 2175 | @Override |
| 2176 | protected void onScrollChanged(int l, int t, int oldl, int oldt) { |
| 2177 | super.onScrollChanged(l, t, oldl, oldt); |
| 2178 | mProvider.getViewDelegate().onScrollChanged(l, t, oldl, oldt); |
| 2179 | } |
| 2180 | |
| 2181 | @Override |
| 2182 | public boolean dispatchKeyEvent(KeyEvent event) { |
| 2183 | return mProvider.getViewDelegate().dispatchKeyEvent(event); |
| 2184 | } |
| 2185 | |
| 2186 | @Override |
| 2187 | public boolean requestFocus(int direction, Rect previouslyFocusedRect) { |
| 2188 | return mProvider.getViewDelegate().requestFocus(direction, previouslyFocusedRect); |
| 2189 | } |
| 2190 | |
| 2191 | @Deprecated |
| 2192 | @Override |
| 2193 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 2194 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 2195 | mProvider.getViewDelegate().onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 2196 | } |
| 2197 | |
| 2198 | @Override |
| 2199 | public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate) { |
| 2200 | return mProvider.getViewDelegate().requestChildRectangleOnScreen(child, rect, immediate); |
| 2201 | } |
| 2202 | |
| 2203 | @Override |
| 2204 | public void setBackgroundColor(int color) { |
| 2205 | mProvider.getViewDelegate().setBackgroundColor(color); |
| 2206 | } |
John Reck | a5408e6 | 2012-03-16 14:18:44 -0700 | [diff] [blame] | 2207 | |
| 2208 | @Override |
| 2209 | public void setLayerType(int layerType, Paint paint) { |
| 2210 | super.setLayerType(layerType, paint); |
| 2211 | mProvider.getViewDelegate().setLayerType(layerType, paint); |
| 2212 | } |
Ben Murdoch | e623e24 | 2012-09-07 20:47:07 +0100 | [diff] [blame] | 2213 | |
| 2214 | @Override |
| 2215 | protected void dispatchDraw(Canvas canvas) { |
| 2216 | mProvider.getViewDelegate().preDispatchDraw(canvas); |
| 2217 | super.dispatchDraw(canvas); |
| 2218 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2219 | } |