Bug 1279240 - use registry key to deduce default browser when possible, r=jaws
☠☠ backed out by 016bf0339326 ☠ ☠
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Fri, 23 Sep 2016 16:27:20 +0100
changeset 315768 4b69e32e3a837f70fcfb9c8a8b2c8b4af4a280de
parent 315767 d0d5180dc062bda67da867ed501ea9e3d23af8e3
child 315769 28d81d95566ba38cb985b671b27a8cb021386b99
push id32691
push usergijskruitbosch@gmail.com
push dateThu, 29 Sep 2016 18:06:25 +0000
treeherderautoland@4b69e32e3a83 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs1279240
milestone52.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 1279240 - use registry key to deduce default browser when possible, r=jaws MozReview-Commit-ID: 7kDMRrt5JNK
browser/components/migration/MigrationUtils.jsm
--- a/browser/components/migration/MigrationUtils.jsm
+++ b/browser/components/migration/MigrationUtils.jsm
@@ -20,16 +20,18 @@ XPCOMUtils.defineLazyModuleGetter(this, 
 XPCOMUtils.defineLazyModuleGetter(this, "BookmarkHTMLUtils",
                                   "resource://gre/modules/BookmarkHTMLUtils.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
                                   "resource://gre/modules/PlacesUtils.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "PromiseUtils",
                                   "resource://gre/modules/PromiseUtils.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "TelemetryStopwatch",
                                   "resource://gre/modules/TelemetryStopwatch.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "WindowsRegistry",
+                                  "resource://gre/modules/WindowsRegistry.jsm");
 
 var gMigrators = null;
 var gProfileStartup = null;
 var gMigrationBundle = null;
 
 XPCOMUtils.defineLazyGetter(this, "gAvailableMigratorKeys", function() {
   if (AppConstants.platform == "win") {
     return [
@@ -598,27 +600,49 @@ this.MigrationUtils = Object.freeze({
       "Google Chrome":                     "chrome",  // Windows, Linux
       "Chrome":                            "chrome",  // OS X
       "Chromium":                          "chromium", // Windows, OS X
       "Chromium Web Browser":              "chromium", // Linux
       "360\u5b89\u5168\u6d4f\u89c8\u5668": "360se",
     };
 
     let browserDesc = "";
+    let key = "";
     try {
       let browserDesc =
         Cc["@mozilla.org/uriloader/external-protocol-service;1"].
         getService(Ci.nsIExternalProtocolService).
         getApplicationDescription("http");
-      return APP_DESC_TO_KEY[browserDesc] || "";
+      key = APP_DESC_TO_KEY[browserDesc] || "";
     }
     catch (ex) {
       Cu.reportError("Could not detect default browser: " + ex);
     }
-    return "";
+
+    // "firefox" is the least useful entry here, and might just be because we've set
+    // ourselves as the default (on Windows 7 and below). In that case, check if we
+    // have a registry key that tells us where to go:
+    if (key == "firefox" && AppConstants.isPlatformAndVersionAtMost("win", "6.2")) {
+      const kRegPath = "Software\\Mozilla\\Firefox";
+      let oldDefault = WindowsRegistry.readRegKey(
+          Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER, kRegPath, "OldDefaultBrowserCommand");
+      if (oldDefault) {
+        // Remove the key:
+        WindowsRegistry.removeRegKey(
+          Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER, kRegPath, "OldDefaultBrowserCommand");
+        try {
+          let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFileWin);
+          file.initWithCommandLine(oldDefault);
+          key = APP_DESC_TO_KEY[file.getVersionInfoField("FileDescription")] || key;
+        } catch (ex) {
+          Cu.reportError("Could not convert old default browser value to description.");
+        }
+      }
+    }
+    return key;
   },
 
   // Whether or not we're in the process of startup migration
   get isStartupMigration() {
     return gProfileStartup != null;
   },
 
   /**