diff --git a/browser/components/uitour/UITour.jsm b/browser/components/uitour/UITour.jsm index e18ed204d1dd..6df5a78ecea7 100644 --- a/browser/components/uitour/UITour.jsm +++ b/browser/components/uitour/UITour.jsm @@ -8,6 +8,7 @@ this.EXPORTED_SYMBOLS = ["UITour", "UITourMetricsProvider"]; const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; +Cu.import("resource://gre/modules/AppConstants.jsm"); Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/Promise.jsm"); @@ -1805,6 +1806,27 @@ this.UITour = { } } catch (e) {} appinfo["defaultBrowser"] = isDefaultBrowser; + + let canSetDefaultBrowserInBackground = true; + if (AppConstants.isPlatformAndVersionAtLeast("win", "6.2")) { + let prefBranch = + Services.prefs.getBranch("browser.shell.associationHash"); + let prefChildren = prefBranch.getChildList(""); + canSetDefaultBrowserInBackground = prefChildren.length > 0; + } else if (AppConstants.isPlatformAndVersionAtLeast("macosx", "10.10")) { + canSetDefaultBrowserInBackground = false; + } else if (AppConstants.platform == "linux") { + // The ShellService may not exist on some versions of Linux. + try { + let shell = aWindow.getShellService(); + } catch (e) { + canSetDefaultBrowserInBackground = null; + } + } + + appinfo["canSetDefaultBrowserInBackground"] = + canSetDefaultBrowserInBackground; + this.sendPageCallback(aMessageManager, aCallbackID, appinfo); break; case "availableTargets": diff --git a/browser/components/uitour/test/browser_UITour_defaultBrowser.js b/browser/components/uitour/test/browser_UITour_defaultBrowser.js index b79c1075e37f..949e7fbf68f6 100644 --- a/browser/components/uitour/test/browser_UITour_defaultBrowser.js +++ b/browser/components/uitour/test/browser_UITour_defaultBrowser.js @@ -61,7 +61,34 @@ let tests = [ .getService(Components.interfaces.nsIShellService); let isDefault = shell.isDefaultBrowser(false); gContentAPI.getConfiguration("appinfo", (data) => { - is(data.value, data.defaultBrowser, "gContentAPI result should match shellService.isDefaultBrowser"); + is(isDefault, data.defaultBrowser, "gContentAPI result should match shellService.isDefaultBrowser"); + done(); + }); + }), + + taskify(function* test_setInBackgroundWhenPrefExists(done) { + Services.prefs.setCharPref("browser.shell.associationHash.http", "ABCDEFG"); + gContentAPI.getConfiguration("appinfo", (data) => { + let canSetInBackground = true; + is(canSetInBackground, data.canSetDefaultBrowserInBackground, + "canSetDefaultBrowserInBackground should be true when a hash is present"); + Services.prefs.clearUserPref("browser.shell.associationHash.http"); + done(); + }); + }), + + taskify(function* test_setInBackgroundWhenPrefDoesntExist(done) { + /* The association hashes are only supported on Windows. */ + Cu.import("resource://gre/modules/AppConstants.jsm"); + if (AppConstants.platform != "win") { + info("Skipping test_setInBackgroundWhenPrefDoesntExist on non-Windows platform"); + return; + } + + gContentAPI.getConfiguration("appinfo", (data) => { + let canSetInBackground = false; + is(canSetInBackground, data.canSetDefaultBrowserInBackground, + "canSetDefaultBrowserInBackground should be false when no hashes are present"); done(); }); })