Backed out 15 changesets (bug 1852806) for causing mda failures on test_video_low_pow...
[gecko.git] / widget / windows / WinUtils.h
blob0d50dd3bfc97724e24b4d1a1d824b22041502afc
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_widget_WinUtils_h__
7 #define mozilla_widget_WinUtils_h__
9 #include "nscore.h"
10 #include <windows.h>
11 #include <shobjidl.h>
12 #include <uxtheme.h>
13 #include <dwmapi.h>
14 #include <unordered_map>
15 #include <utility>
17 // Undo the windows.h damage
18 #undef GetMessage
19 #undef CreateEvent
20 #undef GetClassName
21 #undef GetBinaryType
22 #undef RemoveDirectory
24 #include "nsString.h"
25 #include "nsRegion.h"
26 #include "nsRect.h"
28 #include "nsIRunnable.h"
29 #include "nsICryptoHash.h"
30 #ifdef MOZ_PLACES
31 # include "nsIFaviconService.h"
32 #endif
33 #include "nsIDownloader.h"
34 #include "nsIURI.h"
35 #include "nsIWidget.h"
36 #include "nsIThread.h"
38 #include "mozilla/Attributes.h"
39 #include "mozilla/EventForwards.h"
40 #include "mozilla/HalScreenConfiguration.h"
41 #include "mozilla/HashTable.h"
42 #include "mozilla/LazyIdleThread.h"
43 #include "mozilla/UniquePtr.h"
44 #include "mozilla/Vector.h"
45 #include "mozilla/WindowsDpiAwareness.h"
46 #include "mozilla/WindowsProcessMitigations.h"
47 #include "mozilla/gfx/2D.h"
49 // Starting with version 10.0.22621.0 of the Windows SDK the AR_STATE enum and
50 // types are only defined when building for Windows 8 instead of Windows 7
51 // (although they are always defined for MinGW)
52 #if (WDK_NTDDI_VERSION >= 0x0A00000C) && (WINVER < 0x0602) && \
53 (!defined(__MINGW32__))
55 enum tagAR_STATE {
56 AR_ENABLED = 0x0,
57 AR_DISABLED = 0x1,
58 AR_SUPPRESSED = 0x2,
59 AR_REMOTESESSION = 0x4,
60 AR_MULTIMON = 0x8,
61 AR_NOSENSOR = 0x10,
62 AR_NOT_SUPPORTED = 0x20,
63 AR_DOCKED = 0x40,
64 AR_LAPTOP = 0x80
67 typedef enum tagAR_STATE AR_STATE;
69 using PAR_STATE = enum tagAR_STATE*;
71 #endif // (WDK_NTDDI_VERSION >= 0x0A00000C) && (WINVER < 0x0602)
73 /**
74 * NS_INLINE_DECL_IUNKNOWN_REFCOUNTING should be used for defining and
75 * implementing AddRef() and Release() of IUnknown interface.
76 * This depends on xpcom/base/nsISupportsImpl.h.
79 #define NS_INLINE_DECL_IUNKNOWN_REFCOUNTING(_class) \
80 public: \
81 STDMETHODIMP_(ULONG) AddRef() { \
82 MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(_class) \
83 MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt"); \
84 NS_ASSERT_OWNINGTHREAD(_class); \
85 ++mRefCnt; \
86 NS_LOG_ADDREF(this, mRefCnt, #_class, sizeof(*this)); \
87 return static_cast<ULONG>(mRefCnt.get()); \
88 } \
89 STDMETHODIMP_(ULONG) Release() { \
90 MOZ_ASSERT(int32_t(mRefCnt) > 0, \
91 "Release called on object that has already been released!"); \
92 NS_ASSERT_OWNINGTHREAD(_class); \
93 --mRefCnt; \
94 NS_LOG_RELEASE(this, mRefCnt, #_class); \
95 if (mRefCnt == 0) { \
96 NS_ASSERT_OWNINGTHREAD(_class); \
97 mRefCnt = 1; /* stabilize */ \
98 delete this; \
99 return 0; \
101 return static_cast<ULONG>(mRefCnt.get()); \
104 protected: \
105 nsAutoRefCnt mRefCnt; \
106 NS_DECL_OWNINGTHREAD \
107 public:
109 class nsWindow;
110 struct KeyPair;
112 namespace mozilla {
113 enum class PointerCapabilities : uint8_t;
114 #if defined(ACCESSIBILITY)
115 namespace a11y {
116 class LocalAccessible;
117 } // namespace a11y
118 #endif // defined(ACCESSIBILITY)
120 // Helper function: enumerate all the toplevel HWNDs attached to the current
121 // thread via ::EnumThreadWindows().
123 // Note that this use of ::EnumThreadWindows() is, unfortunately, not an
124 // abstract implementation detail.
125 template <typename F>
126 void EnumerateThreadWindows(F&& f)
127 // requires requires(F f, HWND h) { f(h); }
129 class Impl {
130 public:
131 F f;
132 explicit Impl(F&& f) : f(std::forward<F>(f)) {}
134 void invoke() {
135 WNDENUMPROC proc = &Impl::Callback;
136 ::EnumThreadWindows(::GetCurrentThreadId(), proc,
137 reinterpret_cast<LPARAM>(&f));
140 private:
141 static BOOL CALLBACK Callback(HWND hwnd, LPARAM lp) {
142 (*reinterpret_cast<F*>(lp))(hwnd);
143 return TRUE;
147 Impl(std::forward<F>(f)).invoke();
150 namespace widget {
152 // More complete QS definitions for MsgWaitForMultipleObjects() and
153 // GetQueueStatus() that include newer win8 specific defines.
155 #ifndef QS_RAWINPUT
156 # define QS_RAWINPUT 0x0400
157 #endif
159 #ifndef QS_TOUCH
160 # define QS_TOUCH 0x0800
161 # define QS_POINTER 0x1000
162 #endif
164 #define MOZ_QS_ALLEVENT \
165 (QS_KEY | QS_MOUSEMOVE | QS_MOUSEBUTTON | QS_POSTMESSAGE | QS_TIMER | \
166 QS_PAINT | QS_SENDMESSAGE | QS_HOTKEY | QS_ALLPOSTMESSAGE | QS_RAWINPUT | \
167 QS_TOUCH | QS_POINTER)
169 // Logging macros
170 #define LogFunction() mozilla::widget::WinUtils::Log(__FUNCTION__)
171 #define LogThread() \
172 mozilla::widget::WinUtils::Log("%s: IsMainThread:%d ThreadId:%X", \
173 __FUNCTION__, NS_IsMainThread(), \
174 GetCurrentThreadId())
175 #define LogThis() mozilla::widget::WinUtils::Log("[%X] %s", this, __FUNCTION__)
176 #define LogException(e) \
177 mozilla::widget::WinUtils::Log("%s Exception:%s", __FUNCTION__, \
178 e->ToString()->Data())
179 #define LogHRESULT(hr) \
180 mozilla::widget::WinUtils::Log("%s hr=%X", __FUNCTION__, hr)
182 #ifdef MOZ_PLACES
183 class myDownloadObserver final : public nsIDownloadObserver {
184 ~myDownloadObserver() {}
186 public:
187 NS_DECL_ISUPPORTS
188 NS_DECL_NSIDOWNLOADOBSERVER
190 #endif
192 class WinUtils {
193 // Function pointers for APIs that may not be available depending on
194 // the Win10 update version -- will be set up in Initialize().
195 static SetThreadDpiAwarenessContextProc sSetThreadDpiAwarenessContext;
196 static EnableNonClientDpiScalingProc sEnableNonClientDpiScaling;
197 static GetSystemMetricsForDpiProc sGetSystemMetricsForDpi;
199 // Set on Initialize().
200 static bool sHasPackageIdentity;
202 public:
203 class AutoSystemDpiAware {
204 public:
205 AutoSystemDpiAware() {
206 MOZ_DIAGNOSTIC_ASSERT(!IsWin32kLockedDown());
208 if (sSetThreadDpiAwarenessContext) {
209 mPrevContext =
210 sSetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_SYSTEM_AWARE);
214 ~AutoSystemDpiAware() {
215 if (sSetThreadDpiAwarenessContext) {
216 sSetThreadDpiAwarenessContext(mPrevContext);
220 private:
221 DPI_AWARENESS_CONTEXT mPrevContext;
224 // Wrapper for DefWindowProc that will enable non-client dpi scaling on the
225 // window during creation.
226 static LRESULT WINAPI NonClientDpiScalingDefWindowProcW(HWND hWnd, UINT msg,
227 WPARAM wParam,
228 LPARAM lParam);
231 * Get the system's default logical-to-physical DPI scaling factor,
232 * which is based on the primary display. Note however that unlike
233 * LogToPhysFactor(GetPrimaryMonitor()), this will not change during
234 * a session even if the displays are reconfigured. This scale factor
235 * is used by Windows theme metrics etc, which do not fully support
236 * dynamic resolution changes but are only updated on logout.
238 static double SystemScaleFactor();
240 static bool IsPerMonitorDPIAware();
242 * Get the DPI of the given monitor if it's per-monitor DPI aware, otherwise
243 * return the system DPI.
245 static float MonitorDPI(HMONITOR aMonitor);
246 static float SystemDPI();
248 * Functions to convert between logical pixels as used by most Windows APIs
249 * and physical (device) pixels.
251 static double LogToPhysFactor(HMONITOR aMonitor);
252 static double LogToPhysFactor(HWND aWnd);
253 static double LogToPhysFactor(HDC aDC) {
254 return LogToPhysFactor(::WindowFromDC(aDC));
256 static int32_t LogToPhys(HMONITOR aMonitor, double aValue);
257 static HMONITOR GetPrimaryMonitor();
258 static HMONITOR MonitorFromRect(const gfx::Rect& rect);
260 static bool HasSystemMetricsForDpi();
261 static int GetSystemMetricsForDpi(int nIndex, UINT dpi);
264 * @param msg Windows event message
265 * @return User-friendly event name, or nullptr if no
266 * match is found.
268 static const char* WinEventToEventName(UINT msg);
271 * @param aHdc HDC for printer
272 * @return unwritable margins for currently set page on aHdc or empty margins
273 * if aHdc is null
275 static gfx::MarginDouble GetUnwriteableMarginsForDeviceInInches(HDC aHdc);
277 static bool HasPackageIdentity() { return sHasPackageIdentity; }
280 * The "family name" of a Windows app package is the full name without any of
281 * the components that might change during the life cycle of the app (such as
282 * the version number, or the architecture). This leaves only those properties
283 * which together serve to uniquely identify the app within one Windows
284 * installation, namely the base name and the publisher name. Meaning, this
285 * string is safe to use anywhere that a string uniquely identifying an app
286 * installation is called for (because multiple copies of the same app on the
287 * same system is not a supported feature in the app framework).
289 static nsString GetPackageFamilyName();
292 * Logging helpers that dump output to prlog module 'Widget', console, and
293 * OutputDebugString. Note these output in both debug and release builds.
295 static void Log(const char* fmt, ...);
296 static void LogW(const wchar_t* fmt, ...);
299 * PeekMessage() and GetMessage() are wrapper methods for PeekMessageW(),
300 * GetMessageW(), ITfMessageMgr::PeekMessageW() and
301 * ITfMessageMgr::GetMessageW().
302 * Don't call the native APIs directly. You MUST use these methods instead.
304 static bool PeekMessage(LPMSG aMsg, HWND aWnd, UINT aFirstMessage,
305 UINT aLastMessage, UINT aOption);
306 static bool GetMessage(LPMSG aMsg, HWND aWnd, UINT aFirstMessage,
307 UINT aLastMessage);
310 * Wait until a message is ready to be processed.
311 * Prefer using this method to directly calling ::WaitMessage since
312 * ::WaitMessage will wait if there is an unread message in the queue.
313 * That can cause freezes until another message enters the queue if the
314 * message is marked read by a call to PeekMessage which the caller is
315 * not aware of (e.g., from a different thread).
316 * Note that this method may cause sync dispatch of sent (as opposed to
317 * posted) messages.
318 * @param aTimeoutMs Timeout for waiting in ms, defaults to INFINITE
320 static void WaitForMessage(DWORD aTimeoutMs = INFINITE);
323 * Gets the value of a string-typed registry value.
325 * @param aRoot The registry root to search in.
326 * @param aKeyName The name of the registry key to open.
327 * @param aValueName The name of the registry value in the specified key whose
328 * value is to be retrieved. Can be null, to retrieve the key's unnamed/
329 * default value.
330 * @param aBuffer The buffer into which to store the string value. Can be
331 * null, in which case the return value indicates just whether the value
332 * exists.
333 * @param aBufferLength The size of aBuffer, in bytes.
334 * @return Whether the value exists and is a string.
336 static bool GetRegistryKey(HKEY aRoot, char16ptr_t aKeyName,
337 char16ptr_t aValueName, wchar_t* aBuffer,
338 DWORD aBufferLength);
341 * Checks whether the registry key exists in either 32bit or 64bit branch on
342 * the environment.
344 * @param aRoot The registry root of aName.
345 * @param aKeyName The name of the registry key to check.
346 * @return TRUE if it exists and is readable. Otherwise, FALSE.
348 static bool HasRegistryKey(HKEY aRoot, char16ptr_t aKeyName);
351 * GetTopLevelHWND() returns a window handle of the top level window which
352 * aWnd belongs to. Note that the result may not be our window, i.e., it
353 * may not be managed by nsWindow.
355 * See follwing table for the detail of the result window type.
357 * +-------------------------+-----------------------------------------------+
358 * | | aStopIfNotPopup |
359 * +-------------------------+-----------------------+-----------------------+
360 * | | TRUE | FALSE |
361 + +-----------------+-------+-----------------------+-----------------------+
362 * | | | * an independent top level window |
363 * | | TRUE | * a pupup window (WS_POPUP) |
364 * | | | * an owned top level window (like dialog) |
365 * | aStopIfNotChild +-------+-----------------------+-----------------------+
366 * | | | * independent window | * only an independent |
367 * | | FALSE | * non-popup-owned- | top level window |
368 * | | | window like dialog | |
369 * +-----------------+-------+-----------------------+-----------------------+
371 static HWND GetTopLevelHWND(HWND aWnd, bool aStopIfNotChild = false,
372 bool aStopIfNotPopup = true);
375 * SetNSWindowPtr() associates aWindow with aWnd. If aWidget is nullptr, it
376 * instead dissociates any nsWindow from aWnd.
378 * No AddRef is performed. May not be used off of the main thread.
380 static void SetNSWindowPtr(HWND aWnd, nsWindow* aWindow);
382 * GetNSWindowPtr() returns a pointer to the associated nsWindow pointer, if
383 * one exists, or nullptr, if not.
385 * No AddRef is performed. May not be used off of the main thread.
387 static nsWindow* GetNSWindowPtr(HWND aWnd);
390 * IsOurProcessWindow() returns TRUE if aWnd belongs our process.
391 * Otherwise, FALSE.
393 static bool IsOurProcessWindow(HWND aWnd);
396 * FindOurProcessWindow() returns the nearest ancestor window which
397 * belongs to our process. If it fails to find our process's window by the
398 * top level window, returns nullptr. And note that this is using
399 * ::GetParent() for climbing the window hierarchy, therefore, it gives
400 * up at an owned top level window except popup window (e.g., dialog).
402 static HWND FindOurProcessWindow(HWND aWnd);
405 * FindOurWindowAtPoint() returns the topmost child window which belongs to
406 * our process's top level window.
408 * NOTE: the topmost child window may NOT be our process's window like a
409 * plugin's window.
411 static HWND FindOurWindowAtPoint(const POINT& aPointInScreen);
414 * InitMSG() returns an MSG struct which was initialized by the params.
415 * Don't trust the other members in the result.
417 static MSG InitMSG(UINT aMessage, WPARAM wParam, LPARAM lParam, HWND aWnd);
420 * GetScanCode() returns a scan code for the LPARAM of WM_KEYDOWN, WM_KEYUP,
421 * WM_CHAR and WM_UNICHAR.
424 static WORD GetScanCode(LPARAM aLParam) { return (aLParam >> 16) & 0xFF; }
427 * IsExtendedScanCode() returns TRUE if the LPARAM indicates the key message
428 * is an extended key event.
430 static bool IsExtendedScanCode(LPARAM aLParam) {
431 return (aLParam & 0x1000000) != 0;
435 * GetInternalMessage() converts a native message to an internal message.
436 * If there is no internal message for the given native message, returns
437 * the native message itself.
439 static UINT GetInternalMessage(UINT aNativeMessage);
442 * GetNativeMessage() converts an internal message to a native message.
443 * If aInternalMessage is a native message, returns the native message itself.
445 static UINT GetNativeMessage(UINT aInternalMessage);
448 * GetMouseInputSource() returns a pointing device information. The value is
449 * one of MouseEvent_Binding::MOZ_SOURCE_*. This method MUST be called during
450 * mouse message handling.
452 static uint16_t GetMouseInputSource();
455 * Windows also fires mouse window messages for pens and touches, so we should
456 * retrieve their pointer ID on receiving mouse events as well. Please refer
457 * to
458 * https://msdn.microsoft.com/en-us/library/windows/desktop/ms703320(v=vs.85).aspx
460 static uint16_t GetMousePointerID();
462 static bool GetIsMouseFromTouch(EventMessage aEventType);
465 * ConvertHRGNToRegion converts a Windows HRGN to an LayoutDeviceIntRegion.
467 * aRgn the HRGN to convert.
468 * returns the LayoutDeviceIntRegion.
470 static LayoutDeviceIntRegion ConvertHRGNToRegion(HRGN aRgn);
473 * ToIntRect converts a Windows RECT to a LayoutDeviceIntRect.
475 * aRect the RECT to convert.
476 * returns the LayoutDeviceIntRect.
478 static LayoutDeviceIntRect ToIntRect(const RECT& aRect);
481 * Returns true if the context or IME state is enabled. Otherwise, false.
483 static bool IsIMEEnabled(const InputContext& aInputContext);
484 static bool IsIMEEnabled(IMEEnabled aIMEState);
487 * Returns modifier key array for aModifiers. This is for
488 * nsIWidget::SynthethizeNative*Event().
490 static void SetupKeyModifiersSequence(nsTArray<KeyPair>* aArray,
491 uint32_t aModifiers, UINT aMessage);
494 * Does device have touch support
496 static uint32_t IsTouchDeviceSupportPresent();
499 * The maximum number of simultaneous touch contacts supported by the device.
500 * In the case of devices with multiple digitizers (e.g. multiple touch
501 * screens), the value will be the maximum of the set of maximum supported
502 * contacts by each individual digitizer.
504 static uint32_t GetMaxTouchPoints();
507 * Returns the windows power platform role, which is useful for detecting
508 * tablets.
510 static POWER_PLATFORM_ROLE GetPowerPlatformRole();
512 // For pointer and hover media queries features.
513 static PointerCapabilities GetPrimaryPointerCapabilities();
514 // For any-pointer and any-hover media queries features.
515 static PointerCapabilities GetAllPointerCapabilities();
516 // Returns a string containing a comma-separated list of Fluent IDs
517 // representing the currently active pointing devices
518 static void GetPointerExplanation(nsAString* aExplanation);
521 * Fully resolves a path to its final path name. So if path contains
522 * junction points or symlinks to other folders, we'll resolve the path
523 * fully to the actual path that the links target.
525 * @param aPath path to be resolved.
526 * @return true if successful, including if nothing needs to be changed.
527 * false if something failed or aPath does not exist, aPath will
528 * remain unchanged.
530 static bool ResolveJunctionPointsAndSymLinks(std::wstring& aPath);
531 static bool ResolveJunctionPointsAndSymLinks(nsIFile* aPath);
534 * Returns true if executable's path is on a network drive.
536 static bool RunningFromANetworkDrive();
538 static void Initialize();
540 static nsresult WriteBitmap(nsIFile* aFile,
541 mozilla::gfx::SourceSurface* surface);
542 // This function is a helper, but it cannot be called from the main thread.
543 // Use the one above!
544 static nsresult WriteBitmap(nsIFile* aFile, imgIContainer* aImage);
547 * Wrapper for PathCanonicalize().
548 * Upon success, the resulting output string length is <= MAX_PATH.
549 * @param aPath [in,out] The path to transform.
550 * @return true on success, false on failure.
552 static bool CanonicalizePath(nsAString& aPath);
555 * Converts short paths (e.g. "C:\\PROGRA~1\\XYZ") to full paths.
556 * Upon success, the resulting output string length is <= MAX_PATH.
557 * @param aPath [in,out] The path to transform.
558 * @return true on success, false on failure.
560 static bool MakeLongPath(nsAString& aPath);
563 * Wrapper for PathUnExpandEnvStringsW().
564 * Upon success, the resulting output string length is <= MAX_PATH.
565 * @param aPath [in,out] The path to transform.
566 * @return true on success, false on failure.
568 static bool UnexpandEnvVars(nsAString& aPath);
571 * Retrieve a semicolon-delimited list of DLL files derived from AppInit_DLLs
573 static bool GetAppInitDLLs(nsAString& aOutput);
575 enum class PathTransformFlags : uint32_t {
576 Canonicalize = 1,
577 Lengthen = 2,
578 UnexpandEnvVars = 4,
579 RequireFilePath = 8,
581 Default = 7, // Default omits RequireFilePath
585 * Given a path, transforms it in preparation to be reported via telemetry.
586 * That can include canonicalization, converting short to long paths,
587 * unexpanding environment strings, and removing potentially sensitive data
588 * from the path.
590 * @param aPath [in,out] The path to transform.
591 * @param aFlags [in] Specifies which transformations to perform, allowing
592 * the caller to skip operations they know have already been
593 * performed.
594 * @return true on success, false on failure.
596 static bool PreparePathForTelemetry(
597 nsAString& aPath,
598 PathTransformFlags aFlags = PathTransformFlags::Default);
600 static const size_t kMaxWhitelistedItems = 3;
601 using WhitelistVec =
602 Vector<std::pair<nsString, nsDependentString>, kMaxWhitelistedItems>;
604 static const WhitelistVec& GetWhitelistedPaths();
606 static bool GetClassName(HWND aHwnd, nsAString& aName);
608 static void EnableWindowOcclusion(const bool aEnable);
610 static bool GetTimezoneName(wchar_t* aBuffer);
612 #ifdef DEBUG
613 static nsresult SetHiDPIMode(bool aHiDPI);
614 static nsresult RestoreHiDPIMode();
615 #endif
617 static bool GetAutoRotationState(AR_STATE* aRotationState);
619 private:
620 static WhitelistVec BuildWhitelist();
622 public:
623 #ifdef ACCESSIBILITY
624 static a11y::LocalAccessible* GetRootAccessibleForHWND(HWND aHwnd);
625 #endif
628 #ifdef MOZ_PLACES
629 class AsyncFaviconDataReady final : public nsIFaviconDataCallback {
630 public:
631 NS_DECL_ISUPPORTS
632 NS_DECL_NSIFAVICONDATACALLBACK
634 AsyncFaviconDataReady(nsIURI* aNewURI, RefPtr<LazyIdleThread>& aIOThread,
635 const bool aURLShortcut,
636 already_AddRefed<nsIRunnable> aRunnable);
637 nsresult OnFaviconDataNotAvailable(void);
639 private:
640 ~AsyncFaviconDataReady() {}
642 nsCOMPtr<nsIURI> mNewURI;
643 RefPtr<LazyIdleThread> mIOThread;
644 nsCOMPtr<nsIRunnable> mRunnable;
645 const bool mURLShortcut;
647 #endif
650 * Asynchronously tries add the list to the build
652 class AsyncEncodeAndWriteIcon : public nsIRunnable {
653 public:
654 NS_DECL_THREADSAFE_ISUPPORTS
655 NS_DECL_NSIRUNNABLE
657 // Warning: AsyncEncodeAndWriteIcon assumes ownership of the aData buffer
658 // passed in
659 AsyncEncodeAndWriteIcon(const nsAString& aIconPath,
660 UniquePtr<uint8_t[]> aData, uint32_t aStride,
661 uint32_t aWidth, uint32_t aHeight,
662 already_AddRefed<nsIRunnable> aRunnable);
664 private:
665 virtual ~AsyncEncodeAndWriteIcon();
667 nsAutoString mIconPath;
668 UniquePtr<uint8_t[]> mBuffer;
669 nsCOMPtr<nsIRunnable> mRunnable;
670 uint32_t mStride;
671 uint32_t mWidth;
672 uint32_t mHeight;
675 class AsyncDeleteAllFaviconsFromDisk : public nsIRunnable {
676 public:
677 NS_DECL_THREADSAFE_ISUPPORTS
678 NS_DECL_NSIRUNNABLE
680 explicit AsyncDeleteAllFaviconsFromDisk(bool aIgnoreRecent = false);
682 private:
683 virtual ~AsyncDeleteAllFaviconsFromDisk();
685 int32_t mIcoNoDeleteSeconds;
686 bool mIgnoreRecent;
687 nsCOMPtr<nsIFile> mJumpListCacheDir;
690 class FaviconHelper {
691 public:
692 static const char kJumpListCacheDir[];
693 static const char kShortcutCacheDir[];
694 static nsresult ObtainCachedIconFile(
695 nsCOMPtr<nsIURI> aFaviconPageURI, nsString& aICOFilePath,
696 RefPtr<LazyIdleThread>& aIOThread, bool aURLShortcut,
697 already_AddRefed<nsIRunnable> aRunnable = nullptr);
699 static nsresult HashURI(nsCOMPtr<nsICryptoHash>& aCryptoHash, nsIURI* aUri,
700 nsACString& aUriHash);
702 static nsresult GetOutputIconPath(nsCOMPtr<nsIURI> aFaviconPageURI,
703 nsCOMPtr<nsIFile>& aICOFile,
704 bool aURLShortcut);
706 static nsresult CacheIconFileFromFaviconURIAsync(
707 nsCOMPtr<nsIURI> aFaviconPageURI, nsCOMPtr<nsIFile> aICOFile,
708 RefPtr<LazyIdleThread>& aIOThread, bool aURLShortcut,
709 already_AddRefed<nsIRunnable> aRunnable);
711 static int32_t GetICOCacheSecondsTimeout();
714 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(WinUtils::PathTransformFlags);
716 // RTL shim windows are temporary child windows of our nsWindows created to
717 // address RTL issues in picker dialogs. (See bug 588735.)
718 class MOZ_STACK_CLASS ScopedRtlShimWindow {
719 public:
720 explicit ScopedRtlShimWindow(nsIWidget* aParent);
721 ~ScopedRtlShimWindow();
723 ScopedRtlShimWindow(const ScopedRtlShimWindow&) = delete;
724 ScopedRtlShimWindow(ScopedRtlShimWindow&&) = delete;
726 HWND get() const { return mWnd; }
728 private:
729 HWND mWnd;
732 } // namespace widget
733 } // namespace mozilla
735 #endif // mozilla_widget_WinUtils_h__