Expose site-specific settings in CRH dialog. b=380852, r=gavin

This commit is contained in:
Johnathan Nightingale 2009-01-20 10:59:49 -05:00
Родитель 7a30e530d1
Коммит 6783415329
11 изменённых файлов: 150 добавлений и 3 удалений

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

@ -405,9 +405,9 @@ pref("privacy.item.passwords", false);
pref("privacy.item.downloads", true);
pref("privacy.item.cookies", false);
pref("privacy.item.cache", true);
pref("privacy.item.siteprefs", false);
pref("privacy.item.sessions", true);
pref("privacy.item.offlineApps", false);
pref("privacy.item.siteSettings", false);
// What default should we use for the time span in the sanitizer:
// 0 - Clear everything

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

@ -333,6 +333,24 @@ Sanitizer.prototype = {
authMgr.clearAll();
},
get canClear()
{
return true;
}
},
siteSettings: {
clear: function ()
{
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
.getService(Components.interfaces.nsIPermissionManager);
pm.removeAll();
var cps = Components.classes["@mozilla.org/content-pref/service;1"]
.getService(Components.interfaces.nsIContentPrefService);
cps.removeGroupedPrefs();
},
get canClear()
{
return true;

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

@ -187,6 +187,7 @@
<preference id="privacy.cpd.cache" name="privacy.cpd.cache" type="bool"/>
<preference id="privacy.cpd.offlineApps" name="privacy.cpd.offlineApps" type="bool"/>
<preference id="privacy.cpd.sessions" name="privacy.cpd.sessions" type="bool"/>
<preference id="privacy.cpd.siteSettings" name="privacy.cpd.siteSettings" type="bool"/>
</preferences>
<preferences id="nonItemPreferences">
@ -254,6 +255,10 @@
accesskey="&itemPasswords.accesskey;"
preference="privacy.cpd.passwords"
onsyncfrompreference="return gSanitizePromptDialog.onReadGeneric();"/>
<checkbox label="&itemSiteSettings.label;"
accesskey="&itemSiteSettings.accesskey;"
preference="privacy.cpd.siteSettings"
onsyncfrompreference="return gSanitizePromptDialog.onReadGeneric();"/>
</vbox>
<vbox style="width: &column.width;">
<checkbox label="&itemOfflineApps.label;"

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

@ -86,6 +86,7 @@ _BROWSER_FILES = browser_bug321000.js \
browser_bug386835.js \
bug386835.html \
browser_bug422590.js \
browser_sanitize-sitepermissions.js \
$(NULL)
ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))

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

@ -0,0 +1,43 @@
// Bug 380852 - Delete permission manager entries in Clear Recent History
Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Components.interfaces.mozIJSSubScriptLoader)
.loadSubScript("chrome://browser/content/sanitize.js");
function test() {
// Add a permission entry
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
.getService(Components.interfaces.nsIPermissionManager);
pm.add(uri("http://example.com"), "testing", Ci.nsIPermissionManager.ALLOW_ACTION);
// Sanity check
ok(pm.enumerator.hasMoreElements(), "Permission manager should have elements, since we just added one");
// Set up the sanitizer to just clear siteSettings
let s = new Sanitizer();
s.ignoreTimespan = false;
s.prefDomain = "privacy.cpd.";
var itemPrefs = Cc["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService)
.getBranch(s.prefDomain);
itemPrefs.setBoolPref("history", false);
itemPrefs.setBoolPref("downloads", false);
itemPrefs.setBoolPref("cache", false);
itemPrefs.setBoolPref("cookies", false);
itemPrefs.setBoolPref("formdata", false);
itemPrefs.setBoolPref("offlineApps", false);
itemPrefs.setBoolPref("passwords", false);
itemPrefs.setBoolPref("sessions", false);
itemPrefs.setBoolPref("siteSettings", true);
// Clear it
s.sanitize();
// Make sure it's gone
ok(!pm.enumerator.hasMoreElements(), "Permission manager shouldn't have entries after Sanitizing");
}
function uri(spec) {
return Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService)
.newURI(spec, null, null);
}

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

@ -34,7 +34,7 @@ function test() {
itemPrefs.setBoolPref("offlineApps", false);
itemPrefs.setBoolPref("passwords", false);
itemPrefs.setBoolPref("sessions", false);
itemPrefs.setBoolPref("siteprefs", false);
itemPrefs.setBoolPref("siteSettings", false);
// Clear 1 hour
Sanitizer.prefs.setIntPref("timeSpan", 1);

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

@ -68,6 +68,7 @@
<preference id="privacy.item.cache" name="privacy.item.cache" type="bool"/>
<preference id="privacy.item.offlineApps" name="privacy.item.offlineApps" type="bool"/>
<preference id="privacy.item.sessions" name="privacy.item.sessions" type="bool"/>
<preference id="privacy.item.siteSettings" name="privacy.item.siteSettings" type="bool"/>
</preferences>
<description>&clearDataSettings2.label;</description>
@ -103,6 +104,9 @@
<checkbox label="&itemPasswords.label;"
accesskey="&itemPasswords.accesskey;"
preference="privacy.item.passwords"/>
<checkbox label="&itemSiteSettings.label;"
accesskey="&itemSiteSettings.accesskey;"
preference="privacy.item.siteSettings"/>
</vbox>
<vbox style="width: &column.width;">
<checkbox label="&itemOfflineApps.label;"

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

@ -36,6 +36,8 @@ that require it. -->
<!ENTITY itemDownloadList.accesskey "D">
<!ENTITY itemActiveLogins.label "Active Logins">
<!ENTITY itemActiveLogins.accesskey "L">
<!ENTITY itemSiteSettings.label "Site-specific Settings">
<!ENTITY itemSiteSettings.accesskey "S">
<!ENTITY window.width "30em">
<!ENTITY column.width "14em">

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

@ -65,7 +65,7 @@ interface nsIContentPrefObserver : nsISupports
void onContentPrefRemoved(in AString aGroup, in AString aName);
};
[scriptable, uuid(72c05ba2-9d92-4661-b053-f8f869973e6a)]
[scriptable, uuid(5047e359-dfda-4858-abec-d145c7463250)]
interface nsIContentPrefService : nsISupports
{
/**
@ -110,6 +110,12 @@ interface nsIContentPrefService : nsISupports
*/
void removePref(in nsIURI aURI, in AString aName);
/**
* Remove all grouped prefs. Useful for removing references to the sites
* the user has visited when the user clears their private data.
*/
void removeGroupedPrefs();
/**
* Get the prefs that apply to the given URI.
*

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

@ -225,6 +225,19 @@ ContentPrefService.prototype = {
}
},
removeGroupedPrefs: function ContentPrefService_removeGroupedPrefs() {
this._dbConnection.beginTransaction();
try {
this._dbConnection.executeSimpleSQL("DELETE FROM prefs WHERE groupID IS NOT NULL");
this._dbConnection.executeSimpleSQL("DELETE FROM groups");
this._dbConnection.commitTransaction();
}
catch(ex) {
this._dbConnection.rollbackTransaction();
throw ex;
}
},
getPrefs: function ContentPrefService_getPrefs(aURI) {
if (aURI) {
var group = this.grouper.group(aURI);

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

@ -347,4 +347,59 @@ function run_test() {
do_check_eq(genericObserver.numTimesSetCalled, 2);
do_check_eq(specificObserver.numTimesRemovedCalled, 1);
do_check_eq(genericObserver.numTimesRemovedCalled, 2);
//**************************************************************************//
// Clear Private Data Pref Removal
{
let uri1 = ContentPrefTest.getURI("http://www.domain1.com/");
let uri2 = ContentPrefTest.getURI("http://www.domain2.com/");
let uri3 = ContentPrefTest.getURI("http://www.domain3.com/");
let dbConnection = cps.DBConnection;
let prefCount = Cc["@mozilla.org/storage/statement-wrapper;1"].
createInstance(Ci.mozIStorageStatementWrapper);
prefCount.initialize(dbConnection.createStatement("SELECT COUNT(*) AS count FROM prefs"));
let groupCount = Cc["@mozilla.org/storage/statement-wrapper;1"].
createInstance(Ci.mozIStorageStatementWrapper);
groupCount.initialize(dbConnection.createStatement("SELECT COUNT(*) AS count FROM groups"));
// Add some prefs for multiple domains.
cps.setPref(uri1, "test.removeAllGroups", 1);
cps.setPref(uri2, "test.removeAllGroups", 2);
cps.setPref(uri3, "test.removeAllGroups", 3);
// Add a global pref.
cps.setPref(null, "test.removeAllGroups", 1);
// Make sure there are some prefs and groups in the database.
prefCount.step();
do_check_true(prefCount.row.count > 0);
prefCount.reset();
groupCount.step();
do_check_true(groupCount.row.count > 0);
groupCount.reset();
// Remove all prefs and groups from the database using the same routine
// the Clear Private Data dialog uses.
cps.removeGroupedPrefs();
// Make sure there are no longer any groups in the database and the only pref
// is the global one.
prefCount.step();
do_check_true(prefCount.row.count == 1);
prefCount.reset();
groupCount.step();
do_check_true(groupCount.row.count == 0);
groupCount.reset();
let globalPref = Cc["@mozilla.org/storage/statement-wrapper;1"].
createInstance(Ci.mozIStorageStatementWrapper);
globalPref.initialize(dbConnection.createStatement("SELECT groupID FROM prefs"));
globalPref.step();
do_check_true(globalPref.row.groupID == null);
globalPref.reset();
}
}