Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e64c5567 authored by Grace Kloba's avatar Grace Kloba
Browse files

Fix for the new webkit. Now "expires" takes the string instead of int.

We have to upadte our cache database. Good thing is Gears can avoid the expensive date conversion.
parent 7822de55
Loading
Loading
Loading
Loading
+11 −5
Original line number Diff line number Diff line
@@ -79,6 +79,7 @@ public final class CacheManager {
        int httpStatusCode;
        long contentLength;
        long expires;
        String expiresString;
        String localPath;
        String lastModified;
        String etag;
@@ -107,6 +108,10 @@ public final class CacheManager {
            return expires;
        }

        public String getExpiresString() {
            return expiresString;
        }

        public String getLastModified() {
            return lastModified;
        }
@@ -603,17 +608,18 @@ public final class CacheManager {
        if (location != null) ret.location = location;

        ret.expires = -1;
        String expires = headers.getExpires();
        if (expires != null) {
        ret.expiresString = headers.getExpires();
        if (ret.expiresString != null) {
            try {
                ret.expires = HttpDateTime.parse(expires);
                ret.expires = HttpDateTime.parse(ret.expiresString);
            } catch (IllegalArgumentException ex) {
                // Take care of the special "-1" and "0" cases
                if ("-1".equals(expires) || "0".equals(expires)) {
                if ("-1".equals(ret.expiresString)
                        || "0".equals(ret.expiresString)) {
                    // make it expired, but can be used for history navigation
                    ret.expires = 0;
                } else {
                    Log.e(LOGTAG, "illegal expires: " + expires);
                    Log.e(LOGTAG, "illegal expires: " + ret.expiresString);
                }
            }
        }
+3 −3
Original line number Diff line number Diff line
@@ -949,7 +949,7 @@ class LoadListener extends Handler implements EventHandler {
        final int nativeResponse = nativeCreateResponse(
                mUrl, statusCode, mStatusText,
                mMimeType, mContentLength, mEncoding,
                mCacheResult == null ? 0 : mCacheResult.expires / 1000);
                mCacheResult == null ? null : mCacheResult.expiresString);
        if (mHeaders != null) {
            mHeaders.getHeaders(new Headers.HeaderCallback() {
                    public void header(String name, String value) {
@@ -1460,12 +1460,12 @@ class LoadListener extends Handler implements EventHandler {
     * @param expectedLength An estimate of the content length or the length
     *                       given by the server.
     * @param encoding HTTP encoding.
     * @param expireTime HTTP expires converted to seconds since the epoch.
     * @param expireTime HTTP expires.
     * @return The native response pointer.
     */
    private native int nativeCreateResponse(String url, int statusCode,
            String statusText, String mimeType, long expectedLength,
            String encoding, long expireTime);
            String encoding, String expireTime);

    /**
     * Add a response header to the native object.
+16 −7
Original line number Diff line number Diff line
@@ -48,7 +48,8 @@ public class WebViewDatabase {
    // 6 -> 7 Change cache localPath from int to String
    // 7 -> 8 Move cache to its own db
    // 8 -> 9 Store both scheme and host when storing passwords
    private static final int CACHE_DATABASE_VERSION = 1;
    private static final int CACHE_DATABASE_VERSION = 2;
    // 1 -> 2 Add expires String

    private static WebViewDatabase mInstance = null;

@@ -107,6 +108,8 @@ public class WebViewDatabase {

    private static final String CACHE_EXPIRES_COL = "expires";

    private static final String CACHE_EXPIRES_STRING_COL = "expiresstring";

    private static final String CACHE_MIMETYPE_COL = "mimetype";

    private static final String CACHE_ENCODING_COL = "encoding";
@@ -150,6 +153,7 @@ public class WebViewDatabase {
    private static int mCacheLastModifyColIndex;
    private static int mCacheETagColIndex;
    private static int mCacheExpiresColIndex;
    private static int mCacheExpiresStringColIndex;
    private static int mCacheMimeTypeColIndex;
    private static int mCacheEncodingColIndex;
    private static int mCacheHttpStatusColIndex;
@@ -220,6 +224,8 @@ public class WebViewDatabase {
                        .getColumnIndex(CACHE_ETAG_COL);
                mCacheExpiresColIndex = mCacheInserter
                        .getColumnIndex(CACHE_EXPIRES_COL);
                mCacheExpiresStringColIndex = mCacheInserter
                        .getColumnIndex(CACHE_EXPIRES_STRING_COL);
                mCacheMimeTypeColIndex = mCacheInserter
                        .getColumnIndex(CACHE_MIMETYPE_COL);
                mCacheEncodingColIndex = mCacheInserter
@@ -320,6 +326,7 @@ public class WebViewDatabase {
                    + " TEXT, " + CACHE_FILE_PATH_COL + " TEXT, "
                    + CACHE_LAST_MODIFY_COL + " TEXT, " + CACHE_ETAG_COL
                    + " TEXT, " + CACHE_EXPIRES_COL + " INTEGER, "
                    + CACHE_EXPIRES_STRING_COL + " TEXT, "
                    + CACHE_MIMETYPE_COL + " TEXT, " + CACHE_ENCODING_COL
                    + " TEXT," + CACHE_HTTP_STATUS_COL + " INTEGER, "
                    + CACHE_LOCATION_COL + " TEXT, " + CACHE_CONTENTLENGTH_COL
@@ -537,7 +544,7 @@ public class WebViewDatabase {
        }

        Cursor cursor = mCacheDatabase.rawQuery("SELECT filepath, lastmodify, etag, expires, "
                    + "mimetype, encoding, httpstatus, location, contentlength "
                    + "expiresstring, mimetype, encoding, httpstatus, location, contentlength "
                    + "FROM cache WHERE url = ?",
                new String[] { url });

@@ -548,11 +555,12 @@ public class WebViewDatabase {
                ret.lastModified = cursor.getString(1);
                ret.etag = cursor.getString(2);
                ret.expires = cursor.getLong(3);
                ret.mimeType = cursor.getString(4);
                ret.encoding = cursor.getString(5);
                ret.httpStatusCode = cursor.getInt(6);
                ret.location = cursor.getString(7);
                ret.contentLength = cursor.getLong(8);
                ret.expiresString = cursor.getString(4);
                ret.mimeType = cursor.getString(5);
                ret.encoding = cursor.getString(6);
                ret.httpStatusCode = cursor.getInt(7);
                ret.location = cursor.getString(8);
                ret.contentLength = cursor.getLong(9);
                return ret;
            }
        } finally {
@@ -591,6 +599,7 @@ public class WebViewDatabase {
        mCacheInserter.bind(mCacheLastModifyColIndex, c.lastModified);
        mCacheInserter.bind(mCacheETagColIndex, c.etag);
        mCacheInserter.bind(mCacheExpiresColIndex, c.expires);
        mCacheInserter.bind(mCacheExpiresStringColIndex, c.expiresString);
        mCacheInserter.bind(mCacheMimeTypeColIndex, c.mimeType);
        mCacheInserter.bind(mCacheEncodingColIndex, c.encoding);
        mCacheInserter.bind(mCacheHttpStatusColIndex, c.httpStatusCode);
+3 −8
Original line number Diff line number Diff line
@@ -38,7 +38,6 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.lang.StringBuilder;
import java.util.Date;
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
@@ -57,7 +56,6 @@ import org.apache.http.impl.client.AbstractHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
import org.apache.http.conn.ssl.StrictHostnameVerifier;
import org.apache.http.impl.cookie.DateUtils;
import org.apache.http.util.CharArrayBuffer;

import java.util.concurrent.locks.Condition;
@@ -863,12 +861,9 @@ public final class ApacheHttpRequestAndroid {
        mResponseHeaders = new HashMap<String, String[]>();
        String contentLength = Long.toString(cacheResult.getContentLength());
        setResponseHeader(KEY_CONTENT_LENGTH, contentLength);
        long expires = cacheResult.getExpires();
        if (expires >= 0) {
            // "Expires" header is valid and finite. Milliseconds since 1970
            // epoch, formatted as RFC-1123.
            String expiresString = DateUtils.formatDate(new Date(expires));
            setResponseHeader(KEY_EXPIRES, expiresString);
        String expires = cacheResult.getExpiresString();
        if (expires != null) {
            setResponseHeader(KEY_EXPIRES, expires);
        }
        String lastModified = cacheResult.getLastModified();
        if (lastModified != null) {