Bug 1279240 - save old default browser when setting as default on win7 and below from the installer, r?rstrong draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Tue, 27 Sep 2016 11:41:24 +0100
changeset 419085 9bf900b1ef8f5ced6c7929fa74c704ca244bf177
parent 418992 f7d5008ee2ab9200052e45ad6ecc3f3a348f7f86
child 419086 6cffee19cb695cb799b446a0e3f9d91575ae1712
child 419543 949b1c175da40c8ad4a1d9711dfef497e38c8192
push id30842
push userbmo:gijskruitbosch+bugs@gmail.com
push dateThu, 29 Sep 2016 17:32:26 +0000
reviewersrstrong
bugs1279240
milestone52.0a1
Bug 1279240 - save old default browser when setting as default on win7 and below from the installer, r?rstrong 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