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

Commit 131ed03f authored by Ben Murdoch's avatar Ben Murdoch Committed by Android Git Automerger
Browse files

am e6269f79: am fead0e14: Merge changes I59323dc5,I31a01aa3 into ics-mr1

* commit 'e6269f79':
  WebViewDatabase v11 for ICS.
  Fix a bug in the database upgrade process, and refactor slightly.
parents ee737d9e e6269f79
Loading
Loading
Loading
Loading
+95 −52
Original line number Original line Diff line number Diff line
@@ -42,7 +42,7 @@ public class WebViewDatabase {
    // log tag
    // log tag
    protected static final String LOGTAG = "webviewdatabase";
    protected static final String LOGTAG = "webviewdatabase";


    private static final int DATABASE_VERSION = 10;
    private static final int DATABASE_VERSION = 11;
    // 2 -> 3 Modified Cache table to allow cache of redirects
    // 2 -> 3 Modified Cache table to allow cache of redirects
    // 3 -> 4 Added Oma-Downloads table
    // 3 -> 4 Added Oma-Downloads table
    // 4 -> 5 Modified Cache table to support persistent contentLength
    // 4 -> 5 Modified Cache table to support persistent contentLength
@@ -52,6 +52,9 @@ public class WebViewDatabase {
    // 7 -> 8 Move cache to its own db
    // 7 -> 8 Move cache to its own db
    // 8 -> 9 Store both scheme and host when storing passwords
    // 8 -> 9 Store both scheme and host when storing passwords
    // 9 -> 10 Update httpauth table UNIQUE
    // 9 -> 10 Update httpauth table UNIQUE
    // 10 -> 11 Drop cookies and cache now managed by the chromium stack,
    //          and update the form data table to use the new format
    //          implemented for b/5265606.
    private static final int CACHE_DATABASE_VERSION = 4;
    private static final int CACHE_DATABASE_VERSION = 4;
    // 1 -> 2 Add expires String
    // 1 -> 2 Add expires String
    // 2 -> 3 Add content-disposition
    // 2 -> 3 Add content-disposition
@@ -204,7 +207,9 @@ public class WebViewDatabase {
        }
        }


        initDatabase(context);
        initDatabase(context);
        if (!JniUtil.useChromiumHttpStack()) {
        if (JniUtil.useChromiumHttpStack()) {
            context.deleteDatabase(CACHE_DATABASE_FILE);
        } else {
            initCacheDatabase(context);
            initCacheDatabase(context);
        }
        }


@@ -327,15 +332,59 @@ public class WebViewDatabase {
    }
    }


    private static void upgradeDatabase() {
    private static void upgradeDatabase() {
        upgradeDatabaseToV10();
        upgradeDatabaseFromV10ToV11();
        // Add future database upgrade functions here, one version at a
        // time.
        mDatabase.setVersion(DATABASE_VERSION);
    }

    private static void upgradeDatabaseFromV10ToV11() {
        int oldVersion = mDatabase.getVersion();

        if (oldVersion >= 11) {
            // Nothing to do.
            return;
        }

        if (JniUtil.useChromiumHttpStack()) {
            // Clear out old java stack cookies - this data is now stored in
            // a separate database managed by the Chrome stack.
            mDatabase.execSQL("DROP TABLE IF EXISTS " + mTableNames[TABLE_COOKIES_ID]);

            // Likewise for the old cache table.
            mDatabase.execSQL("DROP TABLE IF EXISTS cache");
        }

        // Update form autocomplete  URLs to match new ICS formatting.
        Cursor c = mDatabase.query(mTableNames[TABLE_FORMURL_ID], null, null,
                null, null, null, null);
        while (c.moveToNext()) {
            String urlId = Long.toString(c.getLong(c.getColumnIndex(ID_COL)));
            String url = c.getString(c.getColumnIndex(FORMURL_URL_COL));
            ContentValues cv = new ContentValues(1);
            cv.put(FORMURL_URL_COL, WebTextView.urlForAutoCompleteData(url));
            mDatabase.update(mTableNames[TABLE_FORMURL_ID], cv, ID_COL + "=?",
                    new String[] { urlId });
        }
        c.close();
    }

    private static void upgradeDatabaseToV10() {
        int oldVersion = mDatabase.getVersion();
        int oldVersion = mDatabase.getVersion();

        if (oldVersion >= 10) {
            // Nothing to do.
            return;
        }

        if (oldVersion != 0) {
        if (oldVersion != 0) {
            Log.i(LOGTAG, "Upgrading database from version "
            Log.i(LOGTAG, "Upgrading database from version "
                    + oldVersion + " to "
                    + oldVersion + " to "
                    + DATABASE_VERSION + ", which will destroy old data");
                    + DATABASE_VERSION + ", which will destroy old data");
        }
        }
        boolean justPasswords = 8 == oldVersion && 9 == DATABASE_VERSION;

        boolean justAuth = 9 == oldVersion && 10 == DATABASE_VERSION;
        if (9 == oldVersion) {
        if (justAuth) {
            mDatabase.execSQL("DROP TABLE IF EXISTS "
            mDatabase.execSQL("DROP TABLE IF EXISTS "
                    + mTableNames[TABLE_HTTPAUTH_ID]);
                    + mTableNames[TABLE_HTTPAUTH_ID]);
            mDatabase.execSQL("CREATE TABLE " + mTableNames[TABLE_HTTPAUTH_ID]
            mDatabase.execSQL("CREATE TABLE " + mTableNames[TABLE_HTTPAUTH_ID]
@@ -348,7 +397,6 @@ public class WebViewDatabase {
            return;
            return;
        }
        }


        if (!justPasswords) {
        mDatabase.execSQL("DROP TABLE IF EXISTS "
        mDatabase.execSQL("DROP TABLE IF EXISTS "
                + mTableNames[TABLE_COOKIES_ID]);
                + mTableNames[TABLE_COOKIES_ID]);
        mDatabase.execSQL("DROP TABLE IF EXISTS cache");
        mDatabase.execSQL("DROP TABLE IF EXISTS cache");
@@ -358,13 +406,9 @@ public class WebViewDatabase {
                + mTableNames[TABLE_FORMDATA_ID]);
                + mTableNames[TABLE_FORMDATA_ID]);
        mDatabase.execSQL("DROP TABLE IF EXISTS "
        mDatabase.execSQL("DROP TABLE IF EXISTS "
                + mTableNames[TABLE_HTTPAUTH_ID]);
                + mTableNames[TABLE_HTTPAUTH_ID]);
        }
        mDatabase.execSQL("DROP TABLE IF EXISTS "
        mDatabase.execSQL("DROP TABLE IF EXISTS "
                + mTableNames[TABLE_PASSWORD_ID]);
                + mTableNames[TABLE_PASSWORD_ID]);


        mDatabase.setVersion(DATABASE_VERSION);

        if (!justPasswords) {
        // cookies
        // cookies
        mDatabase.execSQL("CREATE TABLE " + mTableNames[TABLE_COOKIES_ID]
        mDatabase.execSQL("CREATE TABLE " + mTableNames[TABLE_COOKIES_ID]
                + " (" + ID_COL + " INTEGER PRIMARY KEY, "
                + " (" + ID_COL + " INTEGER PRIMARY KEY, "
@@ -396,7 +440,6 @@ public class WebViewDatabase {
                + HTTPAUTH_PASSWORD_COL + " TEXT," + " UNIQUE ("
                + HTTPAUTH_PASSWORD_COL + " TEXT," + " UNIQUE ("
                + HTTPAUTH_HOST_COL + ", " + HTTPAUTH_REALM_COL
                + HTTPAUTH_HOST_COL + ", " + HTTPAUTH_REALM_COL
                + ") ON CONFLICT REPLACE);");
                + ") ON CONFLICT REPLACE);");
        }
        // passwords
        // passwords
        mDatabase.execSQL("CREATE TABLE " + mTableNames[TABLE_PASSWORD_ID]
        mDatabase.execSQL("CREATE TABLE " + mTableNames[TABLE_PASSWORD_ID]
                + " (" + ID_COL + " INTEGER PRIMARY KEY, "
                + " (" + ID_COL + " INTEGER PRIMARY KEY, "
@@ -411,7 +454,7 @@ public class WebViewDatabase {
        if (oldVersion != 0) {
        if (oldVersion != 0) {
            Log.i(LOGTAG, "Upgrading cache database from version "
            Log.i(LOGTAG, "Upgrading cache database from version "
                    + oldVersion + " to "
                    + oldVersion + " to "
                    + DATABASE_VERSION + ", which will destroy all old data");
                    + CACHE_DATABASE_VERSION + ", which will destroy all old data");
        }
        }
        mCacheDatabase.execSQL("DROP TABLE IF EXISTS cache");
        mCacheDatabase.execSQL("DROP TABLE IF EXISTS cache");
        mCacheDatabase.setVersion(CACHE_DATABASE_VERSION);
        mCacheDatabase.setVersion(CACHE_DATABASE_VERSION);
@@ -1150,7 +1193,7 @@ public class WebViewDatabase {
                cursor = mDatabase.query(mTableNames[TABLE_FORMURL_ID],
                cursor = mDatabase.query(mTableNames[TABLE_FORMURL_ID],
                        ID_PROJECTION, urlSelection, new String[] { url }, null,
                        ID_PROJECTION, urlSelection, new String[] { url }, null,
                        null, null);
                        null, null);
                if (cursor.moveToFirst()) {
                while (cursor.moveToNext()) {
                    long urlid = cursor.getLong(cursor.getColumnIndex(ID_COL));
                    long urlid = cursor.getLong(cursor.getColumnIndex(ID_COL));
                    Cursor dataCursor = null;
                    Cursor dataCursor = null;
                    try {
                    try {