Commit 4f232d43 authored by Becca Hughes's avatar Becca Hughes Committed by Chromium LUCI CQ

[Media Session] Add support for "any" images

At the moment support for images that do not have
a defined size or use "any" does not work. This
fixes that.

BUG=1085814

Change-Id: I28e6d52dfe4f0bf53edf0395af3d675a289340ff
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2621955
Auto-Submit: Becca Hughes <beccahughes@chromium.org>
Commit-Queue: Tommy Steimel <steimel@chromium.org>
Reviewed-by: default avatarTommy Steimel <steimel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#842309}
parent 84d2f334
...@@ -154,6 +154,19 @@ bool IsSizeAtLeast(const gfx::Size& size, int min_size) { ...@@ -154,6 +154,19 @@ bool IsSizeAtLeast(const gfx::Size& size, int min_size) {
return size.width() >= min_size || size.height() >= min_size; return size.width() >= min_size || size.height() >= min_size;
} }
bool IsSizesAtLeast(const std::vector<gfx::Size>& sizes, int min_size) {
// If we haven't found an image based on size then we should check if there
// are any images that have no size data or have an "any" size which is
// denoted by a single empty gfx::Size value.
if (sizes.size() == 0 || (sizes.size() == 1 && sizes[0].IsEmpty()))
return true;
bool check_size = false;
for (auto& size : sizes)
check_size = check_size || IsSizeAtLeast(size, min_size);
return check_size;
}
base::string16 SanitizeMediaTitle(const base::string16 title) { base::string16 SanitizeMediaTitle(const base::string16 title) {
base::string16 out; base::string16 out;
base::TrimString(title, base::ASCIIToUTF16(" "), &out); base::TrimString(title, base::ASCIIToUTF16(" "), &out);
...@@ -1108,12 +1121,7 @@ void MediaSessionImpl::GetMediaImageBitmap( ...@@ -1108,12 +1121,7 @@ void MediaSessionImpl::GetMediaImageBitmap(
} }
} }
// Check that |image.sizes| contains a size that is above the minimum size. if (!found || !IsSizesAtLeast(image.sizes, minimum_size_px)) {
bool check_size = false;
for (auto& size : image.sizes)
check_size = check_size || IsSizeAtLeast(size, minimum_size_px);
if (!found || !check_size) {
std::move(callback).Run(SkBitmap()); std::move(callback).Run(SkBitmap());
return; return;
} }
......
...@@ -88,6 +88,16 @@ base::Optional<MediaImage> MediaImageManager::SelectImage( ...@@ -88,6 +88,16 @@ base::Optional<MediaImage> MediaImageManager::SelectImage(
} }
} }
// If we haven't found an image based on size then we should check if there
// are any images that have an "any" size which is denoted by a single empty
// gfx::Size value.
if (!selected.has_value()) {
for (auto& image : images) {
if (image.sizes.size() == 1 && image.sizes[0].IsEmpty())
return image;
}
}
return selected; return selected;
} }
......
...@@ -204,4 +204,17 @@ TEST_F(MediaImageManagerTest, PreferImagesWithNonZeroArea) { ...@@ -204,4 +204,17 @@ TEST_F(MediaImageManagerTest, PreferImagesWithNonZeroArea) {
EXPECT_EQ(image1, manager()->SelectImage(images)); EXPECT_EQ(image1, manager()->SelectImage(images));
} }
TEST_F(MediaImageManagerTest, PickImageWithAnySize) {
MediaImageManager manager(10, 10);
std::vector<MediaImage> images;
// Empty size denotes "any" value.
MediaImage image;
image.sizes.push_back(gfx::Size());
images.push_back(image);
EXPECT_TRUE(manager.SelectImage(images));
}
} // namespace media_session } // namespace media_session
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment