Bug 1331171 - Part 1: Remove StartupSpecialSystemDirectory() workaround for Windows XP. r?jimm draft
authorChris Peterson <cpeterson@mozilla.com>
Sat, 14 Jan 2017 01:12:02 -0800
changeset 461050 7f7e8453229421c36d2b72b6762a0fb35229a794
parent 461036 5ce3882eec21be3a70e4afc050959ca2f76bfa76
child 461051 5189fece4ca6d19881ff4080b356f0fc5b35dab8
push id41550
push usercpeterson@mozilla.com
push dateSun, 15 Jan 2017 02:26:06 +0000
reviewersjimm
bugs1331171
milestone53.0a1
Bug 1331171 - Part 1: Remove StartupSpecialSystemDirectory() workaround for Windows XP. r?jimm SHGetKnownFolderPath() is available on Windows Vista+ so we no longer need to GetProcAddress("SHGetKnownFolderPath"). We can set _WIN32_WINNT 0x0600 to expose the SHGetKnownFolderPath function declaration in shlobj.h and call it directly. Also remove a redundant #include <shlobj.h>. MozReview-Commit-ID: AoAlrfvQ5AB
xpcom/build/XPCOMInit.cpp
xpcom/io/SpecialSystemDirectory.cpp
xpcom/io/SpecialSystemDirectory.h
--- a/xpcom/build/XPCOMInit.cpp
+++ b/xpcom/build/XPCOMInit.cpp
@@ -578,18 +578,16 @@ NS_InitXPCOM2(nsIServiceManager** aResul
 #endif
 
 #if defined(XP_UNIX)
   NS_StartupNativeCharsetUtils();
 #endif
 
   NS_StartupLocalFile();
 
-  StartupSpecialSystemDirectory();
-
   nsDirectoryService::RealInit();
 
   bool value;
 
   if (aBinDirectory) {
     rv = aBinDirectory->IsDirectory(&value);
 
     if (NS_SUCCEEDED(rv) && value) {
--- a/xpcom/io/SpecialSystemDirectory.cpp
+++ b/xpcom/io/SpecialSystemDirectory.cpp
@@ -6,18 +6,22 @@
 
 #include "SpecialSystemDirectory.h"
 #include "nsString.h"
 #include "nsDependentString.h"
 #include "nsAutoPtr.h"
 
 #if defined(XP_WIN)
 
+#ifdef _WIN32_WINNT
+#undef _WIN32_WINNT
+#endif
+#define _WIN32_WINNT 0x0600
+
 #include <windows.h>
-#include <shlobj.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 #include <direct.h>
 #include <shlobj.h>
 #include <knownfolders.h>
 #include <guiddef.h>
 #include "mozilla/WindowsVersion.h"
@@ -43,50 +47,27 @@ using mozilla::IsWin7OrLater;
 #define MAXPATHLEN _MAX_PATH
 #elif defined(CCHMAXPATH)
 #define MAXPATHLEN CCHMAXPATH
 #else
 #define MAXPATHLEN 1024
 #endif
 #endif
 
-#ifdef XP_WIN
-typedef HRESULT (WINAPI* nsGetKnownFolderPath)(GUID& rfid,
-                                               DWORD dwFlags,
-                                               HANDLE hToken,
-                                               PWSTR* ppszPath);
-
-static nsGetKnownFolderPath gGetKnownFolderPath = nullptr;
-#endif
-
-void
-StartupSpecialSystemDirectory()
-{
-#if defined (XP_WIN)
-  // SHGetKnownFolderPath is only available on Windows Vista
-  // so that we need to use GetProcAddress to get the pointer.
-  HMODULE hShell32DLLInst = GetModuleHandleW(L"shell32.dll");
-  if (hShell32DLLInst) {
-    gGetKnownFolderPath = (nsGetKnownFolderPath)
-      GetProcAddress(hShell32DLLInst, "SHGetKnownFolderPath");
-  }
-#endif
-}
-
 #if defined (XP_WIN)
 
 static nsresult
 GetKnownFolder(GUID* aGuid, nsIFile** aFile)
 {
-  if (!aGuid || !gGetKnownFolderPath) {
+  if (!aGuid) {
     return NS_ERROR_FAILURE;
   }
 
   PWSTR path = nullptr;
-  gGetKnownFolderPath(*aGuid, 0, nullptr, &path);
+  SHGetKnownFolderPath(*aGuid, 0, nullptr, &path);
 
   if (!path) {
     return NS_ERROR_FAILURE;
   }
 
   nsresult rv = NS_NewLocalFile(nsDependentString(path),
                                 true,
                                 aFile);
--- a/xpcom/io/SpecialSystemDirectory.h
+++ b/xpcom/io/SpecialSystemDirectory.h
@@ -11,19 +11,16 @@
 #include "nsIFile.h"
 
 #ifdef MOZ_WIDGET_COCOA
 #include <Carbon/Carbon.h>
 #include "nsILocalFileMac.h"
 #include "prenv.h"
 #endif
 
-extern void StartupSpecialSystemDirectory();
-
-
 enum SystemDirectories {
   OS_DriveDirectory         =   1,
   OS_TemporaryDirectory     =   2,
   OS_CurrentProcessDirectory =  3,
   OS_CurrentWorkingDirectory =  4,
   XPCOM_CurrentProcessComponentDirectory = 5,
   XPCOM_CurrentProcessComponentRegistry =  6,