Bug 562753 - On upgrade, update AppUserModelID for application shortcuts. r=rstrong.
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
* Asaf Romano <mano@mozilla.com>
|
||||
* Ryan Jones <sciguyryan@gmail.com>
|
||||
* Paul O'Shannessy <paul@oshannessy.com>
|
||||
* Jim Mathies <jmathies@mozilla.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
@@ -63,6 +64,8 @@
|
||||
#include "nsDirectoryServiceDefs.h"
|
||||
#include "nsIWindowsRegKey.h"
|
||||
#include "nsUnicharUtils.h"
|
||||
#include "nsIWinTaskbar.h"
|
||||
#include "nsISupportsPrimitives.h"
|
||||
|
||||
#include "windows.h"
|
||||
#include "shellapi.h"
|
||||
@@ -86,6 +89,8 @@
|
||||
#define REG_FAILED(val) \
|
||||
(val != ERROR_SUCCESS)
|
||||
|
||||
#define NS_TASKBAR_CONTRACTID "@mozilla.org/windows-taskbar;1"
|
||||
|
||||
#ifndef WINCE
|
||||
NS_IMPL_ISUPPORTS2(nsWindowsShellService, nsIWindowsShellService, nsIShellService)
|
||||
#else
|
||||
@@ -268,6 +273,127 @@ static SETTING gSettings[] = {
|
||||
{ MAKE_KEY_NAME1("HTTPS", SOP), "", VAL_OPEN }
|
||||
};
|
||||
|
||||
#if !defined(WINCE)
|
||||
nsresult
|
||||
GetHelperPath(nsAutoString& aPath)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIProperties> directoryService =
|
||||
do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsILocalFile> appHelper;
|
||||
rv = directoryService->Get(NS_XPCOM_CURRENT_PROCESS_DIR,
|
||||
NS_GET_IID(nsILocalFile),
|
||||
getter_AddRefs(appHelper));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = appHelper->AppendNative(NS_LITERAL_CSTRING("uninstall"));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = appHelper->AppendNative(NS_LITERAL_CSTRING("helper.exe"));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return appHelper->GetPath(aPath);
|
||||
}
|
||||
|
||||
nsresult
|
||||
LaunchHelper(nsAutoString& aPath)
|
||||
{
|
||||
STARTUPINFOW si = {sizeof(si), 0};
|
||||
PROCESS_INFORMATION pi = {0};
|
||||
|
||||
BOOL ok = CreateProcessW(NULL, (LPWSTR)aPath.get(), NULL, NULL,
|
||||
FALSE, 0, NULL, NULL, &si, &pi);
|
||||
|
||||
if (!ok)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
CloseHandle(pi.hProcess);
|
||||
CloseHandle(pi.hThread);
|
||||
return NS_OK;
|
||||
}
|
||||
#endif // !defined(WINCE)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsWindowsShellService::ShortcutMaintenance()
|
||||
{
|
||||
#if !defined(WINCE)
|
||||
nsresult rv;
|
||||
|
||||
// Launch helper.exe so it can update the application user model ids on
|
||||
// shortcuts in the user's taskbar and start menu. This keeps older pinned
|
||||
// shortcuts grouped correctly after major updates. Note, we also do this
|
||||
// through the upgrade installer script, however, this is the only place we
|
||||
// have a chance to trap links created by users who do control the install/
|
||||
// update process of the browser.
|
||||
|
||||
nsCOMPtr<nsIWinTaskbar> taskbarInfo =
|
||||
do_GetService(NS_TASKBAR_CONTRACTID);
|
||||
if (!taskbarInfo) // If we haven't built with win7 sdk features, this fails.
|
||||
return NS_OK;
|
||||
|
||||
// Avoid if this isn't Win7+
|
||||
PRBool isSupported = PR_FALSE;
|
||||
taskbarInfo->GetAvailable(&isSupported);
|
||||
if (!isSupported)
|
||||
return NS_OK;
|
||||
|
||||
nsAutoString appId;
|
||||
if (NS_FAILED(taskbarInfo->GetDefaultGroupId(appId)))
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
NS_NAMED_LITERAL_CSTRING(prefName, "browser.taskbar.lastgroupid");
|
||||
nsCOMPtr<nsIPrefService> prefs =
|
||||
do_GetService(NS_PREFSERVICE_CONTRACTID);
|
||||
if (!prefs)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
nsCOMPtr<nsIPrefBranch> prefBranch;
|
||||
prefs->GetBranch(nsnull, getter_AddRefs(prefBranch));
|
||||
if (!prefBranch)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
nsCOMPtr<nsISupportsString> prefString;
|
||||
rv = prefBranch->GetComplexValue(prefName.get(),
|
||||
NS_GET_IID(nsISupportsString),
|
||||
getter_AddRefs(prefString));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsAutoString version;
|
||||
prefString->GetData(version);
|
||||
if (!version.IsEmpty() && version.Equals(appId)) {
|
||||
// We're all good, get out of here.
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
// Update the version in prefs
|
||||
prefString =
|
||||
do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
prefString->SetData(appId);
|
||||
rv = prefBranch->SetComplexValue(prefName.get(),
|
||||
NS_GET_IID(nsISupportsString),
|
||||
prefString);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("Couldn't set last user model id!");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
nsAutoString appHelperPath;
|
||||
if (NS_FAILED(GetHelperPath(appHelperPath)))
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
appHelperPath.AppendLiteral(" /UpdateShortcutAppUserModelIds");
|
||||
|
||||
return LaunchHelper(appHelperPath);
|
||||
#else
|
||||
NS_NOTREACHED("ShortcutMaintenance not implemented on wince!");
|
||||
return NS_OK;
|
||||
#endif // !defined(WINCE)
|
||||
}
|
||||
|
||||
#ifndef WINCE
|
||||
PRBool
|
||||
nsWindowsShellService::IsDefaultBrowserVista(PRBool* aIsDefaultBrowser)
|
||||
@@ -366,24 +492,9 @@ NS_IMETHODIMP
|
||||
nsWindowsShellService::SetDefaultBrowser(PRBool aClaimAllTypes, PRBool aForAllUsers)
|
||||
{
|
||||
#ifndef WINCE
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIProperties> directoryService =
|
||||
do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsILocalFile> appHelper;
|
||||
rv = directoryService->Get(NS_XPCOM_CURRENT_PROCESS_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(appHelper));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = appHelper->AppendNative(NS_LITERAL_CSTRING("uninstall"));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = appHelper->AppendNative(NS_LITERAL_CSTRING("helper.exe"));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsAutoString appHelperPath;
|
||||
rv = appHelper->GetPath(appHelperPath);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (NS_FAILED(GetHelperPath(appHelperPath)))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
if (aForAllUsers) {
|
||||
appHelperPath.AppendLiteral(" /SetAsDefaultAppGlobal");
|
||||
@@ -391,17 +502,7 @@ nsWindowsShellService::SetDefaultBrowser(PRBool aClaimAllTypes, PRBool aForAllUs
|
||||
appHelperPath.AppendLiteral(" /SetAsDefaultAppUser");
|
||||
}
|
||||
|
||||
STARTUPINFOW si = {sizeof(si), 0};
|
||||
PROCESS_INFORMATION pi = {0};
|
||||
|
||||
BOOL ok = CreateProcessW(NULL, (LPWSTR)appHelperPath.get(), NULL, NULL,
|
||||
FALSE, 0, NULL, NULL, &si, &pi);
|
||||
|
||||
if (!ok)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
CloseHandle(pi.hProcess);
|
||||
CloseHandle(pi.hThread);
|
||||
return LaunchHelper(appHelperPath);
|
||||
#else
|
||||
SETTING* settings;
|
||||
SETTING* end = gSettings + sizeof(gSettings)/sizeof(SETTING);
|
||||
|
||||
Reference in New Issue
Block a user