diff --git a/widget/src/windows/JumpListItem.cpp b/widget/src/windows/JumpListItem.cpp index 318fb87b77c..3dea09fc831 100644 --- a/widget/src/windows/JumpListItem.cpp +++ b/widget/src/windows/JumpListItem.cpp @@ -55,16 +55,12 @@ #include "mozIAsyncFavicons.h" #include "mozilla/Preferences.h" #include "JumpListBuilder.h" +#include "nsToolkit.h" namespace mozilla { namespace widget { -// SHCreateItemFromParsingName is only available on vista and up. We only load this if we -// need to call it on win7+. -JumpListLink::SHCreateItemFromParsingNamePtr JumpListLink::createItemFromParsingName = nsnull; -const PRUnichar JumpListLink::kSehllLibraryName[] = L"shell32.dll"; const char JumpListItem::kJumpListCacheDir[] = "jumpListCache"; -HMODULE JumpListLink::sShellDll = nsnull; // ISUPPORTS Impl's NS_IMPL_ISUPPORTS1(JumpListItem, @@ -742,18 +738,11 @@ nsresult JumpListLink::GetShellItem(nsCOMPtr& item, nsRefPtr& aLink); protected: - typedef HRESULT (WINAPI * SHCreateItemFromParsingNamePtr)(PCWSTR pszPath, IBindCtx *pbc, REFIID riid, void **ppv); - nsString mUriTitle; nsCOMPtr mURI; nsCOMPtr mCryptoHash; - static const PRUnichar kSehllLibraryName[]; - static HMODULE sShellDll; - static SHCreateItemFromParsingNamePtr createItemFromParsingName; }; class JumpListShortcut : public JumpListItem, public nsIJumpListShortcut diff --git a/widget/src/windows/nsFilePicker.cpp b/widget/src/windows/nsFilePicker.cpp index 10da8f34389..d191a380a09 100644 --- a/widget/src/windows/nsFilePicker.cpp +++ b/widget/src/windows/nsFilePicker.cpp @@ -68,6 +68,7 @@ static const DWORD kDialogTimerID = 9999; static const unsigned long kDialogTimerTimeout = 300; #define MAX_EXTENSION_LENGTH 10 +#define FILE_BUFFER_SIZE 4096 /////////////////////////////////////////////////////////////////////////////// // Helper classes @@ -612,11 +613,12 @@ nsFilePicker::ShowFolderPicker(const nsString& aInitialDir) // initial strings dialog->SetTitle(mTitle.get()); - if (!aInitialDir.IsEmpty()) { + if (!aInitialDir.IsEmpty() && + nsToolkit::VistaCreateItemFromParsingNameInit()) { nsRefPtr folder; - if (SUCCEEDED(SHCreateItemFromParsingName(aInitialDir.get(), NULL, - IID_IShellItem, - getter_AddRefs(folder)))) { + if (SUCCEEDED(nsToolkit::createItemFromParsingName(aInitialDir.get(), NULL, + IID_IShellItem, + getter_AddRefs(folder)))) { dialog->SetFolder(folder); } } @@ -938,11 +940,12 @@ nsFilePicker::ShowFilePicker(const nsString& aInitialDir) } // initial location - if (!aInitialDir.IsEmpty()) { + if (!aInitialDir.IsEmpty() && + nsToolkit::VistaCreateItemFromParsingNameInit()) { nsRefPtr folder; - if (SUCCEEDED(SHCreateItemFromParsingName(aInitialDir.get(), NULL, - IID_IShellItem, - getter_AddRefs(folder)))) { + if (SUCCEEDED(nsToolkit::createItemFromParsingName(aInitialDir.get(), NULL, + IID_IShellItem, + getter_AddRefs(folder)))) { dialog->SetFolder(folder); } } diff --git a/widget/src/windows/nsToolkit.cpp b/widget/src/windows/nsToolkit.cpp index e2ea6f33c91..3bbc656ac13 100644 --- a/widget/src/windows/nsToolkit.cpp +++ b/widget/src/windows/nsToolkit.cpp @@ -54,11 +54,14 @@ #include nsToolkit* nsToolkit::gToolkit = nsnull; - HINSTANCE nsToolkit::mDllInstance = 0; - static const unsigned long kD3DUsageDelay = 5000; +// SHCreateItemFromParsingName is only available on vista and up. +nsToolkit::SHCreateItemFromParsingNamePtr nsToolkit::createItemFromParsingName = nsnull; +const PRUnichar nsToolkit::kSehllLibraryName[] = L"shell32.dll"; +HMODULE nsToolkit::sShellDll = nsnull; + static void StartAllowingD3D9(nsITimer *aTimer, void *aClosure) { @@ -122,6 +125,24 @@ nsToolkit::StartAllowingD3D9() nsWindow::StartAllowingD3D9(false); } +// Load and store Vista+ SHCreateItemFromParsingName +bool +nsToolkit::VistaCreateItemFromParsingNameInit() +{ + if (createItemFromParsingName) + return true; + if (sShellDll) + return false; + sShellDll = LoadLibraryW(kSehllLibraryName); + if (!sShellDll) + return false; + createItemFromParsingName = (SHCreateItemFromParsingNamePtr) + GetProcAddress(sShellDll, "SHCreateItemFromParsingName"); + if (createItemFromParsingName == nsnull) + return false; + return true; +} + //------------------------------------------------------------------------- // // Return the nsToolkit for the current thread. If a toolkit does not diff --git a/widget/src/windows/nsToolkit.h b/widget/src/windows/nsToolkit.h index 86167f44dad..663c3ae285d 100644 --- a/widget/src/windows/nsToolkit.h +++ b/widget/src/windows/nsToolkit.h @@ -43,7 +43,8 @@ #include "nsITimer.h" #include "nsCOMPtr.h" - +#include +#include #include // Avoid including windowsx.h to prevent macro pollution @@ -54,15 +55,6 @@ #define GET_Y_LPARAM(pt) (short(HIWORD(pt))) #endif -// we used to use MAX_PATH -// which works great for one file -// but for multiple files, the format is -// dirpath\0\file1\0file2\0...filen\0\0 -// and that can quickly be more than MAX_PATH (260) -// see bug #172001 for more details -#define FILE_BUFFER_SIZE 4096 - - /** * Makes sure exit/enter mouse messages are always dispatched. * In the case where the mouse has exited the outer most window the @@ -121,12 +113,18 @@ public: static void Startup(HMODULE hModule); static void Shutdown(); static void StartAllowingD3D9(); + static bool VistaCreateItemFromParsingNameInit(); + + typedef HRESULT (WINAPI * SHCreateItemFromParsingNamePtr)(PCWSTR pszPath, IBindCtx *pbc, REFIID riid, void **ppv); + static SHCreateItemFromParsingNamePtr createItemFromParsingName; protected: static nsToolkit* gToolkit; nsCOMPtr mD3D9Timer; MouseTrailer mMouseTrailer; + static const PRUnichar kSehllLibraryName[]; + static HMODULE sShellDll; }; #endif // TOOLKIT_H