@@ -43,6 +43,7 @@ PSSTDAPI PropVariantToString(REFPROPVARIANT propvar, PWSTR psz, UINT cch);
4343
4444#include < objbase.h>
4545#include < shlobj.h>
46+ #include < knownfolders.h>
4647#include " WinUtils.h"
4748#include " mozilla/widget/WinTaskbar.h"
4849
@@ -974,6 +975,58 @@ nsWindowsShellService::IsCurrentAppPinnedToTaskbar(/* out */ bool* aIsPinned) {
974975 return NS_OK ;
975976}
976977
978+ NS_IMETHODIMP
979+ nsWindowsShellService::ClassifyShortcut (const nsAString& aPath,
980+ nsAString& aResult) {
981+ aResult.Truncate ();
982+
983+ nsAutoString shortcutPath (PromiseFlatString (aPath));
984+
985+ // NOTE: On Windows 7, Start Menu pin shortcuts are stored under
986+ // "<FOLDERID_User Pinned>\StartMenu", but on Windows 10 they are just normal
987+ // Start Menu shortcuts. These both map to "StartMenu" for consistency,
988+ // rather than having a separate "StartMenuPins" which would only apply on
989+ // Win7.
990+ struct {
991+ KNOWNFOLDERID folderId;
992+ const char16_t * postfix;
993+ const char16_t * classification;
994+ } folders[] = {{FOLDERID_CommonStartMenu, u" \\ " , u" StartMenu" },
995+ {FOLDERID_StartMenu, u" \\ " , u" StartMenu" },
996+ {FOLDERID_PublicDesktop, u" \\ " , u" Desktop" },
997+ {FOLDERID_Desktop, u" \\ " , u" Desktop" },
998+ {FOLDERID_UserPinned, u" \\ TaskBar\\ " , u" Taskbar" },
999+ {FOLDERID_UserPinned, u" \\ StartMenu\\ " , u" StartMenu" }};
1000+
1001+ for (int i = 0 ; i < ArrayLength (folders); ++i) {
1002+ nsAutoString knownPath;
1003+
1004+ // These flags are chosen to avoid I/O, see bug 1363398.
1005+ DWORD flags =
1006+ KF_FLAG_SIMPLE_IDLIST | KF_FLAG_DONT_VERIFY | KF_FLAG_NO_ALIAS ;
1007+ PWSTR rawPath = nullptr ;
1008+
1009+ if (FAILED (SHGetKnownFolderPath (folders[i].folderId , flags, nullptr ,
1010+ &rawPath))) {
1011+ continue ;
1012+ }
1013+
1014+ knownPath = nsDependentString (rawPath);
1015+ CoTaskMemFree (rawPath);
1016+
1017+ knownPath.Append (folders[i].postfix );
1018+ // Check if the shortcut path starts with the shell folder path.
1019+ if (wcsnicmp (shortcutPath.get (), knownPath.get (), knownPath.Length ()) ==
1020+ 0 ) {
1021+ aResult.Assign (folders[i].classification );
1022+ return NS_OK ;
1023+ }
1024+ }
1025+
1026+ // Nothing found, aResult is already "".
1027+ return NS_OK ;
1028+ }
1029+
9771030nsWindowsShellService::nsWindowsShellService () {}
9781031
9791032nsWindowsShellService::~nsWindowsShellService () {}
0 commit comments