Skip to content

Commit 46ce1db

Browse files
Steve BlockAndroid (Google) Code Review
authored andcommitted
Improve JavaDoc for HTTP basic authentication methods
Bug: 5461416 Change-Id: Ie3bfbf6acde34ea184aa8c8b1d3841e2a2aa8a22
1 parent 219dfa4 commit 46ce1db

File tree

4 files changed

+58
-29
lines changed

4 files changed

+58
-29
lines changed

core/java/android/webkit/HttpAuthHandler.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
import android.os.Handler;
2020

2121
/**
22-
* HTTP authentication request that must be handled by the user interface.
23-
* WebView creates the object and hands it to the current {@link WebViewClient},
24-
* which must call either {@link #proceed(String, String)} or {@link #cancel()}.
22+
* Represents a request for HTTP authentication. Instances of this class are
23+
* created by the WebView and passed to
24+
* {@link WebViewClient#onReceivedHttpAuthRequest}. The host application must
25+
* call either {@link #proceed} or {@link #cancel} to set the WebView's
26+
* response to the request.
2527
*/
2628
public class HttpAuthHandler extends Handler {
2729

@@ -32,27 +34,36 @@ public class HttpAuthHandler extends Handler {
3234
}
3335

3436
/**
35-
* @return True if we can use user credentials on record
36-
* (ie, if we did not fail trying to use them last time)
37+
* Gets whether the credentials stored for the current host (i.e. the host
38+
* for which {@link WebViewClient#onReceivedHttpAuthRequest} was called)
39+
* are suitable for use. Credentials are not suitable if they have
40+
* previously been rejected by the server for the current request.
41+
*
42+
* @return whether the credentials are suitable for use
43+
* @see Webview#getHttpAuthUsernamePassword
3744
*/
3845
public boolean useHttpAuthUsernamePassword() {
3946
return false;
4047
}
4148

4249
/**
43-
* Cancel the authorization request.
50+
* Instructs the WebView to cancel the authentication request.
4451
*/
4552
public void cancel() {
4653
}
4754

4855
/**
49-
* Proceed with the authorization with the given credentials.
56+
* Instructs the WebView to proceed with the authentication with the given
57+
* credentials. Credentials for use with this method can be retrieved from
58+
* the WebView's store using {@link WebView#getHttpAuthUsernamePassword}.
5059
*/
5160
public void proceed(String username, String password) {
5261
}
5362

5463
/**
55-
* return true if the prompt dialog should be suppressed.
64+
* Gets whether the prompt dialog should be suppressed.
65+
*
66+
* @return whether the prompt dialog should be suppressed
5667
* @hide
5768
*/
5869
public boolean suppressDialog() {

core/java/android/webkit/WebView.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -599,13 +599,17 @@ public void savePassword(String host, String username, String password) {
599599
}
600600

601601
/**
602-
* Sets the HTTP authentication credentials for a given host and realm.
602+
* Stores HTTP authentication credentials for a given host and realm. This
603+
* method is intended to be used with
604+
* {@link WebViewClient#onReceivedHttpAuthRequest}.
603605
*
604-
* @param host the host for the credentials
605-
* @param realm the realm for the credentials
606-
* @param username the username for the password. If it is null, it means
607-
* password can't be saved.
606+
* @param host the host to which the credentials apply
607+
* @param realm the realm to which the credentials apply
608+
* @param username the username
608609
* @param password the password
610+
* @see getHttpAuthUsernamePassword
611+
* @see WebViewDatabase#hasHttpAuthUsernamePassword
612+
* @see WebViewDatabase#clearHttpAuthUsernamePassword
609613
*/
610614
public void setHttpAuthUsernamePassword(String host, String realm,
611615
String username, String password) {
@@ -614,13 +618,18 @@ public void setHttpAuthUsernamePassword(String host, String realm,
614618
}
615619

616620
/**
617-
* Retrieves the HTTP authentication username and password for a given
618-
* host and realm pair
621+
* Retrieves HTTP authentication credentials for a given host and realm.
622+
* This method is intended to be used with
623+
* {@link WebViewClient#onReceivedHttpAuthRequest}.
619624
*
620-
* @param host the host for which the credentials apply
621-
* @param realm the realm for which the credentials apply
622-
* @return String[] if found. String[0] is username, which can be null and
623-
* String[1] is password. Return null if it can't find anything.
625+
* @param host the host to which the credentials apply
626+
* @param realm the realm to which the credentials apply
627+
* @return the credentials as a String array, if found. The first element
628+
* is the username and the second element is the password. Null if
629+
* no credentials are found.
630+
* @see setHttpAuthUsernamePassword
631+
* @see WebViewDatabase#hasHttpAuthUsernamePassword
632+
* @see WebViewDatabase#clearHttpAuthUsernamePassword
624633
*/
625634
public String[] getHttpAuthUsernamePassword(String host, String realm) {
626635
checkThread();

core/java/android/webkit/WebViewClient.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,16 @@ public void onReceivedSslError(WebView view, SslErrorHandler handler,
204204
}
205205

206206
/**
207-
* Notify the host application to handle an authentication request. The
208-
* default behavior is to cancel the request.
207+
* Notifies the host application that the WebView received an HTTP
208+
* authentication request. The host application can use the supplied
209+
* {@link HttpAuthHandler} to set the WebView's response to the request.
210+
* The default behavior is to cancel the request.
209211
*
210-
* @param view The WebView that is initiating the callback.
211-
* @param handler The HttpAuthHandler that will handle the user's response.
212-
* @param host The host requiring authentication.
213-
* @param realm A description to help store user credentials for future
214-
* visits.
212+
* @param view the WebView that is initiating the callback
213+
* @param handler the HttpAuthHandler used to set the WebView's response
214+
* @param host the host requiring authentication
215+
* @param realm the realm for which authentication is required
216+
* @see Webview#getHttpAuthUsernamePassword
215217
*/
216218
public void onReceivedHttpAuthRequest(WebView view,
217219
HttpAuthHandler handler, String host, String realm) {

core/java/android/webkit/WebViewDatabase.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,23 @@ public void clearUsernamePassword() {
6666
}
6767

6868
/**
69-
* Gets whether there are any HTTP authentication username/password combinations saved.
69+
* Gets whether there are any saved credentials for HTTP authentication.
7070
*
71-
* @return true if there are any HTTP authentication username/passwords saved
71+
* @return whether there are any saved credentials
72+
* @see Webview#getHttpAuthUsernamePassword
73+
* @see Webview#setHttpAuthUsernamePassword
74+
* @see clearHttpAuthUsernamePassword
7275
*/
7376
public boolean hasHttpAuthUsernamePassword() {
7477
throw new MustOverrideException();
7578
}
7679

7780
/**
78-
* Clears any HTTP authentication username/passwords that are saved.
81+
* Clears any saved credentials for HTTP authentication.
82+
*
83+
* @see Webview#getHttpAuthUsernamePassword
84+
* @see Webview#setHttpAuthUsernamePassword
85+
* @see hasHttpAuthUsernamePassword
7986
*/
8087
public void clearHttpAuthUsernamePassword() {
8188
throw new MustOverrideException();

0 commit comments

Comments
 (0)