2012-01-04 02:21:44 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2012-01-04 02:21:44 -08:00
|
|
|
|
|
|
|
#ifndef mozilla_widget_WinUtils_h__
|
|
|
|
#define mozilla_widget_WinUtils_h__
|
|
|
|
|
|
|
|
#include "nscore.h"
|
|
|
|
#include <windows.h>
|
2012-01-10 18:09:41 -08:00
|
|
|
#include <shobjidl.h>
|
2012-02-16 16:36:04 -08:00
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsString.h"
|
2012-11-02 04:54:44 -07:00
|
|
|
#include "nsRegion.h"
|
|
|
|
#include "nsRect.h"
|
2012-01-04 02:21:44 -08:00
|
|
|
|
2012-07-21 13:07:26 -07:00
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "nsICryptoHash.h"
|
2012-11-09 01:55:56 -08:00
|
|
|
#ifdef MOZ_PLACES
|
|
|
|
#include "nsIFaviconService.h"
|
|
|
|
#endif
|
2012-07-21 13:07:26 -07:00
|
|
|
#include "nsIDownloader.h"
|
2012-11-09 01:55:56 -08:00
|
|
|
#include "nsIURI.h"
|
2012-07-21 13:07:26 -07:00
|
|
|
|
2012-10-04 01:33:24 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2012-07-21 13:07:26 -07:00
|
|
|
|
2012-01-04 02:21:44 -08:00
|
|
|
class nsWindow;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace widget {
|
|
|
|
|
2012-10-04 01:33:24 -07:00
|
|
|
class myDownloadObserver MOZ_FINAL : public nsIDownloadObserver
|
2012-07-21 13:07:26 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIDOWNLOADOBSERVER
|
|
|
|
};
|
|
|
|
|
2012-01-04 02:21:44 -08:00
|
|
|
class WinUtils {
|
|
|
|
public:
|
|
|
|
enum WinVersion {
|
|
|
|
WINXP_VERSION = 0x501,
|
|
|
|
WIN2K3_VERSION = 0x502,
|
|
|
|
VISTA_VERSION = 0x600,
|
|
|
|
// WIN2K8_VERSION = VISTA_VERSION,
|
|
|
|
WIN7_VERSION = 0x601
|
|
|
|
// WIN2K8R2_VERSION = WIN7_VERSION
|
|
|
|
// WIN8_VERSION = 0x602
|
|
|
|
};
|
|
|
|
static WinVersion GetWindowsVersion();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the value of a string-typed registry value.
|
|
|
|
*
|
|
|
|
* @param aRoot The registry root to search in.
|
|
|
|
* @param aKeyName The name of the registry key to open.
|
|
|
|
* @param aValueName The name of the registry value in the specified key whose
|
|
|
|
* value is to be retrieved. Can be null, to retrieve the key's unnamed/
|
|
|
|
* default value.
|
|
|
|
* @param aBuffer The buffer into which to store the string value. Can be
|
|
|
|
* null, in which case the return value indicates just whether the value
|
|
|
|
* exists.
|
|
|
|
* @param aBufferLength The size of aBuffer, in bytes.
|
|
|
|
* @return Whether the value exists and is a string.
|
|
|
|
*/
|
|
|
|
static bool GetRegistryKey(HKEY aRoot,
|
|
|
|
const PRUnichar* aKeyName,
|
|
|
|
const PRUnichar* aValueName,
|
|
|
|
PRUnichar* aBuffer,
|
|
|
|
DWORD aBufferLength);
|
|
|
|
|
2012-03-05 19:20:28 -08:00
|
|
|
/**
|
|
|
|
* Checks whether the registry key exists in either 32bit or 64bit branch on
|
|
|
|
* the environment.
|
|
|
|
*
|
|
|
|
* @param aRoot The registry root of aName.
|
|
|
|
* @param aKeyName The name of the registry key to check.
|
|
|
|
* @return TRUE if it exists and is readable. Otherwise, FALSE.
|
|
|
|
*/
|
|
|
|
static bool HasRegistryKey(HKEY aRoot,
|
|
|
|
const PRUnichar* aKeyName);
|
|
|
|
|
2012-01-04 02:21:44 -08:00
|
|
|
/**
|
|
|
|
* GetTopLevelHWND() returns a window handle of the top level window which
|
|
|
|
* aWnd belongs to. Note that the result may not be our window, i.e., it
|
|
|
|
* may not be managed by nsWindow.
|
|
|
|
*
|
|
|
|
* See follwing table for the detail of the result window type.
|
|
|
|
*
|
|
|
|
* +-------------------------+-----------------------------------------------+
|
|
|
|
* | | aStopIfNotPopup |
|
|
|
|
* +-------------------------+-----------------------+-----------------------+
|
|
|
|
* | | TRUE | FALSE |
|
|
|
|
+ +-----------------+-------+-----------------------+-----------------------+
|
|
|
|
* | | | * an independent top level window |
|
|
|
|
* | | TRUE | * a pupup window (WS_POPUP) |
|
|
|
|
* | | | * an owned top level window (like dialog) |
|
|
|
|
* | aStopIfNotChild +-------+-----------------------+-----------------------+
|
|
|
|
* | | | * independent window | * only an independent |
|
|
|
|
* | | FALSE | * non-popup-owned- | top level window |
|
|
|
|
* | | | window like dialog | |
|
|
|
|
* +-----------------+-------+-----------------------+-----------------------+
|
|
|
|
*/
|
|
|
|
static HWND GetTopLevelHWND(HWND aWnd,
|
|
|
|
bool aStopIfNotChild = false,
|
|
|
|
bool aStopIfNotPopup = true);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SetNSWindowPtr() associates an nsWindow to aWnd. If aWindow is NULL,
|
|
|
|
* it dissociate any nsWindow pointer from aWnd.
|
|
|
|
* GetNSWindowPtr() returns an nsWindow pointer which was associated by
|
|
|
|
* SetNSWindowPtr().
|
|
|
|
*/
|
|
|
|
static bool SetNSWindowPtr(HWND aWnd, nsWindow* aWindow);
|
|
|
|
static nsWindow* GetNSWindowPtr(HWND aWnd);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GetMonitorCount() returns count of monitors on the environment.
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
static int32_t GetMonitorCount();
|
2012-01-04 02:21:44 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* IsOurProcessWindow() returns TRUE if aWnd belongs our process.
|
|
|
|
* Otherwise, FALSE.
|
|
|
|
*/
|
|
|
|
static bool IsOurProcessWindow(HWND aWnd);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* FindOurProcessWindow() returns the nearest ancestor window which
|
|
|
|
* belongs to our process. If it fails to find our process's window by the
|
|
|
|
* top level window, returns NULL. And note that this is using ::GetParent()
|
|
|
|
* for climbing the window hierarchy, therefore, it gives up at an owned top
|
|
|
|
* level window except popup window (e.g., dialog).
|
|
|
|
*/
|
|
|
|
static HWND FindOurProcessWindow(HWND aWnd);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* FindOurWindowAtPoint() returns the topmost child window which belongs to
|
|
|
|
* our process's top level window.
|
|
|
|
*
|
|
|
|
* NOTE: the topmost child window may NOT be our process's window like a
|
|
|
|
* plugin's window.
|
|
|
|
*/
|
|
|
|
static HWND FindOurWindowAtPoint(const POINT& aPointInScreen);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* InitMSG() returns an MSG struct which was initialized by the params.
|
|
|
|
* Don't trust the other members in the result.
|
|
|
|
*/
|
|
|
|
static MSG InitMSG(UINT aMessage, WPARAM wParam, LPARAM lParam);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GetScanCode() returns a scan code for the LPARAM of WM_KEYDOWN, WM_KEYUP,
|
|
|
|
* WM_CHAR and WM_UNICHAR.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static WORD GetScanCode(LPARAM aLParam)
|
|
|
|
{
|
|
|
|
return (aLParam >> 16) & 0xFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* IsExtendedScanCode() returns TRUE if the LPARAM indicates the key message
|
|
|
|
* is an extended key event.
|
|
|
|
*/
|
|
|
|
static bool IsExtendedScanCode(LPARAM aLParam)
|
|
|
|
{
|
|
|
|
return (aLParam & 0x1000000) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GetInternalMessage() converts a native message to an internal message.
|
|
|
|
* If there is no internal message for the given native message, returns
|
|
|
|
* the native message itself.
|
|
|
|
*/
|
|
|
|
static UINT GetInternalMessage(UINT aNativeMessage);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GetNativeMessage() converts an internal message to a native message.
|
|
|
|
* If aInternalMessage is a native message, returns the native message itself.
|
|
|
|
*/
|
|
|
|
static UINT GetNativeMessage(UINT aInternalMessage);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GetMouseInputSource() returns a pointing device information. The value is
|
|
|
|
* one of nsIDOMMouseEvent::MOZ_SOURCE_*. This method MUST be called during
|
|
|
|
* mouse message handling.
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
static uint16_t GetMouseInputSource();
|
2012-01-10 18:09:41 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2012-02-16 16:36:04 -08:00
|
|
|
/**
|
|
|
|
* GetShellItemPath return the file or directory path of a shell item.
|
|
|
|
* Internally calls IShellItem's GetDisplayName.
|
|
|
|
*
|
|
|
|
* aItem the shell item containing the path.
|
|
|
|
* aResultString the resulting string path.
|
|
|
|
* returns true if a path was retreived.
|
|
|
|
*/
|
|
|
|
static bool GetShellItemPath(IShellItem* aItem,
|
|
|
|
nsString& aResultString);
|
|
|
|
|
2012-11-02 04:54:44 -07:00
|
|
|
/**
|
|
|
|
* ConvertHRGNToRegion converts a Windows HRGN to an nsIntRegion.
|
|
|
|
*
|
|
|
|
* aRgn the HRGN to convert.
|
|
|
|
* returns the nsIntRegion.
|
|
|
|
*/
|
|
|
|
static nsIntRegion ConvertHRGNToRegion(HRGN aRgn);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ToIntRect converts a Windows RECT to a nsIntRect.
|
|
|
|
*
|
|
|
|
* aRect the RECT to convert.
|
|
|
|
* returns the nsIntRect.
|
|
|
|
*/
|
|
|
|
static nsIntRect ToIntRect(const RECT& aRect);
|
|
|
|
|
2012-01-10 18:09:41 -08:00
|
|
|
private:
|
|
|
|
typedef HRESULT (WINAPI * SHCreateItemFromParsingNamePtr)(PCWSTR pszPath,
|
|
|
|
IBindCtx *pbc,
|
|
|
|
REFIID riid,
|
|
|
|
void **ppv);
|
|
|
|
static SHCreateItemFromParsingNamePtr sCreateItemFromParsingName;
|
2012-02-16 16:36:04 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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();
|
2012-01-04 02:21:44 -08:00
|
|
|
};
|
|
|
|
|
2012-11-09 01:55:56 -08:00
|
|
|
#ifdef MOZ_PLACES
|
2012-10-04 01:33:24 -07:00
|
|
|
class AsyncFaviconDataReady MOZ_FINAL : public nsIFaviconDataCallback
|
2012-07-21 13:07:26 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIFAVICONDATACALLBACK
|
|
|
|
|
|
|
|
AsyncFaviconDataReady(nsIURI *aNewURI,
|
|
|
|
nsCOMPtr<nsIThread> &aIOThread,
|
|
|
|
const bool aURLShortcut);
|
|
|
|
nsresult OnFaviconDataNotAvailable(void);
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIURI> mNewURI;
|
|
|
|
nsCOMPtr<nsIThread> mIOThread;
|
|
|
|
const bool mURLShortcut;
|
|
|
|
};
|
2012-11-09 01:55:56 -08:00
|
|
|
#endif
|
2012-07-21 13:07:26 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Asynchronously tries add the list to the build
|
|
|
|
*/
|
|
|
|
class AsyncWriteIconToDisk : public nsIRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
const bool mURLShortcut;
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
|
|
|
|
// Warning: AsyncWriteIconToDisk assumes ownership of the aData buffer passed in
|
|
|
|
AsyncWriteIconToDisk(const nsAString &aIconPath,
|
|
|
|
const nsACString &aMimeTypeOfInputData,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t *aData,
|
|
|
|
uint32_t aDataLen,
|
2012-07-21 13:07:26 -07:00
|
|
|
const bool aURLShortcut);
|
|
|
|
virtual ~AsyncWriteIconToDisk();
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsAutoString mIconPath;
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString mMimeTypeOfInputData;
|
2012-08-22 08:56:38 -07:00
|
|
|
nsAutoArrayPtr<uint8_t> mBuffer;
|
|
|
|
uint32_t mBufferLength;
|
2012-07-21 13:07:26 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
class AsyncDeleteIconFromDisk : public nsIRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
|
|
|
|
AsyncDeleteIconFromDisk(const nsAString &aIconPath);
|
|
|
|
virtual ~AsyncDeleteIconFromDisk();
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsAutoString mIconPath;
|
|
|
|
};
|
|
|
|
|
|
|
|
class AsyncDeleteAllFaviconsFromDisk : public nsIRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
|
|
|
|
AsyncDeleteAllFaviconsFromDisk();
|
|
|
|
virtual ~AsyncDeleteAllFaviconsFromDisk();
|
|
|
|
};
|
|
|
|
|
|
|
|
class FaviconHelper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static const char kJumpListCacheDir[];
|
|
|
|
static const char kShortcutCacheDir[];
|
|
|
|
static nsresult ObtainCachedIconFile(nsCOMPtr<nsIURI> aFaviconPageURI,
|
|
|
|
nsString &aICOFilePath,
|
|
|
|
nsCOMPtr<nsIThread> &aIOThread,
|
|
|
|
bool aURLShortcut);
|
|
|
|
|
|
|
|
static nsresult HashURI(nsCOMPtr<nsICryptoHash> &aCryptoHash,
|
|
|
|
nsIURI *aUri,
|
|
|
|
nsACString& aUriHash);
|
|
|
|
|
|
|
|
static nsresult GetOutputIconPath(nsCOMPtr<nsIURI> aFaviconPageURI,
|
|
|
|
nsCOMPtr<nsIFile> &aICOFile,
|
|
|
|
bool aURLShortcut);
|
|
|
|
|
|
|
|
static nsresult
|
|
|
|
CacheIconFileFromFaviconURIAsync(nsCOMPtr<nsIURI> aFaviconPageURI,
|
|
|
|
nsCOMPtr<nsIFile> aICOFile,
|
|
|
|
nsCOMPtr<nsIThread> &aIOThread,
|
|
|
|
bool aURLShortcut);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static int32_t GetICOCacheSecondsTimeout();
|
2012-07-21 13:07:26 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-01-04 02:21:44 -08:00
|
|
|
} // namespace widget
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_widget_WinUtils_h__
|