tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 44b88dad2e5fa531f43c11169c2c170e9073dfda
parent 570166de598ed3f4b5f10bfdaefac07a6fb98218
Author: Tom Schuster <tschuster@mozilla.com>
Date:   Mon, 10 Nov 2025 11:36:57 +0000

Bug 1944033 - Update Windows to use the image from the child. r=media-playback-reviewers,win-reviewers,gstoll,aosmond

Differential Revision: https://phabricator.services.mozilla.com/D271060

Diffstat:
Mwidget/windows/WindowsSMTCProvider.cpp | 119+++++++++++++++++++++----------------------------------------------------------
Mwidget/windows/WindowsSMTCProvider.h | 10+---------
2 files changed, 32 insertions(+), 97 deletions(-)

diff --git a/widget/windows/WindowsSMTCProvider.cpp b/widget/windows/WindowsSMTCProvider.cpp @@ -224,7 +224,6 @@ void WindowsSMTCProvider::ClearMetadata() { if (FAILED(mDisplay->ClearAll())) { LOG("Failed to clear SMTC display"); } - mImageFetchRequest.DisconnectIfExists(); CancelPendingStoreAsyncOperation(); mThumbnailUrl.Truncate(); mProcessingUrl.Truncate(); @@ -596,102 +595,46 @@ void WindowsSMTCProvider::SetPositionState( } void WindowsSMTCProvider::LoadThumbnail( - const nsTArray<mozilla::dom::MediaImage>& aArtwork) { + const nsTArray<mozilla::dom::MediaImageData>& aArtwork) { MOZ_ASSERT(NS_IsMainThread()); - // TODO: Sort the images by the preferred size or format. - mArtwork = aArtwork; - mNextImageIndex = 0; - - // Abort the loading if - // 1) thumbnail is being updated, and one in processing is in the artwork - // 2) thumbnail is not being updated, and one in use is in the artwork - if (!mProcessingUrl.IsEmpty()) { - LOG("Load thumbnail while image: %s is being processed", - NS_ConvertUTF16toUTF8(mProcessingUrl).get()); - if (mozilla::dom::IsImageIn(mArtwork, mProcessingUrl)) { - LOG("No need to load thumbnail. The one being processed is in the " - "artwork"); - return; + for (const dom::MediaImageData& image : aArtwork) { + if (!image.mDataSurface) { + continue; } - } else if (!mThumbnailUrl.IsEmpty()) { - if (mozilla::dom::IsImageIn(mArtwork, mThumbnailUrl)) { - LOG("No need to load thumbnail. The one in use is in the artwork"); + + if (mThumbnailUrl == image.mSrc) { + LOG("Artwork image URL did not change"); return; } - } - - // If there is a pending image store operation, that image must be different - // from the new image will be loaded below, so the pending one should be - // cancelled. - CancelPendingStoreAsyncOperation(); - // Remove the current thumbnail on the interface - ClearThumbnail(); - // Then load the new thumbnail asynchronously - LoadImageAtIndex(mNextImageIndex++); -} - -void WindowsSMTCProvider::LoadImageAtIndex(const size_t aIndex) { - MOZ_ASSERT(NS_IsMainThread()); - if (aIndex >= mArtwork.Length()) { - LOG("Stop loading thumbnail. No more available images"); - mImageFetchRequest.DisconnectIfExists(); - mProcessingUrl.Truncate(); - return; - } - - const mozilla::dom::MediaImage& image = mArtwork[aIndex]; + // Although IMAGE_JPEG or IMAGE_BMP are valid types as well, but a + // png image with transparent background will be converted into a + // jpeg/bmp file with a colored background. IMAGE_PNG format seems + // to be the best choice for now. + uint32_t size = 0; + char* src = nullptr; + // Only used to hold the image data + nsCOMPtr<nsIInputStream> inputStream; + nsresult rv = mozilla::dom::GetEncodedImageBuffer( + image.mDataSurface, nsLiteralCString(IMAGE_PNG), getter_AddRefs(inputStream), + &size, &src); + if (NS_FAILED(rv) || !inputStream || size == 0 || !src) { + LOG("Failed to get the image buffer info. Try next image"); + continue; + } - // TODO: No need to fetch the default image and do image processing since the - // the default image is local file and it's trustworthy. For the default - // image, we can use `CreateFromFile` to create the IRandomAccessStream. We - // should probably cache it since it could be used very often (Bug 1643102) + // If there is a pending image store operation, that image must be different + // from the new image will be loaded below, so the pending one should be + // cancelled. + CancelPendingStoreAsyncOperation(); + // Remove the current thumbnail on the interface + ClearThumbnail(); - if (!mozilla::dom::IsValidImageUrl(image.mSrc)) { - LOG("Skip the image with invalid URL. Try next image"); - mImageFetchRequest.DisconnectIfExists(); - LoadImageAtIndex(mNextImageIndex++); - return; + mProcessingUrl = image.mSrc; + LoadImage(src, size); + break; } - - mImageFetchRequest.DisconnectIfExists(); - mProcessingUrl = image.mSrc; - - mImageFetcher = mozilla::MakeUnique<mozilla::dom::FetchImageHelper>(image); - RefPtr<WindowsSMTCProvider> self = this; - mImageFetcher->FetchImage() - ->Then( - AbstractThread::MainThread(), __func__, - [this, self](const nsCOMPtr<imgIContainer>& aImage) { - LOG("The image is fetched successfully"); - mImageFetchRequest.Complete(); - - // Although IMAGE_JPEG or IMAGE_BMP are valid types as well, but a - // png image with transparent background will be converted into a - // jpeg/bmp file with a colored background. IMAGE_PNG format seems - // to be the best choice for now. - uint32_t size = 0; - char* src = nullptr; - // Only used to hold the image data - nsCOMPtr<nsIInputStream> inputStream; - nsresult rv = mozilla::dom::GetEncodedImageBuffer( - aImage, nsLiteralCString(IMAGE_PNG), - getter_AddRefs(inputStream), &size, &src); - if (NS_FAILED(rv) || !inputStream || size == 0 || !src) { - LOG("Failed to get the image buffer info. Try next image"); - LoadImageAtIndex(mNextImageIndex++); - return; - } - - LoadImage(src, size); - }, - [this, self](bool) { - LOG("Failed to fetch image. Try next image"); - mImageFetchRequest.Complete(); - LoadImageAtIndex(mNextImageIndex++); - }) - ->Track(mImageFetchRequest); } void WindowsSMTCProvider::LoadImage(const char* aImageData, diff --git a/widget/windows/WindowsSMTCProvider.h b/widget/windows/WindowsSMTCProvider.h @@ -12,7 +12,6 @@ # include <Windows.Media.h> # include <wrl.h> -# include "mozilla/dom/FetchImageHelper.h" # include "mozilla/dom/MediaController.h" # include "mozilla/dom/MediaControlKeySource.h" # include "mozilla/UniquePtr.h" @@ -72,10 +71,7 @@ class WindowsSMTCProvider final : public mozilla::dom::MediaControlKeySource { bool SetMusicMetadata(const nsString& aArtist, const nsString& aTitle); // Sets one of the artwork to the SMTC interface asynchronously - void LoadThumbnail(const nsTArray<mozilla::dom::MediaImage>& aArtwork); - // Stores the image at index aIndex of the mArtwork to the Thumbnail - // asynchronously - void LoadImageAtIndex(const size_t aIndex); + void LoadThumbnail(const nsTArray<mozilla::dom::MediaImageData>& aArtwork); // Stores the raw binary data of an image to mImageStream and set it to the // Thumbnail asynchronously void LoadImage(const char* aImageData, uint32_t aDataSize); @@ -118,10 +114,6 @@ class WindowsSMTCProvider final : public mozilla::dom::MediaControlKeySource { CopyableTArray<mozilla::dom::MediaImage> mArtwork; size_t mNextImageIndex; - mozilla::UniquePtr<mozilla::dom::FetchImageHelper> mImageFetcher; - mozilla::MozPromiseRequestHolder<mozilla::dom::ImagePromise> - mImageFetchRequest; - HWND mWindow; // handle to the invisible window // EventRegistrationTokens are used to have a handle on a callback (to remove