Bug 1279240 - use registry key to deduce default browser when possible, r=jaws
MozReview-Commit-ID: 7kDMRrt5JNK
--- 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;
},
/**