Bug 1460768 - Part 3 - Update consumers of SiteDataManager.jsm.
MozReview-Commit-ID: 51Zbg0ZtrUv
--- a/browser/base/content/browser-siteIdentity.js
+++ b/browser/base/content/browser-siteIdentity.js
@@ -206,29 +206,23 @@ var gIdentityHandler = {
permissionAnchors[anchor.getAttribute("data-permission-id")] = anchor;
}
return this._permissionAnchors = permissionAnchors;
},
/**
* Handles clicks on the "Clear Cookies and Site Data" button.
*/
- async clearSiteData(event) {
+ clearSiteData(event) {
if (!this._uriHasHost) {
return;
}
- let host = this._uri.host;
-
- // Site data could have changed while the identity popup was open,
- // reload again to be sure.
- await SiteDataManager.updateSites();
-
- let baseDomain = SiteDataManager.getBaseDomainFromHost(host);
- let siteData = await SiteDataManager.getSites(baseDomain);
+ let baseDomain = SiteDataManager.getBaseDomainFromHost(this._uri.host);
+ let siteData = SiteDataManager.getSites(baseDomain);
// Hide the popup before showing the removal prompt, to
// avoid a pretty ugly transition. Also hide it even
// if the update resulted in no site data, to keep the
// illusion that clicking the button had an effect.
PanelMultiView.hidePopup(this._identityPopup);
if (siteData && siteData.length) {
@@ -609,24 +603,22 @@ var gIdentityHandler = {
* applicable
*/
refreshIdentityPopup() {
// Update cookies and site data information and show the
// "Clear Site Data" button if the site is storing local data.
this._clearSiteDataFooter.hidden = true;
if (this._uriHasHost) {
let host = this._uri.host;
- SiteDataManager.updateSites().then(async () => {
- let baseDomain = SiteDataManager.getBaseDomainFromHost(host);
- let siteData = await SiteDataManager.getSites(baseDomain);
+ let baseDomain = SiteDataManager.getBaseDomainFromHost(host);
+ let siteData = SiteDataManager.getSites(baseDomain);
- if (siteData && siteData.length) {
- this._clearSiteDataFooter.hidden = false;
- }
- });
+ if (siteData && siteData.length) {
+ this._clearSiteDataFooter.hidden = false;
+ }
}
// Update "Learn More" for Mixed Content Blocking and Insecure Login Forms.
let baseURL = Services.urlFormatter.formatURLPref("app.support.baseURL");
this._identityPopupMixedContentLearnMore
.setAttribute("href", baseURL + "mixed-content");
this._identityPopupInsecureLoginFormsLearnMore
.setAttribute("href", baseURL + "insecure-password");
--- a/browser/base/content/pageinfo/security.js
+++ b/browser/base/content/pageinfo/security.js
@@ -127,19 +127,19 @@ var security = {
// Find the secureBrowserUI object (if present)
_getSecurityUI() {
if (window.opener.gBrowser)
return window.opener.gBrowser.securityUI;
return null;
},
- async _updateSiteDataInfo() {
+ _updateSiteDataInfo() {
// Save site data info for deleting.
- this.siteData = await SiteDataManager.getSites(
+ this.siteData = SiteDataManager.getSites(
SiteDataManager.getBaseDomainFromHost(this.uri.host));
let pageInfoBundle = document.getElementById("pageinfobundle");
let clearSiteDataButton = document.getElementById("security-clear-sitedata");
let siteDataLabel = document.getElementById("security-privacy-sitedata-value");
if (!this.siteData.length) {
let noStr = pageInfoBundle.getString("securitySiteDataNo");
@@ -246,17 +246,17 @@ function securityOnLoad(uri, windowInfo)
viewCert.collapsed = true;
/* Set Privacy & History section text */
var yesStr = pageInfoBundle.getString("yes");
var noStr = pageInfoBundle.getString("no");
// Only show quota usage data for websites, not internal sites.
if (uri.scheme == "http" || uri.scheme == "https") {
- SiteDataManager.updateSites().then(() => security._updateSiteDataInfo());
+ security._updateSiteDataInfo();
} else {
document.getElementById("security-privacy-sitedata-row").hidden = true;
}
setText("security-privacy-passwords-value",
realmHasPasswords(uri) ? yesStr : noStr);
var visitCount = previousVisitCount(info.hostName);
--- a/browser/components/preferences/clearSiteData.js
+++ b/browser/components/preferences/clearSiteData.js
@@ -17,30 +17,28 @@ var gClearSiteDataDialog = {
},
async init() {
this._clearButton = document.getElementById("clearButton");
this._cancelButton = document.getElementById("cancelButton");
this._clearSiteDataCheckbox = document.getElementById("clearSiteData");
this._clearCacheCheckbox = document.getElementById("clearCache");
- // We'll block init() on this because the result values may impact
- // subdialog sizing.
- await Promise.all([
- SiteDataManager.getTotalUsage().then(bytes => {
- let [amount, unit] = DownloadUtils.convertByteUnits(bytes);
- document.l10n.setAttributes(this._clearSiteDataCheckbox,
- "clear-site-data-cookies-with-data", { amount, unit });
- }),
- SiteDataManager.getCacheSize().then(bytes => {
- let [amount, unit] = DownloadUtils.convertByteUnits(bytes);
- document.l10n.setAttributes(this._clearCacheCheckbox,
- "clear-site-data-cache-with-data", { amount, unit });
- }),
- ]);
+ // Show quota managed storage size in parentheses.
+ let bytes = SiteDataManager.getTotalUsage();
+ let [amount, unit] = DownloadUtils.convertByteUnits(bytes);
+ document.l10n.setAttributes(this._clearSiteDataCheckbox,
+ "clear-site-data-cookies-with-data", { amount, unit });
+
+ // Show cache size in parentheses.
+ bytes = await SiteDataManager.getCacheSize();
+ [amount, unit] = DownloadUtils.convertByteUnits(bytes);
+ document.l10n.setAttributes(this._clearCacheCheckbox,
+ "clear-site-data-cache-with-data", { amount, unit });
+
await document.l10n.translateElements([
this._clearCacheCheckbox,
this._clearSiteDataCheckbox
]);
window.addEventListener("keypress", this.onWindowKeyPress);
this._cancelButton.addEventListener("command", window.close);
@@ -60,20 +58,20 @@ var gClearSiteDataDialog = {
!(this._clearSiteDataCheckbox.checked || this._clearCacheCheckbox.checked);
},
onClear() {
let allowed = true;
if (this._clearCacheCheckbox.checked && allowed) {
SiteDataManager.removeCache();
- // If we're not clearing site data, we need to tell the
- // SiteDataManager to signal that it's updating.
+ // If the site data manager will not update site data or cookies,
+ // we need to manually signal the preferences UI that it should update.
if (!this._clearSiteDataCheckbox.checked) {
- SiteDataManager.updateSites();
+ Services.obs.notifyObservers(null, "sitedatamanager:sites-updated");
}
}
if (this._clearSiteDataCheckbox.checked) {
allowed = SiteDataManager.promptSiteDataRemoval(window);
if (allowed) {
SiteDataManager.removeSiteData();
}
--- a/browser/components/preferences/in-content/privacy.js
+++ b/browser/components/preferences/in-content/privacy.js
@@ -357,24 +357,23 @@ var gPrivacyPane = {
if (AlertsServiceDND.manualDoNotDisturb) {
let notificationsDoNotDisturb =
document.getElementById("notificationsDoNotDisturb");
notificationsDoNotDisturb.setAttribute("checked", true);
}
}
Services.obs.addObserver(this, "sitedatamanager:sites-updated");
- Services.obs.addObserver(this, "sitedatamanager:updating-sites");
let unload = () => {
window.removeEventListener("unload", unload);
Services.obs.removeObserver(this, "sitedatamanager:sites-updated");
- Services.obs.removeObserver(this, "sitedatamanager:updating-sites");
};
window.addEventListener("unload", unload);
- SiteDataManager.updateSites();
+ this.updateTotalDataSizeLabel();
+
setEventListener("clearSiteDataButton", "command",
gPrivacyPane.clearSiteData);
setEventListener("siteDataSettings", "command",
gPrivacyPane.showSiteDataSettings);
let url = Services.urlFormatter.formatURLPref("app.support.baseURL") + "storage-permissions";
document.getElementById("siteDataLearnMoreLink").setAttribute("href", url);
let notificationInfoURL =
@@ -1014,29 +1013,18 @@ var gPrivacyPane = {
gSubDialog.open("chrome://browser/content/preferences/permissions.xul",
null, params);
},
showSiteDataSettings() {
gSubDialog.open("chrome://browser/content/preferences/siteDataSettings.xul");
},
- toggleSiteData(shouldShow) {
- let clearButton = document.getElementById("clearSiteDataButton");
- let settingsButton = document.getElementById("siteDataSettings");
- clearButton.disabled = !shouldShow;
- settingsButton.disabled = !shouldShow;
- },
-
- showSiteDataLoading() {
- let totalSiteDataSizeLabel = document.getElementById("totalSiteDataSize");
- document.l10n.setAttributes(totalSiteDataSizeLabel, "sitedata-total-size-calculating");
- },
-
- updateTotalDataSizeLabel(siteDataUsage) {
+ updateTotalDataSizeLabel() {
+ let siteDataUsage = SiteDataManager.getTotalUsage();
SiteDataManager.getCacheSize().then(function(cacheUsage) {
let totalSiteDataSizeLabel = document.getElementById("totalSiteDataSize");
let totalUsage = siteDataUsage + cacheUsage;
let [value, unit] = DownloadUtils.convertByteUnits(totalUsage);
document.l10n.setAttributes(totalSiteDataSizeLabel, "sitedata-total-size", {
value,
unit
});
@@ -1619,26 +1607,18 @@ var gPrivacyPane = {
}
}
Preferences.get(PREF_UPLOAD_ENABLED).on("change", updateStudyCheckboxState);
updateStudyCheckboxState();
},
observe(aSubject, aTopic, aData) {
switch (aTopic) {
- case "sitedatamanager:updating-sites":
- // While updating, we want to disable this section and display loading message until updated
- this.toggleSiteData(false);
- this.showSiteDataLoading();
- break;
-
case "sitedatamanager:sites-updated":
- this.toggleSiteData(true);
- SiteDataManager.getTotalUsage()
- .then(this.updateTotalDataSizeLabel.bind(this));
+ this.updateTotalDataSizeLabel();
break;
}
},
// Accessibility checkbox helpers
_initA11yState() {
this._initA11yString();
let checkbox = document.getElementById("a11yPrivacyCheckbox");
--- a/browser/components/preferences/siteDataSettings.js
+++ b/browser/components/preferences/siteDataSettings.js
@@ -92,55 +92,69 @@ let gSiteDataSettings = {
this._absoluteTimeFormat = new Services.intl.DateTimeFormat(undefined, {
dateStyle: "short", timeStyle: "short",
});
this._relativeTimeFormat = new Services.intl.RelativeTimeFormat(undefined, {});
this._list = document.getElementById("sitesList");
this._searchBox = document.getElementById("searchBox");
- SiteDataManager.getSites().then(sites => {
- this._sites = sites;
- let sortCol = document.querySelector("treecol[data-isCurrentSortCol=true]");
- this._sortSites(this._sites, sortCol);
- this._buildSitesList(this._sites);
- Services.obs.notifyObservers(null, "sitedata-settings-init");
- });
+ this._sites = SiteDataManager.getSites();
+ let sortCol = document.querySelector("treecol[data-isCurrentSortCol=true]");
+ this._sortSites(this._sites, sortCol, true);
+ this._buildSitesList(this._sites);
+ Services.obs.notifyObservers(null, "sitedata-settings-init");
+
+ Services.obs.addObserver(this, "sitedatamanager:sites-updated");
setEventListener("sitesList", "select", this.onSelect);
setEventListener("hostCol", "click", this.onClickTreeCol);
setEventListener("usageCol", "click", this.onClickTreeCol);
setEventListener("lastAccessedCol", "click", this.onClickTreeCol);
setEventListener("cookiesCol", "click", this.onClickTreeCol);
setEventListener("cancel", "command", this.close);
setEventListener("save", "command", this.saveChanges);
setEventListener("searchBox", "command", this.onCommandSearch);
setEventListener("removeAll", "command", this.onClickRemoveAll);
setEventListener("removeSelected", "command", this.onClickRemoveSelected);
},
+ uninit() {
+ Services.obs.removeObserver(this, "sitedatamanager:sites-updated");
+ },
+
+ observe(subject, topic, data) {
+ if (topic != "sitedatamanager:sites-updated") {
+ return;
+ }
+ this._sites = SiteDataManager.getSites();
+ let sortCol = document.querySelector("treecol[data-isCurrentSortCol=true]");
+ this._sortSites(this._sites, sortCol, false);
+ this._buildSitesList(this._sites);
+ },
+
_updateButtonsState() {
let items = this._list.getElementsByTagName("richlistitem");
let removeSelectedBtn = document.getElementById("removeSelected");
let removeAllBtn = document.getElementById("removeAll");
removeSelectedBtn.disabled = this._list.selectedItems.length == 0;
removeAllBtn.disabled = items.length == 0;
let l10nId = this._searchBox.value ? "site-data-remove-shown" : "site-data-remove-all";
document.l10n.setAttributes(removeAllBtn, l10nId);
},
/**
* @param sites {Array}
* @param col {XULElement} the <treecol> being sorted on
*/
- _sortSites(sites, col) {
+ _sortSites(sites, col, flipDirection) {
let isCurrentSortCol = col.getAttribute("data-isCurrentSortCol");
let sortDirection = col.getAttribute("data-last-sortDirection") || "ascending";
- if (isCurrentSortCol) {
+ if (flipDirection && isCurrentSortCol) {
// Sort on the current column, flip the sorting direction
sortDirection = sortDirection === "ascending" ? "descending" : "ascending";
}
let sortFunc = null;
switch (col.id) {
case "hostCol":
sortFunc = (a, b) => {
@@ -249,17 +263,17 @@ let gSiteDataSettings = {
}
},
close() {
window.close();
},
onClickTreeCol(e) {
- this._sortSites(this._sites, e.target);
+ this._sortSites(this._sites, e.target, true);
this._buildSitesList(this._sites);
this._list.clearSelection();
},
onCommandSearch() {
this._buildSitesList(this._sites);
this._list.clearSelection();
},
--- a/browser/components/preferences/siteDataSettings.xul
+++ b/browser/components/preferences/siteDataSettings.xul
@@ -11,16 +11,17 @@
<window id="SiteDataSettingsDialog" windowtype="Browser:SiteDataSettings"
data-l10n-id="site-data-settings-window"
data-l10n-attrs="title"
class="windowDialog"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
style="width: 45em;"
onload="gSiteDataSettings.init();"
+ onunload="gSiteDataSettings.uninit();"
onkeypress="gSiteDataSettings.onKeyPress(event);"
persist="screenX screenY width height">
<link rel="localization" href="branding/brand.ftl"/>
<link rel="localization" href="browser/preferences/siteDataSettings.ftl"/>
<script type="application/javascript" src="chrome://global/content/l10n.js"></script>
<script src="chrome://browser/content/preferences/siteDataSettings.js"/>