Bug 1102295 - Get country data on the Mac. r=bsmedberg ba=bsmedberg a=lsblakk
authorSteven Michaud <smichaud@pobox.com>
Mon, 22 Dec 2014 11:45:12 -0600
changeset 234304 caf2307e96a3dbfab5b750f126c216abe4e8b3ba
parent 234303 fcc69cd836bf14a83e098c291ea409d4815653bd
child 234305 d88622dd662221ecc98263b8b7a5cbd071bc36c6
push id4261
push usersmichaud@pobox.com
push dateMon, 22 Dec 2014 17:45:59 +0000
treeherdermozilla-beta@caf2307e96a3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg, lsblakk
bugs1102295
milestone35.0
Bug 1102295 - Get country data on the Mac. r=bsmedberg ba=bsmedberg a=lsblakk
widget/cocoa/GfxInfo.h
widget/cocoa/GfxInfo.mm
widget/moz.build
widget/nsIGfxInfo2.idl
widget/xpwidgets/GfxInfoBase.cpp
widget/xpwidgets/GfxInfoBase.h
--- 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
@@ -26,16 +26,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;
+};
+
--- a/widget/xpwidgets/GfxInfoBase.cpp
+++ b/widget/xpwidgets/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/xpwidgets/GfxInfoBase.h
+++ b/widget/xpwidgets/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();