diff options
author | Moonchild <moonchild@palemoon.org> | 2020-12-04 16:37:02 +0000 |
---|---|---|
committer | Moonchild <moonchild@palemoon.org> | 2020-12-13 18:13:49 +0000 |
commit | d0b7069d1c4416f5163a978822cb206281cb82c1 (patch) | |
tree | a67c679b989f2e391684ba73f97c40c678f7b115 /toolkit/components/cookie/content/cookieAcceptDialog.js | |
parent | 55dbbe4d16d9ce98323be40b1e7137698ff93735 (diff) | |
download | UXP-d0b7069d1c4416f5163a978822cb206281cb82c1.tar UXP-d0b7069d1c4416f5163a978822cb206281cb82c1.tar.gz UXP-d0b7069d1c4416f5163a978822cb206281cb82c1.tar.lz UXP-d0b7069d1c4416f5163a978822cb206281cb82c1.tar.xz UXP-d0b7069d1c4416f5163a978822cb206281cb82c1.zip |
Issue #1694 - Part 1: Use scriptabledateformat for the Cookie Accept dialog.
Diffstat (limited to 'toolkit/components/cookie/content/cookieAcceptDialog.js')
-rw-r--r-- | toolkit/components/cookie/content/cookieAcceptDialog.js | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/toolkit/components/cookie/content/cookieAcceptDialog.js b/toolkit/components/cookie/content/cookieAcceptDialog.js index 4b322e95d..5f5760305 100644 --- a/toolkit/components/cookie/content/cookieAcceptDialog.js +++ b/toolkit/components/cookie/content/cookieAcceptDialog.js @@ -13,6 +13,7 @@ Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm"); var params; var cookieBundle; +var gDateService = null; var showDetails = ""; var hideDetails = ""; @@ -38,6 +39,14 @@ function onload() document.getElementById("cancel").setAttribute("icon", "cancel"); document.getElementById("disclosureButton").setAttribute("icon", "properties"); + // Initialize the date formatter + if (!gDateService) { + const nsScriptableDateFormat_CONTRACTID = "@mozilla.org/intl/scriptabledateformat;1"; + const nsIScriptableDateFormat = Components.interfaces.nsIScriptableDateFormat; + gDateService = Components.classes[nsScriptableDateFormat_CONTRACTID] + .getService(nsIScriptableDateFormat); + } + cookieBundle = document.getElementById("cookieBundle"); // cache strings @@ -174,12 +183,21 @@ function cookieDeny() function GetExpiresString(secondsUntilExpires) { if (secondsUntilExpires) { var date = new Date(1000*secondsUntilExpires); - const locale = Components.classes["@mozilla.org/chrome/chrome-registry;1"] - .getService(Components.interfaces.nsIXULChromeRegistry) - .getSelectedLocale("global", true); - const dtOptions = { year: 'numeric', month: 'long', day: 'numeric', - hour: 'numeric', minute: 'numeric', second: 'numeric' }; - return date.toLocaleString(locale, dtOptions); +
+ // if a server manages to set a really long-lived cookie, the dateservice
+ // can't cope with it properly, so we'll return a descriptive string instead.
+ var expiry = "";
+ try {
+ expiry = gDateService.FormatDateTime("", gDateService.dateFormatLong,
+ gDateService.timeFormatSeconds,
+ date.getFullYear(), date.getMonth()+1,
+ date.getDate(), date.getHours(),
+ date.getMinutes(), date.getSeconds());
+ } catch (ex) {
+ // Expiry duration was out of range for the date formatter, meaning a silly long time.
+ expiry = cookieBundle.getString("expireInAVeryLongTime");
+ }
+ return expiry; } return cookieBundle.getString("expireAtEndOfSession"); } |