Bug 428970: Implement --disable-vista-sdk-requirements configure option and update source to use it, patch by Jim Mathies <jmathies@mozilla.com>, r=rob_strong, r=bsmedberg, a=beltzner
authorgavin@gavinsharp.com
Fri, 25 Apr 2008 09:44:16 -0700
changeset 14683 257494a97718462ac4577a309cb66b674499a2fb
parent 14682 6a0e1ab068b2a1632dfdda8f4342522b24977c03
child 14684 580055592e7395a5476c0f24b531dcd9c5c667e5
push idunknown
push userunknown
push dateunknown
reviewersrob_strong, bsmedberg, beltzner
bugs428970
milestone1.9pre
Bug 428970: Implement --disable-vista-sdk-requirements configure option and update source to use it, patch by Jim Mathies <jmathies@mozilla.com>, r=rob_strong, r=bsmedberg, a=beltzner
browser/components/shell/src/nsWindowsShellService.cpp
browser/components/shell/src/nsWindowsShellService.h
config/autoconf.mk.in
configure.in
uriloader/exthandler/Makefile.in
uriloader/exthandler/win/nsOSHelperAppService.cpp
uriloader/exthandler/win/nsOSHelperAppService.h
--- a/browser/components/shell/src/nsWindowsShellService.cpp
+++ b/browser/components/shell/src/nsWindowsShellService.cpp
@@ -61,17 +61,23 @@
 #include "nsDirectoryServiceUtils.h"
 #include "nsAppDirectoryServiceDefs.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsIWindowsRegKey.h"
 #include "nsUnicharUtils.h"
 
 #include "windows.h"
 #include "shellapi.h"
-#include "shlobj.h"
+
+#ifdef _WIN32_WINNT
+#undef _WIN32_WINNT
+#endif
+#define _WIN32_WINNT 0x0600
+#define INITGUID
+#include <shlobj.h>
 
 #include <mbstring.h>
 
 #ifndef MAX_BUF
 #define MAX_BUF 4096
 #endif
 
 #define REG_SUCCEEDED(val) \
@@ -210,87 +216,43 @@ static SETTING gSettings[] = {
 
   // Protocol Handlers
   { MAKE_KEY_NAME1("HTTP", DI),    "", VAL_FILE_ICON, APP_PATH_SUBSTITUTION },
   { MAKE_KEY_NAME1("HTTP", SOP),   "", VAL_OPEN, APP_PATH_SUBSTITUTION },
   { MAKE_KEY_NAME1("HTTPS", DI),   "", VAL_FILE_ICON, APP_PATH_SUBSTITUTION },
   { MAKE_KEY_NAME1("HTTPS", SOP),  "", VAL_OPEN, APP_PATH_SUBSTITUTION }
 };
 
-
-// Support for versions of shlobj.h that don't include the Vista API's
-#if !defined(IApplicationAssociationRegistration)
-
-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)
 {
+#if !defined(MOZ_DISABLE_VISTA_SDK_REQUIREMENTS)
   IApplicationAssociationRegistration* pAAR;
   
-  HRESULT hr = CoCreateInstance(CLSID_ApplicationAssociationReg,
+  HRESULT hr = CoCreateInstance(CLSID_ApplicationAssociationRegistration,
                                 NULL,
                                 CLSCTX_INPROC,
-                                IID_IApplicationAssociationReg,
+                                IID_IApplicationAssociationRegistration,
                                 (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;
   }
-  
+#endif  
   return PR_FALSE;
 }
 
 NS_IMETHODIMP
 nsWindowsShellService::IsDefaultBrowser(PRBool aStartupCheck,
                                         PRBool* aIsDefaultBrowser)
 {
   // If this is the first browser window, maintain internal state that we've
--- a/browser/components/shell/src/nsWindowsShellService.h
+++ b/browser/components/shell/src/nsWindowsShellService.h
@@ -53,17 +53,16 @@ public:
   virtual ~nsWindowsShellService() {};
 
   NS_DECL_ISUPPORTS
   NS_DECL_NSISHELLSERVICE
   NS_DECL_NSIWINDOWSSHELLSERVICE
 
 protected:
   PRBool    IsDefaultBrowserVista(PRBool aStartupCheck, PRBool* aIsDefaultBrowser);
-  PRBool    SetDefaultBrowserVista();
 
   PRBool    GetMailAccountKey(HKEY* aResult);
   void      SetRegKey(const nsString& aKeyName,
                       const nsString& aValueName,
                       const nsString& aValue, PRBool aHKLMOnly);
 
   DWORD     DeleteRegKey(HKEY baseKey, const nsString& keyName);
   DWORD     DeleteRegKeyDefaultValue(HKEY baseKey,
--- a/config/autoconf.mk.in
+++ b/config/autoconf.mk.in
@@ -135,16 +135,17 @@ XPCOM_USE_LEA = @XPCOM_USE_LEA@
 JS_ULTRASPARC_OPTS = @JS_ULTRASPARC_OPTS@
 JS_STATIC_BUILD = @JS_STATIC_BUILD@
 MOZ_ENABLE_POSTSCRIPT = @MOZ_ENABLE_POSTSCRIPT@
 MOZ_INSTALLER	= @MOZ_INSTALLER@
 MOZ_UPDATER	= @MOZ_UPDATER@
 MOZ_UPDATE_PACKAGING	= @MOZ_UPDATE_PACKAGING@
 MOZ_NO_ACTIVEX_SUPPORT = @MOZ_NO_ACTIVEX_SUPPORT@
 MOZ_ACTIVEX_SCRIPTING_SUPPORT = @MOZ_ACTIVEX_SCRIPTING_SUPPORT@
+MOZ_DISABLE_VISTA_SDK_REQUIREMENTS = @MOZ_DISABLE_VISTA_SDK_REQUIREMENTS@
 MOZ_DISABLE_PARENTAL_CONTROLS = @MOZ_DISABLE_PARENTAL_CONTROLS@
 XPC_IDISPATCH_SUPPORT = @XPC_IDISPATCH_SUPPORT@
 MOZ_SPELLCHECK = @MOZ_SPELLCHECK@
 MOZ_XPFE_COMPONENTS = @MOZ_XPFE_COMPONENTS@
 MOZ_IPCD = @MOZ_IPCD@
 MOZ_PROFILESHARING = @MOZ_PROFILESHARING@
 MOZ_PROFILELOCKING = @MOZ_PROFILELOCKING@
 MOZ_FEEDS = @MOZ_FEEDS@
--- a/configure.in
+++ b/configure.in
@@ -5834,26 +5834,44 @@ dnl parental controls (for Windows Vista
 dnl ========================================================
 MOZ_ARG_DISABLE_BOOL(parental-controls,
 [  --disable-parental-controls
                            Do not build parental controls],
    MOZ_DISABLE_PARENTAL_CONTROLS=1,
    MOZ_DISABLE_PARENTAL_CONTROLS=)
 if test -n "$MOZ_DISABLE_PARENTAL_CONTROLS"; then
     AC_DEFINE(MOZ_DISABLE_PARENTAL_CONTROLS)
+fi
+
+dnl ========================================================
+dnl Vista SDK specific api
+dnl ========================================================
+MOZ_ARG_DISABLE_BOOL(vista-sdk-requirements,
+[  --disable-vista-sdk-requirements
+                           Do not build Vista SDK specific code],
+   MOZ_DISABLE_VISTA_SDK_REQUIREMENTS=1,
+   MOZ_DISABLE_VISTA_SDK_REQUIREMENTS=)
+if test -n "$MOZ_DISABLE_VISTA_SDK_REQUIREMENTS"; then
+    AC_MSG_WARN([Resulting builds will not be compatible with Windows Vista. (bug 428970)])
+    AC_DEFINE(MOZ_DISABLE_VISTA_SDK_REQUIREMENTS)
+    if test -z "$MOZ_DISABLE_PARENTAL_CONTROLS"; then
+        AC_DEFINE(MOZ_DISABLE_PARENTAL_CONTROLS)
+    fi
+    MOZ_DISABLE_PARENTAL_CONTROLS=1
 else
 case "$target" in
 *-mingw*|*-cygwin*|*-msvc*|*-mks*)
     if test "$ac_cv_header_wpcapi_h" = "no"; then
-        AC_MSG_ERROR([System header wpcapi.h is not available. See http://developer.mozilla.org/en/docs/wpcapi.h for details on fixing this problem.])
+        AC_MSG_ERROR([System header wpcapi.h is not available. See updated http://developer.mozilla.org/en/docs/wpcapi.h for details on fixing this problem.])
     fi
     ;;
 esac
 fi
 AC_SUBST(MOZ_DISABLE_PARENTAL_CONTROLS)
+AC_SUBST(MOZ_DISABLE_VISTA_SDK_REQUIREMENTS)
 
 dnl ========================================================
 dnl =
 dnl = Module specific options
 dnl =
 dnl ========================================================
 MOZ_ARG_HEADER(Individual module options)
 
--- a/uriloader/exthandler/Makefile.in
+++ b/uriloader/exthandler/Makefile.in
@@ -126,20 +126,16 @@ ifeq ($(MOZ_WIDGET_TOOLKIT),os2)
 OSHELPER  += nsMIMEInfoOS2.cpp
 REQUIRES  += widget
 endif
 
 EXPORTS = \
 		$(OSDIR)/nsOSHelperAppService.h \
 			$(NULL)
 
-ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
-EXPORTS += $(OSDIR)/IApplicationAssociationRegistration.h
-endif
-
 XPIDLSRCS = \
 	nsCExternalHandlerService.idl	\
 	nsIExternalProtocolService.idl \
 	nsIExternalHelperAppService.idl	\
 	nsIHelperAppLauncherDialog.idl \
 	nsIContentDispatchChooser.idl \
 	nsIHandlerService.idl	\
 	$(NULL)
--- a/uriloader/exthandler/win/nsOSHelperAppService.cpp
+++ b/uriloader/exthandler/win/nsOSHelperAppService.cpp
@@ -55,41 +55,43 @@
 #include "nsNativeCharsetUtils.h"
 #include "nsIWindowsRegKey.h"
 
 // shellapi.h is needed to build with WIN32_LEAN_AND_MEAN
 #include <shellapi.h>
 
 #define LOG(args) PR_LOG(mLog, PR_LOG_DEBUG, args)
 
-// Vista application association interface
-static const CLSID CLSID_AppAssoc = {0x591209C7,0x767B,0x42B2,{0x9F,0xBA,0x44,0xEE,0x46,0x15,0xF2,0xC7}};
-static const IID   IID_IAppAssoc  = {0x4e530b0a,0xe611,0x4c77,{0xa3,0xac,0x90,0x31,0xd0,0x22,0x28,0x1b}};
-
 // helper methods: forward declarations...
 static nsresult GetExtensionFrom4xRegistryInfo(const nsACString& aMimeType, 
                                                nsString& aFileExtension);
 static nsresult GetExtensionFromWindowsMimeDatabase(const nsACString& aMimeType,
                                                     nsString& aFileExtension);
 
 nsOSHelperAppService::nsOSHelperAppService() : 
-  nsExternalHelperAppService(),
-  mAppAssoc(nsnull)
+  nsExternalHelperAppService()
+#if !defined(MOZ_DISABLE_VISTA_SDK_REQUIREMENTS)
+  , mAppAssoc(nsnull)
+#endif
 {
+#if !defined(MOZ_DISABLE_VISTA_SDK_REQUIREMENTS)
   CoInitialize(NULL);
-  CoCreateInstance(CLSID_AppAssoc, NULL, CLSCTX_INPROC,
-                   IID_IAppAssoc, (void**)&mAppAssoc);
+  CoCreateInstance(CLSID_ApplicationAssociationRegistration, NULL, CLSCTX_INPROC,
+                   IID_IApplicationAssociationRegistration, (void**)&mAppAssoc);
+#endif
 }
 
 nsOSHelperAppService::~nsOSHelperAppService()
 {
+#if !defined(MOZ_DISABLE_VISTA_SDK_REQUIREMENTS)
   if (mAppAssoc)
     mAppAssoc->Release();
   mAppAssoc = nsnull;
   CoUninitialize();
+#endif
 }
 
 // The windows registry provides a mime database key which lists a set of mime types and corresponding "Extension" values. 
 // we can use this to look up our mime type to see if there is a preferred extension for the mime type.
 static nsresult GetExtensionFromWindowsMimeDatabase(const nsACString& aMimeType,
                                                     nsString& aFileExtension)
 {
   nsAutoString mimeDatabaseKey;
@@ -152,30 +154,32 @@ static nsresult GetExtensionFrom4xRegist
 }
 
 nsresult nsOSHelperAppService::OSProtocolHandlerExists(const char * aProtocolScheme, PRBool * aHandlerExists)
 {
   // look up the protocol scheme in the windows registry....if we find a match then we have a handler for it...
   *aHandlerExists = PR_FALSE;
   if (aProtocolScheme && *aProtocolScheme)
   {
+#if !defined(MOZ_DISABLE_VISTA_SDK_REQUIREMENTS)
     // Vista: use new application association interface
     if (mAppAssoc) {
       PRUnichar * pResult = nsnull;
       NS_ConvertASCIItoUTF16 scheme(aProtocolScheme);
       // We are responsible for freeing returned strings.
       HRESULT hr = mAppAssoc->QueryCurrentDefault(scheme.get(),
                                                   AT_URLPROTOCOL, AL_EFFECTIVE,
                                                   &pResult);
       if (SUCCEEDED(hr)) {
         CoTaskMemFree(pResult);
         *aHandlerExists = PR_TRUE;
       }
       return NS_OK;
     }
+#endif
 
     HKEY hKey;
     LONG err = ::RegOpenKeyEx(HKEY_CLASSES_ROOT, aProtocolScheme, 0,
                              KEY_QUERY_VALUE, &hKey);
     if (err == ERROR_SUCCESS)
     {
       err = ::RegQueryValueEx(hKey, "URL Protocol", NULL, NULL, NULL, NULL);
       *aHandlerExists = (err == ERROR_SUCCESS);
@@ -191,32 +195,34 @@ NS_IMETHODIMP nsOSHelperAppService::GetA
 {
   nsCOMPtr<nsIWindowsRegKey> regKey = 
     do_CreateInstance("@mozilla.org/windows-registry-key;1");
   if (!regKey) 
     return NS_ERROR_NOT_AVAILABLE;
 
   NS_ConvertASCIItoUTF16 buf(aScheme);
 
+#if !defined(MOZ_DISABLE_VISTA_SDK_REQUIREMENTS)
   // Vista: use new application association interface
   if (mAppAssoc) {
     PRUnichar * pResult = nsnull;
     // We are responsible for freeing returned strings.
     HRESULT hr = mAppAssoc->QueryCurrentDefault(buf.get(),
                                                 AT_URLPROTOCOL, AL_EFFECTIVE,
                                                 &pResult);
     if (SUCCEEDED(hr)) {
       nsCOMPtr<nsIFile> app;
       nsAutoString appInfo(pResult);
       CoTaskMemFree(pResult);
       if (NS_SUCCEEDED(GetDefaultAppInfo(appInfo, _retval, getter_AddRefs(app))))
         return NS_OK;
     }
     return NS_ERROR_NOT_AVAILABLE;
   }
+#endif
 
   nsCOMPtr<nsIFile> app;
   GetDefaultAppInfo(buf, _retval, getter_AddRefs(app));
 
   if (!_retval.Equals(buf))
     return NS_OK;
 
   // Fall back to full path
@@ -541,16 +547,17 @@ already_AddRefed<nsMIMEInfoWin> nsOSHelp
 
   // don't append the '.'
   mimeInfo->AppendExtension(NS_ConvertUTF16toUTF8(Substring(fileExtToUse, 1)));
   mimeInfo->SetPreferredAction(nsIMIMEInfo::useSystemDefault);
 
   nsAutoString appInfo;
   PRBool found;
 
+#if !defined(MOZ_DISABLE_VISTA_SDK_REQUIREMENTS)
   // Retrieve the default application for this extension
   if (mAppAssoc) {
     // Vista: use the new application association COM interfaces
     // for resolving helpers.
     nsString assocType(fileExtToUse);
     PRUnichar * pResult = nsnull;
     HRESULT hr = mAppAssoc->QueryCurrentDefault(assocType.get(),
                                                 AT_FILEEXTENSION, AL_EFFECTIVE,
@@ -559,17 +566,19 @@ already_AddRefed<nsMIMEInfoWin> nsOSHelp
       found = PR_TRUE;
       appInfo.Assign(pResult);
       CoTaskMemFree(pResult);
     } 
     else {
       found = PR_FALSE;
     }
   } 
-  else {
+  else
+#endif
+  {
     found = NS_SUCCEEDED(regKey->ReadStringValue(EmptyString(), 
                                                  appInfo));
   }
 
   // Bug 358297 - ignore the default handler, force the user to choose app
   if (appInfo.EqualsLiteral("XPSViewer.Document"))
     found = PR_FALSE;
 
--- a/uriloader/exthandler/win/nsOSHelperAppService.h
+++ b/uriloader/exthandler/win/nsOSHelperAppService.h
@@ -43,19 +43,23 @@
 // platform. It contains platform specific code for finding helper applications for a given mime type
 // in addition to launching those applications.
 
 #include "nsExternalHelperAppService.h"
 #include "nsCExternalHandlerService.h"
 #include "nsCOMPtr.h"
 #include <windows.h>
 
-// Vista SDK application registration definitions for non-Vista SDK builds
-#include "IApplicationAssociationRegistration.h"
- 
+#ifdef _WIN32_WINNT
+#undef _WIN32_WINNT
+#endif
+#define _WIN32_WINNT 0x0600
+#define INITGUID
+#include <shlobj.h>
+
 class nsMIMEInfoWin;
 
 class nsOSHelperAppService : public nsExternalHelperAppService
 {
 public:
   nsOSHelperAppService();
   virtual ~nsOSHelperAppService();
 
@@ -84,12 +88,14 @@ protected:
   already_AddRefed<nsMIMEInfoWin> GetByExtension(const nsAFlatString& aFileExt, const char *aTypeHint = nsnull);
   nsresult FindOSMimeInfoForType(const char * aMimeContentType, nsIURI * aURI, char ** aFileExtension, nsIMIMEInfo ** aMIMEInfo);
 
   static nsresult GetMIMEInfoFromRegistry(const nsAFlatString& fileType, nsIMIMEInfo *pInfo);
   /// Looks up the type for the extension aExt and compares it to aType
   static PRBool typeFromExtEquals(const PRUnichar* aExt, const char *aType);
 
 private:
+#if !defined(MOZ_DISABLE_VISTA_SDK_REQUIREMENTS)
   IApplicationAssociationRegistration* mAppAssoc;
+#endif
 };
 
 #endif // nsOSHelperAppService_h__