Bug 716819 Move nsToolkit::VistaCreateItemFromParsingNameInit() and nsToolkit::createItemFromParsingName to WinUtils r=jimm

This commit is contained in:
Masayuki Nakano 2012-01-11 11:09:41 +09:00
Родитель d5d81c9c8b
Коммит 0a614dbc86
6 изменённых файлов: 74 добавлений и 43 удалений

Просмотреть файл

@ -55,7 +55,7 @@
#include "mozIAsyncFavicons.h"
#include "mozilla/Preferences.h"
#include "JumpListBuilder.h"
#include "nsToolkit.h"
#include "WinUtils.h"
namespace mozilla {
namespace widget {
@ -738,13 +738,15 @@ nsresult JumpListLink::GetShellItem(nsCOMPtr<nsIJumpListItem>& item, nsRefPtr<IS
NS_ENSURE_SUCCESS(rv, rv);
// Load vista+ SHCreateItemFromParsingName
if (!nsToolkit::VistaCreateItemFromParsingNameInit())
if (!WinUtils::VistaCreateItemFromParsingNameInit()) {
return NS_ERROR_UNEXPECTED;
}
// Create the IShellItem
if (FAILED(nsToolkit::createItemFromParsingName(NS_ConvertASCIItoUTF16(spec).get(),
NULL, IID_PPV_ARGS(&psi))))
if (FAILED(WinUtils::SHCreateItemFromParsingName(
NS_ConvertASCIItoUTF16(spec).get(), NULL, IID_PPV_ARGS(&psi)))) {
return NS_ERROR_INVALID_ARG;
}
// Set the title
nsAutoString linkTitle;

Просмотреть файл

@ -65,6 +65,9 @@
namespace mozilla {
namespace widget {
// SHCreateItemFromParsingName is only available on vista and up.
WinUtils::SHCreateItemFromParsingNamePtr WinUtils::sCreateItemFromParsingName = nsnull;
/* static */
WinUtils::WinVersion
WinUtils::GetWindowsVersion()
@ -363,5 +366,37 @@ WinUtils::InitMSG(UINT aMessage, WPARAM wParam, LPARAM lParam)
return msg;
}
/* static */
bool
WinUtils::VistaCreateItemFromParsingNameInit()
{
// Load and store Vista+ SHCreateItemFromParsingName
if (sCreateItemFromParsingName) {
return true;
}
static HMODULE sShellDll = nsnull;
if (sShellDll) {
return false;
}
static const PRUnichar kSehllLibraryName[] = L"shell32.dll";
sShellDll = ::LoadLibraryW(kSehllLibraryName);
if (!sShellDll) {
return false;
}
sCreateItemFromParsingName = (SHCreateItemFromParsingNamePtr)
GetProcAddress(sShellDll, "SHCreateItemFromParsingName");
return sCreateItemFromParsingName != nsnull;
}
/* static */
HRESULT
WinUtils::SHCreateItemFromParsingName(PCWSTR pszPath, IBindCtx *pbc,
REFIID riid, void **ppv)
{
NS_ENSURE_TRUE(sCreateItemFromParsingName, E_FAIL);
return sCreateItemFromParsingName(pszPath, pbc, riid, ppv);
}
} // namespace widget
} // namespace mozilla

Просмотреть файл

@ -51,6 +51,7 @@
#include "nscore.h"
#include <windows.h>
#include <shobjidl.h>
class nsWindow;
@ -198,6 +199,28 @@ public:
* mouse message handling.
*/
static PRUint16 GetMouseInputSource();
/**
* VistaCreateItemFromParsingNameInit() initializes the static pointer for
* SHCreateItemFromParsingName() API which is usable only on Vista and later.
* This returns TRUE if the API is available. Otherwise, FALSE.
*/
static bool VistaCreateItemFromParsingNameInit();
/**
* SHCreateItemFromParsingName() calls native SHCreateItemFromParsingName()
* API. Note that you must call VistaCreateItemFromParsingNameInit() before
* calling this. And the result must be TRUE. Otherwise, returns E_FAIL.
*/
static HRESULT SHCreateItemFromParsingName(PCWSTR pszPath, IBindCtx *pbc,
REFIID riid, void **ppv);
private:
typedef HRESULT (WINAPI * SHCreateItemFromParsingNamePtr)(PCWSTR pszPath,
IBindCtx *pbc,
REFIID riid,
void **ppv);
static SHCreateItemFromParsingNamePtr sCreateItemFromParsingName;
};
} // namespace widget

Просмотреть файл

@ -619,9 +619,10 @@ nsFilePicker::ShowFolderPicker(const nsString& aInitialDir)
// initial strings
dialog->SetTitle(mTitle.get());
if (!aInitialDir.IsEmpty() &&
nsToolkit::VistaCreateItemFromParsingNameInit()) {
WinUtils::VistaCreateItemFromParsingNameInit()) {
nsRefPtr<IShellItem> folder;
if (SUCCEEDED(nsToolkit::createItemFromParsingName(aInitialDir.get(), NULL,
if (SUCCEEDED(
WinUtils::SHCreateItemFromParsingName(aInitialDir.get(), NULL,
IID_IShellItem,
getter_AddRefs(folder)))) {
dialog->SetFolder(folder);
@ -944,9 +945,10 @@ nsFilePicker::ShowFilePicker(const nsString& aInitialDir)
// initial location
if (!aInitialDir.IsEmpty() &&
nsToolkit::VistaCreateItemFromParsingNameInit()) {
WinUtils::VistaCreateItemFromParsingNameInit()) {
nsRefPtr<IShellItem> folder;
if (SUCCEEDED(nsToolkit::createItemFromParsingName(aInitialDir.get(), NULL,
if (SUCCEEDED(
WinUtils::SHCreateItemFromParsingName(aInitialDir.get(), NULL,
IID_IShellItem,
getter_AddRefs(folder)))) {
dialog->SetFolder(folder);

Просмотреть файл

@ -57,11 +57,6 @@ 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)
{
@ -125,24 +120,6 @@ 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

Просмотреть файл

@ -44,8 +44,6 @@
#include "nsITimer.h"
#include "nsCOMPtr.h"
#include <windows.h>
#include <shobjidl.h>
#include <imm.h>
// Avoid including windowsx.h to prevent macro pollution
#ifndef GET_X_LPARAM
@ -113,18 +111,12 @@ 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<nsITimer> mD3D9Timer;
MouseTrailer mMouseTrailer;
static const PRUnichar kSehllLibraryName[];
static HMODULE sShellDll;
};
#endif // TOOLKIT_H