Android API翻译之WebChromeClient(未完工)

android.webkit.WebChromeClient (API 24源码)

辅助WebView处理JavaScript的对话框、网站图标、网站title、加载进度等

一、嵌套类

1.CustomViewCallback
/**
  * 自定义视图回调接口:宿主程序用来通知当前page——它的自定义视图已经被销毁——的一个回调接口
  */
    public interface CustomViewCallback {
        /**
         * 当宿主程序销毁自定义视图的时候调用
         */
        public void onCustomViewHidden();
    }
2.FileChooserParams
/**
  * 文件选择参数抽象类:为onShowFileChooser方法提供参数
  */
    public static abstract class FileChooserParams {
        /** 打开单个文件,在用户选择它之前要求文件是存在的*/
        public static final int MODE_OPEN = 0;
        /** 类似打开,但是运行用户多选文件. */
        public static final int MODE_OPEN_MULTIPLE = 1;
        /** 类似打开,但是运行用户选择文件夹,实现类应该列举此操作选择的所有文件,目前不支持此功能。*/
        public static final int MODE_OPEN_FOLDER = 2;
        /**  允许选择一个不存在的文件并保存它. */
        public static final int MODE_SAVE = 3;

        /**
         * 
         * 解析文件选择activity返回的结果,这个方法应该被用在createIntent()方法,如何使用请参考
         * createIntent()
         * @param resultCode 文件选择activity返回的整形的返回码.
         * @param data 从文件选择activity返回的intent
         * @return 如果返回码代表的是取消或者其他错误,就返回空,否则就返回所选文件的uri数组
         */
        public static Uri[] parseResult(int resultCode, Intent data) {
            return WebViewFactory.getProvider().getStatics().parseFileChooserResult(resultCode, data);
        }

        /**
         * 返回文件选择模式
         */
        public abstract int getMode();

        /**
         * 返回一个可接受(指定)的MIME类型的数组. MIME类型可以部分是例如 audio/* 这样的,如果没有指定的可
         * 接受类型,数据将为空
         */
        public abstract String[] getAcceptTypes();

        /**
         * 返回是不是开启录音或者录制照片,已开启返回true,未开启返回false
         * 使用getAcceptTypes()方法来确定合适的录制设备
         */
        public abstract boolean isCaptureEnabled();

        /**
         * 返回用于此文件选择器的标题或者是null,如果是null则使用默认标题.
         */
        public abstract CharSequence getTitle();

        /**
         * 指定的默认选择的文件名或者null
         */
        public abstract String getFilenameHint();

        /**
         * 创建一个可以启动文件选择器的intent.这个意图支持从设备上可用的简单文件来源上选择文件.一些高级来源可
         * 能不被支持,例如现场媒体录制,希望支持这些源或更高级的文件操作的应用程序应该创建自己的意图.
         *
         * 使用方法:
         * 1. 使用createIntent()建立一个意图
         * 2. 使用Activity.startActivityForResult()发送一个意图
         * 3. 检查ActivityNotFound异常,如果抛出的话采取一种友好的方式
         * 4. 使用anActivityResult()监听结果
         * 5. 如果没有请求媒体录制,使用parseResult()解析结果
         * 6. 用onShowFileChooser()的filePathCallback参数发送结果
         * @return 返回一个支持基本文件选择器来源的intent
         */
        public abstract Intent createIntent();
    }

二、构造方法

WebChromeClient ()

三、public方法


getDefaultVideoPoster API 7

/** 
  * Html中的视频还没开始播放时,video控件会给用户展示一张海报(预览图)。这个图片可以用html中video标签的   
  * poster属性来指定。如果这个属性没有值,会使用默认的海报。此方法允许ChromeClient提供默认图(即使用此方法来返
  * 回一张默认图)。
  * @return Bitmap 默认的图片,如果没有可用的image就返回null
  */
    public Bitmap getDefaultVideoPoster() {
        return null;
    }

getVideoLoadingProgressView API 7

/**
  * 视频缓冲时获取一个视图,宿主程序可以重写此方法来提供一个包含类似转轮的视图
  * @return View 视频加载时要显示的视图
  */
    public View getVideoLoadingProgressView() {
        return null;
    }

getVisitedHistory API 7

/** 
  * 获取一个所有访问记录的list,用于链接着色
  */
    public void getVisitedHistory(ValueCallback<String[]> callback) {
    }

onCloseWindow API 1

/**
  * 通知宿主程序关闭了WebView,如果有必要把WebView从视图系统中移除。在这个时候WebCore已经停止这个窗口所有的
  * 加载并且移除JS中所有交叉脚本的能力
  * @param window 需要被关闭的WebView.
  */
    public void onCloseWindow(WebView window) {}

onConsoleMessage API 8

 /**
  * 向宿主程序通知一个JS控制台消息。ChromeClient应该在合适的地方重写此方法来处理日志信息。
  * @param consoleMessage 包含控制台消息的详细信息的对象
  * @return true 如果消息被ChromeClient处理了就返回true
  */
    public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
        // Call the old version of this function for backwards compatability.
        onConsoleMessage(consoleMessage.message(), consoleMessage.lineNumber(),
                consoleMessage.sourceId());
        return false;
    }

onConsoleMessage API 7

/**
  * 向宿主程序通知一个JS控制台消息。ChromeClient应该在合适的地方重写此方法来处理日志信息。
  * @param message 通知的错误消息.
  * @param lineNumber 发生错误的行号.
  * @param sourceID 导致错误的源文件的名字.
  * @deprecated 在API8的时候被废弃,请使用onConsoleMessage(ConsoleMessage consoleMessage)
  */
    @Deprecated
    public void onConsoleMessage(String message, int lineNumber, String sourceID) { }

onCreateWindow API 1

 /**
  * 请求宿主应用程序创建一个新窗口。如果宿主程序同意,它应该让这个方法返回true,创建一个新的WebView去管理这个
  * 窗口,并把它插入到View系统,同时把提供的resultMsg当做参数发送给这个新的WebView。如果宿主程序选择不同意这
  * 个请求,这个方法要返回false。这个方法的默认实现是什么都不做,返回false。
  * @param view 请求创建新窗口的WebView
  * @param isDialog 新窗口是不是一个Dialog(非全屏)
  * @param isUserGesture 如果这个请求是由用户发起的就返回true,例如点击了一个链接
  * @param resultMsg 新的WebView创建成功后发送的消息。resultMsg.obj是一个{@link 
  * WebView.WebViewTransport}对象。它应该被用来传递给新的WebView,使用方法是调用
  * WebView.WebViewTransport.setWebView(WebView)
  * @return 想要宿主程序创建一个新窗口就返回true,在这种情况下resultMsg应该会被发送给新的WebView。否则就返
  * 回false,但是这个resultMsg依然会用一种未知的行为被发送出去
  */
    public boolean onCreateWindow(WebView view, boolean isDialog,
            boolean isUserGesture, Message resultMsg) {
        return false;
    }

onExceededDatabaseQuota API 5

 /**
    *  通知客户端,针对特定来源的Web SQL数据库
    * API已经超过了限额,并请求一个新的配额. 客户端必须
    * 通过调用
    * WebStorage.QuotaUpdater#updateQuota(long) updateQuota(long)方法
    * 来进行响应,该方法是提供WebStorage.QuotaUpdater的实例. 
    * 前的配额是可以设置为新配额的最小值.
    * 默认使用当前的配额进行响应,因此配额将
    * 不会增加.
    * @param url 触发通知页面的URL
    * @param databaseIdentifier 超过配额的数据库的标识符。
    * @param quota 以字节为单位的原始配额
    * @param estimatedDatabaseSize 预估的数据库大小 以字节为单位
    * @param totalQuota The total quota for all origins, in bytes
    * @param quotaUpdater An instance of {@link WebStorage.QuotaUpdater} which
    *                     must be used to inform the WebView of the new quota.
    * @deprecated This method is no longer called; WebView now uses the HTML5 / JavaScript Quota
    *             Management API.
    */
    @Deprecated
    public void onExceededDatabaseQuota(String url, String databaseIdentifier,
            long quota, long estimatedDatabaseSize, long totalQuota,
            WebStorage.QuotaUpdater quotaUpdater) {
        // This default implementation passes the current quota back to WebCore.
        // WebCore will interpret this that new quota was declined.
        quotaUpdater.updateQuota(quota);
    }

onGeolocationPermissionsHidePrompt API 5

/**
  * Notify the host application that a request for Geolocation permissions,
  * made with a previous call to
  * {@link #onGeolocationPermissionsShowPrompt(String,GeolocationPermissions.Callback) onGeolocationPermissionsShowPrompt()}
  * has been canceled. Any related UI should therefore be hidden.
  */
    public void onGeolocationPermissionsHidePrompt() {}

onGeolocationPermissionsShowPrompt API 5

 /**
  * Notify the host application that web content from the specified origin
  * is attempting to use the Geolocation API, but no permission state is
  * currently set for that origin. The host application should invoke the
  * specified callback with the desired permission state. See
  * {@link GeolocationPermissions} for details.
  *
  * <p>Note that for applications targeting Android N and later SDKs
  * (API level > {@link android.os.Build.VERSION_CODES#M})
  * this method is only called for requests originating from secure
  * origins such as https. On non-secure origins geolocation requests
  * are automatically denied.</p>
  *
  * @param origin The origin of the web content attempting to use the
  *               Geolocation API.
  * @param callback The callback to use to set the permission state for the
  *                 origin.
  */
    public void onGeolocationPermissionsShowPrompt(String origin,
            GeolocationPermissions.Callback callback) {}

onHideCustomView API 7

 /**
  * 通知宿主程序当前的界面已经退出全屏模式。宿主程序必须隐藏自定义视图,(这个视图可以通过onShowCustomView()方
  * 法重新设置为全屏),可可以参考WebView文档的"Full screen support"部分
  */
    public void onHideCustomView() {}

onJsAlert API 1

/**
  * Tell the client to display a javascript alert dialog.  If the client
  * returns true, WebView will assume that the client will handle the
  * dialog.  If the client returns false, it will continue execution.
  * @param view The WebView that initiated the callback.
  * @param url The url of the page requesting the dialog.
  * @param message Message to be displayed in the window.
  * @param result A JsResult to confirm that the user hit enter.
  * @return boolean Whether the client will handle the alert dialog.
  */
    public boolean onJsAlert(WebView view, String url, String message,
            JsResult result) {
        return false;
    }

onJsBeforeUnload API 1

 /**
  * Tell the client to display a dialog to confirm navigation away from the
  * current page. This is the result of the onbeforeunload javascript event.
  * If the client returns true, WebView will assume that the client will
  * handle the confirm dialog and call the appropriate JsResult method. If
  * the client returns false, a default value of true will be returned to
  * javascript to accept navigation away from the current page. The default
  * behavior is to return false. Setting the JsResult to true will navigate
  * away from the current page, false will cancel the navigation.
  * @param view The WebView that initiated the callback.
  * @param url The url of the page requesting the dialog.
  * @param message Message to be displayed in the window.
  * @param result A JsResult used to send the user's response to
  *               javascript.
  * @return boolean Whether the client will handle the confirm dialog.
  */
    public boolean onJsBeforeUnload(WebView view, String url, String message,
            JsResult result) {
        return false;
    }

onJsConfirm API 1

/**
  * Tell the client to display a confirm dialog to the user. If the client
  * returns true, WebView will assume that the client will handle the
  * confirm dialog and call the appropriate JsResult method. If the
  * client returns false, a default value of false will be returned to
  * javascript. The default behavior is to return false.
  * @param view The WebView that initiated the callback.
  * @param url The url of the page requesting the dialog.
  * @param message Message to be displayed in the window.
  * @param result A JsResult used to send the user's response to
  *               javascript.
  * @return boolean Whether the client will handle the confirm dialog.
  */
    public boolean onJsConfirm(WebView view, String url, String message,
            JsResult result) {
        return false;
    }

onJsPrompt API 1

/**
  * Tell the client to display a prompt dialog to the user. If the client
  * returns true, WebView will assume that the client will handle the
  * prompt dialog and call the appropriate JsPromptResult method. If the
  * client returns false, a default value of false will be returned to to
  * javascript. The default behavior is to return false.
  * @param view The WebView that initiated the callback.
  * @param url The url of the page requesting the dialog.
  * @param message Message to be displayed in the window.
  * @param defaultValue The default value displayed in the prompt dialog.
  * @param result A JsPromptResult used to send the user's reponse to
  *               javascript.
  * @return boolean Whether the client will handle the prompt dialog.
  */
    public boolean onJsPrompt(WebView view, String url, String message,
            String defaultValue, JsPromptResult result) {
        return false;
    }

onJsTimeout API 7

/**
  * Tell the client that a JavaScript execution timeout has occured. And the
  * client may decide whether or not to interrupt the execution. If the
  * client returns true, the JavaScript will be interrupted. If the client
  * returns false, the execution will continue. Note that in the case of
  * continuing execution, the timeout counter will be reset, and the callback
  * will continue to occur if the script does not finish at the next check
  * point.
  * @return boolean Whether the JavaScript execution should be interrupted.
  * @deprecated This method is no longer supported and will not be invoked.
  */
    // This method was only called when using the JSC javascript engine. V8 became
    // the default JS engine with Froyo and support for building with JSC was
    // removed in b/5495373. V8 does not have a mechanism for making a callback such
    // as this.
    public boolean onJsTimeout() {
        return true;
    }

onPermissionRequest API 21

/**
  * Notify the host application that web content is requesting permission to
  * access the specified resources and the permission currently isn't granted
  * or denied. The host application must invoke {@link PermissionRequest#grant(String[])}
  * or {@link PermissionRequest#deny()}.
  *
  * If this method isn't overridden, the permission is denied.
  *
  * @param request the PermissionRequest from current web content.
  */
    public void onPermissionRequest(PermissionRequest request) {
        request.deny();
    }

onPermissionRequestCanceled API 21

/**
  * Notify the host application that the given permission request
  * has been canceled. Any related UI should therefore be hidden.
  *
  * @param request the PermissionRequest that needs be canceled.
  */
    public void onPermissionRequestCanceled(PermissionRequest request) {}

onProgressChanged API 1

 /**
  * Tell the host application the current progress of loading a page.
  * @param view The WebView that initiated the callback.
  * @param newProgress Current page loading progress, represented by
  *                    an integer between 0 and 100.
  */
    public void onProgressChanged(WebView view, int newProgress) {}

onReachedMaxAppCacheSize API 7

/**
    * Notify the host application that the Application Cache has reached the
    * maximum size. The client must respond by invoking the
    * {@link WebStorage.QuotaUpdater#updateQuota(long) updateQuota(long)}
    * method of the supplied {@link WebStorage.QuotaUpdater} instance. The
    * minimum value that can be set for the new quota is the current quota. The
    * default implementation responds with the current quota, so the quota will
    * not be increased.
    * @param requiredStorage The amount of storage required by the Application
    *                        Cache operation that triggered this notification,
    *                        in bytes.
    * @param quota the current maximum Application Cache size, in bytes
    * @param quotaUpdater An instance of {@link WebStorage.QuotaUpdater} which
    *                     must be used to inform the WebView of the new quota.
    * @deprecated This method is no longer called; WebView now uses the HTML5 / JavaScript Quota
    *             Management API.
    */
    @Deprecated
    public void onReachedMaxAppCacheSize(long requiredStorage, long quota,
            WebStorage.QuotaUpdater quotaUpdater) {
        quotaUpdater.updateQuota(quota);
    }

onReceivedIcon API 1

/**
  * Notify the host application of a new favicon for the current page.
  * @param view The WebView that initiated the callback.
  * @param icon A Bitmap containing the favicon for the current page.
  */
    public void onReceivedIcon(WebView view, Bitmap icon) {}

onReceivedTitle API 1

/**
  * Notify the host application of a change in the document title.
  * @param view The WebView that initiated the callback.
  * @param title A String containing the new title of the document.
  */
    public void onReceivedTitle(WebView view, String title) {}

onReceivedTouchIconUrl API 7

/**
  * Notify the host application of the url for an apple-touch-icon.
  * @param view The WebView that initiated the callback.
  * @param url The icon url.
  * @param precomposed True if the url is for a precomposed touch icon.
  */
    public void onReceivedTouchIconUrl(WebView view, String url,
            boolean precomposed) {}

onRequestFocus API 1

 /**
  * Request display and focus for this WebView. This may happen due to
  * another WebView opening a link in this WebView and requesting that this
  * WebView be displayed.
  * @param view The WebView that needs to be focused.
  */
    public void onRequestFocus(WebView view) {}

onShowCustomView API 14

/**
  * Notify the host application that the current page would
  * like to show a custom View in a particular orientation.
  * @param view is the View object to be shown.
  * @param requestedOrientation An orientation constant as used in
  * {@link ActivityInfo#screenOrientation ActivityInfo.screenOrientation}.
  * @param callback is the callback to be invoked if and when the view
  * is dismissed.
  * @deprecated This method supports the obsolete plugin mechanism,
  * and will not be invoked in future
  */
    @Deprecated
    public void onShowCustomView(View view, int requestedOrientation,
            CustomViewCallback callback) {};

onShowCustomView API 7

/**
  * Notify the host application that the current page has entered full
  * screen mode. The host application must show the custom View which
  * contains the web contents &mdash; video or other HTML content &mdash;
  * in full screen mode. Also see "Full screen support" documentation on
  * {@link WebView}.
  * @param view is the View object to be shown.
  * @param callback invoke this callback to request the page to exit
  * full screen mode.
  */
    public void onShowCustomView(View view, CustomViewCallback callback) {};

onShowFileChooser API 21

/**
  * Tell the client to show a file chooser.
  *
  * This is called to handle HTML forms with 'file' input type, in response to the
  * user pressing the "Select File" button.
  * To cancel the request, call <code>filePathCallback.onReceiveValue(null)</code> and
  * return true.
  *
  * @param webView The WebView instance that is initiating the request.
  * @param filePathCallback Invoke this callback to supply the list of paths to files to upload,
  *                         or NULL to cancel. Must only be called if the
  *                         <code>showFileChooser</code> implementations returns true.
  * @param fileChooserParams Describes the mode of file chooser to be opened, and options to be
  *                          used with it.
  * @return true if filePathCallback will be invoked, false to use default handling.
  *
  * @see FileChooserParams
  */
    public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback,
            FileChooserParams fileChooserParams) {
        return false;
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值