FileDocCategorySizeDatePackage
JWebCoreJavaBridge.javaAPI DocAndroid 1.5 API6142Wed May 06 22:41:56 BST 2009android.webkit

JWebCoreJavaBridge

public final class JWebCoreJavaBridge extends android.os.Handler

Fields Summary
private static final int
TIMER_MESSAGE
private static final int
FUNCPTR_MESSAGE
private static final String
LOGTAG
private int
mNativeBridge
private boolean
mHasInstantTimer
private int
mPauseTimerRefCount
Constructors Summary
public JWebCoreJavaBridge()
Construct a new JWebCoreJavaBridge to interface with WebCore timers and cookies.


                    
      
        nativeConstructor();
    
Methods Summary
private java.lang.Stringcookies(java.lang.String url)
Retrieve the cookie string for the given url.

param
url The resource's url.
return
A String representing the cookies for the given resource url.

        return CookieManager.getInstance().getCookie(url);
    
private booleancookiesEnabled()
Returns whether cookies are enabled or not.

        return CookieManager.getInstance().acceptCookie();
    
protected voidfinalize()

        nativeFinalize();
    
public voidhandleMessage(android.os.Message msg)
handleMessage

param
msg The dispatched message. The only accepted message currently is TIMER_MESSAGE

        switch (msg.what) {
            case TIMER_MESSAGE: {
                PerfChecker checker = new PerfChecker();
                // clear the flag so that sharedTimerFired() can set a new timer
                mHasInstantTimer = false;
                sharedTimerFired();
                checker.responseAlert("sharedTimer");
                break;
            }
            case FUNCPTR_MESSAGE:
                nativeServiceFuncPtrQueue();
                break;
        }
    
private native voidnativeConstructor()

private native voidnativeFinalize()

private native voidnativeServiceFuncPtrQueue()

public voidpause()
Pause all timers.

        if (--mPauseTimerRefCount == 0) {
            setDeferringTimers(true);
        }
    
public voidresume()
Resume all timers.

        if (++mPauseTimerRefCount == 1) {
            setDeferringTimers(false);
        }
    
public native voidsetCacheSize(int bytes)
Set WebCore cache size.

param
bytes The cache size in bytes.

private voidsetCookies(java.lang.String url, java.lang.String docUrl, java.lang.String value)
Store a cookie string associated with a url.

param
url The url to be used as a key for the cookie.
param
docUrl The policy base url used by WebCore.
param
value The cookie string to be stored.

        if (value.contains("\r") || value.contains("\n")) {
            // for security reason, filter out '\r' and '\n' from the cookie
            int size = value.length();
            StringBuilder buffer = new StringBuilder(size);
            int i = 0;
            while (i != -1 && i < size) {
                int ir = value.indexOf('\r", i);
                int in = value.indexOf('\n", i);
                int newi = (ir == -1) ? in : (in == -1 ? ir : (ir < in ? ir
                        : in));
                if (newi > i) {
                    buffer.append(value.subSequence(i, newi));
                } else if (newi == -1) {
                    buffer.append(value.subSequence(i, size));
                    break;
                }
                i = newi + 1;
            }
            value = buffer.toString();
        }
        CookieManager.getInstance().setCookie(url, value);
    
private native voidsetDeferringTimers(boolean defer)

public native voidsetNetworkOnLine(boolean online)

private voidsetSharedTimer(long timemillis)
setSharedTimer

param
timemillis The relative time when the timer should fire

        if (Config.LOGV) Log.v(LOGTAG, "setSharedTimer " + timemillis);

        if (timemillis <= 0) {
            // we don't accumulate the sharedTimer unless it is a delayed
            // request. This way we won't flood the message queue with
            // WebKit messages. This should improve the browser's
            // responsiveness to key events.
            if (mHasInstantTimer) {
                return;
            } else {
                mHasInstantTimer = true;
                Message msg = obtainMessage(TIMER_MESSAGE);
                sendMessageDelayed(msg, timemillis);
            }
        } else {
            Message msg = obtainMessage(TIMER_MESSAGE);
            sendMessageDelayed(msg, timemillis);
        }
    
private native voidsharedTimerFired()

private voidsignalServiceFuncPtrQueue()

        Message msg = obtainMessage(FUNCPTR_MESSAGE);
        sendMessage(msg);
    
private voidstopSharedTimer()
Stop the shared timer.

        if (Config.LOGV) {
            Log.v(LOGTAG, "stopSharedTimer removing all timers");
        }
        removeMessages(TIMER_MESSAGE);
        mHasInstantTimer = false;