bug 352424. Default Application on Vista not working. r=rob_strong

This commit is contained in:
dougt@meer.net
2006-09-22 14:45:57 +00:00
parent 15f3bc0d9e
commit 20d5a19da4
2 changed files with 134 additions and 5 deletions

View File

@@ -192,6 +192,7 @@ typedef struct {
#define SOP "\\shell\\open\\command" #define SOP "\\shell\\open\\command"
#define DDE "\\shell\\open\\ddeexec\\" #define DDE "\\shell\\open\\ddeexec\\"
#define DDE_NAME "Firefox" // This must be kept in sync with ID_DDE_APPLICATION_NAME as defined in splash.rc #define DDE_NAME "Firefox" // This must be kept in sync with ID_DDE_APPLICATION_NAME as defined in splash.rc
#define APP_REG_NAME L"Firefox"
#define DDE_COMMAND "\"%1\",,0,0,,,," #define DDE_COMMAND "\"%1\",,0,0,,,,"
#define DDE_IFEXEC ",,0,0,,,," #define DDE_IFEXEC ",,0,0,,,,"
#define EXE "firefox.exe" #define EXE "firefox.exe"
@@ -289,9 +290,126 @@ static SETTING gSettings[] = {
// firefox.exe\shell\safemode (default) REG_SZ Firefox &Safe Mode // firefox.exe\shell\safemode (default) REG_SZ Firefox &Safe Mode
}; };
#ifndef __shobjidl_h__
// This block should be removed when our build environment
// is migrated to the latest windows sdk.
typedef enum tagASSOCIATIONLEVEL
{
AL_MACHINE,
AL_EFFECTIVE,
AL_USER
} ASSOCIATIONLEVEL;
typedef enum tagASSOCIATIONTYPE
{
AT_FILEEXTENSION,
AT_URLPROTOCOL,
AT_STARTMENUCLIENT,
AT_MIMETYPE
} ASSOCIATIONTYPE;
MIDL_INTERFACE("4e530b0a-e611-4c77-a3ac-9031d022281b")
IApplicationAssociationRegistration : public IUnknown
{
public:
virtual HRESULT STDMETHODCALLTYPE QueryCurrentDefault(LPCWSTR pszQuery,
ASSOCIATIONTYPE atQueryType,
ASSOCIATIONLEVEL alQueryLevel,
LPWSTR *ppszAssociation) = 0;
virtual HRESULT STDMETHODCALLTYPE QueryAppIsDefault(LPCWSTR pszQuery,
ASSOCIATIONTYPE atQueryType,
ASSOCIATIONLEVEL alQueryLevel,
LPCWSTR pszAppRegistryName,
BOOL *pfDefault) = 0;
virtual HRESULT STDMETHODCALLTYPE QueryAppIsDefaultAll(ASSOCIATIONLEVEL alQueryLevel,
LPCWSTR pszAppRegistryName,
BOOL *pfDefault) = 0;
virtual HRESULT STDMETHODCALLTYPE SetAppAsDefault(LPCWSTR pszAppRegistryName,
LPCWSTR pszSet,
ASSOCIATIONTYPE atSetType) = 0;
virtual HRESULT STDMETHODCALLTYPE SetAppAsDefaultAll(LPCWSTR pszAppRegistryName) = 0;
virtual HRESULT STDMETHODCALLTYPE ClearUserAssociations( void) = 0;
};
#endif
static const CLSID CLSID_ApplicationAssociationReg = {0x591209C7,0x767B,0x42B2,{0x9F,0xBA,0x44,0xEE,0x46,0x15,0xF2,0xC7}};
static const IID IID_IApplicationAssociationReg = {0x4e530b0a,0xe611,0x4c77,{0xa3,0xac,0x90,0x31,0xd0,0x22,0x28,0x1b}};
PRBool
nsWindowsShellService::IsDefaultBrowserVista(PRBool aStartupCheck, PRBool* aIsDefaultBrowser)
{
IApplicationAssociationRegistration* pAAR;
HRESULT hr = CoCreateInstance (CLSID_ApplicationAssociationReg,
NULL,
CLSCTX_INPROC,
IID_IApplicationAssociationReg,
(void**)&pAAR);
if (SUCCEEDED(hr))
{
hr = pAAR->QueryAppIsDefaultAll(AL_EFFECTIVE,
APP_REG_NAME,
aIsDefaultBrowser);
// If this is the first browser window, maintain internal state that we've
// checked this session (so that subsequent window opens don't show the
// default browser dialog).
if (aStartupCheck)
mCheckedThisSession = PR_TRUE;
pAAR->Release();
return PR_TRUE;
}
return PR_FALSE;
}
PRBool
nsWindowsShellService::SetDefaultBrowserVista()
{
IApplicationAssociationRegistration* pAAR;
HRESULT hr = CoCreateInstance (CLSID_ApplicationAssociationReg,
NULL,
CLSCTX_INPROC,
IID_IApplicationAssociationReg,
(void**)&pAAR);
if (SUCCEEDED(hr))
{
hr = pAAR->SetAppAsDefaultAll(APP_REG_NAME);
pAAR->Release();
return PR_TRUE;
}
return PR_FALSE;
}
PRBool
nsWindowsShellService::RestoreFileSettingsVista()
{
// With the new vista API, there is no need to restore file setting.
if (GetVersion() >= 6)
return PR_TRUE;
return PR_FALSE;
}
NS_IMETHODIMP NS_IMETHODIMP
nsWindowsShellService::IsDefaultBrowser(PRBool aStartupCheck, PRBool* aIsDefaultBrowser) nsWindowsShellService::IsDefaultBrowser(PRBool aStartupCheck, PRBool* aIsDefaultBrowser)
{ {
if (IsDefaultBrowserVista(aStartupCheck, aIsDefaultBrowser))
return NS_OK;
SETTING* settings; SETTING* settings;
SETTING* end = gSettings + sizeof(gSettings)/sizeof(SETTING); SETTING* end = gSettings + sizeof(gSettings)/sizeof(SETTING);
@@ -358,6 +476,9 @@ nsWindowsShellService::IsDefaultBrowser(PRBool aStartupCheck, PRBool* aIsDefault
NS_IMETHODIMP NS_IMETHODIMP
nsWindowsShellService::SetDefaultBrowser(PRBool aClaimAllTypes, PRBool aForAllUsers) nsWindowsShellService::SetDefaultBrowser(PRBool aClaimAllTypes, PRBool aForAllUsers)
{ {
if (SetDefaultBrowserVista())
return NS_OK;
// Locate the Backup key // Locate the Backup key
HKEY backupKey; HKEY backupKey;
nsresult rv = OpenKeyForWriting(MOZ_BACKUP_REGISTRY, &backupKey, aForAllUsers, PR_TRUE); nsresult rv = OpenKeyForWriting(MOZ_BACKUP_REGISTRY, &backupKey, aForAllUsers, PR_TRUE);
@@ -474,6 +595,9 @@ nsWindowsShellService::SetDefaultBrowser(PRBool aClaimAllTypes, PRBool aForAllUs
NS_IMETHODIMP NS_IMETHODIMP
nsWindowsShellService::RestoreFileSettings(PRBool aForAllUsers) nsWindowsShellService::RestoreFileSettings(PRBool aForAllUsers)
{ {
if (RestoreFileSettingsVista())
return NS_OK;
// Locate the Backup key // Locate the Backup key
HKEY backupKey; HKEY backupKey;
nsresult rv = OpenKeyForWriting(MOZ_BACKUP_REGISTRY, &backupKey, aForAllUsers, PR_FALSE); nsresult rv = OpenKeyForWriting(MOZ_BACKUP_REGISTRY, &backupKey, aForAllUsers, PR_FALSE);
@@ -493,9 +617,9 @@ nsWindowsShellService::RestoreFileSettings(PRBool aForAllUsers)
result = ::RegOpenKeyEx(NULL, origKeyName, 0, KEY_READ, &origKey); result = ::RegOpenKeyEx(NULL, origKeyName, 0, KEY_READ, &origKey);
if (REG_SUCCEEDED(result)) if (REG_SUCCEEDED(result))
{ {
result = ::RegSetValueEx(origKey, "", 0, REG_SZ, (LPBYTE)origValue, len); result = ::RegSetValueEx(origKey, "", 0, REG_SZ, (LPBYTE)origValue, len);
// Close the key we opened. // Close the key we opened.
::RegCloseKey(origKey); ::RegCloseKey(origKey);
} }
} }
} }
@@ -959,8 +1083,8 @@ nsWindowsShellService::GetMailAccountKey(HKEY* aResult)
result = ::RegOpenKeyEx(mailKey, subkeyName, 0, KEY_READ, &accountKey); result = ::RegOpenKeyEx(mailKey, subkeyName, 0, KEY_READ, &accountKey);
if (REG_SUCCEEDED(result)) { if (REG_SUCCEEDED(result)) {
*aResult = accountKey; *aResult = accountKey;
// Close the key we opened. // Close the key we opened.
::RegCloseKey(mailKey); ::RegCloseKey(mailKey);
return PR_TRUE; return PR_TRUE;

View File

@@ -43,6 +43,7 @@
#include "nsIWindowsShellService.h" #include "nsIWindowsShellService.h"
#include <windows.h> #include <windows.h>
#include <ole2.h>
class nsWindowsShellService : public nsIWindowsShellService class nsWindowsShellService : public nsIWindowsShellService
{ {
@@ -55,6 +56,10 @@ public:
NS_DECL_NSIWINDOWSSHELLSERVICE NS_DECL_NSIWINDOWSSHELLSERVICE
protected: protected:
PRBool IsDefaultBrowserVista(PRBool aStartupCheck, PRBool* aIsDefaultBrowser);
PRBool SetDefaultBrowserVista();
PRBool RestoreFileSettingsVista();
PRBool GetMailAccountKey(HKEY* aResult); PRBool GetMailAccountKey(HKEY* aResult);
void SetRegKey(const char* aKeyName, const char* aValueName, void SetRegKey(const char* aKeyName, const char* aValueName,
const char* aValue, PRBool aBackup, HKEY aBackupKey, const char* aValue, PRBool aBackup, HKEY aBackupKey,