Bug 1279240 - save old default browser when setting as default on win7 and below from the installer, r?rstrong
MozReview-Commit-ID: CmMI8bztpaL
--- a/browser/installer/windows/nsis/installer.nsi
+++ b/browser/installer/windows/nsis/installer.nsi
@@ -591,31 +591,58 @@ SectionEnd
Section "-InstallEndCleanup"
SetDetailsPrint both
DetailPrint "$(STATUS_CLEANUP)"
SetDetailsPrint none
${Unless} ${Silent}
${MUI_INSTALLOPTIONS_READ} $0 "summary.ini" "Field 4" "State"
${If} "$0" == "1"
+ ; NB: this code is duplicated in stub.nsi. Please keep in sync.
+ ; For data migration in the app, we want to know what the default browser
+ ; value was before we changed it. To do so, we read it here and store it
+ ; in our own registry key.
+ StrCpy $0 ""
+ ${If} ${AtLeastWinVista}
+ AppAssocReg::QueryCurrentDefault "http" "protocol" "effective"
+ Pop $1
+ ; If the method hasn't failed, $1 will contain the progid. Check:
+ ${If} "$1" != "method failed"
+ ${AndIf} "$1" != "method not available"
+ ; Read the actual command from the progid
+ ReadRegStr $0 HKCR "$1\shell\open\command" ""
+ ${EndIf}
+ ${EndIf}
+ ; If using the App Association Registry didn't happen or failed, fall back
+ ; to the effective http default:
+ ${If} "$0" == ""
+ ReadRegStr $0 HKCR "http\shell\open\command" ""
+ ${EndIf}
+ ; If we have something other than empty string now, write the value.
+ ${If} "$0" != ""
+ ClearErrors
+ WriteRegStr HKCU "Software\Mozilla\Firefox" "OldDefaultBrowserCommand" "$0"
+ ${EndIf}
+
${LogHeader} "Setting as the default browser"
ClearErrors
${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"
+ ClearErrors
WriteRegStr HKCU "Software\Mozilla\Firefox" "DefaultBrowserOptOut" "True"
${If} ${Errors}
- ${LogHeader} "Error writing default-browser opt-out"
+ ${LogMsg} "Error writing default-browser opt-out"
${EndIf}
${EndIf}
${EndUnless}
; Adds a pinned Task Bar shortcut (see MigrateTaskBarShortcut for details).
${MigrateTaskBarShortcut}
; Add the Firewall entries during install
--- a/browser/installer/windows/nsis/stub.nsi
+++ b/browser/installer/windows/nsis/stub.nsi
@@ -1743,16 +1743,42 @@ Function FinishInstall
${EndIf}
${NSD_KillTimer} FinishInstall
StrCpy $ProgressCompleted "$ProgressTotal"
Call SetProgressBars
${If} "$CheckboxSetAsDefault" == "1"
+ ; NB: this code is duplicated in installer.nsi. Please keep in sync.
+ ; For data migration in the app, we want to know what the default browser
+ ; value was before we changed it. To do so, we read it here and store it
+ ; in our own registry key.
+ StrCpy $0 ""
+ ${If} ${AtLeastWinVista}
+ AppAssocReg::QueryCurrentDefault "http" "protocol" "effective"
+ Pop $1
+ ; If the method hasn't failed, $1 will contain the progid. Check:
+ ${If} "$1" != "method failed"
+ ${AndIf} "$1" != "method not available"
+ ; Read the actual command from the progid
+ ReadRegStr $0 HKCR "$1\shell\open\command" ""
+ ${EndIf}
+ ${EndIf}
+ ; If using the App Association Registry didn't happen or failed, fall back
+ ; to the effective http default:
+ ${If} "$0" == ""
+ ReadRegStr $0 HKCR "http\shell\open\command" ""
+ ${EndIf}
+ ; If we have something other than empty string now, write the value.
+ ${If} "$0" != ""
+ ClearErrors
+ WriteRegStr HKCU "Software\Mozilla\Firefox" "OldDefaultBrowserCommand" "$0"
+ ${EndIf}
+
${GetParameters} $0
ClearErrors
${GetOptions} "$0" "/UAC:" $0
${If} ${Errors} ; Not elevated
Call ExecSetAsDefaultAppUser
${Else} ; Elevated - execute the function in the unelevated process
GetFunctionAddress $0 ExecSetAsDefaultAppUser
UAC::ExecCodeSegment $0