Skip to content

Commit cd0dd93

Browse files
author
Ben Murdoch
committed
WebViewDatabase v11 for ICS.
Bump WebView database version to 11. This has the following effects: - Removes the old webview cookie table on GB devices. Cookies are now managed by the Chromium stack. - Removes the old webview cache database on GB devices. Cache is now managed by the Chromium stack. - Autocomplete form data is now stored/retrieved based on the URL minus the query string/fragment. Upgrade any existing form URLs in the database to match this format, so we can still use them. This will impact GB and HC devices. This has an unfortunate side effect that we may end up with duplicate URLs in the formurl table (say we had two URLS for the same host but with different query strings). Currently we only take the first url from the table - which is fine when they were unique. The simplest way to work around this is just iterate all the rows returned and use all the values we find. Bug: 5560410 Change-Id: I59323dc5e523969e0a1c268b5936d6fa998d625c
1 parent f10daf6 commit cd0dd93

File tree

1 file changed

+41
-6
lines changed

1 file changed

+41
-6
lines changed

core/java/android/webkit/WebViewDatabase.java

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class WebViewDatabase {
4242
// log tag
4343
protected static final String LOGTAG = "webviewdatabase";
4444

45-
private static final int DATABASE_VERSION = 10;
45+
private static final int DATABASE_VERSION = 11;
4646
// 2 -> 3 Modified Cache table to allow cache of redirects
4747
// 3 -> 4 Added Oma-Downloads table
4848
// 4 -> 5 Modified Cache table to support persistent contentLength
@@ -52,6 +52,9 @@ public class WebViewDatabase {
5252
// 7 -> 8 Move cache to its own db
5353
// 8 -> 9 Store both scheme and host when storing passwords
5454
// 9 -> 10 Update httpauth table UNIQUE
55+
// 10 -> 11 Drop cookies and cache now managed by the chromium stack,
56+
// and update the form data table to use the new format
57+
// implemented for b/5265606.
5558
private static final int CACHE_DATABASE_VERSION = 4;
5659
// 1 -> 2 Add expires String
5760
// 2 -> 3 Add content-disposition
@@ -204,7 +207,9 @@ private synchronized void init(Context context) {
204207
}
205208

206209
initDatabase(context);
207-
if (!JniUtil.useChromiumHttpStack()) {
210+
if (JniUtil.useChromiumHttpStack()) {
211+
context.deleteDatabase(CACHE_DATABASE_FILE);
212+
} else {
208213
initCacheDatabase(context);
209214
}
210215

@@ -328,8 +333,41 @@ private void initCacheDatabase(Context context) {
328333

329334
private static void upgradeDatabase() {
330335
upgradeDatabaseToV10();
336+
upgradeDatabaseFromV10ToV11();
331337
// Add future database upgrade functions here, one version at a
332338
// time.
339+
mDatabase.setVersion(DATABASE_VERSION);
340+
}
341+
342+
private static void upgradeDatabaseFromV10ToV11() {
343+
int oldVersion = mDatabase.getVersion();
344+
345+
if (oldVersion >= 11) {
346+
// Nothing to do.
347+
return;
348+
}
349+
350+
if (JniUtil.useChromiumHttpStack()) {
351+
// Clear out old java stack cookies - this data is now stored in
352+
// a separate database managed by the Chrome stack.
353+
mDatabase.execSQL("DROP TABLE IF EXISTS " + mTableNames[TABLE_COOKIES_ID]);
354+
355+
// Likewise for the old cache table.
356+
mDatabase.execSQL("DROP TABLE IF EXISTS cache");
357+
}
358+
359+
// Update form autocomplete URLs to match new ICS formatting.
360+
Cursor c = mDatabase.query(mTableNames[TABLE_FORMURL_ID], null, null,
361+
null, null, null, null);
362+
while (c.moveToNext()) {
363+
String urlId = Long.toString(c.getLong(c.getColumnIndex(ID_COL)));
364+
String url = c.getString(c.getColumnIndex(FORMURL_URL_COL));
365+
ContentValues cv = new ContentValues(1);
366+
cv.put(FORMURL_URL_COL, WebTextView.urlForAutoCompleteData(url));
367+
mDatabase.update(mTableNames[TABLE_FORMURL_ID], cv, ID_COL + "=?",
368+
new String[] { urlId });
369+
}
370+
c.close();
333371
}
334372

335373
private static void upgradeDatabaseToV10() {
@@ -356,7 +394,6 @@ private static void upgradeDatabaseToV10() {
356394
+ HTTPAUTH_PASSWORD_COL + " TEXT," + " UNIQUE ("
357395
+ HTTPAUTH_HOST_COL + ", " + HTTPAUTH_REALM_COL
358396
+ ") ON CONFLICT REPLACE);");
359-
mDatabase.setVersion(DATABASE_VERSION);
360397
return;
361398
}
362399

@@ -410,8 +447,6 @@ private static void upgradeDatabaseToV10() {
410447
+ " TEXT, " + PASSWORD_PASSWORD_COL + " TEXT," + " UNIQUE ("
411448
+ PASSWORD_HOST_COL + ", " + PASSWORD_USERNAME_COL
412449
+ ") ON CONFLICT REPLACE);");
413-
414-
mDatabase.setVersion(DATABASE_VERSION);
415450
}
416451

417452
private static void upgradeCacheDatabase() {
@@ -1158,7 +1193,7 @@ ArrayList<String> getFormData(String url, String name) {
11581193
cursor = mDatabase.query(mTableNames[TABLE_FORMURL_ID],
11591194
ID_PROJECTION, urlSelection, new String[] { url }, null,
11601195
null, null);
1161-
if (cursor.moveToFirst()) {
1196+
while (cursor.moveToNext()) {
11621197
long urlid = cursor.getLong(cursor.getColumnIndex(ID_COL));
11631198
Cursor dataCursor = null;
11641199
try {

0 commit comments

Comments
 (0)