Bug 563381 - Sync AppUserModelID with plugin-container. r=bsmedberg.

This commit is contained in:
Jim Mathies 2010-05-14 19:25:10 -05:00
Родитель 80aa8025c6
Коммит 60b7d64908
2 изменённых файлов: 80 добавлений и 0 удалений

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

@ -56,6 +56,11 @@
#include "mozilla/ipc/BrowserProcessSubThread.h"
#ifdef XP_WIN
#include "nsIWinTaskbar.h"
#define NS_TASKBAR_CONTRACTID "@mozilla.org/windows-taskbar;1"
#endif
using mozilla::MonitorAutoEnter;
using mozilla::ipc::GeckoChildProcessHost;
@ -265,6 +270,31 @@ GeckoChildProcessHost::PerformAsyncLaunch(std::vector<std::string> aExtraOpts)
cmdLine.AppendLooseValue(UTF8ToWide(*it));
}
// On Win7+, pass the application user model to the child, so it can
// register with it. This insures windows created by the container
// properly group with the parent app on the Win7 taskbar.
nsCOMPtr<nsIWinTaskbar> taskbarInfo =
do_GetService(NS_TASKBAR_CONTRACTID);
PRBool set = PR_FALSE;
if (taskbarInfo) {
PRBool isSupported = PR_FALSE;
taskbarInfo->GetAvailable(&isSupported);
if (isSupported) {
// Set the id for the container.
nsAutoString appId, param;
param.Append(PRUnichar('\"'));
if (NS_SUCCEEDED(taskbarInfo->GetDefaultGroupId(appId))) {
param.Append(appId);
param.Append(PRUnichar('\"'));
cmdLine.AppendLooseValue(std::wstring(param.get()));
set = PR_TRUE;
}
}
}
if (!set) {
cmdLine.AppendLooseValue(std::wstring(L"-"));
}
cmdLine.AppendLooseValue(UTF8ToWide(pidstring));
cmdLine.AppendLooseValue(UTF8ToWide(childProcessType));
#if defined(MOZ_CRASHREPORTER)

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

@ -111,6 +111,10 @@ using mozilla::startup::sChildProcessType;
static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
#ifdef XP_WIN
static const PRUnichar kShellLibraryName[] = L"shell32.dll";
#endif
void
XRE_GetStaticComponents(nsStaticModuleInfo const **aStaticComponents,
PRUint32 *aComponentCount)
@ -274,6 +278,33 @@ XRE_SetRemoteExceptionHandler(const char* aPipe/*= 0*/)
#endif // !XP_MACOSX
#endif // if defined(MOZ_CRASHREPORTER)
#if defined(XP_WIN)
void
SetTaskbarGroupId(const nsString& aId)
{
typedef HRESULT (WINAPI * SetCurrentProcessExplicitAppUserModelIDPtr)(PCWSTR AppID);
SetCurrentProcessExplicitAppUserModelIDPtr funcAppUserModelID = nsnull;
HMODULE hDLL = ::LoadLibraryW(kShellLibraryName);
funcAppUserModelID = (SetCurrentProcessExplicitAppUserModelIDPtr)
GetProcAddress(hDLL, "SetCurrentProcessExplicitAppUserModelID");
if (!funcAppUserModelID) {
::FreeLibrary(hDLL);
return;
}
if (FAILED(funcAppUserModelID(aId.get()))) {
NS_WARNING("SetCurrentProcessExplicitAppUserModelID failed for child process.");
}
if (hDLL)
::FreeLibrary(hDLL);
}
#endif
nsresult
XRE_InitChildProcess(int aArgc,
char* aArgv[],
@ -318,6 +349,25 @@ XRE_InitChildProcess(int aArgc,
bool ok = base::OpenProcessHandle(parentPID, &parentHandle);
NS_ABORT_IF_FALSE(ok, "can't open handle to parent");
#if defined(XP_WIN)
// On Win7+, register the application user model id passed in by
// parent. This insures windows created by the container properly
// group with the parent app on the Win7 taskbar.
const char* const appModelUserId = aArgv[aArgc-1];
--aArgc;
if (appModelUserId) {
// '-' implies no support
if (*appModelUserId != '-') {
nsString appId;
appId.AssignWithConversion(nsDependentCString(appModelUserId));
// The version string is encased in quotes
appId.Trim(NS_LITERAL_CSTRING("\"").get());
// Set the id
SetTaskbarGroupId(appId);
}
}
#endif
base::AtExitManager exitManager;
NotificationService notificationService;