mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-20 00:35:44 +00:00
Bug 1422163 - Part 1 - Make a new confirm dialog for clearing all site data that allows you to clear cache. r=Gijs
MozReview-Commit-ID: G9xQXlfT9Ay --HG-- extra : rebase_source : 045092865b7ad533174090a05e0282e5c1b30396
This commit is contained in:
parent
a0ff3ed908
commit
1dd2560f1b
@ -17,6 +17,10 @@ this.EXPORTED_SYMBOLS = [
|
||||
"SiteDataManager"
|
||||
];
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "gStringBundle", function() {
|
||||
return Services.strings.createBundle("chrome://browser/locale/siteData.properties");
|
||||
});
|
||||
|
||||
this.SiteDataManager = {
|
||||
|
||||
_qms: Services.qms,
|
||||
@ -32,6 +36,10 @@ this.SiteDataManager = {
|
||||
// - appCacheList: an array of app cache; instances of nsIApplicationCache
|
||||
_sites: new Map(),
|
||||
|
||||
_getCacheSizeObserver: null,
|
||||
|
||||
_getCacheSizePromise: null,
|
||||
|
||||
_getQuotaUsagePromise: null,
|
||||
|
||||
_quotaUsageRequest: null,
|
||||
@ -43,6 +51,46 @@ this.SiteDataManager = {
|
||||
Services.obs.notifyObservers(null, "sitedatamanager:sites-updated");
|
||||
},
|
||||
|
||||
/**
|
||||
* Retrieves the amount of space currently used by disk cache.
|
||||
*
|
||||
* You can use DownloadUtils.convertByteUnits to convert this to
|
||||
* a user-understandable size/unit combination.
|
||||
*
|
||||
* @returns a Promise that resolves with the cache size on disk in bytes.
|
||||
*/
|
||||
getCacheSize() {
|
||||
if (this._getCacheSizePromise) {
|
||||
return this._getCacheSizePromise;
|
||||
}
|
||||
|
||||
this._getCacheSizePromise = new Promise((resolve, reject) => {
|
||||
// Needs to root the observer since cache service keeps only a weak reference.
|
||||
this._getCacheSizeObserver = {
|
||||
onNetworkCacheDiskConsumption: consumption => {
|
||||
resolve(consumption);
|
||||
this._getCacheSizePromise = null;
|
||||
this._getCacheSizeObserver = null;
|
||||
},
|
||||
|
||||
QueryInterface: XPCOMUtils.generateQI([
|
||||
Components.interfaces.nsICacheStorageConsumptionObserver,
|
||||
Components.interfaces.nsISupportsWeakReference
|
||||
])
|
||||
};
|
||||
|
||||
try {
|
||||
Services.cache2.asyncGetDiskConsumption(this._getCacheSizeObserver);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
this._getCacheSizePromise = null;
|
||||
this._getCacheSizeObserver = null;
|
||||
}
|
||||
});
|
||||
|
||||
return this._getCacheSizePromise;
|
||||
},
|
||||
|
||||
_getQuotaUsage() {
|
||||
// Clear old data and requests first
|
||||
this._sites.clear();
|
||||
@ -278,8 +326,56 @@ this.SiteDataManager = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* In the specified window, shows a prompt for removing
|
||||
* all site data, warning the user that this may log them
|
||||
* out of websites.
|
||||
*
|
||||
* @param {mozIDOMWindowProxy} a parent DOM window to host the dialog.
|
||||
* @returns a boolean whether the user confirmed the prompt.
|
||||
*/
|
||||
promptSiteDataRemoval(win) {
|
||||
let flags =
|
||||
Services.prompt.BUTTON_TITLE_IS_STRING * Services.prompt.BUTTON_POS_0 +
|
||||
Services.prompt.BUTTON_TITLE_CANCEL * Services.prompt.BUTTON_POS_1 +
|
||||
Services.prompt.BUTTON_POS_0_DEFAULT;
|
||||
let title = gStringBundle.GetStringFromName("clearSiteDataPromptTitle");
|
||||
let text = gStringBundle.GetStringFromName("clearSiteDataPromptText");
|
||||
let btn0Label = gStringBundle.GetStringFromName("clearSiteDataNow");
|
||||
|
||||
let result = Services.prompt.confirmEx(
|
||||
win, title, text, flags, btn0Label, null, null, null, {});
|
||||
return result == 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* Clears all site data and cache
|
||||
*
|
||||
* @returns a Promise that resolves when the data is cleared.
|
||||
*/
|
||||
async removeAll() {
|
||||
this.removeCache();
|
||||
return this.removeSiteData();
|
||||
},
|
||||
|
||||
/**
|
||||
* Clears the entire network cache.
|
||||
*/
|
||||
removeCache() {
|
||||
Services.cache2.clear();
|
||||
},
|
||||
|
||||
/**
|
||||
* Clears all site data, which currently means
|
||||
* - Cookies
|
||||
* - AppCache
|
||||
* - ServiceWorkers
|
||||
* - Quota Managed Storage
|
||||
* - persistent-storage permissions
|
||||
*
|
||||
* @returns a Promise that resolves with the cache size on disk in bytes
|
||||
*/
|
||||
async removeSiteData() {
|
||||
Services.cookies.removeAll();
|
||||
OfflineAppCacheHelper.clear();
|
||||
|
||||
|
19
browser/components/preferences/clearSiteData.css
Normal file
19
browser/components/preferences/clearSiteData.css
Normal file
@ -0,0 +1,19 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
.options-container {
|
||||
background-color: var(--in-content-box-background);
|
||||
border: 1px solid var(--in-content-box-border-color);
|
||||
border-radius: 2px;
|
||||
color: var(--in-content-text-color);
|
||||
padding: 0.5em;
|
||||
}
|
||||
|
||||
.option {
|
||||
padding-bottom: 16px;
|
||||
}
|
||||
|
||||
.option-description {
|
||||
color: #737373;
|
||||
}
|
78
browser/components/preferences/clearSiteData.js
Normal file
78
browser/components/preferences/clearSiteData.js
Normal file
@ -0,0 +1,78 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
|
||||
ChromeUtils.import("resource://gre/modules/DownloadUtils.jsm");
|
||||
ChromeUtils.import("resource:///modules/SiteDataManager.jsm");
|
||||
|
||||
var gClearSiteDataDialog = {
|
||||
_clearSiteDataCheckbox: null,
|
||||
_clearCacheCheckbox: null,
|
||||
_clearButton: null,
|
||||
|
||||
init() {
|
||||
this._bundle = Services.strings
|
||||
.createBundle("chrome://browser/locale/preferences/clearSiteData.properties");
|
||||
|
||||
SiteDataManager.getTotalUsage().then(bytes => {
|
||||
// Size is an array of amount and unit, e.g. [20, "MB"].
|
||||
let size = DownloadUtils.convertByteUnits(bytes);
|
||||
document.getElementById("clearSiteDataLabel").value =
|
||||
this._bundle.formatStringFromName("clearSiteDataWithEstimates.label", size, 2);
|
||||
});
|
||||
SiteDataManager.getCacheSize().then(bytes => {
|
||||
// Size is an array of amount and unit, e.g. [20, "MB"].
|
||||
let size = DownloadUtils.convertByteUnits(bytes);
|
||||
document.getElementById("clearCacheLabel").value =
|
||||
this._bundle.formatStringFromName("clearCacheWithEstimates.label", size, 2);
|
||||
});
|
||||
|
||||
this._clearButton = document.getElementById("clearButton");
|
||||
this._cancelButton = document.getElementById("cancelButton");
|
||||
this._clearSiteDataCheckbox = document.getElementById("clearSiteData");
|
||||
this._clearCacheCheckbox = document.getElementById("clearCache");
|
||||
|
||||
window.addEventListener("keypress", this.onWindowKeyPress);
|
||||
|
||||
this._cancelButton.addEventListener("command", window.close);
|
||||
this._clearButton.addEventListener("command", () => this.onClear());
|
||||
|
||||
this._clearSiteDataCheckbox.addEventListener("command", e => this.onCheckboxCommand(e));
|
||||
this._clearCacheCheckbox.addEventListener("command", e => this.onCheckboxCommand(e));
|
||||
},
|
||||
|
||||
onWindowKeyPress(event) {
|
||||
if (event.keyCode == KeyEvent.DOM_VK_ESCAPE)
|
||||
window.close();
|
||||
},
|
||||
|
||||
onCheckboxCommand(event) {
|
||||
this._clearButton.disabled =
|
||||
!(this._clearSiteDataCheckbox.checked || this._clearCacheCheckbox.checked);
|
||||
},
|
||||
|
||||
onClear() {
|
||||
let allowed = true;
|
||||
|
||||
if (this._clearSiteDataCheckbox.checked) {
|
||||
allowed = SiteDataManager.promptSiteDataRemoval(window);
|
||||
if (allowed) {
|
||||
SiteDataManager.removeSiteData();
|
||||
}
|
||||
}
|
||||
|
||||
if (this._clearCacheCheckbox.checked && allowed) {
|
||||
SiteDataManager.removeCache();
|
||||
// Update cache UI in about:preferences
|
||||
window.opener.gPrivacyPane.updateActualCacheSize();
|
||||
}
|
||||
|
||||
if (allowed) {
|
||||
window.close();
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
window.addEventListener("load", () => gClearSiteDataDialog.init());
|
59
browser/components/preferences/clearSiteData.xul
Normal file
59
browser/components/preferences/clearSiteData.xul
Normal file
@ -0,0 +1,59 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
|
||||
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
|
||||
<?xml-stylesheet href="chrome://browser/skin/preferences/preferences.css" type="text/css"?>
|
||||
<?xml-stylesheet href="chrome://browser/content/preferences/clearSiteData.css" type="text/css"?>
|
||||
|
||||
<!DOCTYPE dialog SYSTEM "chrome://browser/locale/preferences/clearSiteData.dtd" >
|
||||
|
||||
<window id="ClearSiteDataDialog" class="windowDialog"
|
||||
windowtype="Browser:ClearSiteData"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
style="width: &window.width;;"
|
||||
title="&window.title;"
|
||||
persist="screenX screenY width height">
|
||||
|
||||
<script src="chrome://browser/content/preferences/clearSiteData.js"/>
|
||||
|
||||
<stringbundle id="bundlePreferences"
|
||||
src="chrome://browser/locale/preferences/preferences.properties"/>
|
||||
|
||||
<keyset>
|
||||
<key key="&windowClose.key;" modifiers="accel" oncommand="window.close();"/>
|
||||
</keyset>
|
||||
|
||||
<vbox class="contentPane largeDialogContainer" flex="1">
|
||||
<description control="url">&window.description;</description>
|
||||
<separator class="thin"/>
|
||||
<vbox class="options-container">
|
||||
<hbox class="option">
|
||||
<checkbox id="clearSiteData" checked="true"
|
||||
accesskey="&clearSiteData.accesskey;" />
|
||||
<vbox>
|
||||
<label for="clearSiteData" id="clearSiteDataLabel" value="&clearSiteData.label;" />
|
||||
<description class="option-description">&clearSiteData.description;</description>
|
||||
</vbox>
|
||||
</hbox>
|
||||
<hbox class="option">
|
||||
<checkbox id="clearCache" checked="true"
|
||||
accesskey="&clearCache.accesskey;" />
|
||||
<vbox>
|
||||
<label for="clearCache" id="clearCacheLabel" value="&clearCache.label;" />
|
||||
<description class="option-description">&clearCache.description;</description>
|
||||
</vbox>
|
||||
</hbox>
|
||||
</vbox>
|
||||
</vbox>
|
||||
<vbox>
|
||||
<hbox class="actionButtons" align="right" flex="1">
|
||||
<button id="cancelButton" icon="close"
|
||||
label="&button.cancel.label;" accesskey="&button.cancel.accesskey;" />
|
||||
<button id="clearButton" icon="save"
|
||||
label="&button.clear.label;" accesskey="&button.clear.accesskey;"/>
|
||||
</hbox>
|
||||
</vbox>
|
||||
</window>
|
@ -1519,20 +1519,7 @@ var gPrivacyPane = {
|
||||
},
|
||||
|
||||
clearSiteData() {
|
||||
let flags =
|
||||
Services.prompt.BUTTON_TITLE_IS_STRING * Services.prompt.BUTTON_POS_0 +
|
||||
Services.prompt.BUTTON_TITLE_CANCEL * Services.prompt.BUTTON_POS_1 +
|
||||
Services.prompt.BUTTON_POS_0_DEFAULT;
|
||||
let prefStrBundle = document.getElementById("bundlePreferences");
|
||||
let title = prefStrBundle.getString("clearSiteDataPromptTitle");
|
||||
let text = prefStrBundle.getString("clearSiteDataPromptText");
|
||||
let btn0Label = prefStrBundle.getString("clearSiteDataNow");
|
||||
|
||||
let result = Services.prompt.confirmEx(
|
||||
window, title, text, flags, btn0Label, null, null, null, {});
|
||||
if (result == 0) {
|
||||
SiteDataManager.removeAll();
|
||||
}
|
||||
gSubDialog.open("chrome://browser/content/preferences/clearSiteData.xul");
|
||||
},
|
||||
|
||||
initDataCollection() {
|
||||
|
@ -7,6 +7,9 @@ browser.jar:
|
||||
content/browser/preferences/applicationManager.js
|
||||
content/browser/preferences/blocklists.xul
|
||||
content/browser/preferences/blocklists.js
|
||||
content/browser/preferences/clearSiteData.css
|
||||
content/browser/preferences/clearSiteData.js
|
||||
content/browser/preferences/clearSiteData.xul
|
||||
* content/browser/preferences/colors.xul
|
||||
content/browser/preferences/colors.js
|
||||
* content/browser/preferences/cookies.xul
|
||||
|
@ -208,18 +208,7 @@ let gSiteDataSettings = {
|
||||
|
||||
if (removals.size > 0) {
|
||||
if (this._sites.length == 0) {
|
||||
// User selects all sites so equivalent to clearing all data
|
||||
let flags =
|
||||
Services.prompt.BUTTON_TITLE_IS_STRING * Services.prompt.BUTTON_POS_0 +
|
||||
Services.prompt.BUTTON_TITLE_CANCEL * Services.prompt.BUTTON_POS_1 +
|
||||
Services.prompt.BUTTON_POS_0_DEFAULT;
|
||||
let prefStrBundle = document.getElementById("bundlePreferences");
|
||||
let title = prefStrBundle.getString("clearSiteDataPromptTitle");
|
||||
let text = prefStrBundle.getString("clearSiteDataPromptText");
|
||||
let btn0Label = prefStrBundle.getString("clearSiteDataNow");
|
||||
let result = Services.prompt.confirmEx(window, title, text, flags, btn0Label, null, null, null, {});
|
||||
allowed = result == 0;
|
||||
if (allowed) {
|
||||
if (SiteDataManager.promptSiteDataRemoval(window)) {
|
||||
SiteDataManager.removeAll();
|
||||
}
|
||||
} else {
|
||||
|
@ -0,0 +1,22 @@
|
||||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
|
||||
<!ENTITY window.title "Clear Data">
|
||||
<!ENTITY window.width "35em">
|
||||
|
||||
<!ENTITY window.description "Clearing all cookies and site data stored by Firefox may sign you out of websites and remove offline web content. Clearing cache data will not affect your logins.">
|
||||
<!ENTITY windowClose.key "w">
|
||||
|
||||
<!ENTITY clearSiteData.label "Cookies and Site Data">
|
||||
<!ENTITY clearSiteData.accesskey "S">
|
||||
<!ENTITY clearSiteData.description "You may get signed out of websites if cleared">
|
||||
|
||||
<!ENTITY clearCache.label "Cached Web Content">
|
||||
<!ENTITY clearCache.accesskey "W">
|
||||
<!ENTITY clearCache.description "Will require websites to reload images and data">
|
||||
|
||||
<!ENTITY button.cancel.label "Cancel">
|
||||
<!ENTITY button.cancel.accesskey "C">
|
||||
<!ENTITY button.clear.label "Clear">
|
||||
<!ENTITY button.clear.accesskey "l">
|
@ -0,0 +1,7 @@
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
clearSiteDataWithEstimates.label = Site Data and Cookies (%1$S %2$S)
|
||||
clearCacheWithEstimates.label = Cached Web Content (%1$S %2$S)
|
||||
|
@ -188,9 +188,6 @@ actualAppCacheSize=Your application cache is currently using %1$S %2$S of disk s
|
||||
# %2$S = unit (MB, KB, etc.)
|
||||
totalSiteDataSize=Your stored site data is currently using %1$S %2$S of disk space
|
||||
loadingSiteDataSize=Calculating site data size…
|
||||
clearSiteDataPromptTitle=Clear all cookies and site data
|
||||
clearSiteDataPromptText=Selecting ‘Clear Now’ will clear all cookies and site data stored by Firefox. This may sign you out of websites and remove offline web content.
|
||||
clearSiteDataNow=Clear Now
|
||||
persistent=Persistent
|
||||
siteUsage=%1$S %2$S
|
||||
acceptRemove=Remove
|
||||
|
7
browser/locales/en-US/chrome/browser/siteData.properties
Normal file
7
browser/locales/en-US/chrome/browser/siteData.properties
Normal file
@ -0,0 +1,7 @@
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
clearSiteDataPromptTitle=Clear all cookies and site data
|
||||
clearSiteDataPromptText=Selecting ‘Clear Now’ will clear all cookies and site data stored by Firefox. This may sign you out of websites and remove offline web content.
|
||||
clearSiteDataNow=Clear Now
|
@ -38,6 +38,7 @@
|
||||
locale/browser/safeMode.dtd (%chrome/browser/safeMode.dtd)
|
||||
locale/browser/sanitize.dtd (%chrome/browser/sanitize.dtd)
|
||||
locale/browser/search.properties (%chrome/browser/search.properties)
|
||||
locale/browser/siteData.properties (%chrome/browser/siteData.properties)
|
||||
locale/browser/sitePermissions.properties (%chrome/browser/sitePermissions.properties)
|
||||
locale/browser/engineManager.properties (%chrome/browser/engineManager.properties)
|
||||
locale/browser/setDesktopBackground.dtd (%chrome/browser/setDesktopBackground.dtd)
|
||||
@ -65,6 +66,8 @@
|
||||
locale/browser/preferences/applicationManager.properties (%chrome/browser/preferences/applicationManager.properties)
|
||||
locale/browser/preferences/applications.dtd (%chrome/browser/preferences/applications.dtd)
|
||||
locale/browser/preferences/blocklists.dtd (%chrome/browser/preferences/blocklists.dtd)
|
||||
locale/browser/preferences/clearSiteData.dtd (%chrome/browser/preferences/clearSiteData.dtd)
|
||||
locale/browser/preferences/clearSiteData.properties (%chrome/browser/preferences/clearSiteData.properties)
|
||||
locale/browser/preferences/colors.dtd (%chrome/browser/preferences/colors.dtd)
|
||||
locale/browser/preferences/connection.dtd (%chrome/browser/preferences/connection.dtd)
|
||||
locale/browser/preferences/containers.dtd (%chrome/browser/preferences/containers.dtd)
|
||||
|
Loading…
Reference in New Issue
Block a user