Bug 1253010 - part 2 - provide a non-XPCOM way to create new nsIDateTimeFormat instances; r=smontagu
authorNathan Froyd <froydnj@mozilla.com>
Sat, 05 Dec 2015 10:30:53 -0500
changeset 287373 22d7c93ec6579884fa9468e5f5503387cb23cc0a
parent 287372 d3bc99831ce627675c2efbb168ebd5b82b4ff7ee
child 287374 051996f609673e75383fbf6fd44e5babb2275f0f
push id30068
push usercbook@mozilla.com
push dateWed, 09 Mar 2016 10:46:58 +0000
treeherdermozilla-central@af7c0cb0798f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmontagu
bugs1253010
milestone47.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 1253010 - part 2 - provide a non-XPCOM way to create new nsIDateTimeFormat instances; r=smontagu To avoid hitting the component manager from the security manager, we need a way of creating nsIDateTimeFormat instances that don't go through the component manager. The only wrinkle is that these formatters are platform-dependent. Let's write a thin wrapper over nsIDateTimeFormat that abstracts away the platform details.
intl/locale/moz.build
intl/locale/nsIDateTimeFormat.cpp
intl/locale/nsIDateTimeFormat.h
--- a/intl/locale/moz.build
+++ b/intl/locale/moz.build
@@ -32,16 +32,17 @@ EXPORTS += [
     'nsILanguageAtomService.h',
     'nsIPlatformCharset.h',
     'nsPosixLocale.h',
     'nsWin32Locale.h',
 ]
 
 UNIFIED_SOURCES += [
     'nsCollation.cpp',
+    'nsIDateTimeFormat.cpp',
     'nsLanguageAtomService.cpp',
     'nsLocale.cpp',
     'nsLocaleService.cpp',
     'nsScriptableDateFormat.cpp',
     'nsUConvPropertySearch.cpp',
 ]
 
 EXTRA_JS_MODULES += [
new file mode 100644
--- /dev/null
+++ b/intl/locale/nsIDateTimeFormat.cpp
@@ -0,0 +1,39 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 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/. */
+
+#include "nsIDateTimeFormat.h"
+#include "mozilla/RefPtr.h"
+
+#if defined(XP_MACOSX)
+#define USE_MAC_LOCALE
+#elif defined(XP_UNIX)
+#define USE_UNIX_LOCALE
+#endif
+
+#ifdef XP_WIN
+#include "windows/nsDateTimeFormatWin.h"
+#endif
+#ifdef USE_UNIX_LOCALE
+#include "unix/nsDateTimeFormatUnix.h"
+#endif
+#ifdef USE_MAC_LOCALE
+#include "mac/nsDateTimeFormatMac.h"
+#endif
+
+using mozilla::MakeAndAddRef;
+
+/*static*/ already_AddRefed<nsIDateTimeFormat>
+nsIDateTimeFormat::Create()
+{
+#ifdef XP_WIN
+  return MakeAndAddRef<nsDateTimeFormatWin>();
+#elif defined(USE_UNIX_LOCALE)
+  return MakeAndAddRef<nsDateTimeFormatUnix>();
+#elif defined(USE_MAC_LOCALE)
+  return MakeAndAddRef<nsDateTimeFormatMac>();
+#else
+  return nullptr;
+#endif
+}
--- a/intl/locale/nsIDateTimeFormat.h
+++ b/intl/locale/nsIDateTimeFormat.h
@@ -21,20 +21,25 @@
 #define NS_IDATETIMEFORMAT_IID \
 { 0x2bbaa0b0, 0xa591, 0x11d2, \
 { 0x91, 0x19, 0x0, 0x60, 0x8, 0xa6, 0xed, 0xf6 } }
 
 
 // Locale sensitive date and time format interface
 // 
 class nsIDateTimeFormat : public nsISupports {
+protected:
+  nsIDateTimeFormat() {}
+  virtual ~nsIDateTimeFormat() {}
 
 public: 
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDATETIMEFORMAT_IID)
 
+  static already_AddRefed<nsIDateTimeFormat> Create();
+
   // performs a locale sensitive date formatting operation on the time_t parameter
   NS_IMETHOD FormatTime(nsILocale* locale, 
                         const nsDateFormatSelector  dateFormatSelector, 
                         const nsTimeFormatSelector timeFormatSelector, 
                         const time_t  timetTime,
                         nsAString& stringOut) = 0; 
 
   // performs a locale sensitive date formatting operation on the struct tm parameter