Bug 1279240 - use registry key to deduce default browser when possible, r=jaws draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Fri, 23 Sep 2016 16:27:20 +0100
changeset 419544 034a164e2a5ea2ec371c1ab91490866f3bb1fa84
parent 419543 949b1c175da40c8ad4a1d9711dfef497e38c8192
child 532601 1d85de1d2b7bd481ee52e8e7e8a040d6e5063810
push id30959
push userbmo:gijskruitbosch+bugs@gmail.com
push dateFri, 30 Sep 2016 16:32:26 +0000
reviewersjaws
bugs1279240
milestone52.0a1
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;
   },
 
   /**