Bug 1301655 - pt 5 - Replace use of nsIScriptableDateFormat for cookie date formatting. r=gandalf
authorJonathan Kew <jkew@mozilla.com>
Fri, 28 Oct 2016 12:04:07 +0100
changeset 319933 48e81da5a95b8b2c53213a3675ce20d86df87a35
parent 319932 59f24ab7fc079e573cbdb2fb8d828a951639e62a
child 319934 17efbf713de8bb8f672340ef87cf0e78e5565232
push id83271
push userjkew@mozilla.com
push dateFri, 28 Oct 2016 11:07:26 +0000
treeherdermozilla-inbound@686282bd2f19 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgandalf
bugs1301655
milestone52.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1301655 - pt 5 - Replace use of nsIScriptableDateFormat for cookie date formatting. r=gandalf
browser/components/preferences/cookies.js
toolkit/components/cookie/content/cookieAcceptDialog.js
--- a/browser/components/preferences/cookies.js
+++ b/browser/components/preferences/cookies.js
@@ -11,18 +11,16 @@ Components.utils.import("resource://gre/
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "ContextualIdentityService",
                                   "resource://gre/modules/ContextualIdentityService.jsm");
 
 var gCookiesWindow = {
   _cm               : Components.classes["@mozilla.org/cookiemanager;1"]
                                 .getService(Components.interfaces.nsICookieManager),
-  _ds               : Components.classes["@mozilla.org/intl/scriptabledateformat;1"]
-                                .getService(Components.interfaces.nsIScriptableDateFormat),
   _hosts            : {},
   _hostOrder        : [],
   _tree             : null,
   _bundle           : null,
 
   init: function () {
     var os = Components.classes["@mozilla.org/observer-service;1"]
                        .getService(Components.interfaces.nsIObserverService);
@@ -508,24 +506,22 @@ var gCookiesWindow = {
         break;
     }
     this._view._rowCount = hostCount.value;
   },
 
   formatExpiresString: function (aExpires) {
     if (aExpires) {
       var date = new Date(1000 * aExpires);
-      return this._ds.FormatDateTime("", this._ds.dateFormatLong,
-                                     this._ds.timeFormatSeconds,
-                                     date.getFullYear(),
-                                     date.getMonth() + 1,
-                                     date.getDate(),
-                                     date.getHours(),
-                                     date.getMinutes(),
-                                     date.getSeconds());
+      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);
     }
     return this._bundle.getString("expireAtEndOfSession");
   },
 
   _getUserContextString: function(aUserContextId) {
     if (parseInt(aUserContextId) == 0) {
       return this._bundle.getString("defaultUserContextLabel");
     }
--- a/toolkit/components/cookie/content/cookieAcceptDialog.js
+++ b/toolkit/components/cookie/content/cookieAcceptDialog.js
@@ -8,17 +8,16 @@ const nsICookieAcceptDialog = Components
 const nsIDialogParamBlock = Components.interfaces.nsIDialogParamBlock;
 const nsICookie = Components.interfaces.nsICookie;
 const nsICookiePromptService = Components.interfaces.nsICookiePromptService;
 
 Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
 
 var params;
 var cookieBundle;
-var gDateService = null;
 
 var showDetails = "";
 var hideDetails = "";
 var detailsAccessKey = "";
 
 function onload()
 {
   doSetOKCancel(cookieAcceptNormal, cookieDeny, cookieAcceptSession);
@@ -34,23 +33,16 @@ function onload()
   document.getElementById("cancel").label = dialog.getAttribute("cancelLabel");
   document.getElementById("cancel").accessKey = dialog.getAttribute("cancelKey");
 
   // hook up button icons where implemented
   document.getElementById("ok").setAttribute("icon", "accept");
   document.getElementById("cancel").setAttribute("icon", "cancel");
   document.getElementById("disclosureButton").setAttribute("icon", "properties");
 
-  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
   if (!showDetails) {
     showDetails = cookieBundle.getString('showDetails');
   }
   if (!hideDetails) {
     hideDetails = cookieBundle.getString('hideDetails');
@@ -178,26 +170,17 @@ function cookieDeny()
   // And remember that when needed
   params.SetInt(nsICookieAcceptDialog.REMEMBER_DECISION, document.getElementById('persistDomainAcceptance').checked);
   window.close();
 }
 
 function GetExpiresString(secondsUntilExpires) {
   if (secondsUntilExpires) {
     var date = new Date(1000*secondsUntilExpires);
-
-    // if a server manages to set a really long-lived cookie, the dateservice
-    // can't cope with it properly, so we'll just return a blank string
-    // see bug 238045 for details
-    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) {
-      // do nothing
-    }
-    return expiry;
+    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);
   }
   return cookieBundle.getString("expireAtEndOfSession");
 }