FileDocCategorySizeDatePackage
HttpAuthHandler.javaAPI DocAndroid 1.5 API4722Wed May 06 22:41:56 BST 2009android.webkit

HttpAuthHandler

public class HttpAuthHandler extends android.os.Handler
HTTP authentication handler: local handler that takes care of HTTP authentication requests. This class is passed as a parameter to BrowserCallback.displayHttpAuthDialog and is meant to receive the user's response.

Fields Summary
private static final String
LOGTAG
private Network
mNetwork
Network.
private LinkedList
mLoaderQueue
Loader queue.
private final int
AUTH_PROCEED
private final int
AUTH_CANCEL
Constructors Summary
HttpAuthHandler(Network network)
Creates a new HTTP authentication handler with an empty loader queue

param
network The parent network object


                          
    /* package */   
        mNetwork = network;
        mLoaderQueue = new LinkedList<LoadListener>();
    
Methods Summary
public voidcancel()
Cancel the authorization request

        sendMessage(obtainMessage(AUTH_CANCEL));
    
voidhandleAuthRequest(LoadListener loader)
Enqueues the loader, if the loader is the only element in the queue, starts processing the loader

param
loader The loader that resulted in this http authentication request

        boolean processNext = false;

        synchronized (mLoaderQueue) {
            mLoaderQueue.offer(loader);
            processNext =
                (mLoaderQueue.size() == 1);
        }

        if (processNext) {
            processNextLoader();
        }
    
public voidhandleMessage(android.os.Message msg)

        LoadListener loader = null;
        synchronized (mLoaderQueue) {
            loader = mLoaderQueue.poll();
        }

        switch (msg.what) {
            case AUTH_PROCEED:
                String username = msg.getData().getString("username");
                String password = msg.getData().getString("password");

                loader.handleAuthResponse(username, password);
                break;

            case AUTH_CANCEL:
                loader.handleAuthResponse(null, null);
                break;
        }

        processNextLoader();
    
public voidproceed(java.lang.String username, java.lang.String password)
Proceed with the authorization with the given credentials

param
username The username to use for authentication
param
password The password to use for authentication

        Message msg = obtainMessage(AUTH_PROCEED);
        msg.getData().putString("username", username);
        msg.getData().putString("password", password);
        sendMessage(msg);
    
private voidprocessNextLoader()
Process the next loader in the queue (helper method)

        LoadListener loader = null;
        synchronized (mLoaderQueue) {
            loader = mLoaderQueue.peek();
        }
        if (loader != null) {
            CallbackProxy proxy = loader.getFrame().getCallbackProxy();

            String hostname = loader.proxyAuthenticate() ?
                mNetwork.getProxyHostname() : loader.host();

            String realm = loader.realm();

            proxy.onReceivedHttpAuthRequest(this, hostname, realm);
        }
    
public booleanuseHttpAuthUsernamePassword()

return
True if we can use user credentials on record (ie, if we did not fail trying to use them last time)

        LoadListener loader = null;
        synchronized (mLoaderQueue) {
            loader = mLoaderQueue.peek();
        }
        if (loader != null) {
            return !loader.authCredentialsInvalid();
        }

        return false;