FileDocCategorySizeDatePackage
SslErrorHandler.javaAPI DocAndroid 1.5 API6930Wed May 06 22:41:56 BST 2009android.webkit

SslErrorHandler

public class SslErrorHandler extends android.os.Handler
SslErrorHandler: class responsible for handling SSL errors. This class is passed as a parameter to BrowserCallback.displaySslErrorDialog and is meant to receive the user's response.

Fields Summary
private static final String
LOGTAG
private Network
mNetwork
Network.
private LinkedList
mLoaderQueue
Queue of loaders that experience SSL-related problems.
private android.os.Bundle
mSslPrefTable
SSL error preference table.
private final int
HANDLE_RESPONSE
Constructors Summary
SslErrorHandler(Network network)
Creates a new error handler with an empty loader queue.

        mNetwork = network;

        mLoaderQueue = new LinkedList<LoadListener>();
        mSslPrefTable = new Bundle();
    
Methods Summary
public voidcancel()
Cancel this request and all pending requests for the WebView that had the error.

        sendMessage(obtainMessage(HANDLE_RESPONSE, 0, 0));
    
synchronized voidclear()
Clears SSL error preference table.

        mSslPrefTable.clear();
    
voidfastProcessQueuedSslErrors()
Processes queued SSL-error confirmation requests in a tight loop while there is no need to ask the user.

        while (processNextLoader());
    
public voidhandleMessage(android.os.Message msg)


    
        
        switch (msg.what) {
            case HANDLE_RESPONSE:
                handleSslErrorResponse(msg.arg1 == 1);
                fastProcessQueuedSslErrors();
                break;
        }
    
synchronized voidhandleSslErrorRequest(LoadListener loader)
Handles SSL error(s) on the way up to the user.

        if (Config.LOGV) {
            Log.v(LOGTAG, "SslErrorHandler.handleSslErrorRequest(): " +
                  "url=" + loader.url());
        }

        if (!loader.cancelled()) {
            mLoaderQueue.offer(loader);
            if (loader == mLoaderQueue.peek()) {
                fastProcessQueuedSslErrors();
            }
        }
    
synchronized voidhandleSslErrorResponse(boolean proceed)
Handles SSL error(s) on the way down from the user.

        LoadListener loader = mLoaderQueue.poll();
        if (Config.DEBUG) {
            Assert.assertNotNull(loader);
        }

        if (Config.LOGV) {
            Log.v(LOGTAG, "SslErrorHandler.handleSslErrorResponse():"
                  + " proceed: " + proceed
                  + " url:" + loader.url());
        }

        if (!loader.cancelled()) {
            if (proceed) {
                // update the user's SSL error preference table
                int primary = loader.sslError().getPrimaryError();
                String host = loader.host();

                if (Config.DEBUG) {
                    Assert.assertTrue(host != null && primary != 0);
                }
                boolean hasKey = mSslPrefTable.containsKey(host);
                if (!hasKey ||
                    primary > mSslPrefTable.getInt(host)) {
                    mSslPrefTable.putInt(host, new Integer(primary));
                }
            }
            loader.handleSslErrorResponse(proceed);
        }
    
public voidproceed()
Proceed with the SSL certificate.

        sendMessage(obtainMessage(HANDLE_RESPONSE, 1, 0));
    
private synchronized booleanprocessNextLoader()
Processes the next loader in the queue.

return
True iff should proceed to processing the following loader in the queue

        LoadListener loader = mLoaderQueue.peek();
        if (loader != null) {
            // if this loader has been cancelled
            if (loader.cancelled()) {
                // go to the following loader in the queue
                return true;
            }

            SslError error = loader.sslError();

            if (Config.DEBUG) {
                Assert.assertNotNull(error);
            }

            int primary = error.getPrimaryError();
            String host = loader.host();

            if (Config.DEBUG) {
                Assert.assertTrue(host != null && primary != 0);
            }

            if (mSslPrefTable.containsKey(host)) {
                if (primary <= mSslPrefTable.getInt(host)) {
                    handleSslErrorResponse(true);
                    return true;
                }
            }

            // if we do not have information on record, ask
            // the user (display a dialog)
            CallbackProxy proxy = loader.getFrame().getCallbackProxy();
            proxy.onReceivedSslError(this, error);
        }

        // the queue must be empty, stop
        return false;
    
booleanrestoreState(android.os.Bundle inState)
Restores this handler's state from a map.

return
True iff succeeds.

        boolean success = (inState != null);
        if (success) {
            success = inState.containsKey("ssl-error-handler");
            if (success) {
                mSslPrefTable = inState.getBundle("ssl-error-handler");
            }
        }

        return success;
    
booleansaveState(android.os.Bundle outState)
Saves this handler's state into a map.

return
True iff succeeds.

        boolean success = (outState != null);
        if (success) {
            // TODO?
            outState.putBundle("ssl-error-handler", mSslPrefTable);
        }

        return success;