From bbfa3c06c33ac6cd99c3bbd1b6ab3d63049c934c Mon Sep 17 00:00:00 2001 From: Jim Mathies Date: Thu, 3 Nov 2011 09:39:50 -0500 Subject: [PATCH] Bug 577867 - Add widget support for new cityhash based taskbar registration ids. r=neil --- widget/src/windows/WinTaskbar.cpp | 61 +++++++++++++++++++++---------- widget/src/windows/nsWindow.cpp | 41 +++++++++++---------- widget/src/windows/nsWindow.h | 5 +++ 3 files changed, 68 insertions(+), 39 deletions(-) diff --git a/widget/src/windows/WinTaskbar.cpp b/widget/src/windows/WinTaskbar.cpp index 9035d84a270f..48344b2443a9 100644 --- a/widget/src/windows/WinTaskbar.cpp +++ b/widget/src/windows/WinTaskbar.cpp @@ -61,6 +61,7 @@ #include "JumpListBuilder.h" #include "nsWidgetsCID.h" #include "nsPIDOMWindow.h" +#include "nsAppDirectoryServiceDefs.h" #include #include #include @@ -273,33 +274,53 @@ WinTaskbar::~WinTaskbar() { // static bool WinTaskbar::GetAppUserModelID(nsAString & aDefaultGroupId) { + // The default value is set by the installer and is stored in the registry + // under (HKLM||HKCU)/Software/Mozilla/Firefox/TaskBarIDs. If for any reason + // hash generation operation fails, the installer will not store a value in + // the registry or set ids on shortcuts. A lack of an id can also occur for + // zipped builds. We skip setting the global id in this case as well. nsCOMPtr appInfo = do_GetService("@mozilla.org/xre/app-info;1"); if (!appInfo) return false; - // The default, pulled from application.ini: - // 'vendor.application.version' - nsCString val; - if (NS_SUCCEEDED(appInfo->GetVendor(val))) { - AppendASCIItoUTF16(val, aDefaultGroupId); - aDefaultGroupId.Append(PRUnichar('.')); - } - if (NS_SUCCEEDED(appInfo->GetName(val))) { - AppendASCIItoUTF16(val, aDefaultGroupId); - aDefaultGroupId.Append(PRUnichar('.')); - } - if (NS_SUCCEEDED(appInfo->GetVersion(val))) { - AppendASCIItoUTF16(val, aDefaultGroupId); - } - - if (aDefaultGroupId.IsEmpty()) + nsCString appName; + if (NS_FAILED(appInfo->GetName(appName))) { + // We just won't register then, let Windows handle it. return false; + } - // Differentiate 64-bit builds -#if defined(_WIN64) - aDefaultGroupId.AppendLiteral(".Win64"); -#endif + nsAutoString regKey; + regKey.AssignLiteral("Software\\Mozilla\\"); + AppendASCIItoUTF16(appName, regKey); + regKey.AppendLiteral("\\TaskBarIDs"); + + WCHAR path[MAX_PATH]; + if (GetModuleFileNameW(NULL, path, MAX_PATH)) { + PRUnichar* slash = wcsrchr(path, '\\'); + if (!slash) + return false; + *slash = '\0'; // no trailing slash + + // The hash is short, but users may customize this, so use a respectable + // string buffer. + PRUnichar buf[256]; + if (nsWindow::GetRegistryKey(HKEY_LOCAL_MACHINE, + regKey.get(), + path, + buf, + sizeof buf)) { + aDefaultGroupId.Assign(buf); + } else if (nsWindow::GetRegistryKey(HKEY_CURRENT_USER, + regKey.get(), + path, + buf, + sizeof buf)) { + aDefaultGroupId.Assign(buf); + } + } + + return !aDefaultGroupId.IsEmpty(); return true; } diff --git a/widget/src/windows/nsWindow.cpp b/widget/src/windows/nsWindow.cpp index d1222c71fec9..47f677a72fbe 100644 --- a/widget/src/windows/nsWindow.cpp +++ b/widget/src/windows/nsWindow.cpp @@ -9030,12 +9030,15 @@ HasRegistryKey(HKEY aRoot, PRUnichar* aName) * @param aBufferLength The size of aBuffer, in bytes. * @return Whether the value exists and is a string. */ -static bool -GetRegistryKey(HKEY aRoot, PRUnichar* aKeyName, PRUnichar* aValueName, PRUnichar* aBuffer, DWORD aBufferLength) +bool +nsWindow::GetRegistryKey(HKEY aRoot, + const PRUnichar* aKeyName, + const PRUnichar* aValueName, + PRUnichar* aBuffer, + DWORD aBufferLength) { - if (!aKeyName) { + if (!aKeyName) return false; - } HKEY key; LONG result = ::RegOpenKeyExW(aRoot, aKeyName, NULL, KEY_READ | KEY_WOW64_32KEY, &key); @@ -9058,11 +9061,11 @@ static bool IsObsoleteSynapticsDriver() { PRUnichar buf[40]; - bool foundKey = GetRegistryKey(HKEY_LOCAL_MACHINE, - L"Software\\Synaptics\\SynTP\\Install", - L"DriverVersion", - buf, - sizeof buf); + bool foundKey = nsWindow::GetRegistryKey(HKEY_LOCAL_MACHINE, + L"Software\\Synaptics\\SynTP\\Install", + L"DriverVersion", + buf, + sizeof buf); if (!foundKey) return false; @@ -9080,17 +9083,17 @@ GetElantechDriverMajorVersion() { PRUnichar buf[40]; // The driver version is found in one of these two registry keys. - bool foundKey = GetRegistryKey(HKEY_CURRENT_USER, - L"Software\\Elantech\\MainOption", - L"DriverVersion", - buf, - sizeof buf); + bool foundKey = nsWindow::GetRegistryKey(HKEY_CURRENT_USER, + L"Software\\Elantech\\MainOption", + L"DriverVersion", + buf, + sizeof buf); if (!foundKey) - foundKey = GetRegistryKey(HKEY_CURRENT_USER, - L"Software\\Elantech", - L"DriverVersion", - buf, - sizeof buf); + foundKey = nsWindow::GetRegistryKey(HKEY_CURRENT_USER, + L"Software\\Elantech", + L"DriverVersion", + buf, + sizeof buf); if (!foundKey) return false; diff --git a/widget/src/windows/nsWindow.h b/widget/src/windows/nsWindow.h index 7de435fe90be..07677f5185fb 100644 --- a/widget/src/windows/nsWindow.h +++ b/widget/src/windows/nsWindow.h @@ -205,6 +205,11 @@ public: * Statics used in other classes */ static PRInt32 GetWindowsVersion(); + static bool GetRegistryKey(HKEY aRoot, + const PRUnichar* aKeyName, + const PRUnichar* aValueName, + PRUnichar* aBuffer, + DWORD aBufferLength); /** * Event helpers