From 0210e257d7dd33f40f8515cfa507aff832753664 Mon Sep 17 00:00:00 2001 From: Ben Hearsum Date: Mon, 27 Jun 2022 16:31:36 +0000 Subject: [PATCH] Bug 1771951: add pin to taskbar support in the installer on Windows 10 & 11 r=mhowell This patch starts pinning Firefox to the Taskbar by default on all supported Windows versions. The main addition here is a port of our existing taskbar pinning code for modern Windows 10 & 11 versions to an NSIS plugin (compiled version also included). After discussion with a few stakeholders, we also decided that we will never pin during an update on Windows 10 or 11. (Arguably we could stop on Windows 7 & 8 as well - but I don't really see any harm in carrying forward our pre-existing behaviour there.) With this in mind, I dropped all the second pinning attempt code (which was only ever enabled for Windows 10). Differential Revision: https://phabricator.services.mozilla.com/D148288 --- browser/installer/windows/nsis/shared.nsh | 42 ++--- .../Contrib/PinToTaskbar/PinToTaskbar.cpp | 150 +++++++++++++++ .../Contrib/PinToTaskbar/PinToTaskbar.sln | 31 ++++ .../Contrib/PinToTaskbar/PinToTaskbar.vcxproj | 175 ++++++++++++++++++ other-licenses/nsis/Plugins/PinToTaskbar.dll | Bin 0 -> 3584 bytes .../installer/windows/nsis/makensis.mk | 1 + 6 files changed, 374 insertions(+), 25 deletions(-) create mode 100644 other-licenses/nsis/Contrib/PinToTaskbar/PinToTaskbar.cpp create mode 100644 other-licenses/nsis/Contrib/PinToTaskbar/PinToTaskbar.sln create mode 100644 other-licenses/nsis/Contrib/PinToTaskbar/PinToTaskbar.vcxproj create mode 100644 other-licenses/nsis/Plugins/PinToTaskbar.dll diff --git a/browser/installer/windows/nsis/shared.nsh b/browser/installer/windows/nsis/shared.nsh index 5554e88488da..101942da9d9f 100755 --- a/browser/installer/windows/nsis/shared.nsh +++ b/browser/installer/windows/nsis/shared.nsh @@ -40,7 +40,16 @@ ${EndIf} ; Adds a pinned Task Bar shortcut (see MigrateTaskBarShortcut for details). - ${MigrateTaskBarShortcut} + ; When we enabled this feature for Windows 10 & 11 we decided _not_ to pin + ; during an update (even once) because we already offered to do when the + ; the user originally installed, and we don't want to go against their + ; explicit wishes. + ; For Windows 7 and 8, we've been doing this ~forever, and those users may + ; not have experienced the onboarding offer to pin to taskbar, so we're + ; leaving it enabled there. + ${If} ${AtMostWin2012R2} + ${MigrateTaskBarShortcut} + ${EndIf} ; Update the name/icon/AppModelID of our shortcuts as needed, then update the ; lastwritetime of the Start Menu shortcut to clear the tile icon cache. @@ -1292,28 +1301,6 @@ ${RemoveDefaultBrowserAgentShortcut} ${PinToTaskBar} ${EndIf} ${EndIf} - ${ElseIf} ${AtLeastWin10} - ${GetInstallerRegistryPref} "Software\Mozilla\${AppName}" \ - "installer.taskbarpin.win10.enabled" $2 - ${If} $2 == "true" - ; On Windows 10, we may have previously tried to make a taskbar pin - ; and failed because the API we tried to use was blocked by the OS. - ; We have an option that works in more cases now, so we're going to try - ; again, but also record that we've done so by writing a particular - ; registry value, so that we don't continue to do this repeatedly. - ClearErrors - ReadRegDWORD $2 HKCU \ - "Software\Mozilla\${AppName}\Installer\$AppUserModelID" \ - "WasPinnedToTaskbar" - ${If} ${Errors} - WriteRegDWORD HKCU \ - "Software\Mozilla\${AppName}\Installer\$AppUserModelID" \ - "WasPinnedToTaskbar" 1 - ${If} $AddTaskbarSC != "0" - ${PinToTaskBar} - ${EndIf} - ${EndIf} - ${EndIf} ${EndIf} ${EndIf} !macroend @@ -1380,17 +1367,22 @@ ${RemoveDefaultBrowserAgentShortcut} ; Pin the shortcut to the TaskBar. 5386 is the shell32.dll ; resource id for the "Pin to Taskbar" string. InvokeShellVerb::DoIt "$SMPROGRAMS" "$1" "5386" - ${Else} + ${ElseIf} ${AtMostWaaS} 1809 ; In Windows 10 the "Pin to Taskbar" resource was removed, so we ; can't access the verb that way anymore. We have a create a ; command key using the GUID that's assigned to this action and - ; then invoke that as a verb. + ; then invoke that as a verb. This works up until build 1809 ReadRegStr $R9 HKLM \ "Software\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Windows.taskbarpin" \ "ExplorerCommandHandler" WriteRegStr HKCU "Software\Classes\*\shell\${AppRegName}-$AppUserModelID" "ExplorerCommandHandler" $R9 InvokeShellVerb::DoIt "$SMPROGRAMS" "$1" "${AppRegName}-$AppUserModelID" DeleteRegKey HKCU "Software\Classes\*\shell\${AppRegName}-$AppUserModelID" + ${Else} + ; In the Windows 10 1903 and up (and Windows 11) the above no + ; longer works. We have yet another method for these versions + ; which is detailed in the PinToTaskbar plugin code. + PinToTaskbar::Pin "$SMPROGRAMS\$1" ${EndIf} ; Delete the shortcut if it was created diff --git a/other-licenses/nsis/Contrib/PinToTaskbar/PinToTaskbar.cpp b/other-licenses/nsis/Contrib/PinToTaskbar/PinToTaskbar.cpp new file mode 100644 index 000000000000..c891680549f2 --- /dev/null +++ b/other-licenses/nsis/Contrib/PinToTaskbar/PinToTaskbar.cpp @@ -0,0 +1,150 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, you can obtain one at http://mozilla.org/MPL/2.0/. */ + +// This file is an NSIS plugin which exports a function that pins a provided +// Shortcut to the Windows Taskbar on Windows 10 (1903+) and Windows 11. +// This is an adapted version of the Pin to Taskbar code that is used in +// Firefox: https://searchfox.org/mozilla-central/rev/4bce7d85ba4796dd03c5dcc7cfe8eee0e4c07b3b/browser/components/shell/nsWindowsShellService.cpp#1178 + +#include +#include + +#pragma comment(lib, "shlwapi.lib") + +static bool +PinShortcutToTaskbar(const wchar_t *shortcutPath) +{ + // This enum is likely only used for Windows telemetry, INT_MAX is chosen to + // avoid confusion with existing uses. + enum PINNEDLISTMODIFYCALLER { PLMC_INT_MAX = INT_MAX }; + + // The types below, and the idea of using IPinnedList3::Modify, + // are thanks to Gee Law + static constexpr GUID CLSID_TaskbandPin = { + 0x90aa3a4e, + 0x1cba, + 0x4233, + {0xb8, 0xbb, 0x53, 0x57, 0x73, 0xd4, 0x84, 0x49}}; + + static constexpr GUID IID_IPinnedList3 = { + 0x0dd79ae2, + 0xd156, + 0x45d4, + {0x9e, 0xeb, 0x3b, 0x54, 0x97, 0x69, 0xe9, 0x40}}; + + struct IPinnedList3Vtbl; + struct IPinnedList3 { + IPinnedList3Vtbl* vtbl; + }; + + typedef ULONG STDMETHODCALLTYPE ReleaseFunc(IPinnedList3 * that); + typedef HRESULT STDMETHODCALLTYPE ModifyFunc( + IPinnedList3 * that, PCIDLIST_ABSOLUTE unpin, PCIDLIST_ABSOLUTE pin, + PINNEDLISTMODIFYCALLER caller); + + struct IPinnedList3Vtbl { + void* QueryInterface; // 0 + void* AddRef; // 1 + ReleaseFunc* Release; // 2 + void* Other[13]; // 3-15 + ModifyFunc* Modify; // 16 + }; + + PIDLIST_ABSOLUTE path = nullptr; + HRESULT hr = SHParseDisplayName(shortcutPath, nullptr, &path, 0, nullptr); + if (FAILED(hr) || !path) { + return false; + } + + IPinnedList3* pinnedList = nullptr; + hr = CoCreateInstance(CLSID_TaskbandPin, nullptr, CLSCTX_INPROC_SERVER, + IID_IPinnedList3, (void**)&pinnedList); + if (FAILED(hr) || !pinnedList) { + return false; + } + + hr = pinnedList->vtbl->Modify(pinnedList, nullptr, path, PLMC_INT_MAX); + + pinnedList->vtbl->Release(pinnedList); + CoTaskMemFree(path); + return true; +} + +struct stack_t { + stack_t* next; + TCHAR text[MAX_PATH]; +}; + +/** + * Removes an element from the top of the NSIS stack + * + * @param stacktop A pointer to the top of the stack + * @param str The string to pop to + * @param len The max length + * @return 0 on success + */ +int +popstring(stack_t **stacktop, TCHAR *str, int len) +{ + // Removes the element from the top of the stack and puts it in the buffer + stack_t *th; + if (!stacktop || !*stacktop) { + return 1; + } + + th = (*stacktop); + lstrcpyn(str, th->text, len); + *stacktop = th->next; + HeapFree(GetProcessHeap(), 0, th); + return 0; +} + +/** + * Adds an element to the top of the NSIS stack + * + * @param stacktop A pointer to the top of the stack + * @param str The string to push on the stack + * @param len The length of the string to push on the stack + * @return 0 on success + */ +void +pushstring(stack_t **stacktop, const TCHAR *str, int len) +{ + stack_t *th; + if (!stacktop) { + return; + } + th = (stack_t*)HeapAlloc(GetProcessHeap(), 0, sizeof(stack_t) + len); + lstrcpyn(th->text, str, len); + th->next = *stacktop; + *stacktop = th; +} + +/** +* Pins a provided shortcut to the Taskbar on Windows 10 (1903) and up. +* +* @param stacktop Pointer to the top of the stack, AKA the first parameter to + the plugin call. Should contain the shortcut to pin. +* @return 1 if the shortcut was pinned successfully, otherwise 0 +*/ +extern "C" void __declspec(dllexport) +Pin(HWND, int, TCHAR *, stack_t **stacktop, void *) +{ + wchar_t shortcutPath[MAX_PATH + 1]; + bool rv = false; + // We're skipping building the C runtime to keep the file size low, so we + // can't use a normal string initialization because that would call memset. + shortcutPath[0] = L'\0'; + popstring(stacktop, shortcutPath, MAX_PATH); + + rv = PinShortcutToTaskbar(shortcutPath); + + pushstring(stacktop, rv ? L"1" : L"0", 2); +} + +BOOL APIENTRY +DllMain(HMODULE, DWORD, LPVOID) +{ + return TRUE; +} diff --git a/other-licenses/nsis/Contrib/PinToTaskbar/PinToTaskbar.sln b/other-licenses/nsis/Contrib/PinToTaskbar/PinToTaskbar.sln new file mode 100644 index 000000000000..834ba1c920dd --- /dev/null +++ b/other-licenses/nsis/Contrib/PinToTaskbar/PinToTaskbar.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.27428.2015 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PinToTaskbar", "PinToTaskbar.vcxproj", "{84FDFDE2-893F-418F-A524-4B8DACF11EB6}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {84FDFDE2-893F-418F-A524-4B8DACF11EB6}.Debug|x64.ActiveCfg = Debug|x64 + {84FDFDE2-893F-418F-A524-4B8DACF11EB6}.Debug|x64.Build.0 = Debug|x64 + {84FDFDE2-893F-418F-A524-4B8DACF11EB6}.Debug|x86.ActiveCfg = Debug|Win32 + {84FDFDE2-893F-418F-A524-4B8DACF11EB6}.Debug|x86.Build.0 = Debug|Win32 + {84FDFDE2-893F-418F-A524-4B8DACF11EB6}.Release|x64.ActiveCfg = Release|x64 + {84FDFDE2-893F-418F-A524-4B8DACF11EB6}.Release|x64.Build.0 = Release|x64 + {84FDFDE2-893F-418F-A524-4B8DACF11EB6}.Release|x86.ActiveCfg = Release|Win32 + {84FDFDE2-893F-418F-A524-4B8DACF11EB6}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {975FF9C9-7351-4314-BC67-F348FAC9ECB2} + EndGlobalSection +EndGlobal diff --git a/other-licenses/nsis/Contrib/PinToTaskbar/PinToTaskbar.vcxproj b/other-licenses/nsis/Contrib/PinToTaskbar/PinToTaskbar.vcxproj new file mode 100644 index 000000000000..d62b3457575c --- /dev/null +++ b/other-licenses/nsis/Contrib/PinToTaskbar/PinToTaskbar.vcxproj @@ -0,0 +1,175 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {84fdfde2-893f-418f-a524-4b8dacf11eb6} + Win32Proj + PinToTaskbar + 10.0.15063.0 + + + + DynamicLibrary + true + v143 + Unicode + + + DynamicLibrary + false + v143 + true + Unicode + + + DynamicLibrary + true + v143 + Unicode + + + DynamicLibrary + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + false + + + false + + + false + + + false + + + + NotUsing + Level3 + Disabled + false + WIN32;_DEBUG;EXECINEXPLORER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + MultiThreadedDebug + true + false + Default + + + Windows + true + DllMain + Default + + + + + NotUsing + Level3 + Disabled + false + _DEBUG;EXECINEXPLORER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + MultiThreadedDebug + true + false + Default + + + Windows + true + DllMain + Default + + + + + NotUsing + Level3 + MaxSpeed + true + true + false + WIN32;NDEBUG;EXECINEXPLORER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + MultiThreaded + true + false + false + + + Windows + true + true + false + DllMain + Default + + + + + NotUsing + Level3 + MaxSpeed + true + true + false + NDEBUG;EXECINEXPLORER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + MultiThreaded + true + false + false + + + Windows + true + true + false + DllMain + Default + + + + + + + + + diff --git a/other-licenses/nsis/Plugins/PinToTaskbar.dll b/other-licenses/nsis/Plugins/PinToTaskbar.dll new file mode 100644 index 0000000000000000000000000000000000000000..0659dc5f033f732845eed6f2c3936979109beb01 GIT binary patch literal 3584 zcmeHJU1%It6h6CM(``-S1{&%^pf@GBeP}nkiTxq&noXOj32xJElcpfmcCveuo$dT= zXJ(fq5RBA773J`~AAbUf$oOu7v*`ldn; zd+#~tJLlY=bMHN~2cA0*>i{5x&2<6hkrSmwzjk*M&5c_wH^PS-uD8wyGS^#&3W~)_ zrZHy98q3MLZrE&uGqbESMQ6PS2bpH%d90yfW1BZLFMYqawdq`w-`1Tv8+k(LXPbz> zQ+Or91V88TQd3o*6Z&B#SD@IHE6qv(nLr563|$=YZMPuU`e>kW3j`4fSJCqkVLJC6q5fMaj6d-t&l^8%DqSsnMgg_kNR)G9gP#S=8kYxZZD@<#u z=)Y|ZhnUUBZL}Y!IcZ(AS8v@Y31R>zVrE{pWq_MxM?m=an?{u=jlY;_nK_ij9&j&W zyp70fC@uWBYM`SyR|JG#eT@@}2=9Fmd8qx{893tHJ$*M^gd)sIOIM{OT2HnJZaM5W zZ(2ZT4F$KERUJE>1B)|X+S{E#!FAmi-SU!? zP8Z>jyWmKRStsoDgxv*1-R2eyct7C$@cd^TSE#?XO!IVaKdlEJ!1cX!w;nI)u(LCS zQJq(gI#ZiQXJ_vH?z%IsopE;0{AQ;MA&i^bAIi=NL)L8$qq9@zMHOLoz55NKc-14G z%TEDZ6f85BS2!>$;7toMsU za|5A6-mL3q>t=T!e}Ohe>H1Gob}PU!Y&y1HY(!@~{t5C+o;=WX>HOuE&b{*=4<5B{ zyxf2L&2JlqzrG<|xbxJ|>&nmR1jbQ$Ao6Q&1IqWX-DKEmY76Eazcc_B5vSw!+Z(9A zh3#!>Si3$zj<-?Khm0ZFIyoYnvAn7h0Pr|kg44li@*rAZUP;F|QTqt=WKk2_G>k%G z)%qDzsQ$I>BnU6DsM&r^^lNyGS8L=v+VKZfdt1d&Z7q*F?Thy3;gge-`H?ZysrDxc zug=kdB7`xIo9<(sgtZ_>wcPW2k}x`h*Y0Dx2&2TFKqhK&Tbxo2ClH$sEMsC08qcRm zk{O29U>8uvHw}Agu&+?Y*SISE)4P#c*T>~jk4hha9wF~HIR|(z_zbtRrjg^8MIHd# z>r~4&bEOIWC_F129*{Df9pX&k)xcn1RyHl(t5_vfo*0ld9AU6e%J?qZV4tzizg{s;ax==xN>7g7Mk+cgs}_&4_T_Ps?SDN>vi*TICEJ%bhvCU~KX0h4 wJdD-!NcBHkOMF+nJ1)g5@pt3j#c#)diEl`>C%O{diG!lvtQPtZ`~PR)Pxg55XaE2J literal 0 HcmV?d00001 diff --git a/toolkit/mozapps/installer/windows/nsis/makensis.mk b/toolkit/mozapps/installer/windows/nsis/makensis.mk index b175c77e21b0..4fa6dea94810 100755 --- a/toolkit/mozapps/installer/windows/nsis/makensis.mk +++ b/toolkit/mozapps/installer/windows/nsis/makensis.mk @@ -41,6 +41,7 @@ CUSTOM_NSIS_PLUGINS = \ InvokeShellVerb.dll \ liteFirewallW.dll \ nsJSON.dll \ + PinToTaskbar.dll \ ServicesHelper.dll \ ShellLink.dll \ UAC.dll \