From e165e3ca05770f15ca421885f99a915df961b329 Mon Sep 17 00:00:00 2001 From: Ping Chen Date: Thu, 8 Apr 2021 13:13:31 +0300 Subject: [PATCH] Bug 1237571 - Register as webcal(s):// handler on Windows. r=mkmelin Differential Revision: https://phabricator.services.mozilla.com/D111220 --HG-- extra : amend_source : 4a76ac4c24d005777ff5dec2d703d251da6985e8 --- .../shell/nsWindowsShellService.cpp | 2 + mail/installer/windows/nsis/installer.nsi | 7 +- mail/installer/windows/nsis/shared.nsh | 161 ++++++++++++++++-- mail/installer/windows/nsis/uninstaller.nsi | 9 +- 4 files changed, 166 insertions(+), 13 deletions(-) diff --git a/mail/components/shell/nsWindowsShellService.cpp b/mail/components/shell/nsWindowsShellService.cpp index 1459a28be9..535f7011be 100644 --- a/mail/components/shell/nsWindowsShellService.cpp +++ b/mail/components/shell/nsWindowsShellService.cpp @@ -72,6 +72,7 @@ typedef enum { #define CLS_MIDURL "Thunderbird.Url.mid" #define CLS_NEWSURL "Thunderbird.Url.news" #define CLS_FEEDURL "Thunderbird.Url.feed" +#define CLS_WEBCALURL "Thunderbird.Url.webcal" #define CLS_ICS "ThunderbirdICS" #define SOP "\\shell\\open\\command" #define VAL_OPEN "\"%APPPATH%\" \"%1\"" @@ -116,6 +117,7 @@ static SETTING gCalendarSettings[] = { {MAKE_KEY_NAME1(CLS_ICS, SOP), "", VAL_OPEN, APP_PATH_SUBSTITUTION}, // Protocol Handlers + {MAKE_KEY_NAME1(CLS_WEBCALURL, SOP), "", VAL_OPEN, APP_PATH_SUBSTITUTION}, {MAKE_KEY_NAME1("webcal", SOP), "", VAL_OPEN, APP_PATH_SUBSTITUTION}, {MAKE_KEY_NAME1("webcals", SOP), "", VAL_OPEN, APP_PATH_SUBSTITUTION}, }; diff --git a/mail/installer/windows/nsis/installer.nsi b/mail/installer/windows/nsis/installer.nsi index 9635d76a4d..64d50d5c81 100755 --- a/mail/installer/windows/nsis/installer.nsi +++ b/mail/installer/windows/nsis/installer.nsi @@ -429,7 +429,8 @@ Section "-Application" APP_IDX ${SetUninstallKeys} ; On install always add the ThunderbirdEML, Thunderbird.Url.mailto, - ; Thunderbird.Url.mid, Thunderbird.Url.news, and ThunderbirdICS keys. + ; Thunderbird.Url.mid, Thunderbird.Url.news, Thunderbird.webcal and + ; ThunderbirdICS keys. ${GetLongPath} "$INSTDIR\${FileMainEXE}" $8 StrCpy $0 "SOFTWARE\Classes" StrCpy $1 "$\"$8$\" $\"%1$\"" @@ -446,6 +447,8 @@ Section "-Application" APP_IDX "${AppRegNameNews} URL" "delete" "" ${AddHandlerValues} "$0\Thunderbird.Url.mid" "$1" "$8,0" \ "${AppRegNameMail} URL" "delete" "" + ${AddHandlerValues} "$0\Thunderbird.Url.webcal" "$1" "$8,0" \ + "${AppRegNameCalendar} URL" "delete" "" ; An empty string is used for the 5th param because ThunderbirdICS is not a ; protocol handler ${AddHandlerValues} "$0\ThunderbirdICS" "$1" "$8,0" \ @@ -457,10 +460,12 @@ Section "-Application" APP_IDX ; Set the Start Menu Mail/News and Registered App HKLM registry keys. ${SetClientsMail} "HKLM" ${SetClientsNews} "HKLM" + ${SetClientsCalendar} "HKLM" ${ElseIf} ${AtLeastWin8} ; Set the Start Menu Mail/News and Registered App HKCU registry keys. ${SetClientsMail} "HKCU" ${SetClientsNews} "HKCU" + ${SetClientsCalendar} "HKCU" ${EndIf} !ifdef MOZ_MAINTENANCE_SERVICE diff --git a/mail/installer/windows/nsis/shared.nsh b/mail/installer/windows/nsis/shared.nsh index 41423efa41..e1edb9e38f 100755 --- a/mail/installer/windows/nsis/shared.nsh +++ b/mail/installer/windows/nsis/shared.nsh @@ -60,6 +60,18 @@ ${If} "$0" == "$INSTDIR" ${SetClientsNews} "HKLM" ${EndIf} + + ; Only update the Clients\Calendar registry key values if they don't exist or + ; this installation is the same as the one set in those keys. + ReadRegStr $0 HKLM "Software\Clients\Calendar\${ClientsRegName}\DefaultIcon" "" + ${GetPathFromString} "$0" $0 + ${GetParent} "$0" $0 + ${If} ${FileExists} "$0" + ${GetLongPath} "$0" $0 + ${EndIf} + ${If} "$0" == "$INSTDIR" + ${SetClientsCalendar} "HKLM" + ${EndIf} ${EndIf} ; Migrate the application's Start Menu directory to a single shortcut in the @@ -171,6 +183,7 @@ ${SetHandlersNews} ; Uses SHCTX ${SetClientsMail} "HKLM" ${SetClientsNews} "HKLM" + ${SetClientsCalendar} "HKLM" ${SetMailClientForMapi} "HKLM" ${ShowShortcuts} !macroend @@ -329,21 +342,12 @@ ${AddHandlerValues} "$0\mailto" "$2" "$8,0" "${AppRegNameMail} URL" "true" "" ${AddHandlerValues} "$0\Thunderbird.Url.mid" "$1" "$8,0" "${AppRegNameMail} URL" "delete" "" ${AddHandlerValues} "$0\mid" "$1" "$8,0" "${AppRegNameMail} URL" "true" "" - ; An empty string is used for the 5th param because ThunderbirdICS is not a - ; protocol handler - ${AddHandlerValues} "$0\ThunderbirdICS" "$1" "$8,0" \ - "${AppRegNameCalendar} Document" "" "" ; Associate the file handlers with ThunderbirdEML ReadRegStr $6 SHCTX ".eml" "" ${If} "$6" != "ThunderbirdEML" WriteRegStr SHCTX "$0\.eml" "" "ThunderbirdEML" ${EndIf} - ;; Associate the file handlers with ThunderbirdICS - ReadRegStr $6 SHCTX ".ics" "" - ${If} "$6" != "ThunderbirdICS" - WriteRegStr SHCTX "$0\.ics" "" "ThunderbirdICS" - ${EndIf} !macroend !define SetHandlersMail "!insertmacro SetHandlersMail" @@ -360,6 +364,28 @@ !macroend !define SetHandlersNews "!insertmacro SetHandlersNews" +!macro SetHandlersCalendar + ${GetLongPath} "$INSTDIR\${FileMainEXE}" $8 + + StrCpy $0 "SOFTWARE\Classes" + StrCpy $1 "$\"$8$\" $\"%1$\"" + + ${AddHandlerValues} "$0\Thunderbird.Url.webcal" "$1" "$8,0" "${AppRegNameCalendar} URL" "delete" "" + ${AddHandlerValues} "$0\webcal" "$1" "$8,0" "${AppRegNameCalendar} URL" "true" "" + ${AddHandlerValues} "$0\webcals" "$1" "$8,0" "${AppRegNameCalendar} URL" "true" "" + ; An empty string is used for the 5th param because ThunderbirdICS is not a + ; protocol handler + ${AddHandlerValues} "$0\ThunderbirdICS" "$1" "$8,0" \ + "${AppRegNameCalendar} Document" "" "" + + ;; Associate the file handlers with ThunderbirdICS + ReadRegStr $6 SHCTX ".ics" "" + ${If} "$6" != "ThunderbirdICS" + WriteRegStr SHCTX "$0\.ics" "" "ThunderbirdICS" + ${EndIf} +!macroend +!define SetHandlersCalendar "!insertmacro SetHandlersCalendar" + ; XXXrstrong - there are several values that will be overwritten by and ; overwrite other installs of the same application. !macro SetClientsMail RegKey @@ -443,7 +469,6 @@ WriteRegStr ${RegKey} "$0\Capabilities" "ApplicationName" "${AppRegNameMail}" WriteRegStr ${RegKey} "$0\Capabilities\FileAssociations" ".eml" "ThunderbirdEML" WriteRegStr ${RegKey} "$0\Capabilities\FileAssociations" ".wdseml" "ThunderbirdEML" - WriteRegStr ${RegKey} "$0\Capabilities\FileAssociations" ".ics" "ThunderbirdICS" WriteRegStr ${RegKey} "$0\Capabilities\StartMenu" "Mail" "${ClientsRegName}" WriteRegStr ${RegKey} "$0\Capabilities\URLAssociations" "mailto" "Thunderbird.Url.mailto" WriteRegStr ${RegKey} "$0\Capabilities\URLAssociations" "mid" "Thunderbird.Url.mid" @@ -588,6 +613,43 @@ !macroend !define SetClientsNews "!insertmacro SetClientsNews" +!macro SetClientsCalendar RegKey + ${GetLongPath} "$INSTDIR\${FileMainEXE}" $8 + ${GetLongPath} "$INSTDIR\uninstall\helper.exe" $7 + ${GetLongPath} "$INSTDIR\mozMapi32_InUse.dll" $6 + + StrCpy $0 "Software\Clients\Calendar\${ClientsRegName}" + + WriteRegStr ${RegKey} "$0" "" "${ClientsRegName}" + WriteRegStr ${RegKey} "$0\DefaultIcon" "" "$8,0" + WriteRegStr ${RegKey} "$0" "DLLPath" "$6" + + WriteRegStr ${RegKey} "$0\shell\open\command" "" "$\"$8$\"" + + WriteRegStr ${RegKey} "$0\shell\properties" "" "$(CONTEXT_OPTIONS)" + WriteRegStr ${RegKey} "$0\shell\properties\command" "" "$\"$8$\" -options" + + WriteRegStr ${RegKey} "$0\shell\safemode" "" "$(CONTEXT_SAFE_MODE)" + WriteRegStr ${RegKey} "$0\shell\safemode\command" "" "$\"$8$\" -safe-mode" + + ; Protocols + StrCpy $1 "$\"$8$\" $\"%1$\"" + ${AddHandlerValues} "$0\Protocols\webcal" "$1" "$8,0" "${AppRegNameCalendar} URL" "true" "" + ${AddHandlerValues} "$0\Protocols\webcals" "$1" "$8,0" "${AppRegNameCalendar} URL" "true" "" + + ; Capabilities registry keys + WriteRegStr ${RegKey} "$0\Capabilities" "ApplicationDescription" "$(REG_APP_DESC)" + WriteRegStr ${RegKey} "$0\Capabilities" "ApplicationIcon" "$8,0" + WriteRegStr ${RegKey} "$0\Capabilities" "ApplicationName" "${AppRegNameCalendar}" + WriteRegStr ${RegKey} "$0\Capabilities\FileAssociations" ".ics" "ThunderbirdICS" + WriteRegStr ${RegKey} "$0\Capabilities\URLAssociations" "webcal" "Thunderbird.Url.webcal" + WriteRegStr ${RegKey} "$0\Capabilities\URLAssociations" "webcals" "Thunderbird.Url.webcal" + + ; Registered Application + WriteRegStr ${RegKey} "Software\RegisteredApplications" "${AppRegNameCalendar}" "$0\Capabilities" +!macroend +!define SetClientsCalendar "!insertmacro SetClientsCalendar" + ; Add Software\Mozilla\ registry entries (uses SHCTX). !macro SetAppKeys ${GetLongPath} "$INSTDIR" $8 @@ -734,6 +796,22 @@ ${AddHandlerValues} "SOFTWARE\Classes\nntp" "$2" "$8,0" "" "" "" ${EndIf} + ${IsHandlerForInstallDir} "Thunderbird.Url.webcal" $R9 + ${If} "$R9" == "true" + ${AddHandlerValues} "SOFTWARE\Classes\Thunderbird.Url.webcal" "$3" "$8,0" \ + "${AppRegNameCalendar} URL" "delete" "" + ${EndIf} + + ${IsHandlerForInstallDir} "webcal" $R9 + ${If} "$R9" == "true" + ${AddHandlerValues} "SOFTWARE\Classes\webcal" "$3" "$8,0" "" "" "" + ${EndIf} + + ${IsHandlerForInstallDir} "webcals" $R9 + ${If} "$R9" == "true" + ${AddHandlerValues} "SOFTWARE\Classes\webcals" "$3" "$8,0" "" "" "" + ${EndIf} + ${IsHandlerForInstallDir} "ThunderbirdICS" $R9 ${If} "$R9" == "true" ${AddHandlerValues} "SOFTWARE\Classes\ThunderbirdICS" "$3" "$8,0" \ @@ -1244,6 +1322,32 @@ Function SetAsDefaultAppUser ${EndIf} ${EndUnless} + ClearErrors + ${GetOptions} "$R0" "Calendar" $R1 + ${Unless} ${Errors} + ; Check if this install location registered as the Calendar client + ClearErrors + ReadRegStr $0 HKLM "Software\Clients\Calendar\${ClientsRegName}\DefaultIcon" "" + ${GetPathFromString} "$0" $0 + ${GetParent} "$0" $0 + ${If} ${FileExists} "$0" + ${GetLongPath} "$0" $0 + ${If} "$0" == "$INSTDIR" + ; Check if this is running in an elevated process + ClearErrors + ${GetParameters} $0 + ${GetOptions} "$0" "/UAC:" $0 + ${If} ${Errors} ; Not elevated + Call SetAsDefaultCalendarAppUserHKCU + ${Else} ; Elevated - execute the function in the unelevated process + GetFunctionAddress $0 SetAsDefaultCalendarAppUserHKCU + UAC::ExecCodeSegment $0 + ${EndIf} + Return ; Nothing more needs to be done + ${EndIf} + ${EndIf} + ${EndUnless} + ; The code after ElevateUAC won't be executed when the user: ; a) is a member of the administrators group (e.g. elevation is required) ; b) is not a member of the administrators group and chooses to elevate @@ -1252,6 +1356,7 @@ Function SetAsDefaultAppUser SetShellVarContext all ; Set SHCTX to all users (e.g. HKLM) ${SetClientsMail} "HKLM" ${SetClientsNews} "HKLM" + ${SetClientsCalendar} "HKLM" ${RemoveDeprecatedKeys} ${MigrateTaskBarShortcut} @@ -1364,4 +1469,40 @@ Function SetAsDefaultNewsAppUserHKCU ${EndUnless} FunctionEnd +; Sets this installation as the default calendar client by setting the registry keys +; under HKEY_CURRENT_USER via registry calls and using the AppAssocReg NSIS +; plugin. This is a function instead of a macro so it is +; easily called from an elevated instance of the binary. Since this can be +; called by an elevated instance logging is not performed in this function. +Function SetAsDefaultCalendarAppUserHKCU + ; Only set as the user's Calendar client if the StartMenuInternet + ; registry keys are for this install. + ClearErrors + ReadRegStr $0 HKLM "Software\Clients\Calendar\${ClientsRegName}\DefaultIcon" "" + ${Unless} ${Errors} + ${GetPathFromString} "$0" $0 + ${GetParent} "$0" $0 + ${If} ${FileExists} "$0" + ${GetLongPath} "$0" $0 + ${If} "$0" == "$INSTDIR" + WriteRegStr HKCU "Software\Clients\Calendar" "" "${ClientsRegName}" + ${EndIf} + ${EndIf} + ${EndUnless} + + SetShellVarContext current ; Set SHCTX to the current user (e.g. HKCU) + + ${If} ${AtLeastWin8} + ${SetHandlersCalendar} + ${EndIf} + + ClearErrors + ReadRegStr $0 HKLM "Software\RegisteredApplications" "${AppRegNameCalendar}" + ; Only register as the handler if the app registry name exists + ; under the RegisteredApplications registry key. + ${Unless} ${Errors} + AppAssocReg::SetAppAsDefaultAll "${AppRegNameCalendar}" + ${EndUnless} +FunctionEnd + !endif diff --git a/mail/installer/windows/nsis/uninstaller.nsi b/mail/installer/windows/nsis/uninstaller.nsi index 7ae42ba7af..a7235b6dcc 100755 --- a/mail/installer/windows/nsis/uninstaller.nsi +++ b/mail/installer/windows/nsis/uninstaller.nsi @@ -301,6 +301,7 @@ Section "Uninstall" ${un.RegCleanAppHandler} "Thunderbird.Url.mailto" ${un.RegCleanAppHandler} "Thunderbird.Url.mid" ${un.RegCleanAppHandler} "Thunderbird.Url.news" + ${un.RegCleanAppHandler} "Thunderbird.Url.webcal" ${un.RegCleanAppHandler} "ThunderbirdEML" ${un.RegCleanAppHandler} "ThunderbirdICS" ${un.RegCleanProtocolHandler} "mailto" @@ -308,6 +309,8 @@ Section "Uninstall" ${un.RegCleanProtocolHandler} "news" ${un.RegCleanProtocolHandler} "nntp" ${un.RegCleanProtocolHandler} "snews" + ${un.RegCleanProtocolHandler} "webcal" + ${un.RegCleanProtocolHandler} "webcals" ClearErrors ReadRegStr $R9 HKCR "ThunderbirdEML" "" @@ -345,8 +348,8 @@ Section "Uninstall" ${un.RemoveQuotesFromPath} "$R1" $R1 ${un.GetParent} "$R1" $R1 - ; Only remove the Clients\Mail and Clients\News key if it refers to this - ; install location. The Clients\Mail & Clients\News keys are independent + ; Only remove the Clients\Mail & Clients\News & Clients\Calendar key if it + ; refers to this install location. The Clients\* keys are independent ; of the default app for the OS settings. The XPInstall base un-installer ; always removes these keys if it is uninstalling the default app and it ; will always replace the keys when installing even if there is another @@ -356,8 +359,10 @@ Section "Uninstall" ${If} "$INSTDIR" == "$R1" DeleteRegKey HKLM "Software\Clients\Mail\${ClientsRegName}" DeleteRegKey HKLM "Software\Clients\News\${ClientsRegName}" + DeleteRegKey HKLM "Software\Clients\Calendar\${ClientsRegName}" DeleteRegValue HKLM "Software\RegisteredApplications" "${AppRegNameMail}" DeleteRegValue HKLM "Software\RegisteredApplications" "${AppRegNameNews}" + DeleteRegValue HKLM "Software\RegisteredApplications" "${AppRegNameCalendar}" ${EndIf} StrCpy $0 "Software\Microsoft\Windows\CurrentVersion\App Paths\${FileMainEXE}"