The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
Nate Fischer | 3442c74 | 2017-09-08 17:02:00 -0700 | [diff] [blame] | 19 | import android.annotation.Nullable; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | import android.content.Context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | |
Ben Murdoch | 99c12e8 | 2012-04-25 15:00:17 +0100 | [diff] [blame] | 22 | /** |
| 23 | * This class allows developers to determine whether any WebView used in the |
| 24 | * application has stored any of the following types of browsing data and |
| 25 | * to clear any such stored data for all WebViews in the application. |
| 26 | * <ul> |
Steve Block | 32fe410 | 2012-07-17 16:29:11 +0100 | [diff] [blame] | 27 | * <li>Username/password pairs for web forms</li> |
Ben Murdoch | 99c12e8 | 2012-04-25 15:00:17 +0100 | [diff] [blame] | 28 | * <li>HTTP authentication username/password pairs</li> |
| 29 | * <li>Data entered into text fields (e.g. for autocomplete suggestions)</li> |
| 30 | * </ul> |
| 31 | */ |
Ignacio Solla | 451e338 | 2014-11-10 10:35:54 +0000 | [diff] [blame] | 32 | public abstract class WebViewDatabase { |
Kristian Monsen | f491258 | 2012-08-16 15:26:24 -0400 | [diff] [blame] | 33 | /** |
| 34 | * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} |
| 35 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | protected static final String LOGTAG = "webviewdatabase"; |
| 37 | |
John Reck | 9f9d345 | 2012-09-20 13:18:59 -0700 | [diff] [blame] | 38 | public static WebViewDatabase getInstance(Context context) { |
Ben Murdoch | 99c12e8 | 2012-04-25 15:00:17 +0100 | [diff] [blame] | 39 | return WebViewFactory.getProvider().getWebViewDatabase(context); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | /** |
Steve Block | 32fe410 | 2012-07-17 16:29:11 +0100 | [diff] [blame] | 43 | * Gets whether there are any saved username/password pairs for web forms. |
| 44 | * Note that these are unrelated to HTTP authentication credentials. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | * |
Nate Fischer | 0a6140d | 2017-09-05 12:37:49 -0700 | [diff] [blame] | 46 | * @return {@code true} if there are any saved username/password pairs |
Steve Block | 32fe410 | 2012-07-17 16:29:11 +0100 | [diff] [blame] | 47 | * @see WebView#savePassword |
Hui Shu | 433fb93 | 2016-08-29 11:49:46 -0700 | [diff] [blame] | 48 | * @see #clearUsernamePassword |
Ben Murdoch | 924ac51 | 2013-04-11 13:51:59 +0100 | [diff] [blame] | 49 | * @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] | 50 | */ |
Ben Murdoch | 924ac51 | 2013-04-11 13:51:59 +0100 | [diff] [blame] | 51 | @Deprecated |
Ignacio Solla | 451e338 | 2014-11-10 10:35:54 +0000 | [diff] [blame] | 52 | public abstract boolean hasUsernamePassword(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | |
| 54 | /** |
Steve Block | 32fe410 | 2012-07-17 16:29:11 +0100 | [diff] [blame] | 55 | * Clears any saved username/password pairs for web forms. |
| 56 | * Note that these are unrelated to HTTP authentication credentials. |
| 57 | * |
| 58 | * @see WebView#savePassword |
Jonathan Dixon | 7c28219 | 2012-11-30 15:53:28 -0800 | [diff] [blame] | 59 | * @see #hasUsernamePassword |
Ben Murdoch | 924ac51 | 2013-04-11 13:51:59 +0100 | [diff] [blame] | 60 | * @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] | 61 | */ |
Ben Murdoch | 924ac51 | 2013-04-11 13:51:59 +0100 | [diff] [blame] | 62 | @Deprecated |
Ignacio Solla | 451e338 | 2014-11-10 10:35:54 +0000 | [diff] [blame] | 63 | public abstract void clearUsernamePassword(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | |
| 65 | /** |
Steve Block | 46ce1db | 2012-07-17 16:43:00 +0100 | [diff] [blame] | 66 | * Gets whether there are any saved credentials for HTTP authentication. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | * |
Steve Block | 46ce1db | 2012-07-17 16:43:00 +0100 | [diff] [blame] | 68 | * @return whether there are any saved credentials |
Nate Fischer | c7edfb0 | 2016-09-23 15:59:21 -0700 | [diff] [blame] | 69 | * @see #getHttpAuthUsernamePassword |
| 70 | * @see #setHttpAuthUsernamePassword |
Jonathan Dixon | 7c28219 | 2012-11-30 15:53:28 -0800 | [diff] [blame] | 71 | * @see #clearHttpAuthUsernamePassword |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | */ |
Ignacio Solla | 451e338 | 2014-11-10 10:35:54 +0000 | [diff] [blame] | 73 | public abstract boolean hasHttpAuthUsernamePassword(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | |
| 75 | /** |
Hui Shu | 433fb93 | 2016-08-29 11:49:46 -0700 | [diff] [blame] | 76 | * Clears any saved credentials for HTTP authentication. This method only clears the username |
| 77 | * and password stored in WebViewDatabase instance. The username and password are not read from |
| 78 | * the {@link WebViewDatabase} during {@link WebViewClient#onReceivedHttpAuthRequest}. It is up |
| 79 | * to the app to do this or not. |
| 80 | * <p> |
| 81 | * The username and password used for http authentication might be cached in the network stack |
| 82 | * itself, and are not cleared when this method is called. WebView does not provide a special |
| 83 | * mechanism to clear HTTP authentication for implementing client logout. The client logout |
| 84 | * mechanism should be implemented by the Web site designer (such as server sending a HTTP 401 |
| 85 | * for invalidating credentials). |
Steve Block | 46ce1db | 2012-07-17 16:43:00 +0100 | [diff] [blame] | 86 | * |
Nate Fischer | c7edfb0 | 2016-09-23 15:59:21 -0700 | [diff] [blame] | 87 | * @see #getHttpAuthUsernamePassword |
| 88 | * @see #setHttpAuthUsernamePassword |
Jonathan Dixon | 7c28219 | 2012-11-30 15:53:28 -0800 | [diff] [blame] | 89 | * @see #hasHttpAuthUsernamePassword |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | */ |
Ignacio Solla | 451e338 | 2014-11-10 10:35:54 +0000 | [diff] [blame] | 91 | public abstract void clearHttpAuthUsernamePassword(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | |
| 93 | /** |
Nate Fischer | c7edfb0 | 2016-09-23 15:59:21 -0700 | [diff] [blame] | 94 | * Stores HTTP authentication credentials for a given host and realm to the {@link WebViewDatabase} |
| 95 | * instance. |
| 96 | * <p> |
| 97 | * To use HTTP authentication, the embedder application has to implement |
| 98 | * {@link WebViewClient#onReceivedHttpAuthRequest}, and call {@link HttpAuthHandler#proceed} |
| 99 | * with the correct username and password. |
| 100 | * <p> |
| 101 | * The embedder app can get the username and password any way it chooses, and does not have to |
| 102 | * use {@link WebViewDatabase}. |
| 103 | * <p> |
| 104 | * Notes: |
| 105 | * <li> |
| 106 | * {@link WebViewDatabase} is provided only as a convenience to store and retrieve http |
| 107 | * authentication credentials. WebView does not read from it during HTTP authentication. |
| 108 | * </li> |
| 109 | * <li> |
| 110 | * WebView does not provide a special mechanism to clear HTTP authentication credentials for |
| 111 | * implementing client logout. The client logout mechanism should be implemented by the Web site |
| 112 | * designer (such as server sending a HTTP 401 for invalidating credentials). |
| 113 | * </li> |
| 114 | * |
| 115 | * @param host the host to which the credentials apply |
| 116 | * @param realm the realm to which the credentials apply |
| 117 | * @param username the username |
| 118 | * @param password the password |
| 119 | * @see #getHttpAuthUsernamePassword |
| 120 | * @see #hasHttpAuthUsernamePassword |
| 121 | * @see #clearHttpAuthUsernamePassword |
| 122 | */ |
| 123 | public abstract void setHttpAuthUsernamePassword(String host, String realm, |
| 124 | String username, String password); |
| 125 | |
| 126 | /** |
| 127 | * Retrieves HTTP authentication credentials for a given host and realm from the {@link |
| 128 | * WebViewDatabase} instance. |
| 129 | * |
| 130 | * @param host the host to which the credentials apply |
| 131 | * @param realm the realm to which the credentials apply |
| 132 | * @return the credentials as a String array, if found. The first element |
Nate Fischer | 0a6140d | 2017-09-05 12:37:49 -0700 | [diff] [blame] | 133 | * is the username and the second element is the password. {@code null} if |
Nate Fischer | c7edfb0 | 2016-09-23 15:59:21 -0700 | [diff] [blame] | 134 | * no credentials are found. |
| 135 | * @see #setHttpAuthUsernamePassword |
| 136 | * @see #hasHttpAuthUsernamePassword |
| 137 | * @see #clearHttpAuthUsernamePassword |
| 138 | */ |
Nate Fischer | 3442c74 | 2017-09-08 17:02:00 -0700 | [diff] [blame] | 139 | @Nullable |
Nate Fischer | c7edfb0 | 2016-09-23 15:59:21 -0700 | [diff] [blame] | 140 | public abstract String[] getHttpAuthUsernamePassword(String host, String realm); |
| 141 | |
| 142 | /** |
Steve Block | 219dfa4 | 2012-07-20 10:31:21 +0100 | [diff] [blame] | 143 | * Gets whether there is any saved data for web forms. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 144 | * |
Steve Block | 219dfa4 | 2012-07-20 10:31:21 +0100 | [diff] [blame] | 145 | * @return whether there is any saved data for web forms |
Jonathan Dixon | 7c28219 | 2012-11-30 15:53:28 -0800 | [diff] [blame] | 146 | * @see #clearFormData |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 147 | */ |
Selim Gurun | 13e5b0b | 2017-04-03 14:29:14 -0700 | [diff] [blame] | 148 | @Deprecated |
Ignacio Solla | 451e338 | 2014-11-10 10:35:54 +0000 | [diff] [blame] | 149 | public abstract boolean hasFormData(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | |
| 151 | /** |
Steve Block | 219dfa4 | 2012-07-20 10:31:21 +0100 | [diff] [blame] | 152 | * Clears any saved data for web forms. |
| 153 | * |
Jonathan Dixon | 7c28219 | 2012-11-30 15:53:28 -0800 | [diff] [blame] | 154 | * @see #hasFormData |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | */ |
Selim Gurun | 13e5b0b | 2017-04-03 14:29:14 -0700 | [diff] [blame] | 156 | @Deprecated |
Ignacio Solla | 451e338 | 2014-11-10 10:35:54 +0000 | [diff] [blame] | 157 | public abstract void clearFormData(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 158 | } |