Home | History | Annotate | Download | only in browser
      1 /*
      2  * Copyright (C) 2010 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 com.android.browser;
     18 
     19 import android.graphics.Bitmap;
     20 import android.net.Uri;
     21 import android.os.Message;
     22 import android.view.View;
     23 import android.webkit.ConsoleMessage;
     24 import android.webkit.GeolocationPermissions;
     25 import android.webkit.JsPromptResult;
     26 import android.webkit.JsResult;
     27 import android.webkit.ValueCallback;
     28 import android.webkit.WebChromeClient;
     29 import android.webkit.WebStorage;
     30 import android.webkit.WebView;
     31 
     32 /**
     33  *
     34  * WebChromeClient for browser tests.
     35  * Wraps around existing client so that specific methods can be overridden if needed.
     36  *
     37  */
     38 abstract class TestWebChromeClient extends WebChromeClient {
     39 
     40     private WebChromeClient mWrappedClient;
     41 
     42     protected TestWebChromeClient(WebChromeClient wrappedClient) {
     43         mWrappedClient = wrappedClient;
     44     }
     45 
     46     /** {@inheritDoc} */
     47     @Override
     48     public void onProgressChanged(WebView view, int newProgress) {
     49         mWrappedClient.onProgressChanged(view, newProgress);
     50     }
     51 
     52     /** {@inheritDoc} */
     53     @Override
     54     public void onReceivedTitle(WebView view, String title) {
     55         mWrappedClient.onReceivedTitle(view, title);
     56     }
     57 
     58     /** {@inheritDoc} */
     59     @Override
     60     public void onReceivedIcon(WebView view, Bitmap icon) {
     61         mWrappedClient.onReceivedIcon(view, icon);
     62     }
     63 
     64     /** {@inheritDoc} */
     65     @Override
     66     public void onReceivedTouchIconUrl(WebView view, String url,
     67             boolean precomposed) {
     68         mWrappedClient.onReceivedTouchIconUrl(view, url, precomposed);
     69     }
     70 
     71     /** {@inheritDoc} */
     72     @Override
     73     public void onShowCustomView(View view, CustomViewCallback callback) {
     74         mWrappedClient.onShowCustomView(view, callback);
     75     }
     76 
     77     /** {@inheritDoc} */
     78     @Override
     79     public void onHideCustomView() {
     80         mWrappedClient.onHideCustomView();
     81     }
     82 
     83     /** {@inheritDoc} */
     84     @Override
     85     public boolean onCreateWindow(WebView view, boolean dialog,
     86             boolean userGesture, Message resultMsg) {
     87         // do not open any new pop-ups
     88         resultMsg.sendToTarget();
     89         return true;
     90     }
     91 
     92     /** {@inheritDoc} */
     93     @Override
     94     public void onRequestFocus(WebView view) {
     95         mWrappedClient.onRequestFocus(view);
     96     }
     97 
     98     /** {@inheritDoc} */
     99     @Override
    100     public void onCloseWindow(WebView window) {
    101         mWrappedClient.onCloseWindow(window);
    102     }
    103 
    104     /** {@inheritDoc} */
    105     @Override
    106     public boolean onJsAlert(WebView view, String url, String message,
    107             JsResult result) {
    108         return mWrappedClient.onJsAlert(view, url, message, result);
    109     }
    110 
    111     /** {@inheritDoc} */
    112     @Override
    113     public boolean onJsConfirm(WebView view, String url, String message,
    114             JsResult result) {
    115         return mWrappedClient.onJsConfirm(view, url, message, result);
    116     }
    117 
    118     /** {@inheritDoc} */
    119     @Override
    120     public boolean onJsPrompt(WebView view, String url, String message,
    121             String defaultValue, JsPromptResult result) {
    122         return mWrappedClient.onJsPrompt(view, url, message, defaultValue, result);
    123     }
    124 
    125     /** {@inheritDoc} */
    126     @Override
    127     public boolean onJsBeforeUnload(WebView view, String url, String message,
    128             JsResult result) {
    129         return mWrappedClient.onJsBeforeUnload(view, url, message, result);
    130     }
    131 
    132     /** {@inheritDoc} */
    133     @Override
    134     public void onExceededDatabaseQuota(String url, String databaseIdentifier,
    135             long currentQuota, long estimatedSize, long totalUsedQuota,
    136             WebStorage.QuotaUpdater quotaUpdater) {
    137         mWrappedClient.onExceededDatabaseQuota(url, databaseIdentifier, currentQuota,
    138                 estimatedSize, totalUsedQuota, quotaUpdater);
    139     }
    140 
    141     /** {@inheritDoc} */
    142     @Override
    143     public void onReachedMaxAppCacheSize(long spaceNeeded, long totalUsedQuota,
    144             WebStorage.QuotaUpdater quotaUpdater) {
    145         mWrappedClient.onReachedMaxAppCacheSize(spaceNeeded, totalUsedQuota, quotaUpdater);
    146     }
    147 
    148     /** {@inheritDoc} */
    149     @Override
    150     public void onGeolocationPermissionsShowPrompt(String origin,
    151             GeolocationPermissions.Callback callback) {
    152         mWrappedClient.onGeolocationPermissionsShowPrompt(origin, callback);
    153     }
    154 
    155     /** {@inheritDoc} */
    156     @Override
    157     public void onGeolocationPermissionsHidePrompt() {
    158         mWrappedClient.onGeolocationPermissionsHidePrompt();
    159     }
    160 
    161     /** {@inheritDoc} */
    162     @Override
    163     public boolean onJsTimeout() {
    164         return mWrappedClient.onJsTimeout();
    165     }
    166 
    167     /** {@inheritDoc} */
    168     @Override
    169     @Deprecated
    170     public void onConsoleMessage(String message, int lineNumber, String sourceID) {
    171         mWrappedClient.onConsoleMessage(message, lineNumber, sourceID);
    172     }
    173 
    174     /** {@inheritDoc} */
    175     @Override
    176     public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
    177         return mWrappedClient.onConsoleMessage(consoleMessage);
    178     }
    179 
    180     /** {@inheritDoc} */
    181     @Override
    182     public Bitmap getDefaultVideoPoster() {
    183         return mWrappedClient.getDefaultVideoPoster();
    184     }
    185 
    186     /** {@inheritDoc} */
    187     @Override
    188     public View getVideoLoadingProgressView() {
    189         return mWrappedClient.getVideoLoadingProgressView();
    190     }
    191 
    192     /** {@inheritDoc} */
    193     @Override
    194     public void getVisitedHistory(ValueCallback<String[]> callback) {
    195         mWrappedClient.getVisitedHistory(callback);
    196     }
    197 
    198     /** {@inheritDoc} */
    199     @Override
    200     public void openFileChooser(ValueCallback<Uri> uploadFile, String acceptType, String capture) {
    201         mWrappedClient.openFileChooser(uploadFile, acceptType, capture);
    202     }
    203 }
    204