Bug 1041514 - Don't show default browser prompt if a user opts out in the installer. r=jimm

MozReview-Commit-ID: Hyr7zGKUAWj
This commit is contained in:
Jared Wein 2016-02-22 12:34:30 -05:00
parent ad7a8d19d6
commit 0c5bdadf1a
3 changed files with 54 additions and 1 deletions

View File

@ -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

View File

@ -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}

View File

@ -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();
}
}
};