From 0c5bdadf1a8a7bae95367e94044c6f62c0fde66d Mon Sep 17 00:00:00 2001 From: Jared Wein Date: Mon, 22 Feb 2016 12:34:30 -0500 Subject: [PATCH] Bug 1041514 - Don't show default browser prompt if a user opts out in the installer. r=jimm MozReview-Commit-ID: Hyr7zGKUAWj --- browser/components/shell/ShellService.jsm | 23 ++++++++++++++++- browser/installer/windows/nsis/installer.nsi | 6 +++++ toolkit/modules/WindowsRegistry.jsm | 26 ++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/browser/components/shell/ShellService.jsm b/browser/components/shell/ShellService.jsm index f935eac94a7..2fd05d3f4c8 100644 --- a/browser/components/shell/ShellService.jsm +++ b/browser/components/shell/ShellService.jsm @@ -11,6 +11,8 @@ 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"); +XPCOMUtils.defineLazyModuleGetter(this, "WindowsRegistry", + "resource://gre/modules/WindowsRegistry.jsm"); /** * Internal functionality to save and restore the docShell.allow* properties. @@ -54,11 +56,30 @@ let ShellServiceInternal = { return false; } - return Services.prefs.getBoolPref("browser.shell.checkDefaultBrowser"); + if (!Services.prefs.getBoolPref("browser.shell.checkDefaultBrowser")) { + return false; + } + + if (AppConstants.platform == "win") { + let optOutValue = WindowsRegistry.readRegKey(Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER, + "Software\\Mozilla\\Firefox", + "DefaultBrowserOptOut"); + WindowsRegistry.removeRegKey(Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER, + "Software\\Mozilla\\Firefox", + "DefaultBrowserOptOut"); + if (optOutValue == "True") { + Services.prefs.setBoolPref("browser.shell.checkDefaultBrowser", false); + return false; + } + } + + return true; }, + set shouldCheckDefaultBrowser(shouldCheck) { Services.prefs.setBoolPref("browser.shell.checkDefaultBrowser", !!shouldCheck); }, + isDefaultBrowser(startupCheck, forAllTypes) { // If this is the first browser window, maintain internal state that we've // checked this session (so that subsequent window opens don't show the diff --git a/browser/installer/windows/nsis/installer.nsi b/browser/installer/windows/nsis/installer.nsi index 70c605b87e1..4be6bdfec38 100755 --- a/browser/installer/windows/nsis/installer.nsi +++ b/browser/installer/windows/nsis/installer.nsi @@ -605,6 +605,12 @@ Section "-InstallEndCleanup" GetFunctionAddress $0 SetAsDefaultAppUserHKCU UAC::ExecCodeSegment $0 ${EndIf} + ${Else} + ${LogHeader} "Writing default-browser opt-out" + WriteRegStr HKCU "Software\Mozilla\Firefox" "DefaultBrowserOptOut" "True" + ${If} ${Errors} + ${LogHeader} "Error writing default-browser opt-out" + ${EndIf} ${EndIf} ${EndUnless} diff --git a/toolkit/modules/WindowsRegistry.jsm b/toolkit/modules/WindowsRegistry.jsm index 6bd0b9f7b91..2e7a5ad3938 100644 --- a/toolkit/modules/WindowsRegistry.jsm +++ b/toolkit/modules/WindowsRegistry.jsm @@ -47,4 +47,30 @@ var WindowsRegistry = { } return undefined; }, + + /** + * 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. + */ + removeRegKey: function(aRoot, aPath, aKey) { + 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; + registry.open(aRoot, aPath, mode); + if (registry.hasValue(aKey)) { + registry.removeValue(aKey); + } + } catch (ex) { + } finally { + registry.close(); + } + } };