blob: f6166c58a4c908d6b904befeba75873917b6bb10 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17package android.webkit;
18
Nate Fischer3442c742017-09-08 17:02:00 -070019import android.annotation.Nullable;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020import android.content.Context;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021
Ben Murdoch99c12e82012-04-25 15:00:17 +010022/**
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 Block32fe4102012-07-17 16:29:11 +010027 * <li>Username/password pairs for web forms</li>
Ben Murdoch99c12e82012-04-25 15:00:17 +010028 * <li>HTTP authentication username/password pairs</li>
29 * <li>Data entered into text fields (e.g. for autocomplete suggestions)</li>
30 * </ul>
31 */
Ignacio Solla451e3382014-11-10 10:35:54 +000032public abstract class WebViewDatabase {
Kristian Monsenf4912582012-08-16 15:26:24 -040033 /**
34 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
35 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036 protected static final String LOGTAG = "webviewdatabase";
37
John Reck9f9d3452012-09-20 13:18:59 -070038 public static WebViewDatabase getInstance(Context context) {
Ben Murdoch99c12e82012-04-25 15:00:17 +010039 return WebViewFactory.getProvider().getWebViewDatabase(context);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040 }
41
42 /**
Steve Block32fe4102012-07-17 16:29:11 +010043 * 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 Project9066cfe2009-03-03 19:31:44 -080045 *
Nate Fischer0a6140d2017-09-05 12:37:49 -070046 * @return {@code true} if there are any saved username/password pairs
Steve Block32fe4102012-07-17 16:29:11 +010047 * @see WebView#savePassword
Hui Shu433fb932016-08-29 11:49:46 -070048 * @see #clearUsernamePassword
Ben Murdoch924ac512013-04-11 13:51:59 +010049 * @deprecated Saving passwords in WebView will not be supported in future versions.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050 */
Ben Murdoch924ac512013-04-11 13:51:59 +010051 @Deprecated
Ignacio Solla451e3382014-11-10 10:35:54 +000052 public abstract boolean hasUsernamePassword();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053
54 /**
Steve Block32fe4102012-07-17 16:29:11 +010055 * 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 Dixon7c282192012-11-30 15:53:28 -080059 * @see #hasUsernamePassword
Ben Murdoch924ac512013-04-11 13:51:59 +010060 * @deprecated Saving passwords in WebView will not be supported in future versions.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061 */
Ben Murdoch924ac512013-04-11 13:51:59 +010062 @Deprecated
Ignacio Solla451e3382014-11-10 10:35:54 +000063 public abstract void clearUsernamePassword();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064
65 /**
Steve Block46ce1db2012-07-17 16:43:00 +010066 * Gets whether there are any saved credentials for HTTP authentication.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067 *
Steve Block46ce1db2012-07-17 16:43:00 +010068 * @return whether there are any saved credentials
Nate Fischerc7edfb02016-09-23 15:59:21 -070069 * @see #getHttpAuthUsernamePassword
70 * @see #setHttpAuthUsernamePassword
Jonathan Dixon7c282192012-11-30 15:53:28 -080071 * @see #clearHttpAuthUsernamePassword
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072 */
Ignacio Solla451e3382014-11-10 10:35:54 +000073 public abstract boolean hasHttpAuthUsernamePassword();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074
75 /**
Hui Shu433fb932016-08-29 11:49:46 -070076 * 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 Block46ce1db2012-07-17 16:43:00 +010086 *
Nate Fischerc7edfb02016-09-23 15:59:21 -070087 * @see #getHttpAuthUsernamePassword
88 * @see #setHttpAuthUsernamePassword
Jonathan Dixon7c282192012-11-30 15:53:28 -080089 * @see #hasHttpAuthUsernamePassword
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090 */
Ignacio Solla451e3382014-11-10 10:35:54 +000091 public abstract void clearHttpAuthUsernamePassword();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092
93 /**
Nate Fischerc7edfb02016-09-23 15:59:21 -070094 * 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 Fischer0a6140d2017-09-05 12:37:49 -0700133 * is the username and the second element is the password. {@code null} if
Nate Fischerc7edfb02016-09-23 15:59:21 -0700134 * no credentials are found.
135 * @see #setHttpAuthUsernamePassword
136 * @see #hasHttpAuthUsernamePassword
137 * @see #clearHttpAuthUsernamePassword
138 */
Nate Fischer3442c742017-09-08 17:02:00 -0700139 @Nullable
Nate Fischerc7edfb02016-09-23 15:59:21 -0700140 public abstract String[] getHttpAuthUsernamePassword(String host, String realm);
141
142 /**
Steve Block219dfa42012-07-20 10:31:21 +0100143 * Gets whether there is any saved data for web forms.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144 *
Steve Block219dfa42012-07-20 10:31:21 +0100145 * @return whether there is any saved data for web forms
Jonathan Dixon7c282192012-11-30 15:53:28 -0800146 * @see #clearFormData
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147 */
Selim Gurun13e5b0b2017-04-03 14:29:14 -0700148 @Deprecated
Ignacio Solla451e3382014-11-10 10:35:54 +0000149 public abstract boolean hasFormData();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150
151 /**
Steve Block219dfa42012-07-20 10:31:21 +0100152 * Clears any saved data for web forms.
153 *
Jonathan Dixon7c282192012-11-30 15:53:28 -0800154 * @see #hasFormData
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155 */
Selim Gurun13e5b0b2017-04-03 14:29:14 -0700156 @Deprecated
Ignacio Solla451e3382014-11-10 10:35:54 +0000157 public abstract void clearFormData();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158}