Bug 1255472 - Add support for the WOW64 mode to the WindowsRegistry. r=gfritzsche, a=ritu
authorAlessio Placitelli <alessio.placitelli@gmail.com>
Fri, 15 Apr 2016 10:23:00 +0200
changeset 324095 a63292ca84320beefbba140bce8a37ad4ceb917c
parent 324094 79b66a95e5ba856523f20f065bc92b45336efe60
child 324096 e636f660d797d1d6137629be7bba6e3fc371cb67
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgfritzsche, ritu
bugs1255472
milestone47.0a2
Bug 1255472 - Add support for the WOW64 mode to the WindowsRegistry. r=gfritzsche, a=ritu
toolkit/components/telemetry/TelemetryEnvironment.jsm
toolkit/components/telemetry/tests/unit/test_TelemetryEnvironment.js
toolkit/modules/WindowsRegistry.jsm
--- a/toolkit/components/telemetry/TelemetryEnvironment.jsm
+++ b/toolkit/components/telemetry/TelemetryEnvironment.jsm
@@ -1254,17 +1254,18 @@ EnvironmentCache.prototype = {
       data.servicePackMinor = versionInfo.servicePackMinor;
       // We only need the build number and UBR if we're at or above Windows 10.
       if (typeof(data.version) === 'string' &&
           Services.vc.compare(data.version, "10") >= 0) {
         data.windowsBuildNumber = versionInfo.buildNumber;
         // Query the UBR key and only add it to the environment if it's available.
         // |readRegKey| doesn't throw, but rather returns 'undefined' on error.
         let ubr = WindowsRegistry.readRegKey(Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE,
-                                             WINDOWS_UBR_KEY_PATH, "UBR");
+                                             WINDOWS_UBR_KEY_PATH, "UBR",
+                                             Ci.nsIWindowsRegKey.WOW64_64);
         data.windowsUBR = (ubr !== undefined) ? ubr : null;
       }
       data.installYear = getSysinfoProperty("installYear", null);
     }
 
     return data;
   },
 
--- a/toolkit/components/telemetry/tests/unit/test_TelemetryEnvironment.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryEnvironment.js
@@ -513,18 +513,18 @@ function checkSystemSection(data) {
               "ServicePackMinor must be a number.");
     if ("windowsBuildNumber" in osData) {
       // This might not be available on all Windows platforms.
       Assert.ok(Number.isFinite(osData["windowsBuildNumber"]),
                 "windowsBuildNumber must be a number.");
     }
     if ("windowsUBR" in osData) {
       // This might not be available on all Windows platforms.
-      Assert.ok(Number.isFinite(osData["windowsUBR"]),
-                "windowsUBR must be a number.");
+      Assert.ok((osData["windowsUBR"] === null) || Number.isFinite(osData["windowsUBR"]),
+                "windowsUBR must be null or a number.");
     }
   } else if (gIsAndroid || gIsGonk) {
     Assert.ok(checkNullOrString(osData.kernelVersion));
   }
 
   let check = gIsWindows ? checkString : checkNullOrString;
   for (let disk of EXPECTED_HDD_FIELDS) {
     Assert.ok(check(data.system.hdd[disk].model));
--- a/toolkit/modules/WindowsRegistry.jsm
+++ b/toolkit/modules/WindowsRegistry.jsm
@@ -12,25 +12,29 @@ var WindowsRegistry = {
    * Safely reads a value from the registry.
    *
    * @param aRoot
    *        The root registry to use.
    * @param aPath
    *        The registry path to the key.
    * @param aKey
    *        The key name.
+   * @param [aRegistryNode=0]
+   *        Optionally set to nsIWindowsRegKey.WOW64_64 (or nsIWindowsRegKey.WOW64_32)
+   *        to access a 64-bit (32-bit) key from either a 32-bit or 64-bit application.
    * @return The key value or undefined if it doesn't exist.  If the key is
    *         a REG_MULTI_SZ, an array is returned.
    */
-  readRegKey: function(aRoot, aPath, aKey) {
+  readRegKey: function(aRoot, aPath, aKey, aRegistryNode=0) {
     const kRegMultiSz = 7;
+    const kMode = Ci.nsIWindowsRegKey.ACCESS_READ | aRegistryNode;
     let registry = Cc["@mozilla.org/windows-registry-key;1"].
                    createInstance(Ci.nsIWindowsRegKey);
     try {
-      registry.open(aRoot, aPath, Ci.nsIWindowsRegKey.ACCESS_READ);
+      registry.open(aRoot, aPath, kMode);
       if (registry.hasValue(aKey)) {
         let type = registry.getValueType(aKey);
         switch (type) {
           case kRegMultiSz:
             // nsIWindowsRegKey doesn't support REG_MULTI_SZ type out of the box.
             let str = registry.readStringValue(aKey);
             return str.split("\0").filter(v => v);
           case Ci.nsIWindowsRegKey.TYPE_STRING:
@@ -52,23 +56,27 @@ var WindowsRegistry = {
    * Safely removes a key from the registry.
    *
    * @param aRoot
    *        The root registry to use.
    * @param aPath
    *        The registry path to the key.
    * @param aKey
    *        The key name.
+   * @param [aRegistryNode=0]
+   *        Optionally set to nsIWindowsRegKey.WOW64_64 (or nsIWindowsRegKey.WOW64_32)
+   *        to access a 64-bit (32-bit) key from either a 32-bit or 64-bit application.
    */
-  removeRegKey: function(aRoot, aPath, aKey) {
+  removeRegKey: function(aRoot, aPath, aKey, aRegistryNode=0) {
     let registry = Cc["@mozilla.org/windows-registry-key;1"].
                    createInstance(Ci.nsIWindowsRegKey);
     try {
       let mode = Ci.nsIWindowsRegKey.ACCESS_QUERY_VALUE |
-                 Ci.nsIWindowsRegKey.ACCESS_SET_VALUE;
+                 Ci.nsIWindowsRegKey.ACCESS_SET_VALUE |
+                 aRegistryNode;
       registry.open(aRoot, aPath, mode);
       if (registry.hasValue(aKey)) {
         registry.removeValue(aKey);
       }
     } catch (ex) {
     } finally {
       registry.close();
     }