Bug 1279240 - save old default browser when setting as default on win7 and below from the installer, r=rstrong a=gchang
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Tue, 27 Sep 2016 11:41:24 +0100
changeset 340606 935a54e00cc50f80eb57d4a4545781991c505b89
parent 340605 831e1d88f5940d8d1991968ed7962be158320b20
child 340607 8b275c9c39bf834e1c883c0f585adfc3d806bb95
push id10156
push userkwierso@gmail.com
push dateMon, 17 Oct 2016 20:08:56 +0000
treeherdermozilla-aurora@be9b2b04f7e3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrstrong, gchang
bugs1279240
milestone51.0a2
Bug 1279240 - save old default browser when setting as default on win7 and below from the installer, r=rstrong a=gchang MozReview-Commit-ID: CmMI8bztpaL
browser/installer/windows/nsis/installer.nsi
browser/installer/windows/nsis/stub.nsi
--- 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