Bug 1102295 - Get country data on the Mac. r=bsmedberg
authorSteven Michaud <smichaud@pobox.com>
Fri, 21 Nov 2014 18:23:09 -0600
changeset 241291 d0d36a9b8b7d9dfbd1dd78d3b926a75ad7298c8b
parent 241290 fcf715632ae005b3fae926661a9ef01fb855db60
child 241292 281d52f5d0e65f3071b6314ad8be2253cc593038
push id4311
push userraliiev@mozilla.com
push dateMon, 12 Jan 2015 19:37:41 +0000
treeherdermozilla-beta@150c9fed433b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs1102295
milestone36.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 1102295 - Get country data on the Mac. r=bsmedberg
widget/GfxInfoBase.cpp
widget/GfxInfoBase.h
widget/cocoa/GfxInfo.h
widget/cocoa/GfxInfo.mm
widget/moz.build
widget/nsIGfxInfo2.idl
--- a/widget/GfxInfoBase.cpp
+++ b/widget/GfxInfoBase.cpp
@@ -85,17 +85,21 @@ void InitGfxDriverInfoShutdownObserver()
 
   ShutdownObserver *obs = new ShutdownObserver();
   observerService->AddObserver(obs, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
 }
 
 using namespace mozilla::widget;
 using namespace mozilla;
 
+#ifdef XP_MACOSX
+NS_IMPL_ISUPPORTS(GfxInfoBase, nsIGfxInfo, nsIGfxInfo2, nsIObserver, nsISupportsWeakReference)
+#else
 NS_IMPL_ISUPPORTS(GfxInfoBase, nsIGfxInfo, nsIObserver, nsISupportsWeakReference)
+#endif
 
 #define BLACKLIST_PREF_BRANCH "gfx.blacklist."
 #define SUGGESTED_VERSION_PREF BLACKLIST_PREF_BRANCH "suggested-driver-version"
 #define BLACKLIST_ENTRY_TAG_NAME "gfxBlacklistEntry"
 
 static const char*
 GetPrefNameForFeature(int32_t aFeature)
 {
--- a/widget/GfxInfoBase.h
+++ b/widget/GfxInfoBase.h
@@ -4,32 +4,38 @@
  * 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/. */
 
 #ifndef __mozilla_widget_GfxInfoBase_h__
 #define __mozilla_widget_GfxInfoBase_h__
 
 #include "nsIGfxInfo.h"
+#ifdef XP_MACOSX
+#include "nsIGfxInfo2.h"
+#endif
 #include "nsCOMPtr.h"
 #include "nsIObserver.h"
 #include "nsWeakReference.h"
 #include "GfxDriverInfo.h"
 #include "nsTArray.h"
 #include "nsString.h"
 #include "GfxInfoCollector.h"
 #include "nsIGfxInfoDebug.h"
 #include "mozilla/Mutex.h"
 #include "js/Value.h"
 #include "mozilla/Attributes.h"
 
 namespace mozilla {
 namespace widget {  
 
 class GfxInfoBase : public nsIGfxInfo,
+#ifdef XP_MACOSX
+                    public nsIGfxInfo2,
+#endif
                     public nsIObserver,
                     public nsSupportsWeakReference
 #ifdef DEBUG
                   , public nsIGfxInfoDebug
 #endif
 {
 public:
   GfxInfoBase();
--- a/widget/cocoa/GfxInfo.h
+++ b/widget/cocoa/GfxInfo.h
@@ -4,16 +4,17 @@
  * 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/. */
 
 #ifndef __mozilla_widget_GfxInfo_h__
 #define __mozilla_widget_GfxInfo_h__
 
 #include "GfxInfoBase.h"
+#include "nsIGfxInfo2.h"
 
 #include "nsString.h"
 
 namespace mozilla {
 namespace widget {
 
 class GfxInfo : public GfxInfoBase
 {
@@ -45,20 +46,21 @@ public:
   NS_IMETHOD GetIsGPU2Active(bool *aIsGPU2Active);
 
   using GfxInfoBase::GetFeatureStatus;
   using GfxInfoBase::GetFeatureSuggestedDriverVersion;
   using GfxInfoBase::GetWebGLParameter;
 
   virtual nsresult Init();
 
+  NS_DECL_ISUPPORTS_INHERITED
 #ifdef DEBUG
-  NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIGFXINFODEBUG
 #endif
+  NS_DECL_NSIGFXINFO2
 
   virtual uint32_t OperatingSystemVersion() MOZ_OVERRIDE { return mOSXVersion; }
 
 protected:
 
   virtual ~GfxInfo() {}
 
   virtual nsresult GetFeatureStatusImpl(int32_t aFeature, 
@@ -66,26 +68,29 @@ protected:
                                         nsAString & aSuggestedDriverVersion, 
                                         const nsTArray<GfxDriverInfo>& aDriverInfo,
                                         OperatingSystem* aOS = nullptr);
   virtual const nsTArray<GfxDriverInfo>& GetGfxDriverInfo();
 
 private:
 
   void GetDeviceInfo();
+  void GetSelectedCityInfo();
   void AddCrashReportAnnotations();
 
   nsString mAdapterRAMString;
   nsString mDeviceID;
   nsString mDriverVersion;
   nsString mDriverDate;
   nsString mDeviceKey;
 
   nsString mAdapterVendorID;
   nsString mAdapterDeviceID;
 
+  nsString mCountryCode;
+
   uint32_t mOSXVersion;
 };
 
 } // namespace widget
 } // namespace mozilla
 
 #endif /* __mozilla_widget_GfxInfo_h__ */
--- a/widget/cocoa/GfxInfo.mm
+++ b/widget/cocoa/GfxInfo.mm
@@ -29,17 +29,19 @@
 #define MAC_OS_X_VERSION_10_6_HEX   0x00001060
 #define MAC_OS_X_VERSION_10_7_HEX   0x00001070
 #define MAC_OS_X_VERSION_10_8_HEX   0x00001080
 
 using namespace mozilla;
 using namespace mozilla::widget;
 
 #ifdef DEBUG
-NS_IMPL_ISUPPORTS_INHERITED(GfxInfo, GfxInfoBase, nsIGfxInfoDebug)
+NS_IMPL_ISUPPORTS_INHERITED(GfxInfo, GfxInfoBase, nsIGfxInfo2, nsIGfxInfoDebug)
+#else
+NS_IMPL_ISUPPORTS_INHERITED(GfxInfo, GfxInfoBase, nsIGfxInfo2)
 #endif
 
 GfxInfo::GfxInfo()
 {
 }
 
 static OperatingSystem
 OSXVersionToOperatingSystem(uint32_t aOSXVersion)
@@ -91,27 +93,43 @@ GfxInfo::GetDeviceInfo()
   }
   CFTypeRef device_id_ref = SearchPortForProperty(dsp_port, CFSTR("device-id"));
   if (device_id_ref) {
     mAdapterDeviceID.AppendPrintf("0x%4x", IntValueOfCFData((CFDataRef)device_id_ref));
     CFRelease(device_id_ref);
   }
 }
 
+void
+GfxInfo::GetSelectedCityInfo()
+{
+  NSDictionary* selected_city =
+    [[NSUserDefaults standardUserDefaults]
+      objectForKey:@"com.apple.preferences.timezone.selected_city"];
+  NSString *countryCode = (NSString *)
+    [selected_city objectForKey:@"CountryCode"];
+  const char *countryCodeUTF8 = [countryCode UTF8String];
+  if (countryCodeUTF8) {
+    AppendUTF8toUTF16(countryCodeUTF8, mCountryCode);
+  }
+}
+
 nsresult
 GfxInfo::Init()
 {
   nsresult rv = GfxInfoBase::Init();
 
   // Calling CGLQueryRendererInfo causes us to switch to the discrete GPU
   // even when we don't want to. We'll avoid doing so for now and just
   // use the device ids.
 
   GetDeviceInfo();
 
+  GetSelectedCityInfo();
+
   AddCrashReportAnnotations();
 
   mOSXVersion = nsCocoaFeatures::OSXVersion();
 
   return rv;
 }
 
 NS_IMETHODIMP
@@ -261,16 +279,25 @@ GfxInfo::GetAdapterSubsysID2(nsAString &
 
 /* readonly attribute boolean isGPU2Active; */
 NS_IMETHODIMP
 GfxInfo::GetIsGPU2Active(bool* aIsGPU2Active)
 {
   return NS_ERROR_FAILURE;
 }
 
+/* interface nsIGfxInfo2 */
+/* readonly attribute DOMString countryCode; */
+NS_IMETHODIMP
+GfxInfo::GetCountryCode(nsAString & aCountryCode)
+{
+  aCountryCode = mCountryCode;
+  return NS_OK;
+}
+
 void
 GfxInfo::AddCrashReportAnnotations()
 {
 #if defined(MOZ_CRASHREPORTER)
   nsString deviceID, vendorID, driverVersion;
   nsAutoCString narrowDeviceID, narrowVendorID, narrowDriverVersion;
 
   GetAdapterDeviceID(deviceID);
--- a/widget/moz.build
+++ b/widget/moz.build
@@ -24,16 +24,17 @@ if toolkit == 'windows':
         'nsITaskbarPreviewController.idl',
         'nsITaskbarProgress.idl',
         'nsITaskbarTabPreview.idl',
         'nsITaskbarWindowPreview.idl',
         'nsIWinTaskbar.idl',
     ]
 elif toolkit == 'cocoa':
     XPIDL_SOURCES += [
+        'nsIGfxInfo2.idl',
         'nsIMacDockSupport.idl',
         'nsIMacWebAppUtils.idl',
         'nsIStandaloneNativeMenu.idl',
         'nsISystemStatusBar.idl',
         'nsITaskbarProgress.idl',
     ]
     EXPORTS += [
         'nsINativeMenuService.h',
new file mode 100644
--- /dev/null
+++ b/widget/nsIGfxInfo2.idl
@@ -0,0 +1,24 @@
+/* -*- Mode: IDL; 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 "nsISupports.idl"
+
+/**
+ * nsIGfxInfo2 is a separately implemented extension of nsIGfxInfo, to
+ * allow us (in effect) to tack things onto the nsIGfxInfo interface
+ * without changing it.
+ */
+
+[scriptable, uuid(9C8D8F44-6D52-45AA-8921-734EF4DF5DFE)]
+interface nsIGfxInfo2 : nsISupports
+{
+  /**
+   * Not really Gfx-related.  Here for convenience,
+   * possibly only temporarily.  See bug 1102295.
+   */
+  readonly attribute DOMString countryCode;
+};
+