Bug 329741 - history.dat, formhistory.dat, downloads.rdf should be deleted when the user clears private data, r=gavin

This commit is contained in:
mconnor@steelgryphon.com 2008-03-18 05:54:23 -07:00
Родитель d12d792587
Коммит a2bc45835d
11 изменённых файлов: 313 добавлений и 1 удалений

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

@ -1551,6 +1551,19 @@ nsDownloadManager::CleanUp()
rv = stmt->Execute();
NS_ENSURE_SUCCESS(rv, rv);
// privacy cleanup, if there's an old downloads.rdf around, just delete it
nsCOMPtr<nsIFile> oldDownloadsFile;
rv = NS_GetSpecialDirectory(NS_APP_DOWNLOADS_50_FILE,
getter_AddRefs(oldDownloadsFile));
if (NS_FAILED(rv)) return rv;
PRBool fileExists;
if (NS_SUCCEEDED(oldDownloadsFile->Exists(&fileExists)) && fileExists) {
rv = oldDownloadsFile->Remove(PR_FALSE);
NS_ENSURE_SUCCESS(rv, rv);
}
// Notify the UI with the topic and null subject to indicate "remove all"
return mObserverService->NotifyObservers(nsnull,
"download-manager-remove-download",

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

@ -0,0 +1,72 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Download Manager Test Code.
*
* The Initial Developer of the Original Code is
* Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2008
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mike Connor <mconnor@mozilla.com> (Original Author)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// This tests the cleanup code to make sure we properly remove old downloads.rdf files
// when clearing data.
function cleanup()
{
// removing rdf
var rdfFile = dirSvc.get("DLoads", Ci.nsIFile);
if (rdfFile.exists()) rdfFile.remove(true);
// removing database
var dbFile = dirSvc.get("ProfD", Ci.nsIFile);
dbFile.append("downloads.sqlite");
if (dbFile.exists())
try { dbFile.remove(true); } catch(e) { /* stupid windows box */ }
}
cleanup();
importDownloadsFile("bug_381535_downloads.rdf");
importDownloadsFile("bug_409179_downloads.sqlite");
function run_test()
{
var rdfFile = dirSvc.get("DLoads", Ci.nsIFile);
do_check_true(rdfFile.exists());
var dm = Cc["@mozilla.org/download-manager;1"].
getService(Ci.nsIDownloadManager);
dm.cleanUp();
do_check_false(rdfFile.exists());
cleanup();
}

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

@ -3799,6 +3799,19 @@ nsNavHistory::RemoveAllPages()
nsresult rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING("VACUUM"));
NS_ENSURE_SUCCESS(rv, rv);
#endif
// privacy cleanup, if there's an old history.dat around, just delete it
nsCOMPtr<nsIFile> oldHistoryFile;
nsresult rv = NS_GetSpecialDirectory(NS_APP_HISTORY_50_FILE,
getter_AddRefs(oldHistoryFile));
if (NS_FAILED(rv)) return rv;
PRBool fileExists;
if (NS_SUCCEEDED(oldHistoryFile->Exists(&fileExists)) && fileExists) {
rv = oldHistoryFile->Remove(PR_FALSE);
NS_ENSURE_SUCCESS(rv, rv);
}
return NS_OK;
}

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

@ -0,0 +1 @@
// <!-- <mdb:mork:z v="1.4"/> --> < <(a=c)> // (f=iso-8859-1) (8A=Typed)(8B=LastPageVisited)(8C=ByteOrder) (80=ns:history:db:row:scope:history:all) (81=ns:history:db:table:kind:history)(82=URL)(83=Referrer) (84=LastVisitDate)(85=FirstVisitDate)(86=VisitCount)(87=Name) (88=Hostname)(89=Hidden)> <(80=LE)(81=http://en-us.www.mozilla.com/en-US/firefox/2.0.0.12/whatsnew/) (82=1205364946314923)(83=en-us.www.mozilla.com)(84 =F$00i$00r$00e$00f$00o$00x$00 $00U$00p$00d$00a$00t$00e$00d$00)> {1:^80 {(k^81:c)(s=9)[1(^8C=LE)]} [2(^82^81)(^84^82)(^85^82)(^88^83)(^87^84)]} @$${2{@ @$$}2}@

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

@ -223,4 +223,16 @@ function run_test() {
do_check_false(uri_in_db(referrerURI));
add_visit(uri("http://mozilla.com"), referrerURI);
do_check_true(uri_in_db(referrerURI));
// test to ensure history.dat gets deleted if all history is being cleared
var file = do_get_file("toolkit/components/places/tests/unit/history.dat");
var histFile = dirSvc.get("ProfD", Ci.nsIFile);
file.copyTo(histFile, "history.dat");
histFile.append("history.dat");
do_check_true(histFile.exists());
var globalHistory = Components.classes["@mozilla.org/browser/global-history;2"]
.getService(Components.interfaces.nsIBrowserHistory);
globalHistory.removeAllPages();
do_check_false(histFile.exists());
}

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

@ -42,6 +42,6 @@ VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = public src
DIRS = public src test
include $(topsrcdir)/config/rules.mk

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

@ -315,6 +315,21 @@ nsFormHistory::RemoveAllEntries()
getter_AddRefs(dbDeleteAll));
NS_ENSURE_SUCCESS(rv,rv);
// privacy cleanup, if there's an old mork formhistory around, just delete it
nsCOMPtr<nsIFile> oldFormHistoryFile;
rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR,
getter_AddRefs(oldFormHistoryFile));
if (NS_FAILED(rv)) return rv;
rv = oldFormHistoryFile->Append(NS_LITERAL_STRING("formhistory.dat"));
NS_ENSURE_SUCCESS(rv, rv);
PRBool fileExists;
if (NS_SUCCEEDED(oldFormHistoryFile->Exists(&fileExists)) && fileExists) {
rv = oldFormHistoryFile->Remove(PR_FALSE);
NS_ENSURE_SUCCESS(rv, rv);
}
return dbDeleteAll->Execute();
}

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

@ -0,0 +1,53 @@
#
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Mozilla code.
#
# The Initial Developer of the Original Code is
# Mozilla Corporation.
# Portions created by the Initial Developer are Copyright (C) 2008
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Shawn Wilsher <me@shawnwilsher.com> (Original Author)
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = test_satchel
XPCSHELL_TESTS = \
unit \
$(NULL)
include $(topsrcdir)/config/rules.mk

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

@ -0,0 +1 @@
// <!-- <mdb:mork:z v="1.4"/> --> < <(a=c)> // (f=iso-8859-1) (80=ns:formhistory:db:row:scope:formhistory:all) (81=ns:formhistory:db:table:kind:formhistory)(82=Value)(83=Name) (84=ByteOrder)> <(80=llll)(81=q$00)(82=f$00o$00o$00)> {1:^80 {(k^81:c)(s=9)[1(^84^80)]} [2(^83^81)(^82^82)]}

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

@ -0,0 +1,78 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Form Autocomplete Test Code.
*
* The Initial Developer of the Original Code is
* Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2008
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mike Connor <mconnor@mozilla.com> (Original Author)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
const Ci = Components.interfaces;
const Cc = Components.classes;
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties);
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties);
var profileDir = null;
try {
profileDir = dirSvc.get("ProfD", Ci.nsIFile);
} catch (e) { }
if (!profileDir) {
// Register our own provider for the profile directory.
// It will simply return the current directory.
var provider = {
getFile: function(prop, persistent) {
persistent.value = true;
if (prop == "ProfD") {
return dirSvc.get("CurProcD", Ci.nsILocalFile);
}
print("*** Throwing trying to get " + prop);
throw Cr.NS_ERROR_FAILURE;
},
QueryInterface: function(iid) {
if (iid.equals(Ci.nsIDirectoryProvider) ||
iid.equals(Ci.nsISupports)) {
return this;
}
throw Cr.NS_ERROR_NO_INTERFACE;
}
};
dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
}
function cleanUpFormHist() {
var formhistFile = dirSvc.get("ProfD", Ci.nsIFile);
formhistFile.append("formhistory.dat");
if (formhistFile.exists())
formhistFile.remove();
}
cleanUpFormHist();

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

@ -0,0 +1,54 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Satchel Test Code.
*
* The Initial Developer of the Original Code is
* Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2008
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mike Connor <mconnor@mozilla.com> (Original Author)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// Test to make sure we drop formhistory.dat when clearing form logins
function run_test()
{
var file = do_get_file("toolkit/components/satchel/test/unit/formhistory.dat");
var formhistFile = dirSvc.get("ProfD", Ci.nsIFile);
file.copyTo(formhistFile, "formhistory.dat");
formhistFile.append("formhistory.dat");
do_check_true(formhistFile.exists());
var formHistory = Cc["@mozilla.org/satchel/form-history;1"].
getService(Ci.nsIFormHistory2);
formHistory.removeAllEntries();
do_check_false(formhistFile.exists());
}