Bug 725052 - Check if a password is in the deleted database before inserting it. r=rnewman

This commit is contained in:
Wes Johnston 2012-03-08 10:25:44 -08:00
Родитель 8cb3acf165
Коммит e5a7a3e889
3 изменённых файлов: 62 добавлений и 21 удалений

Просмотреть файл

@ -54,6 +54,9 @@ public class FormHistoryProvider extends GeckoProvider {
private static int DB_VERSION = 4; private static int DB_VERSION = 4;
private static String DB_FILENAME = "formhistory.sqlite"; private static String DB_FILENAME = "formhistory.sqlite";
private static final String WHERE_GUID_IS_NULL = BrowserContract.DeletedFormHistory.GUID + " IS NULL";
private static final String WHERE_GUID_IS_VALUE = BrowserContract.DeletedFormHistory.GUID + " = ?";
static { static {
URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH); URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
URI_MATCHER.addURI(BrowserContract.FORM_HISTORY_AUTHORITY, "formhistory", FORM_HISTORY); URI_MATCHER.addURI(BrowserContract.FORM_HISTORY_AUTHORITY, "formhistory", FORM_HISTORY);
@ -144,9 +147,27 @@ public class FormHistoryProvider extends GeckoProvider {
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("FormHistory:Init", null)); GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("FormHistory:Init", null));
} }
public void onPreInsert(ContentValues values, Uri uri) { } @Override
public void onPreInsert(ContentValues values, Uri uri, SQLiteBridge db) {
if (!values.containsKey(FormHistory.GUID)) {
return;
}
String guid = values.getAsString(FormHistory.GUID);
try {
if (guid == null) {
db.delete(TABLE_DELETED_FORM_HISTORY, WHERE_GUID_IS_NULL, null);
return;
}
String[] args = new String[] { guid };
db.delete(TABLE_DELETED_FORM_HISTORY, WHERE_GUID_IS_VALUE, args);
} catch(SQLiteBridgeException ex) {
Log.w(getLogTag(), "Error removing entry with GUID " + guid, ex);
}
}
public void onPreUpdate(ContentValues values, Uri uri) { } @Override
public void onPreUpdate(ContentValues values, Uri uri, SQLiteBridge db) { }
public void onPostQuery(Cursor cursor, Uri uri) { } @Override
public void onPostQuery(Cursor cursor, Uri uri, SQLiteBridge db) { }
} }

Просмотреть файл

@ -222,7 +222,7 @@ public abstract class GeckoProvider extends ContentProvider {
setupDefaults(uri, values); setupDefaults(uri, values);
onPreInsert(values, uri); onPreInsert(values, uri, db);
try { try {
id = db.insert(getTable(uri), null, values); id = db.insert(getTable(uri), null, values);
@ -245,7 +245,7 @@ public abstract class GeckoProvider extends ContentProvider {
if (db == null) if (db == null)
return updated; return updated;
onPreUpdate(values, uri); onPreUpdate(values, uri, db);
try { try {
updated = db.update(getTable(uri), values, selection, selectionArgs); updated = db.update(getTable(uri), values, selection, selectionArgs);
@ -272,7 +272,7 @@ public abstract class GeckoProvider extends ContentProvider {
try { try {
cursor = db.query(getTable(uri), projection, selection, selectionArgs, null, null, sortOrder, null); cursor = db.query(getTable(uri), projection, selection, selectionArgs, null, null, sortOrder, null);
onPostQuery(cursor, uri); onPostQuery(cursor, uri, db);
} catch (SQLiteBridgeException ex) { } catch (SQLiteBridgeException ex) {
Log.e(mLogTag, "Error querying database", ex); Log.e(mLogTag, "Error querying database", ex);
} }
@ -288,9 +288,9 @@ public abstract class GeckoProvider extends ContentProvider {
public abstract void initGecko(); public abstract void initGecko();
public abstract void onPreInsert(ContentValues values, Uri uri); public abstract void onPreInsert(ContentValues values, Uri uri, SQLiteBridge db);
public abstract void onPreUpdate(ContentValues values, Uri uri); public abstract void onPreUpdate(ContentValues values, Uri uri, SQLiteBridge db);
public abstract void onPostQuery(Cursor cursor, Uri uri); public abstract void onPostQuery(Cursor cursor, Uri uri, SQLiteBridge db);
} }

Просмотреть файл

@ -59,6 +59,9 @@ public class PasswordsProvider extends GeckoProvider {
private static final int DB_VERSION = 5; private static final int DB_VERSION = 5;
private static final String DB_FILENAME = "signons.sqlite"; private static final String DB_FILENAME = "signons.sqlite";
private static final String WHERE_GUID_IS_NULL = BrowserContract.DeletedPasswords.GUID + " IS NULL";
private static final String WHERE_GUID_IS_VALUE = BrowserContract.DeletedPasswords.GUID + " = ?";
static { static {
URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH); URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
@ -210,19 +213,22 @@ public class PasswordsProvider extends GeckoProvider {
return result; return result;
} }
public void onPreInsert(ContentValues values, Uri uri) { @Override
if (values.containsKey(Passwords.ENCRYPTED_PASSWORD)) { public void onPreInsert(ContentValues values, Uri uri, SQLiteBridge db) {
String res = doCrypto(values.getAsString(Passwords.ENCRYPTED_PASSWORD), uri, true); if (values.containsKey(Passwords.GUID)) {
values.put(Passwords.ENCRYPTED_PASSWORD, res); String guid = values.getAsString(Passwords.GUID);
try {
if (guid == null) {
db.delete(TABLE_DELETED_PASSWORDS, WHERE_GUID_IS_NULL, null);
return;
}
String[] args = new String[] { guid };
db.delete(TABLE_DELETED_PASSWORDS, WHERE_GUID_IS_VALUE, args);
} catch(SQLiteBridgeException ex) {
Log.w(getLogTag(), "Error removing entry with GUID " + guid, ex);
}
} }
if (values.containsKey(Passwords.ENCRYPTED_USERNAME)) {
String res = doCrypto(values.getAsString(Passwords.ENCRYPTED_USERNAME), uri, true);
values.put(Passwords.ENCRYPTED_USERNAME, res);
}
}
public void onPreUpdate(ContentValues values, Uri uri) {
if (values.containsKey(Passwords.ENCRYPTED_PASSWORD)) { if (values.containsKey(Passwords.ENCRYPTED_PASSWORD)) {
String res = doCrypto(values.getAsString(Passwords.ENCRYPTED_PASSWORD), uri, true); String res = doCrypto(values.getAsString(Passwords.ENCRYPTED_PASSWORD), uri, true);
values.put(Passwords.ENCRYPTED_PASSWORD, res); values.put(Passwords.ENCRYPTED_PASSWORD, res);
@ -234,7 +240,21 @@ public class PasswordsProvider extends GeckoProvider {
} }
} }
public void onPostQuery(Cursor cursor, Uri uri) { @Override
public void onPreUpdate(ContentValues values, Uri uri, SQLiteBridge db) {
if (values.containsKey(Passwords.ENCRYPTED_PASSWORD)) {
String res = doCrypto(values.getAsString(Passwords.ENCRYPTED_PASSWORD), uri, true);
values.put(Passwords.ENCRYPTED_PASSWORD, res);
}
if (values.containsKey(Passwords.ENCRYPTED_USERNAME)) {
String res = doCrypto(values.getAsString(Passwords.ENCRYPTED_USERNAME), uri, true);
values.put(Passwords.ENCRYPTED_USERNAME, res);
}
}
@Override
public void onPostQuery(Cursor cursor, Uri uri, SQLiteBridge db) {
int passwordIndex = -1; int passwordIndex = -1;
int usernameIndex = -1; int usernameIndex = -1;
String profilePath = null; String profilePath = null;