Home | History | Annotate | Download | only in webkit
      1 /*
      2  * Copyright (C) 2007 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package android.webkit;
     18 
     19 import android.content.Context;
     20 
     21 /**
     22  * This class allows developers to determine whether any WebView used in the
     23  * application has stored any of the following types of browsing data and
     24  * to clear any such stored data for all WebViews in the application.
     25  * <ul>
     26  *  <li>Username/password pairs for web forms</li>
     27  *  <li>HTTP authentication username/password pairs</li>
     28  *  <li>Data entered into text fields (e.g. for autocomplete suggestions)</li>
     29  * </ul>
     30  */
     31 public abstract class WebViewDatabase {
     32     /**
     33      * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
     34      */
     35     protected static final String LOGTAG = "webviewdatabase";
     36 
     37     public static WebViewDatabase getInstance(Context context) {
     38         return WebViewFactory.getProvider().getWebViewDatabase(context);
     39     }
     40 
     41     /**
     42      * Gets whether there are any saved username/password pairs for web forms.
     43      * Note that these are unrelated to HTTP authentication credentials.
     44      *
     45      * @return true if there are any saved username/password pairs
     46      * @see WebView#savePassword
     47      * @see #clearUsernamePassword
     48      * @deprecated Saving passwords in WebView will not be supported in future versions.
     49      */
     50     @Deprecated
     51     public abstract boolean hasUsernamePassword();
     52 
     53     /**
     54      * Clears any saved username/password pairs for web forms.
     55      * Note that these are unrelated to HTTP authentication credentials.
     56      *
     57      * @see WebView#savePassword
     58      * @see #hasUsernamePassword
     59      * @deprecated Saving passwords in WebView will not be supported in future versions.
     60      */
     61     @Deprecated
     62     public abstract void clearUsernamePassword();
     63 
     64     /**
     65      * Gets whether there are any saved credentials for HTTP authentication.
     66      *
     67      * @return whether there are any saved credentials
     68      * @see #getHttpAuthUsernamePassword
     69      * @see #setHttpAuthUsernamePassword
     70      * @see #clearHttpAuthUsernamePassword
     71      */
     72     public abstract boolean hasHttpAuthUsernamePassword();
     73 
     74     /**
     75      * Clears any saved credentials for HTTP authentication. This method only clears the username
     76      * and password stored in WebViewDatabase instance. The username and password are not read from
     77      * the {@link WebViewDatabase} during {@link WebViewClient#onReceivedHttpAuthRequest}. It is up
     78      * to the app to do this or not.
     79      * <p>
     80      * The username and password used for http authentication might be cached in the network stack
     81      * itself, and are not cleared when this method is called.  WebView does not provide a special
     82      * mechanism to clear HTTP authentication for implementing client logout. The client logout
     83      * mechanism should be implemented by the Web site designer (such as server sending a HTTP 401
     84      * for invalidating credentials).
     85      *
     86      * @see #getHttpAuthUsernamePassword
     87      * @see #setHttpAuthUsernamePassword
     88      * @see #hasHttpAuthUsernamePassword
     89      */
     90     public abstract void clearHttpAuthUsernamePassword();
     91 
     92     /**
     93      * Stores HTTP authentication credentials for a given host and realm to the {@link WebViewDatabase}
     94      * instance.
     95      * <p>
     96      * To use HTTP authentication, the embedder application has to implement
     97      * {@link WebViewClient#onReceivedHttpAuthRequest}, and call {@link HttpAuthHandler#proceed}
     98      * with the correct username and password.
     99      * <p>
    100      * The embedder app can get the username and password any way it chooses, and does not have to
    101      * use {@link WebViewDatabase}.
    102      * <p>
    103      * Notes:
    104      * <li>
    105      * {@link WebViewDatabase} is provided only as a convenience to store and retrieve http
    106      * authentication credentials. WebView does not read from it during HTTP authentication.
    107      * </li>
    108      * <li>
    109      * WebView does not provide a special mechanism to clear HTTP authentication credentials for
    110      * implementing client logout. The client logout mechanism should be implemented by the Web site
    111      * designer (such as server sending a HTTP 401 for invalidating credentials).
    112      * </li>
    113      *
    114      * @param host the host to which the credentials apply
    115      * @param realm the realm to which the credentials apply
    116      * @param username the username
    117      * @param password the password
    118      * @see #getHttpAuthUsernamePassword
    119      * @see #hasHttpAuthUsernamePassword
    120      * @see #clearHttpAuthUsernamePassword
    121      */
    122     public abstract void setHttpAuthUsernamePassword(String host, String realm,
    123             String username, String password);
    124 
    125    /**
    126      * Retrieves HTTP authentication credentials for a given host and realm from the {@link
    127      * WebViewDatabase} instance.
    128      *
    129      * @param host the host to which the credentials apply
    130      * @param realm the realm to which the credentials apply
    131      * @return the credentials as a String array, if found. The first element
    132      *         is the username and the second element is the password. Null if
    133      *         no credentials are found.
    134      * @see #setHttpAuthUsernamePassword
    135      * @see #hasHttpAuthUsernamePassword
    136      * @see #clearHttpAuthUsernamePassword
    137      */
    138     public abstract String[] getHttpAuthUsernamePassword(String host, String realm);
    139 
    140     /**
    141      * Gets whether there is any saved data for web forms.
    142      *
    143      * @return whether there is any saved data for web forms
    144      * @see #clearFormData
    145      */
    146     @Deprecated
    147     public abstract boolean hasFormData();
    148 
    149     /**
    150      * Clears any saved data for web forms.
    151      *
    152      * @see #hasFormData
    153      */
    154     @Deprecated
    155     public abstract void clearFormData();
    156 }
    157