Search in sources :

Example 1 with CacheResult

use of android.webkit.CacheManager.CacheResult in project android_frameworks_base by ParanoidAndroid.

the class HttpHeaderTest method testCacheControlMultipleArguments.

// Test that cache behaves correctly when receiving a compund
// cache-control statement containing no-cache and max-age argument.
//
// If a cache control header contains both a max-age arument and
// a no-cache argument the max-age argument should be ignored.
// The resource can be cached, but a validity check must be done on
// every request. Test case checks that the expiry time is 0 for
// this item, so item will be validated on subsequent requests.
public void testCacheControlMultipleArguments() throws Exception {
    // get private method CacheManager.parseHeaders()
    Method m = CacheManager.class.getDeclaredMethod("parseHeaders", new Class[] { int.class, Headers.class, String.class });
    m.setAccessible(true);
    // create indata
    Headers h = new Headers();
    CharArrayBuffer buffer = new CharArrayBuffer(64);
    buffer.append(CACHE_CONTROL_COMPOUND);
    h.parseHeader(buffer);
    CacheResult c = (CacheResult) m.invoke(null, 200, h, "text/html");
    // Check that expires is set to 0, to ensure that no-cache has overridden
    // the max-age argument
    assertEquals(0, c.getExpires());
    // check reverse order
    buffer.clear();
    buffer.append(CACHE_CONTROL_COMPOUND2);
    h.parseHeader(buffer);
    c = (CacheResult) m.invoke(null, 200, h, "text/html");
    assertEquals(0, c.getExpires());
}
Also used : Headers(android.net.http.Headers) CharArrayBuffer(org.apache.http.util.CharArrayBuffer) CacheResult(android.webkit.CacheManager.CacheResult) Method(java.lang.reflect.Method)

Example 2 with CacheResult

use of android.webkit.CacheManager.CacheResult in project android_frameworks_base by ResurrectionRemix.

the class UrlInterceptRegistry method getSurrogate.

/**
     * Given an url, returns the CacheResult of the first
     * UrlInterceptHandler interested, or null if none are.
     *
     * @return A CacheResult containing surrogate content.
     *
     * @hide
     * @deprecated This class was intended to be used by Gears. Since Gears was
     * deprecated, so is this class.
     */
@Deprecated
public static synchronized CacheResult getSurrogate(String url, Map<String, String> headers) {
    if (urlInterceptDisabled()) {
        return null;
    }
    Iterator iter = getHandlers().listIterator();
    while (iter.hasNext()) {
        UrlInterceptHandler handler = (UrlInterceptHandler) iter.next();
        CacheResult result = handler.service(url, headers);
        if (result != null) {
            return result;
        }
    }
    return null;
}
Also used : UrlInterceptHandler(android.webkit.UrlInterceptHandler) Iterator(java.util.Iterator) CacheResult(android.webkit.CacheManager.CacheResult)

Example 3 with CacheResult

use of android.webkit.CacheManager.CacheResult in project XobotOS by xamarin.

the class LoadListener method checkCache.

/**
     * Check the cache for the current URL, and load it if it is valid.
     *
     * @param headers for the request
     * @return true if cached response is used.
     */
boolean checkCache(Map<String, String> headers) {
    // Get the cache file name for the current URL
    CacheResult result = CacheManager.getCacheFile(url(), mPostIdentifier, headers);
    // Go ahead and set the cache loader to null in case the result is
    // null.
    mCacheLoader = null;
    // reset the flag
    mFromCache = false;
    if (result != null) {
        // The contents of the cache may need to be revalidated so just
        // remember the cache loader in the case that the server responds
        // positively to the cached content. This is also used to detect if
        // a redirect came from the cache.
        mCacheLoader = new CacheLoader(this, result);
        // added, then the cached content valid, we should use it.
        if (!headers.containsKey(CacheManager.HEADER_KEY_IFNONEMATCH) && !headers.containsKey(CacheManager.HEADER_KEY_IFMODIFIEDSINCE)) {
            if (DebugFlags.LOAD_LISTENER) {
                Log.v(LOGTAG, "FrameLoader: HTTP URL in cache " + "and usable: " + url());
            }
            if (isSynchronous()) {
                mCacheLoader.load();
            } else {
                // Load the cached file in a separate thread
                WebViewWorker.getHandler().obtainMessage(WebViewWorker.MSG_ADD_STREAMLOADER, mCacheLoader).sendToTarget();
            }
            mFromCache = true;
            return true;
        }
    }
    return false;
}
Also used : CacheResult(android.webkit.CacheManager.CacheResult)

Example 4 with CacheResult

use of android.webkit.CacheManager.CacheResult in project android_frameworks_base by ParanoidAndroid.

the class UrlInterceptRegistry method getSurrogate.

/**
     * Given an url, returns the CacheResult of the first
     * UrlInterceptHandler interested, or null if none are.
     *
     * @return A CacheResult containing surrogate content.
     *
     * @hide
     * @deprecated This class was intended to be used by Gears. Since Gears was
     * deprecated, so is this class.
     */
@Deprecated
public static synchronized CacheResult getSurrogate(String url, Map<String, String> headers) {
    if (urlInterceptDisabled()) {
        return null;
    }
    Iterator iter = getHandlers().listIterator();
    while (iter.hasNext()) {
        UrlInterceptHandler handler = (UrlInterceptHandler) iter.next();
        CacheResult result = handler.service(url, headers);
        if (result != null) {
            return result;
        }
    }
    return null;
}
Also used : UrlInterceptHandler(android.webkit.UrlInterceptHandler) Iterator(java.util.Iterator) CacheResult(android.webkit.CacheManager.CacheResult)

Example 5 with CacheResult

use of android.webkit.CacheManager.CacheResult in project android_frameworks_base by AOSPA.

the class UrlInterceptRegistry method getSurrogate.

/**
     * Given an url, returns the CacheResult of the first
     * UrlInterceptHandler interested, or null if none are.
     *
     * @return A CacheResult containing surrogate content.
     *
     * @hide
     * @deprecated This class was intended to be used by Gears. Since Gears was
     * deprecated, so is this class.
     */
@Deprecated
public static synchronized CacheResult getSurrogate(String url, Map<String, String> headers) {
    if (urlInterceptDisabled()) {
        return null;
    }
    Iterator iter = getHandlers().listIterator();
    while (iter.hasNext()) {
        UrlInterceptHandler handler = (UrlInterceptHandler) iter.next();
        CacheResult result = handler.service(url, headers);
        if (result != null) {
            return result;
        }
    }
    return null;
}
Also used : UrlInterceptHandler(android.webkit.UrlInterceptHandler) Iterator(java.util.Iterator) CacheResult(android.webkit.CacheManager.CacheResult)

Aggregations

CacheResult (android.webkit.CacheManager.CacheResult)10 UrlInterceptHandler (android.webkit.UrlInterceptHandler)7 Iterator (java.util.Iterator)7 Cursor (android.database.Cursor)1 Headers (android.net.http.Headers)1 Method (java.lang.reflect.Method)1 CharArrayBuffer (org.apache.http.util.CharArrayBuffer)1