Skip to content

Commit

Permalink
fix: maxSize enforcement on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Feb 21, 2023
1 parent f9417ca commit 07c6d7b
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions shell/common/api/electron_api_native_image_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ namespace electron::api {
v8::Local<v8::Promise> NativeImage::CreateThumbnailFromPath(
v8::Isolate* isolate,
const base::FilePath& path,
const gfx::Size& size) {
const gfx::Size& max_size) {
base::win::ScopedCOMInitializer scoped_com_initializer;

gin_helper::Promise<gfx::Image> promise(isolate);
v8::Local<v8::Promise> handle = promise.GetHandle();
HRESULT hr;

if (size.IsEmpty()) {
promise.RejectWithErrorMessage("size must not be empty");
if (max_size.IsEmpty()) {
promise.RejectWithErrorMessage("maxSize must not be empty");
return handle;
}

Expand Down Expand Up @@ -61,10 +61,19 @@ v8::Local<v8::Promise> NativeImage::CreateThumbnailFromPath(
Microsoft::WRL::ComPtr<ISharedBitmap> pThumbnail;
WTS_CACHEFLAGS flags;
WTS_THUMBNAILID thumbId;
hr = pThumbnailCache->GetThumbnail(pItem.Get(), size.width(),
hr = pThumbnailCache->GetThumbnail(pItem.Get(), max_size.width(),
WTS_FLAGS::WTS_NONE, &pThumbnail, &flags,
&thumbId);

// If the thumbnail size is smaller than the requested size (max_size),
// WTS_LOWQUALITY will be set in WTS_CACHEFLAGS. If it is *not* set, that
// means the image is bigger than max_size and we must scale it down.
if ((flags & WTS_CACHEFLAGS::WTS_LOWQUALITY) == 0) {
hr = pThumbnailCache->GetThumbnail(pItem.Get(), max_size.width(),
WTS_FLAGS::WTS_SCALETOREQUESTEDSIZE,
&pThumbnail, &flags, &thumbId);
}

if (FAILED(hr)) {
promise.RejectWithErrorMessage(
"failed to get thumbnail from local thumbnail cache reference");
Expand Down

0 comments on commit 07c6d7b

Please sign in to comment.