diff --git a/toolkit/components/passwordmgr/storage-mozStorage.js b/toolkit/components/passwordmgr/storage-mozStorage.js index 5c30bbf50b7..06c0bb5eaa9 100644 --- a/toolkit/components/passwordmgr/storage-mozStorage.js +++ b/toolkit/components/passwordmgr/storage-mozStorage.js @@ -345,6 +345,7 @@ LoginManagerStorage_mozStorage.prototype = { try { stmt = this._dbCreateStatement(query, params); stmt.execute(); + this.storeDeletedLogin(storedLogin); transaction.commit(); } catch (e) { this.log("_removeLogin failed: " + e.name + " : " + e.message); @@ -650,6 +651,31 @@ LoginManagerStorage_mozStorage.prototype = { return [logins, ids]; }, + /* storeDeletedLogin + * + * Moves a login to the deleted logins table + * + */ + storeDeletedLogin : function(aLogin) { +#ifdef ANDROID + let stmt = null; + try { + this.log("Storing " + aLogin.guid + " in deleted passwords\n"); + let query = "INSERT INTO moz_deleted_logins (guid, timeDeleted) VALUES (:guid, :timeDeleted)"; + let params = { guid: aLogin.guid, + timeDeleted: Date.now() }; + let stmt = this._dbCreateStatement(query, params); + stmt.execute(); + } catch(ex) { + throw ex; + } finally { + if (stmt) + stmt.reset(); + } +#endif + }, + + /* * removeAllLogins * @@ -667,6 +693,11 @@ LoginManagerStorage_mozStorage.prototype = { // Disabled hosts kept, as one presumably doesn't want to erase those. query = "DELETE FROM moz_logins"; try { + let logins = this.getAllLogins(); + for each (let login in logins) { + let [id, storedLogin] = this._getIdForLogin(login); + this.storeDeletedLogin(storedLogin); + } stmt = this._dbCreateStatement(query); stmt.execute(); transaction.commit(); diff --git a/toolkit/components/satchel/nsFormHistory.js b/toolkit/components/satchel/nsFormHistory.js index 30c321567a3..697c9f6f974 100644 --- a/toolkit/components/satchel/nsFormHistory.js +++ b/toolkit/components/satchel/nsFormHistory.js @@ -222,6 +222,10 @@ FormHistory.prototype = { existingTransactionInProgress = this.dbConnection.transactionInProgress; if (!existingTransactionInProgress) this.dbConnection.beginTransaction(); + this.moveToDeletedTable("VALUES (:guid, :timeDeleted)", { + guid: guid, + timeDeleted: Date.now() + }); // remove from the formhistory database stmt = this.dbCreateStatement(query, params); @@ -257,6 +261,12 @@ FormHistory.prototype = { existingTransactionInProgress = this.dbConnection.transactionInProgress; if (!existingTransactionInProgress) this.dbConnection.beginTransaction(); + this.moveToDeletedTable( + "SELECT guid, :timeDeleted FROM moz_formhistory " + + "WHERE fieldname = :fieldname", { + fieldname: name, + timeDeleted: Date.now() + }); stmt = this.dbCreateStatement(query, params); stmt.execute(); @@ -290,6 +300,11 @@ FormHistory.prototype = { existingTransactionInProgress = this.dbConnection.transactionInProgress; if (!existingTransactionInProgress) this.dbConnection.beginTransaction(); + this.moveToDeletedTable( + "SELECT guid, :timeDeleted FROM moz_formhistory", { + timeDeleted: Date.now() + }); + stmt = this.dbCreateStatement(query); stmt.execute(); this.sendNotification("removeAllEntries", null); @@ -352,6 +367,12 @@ FormHistory.prototype = { existingTransactionInProgress = this.dbConnection.transactionInProgress; if (!existingTransactionInProgress) this.dbConnection.beginTransaction(); + this.moveToDeletedTable( + "SELECT guid, :timeDeleted FROM moz_formhistory " + + "WHERE firstUsed >= :beginTime AND firstUsed <= :endTime", { + beginTime: beginTime, + endTime: endTime + }); stmt = this.dbCreateStatement(query, params); stmt.executeStep(); @@ -370,6 +391,29 @@ FormHistory.prototype = { this.dbConnection.commitTransaction(); }, + moveToDeletedTable : function moveToDeletedTable(values, params) { +#ifdef ANDROID + this.log("Moving entries to deleted table."); + + let stmt; + + try { + // Move the entries to the deleted items table. + let query = "INSERT INTO moz_deleted_formhistory (guid, timeDeleted) "; + if (values) query += values; + stmt = this.dbCreateStatement(query, params); + stmt.execute(); + } catch (e) { + this.log("Moving deleted entries failed: " + e); + throw e; + } finally { + if (stmt) { + stmt.reset(); + } + } +#endif + }, + get dbConnection() { // Make sure dbConnection can't be called from now to prevent infinite loops. delete FormHistory.prototype.dbConnection;