![trop[bot]](/assets/img/avatar_default.png)
* chore: bump chromium to 134.0.6992.0 Co-authored-by: Charles Kerr <charles@charleskerr.com> * chore: add BrowserProcessImpl::CreateGlobalFeaturesForTesting() stub Xref: https://chromium-review.googlesource.com/c/chromium/src/+/6216193 Remove GlobalFeatures from TestingBrowserProcess::Init Co-authored-by: Charles Kerr <charles@charleskerr.com> * chore: bump chromium to 134.0.6994.0 Co-authored-by: Charles Kerr <charles@charleskerr.com> * 6208630: Mac sandbox: don't use protobuf for policy serialization | https://chromium-review.googlesource.com/c/chromium/src/+/6208630 Co-authored-by: alice <alice@makenotion.com> * Remove HasUnsupportedFeature Mojo interface Xref: https://chromium-review.googlesource.com/c/chromium/src/+/6220800 Co-authored-by: Charles Kerr <charles@charleskerr.com> * 6217444: Remove scoped_gdi_object.h type aliases. | https://chromium-review.googlesource.com/c/chromium/src/+/6217444 Co-authored-by: alice <alice@makenotion.com> * chore: bump chromium to 134.0.6998.10 Co-authored-by: Charles Kerr <charles@charleskerr.com> * 6221378: Revert [OBC] Exclude Aliasing Cookies in FilterCookiesWithOptions() | https://chromium-review.googlesource.com/c/chromium/src/+/6221378 Co-authored-by: alice <alice@makenotion.com> * Update ExtensionPrefs::GetDisableReasons to return DisableReasonSet Xref: https://chromium-review.googlesource.com/c/chromium/src/+/6218840 change copied from 6218840 extensions/shell/browser/shell_extension_loader.cc Co-authored-by: Charles Kerr <charles@charleskerr.com> * 6218402: Typemap ui.gfx.DXGIHandle <=> gfx::DXGIHandle | https://chromium-review.googlesource.com/c/chromium/src/+/6218402 Co-authored-by: alice <alice@makenotion.com> * chore: disable flaky contentTracing test not new to this roll; it is happening in main as well Co-authored-by: Charles Kerr <charles@charleskerr.com> * fixup! chore: disable flaky contentTracing test Co-authored-by: Charles Kerr <charles@charleskerr.com> * chore: update patches * chore: disable flaky content tracing tests on Linux (#45612) (cherry picked from commit a1e4550c9e5b2b220530a9238795286bd028dbfb) --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr <charles@charleskerr.com> Co-authored-by: alice <alice@makenotion.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
102 lines
3 KiB
C++
102 lines
3 KiB
C++
// Copyright (c) 2020 GitHub, Inc.
|
|
// Use of this source code is governed by the MIT license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "shell/common/api/electron_api_native_image.h"
|
|
|
|
#include <windows.h>
|
|
|
|
#include <thumbcache.h>
|
|
#include <wrl/client.h>
|
|
|
|
#include "base/win/scoped_com_initializer.h"
|
|
#include "shell/common/gin_converters/image_converter.h"
|
|
#include "shell/common/gin_helper/promise.h"
|
|
#include "shell/common/skia_util.h"
|
|
#include "third_party/skia/include/core/SkBitmap.h"
|
|
#include "ui/gfx/icon_util.h"
|
|
#include "ui/gfx/image/image_skia.h"
|
|
|
|
namespace electron::api {
|
|
|
|
// static
|
|
v8::Local<v8::Promise> NativeImage::CreateThumbnailFromPath(
|
|
v8::Isolate* isolate,
|
|
const base::FilePath& path,
|
|
const gfx::Size& 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");
|
|
return handle;
|
|
}
|
|
|
|
// create an IShellItem
|
|
Microsoft::WRL::ComPtr<IShellItem> pItem;
|
|
std::wstring image_path = path.value();
|
|
hr = SHCreateItemFromParsingName(image_path.c_str(), nullptr,
|
|
IID_PPV_ARGS(&pItem));
|
|
|
|
if (FAILED(hr)) {
|
|
promise.RejectWithErrorMessage(
|
|
"Failed to create IShellItem from the given path");
|
|
return handle;
|
|
}
|
|
|
|
// Init thumbnail cache
|
|
Microsoft::WRL::ComPtr<IThumbnailCache> pThumbnailCache;
|
|
hr = CoCreateInstance(CLSID_LocalThumbnailCache, nullptr, CLSCTX_INPROC,
|
|
IID_PPV_ARGS(&pThumbnailCache));
|
|
if (FAILED(hr)) {
|
|
promise.RejectWithErrorMessage(
|
|
"Failed to acquire local thumbnail cache reference");
|
|
return handle;
|
|
}
|
|
|
|
// Populate the IShellBitmap
|
|
Microsoft::WRL::ComPtr<ISharedBitmap> pThumbnail;
|
|
hr = pThumbnailCache->GetThumbnail(
|
|
pItem.Get(), size.width(),
|
|
WTS_FLAGS::WTS_SCALETOREQUESTEDSIZE | WTS_FLAGS::WTS_SCALEUP, &pThumbnail,
|
|
nullptr, nullptr);
|
|
|
|
if (FAILED(hr)) {
|
|
promise.RejectWithErrorMessage(
|
|
"Failed to get thumbnail from local thumbnail cache reference");
|
|
return handle;
|
|
}
|
|
|
|
// Init HBITMAP
|
|
HBITMAP hBitmap = nullptr;
|
|
hr = pThumbnail->GetSharedBitmap(&hBitmap);
|
|
if (FAILED(hr)) {
|
|
promise.RejectWithErrorMessage("Failed to extract bitmap from thumbnail");
|
|
return handle;
|
|
}
|
|
|
|
// convert HBITMAP to gfx::Image
|
|
BITMAP bitmap;
|
|
if (!GetObject(hBitmap, sizeof(bitmap), &bitmap)) {
|
|
promise.RejectWithErrorMessage("Could not convert HBITMAP to BITMAP");
|
|
return handle;
|
|
}
|
|
|
|
ICONINFO icon_info;
|
|
icon_info.fIcon = TRUE;
|
|
icon_info.hbmMask = hBitmap;
|
|
icon_info.hbmColor = hBitmap;
|
|
|
|
base::win::ScopedGDIObject<HICON> icon(CreateIconIndirect(&icon_info));
|
|
SkBitmap skbitmap = IconUtil::CreateSkBitmapFromHICON(icon.get());
|
|
gfx::ImageSkia image_skia =
|
|
gfx::ImageSkia::CreateFromBitmap(skbitmap, 1.0 /*scale factor*/);
|
|
gfx::Image gfx_image = gfx::Image(image_skia);
|
|
promise.Resolve(gfx_image);
|
|
return handle;
|
|
}
|
|
|
|
} // namespace electron::api
|