mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-03 13:57:31 +09:00
Issue #1694 - Part 1: Use scriptabledateformat for the Cookie Accept dialog.
This commit is contained in:
parent
de6b427be4
commit
b6354a7a37
2 changed files with 26 additions and 6 deletions
|
|
@ -13,6 +13,7 @@ Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
|
||||||
|
|
||||||
var params;
|
var params;
|
||||||
var cookieBundle;
|
var cookieBundle;
|
||||||
|
var gDateService = null;
|
||||||
|
|
||||||
var showDetails = "";
|
var showDetails = "";
|
||||||
var hideDetails = "";
|
var hideDetails = "";
|
||||||
|
|
@ -38,6 +39,14 @@ function onload()
|
||||||
document.getElementById("cancel").setAttribute("icon", "cancel");
|
document.getElementById("cancel").setAttribute("icon", "cancel");
|
||||||
document.getElementById("disclosureButton").setAttribute("icon", "properties");
|
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");
|
cookieBundle = document.getElementById("cookieBundle");
|
||||||
|
|
||||||
// cache strings
|
// cache strings
|
||||||
|
|
@ -174,12 +183,21 @@ function cookieDeny()
|
||||||
function GetExpiresString(secondsUntilExpires) {
|
function GetExpiresString(secondsUntilExpires) {
|
||||||
if (secondsUntilExpires) {
|
if (secondsUntilExpires) {
|
||||||
var date = new Date(1000*secondsUntilExpires);
|
var date = new Date(1000*secondsUntilExpires);
|
||||||
const locale = Components.classes["@mozilla.org/chrome/chrome-registry;1"]
|
|
||||||
.getService(Components.interfaces.nsIXULChromeRegistry)
|
// if a server manages to set a really long-lived cookie, the dateservice
|
||||||
.getSelectedLocale("global", true);
|
// can't cope with it properly, so we'll return a descriptive string instead.
|
||||||
const dtOptions = { year: 'numeric', month: 'long', day: 'numeric',
|
var expiry = "";
|
||||||
hour: 'numeric', minute: 'numeric', second: 'numeric' };
|
try {
|
||||||
return date.toLocaleString(locale, dtOptions);
|
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");
|
return cookieBundle.getString("expireAtEndOfSession");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ domainColon=Domain:
|
||||||
forSecureOnly=Encrypted connections only
|
forSecureOnly=Encrypted connections only
|
||||||
forAnyConnection=Any type of connection
|
forAnyConnection=Any type of connection
|
||||||
expireAtEndOfSession=At end of session
|
expireAtEndOfSession=At end of session
|
||||||
|
# LOCALIZATION NOTE (expireInAVeryLongTime) This string is used if a cookie won't expire for a literal life age and then some.
|
||||||
|
expireInAVeryLongTime=Not in your lifetime
|
||||||
|
|
||||||
showDetails=Show Details
|
showDetails=Show Details
|
||||||
hideDetails=Hide Details
|
hideDetails=Hide Details
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue