Bug 1041514 - Don't show default browser prompt if a user opts out in the installer. r?jimm
MozReview-Commit-ID: JRIpOLXWmG1
--- a/browser/components/shell/ShellService.jsm
+++ b/browser/components/shell/ShellService.jsm
@@ -6,16 +6,18 @@
this.EXPORTED_SYMBOLS = ["ShellService"];
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.
*/
let ShellServiceInternal = {
/**
* Used to determine whether or not to offer "Set as desktop background"
* functionality. Even if shell service is available it is not
@@ -49,21 +51,40 @@ let ShellServiceInternal = {
_checkedThisSession: false,
get shouldCheckDefaultBrowser() {
// If we've already checked, the browser has been started and this is a
// new window open, and we don't want to check again.
if (this._checkedThisSession) {
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
// default browser dialog).
if (startupCheck) {
this._checkedThisSession = true;
}
if (this.shellService) {
--- a/browser/installer/windows/nsis/installer.nsi
+++ b/browser/installer/windows/nsis/installer.nsi
@@ -595,16 +595,22 @@ Section "-InstallEndCleanup"
${GetParameters} $0
${GetOptions} "$0" "/UAC:" $0
${If} ${Errors}
Call SetAsDefaultAppUserHKCU
${Else}
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}
; Adds a pinned Task Bar shortcut (see MigrateTaskBarShortcut for details).
${MigrateTaskBarShortcut}
${EndUnless}
${GetShortcutsLogPath} $0
WriteIniStr "$0" "TASKBAR" "Migrated" "true"
--- a/toolkit/modules/WindowsRegistry.jsm
+++ b/toolkit/modules/WindowsRegistry.jsm
@@ -42,9 +42,35 @@ var WindowsRegistry = {
}
}
} catch (ex) {
} finally {
registry.close();
}
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();
+ }
+ }
};