Bug 577867 - Add widget support for new cityhash based taskbar registration ids. r=neil

This commit is contained in:
Jim Mathies 2011-11-03 09:39:50 -05:00
Родитель 030e6ff4e0
Коммит bbfa3c06c3
3 изменённых файлов: 68 добавлений и 39 удалений

Просмотреть файл

@ -61,6 +61,7 @@
#include "JumpListBuilder.h"
#include "nsWidgetsCID.h"
#include "nsPIDOMWindow.h"
#include "nsAppDirectoryServiceDefs.h"
#include <io.h>
#include <propvarutil.h>
#include <propkey.h>
@ -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<nsIXULAppInfo> 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;
}

Просмотреть файл

@ -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;

Просмотреть файл

@ -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