/* * Copyright (C) 2006 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.webkit; import android.annotation.Widget; import android.content.Context; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Picture; import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.net.http.SslCertificate; import android.os.Bundle; import android.os.Looper; import android.os.Message; import android.os.StrictMode; import android.util.AttributeSet; import android.util.Log; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; import android.view.ViewDebug; import android.view.ViewGroup; import android.view.ViewTreeObserver; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityNodeInfo; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputConnection; import android.widget.AbsoluteLayout; import java.io.BufferedWriter; import java.io.File; import java.util.Map; /** *
A View that displays web pages. This class is the basis upon which you * can roll your own web browser or simply display some online content within your Activity. * It uses the WebKit rendering engine to display * web pages and includes methods to navigate forward and backward * through a history, zoom in and out, perform text searches and more.
*To enable the built-in zoom, set * {@link #getSettings() WebSettings}.{@link WebSettings#setBuiltInZoomControls(boolean)} * (introduced in API level {@link android.os.Build.VERSION_CODES#CUPCAKE}). *
Note that, in order for your Activity to access the Internet and load web pages * in a WebView, you must add the {@code INTERNET} permissions to your * Android Manifest file:
*<uses-permission android:name="android.permission.INTERNET" />* *
This must be a child of the {@code
See the Web View * tutorial.
* *By default, a WebView provides no browser-like widgets, does not * enable JavaScript and web page errors are ignored. If your goal is only * to display some HTML as a part of your UI, this is probably fine; * the user won't need to interact with the web page beyond reading * it, and the web page won't need to interact with the user. If you * actually want a full-blown web browser, then you probably want to * invoke the Browser application with a URL Intent rather than show it * with a WebView. For example: *
* Uri uri = Uri.parse("http://www.example.com"); * Intent intent = new Intent(Intent.ACTION_VIEW, uri); * startActivity(intent); **
See {@link android.content.Intent} for more information.
* *To provide a WebView in your own Activity, include a {@code
* WebView webview = new WebView(this); * setContentView(webview); ** *
Then load the desired web page:
** // Simplest usage: note that an exception will NOT be thrown * // if there is an error loading this page (see below). * webview.loadUrl("http://slashdot.org/"); * * // OR, you can also load from an HTML string: * String summary = "<html><body>You scored <b>192</b> points.</body></html>"; * webview.loadData(summary, "text/html", null); * // ... although note that there are restrictions on what this HTML can do. * // See the JavaDocs for {@link #loadData(String,String,String) loadData()} and {@link * #loadDataWithBaseURL(String,String,String,String,String) loadDataWithBaseURL()} for more info. ** *
A WebView has several customization points where you can add your * own behavior. These are:
* *Here's a more complicated example, showing error handling, * settings, and progress notification:
* ** // Let's display the progress in the activity title bar, like the * // browser app does. * getWindow().requestFeature(Window.FEATURE_PROGRESS); * * webview.getSettings().setJavaScriptEnabled(true); * * final Activity activity = this; * webview.setWebChromeClient(new WebChromeClient() { * public void onProgressChanged(WebView view, int progress) { * // Activities and WebViews measure progress with different scales. * // The progress meter will automatically disappear when we reach 100% * activity.setProgress(progress * 1000); * } * }); * webview.setWebViewClient(new WebViewClient() { * public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { * Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show(); * } * }); * * webview.loadUrl("http://slashdot.org/"); ** *
For obvious security reasons, your application has its own * cache, cookie store etc.—it does not share the Browser * application's data. Cookies are managed on a separate thread, so * operations like index building don't block the UI * thread. Follow the instructions in {@link android.webkit.CookieSyncManager} * if you want to use cookies in your application. *
* *By default, requests by the HTML to open new windows are * ignored. This is true whether they be opened by JavaScript or by * the target attribute on a link. You can customize your * {@link WebChromeClient} to provide your own behaviour for opening multiple windows, * and render them in whatever manner you want.
* *The standard behavior for an Activity is to be destroyed and * recreated when the device orientation or any other configuration changes. This will cause * the WebView to reload the current page. If you don't want that, you * can set your Activity to handle the {@code orientation} and {@code keyboardHidden} * changes, and then just leave the WebView alone. It'll automatically * re-orient itself as appropriate. Read Handling Runtime Changes for * more information about how to handle configuration changes during runtime.
* * *The screen density of a device is based on the screen resolution. A screen with low density * has fewer available pixels per inch, where a screen with high density * has more — sometimes significantly more — pixels per inch. The density of a * screen is important because, other things being equal, a UI element (such as a button) whose * height and width are defined in terms of screen pixels will appear larger on the lower density * screen and smaller on the higher density screen. * For simplicity, Android collapses all actual screen densities into three generalized densities: * high, medium, and low.
*By default, WebView scales a web page so that it is drawn at a size that matches the default * appearance on a medium density screen. So, it applies 1.5x scaling on a high density screen * (because its pixels are smaller) and 0.75x scaling on a low density screen (because its pixels * are bigger). * Starting with API level {@link android.os.Build.VERSION_CODES#ECLAIR}, WebView supports DOM, CSS, * and meta tag features to help you (as a web developer) target screens with different screen * densities.
*Here's a summary of the features you can use to handle different screen densities:
** <link rel="stylesheet" media="screen and (-webkit-device-pixel-ratio:1.5)" href="hdpi.css" />*
The {@code hdpi.css} stylesheet is only used for devices with a screen pixel ration of 1.5, * which is the high density pixel ratio.
*Here's an example meta tag to specify the target density:
*<meta name="viewport" content="target-densitydpi=device-dpi" />
If you want to modify your web page for different densities, by using the {@code * -webkit-device-pixel-ratio} CSS media query and/or the {@code * window.devicePixelRatio} DOM property, then you should set the {@code target-densitydpi} meta * property to {@code device-dpi}. This stops Android from performing scaling in your web page and * allows you to make the necessary adjustments for each density via CSS and JavaScript.
* *In order to support inline HTML5 video in your application, you need to have hardware * acceleration turned on, and set a {@link android.webkit.WebChromeClient}. For full screen support, * implementations of {@link WebChromeClient#onShowCustomView(View, WebChromeClient.CustomViewCallback)} * and {@link WebChromeClient#onHideCustomView()} are required, * {@link WebChromeClient#getVideoLoadingProgressView()} is optional. *
*/ // Implementation notes. // The WebView is a thin API class that delegates its public API to a backend WebViewProvider // class instance. WebView extends {@link AbsoluteLayout} for backward compatibility reasons. // Methods are delegated to the provider implementation: all public API methods introduced in this // file are fully delegated, whereas public and protected methods from the View base classes are // only delegated where a specific need exists for them to do so. @Widget public class WebView extends AbsoluteLayout implements ViewTreeObserver.OnGlobalFocusChangeListener, ViewGroup.OnHierarchyChangeListener, ViewDebug.HierarchyHandler { private static final String LOGTAG = "webview_proxy"; /** * Transportation object for returning WebView across thread boundaries. */ public class WebViewTransport { private WebView mWebview; /** * Sets the WebView to the transportation object. * * @param webview the WebView to transport */ public synchronized void setWebView(WebView webview) { mWebview = webview; } /** * Gets the WebView object. * * @return the transported WebView object */ public synchronized WebView getWebView() { return mWebview; } } /** * URI scheme for telephone number. */ public static final String SCHEME_TEL = "tel:"; /** * URI scheme for email address. */ public static final String SCHEME_MAILTO = "mailto:"; /** * URI scheme for map address. */ public static final String SCHEME_GEO = "geo:0,0?q="; /** * Interface to listen for find results. */ public interface FindListener { /** * Notifies the listener about progress made by a find operation. * * @param numberOfMatches how many matches have been found * @param activeMatchOrdinal the zero-based ordinal of the currently selected match * @param isDoneCounting whether the find operation has actually completed. The listener * may be notified multiple times while the * operation is underway, and the numberOfMatches * value should not be considered final unless * isDoneCounting is true. */ public void onFindResultReceived(int numberOfMatches, int activeMatchOrdinal, boolean isDoneCounting); } /** * Interface to listen for new pictures as they change. * * @deprecated This interface is now obsolete. */ @Deprecated public interface PictureListener { /** * Notifies the listener that the picture has changed. * * @param view the WebView that owns the picture * @param picture the new picture * @deprecated Due to internal changes, the picture does not include * composited layers such as fixed position elements or * scrollable divs. While the PictureListener API can still * be used to detect changes in the WebView content, you * are advised against its usage until a replacement is * provided in a future Android release. */ @Deprecated public void onNewPicture(WebView view, Picture picture); } public static class HitTestResult { /** * Default HitTestResult, where the target is unknown. */ public static final int UNKNOWN_TYPE = 0; /** * @deprecated This type is no longer used. */ @Deprecated public static final int ANCHOR_TYPE = 1; /** * HitTestResult for hitting a phone number. */ public static final int PHONE_TYPE = 2; /** * HitTestResult for hitting a map address. */ public static final int GEO_TYPE = 3; /** * HitTestResult for hitting an email address. */ public static final int EMAIL_TYPE = 4; /** * HitTestResult for hitting an HTML::img tag. */ public static final int IMAGE_TYPE = 5; /** * @deprecated This type is no longer used. */ @Deprecated public static final int IMAGE_ANCHOR_TYPE = 6; /** * HitTestResult for hitting a HTML::a tag with src=http. */ public static final int SRC_ANCHOR_TYPE = 7; /** * HitTestResult for hitting a HTML::a tag with src=http + HTML::img. */ public static final int SRC_IMAGE_ANCHOR_TYPE = 8; /** * HitTestResult for hitting an edit text area. */ public static final int EDIT_TEXT_TYPE = 9; private int mType; private String mExtra; /** * @hide Only for use by WebViewProvider implementations */ public HitTestResult() { mType = UNKNOWN_TYPE; } /** * @hide Only for use by WebViewProvider implementations */ public void setType(int type) { mType = type; } /** * @hide Only for use by WebViewProvider implementations */ public void setExtra(String extra) { mExtra = extra; } /** * Gets the type of the hit test result. See the XXX_TYPE constants * defined in this class. * * @return the type of the hit test result */ public int getType() { return mType; } /** * Gets additional type-dependant information about the result. See * {@link WebView#getHitTestResult()} for details. May either be null * or contain extra information about this result. * * @return additional type-dependant information about the result */ public String getExtra() { return mExtra; } } /** * Constructs a new WebView with a Context object. * * @param context a Context object used to access application assets */ public WebView(Context context) { this(context, null); } /** * Constructs a new WebView with layout parameters. * * @param context a Context object used to access application assets * @param attrs an AttributeSet passed to our parent */ public WebView(Context context, AttributeSet attrs) { this(context, attrs, com.android.internal.R.attr.webViewStyle); } /** * Constructs a new WebView with layout parameters and a default style. * * @param context a Context object used to access application assets * @param attrs an AttributeSet passed to our parent * @param defStyle the default style resource ID */ public WebView(Context context, AttributeSet attrs, int defStyle) { this(context, attrs, defStyle, false); } /** * Constructs a new WebView with layout parameters and a default style. * * @param context a Context object used to access application assets * @param attrs an AttributeSet passed to our parent * @param defStyle the default style resource ID * @param privateBrowsing whether this WebView will be initialized in * private mode */ public WebView(Context context, AttributeSet attrs, int defStyle, boolean privateBrowsing) { this(context, attrs, defStyle, null, privateBrowsing); } /** * Constructs a new WebView with layout parameters, a default style and a set * of custom Javscript interfaces to be added to this WebView at initialization * time. This guarantees that these interfaces will be available when the JS * context is initialized. * * @param context a Context object used to access application assets * @param attrs an AttributeSet passed to our parent * @param defStyle the default style resource ID * @param javaScriptInterfaces a Map of interface names, as keys, and * object implementing those interfaces, as * values * @param privateBrowsing whether this WebView will be initialized in * private mode * @hide This is used internally by dumprendertree, as it requires the javaScript interfaces to * be added synchronously, before a subsequent loadUrl call takes effect. */ @SuppressWarnings("deprecation") // for super() call into deprecated base class constructor. protected WebView(Context context, AttributeSet attrs, int defStyle, Map* Note that JavaScript's same origin policy means that script running in a * page loaded using this method will be unable to access content loaded * using any scheme other than 'data', including 'http(s)'. To avoid this * restriction, use {@link * #loadDataWithBaseURL(String,String,String,String,String) * loadDataWithBaseURL()} with an appropriate base URL. *
* If the value of the encoding parameter is 'base64', then the data must * be encoded as base64. Otherwise, the data must use ASCII encoding for * octets inside the range of safe URL characters and use the standard %xx * hex encoding of URLs for octets outside that range. For example, * '#', '%', '\', '?' should be replaced by %23, %25, %27, %3f respectively. *
* The 'data' scheme URL formed by this method uses the default US-ASCII * charset. If you need need to set a different charset, you should form a * 'data' scheme URL which explicitly specifies a charset parameter in the * mediatype portion of the URL and call {@link #loadUrl(String)} instead. * Note that the charset obtained from the mediatype portion of a data URL * always overrides that specified in the HTML or XML document itself. * * @param data a String of data in the given encoding * @param mimeType the MIME type of the data, e.g. 'text/html' * @param encoding the encoding of the data */ public void loadData(String data, String mimeType, String encoding) { checkThread(); mProvider.loadData(data, mimeType, encoding); } /** * Loads the given data into this WebView, using baseUrl as the base URL for * the content. The base URL is used both to resolve relative URLs and when * applying JavaScript's same origin policy. The historyUrl is used for the * history entry. *
* Note that content specified in this way can access local device files * (via 'file' scheme URLs) only if baseUrl specifies a scheme other than * 'http', 'https', 'ftp', 'ftps', 'about' or 'javascript'. *
* If the base URL uses the data scheme, this method is equivalent to
* calling {@link #loadData(String,String,String) loadData()} and the
* historyUrl is ignored.
*
* @param baseUrl the URL to use as the page's base URL. If null defaults to
* 'about:blank'.
* @param data a String of data in the given encoding
* @param mimeType the MIMEType of the data, e.g. 'text/html'. If null,
* defaults to 'text/html'.
* @param encoding the encoding of the data
* @param historyUrl the URL to use as the history entry. If null defaults
* to 'about:blank'.
*/
public void loadDataWithBaseURL(String baseUrl, String data,
String mimeType, String encoding, String historyUrl) {
checkThread();
mProvider.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, historyUrl);
}
/**
* Saves the current view as a web archive.
*
* @param filename the filename where the archive should be placed
*/
public void saveWebArchive(String filename) {
checkThread();
mProvider.saveWebArchive(filename);
}
/**
* Saves the current view as a web archive.
*
* @param basename the filename where the archive should be placed
* @param autoname if false, takes basename to be a file. If true, basename
* is assumed to be a directory in which a filename will be
* chosen according to the URL of the current page.
* @param callback called after the web archive has been saved. The
* parameter for onReceiveValue will either be the filename
* under which the file was saved, or null if saving the
* file failed.
*/
public void saveWebArchive(String basename, boolean autoname, ValueCallback
* IMPORTANT:
*
*
* All names must be correctly capitalized, and the zip code, if present,
* must be valid for the state. The street type must be a standard USPS
* spelling or abbreviation. The state or territory must also be spelled
* or abbreviated using USPS standards. The house number may not exceed
* five digits.
*
* @param addr the string to search for addresses
* @return the address, or if no address is found, null
*/
public static String findAddress(String addr) {
checkThread();
return getFactory().getStatics().findAddress(addr);
}
/**
* Clears the highlighting surrounding text matches created by
* {@link #findAll} or {@link #findAllAsync}.
*/
public void clearMatches() {
checkThread();
mProvider.clearMatches();
}
/**
* Queries the document to see if it contains any image references. The
* message object will be dispatched with arg1 being set to 1 if images
* were found and 0 if the document does not reference any images.
*
* @param response the message that will be dispatched with the result
*/
public void documentHasImages(Message response) {
checkThread();
mProvider.documentHasImages(response);
}
/**
* Sets the WebViewClient that will receive various notifications and
* requests. This will replace the current handler.
*
* @param client an implementation of WebViewClient
*/
public void setWebViewClient(WebViewClient client) {
checkThread();
mProvider.setWebViewClient(client);
}
/**
* Registers the interface to be used when content can not be handled by
* the rendering engine, and should be downloaded instead. This will replace
* the current handler.
*
* @param listener an implementation of DownloadListener
*/
public void setDownloadListener(DownloadListener listener) {
checkThread();
mProvider.setDownloadListener(listener);
}
/**
* Sets the chrome handler. This is an implementation of WebChromeClient for
* use in handling JavaScript dialogs, favicons, titles, and the progress.
* This will replace the current handler.
*
* @param client an implementation of WebChromeClient
*/
public void setWebChromeClient(WebChromeClient client) {
checkThread();
mProvider.setWebChromeClient(client);
}
/**
* Sets the Picture listener. This is an interface used to receive
* notifications of a new Picture.
*
* @param listener an implementation of WebView.PictureListener
* @deprecated This method is now obsolete.
*/
@Deprecated
public void setPictureListener(PictureListener listener) {
checkThread();
mProvider.setPictureListener(listener);
}
/**
* Injects the supplied Java object into this WebView. The object is
* injected into the JavaScript context of the main frame, using the
* supplied name. This allows the Java object's public methods to be
* accessed from JavaScript. Note that that injected objects will not
* appear in JavaScript until the page is next (re)loaded. For example:
* webView.addJavascriptInterface(new Object(), "injectedObject");
* webView.loadData("
*
*
*
* @param object the Java object to inject into this WebView's JavaScript
* context. Null values are ignored.
* @param name the name used to expose the object in JavaScript
*/
public void addJavascriptInterface(Object object, String name) {
checkThread();
mProvider.addJavascriptInterface(object, name);
}
/**
* Removes a previously injected Java object from this WebView. Note that
* the removal will not be reflected in JavaScript until the page is next
* (re)loaded. See {@link #addJavascriptInterface}.
*
* @param name the name used to expose the object in JavaScript
*/
public void removeJavascriptInterface(String name) {
checkThread();
mProvider.removeJavascriptInterface(name);
}
/**
* Gets the WebSettings object used to control the settings for this
* WebView.
*
* @return a WebSettings object that can be used to control this WebView's
* settings
*/
public WebSettings getSettings() {
checkThread();
return mProvider.getSettings();
}
/**
* Gets the list of currently loaded plugins.
*
* @return the list of currently loaded plugins
* @deprecated This was used for Gears, which has been deprecated.
* @hide
*/
@Deprecated
public static synchronized PluginList getPluginList() {
checkThread();
return new PluginList();
}
/**
* @deprecated This was used for Gears, which has been deprecated.
* @hide
*/
@Deprecated
public void refreshPlugins(boolean reloadOpenPages) {
checkThread();
}
/**
* Puts this WebView into text selection mode. Do not rely on this
* functionality; it will be deprecated in the future.
*
* @deprecated This method is now obsolete.
*/
@Deprecated
public void emulateShiftHeld() {
checkThread();
mProvider.emulateShiftHeld();
}
/**
* @deprecated WebView no longer needs to implement
* ViewGroup.OnHierarchyChangeListener. This method does nothing now.
*/
@Override
// Cannot add @hide as this can always be accessed via the interface.
@Deprecated
public void onChildViewAdded(View parent, View child) {}
/**
* @deprecated WebView no longer needs to implement
* ViewGroup.OnHierarchyChangeListener. This method does nothing now.
*/
@Override
// Cannot add @hide as this can always be accessed via the interface.
@Deprecated
public void onChildViewRemoved(View p, View child) {}
/**
* @deprecated WebView should not have implemented
* ViewTreeObserver.OnGlobalFocusChangeListener. This method does nothing now.
*/
@Override
// Cannot add @hide as this can always be accessed via the interface.
@Deprecated
public void onGlobalFocusChanged(View oldFocus, View newFocus) {
}
public void setMapTrackballToArrowKeys(boolean setMap) {
checkThread();
mProvider.setMapTrackballToArrowKeys(setMap);
}
public void flingScroll(int vx, int vy) {
checkThread();
mProvider.flingScroll(vx, vy);
}
/**
* Gets the zoom controls for this WebView, as a separate View. The caller
* is responsible for inserting this View into the layout hierarchy.
*
* API level {@link android.os.Build.VERSION_CODES#CUPCAKE} introduced
* built-in zoom mechanisms for the WebView, as opposed to these separate
* zoom controls. The built-in mechanisms are preferred and can be enabled
* using {@link WebSettings#setBuiltInZoomControls}.
*
* @deprecated the built-in zoom mechanisms are preferred
* @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN}
*/
@Deprecated
public View getZoomControls() {
checkThread();
return mProvider.getZoomControls();
}
/**
* Gets whether this WebView can be zoomed in.
*
* @return true if this WebView can be zoomed in
*/
public boolean canZoomIn() {
checkThread();
return mProvider.canZoomIn();
}
/**
* Gets whether this WebView can be zoomed out.
*
* @return true if this WebView can be zoomed out
*/
public boolean canZoomOut() {
checkThread();
return mProvider.canZoomOut();
}
/**
* Performs zoom in in this WebView.
*
* @return true if zoom in succeeds, false if no zoom changes
*/
public boolean zoomIn() {
checkThread();
return mProvider.zoomIn();
}
/**
* Performs zoom out in this WebView.
*
* @return true if zoom out succeeds, false if no zoom changes
*/
public boolean zoomOut() {
checkThread();
return mProvider.zoomOut();
}
/**
* @deprecated This method is now obsolete.
*/
@Deprecated
public void debugDump() {
checkThread();
mProvider.debugDump();
}
/**
* See {@link ViewDebug.HierarchyHandler#dumpViewHierarchyWithProperties(BufferedWriter, int)}
* @hide
*/
@Override
public void dumpViewHierarchyWithProperties(BufferedWriter out, int level) {
mProvider.dumpViewHierarchyWithProperties(out, level);
}
/**
* See {@link ViewDebug.HierarchyHandler#findHierarchyView(String, int)}
* @hide
*/
@Override
public View findHierarchyView(String className, int hashCode) {
return mProvider.findHierarchyView(className, hashCode);
}
//-------------------------------------------------------------------------
// Interface for WebView providers
//-------------------------------------------------------------------------
/**
* Gets the WebViewProvider. Used by providers to obtain the underlying
* implementation, e.g. when the appliction responds to
* WebViewClient.onCreateWindow() request.
*
* @hide WebViewProvider is not public API.
*/
public WebViewProvider getWebViewProvider() {
return mProvider;
}
/**
* Callback interface, allows the provider implementation to access non-public methods
* and fields, and make super-class calls in this WebView instance.
* @hide Only for use by WebViewProvider implementations
*/
public class PrivateAccess {
// ---- Access to super-class methods ----
public int super_getScrollBarStyle() {
return WebView.super.getScrollBarStyle();
}
public void super_scrollTo(int scrollX, int scrollY) {
WebView.super.scrollTo(scrollX, scrollY);
}
public void super_computeScroll() {
WebView.super.computeScroll();
}
public boolean super_performAccessibilityAction(int action, Bundle arguments) {
return WebView.super.performAccessibilityAction(action, arguments);
}
public boolean super_performLongClick() {
return WebView.super.performLongClick();
}
public boolean super_setFrame(int left, int top, int right, int bottom) {
return WebView.super.setFrame(left, top, right, bottom);
}
public boolean super_dispatchKeyEvent(KeyEvent event) {
return WebView.super.dispatchKeyEvent(event);
}
public boolean super_onGenericMotionEvent(MotionEvent event) {
return WebView.super.onGenericMotionEvent(event);
}
public boolean super_requestFocus(int direction, Rect previouslyFocusedRect) {
return WebView.super.requestFocus(direction, previouslyFocusedRect);
}
public void super_setLayoutParams(ViewGroup.LayoutParams params) {
WebView.super.setLayoutParams(params);
}
// ---- Access to non-public methods ----
public void overScrollBy(int deltaX, int deltaY,
int scrollX, int scrollY,
int scrollRangeX, int scrollRangeY,
int maxOverScrollX, int maxOverScrollY,
boolean isTouchEvent) {
WebView.this.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX, scrollRangeY,
maxOverScrollX, maxOverScrollY, isTouchEvent);
}
public void awakenScrollBars(int duration) {
WebView.this.awakenScrollBars(duration);
}
public void awakenScrollBars(int duration, boolean invalidate) {
WebView.this.awakenScrollBars(duration, invalidate);
}
public float getVerticalScrollFactor() {
return WebView.this.getVerticalScrollFactor();
}
public float getHorizontalScrollFactor() {
return WebView.this.getHorizontalScrollFactor();
}
public void setMeasuredDimension(int measuredWidth, int measuredHeight) {
WebView.this.setMeasuredDimension(measuredWidth, measuredHeight);
}
public void onScrollChanged(int l, int t, int oldl, int oldt) {
WebView.this.onScrollChanged(l, t, oldl, oldt);
}
public int getHorizontalScrollbarHeight() {
return WebView.this.getHorizontalScrollbarHeight();
}
// ---- Access to (non-public) fields ----
/** Raw setter for the scroll X value, without invoking onScrollChanged handlers etc. */
public void setScrollXRaw(int scrollX) {
WebView.this.mScrollX = scrollX;
}
/** Raw setter for the scroll Y value, without invoking onScrollChanged handlers etc. */
public void setScrollYRaw(int scrollY) {
WebView.this.mScrollY = scrollY;
}
}
//-------------------------------------------------------------------------
// Private internal stuff
//-------------------------------------------------------------------------
private WebViewProvider mProvider;
private void ensureProviderCreated() {
checkThread();
if (mProvider == null) {
// As this can get called during the base class constructor chain, pass the minimum
// number of dependencies here; the rest are deferred to init().
mProvider = getFactory().createWebView(this, new PrivateAccess());
}
}
private static synchronized WebViewFactoryProvider getFactory() {
// For now the main purpose of this function (and the factory abstration) is to keep
// us honest and minimize usage of WebViewClassic internals when binding the proxy.
checkThread();
return WebViewFactory.getProvider();
}
private static void checkThread() {
if (Looper.myLooper() != Looper.getMainLooper()) {
Throwable throwable = new Throwable(
"Warning: A WebView method was called on thread '" +
Thread.currentThread().getName() + "'. " +
"All WebView methods must be called on the UI thread. " +
"Future versions of WebView may not support use on other threads.");
Log.w(LOGTAG, Log.getStackTraceString(throwable));
StrictMode.onWebViewMethodCalledOnWrongThread(throwable);
}
}
//-------------------------------------------------------------------------
// Override View methods
//-------------------------------------------------------------------------
// TODO: Add a test that enumerates all methods in ViewDelegte & ScrollDelegate, and ensures
// there's a corresponding override (or better, caller) for each of them in here.
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
mProvider.getViewDelegate().onAttachedToWindow();
}
@Override
protected void onDetachedFromWindow() {
mProvider.getViewDelegate().onDetachedFromWindow();
super.onDetachedFromWindow();
}
@Override
public void setLayoutParams(ViewGroup.LayoutParams params) {
mProvider.getViewDelegate().setLayoutParams(params);
}
@Override
public void setOverScrollMode(int mode) {
super.setOverScrollMode(mode);
// This method may called in the constructor chain, before the WebView provider is
// created. (Fortunately, this is the only method we override that can get called by
// any of the base class constructors).
ensureProviderCreated();
mProvider.getViewDelegate().setOverScrollMode(mode);
}
@Override
public void setScrollBarStyle(int style) {
mProvider.getViewDelegate().setScrollBarStyle(style);
super.setScrollBarStyle(style);
}
@Override
protected int computeHorizontalScrollRange() {
return mProvider.getScrollDelegate().computeHorizontalScrollRange();
}
@Override
protected int computeHorizontalScrollOffset() {
return mProvider.getScrollDelegate().computeHorizontalScrollOffset();
}
@Override
protected int computeVerticalScrollRange() {
return mProvider.getScrollDelegate().computeVerticalScrollRange();
}
@Override
protected int computeVerticalScrollOffset() {
return mProvider.getScrollDelegate().computeVerticalScrollOffset();
}
@Override
protected int computeVerticalScrollExtent() {
return mProvider.getScrollDelegate().computeVerticalScrollExtent();
}
@Override
public void computeScroll() {
mProvider.getScrollDelegate().computeScroll();
}
@Override
public boolean onHoverEvent(MotionEvent event) {
return mProvider.getViewDelegate().onHoverEvent(event);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return mProvider.getViewDelegate().onTouchEvent(event);
}
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
return mProvider.getViewDelegate().onGenericMotionEvent(event);
}
@Override
public boolean onTrackballEvent(MotionEvent event) {
return mProvider.getViewDelegate().onTrackballEvent(event);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
return mProvider.getViewDelegate().onKeyDown(keyCode, event);
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
return mProvider.getViewDelegate().onKeyUp(keyCode, event);
}
@Override
public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
return mProvider.getViewDelegate().onKeyMultiple(keyCode, repeatCount, event);
}
/*
TODO: These are not currently implemented in WebViewClassic, but it seems inconsistent not
to be delegating them too.
@Override
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
return mProvider.getViewDelegate().onKeyPreIme(keyCode, event);
}
@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
return mProvider.getViewDelegate().onKeyLongPress(keyCode, event);
}
@Override
public boolean onKeyShortcut(int keyCode, KeyEvent event) {
return mProvider.getViewDelegate().onKeyShortcut(keyCode, event);
}
*/
@Deprecated
@Override
public boolean shouldDelayChildPressedState() {
return mProvider.getViewDelegate().shouldDelayChildPressedState();
}
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(info);
info.setClassName(WebView.class.getName());
mProvider.getViewDelegate().onInitializeAccessibilityNodeInfo(info);
}
@Override
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
super.onInitializeAccessibilityEvent(event);
event.setClassName(WebView.class.getName());
mProvider.getViewDelegate().onInitializeAccessibilityEvent(event);
}
@Override
public boolean performAccessibilityAction(int action, Bundle arguments) {
return mProvider.getViewDelegate().performAccessibilityAction(action, arguments);
}
/** @hide */
@Override
protected void onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar,
int l, int t, int r, int b) {
mProvider.getViewDelegate().onDrawVerticalScrollBar(canvas, scrollBar, l, t, r, b);
}
@Override
protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
mProvider.getViewDelegate().onOverScrolled(scrollX, scrollY, clampedX, clampedY);
}
@Override
protected void onWindowVisibilityChanged(int visibility) {
super.onWindowVisibilityChanged(visibility);
mProvider.getViewDelegate().onWindowVisibilityChanged(visibility);
}
@Override
protected void onDraw(Canvas canvas) {
mProvider.getViewDelegate().onDraw(canvas);
}
@Override
public boolean performLongClick() {
return mProvider.getViewDelegate().performLongClick();
}
@Override
protected void onConfigurationChanged(Configuration newConfig) {
mProvider.getViewDelegate().onConfigurationChanged(newConfig);
}
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
return mProvider.getViewDelegate().onCreateInputConnection(outAttrs);
}
@Override
protected void onVisibilityChanged(View changedView, int visibility) {
super.onVisibilityChanged(changedView, visibility);
mProvider.getViewDelegate().onVisibilityChanged(changedView, visibility);
}
@Override
public void onWindowFocusChanged(boolean hasWindowFocus) {
mProvider.getViewDelegate().onWindowFocusChanged(hasWindowFocus);
super.onWindowFocusChanged(hasWindowFocus);
}
@Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
mProvider.getViewDelegate().onFocusChanged(focused, direction, previouslyFocusedRect);
super.onFocusChanged(focused, direction, previouslyFocusedRect);
}
/** @hide */
@Override
protected boolean setFrame(int left, int top, int right, int bottom) {
return mProvider.getViewDelegate().setFrame(left, top, right, bottom);
}
@Override
protected void onSizeChanged(int w, int h, int ow, int oh) {
super.onSizeChanged(w, h, ow, oh);
mProvider.getViewDelegate().onSizeChanged(w, h, ow, oh);
}
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
super.onScrollChanged(l, t, oldl, oldt);
mProvider.getViewDelegate().onScrollChanged(l, t, oldl, oldt);
}
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
return mProvider.getViewDelegate().dispatchKeyEvent(event);
}
@Override
public boolean requestFocus(int direction, Rect previouslyFocusedRect) {
return mProvider.getViewDelegate().requestFocus(direction, previouslyFocusedRect);
}
@Deprecated
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
mProvider.getViewDelegate().onMeasure(widthMeasureSpec, heightMeasureSpec);
}
@Override
public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate) {
return mProvider.getViewDelegate().requestChildRectangleOnScreen(child, rect, immediate);
}
@Override
public void setBackgroundColor(int color) {
mProvider.getViewDelegate().setBackgroundColor(color);
}
@Override
public void setLayerType(int layerType, Paint paint) {
super.setLayerType(layerType, paint);
mProvider.getViewDelegate().setLayerType(layerType, paint);
}
}