From a46f2e09466859e28877d0e78f3e08bcbef25f2b Mon Sep 17 00:00:00 2001 From: Natalia Csoregi Date: Fri, 19 Jan 2024 00:54:37 +0200 Subject: [PATCH] Backed out changeset 7969278ce39f (bug 1869884) for causing failures on browser_sanitizeDialog_v2.js. CLOSED TREE --- browser/app/profile/firefox.js | 5 +- browser/base/content/sanitizeDialog.js | 24 +++++-- browser/base/content/sanitize_v2.xhtml | 39 +++++++---- .../sanitize/browser_purgehistory_clears_sh.js | 2 +- .../test/sanitize/browser_sanitize-formhistory.js | 2 +- .../test/sanitize/browser_sanitize-history.js | 2 +- .../test/sanitize/browser_sanitizeDialog_v2.js | 81 ++++++++++++++++++---- browser/locales/en-US/browser/sanitize.ftl | 21 ++++-- browser/modules/Sanitizer.sys.mjs | 18 ++--- browser/modules/SiteDataManager.sys.mjs | 35 ++++++++++ 10 files changed, 172 insertions(+), 57 deletions(-) diff --git a/browser/app/profile/firefox.js b/browser/app/profile/firefox.js index a7254a1298d8..a508a8c63907 100644 --- a/browser/app/profile/firefox.js +++ b/browser/app/profile/firefox.js @@ -1019,10 +1019,11 @@ pref("privacy.clearOnShutdown.offlineApps", false); pref("privacy.clearOnShutdown.siteSettings", false); pref("privacy.clearOnShutdown.openWindows", false); // Clear on shutdown prefs used in the new dialog -pref("privacy.clearOnShutdown_v2.historyFormDataAndDownloads", true); +pref("privacy.clearOnShutdown_v2.historyAndFormData", true); pref("privacy.clearOnShutdown_v2.cookiesAndStorage", true); pref("privacy.clearOnShutdown_v2.cache", true); pref("privacy.clearOnShutdown_v2.siteSettings", false); +pref("privacy.clearOnShutdown_v2.downloads", true); pref("privacy.cpd.history", true); pref("privacy.cpd.formdata", true); @@ -1571,7 +1572,7 @@ pref("services.sync.prefs.sync.privacy.clearOnShutdown.downloads", true); pref("services.sync.prefs.sync.privacy.clearOnShutdown_v2.downloads", true); pref("services.sync.prefs.sync.privacy.clearOnShutdown.formdata", true); pref("services.sync.prefs.sync.privacy.clearOnShutdown.history", true); -pref("services.sync.prefs.sync.privacy.clearOnShutdown_v2.historyFormDataAndDownloads", true); +pref("services.sync.prefs.sync.privacy.clearOnShutdown_v2.historyAndFormData", true); pref("services.sync.prefs.sync.privacy.clearOnShutdown.offlineApps", true); pref("services.sync.prefs.sync.privacy.clearOnShutdown.sessions", true); pref("services.sync.prefs.sync.privacy.clearOnShutdown.siteSettings", true); diff --git a/browser/base/content/sanitizeDialog.js b/browser/base/content/sanitizeDialog.js index caed9b0504ba..48609645c090 100644 --- a/browser/base/content/sanitizeDialog.js +++ b/browser/base/content/sanitizeDialog.js @@ -38,10 +38,7 @@ Preferences.addAll([ { id: "privacy.cpd.siteSettings", type: "bool" }, { id: "privacy.sanitize.timeSpan", type: "int" }, { id: "privacy.clearOnShutdown.history", type: "bool" }, - { - id: "privacy.clearOnShutdown_v2.historyFormDataAndDownloads", - type: "bool", - }, + { id: "privacy.clearOnShutdown_v2.historyAndFormData", type: "bool" }, { id: "privacy.clearOnShutdown.formdata", type: "bool" }, { id: "privacy.clearOnShutdown.downloads", type: "bool" }, { id: "privacy.clearOnShutdown_v2.downloads", type: "bool" }, @@ -75,11 +72,13 @@ var gSanitizePromptDialog = { */ this.siteDataSizes = {}; this.cacheSize = []; + this.downloadSizes = {}; if (!lazy.USE_OLD_DIALOG) { this._cookiesAndSiteDataCheckbox = document.getElementById("cookiesAndStorage"); this._cacheCheckbox = document.getElementById("cache"); + this._downloadHistoryCheckbox = document.getElementById("downloads"); } let arg = window.arguments?.[0] || {}; @@ -103,9 +102,10 @@ var gSanitizePromptDialog = { // follow the clear history default prefs this.defaultCheckedByContext = { clearHistory: [ - "historyFormDataAndDownloads", + "historyAndFormData", "cookiesAndStorage", "cache", + "downloads", ], clearSiteData: ["cookiesAndStorage", "cache"], }; @@ -363,9 +363,10 @@ var gSanitizePromptDialog = { "TIMESPAN_EVERYTHING", ]; - let [quotaUsage, cacheSize] = await Promise.all([ + let [quotaUsage, cacheSize, downloadCount] = await Promise.all([ lazy.SiteDataManager.getQuotaUsageForTimeRanges(ALL_TIMESPANS), lazy.SiteDataManager.getCacheSize(), + lazy.SiteDataManager.getDownloadCountForTimeRanges(ALL_TIMESPANS), ]); // Convert sizes to [amount, unit] for (const timespan in quotaUsage) { @@ -374,6 +375,7 @@ var gSanitizePromptDialog = { ); } this.cacheSize = lazy.DownloadUtils.convertByteUnits(cacheSize); + this.downloadSizes = downloadCount; this.updateDataSizesInUI(); }, @@ -474,12 +476,20 @@ var gSanitizePromptDialog = { "item-cached-content-with-size", { amount, unit } ); + + const downloadcount = this.downloadSizes[timeSpanSelected]; + + document.l10n.setAttributes( + this._downloadHistoryCheckbox, + "item-download-history-with-size", + { count: downloadcount } + ); }, /** * Get all items to clear based on checked boxes * - * @returns {string[]} array of items ["cache", "historyFormDataAndDownloads"...] + * @returns {string[]} array of items ["cache", "historyAndFormData"...] */ getItemsToClear() { // the old dialog uses the preferences to decide what to clear diff --git a/browser/base/content/sanitize_v2.xhtml b/browser/base/content/sanitize_v2.xhtml index 97ad484e5f99..202e3c71d720 100644 --- a/browser/base/content/sanitize_v2.xhtml +++ b/browser/base/content/sanitize_v2.xhtml @@ -107,13 +107,8 @@ - @@ -162,20 +157,24 @@ /> + + + + + - @@ -227,6 +226,16 @@ /> + + + + + diff --git a/browser/base/content/test/sanitize/browser_purgehistory_clears_sh.js b/browser/base/content/test/sanitize/browser_purgehistory_clears_sh.js index 5ad7b78d6985..c75946bf2bcc 100644 --- a/browser/base/content/test/sanitize/browser_purgehistory_clears_sh.js +++ b/browser/base/content/test/sanitize/browser_purgehistory_clears_sh.js @@ -6,7 +6,7 @@ const url = // We will be removing the ["history"] option once we remove the // old clear history dialog in Bug 1856418 - Remove all old clear data dialog boxes -let prefs = [["history"], ["historyFormDataAndDownloads"]]; +let prefs = [["history"], ["historyAndFormData"]]; for (let itemsToClear of prefs) { add_task(async function purgeHistoryTest() { diff --git a/browser/base/content/test/sanitize/browser_sanitize-formhistory.js b/browser/base/content/test/sanitize/browser_sanitize-formhistory.js index ae043dbd62dc..903dbbfebd7e 100644 --- a/browser/base/content/test/sanitize/browser_sanitize-formhistory.js +++ b/browser/base/content/test/sanitize/browser_sanitize-formhistory.js @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ add_task(async function test() { - let prefs = ["history", "historyFormDataAndDownloads"]; + let prefs = ["history", "historyAndFormData"]; for (let pref of prefs) { // This test relies on the form history being empty to start with delete diff --git a/browser/base/content/test/sanitize/browser_sanitize-history.js b/browser/base/content/test/sanitize/browser_sanitize-history.js index e003762f3543..c9902d27cf14 100644 --- a/browser/base/content/test/sanitize/browser_sanitize-history.js +++ b/browser/base/content/test/sanitize/browser_sanitize-history.js @@ -4,7 +4,7 @@ // Tests that sanitizing history will clear storage access permissions // for sites without cookies or site data. add_task(async function sanitizeStorageAccessPermissions() { - let categories = ["history", "historyFormDataAndDownloads"]; + let categories = ["history", "historyAndFormData"]; for (let pref of categories) { await new Promise(resolve => { diff --git a/browser/base/content/test/sanitize/browser_sanitizeDialog_v2.js b/browser/base/content/test/sanitize/browser_sanitizeDialog_v2.js index 6b2f31071a81..f66d9afaa86e 100644 --- a/browser/base/content/test/sanitize/browser_sanitizeDialog_v2.js +++ b/browser/base/content/test/sanitize/browser_sanitizeDialog_v2.js @@ -529,6 +529,9 @@ async function validateDataSizes(dialogHelper) { // get current data sizes from siteDataManager let cacheUsage = await SiteDataManager.getCacheSize(); let quotaUsage = await SiteDataManager.getQuotaUsageForTimeRanges(timespans); + let downloadUsage = await SiteDataManager.getDownloadCountForTimeRanges( + timespans + ); for (let i = 0; i < timespans.length; i++) { // select timespan to check @@ -538,6 +541,8 @@ async function validateDataSizes(dialogHelper) { let clearCookiesAndSiteDataCheckbox = dialogHelper.win.document.getElementById("cookiesAndStorage"); let clearCacheCheckbox = dialogHelper.win.document.getElementById("cache"); + let clearDownloadsCheckbox = + dialogHelper.win.document.getElementById("downloads"); let [convertedQuotaUsage] = DownloadUtils.convertByteUnits( quotaUsage[timespans[i]] @@ -548,6 +553,7 @@ async function validateDataSizes(dialogHelper) { await dialogHelper.win.document.l10n.translateElements([ clearCookiesAndSiteDataCheckbox, clearCacheCheckbox, + clearDownloadsCheckbox, ]); ok( clearCacheCheckbox.label.includes(convertedCacheUnit), @@ -557,6 +563,10 @@ async function validateDataSizes(dialogHelper) { clearCookiesAndSiteDataCheckbox.label.includes(convertedQuotaUsage), `Should show the quota usage as ${convertedQuotaUsage}` ); + ok( + clearDownloadsCheckbox.label.includes(downloadUsage[timespans[i]]), + `Should show the downloads usage as ${downloadUsage[timespans[i]]}` + ); } } @@ -592,7 +602,7 @@ add_task(async function test_cancel() { let dh = new DialogHelper(); dh.onload = function () { this.selectDuration(Sanitizer.TIMESPAN_HOUR); - this.checkPrefCheckbox("historyFormDataAndDownloads", false); + this.checkPrefCheckbox("historyAndFormData", false); this.cancelDialog(); }; dh.onunload = async function () { @@ -632,7 +642,7 @@ add_task(async function test_everything() { "with a predefined timespan" ); this.selectDuration(Sanitizer.TIMESPAN_EVERYTHING); - this.checkPrefCheckbox("historyFormDataAndDownloads", true); + this.checkPrefCheckbox("historyAndFormData", true); this.acceptDialog(); }; dh.onunload = async function () { @@ -679,7 +689,7 @@ add_task(async function test_everything_warning() { "with clearing everything" ); this.selectDuration(Sanitizer.TIMESPAN_EVERYTHING); - this.checkPrefCheckbox("historyFormDataAndDownloads", true); + this.checkPrefCheckbox("historyAndFormData", true); this.acceptDialog(); }; dh.onunload = async function () { @@ -737,7 +747,8 @@ add_task(async function test_history_downloads_checked() { let dh = new DialogHelper(); dh.onload = function () { this.selectDuration(Sanitizer.TIMESPAN_HOUR); - this.checkPrefCheckbox("historyFormDataAndDownloads", true); + this.checkPrefCheckbox("downloads", true); + this.checkPrefCheckbox("historyAndFormData", true); this.acceptDialog(); }; dh.onunload = async function () { @@ -789,7 +800,7 @@ add_task(async function test_cannot_clear_history() { let dh = new DialogHelper(); dh.onload = function () { var cb = this.win.document.querySelectorAll( - "checkbox[id='historyFormDataAndDownloads']" + "checkbox[id='historyAndFormData']" ); ok( cb.length == 1 && !cb[0].disabled, @@ -816,7 +827,7 @@ add_task(async function test_no_formdata_history_to_clear() { let dh = new DialogHelper(); dh.onload = function () { var cb = this.win.document.querySelectorAll( - "checkbox[id='historyFormDataAndDownloads']" + "checkbox[id='historyAndFormData']" ); ok( cb.length == 1 && !cb[0].disabled && cb[0].checked, @@ -839,7 +850,7 @@ add_task(async function test_form_entries() { let dh = new DialogHelper(); dh.onload = function () { var cb = this.win.document.querySelectorAll( - "checkbox[id='historyFormDataAndDownloads']" + "checkbox[id='historyAndFormData']" ); is(cb.length, 1, "There is only one checkbox for history and form data"); ok(!cb[0].disabled, "The checkbox is enabled"); @@ -940,6 +951,33 @@ add_task(async function test_all_data_sizes() { }); }); +add_task(async function test_single_download() { + // add download + let downloadIDs = []; + await addDownloadWithMinutesAgo(downloadIDs, 100000000000); + + let dh = new DialogHelper(); + dh.onload = async function () { + this.uncheckAllCheckboxes(); + this.checkPrefCheckbox("downloads", true); + this.selectDuration(Sanitizer.TIMESPAN_EVERYTHING); + let clearDownloadsCheckbox = dh.win.document.getElementById("downloads"); + // Wait for the UI to update + await dh.win.document.l10n.translateElements([clearDownloadsCheckbox]); + ok( + clearDownloadsCheckbox.label.includes("1 file)"), + "Should show singular file" + ); + this.acceptDialog(); + }; + dh.onunload = async function () { + await ensureDownloadsClearedState(downloadIDs, true); + }; + dh.open(); + await dh.promiseClosed; + blankSlate(); +}); + // test the case when we open the dialog through the clear on shutdown settings add_task(async function test_clear_on_shutdown() { await openPreferencesViaOpenPreferencesAPI("privacy", { leaveOpen: true }); @@ -952,7 +990,7 @@ add_task(async function test_clear_on_shutdown() { dh.setMode("clearOnShutdown"); dh.onload = async function () { this.uncheckAllCheckboxes(); - this.checkPrefCheckbox("historyFormDataAndDownloads", false); + this.checkPrefCheckbox("historyAndFormData", true); this.checkPrefCheckbox("cookiesAndStorage", true); this.acceptDialog(); }; @@ -971,7 +1009,7 @@ add_task(async function test_clear_on_shutdown() { } boolPrefIs( - "clearOnShutdown_v2.historyAndFormDataAndDownloads", + "clearOnShutdown_v2.historyAndFormData", true, "clearOnShutdown_v2 history should be true " ); @@ -983,6 +1021,12 @@ add_task(async function test_clear_on_shutdown() { ); boolPrefIs( + "clearOnShutdown_v2.downloads", + false, + "clearOnShutdown_v2 downloads should be false" + ); + + boolPrefIs( "clearOnShutdown_v2.cache", false, "clearOnShutdown_v2 cache should be false" @@ -1022,14 +1066,15 @@ add_task(async function test_clear_on_shutdown() { dh.setMode("clearOnShutdown"); dh.onload = async function () { this.uncheckAllCheckboxes(); - this.checkPrefCheckbox("historyFormDataAndDownloads", true); + this.checkPrefCheckbox("historyAndFormData", true); + this.checkPrefCheckbox("downloads", true); this.acceptDialog(); }; dh.open(); await dh.promiseClosed; boolPrefIs( - "clearOnShutdown_v2.historyAndFormDataAndDownloads", + "clearOnShutdown_v2.historyAndFormData", true, "clearOnShutdown_v2 history should be true" ); @@ -1041,6 +1086,12 @@ add_task(async function test_clear_on_shutdown() { ); boolPrefIs( + "clearOnShutdown_v2.downloads", + true, + "clearOnShutdown_v2 downloads should be true" + ); + + boolPrefIs( "clearOnShutdown_v2.cache", false, "clearOnShutdown_v2 cache should be false" @@ -1084,10 +1135,11 @@ add_task(async function test_defaults_prefs() { dh.setMode("clearSiteData"); dh.onload = function () { - this.validateCheckbox("historyFormDataAndDownloads", false); + this.validateCheckbox("historyAndFormData", false); this.validateCheckbox("cache", true); this.validateCheckbox("cookiesAndStorage", true); this.validateCheckbox("siteSettings", false); + this.validateCheckbox("downloads", false); this.cancelDialog(); }; @@ -1100,10 +1152,11 @@ add_task(async function test_defaults_prefs() { dh = new DialogHelper(); dh.onload = function () { // Default checked for browser and clear history mode - this.validateCheckbox("historyFormDataAndDownloads", true); + this.validateCheckbox("historyAndFormData", true); this.validateCheckbox("cache", true); this.validateCheckbox("cookiesAndStorage", true); this.validateCheckbox("siteSettings", false); + this.validateCheckbox("downloads", true); this.cancelDialog(); }; @@ -1140,7 +1193,7 @@ async function clearAndValidateDataSizes({ await validateDataSizes(this); this.checkPrefCheckbox("cache", clearCache); this.checkPrefCheckbox("cookiesAndStorage", clearCookies); - this.checkPrefCheckbox("historyFormDataAndDownloads", clearDownloads); + this.checkPrefCheckbox("downloads", clearDownloads); this.selectDuration(timespan); this.acceptDialog(); }; diff --git a/browser/locales/en-US/browser/sanitize.ftl b/browser/locales/en-US/browser/sanitize.ftl index df5bb713f3c0..b37dd028932a 100644 --- a/browser/locales/en-US/browser/sanitize.ftl +++ b/browser/locales/en-US/browser/sanitize.ftl @@ -70,11 +70,9 @@ item-history-and-downloads = .label = Browsing & download history .accesskey = B -item-history-form-data-downloads = - .label = History - .accesskey = H - -item-history-form-data-downloads-description = Clears site and download history, saved form info, and searches +item-browsing-and-search = + .label = Visited sites, saved form info and searches + .accesskey = V item-cookies = .label = Cookies @@ -124,6 +122,19 @@ item-site-prefs = item-site-prefs-description = Resets your permissions and site preferences to original settings +# Variables: +# $count (Number) - Number of downloads recorded +item-download-history-with-size = + .label = { $count -> + [one] Downloaded files list ({ $count } file) + *[other] Downloaded files list ({ $count } files) + } + .accesskey = D + +item-download-history = + .label = Downloaded files list + .accesskey = D + data-section-label = Data item-site-settings = diff --git a/browser/modules/Sanitizer.sys.mjs b/browser/modules/Sanitizer.sys.mjs index 1dd891b88d5f..067a1c170ed9 100644 --- a/browser/modules/Sanitizer.sys.mjs +++ b/browser/modules/Sanitizer.sys.mjs @@ -751,7 +751,7 @@ export var Sanitizer = { // Combine History and Form Data clearing for the // new clear history dialog box. - historyFormDataAndDownloads: { + historyAndFormData: { async clear(range, { progress }) { progress.step = "getAllPrincipals"; let principals = await gPrincipalsCollector.getAllPrincipals(progress); @@ -836,12 +836,6 @@ export var Sanitizer = { if (seenException) { throw seenException; } - - // clear Downloads - refObj = {}; - TelemetryStopwatch.start("FX_SANITIZE_DOWNLOADS", refObj); - await clearData(range, Ci.nsIClearDataService.CLEAR_DOWNLOADS); - TelemetryStopwatch.finish("FX_SANITIZE_DOWNLOADS", refObj); }, }, @@ -1031,16 +1025,18 @@ async function sanitizeOnShutdown(progress) { privacy_clearOnShutdown_v2_cookiesAndStorage: Services.prefs.getBoolPref( "privacy.clearOnShutdown_v2.cookiesAndStorage" ), - privacy_clearOnShutdown_v2_historyFormDataAndDownloads: - Services.prefs.getBoolPref( - "privacy.clearOnShutdown_v2.historyFormDataAndDownloads" - ), + privacy_clearOnShutdown_v2_historyAndFormData: Services.prefs.getBoolPref( + "privacy.clearOnShutdown_v2.historyAndFormData" + ), privacy_clearOnShutdown_v2_cache: Services.prefs.getBoolPref( "privacy.clearOnShutdown_v2.cache" ), privacy_clearOnShutdown_v2_siteSettings: Services.prefs.getBoolPref( "privacy.clearOnShutdown_v2.siteSettings" ), + privacy_clearOnShutdown_v2_downloads: Services.prefs.getBoolPref( + "privacy.clearOnShutdown_v2.downloads" + ), }; } diff --git a/browser/modules/SiteDataManager.sys.mjs b/browser/modules/SiteDataManager.sys.mjs index 2f5585cd25a3..2012a41cb1c1 100644 --- a/browser/modules/SiteDataManager.sys.mjs +++ b/browser/modules/SiteDataManager.sys.mjs @@ -17,6 +17,7 @@ ChromeUtils.defineLazyGetter(lazy, "gBrandBundle", function () { }); ChromeUtils.defineESModuleGetters(lazy, { + DownloadHistory: "resource://gre/modules/DownloadHistory.sys.mjs", Sanitizer: "resource:///modules/Sanitizer.sys.mjs", }); @@ -416,6 +417,40 @@ export var SiteDataManager = { }, /** + * Fetches number of downloads for all timespans in timeSpanArr + * + * @param {String[]} timeSpanArr - Array of timespan options to get downloads count + * from Sanitizer, e.g. ["TIMESPAN_HOUR", "TIMESPAN_2HOURS"] + * @returns {Object} downloads counted for each timespan + */ + async getDownloadCountForTimeRanges(timeSpanArr) { + let downloads = await lazy.DownloadHistory.getList(); + + let downloadSizes = {}; + timeSpanArr.forEach(timespan => { + downloadSizes[timespan] = 0; + }); + + let timeNow = Date.now(); + + for (let download of downloads._downloads) { + let startTime = new Date(download.startTime); + for (let timeSpan of timeSpanArr) { + let compareTime = new Date( + timeNow - lazy.Sanitizer.timeSpanMsMap[timeSpan] + ); + + if (timeSpan === "TIMESPAN_EVERYTHING") { + downloadSizes[timeSpan] += 1; + } else if (startTime >= compareTime) { + downloadSizes[timeSpan] += 1; + } + } + } + return downloadSizes; + }, + + /** * Gets all sites that are currently storing site data. Entries are grouped by * parent base domain if applicable. For example "foo.example.com", * "example.com" and "bar.example.com" will have one entry with the baseDomain -- 2.11.4.GIT