From 95241d2225f384fdd0b216827b1575032d1d44ac Mon Sep 17 00:00:00 2001 From: Masatoshi Kimura Date: Mon, 6 Jan 2020 13:31:54 +0000 Subject: [PATCH] Bug 1602615 - Add a callback parameter to ObtainCachedIconFile and use it in GetFileContentsInternetShortcut. r=jmathies Differential Revision: https://phabricator.services.mozilla.com/D56478 --HG-- extra : moz-landing-system : lando --- widget/windows/WinUtils.cpp | 54 +++++++++++++++++++++--------------- widget/windows/WinUtils.h | 19 +++++++------ widget/windows/nsDataObj.cpp | 8 ++++-- 3 files changed, 49 insertions(+), 32 deletions(-) diff --git a/widget/windows/WinUtils.cpp b/widget/windows/WinUtils.cpp index b75aa316a8cf..cdabf7840513 100644 --- a/widget/windows/WinUtils.cpp +++ b/widget/windows/WinUtils.cpp @@ -1106,12 +1106,17 @@ void WinUtils::InvalidatePluginAsWorkaround(nsIWidget* aWidget, * @param aIOThread : the thread which performs the action * @param aURLShortcut : Differentiates between (false)Jumplistcache and * (true)Shortcutcache + * @param aRunnable : Executed in the aIOThread when the favicon cache is + * avaiable ************************************************************************/ -AsyncFaviconDataReady::AsyncFaviconDataReady(nsIURI* aNewURI, - nsCOMPtr& aIOThread, - const bool aURLShortcut) - : mNewURI(aNewURI), mIOThread(aIOThread), mURLShortcut(aURLShortcut) {} +AsyncFaviconDataReady::AsyncFaviconDataReady( + nsIURI* aNewURI, nsCOMPtr& aIOThread, const bool aURLShortcut, + already_AddRefed aRunnable) + : mNewURI(aNewURI), + mIOThread(aIOThread), + mRunnable(aRunnable), + mURLShortcut(aURLShortcut) {} NS_IMETHODIMP myDownloadObserver::OnDownloadComplete(nsIDownloader* downloader, @@ -1247,8 +1252,9 @@ AsyncFaviconDataReady::OnComplete(nsIURI* aFaviconURI, uint32_t aDataLen, int32_t stride = 4 * size.width; // AsyncEncodeAndWriteIcon takes ownership of the heap allocated buffer - nsCOMPtr event = new AsyncEncodeAndWriteIcon( - path, std::move(data), stride, size.width, size.height, mURLShortcut); + nsCOMPtr event = + new AsyncEncodeAndWriteIcon(path, std::move(data), stride, size.width, + size.height, mRunnable.forget()); mIOThread->Dispatch(event, NS_DISPATCH_NORMAL); return NS_OK; @@ -1259,10 +1265,10 @@ AsyncFaviconDataReady::OnComplete(nsIURI* aFaviconURI, uint32_t aDataLen, // in AsyncEncodeAndWriteIcon::AsyncEncodeAndWriteIcon( const nsAString& aIconPath, UniquePtr aBuffer, uint32_t aStride, - uint32_t aWidth, uint32_t aHeight, const bool aURLShortcut) - : mURLShortcut(aURLShortcut), - mIconPath(aIconPath), + uint32_t aWidth, uint32_t aHeight, already_AddRefed aRunnable) + : mIconPath(aIconPath), mBuffer(std::move(aBuffer)), + mRunnable(aRunnable), mStride(aStride), mWidth(aWidth), mHeight(aHeight) {} @@ -1306,9 +1312,8 @@ NS_IMETHODIMP AsyncEncodeAndWriteIcon::Run() { fclose(file); NS_ENSURE_SUCCESS(rv, rv); - if (mURLShortcut) { - SendNotifyMessage(HWND_BROADCAST, WM_SETTINGCHANGE, SPI_SETNONCLIENTMETRICS, - 0); + if (mRunnable) { + mRunnable->Run(); } return rv; } @@ -1389,12 +1394,15 @@ AsyncDeleteAllFaviconsFromDisk::~AsyncDeleteAllFaviconsFromDisk() {} * @param aICOFilePath The path of the icon file * @param aIOThread The thread to perform the Fetch on * @param aURLShortcut to distinguish between jumplistcache(false) and - * shortcutcache(true) + * shortcutcache(true) + * @param aRunnable Executed in the aIOThread when the favicon cache is + * avaiable */ -nsresult FaviconHelper::ObtainCachedIconFile(nsCOMPtr aFaviconPageURI, - nsString& aICOFilePath, - nsCOMPtr& aIOThread, - bool aURLShortcut) { +nsresult FaviconHelper::ObtainCachedIconFile( + nsCOMPtr aFaviconPageURI, nsString& aICOFilePath, + nsCOMPtr& aIOThread, bool aURLShortcut, + already_AddRefed aRunnable) { + nsCOMPtr runnable = aRunnable; // Obtain the ICO file path nsCOMPtr icoFile; nsresult rv = GetOutputIconPath(aFaviconPageURI, icoFile, aURLShortcut); @@ -1418,14 +1426,14 @@ nsresult FaviconHelper::ObtainCachedIconFile(nsCOMPtr aFaviconPageURI, // the next time we try to build the jump list, the data will be available. if (NS_FAILED(rv) || (nowTime - fileModTime) > icoReCacheSecondsTimeout) { CacheIconFileFromFaviconURIAsync(aFaviconPageURI, icoFile, aIOThread, - aURLShortcut); + aURLShortcut, runnable.forget()); return NS_ERROR_NOT_AVAILABLE; } } else { // The file does not exist yet, obtain it async from the favicon service so // that the next time we try to build the jump list it'll be available. CacheIconFileFromFaviconURIAsync(aFaviconPageURI, icoFile, aIOThread, - aURLShortcut); + aURLShortcut, runnable.forget()); return NS_ERROR_NOT_AVAILABLE; } @@ -1497,7 +1505,9 @@ nsresult FaviconHelper::GetOutputIconPath(nsCOMPtr aFaviconPageURI, // page aFaviconPageURI and stores it to disk at the path of aICOFile. nsresult FaviconHelper::CacheIconFileFromFaviconURIAsync( nsCOMPtr aFaviconPageURI, nsCOMPtr aICOFile, - nsCOMPtr& aIOThread, bool aURLShortcut) { + nsCOMPtr& aIOThread, bool aURLShortcut, + already_AddRefed aRunnable) { + nsCOMPtr runnable = aRunnable; #ifdef MOZ_PLACES // Obtain the favicon service and get the favicon for the specified page nsCOMPtr favIconSvc( @@ -1505,8 +1515,8 @@ nsresult FaviconHelper::CacheIconFileFromFaviconURIAsync( NS_ENSURE_TRUE(favIconSvc, NS_ERROR_FAILURE); nsCOMPtr callback = - new mozilla::widget::AsyncFaviconDataReady(aFaviconPageURI, aIOThread, - aURLShortcut); + new mozilla::widget::AsyncFaviconDataReady( + aFaviconPageURI, aIOThread, aURLShortcut, runnable.forget()); favIconSvc->GetFaviconDataForPage(aFaviconPageURI, callback, 0); #endif diff --git a/widget/windows/WinUtils.h b/widget/windows/WinUtils.h index 028b1bd746db..78db7504ba68 100644 --- a/widget/windows/WinUtils.h +++ b/widget/windows/WinUtils.h @@ -589,7 +589,8 @@ class AsyncFaviconDataReady final : public nsIFaviconDataCallback { NS_DECL_NSIFAVICONDATACALLBACK AsyncFaviconDataReady(nsIURI* aNewURI, nsCOMPtr& aIOThread, - const bool aURLShortcut); + const bool aURLShortcut, + already_AddRefed aRunnable); nsresult OnFaviconDataNotAvailable(void); private: @@ -597,6 +598,7 @@ class AsyncFaviconDataReady final : public nsIFaviconDataCallback { nsCOMPtr mNewURI; nsCOMPtr mIOThread; + nsCOMPtr mRunnable; const bool mURLShortcut; }; #endif @@ -606,7 +608,6 @@ class AsyncFaviconDataReady final : public nsIFaviconDataCallback { */ class AsyncEncodeAndWriteIcon : public nsIRunnable { public: - const bool mURLShortcut; NS_DECL_THREADSAFE_ISUPPORTS NS_DECL_NSIRUNNABLE @@ -615,13 +616,14 @@ class AsyncEncodeAndWriteIcon : public nsIRunnable { AsyncEncodeAndWriteIcon(const nsAString& aIconPath, UniquePtr aData, uint32_t aStride, uint32_t aWidth, uint32_t aHeight, - const bool aURLShortcut); + already_AddRefed aRunnable); private: virtual ~AsyncEncodeAndWriteIcon(); nsAutoString mIconPath; UniquePtr mBuffer; + nsCOMPtr mRunnable; uint32_t mStride; uint32_t mWidth; uint32_t mHeight; @@ -646,10 +648,10 @@ class FaviconHelper { public: static const char kJumpListCacheDir[]; static const char kShortcutCacheDir[]; - static nsresult ObtainCachedIconFile(nsCOMPtr aFaviconPageURI, - nsString& aICOFilePath, - nsCOMPtr& aIOThread, - bool aURLShortcut); + static nsresult ObtainCachedIconFile( + nsCOMPtr aFaviconPageURI, nsString& aICOFilePath, + nsCOMPtr& aIOThread, bool aURLShortcut, + already_AddRefed aRunnable = nullptr); static nsresult HashURI(nsCOMPtr& aCryptoHash, nsIURI* aUri, nsACString& aUriHash); @@ -660,7 +662,8 @@ class FaviconHelper { static nsresult CacheIconFileFromFaviconURIAsync( nsCOMPtr aFaviconPageURI, nsCOMPtr aICOFile, - nsCOMPtr& aIOThread, bool aURLShortcut); + nsCOMPtr& aIOThread, bool aURLShortcut, + already_AddRefed aRunnable); static int32_t GetICOCacheSecondsTimeout(); }; diff --git a/widget/windows/nsDataObj.cpp b/widget/windows/nsDataObj.cpp index 5e3f9a04f0a1..65ca1e3a3034 100644 --- a/widget/windows/nsDataObj.cpp +++ b/widget/windows/nsDataObj.cpp @@ -1137,8 +1137,12 @@ nsDataObj ::GetFileContentsInternetShortcut(FORMATETC& aFE, STGMEDIUM& aSTG) { nsAutoString aUriHash; - mozilla::widget::FaviconHelper::ObtainCachedIconFile(aUri, aUriHash, - mIOThread, true); + mozilla::widget::FaviconHelper::ObtainCachedIconFile( + aUri, aUriHash, mIOThread, true, + NS_NewRunnableFunction("FaviconHelper::RefreshDesktop", [] { + SendNotifyMessage(HWND_BROADCAST, WM_SETTINGCHANGE, + SPI_SETNONCLIENTMETRICS, 0); + })); rv = mozilla::widget::FaviconHelper::GetOutputIconPath(aUri, icoFile, true); NS_ENSURE_SUCCESS(rv, E_FAIL);