Bug 1102297: Obtain user GEOID from Windows; r=jimm
authorAaron Klotz <aklotz@mozilla.com>
Sun, 08 Feb 2015 14:29:13 -0700
changeset 255417 f74a7a410dd3e8ba6fdcf7bee0c48324c3b00be1
parent 255416 d4db645f077b917d959c6851cbfc24affeedea9b
child 255418 f6fde9d79acf40f027c5f5356aaebc15e6c5a0b7
push id4610
push userjlund@mozilla.com
push dateMon, 30 Mar 2015 18:32:55 +0000
treeherdermozilla-beta@4df54044d9ef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm
bugs1102297
milestone38.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 1102297: Obtain user GEOID from Windows; r=jimm
widget/GfxInfoBase.h
widget/moz.build
widget/windows/GfxInfo.cpp
widget/windows/GfxInfo.h
--- a/widget/GfxInfoBase.h
+++ b/widget/GfxInfoBase.h
@@ -4,17 +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_GfxInfoBase_h__
 #define __mozilla_widget_GfxInfoBase_h__
 
 #include "nsIGfxInfo.h"
-#ifdef XP_MACOSX
+#if defined(XP_MACOSX) || defined(XP_WIN)
 #include "nsIGfxInfo2.h"
 #endif
 #include "nsCOMPtr.h"
 #include "nsIObserver.h"
 #include "nsWeakReference.h"
 #include "GfxDriverInfo.h"
 #include "nsTArray.h"
 #include "nsString.h"
@@ -23,17 +23,17 @@
 #include "mozilla/Mutex.h"
 #include "js/Value.h"
 #include "mozilla/Attributes.h"
 
 namespace mozilla {
 namespace widget {  
 
 class GfxInfoBase : public nsIGfxInfo,
-#ifdef XP_MACOSX
+#if defined(XP_MACOSX) || defined(XP_WIN)
                     public nsIGfxInfo2,
 #endif
                     public nsIObserver,
                     public nsSupportsWeakReference
 #ifdef DEBUG
                   , public nsIGfxInfoDebug
 #endif
 {
--- a/widget/moz.build
+++ b/widget/moz.build
@@ -10,16 +10,17 @@ if toolkit in ('cocoa', 'qt', 'android',
     DIRS += [toolkit]
 if toolkit in ('qt', 'android', 'gonk', 'gtk2', 'gtk3'):
     EXPORTS += ['nsIPrintDialogService.h']
 
 if toolkit == 'windows':
     DIRS += ['windows']
 
     XPIDL_SOURCES += [
+        'nsIGfxInfo2.idl',
         'nsIJumpListBuilder.idl',
         'nsIJumpListItem.idl',
         'nsIPrintSettingsWin.idl',
         'nsITaskbarOverlayIconController.idl',
         'nsITaskbarPreview.idl',
         'nsITaskbarPreviewButton.idl',
         'nsITaskbarPreviewController.idl',
         'nsITaskbarProgress.idl',
--- a/widget/windows/GfxInfo.cpp
+++ b/widget/windows/GfxInfo.cpp
@@ -22,17 +22,19 @@
 #include "nsICrashReporter.h"
 #define NS_CRASHREPORTER_CONTRACTID "@mozilla.org/toolkit/crash-reporter;1"
 #endif
 
 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
 
 static const uint32_t allWindowsVersions = 0xffffffff;
 
 GfxInfo::GfxInfo()
  :  mWindowsVersion(0),
     mHasDualGPU(false),
     mIsGPU2Active(false)
@@ -544,16 +546,18 @@ GfxInfo::Init()
 
   const char *spoofedDevice = PR_GetEnv("MOZ_GFX_SPOOF_DEVICE_ID");
   if (spoofedDevice) {
     mAdapterDeviceID.AssignASCII(spoofedDevice);
   }
 
   AddCrashReportAnnotations();
 
+  GetCountryCode();
+
   return rv;
 }
 
 /* readonly attribute DOMString adapterDescription; */
 NS_IMETHODIMP
 GfxInfo::GetAdapterDescription(nsAString & aAdapterDescription)
 {
   aAdapterDescription = mDeviceString;
@@ -710,16 +714,25 @@ CheckForCiscoVPN() {
   result = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\Cisco Systems\\VPN Client", 0, KEY_QUERY_VALUE, &key);
   if (result == ERROR_SUCCESS) {
     RegCloseKey(key);
     CrashReporter::AppendAppNotesToCrashReport(NS_LITERAL_CSTRING("Cisco VPN\n"));
   }
 }
 #endif
 
+/* interface nsIGfxInfo2 */
+/* readonly attribute DOMString countryCode; */
+NS_IMETHODIMP
+GfxInfo::GetCountryCode(nsAString& aCountryCode)
+{
+  aCountryCode = mCountryCode;
+  return NS_OK;
+}
+
 void
 GfxInfo::AddCrashReportAnnotations()
 {
 #if defined(MOZ_CRASHREPORTER)
   CheckForCiscoVPN();
 
   if (mHasDriverVersionMismatch) {
     CrashReporter::AppendAppNotesToCrashReport(NS_LITERAL_CSTRING("DriverVersionMismatch\n"));
@@ -791,16 +804,38 @@ GfxInfo::AddCrashReportAnnotations()
     note.AppendLiteral(", AdapterDriverVersion2: ");
     note.Append(NS_LossyConvertUTF16toASCII(adapterDriverVersionString2));
   }
   CrashReporter::AppendAppNotesToCrashReport(note);
 
 #endif
 }
 
+void
+GfxInfo::GetCountryCode()
+{
+  GEOID geoid = GetUserGeoID(GEOCLASS_NATION);
+  if (geoid == GEOID_NOT_AVAILABLE) {
+    return;
+  }
+  // Get required length
+  int numChars = GetGeoInfoW(geoid, GEO_ISO2, nullptr, 0, 0);
+  if (!numChars) {
+    return;
+  }
+  // Now get the string for real
+  mCountryCode.SetLength(numChars);
+  numChars = GetGeoInfoW(geoid, GEO_ISO2, mCountryCode.BeginWriting(),
+                         mCountryCode.Length(), 0);
+  if (numChars) {
+    // numChars includes null terminator
+    mCountryCode.Truncate(numChars - 1);
+  }
+}
+
 static OperatingSystem
 WindowsVersionToOperatingSystem(int32_t aWindowsVersion)
 {
   switch(aWindowsVersion) {
     case kWindowsXP:
       return DRIVER_OS_WINDOWS_XP;
     case kWindowsServer2003:
       return DRIVER_OS_WINDOWS_SERVER_2003;
--- a/widget/windows/GfxInfo.h
+++ b/widget/windows/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"
 
 namespace mozilla {
 namespace widget {
 
 class GfxInfo : public GfxInfoBase
 {
   ~GfxInfo() {}
 public:
@@ -45,33 +46,37 @@ public:
   using GfxInfoBase::GetFeatureStatus;
   using GfxInfoBase::GetFeatureSuggestedDriverVersion;
   using GfxInfoBase::GetWebGLParameter;
 
   virtual nsresult Init();
 
   virtual uint32_t OperatingSystemVersion() MOZ_OVERRIDE { return mWindowsVersion; }
 
+  NS_DECL_ISUPPORTS_INHERITED
 #ifdef DEBUG
-  NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIGFXINFODEBUG
 #endif
+  NS_DECL_NSIGFXINFO2
 
 protected:
 
   virtual nsresult GetFeatureStatusImpl(int32_t aFeature, 
                                         int32_t *aStatus, 
                                         nsAString & aSuggestedDriverVersion, 
                                         const nsTArray<GfxDriverInfo>& aDriverInfo, 
                                         OperatingSystem* aOS = nullptr);
   virtual const nsTArray<GfxDriverInfo>& GetGfxDriverInfo();
 
 private:
 
   void AddCrashReportAnnotations();
+  void GetCountryCode();
+
+  nsString mCountryCode;
   nsString mDeviceString;
   nsString mDeviceID;
   nsString mDriverVersion;
   nsString mDriverDate;
   nsString mDeviceKey;
   nsString mDeviceKeyDebug;
   nsString mAdapterVendorID;
   nsString mAdapterDeviceID;