chore: move gin::Handle to gin_helper (#48016)

chore: move gin::Handle to gin_helper (#47959)

* chore: move gin::Handle to gin_helper

* chore: fix lint

Co-authored-by: Robo <hop2deep@gmail.com>
This commit is contained in:
Calvin 2025-08-10 13:46:37 -06:00 committed by GitHub
commit e3f358a45a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
95 changed files with 555 additions and 419 deletions

View file

@ -4,11 +4,11 @@
#include <vector>
#include "gin/handle.h"
#include "shell/common/asar/archive.h"
#include "shell/common/asar/asar_util.h"
#include "shell/common/gin_converters/file_path_converter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/gin_helper/handle.h"
#include "shell/common/node_includes.h"
namespace {

View file

@ -16,7 +16,6 @@
#include "base/strings/pattern.h"
#include "base/strings/utf_string_conversions.h"
#include "gin/arguments.h"
#include "gin/handle.h"
#include "gin/object_template_builder.h"
#include "gin/per_isolate_data.h"
#include "net/base/data_url.h"
@ -29,6 +28,7 @@
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/gin_helper/error_thrower.h"
#include "shell/common/gin_helper/function_template_extensions.h"
#include "shell/common/gin_helper/handle.h"
#include "shell/common/gin_helper/object_template_builder.h"
#include "shell/common/node_includes.h"
#include "shell/common/node_util.h"
@ -338,8 +338,8 @@ float NativeImage::GetAspectRatio(const std::optional<float> scale_factor) {
return static_cast<float>(size.width()) / static_cast<float>(size.height());
}
gin::Handle<NativeImage> NativeImage::Resize(gin::Arguments* args,
base::Value::Dict options) {
gin_helper::Handle<NativeImage> NativeImage::Resize(gin::Arguments* args,
base::Value::Dict options) {
float scale_factor = GetScaleFactorFromOptions(args);
gfx::Size size = GetSize(scale_factor);
@ -375,8 +375,8 @@ gin::Handle<NativeImage> NativeImage::Resize(gin::Arguments* args,
image_.AsImageSkia(), method, size)});
}
gin::Handle<NativeImage> NativeImage::Crop(v8::Isolate* isolate,
const gfx::Rect& rect) {
gin_helper::Handle<NativeImage> NativeImage::Crop(v8::Isolate* isolate,
const gfx::Rect& rect) {
return Create(isolate, gfx::Image{gfx::ImageSkiaOperations::ExtractSubset(
image_.AsImageSkia(), rect)});
}
@ -424,18 +424,18 @@ bool NativeImage::IsTemplateImage() {
#endif
// static
gin::Handle<NativeImage> NativeImage::CreateEmpty(v8::Isolate* isolate) {
gin_helper::Handle<NativeImage> NativeImage::CreateEmpty(v8::Isolate* isolate) {
return Create(isolate, gfx::Image{});
}
// static
gin::Handle<NativeImage> NativeImage::Create(v8::Isolate* isolate,
const gfx::Image& image) {
return gin::CreateHandle(isolate, new NativeImage(isolate, image));
gin_helper::Handle<NativeImage> NativeImage::Create(v8::Isolate* isolate,
const gfx::Image& image) {
return gin_helper::CreateHandle(isolate, new NativeImage(isolate, image));
}
// static
gin::Handle<NativeImage> NativeImage::CreateFromPNG(
gin_helper::Handle<NativeImage> NativeImage::CreateFromPNG(
v8::Isolate* isolate,
const base::span<const uint8_t> data) {
gfx::ImageSkia image_skia;
@ -444,7 +444,7 @@ gin::Handle<NativeImage> NativeImage::CreateFromPNG(
}
// static
gin::Handle<NativeImage> NativeImage::CreateFromJPEG(
gin_helper::Handle<NativeImage> NativeImage::CreateFromJPEG(
v8::Isolate* isolate,
const base::span<const uint8_t> buffer) {
gfx::ImageSkia image_skia;
@ -453,19 +453,20 @@ gin::Handle<NativeImage> NativeImage::CreateFromJPEG(
}
// static
gin::Handle<NativeImage> NativeImage::CreateFromPath(
gin_helper::Handle<NativeImage> NativeImage::CreateFromPath(
v8::Isolate* isolate,
const base::FilePath& path) {
base::FilePath image_path = NormalizePath(path);
#if BUILDFLAG(IS_WIN)
if (image_path.MatchesExtension(FILE_PATH_LITERAL(".ico"))) {
return gin::CreateHandle(isolate, new NativeImage(isolate, image_path));
return gin_helper::CreateHandle(isolate,
new NativeImage(isolate, image_path));
}
#endif
gfx::ImageSkia image_skia;
electron::util::PopulateImageSkiaRepsFromPath(&image_skia, image_path);
gfx::Image image(image_skia);
gin::Handle<NativeImage> handle = Create(isolate, image);
gin_helper::Handle<NativeImage> handle = Create(isolate, image);
#if BUILDFLAG(IS_MAC)
if (IsTemplateFilename(image_path))
handle->SetTemplateImage(true);
@ -474,7 +475,7 @@ gin::Handle<NativeImage> NativeImage::CreateFromPath(
}
// static
gin::Handle<NativeImage> NativeImage::CreateFromBitmap(
gin_helper::Handle<NativeImage> NativeImage::CreateFromBitmap(
gin_helper::ErrorThrower thrower,
v8::Local<v8::Value> buffer,
const gin_helper::Dictionary& options) {
@ -520,7 +521,7 @@ gin::Handle<NativeImage> NativeImage::CreateFromBitmap(
}
// static
gin::Handle<NativeImage> NativeImage::CreateFromBuffer(
gin_helper::Handle<NativeImage> NativeImage::CreateFromBuffer(
gin_helper::ErrorThrower thrower,
v8::Local<v8::Value> buffer,
gin::Arguments* args) {
@ -548,8 +549,9 @@ gin::Handle<NativeImage> NativeImage::CreateFromBuffer(
}
// static
gin::Handle<NativeImage> NativeImage::CreateFromDataURL(v8::Isolate* isolate,
const GURL& url) {
gin_helper::Handle<NativeImage> NativeImage::CreateFromDataURL(
v8::Isolate* isolate,
const GURL& url) {
std::string mime_type, charset, data;
if (net::DataURL::Parse(url, &mime_type, &charset, &data)) {
if (mime_type == "image/png")
@ -562,8 +564,9 @@ gin::Handle<NativeImage> NativeImage::CreateFromDataURL(v8::Isolate* isolate,
}
#if !BUILDFLAG(IS_MAC)
gin::Handle<NativeImage> NativeImage::CreateFromNamedImage(gin::Arguments* args,
std::string name) {
gin_helper::Handle<NativeImage> NativeImage::CreateFromNamedImage(
gin::Arguments* args,
std::string name) {
return CreateEmpty(args->isolate());
}
#endif

View file

@ -34,14 +34,13 @@ class Size;
namespace gin {
class Arguments;
template <typename T>
class Handle;
} // namespace gin
namespace gin_helper {
class Dictionary;
class ErrorThrower;
template <typename T>
class Handle;
} // namespace gin_helper
namespace electron::api {
@ -58,28 +57,31 @@ class NativeImage final : public gin_helper::DeprecatedWrappable<NativeImage> {
NativeImage(const NativeImage&) = delete;
NativeImage& operator=(const NativeImage&) = delete;
static gin::Handle<NativeImage> CreateEmpty(v8::Isolate* isolate);
static gin::Handle<NativeImage> Create(v8::Isolate* isolate,
const gfx::Image& image);
static gin::Handle<NativeImage> CreateFromPNG(v8::Isolate* isolate,
base::span<const uint8_t> data);
static gin::Handle<NativeImage> CreateFromJPEG(
static gin_helper::Handle<NativeImage> CreateEmpty(v8::Isolate* isolate);
static gin_helper::Handle<NativeImage> Create(v8::Isolate* isolate,
const gfx::Image& image);
static gin_helper::Handle<NativeImage> CreateFromPNG(
v8::Isolate* isolate,
base::span<const uint8_t> data);
static gin::Handle<NativeImage> CreateFromPath(v8::Isolate* isolate,
const base::FilePath& path);
static gin::Handle<NativeImage> CreateFromBitmap(
static gin_helper::Handle<NativeImage> CreateFromJPEG(
v8::Isolate* isolate,
base::span<const uint8_t> data);
static gin_helper::Handle<NativeImage> CreateFromPath(
v8::Isolate* isolate,
const base::FilePath& path);
static gin_helper::Handle<NativeImage> CreateFromBitmap(
gin_helper::ErrorThrower thrower,
v8::Local<v8::Value> buffer,
const gin_helper::Dictionary& options);
static gin::Handle<NativeImage> CreateFromBuffer(
static gin_helper::Handle<NativeImage> CreateFromBuffer(
gin_helper::ErrorThrower thrower,
v8::Local<v8::Value> buffer,
gin::Arguments* args);
static gin::Handle<NativeImage> CreateFromDataURL(v8::Isolate* isolate,
const GURL& url);
static gin::Handle<NativeImage> CreateFromNamedImage(gin::Arguments* args,
std::string name);
static gin_helper::Handle<NativeImage> CreateFromDataURL(v8::Isolate* isolate,
const GURL& url);
static gin_helper::Handle<NativeImage> CreateFromNamedImage(
gin::Arguments* args,
std::string name);
#if !BUILDFLAG(IS_LINUX)
static v8::Local<v8::Promise> CreateThumbnailFromPath(
v8::Isolate* isolate,
@ -114,9 +116,10 @@ class NativeImage final : public gin_helper::DeprecatedWrappable<NativeImage> {
std::vector<float> GetScaleFactors();
v8::Local<v8::Value> GetBitmap(gin::Arguments* args);
v8::Local<v8::Value> GetNativeHandle(gin_helper::ErrorThrower thrower);
gin::Handle<NativeImage> Resize(gin::Arguments* args,
base::Value::Dict options);
gin::Handle<NativeImage> Crop(v8::Isolate* isolate, const gfx::Rect& rect);
gin_helper::Handle<NativeImage> Resize(gin::Arguments* args,
base::Value::Dict options);
gin_helper::Handle<NativeImage> Crop(v8::Isolate* isolate,
const gfx::Rect& rect);
std::string ToDataURL(gin::Arguments* args);
bool IsEmpty();
gfx::Size GetSize(const std::optional<float> scale_factor);

View file

@ -16,8 +16,8 @@
#include "base/strings/sys_string_conversions.h"
#include "base/task/bind_post_task.h"
#include "gin/arguments.h"
#include "gin/handle.h"
#include "shell/common/gin_converters/image_converter.h"
#include "shell/common/gin_helper/handle.h"
#include "shell/common/gin_helper/promise.h"
#include "shell/common/mac_util.h"
#include "ui/gfx/color_utils.h"
@ -103,8 +103,9 @@ v8::Local<v8::Promise> NativeImage::CreateThumbnailFromPath(
return handle;
}
gin::Handle<NativeImage> NativeImage::CreateFromNamedImage(gin::Arguments* args,
std::string name) {
gin_helper::Handle<NativeImage> NativeImage::CreateFromNamedImage(
gin::Arguments* args,
std::string name) {
@autoreleasepool {
std::vector<double> hsl_shift;

View file

@ -4,7 +4,6 @@
#include <string>
#include "gin/handle.h"
#include "net/base/filename_util.h"
#include "net/base/network_change_notifier.h"
#include "net/http/http_util.h"
@ -17,6 +16,7 @@
#include "shell/common/gin_converters/net_converter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/gin_helper/error_thrower.h"
#include "shell/common/gin_helper/handle.h"
#include "shell/common/gin_helper/object_template_builder.h"
#include "shell/common/gin_helper/promise.h"
#include "shell/common/node_includes.h"

View file

@ -17,7 +17,6 @@
#include "base/memory/raw_ptr.h"
#include "base/notreached.h"
#include "base/sequence_checker.h"
#include "gin/handle.h"
#include "gin/object_template_builder.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/system/data_pipe_producer.h"
@ -43,6 +42,7 @@
#include "shell/common/gin_converters/gurl_converter.h"
#include "shell/common/gin_converters/net_converter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/gin_helper/handle.h"
#include "shell/common/gin_helper/object_template_builder.h"
#include "shell/common/gin_helper/promise.h"
#include "shell/common/node_includes.h"
@ -167,12 +167,12 @@ class JSChunkedDataPipeGetter final
: public gin_helper::DeprecatedWrappable<JSChunkedDataPipeGetter>,
public network::mojom::ChunkedDataPipeGetter {
public:
static gin::Handle<JSChunkedDataPipeGetter> Create(
static gin_helper::Handle<JSChunkedDataPipeGetter> Create(
v8::Isolate* isolate,
v8::Local<v8::Function> body_func,
mojo::PendingReceiver<network::mojom::ChunkedDataPipeGetter>
chunked_data_pipe_getter) {
return gin::CreateHandle(
return gin_helper::CreateHandle(
isolate, new JSChunkedDataPipeGetter(
isolate, body_func, std::move(chunked_data_pipe_getter)));
}
@ -390,7 +390,8 @@ void SimpleURLLoaderWrapper::Start() {
void SimpleURLLoaderWrapper::Pin() {
// Prevent ourselves from being GC'd until the request is complete. Must be
// called after gin::CreateHandle, otherwise the wrapper isn't initialized.
// called after gin_helper::CreateHandle, otherwise the wrapper isn't
// initialized.
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
pinned_wrapper_.Reset(isolate, GetWrapper(isolate).ToLocalChecked());
}
@ -522,7 +523,7 @@ SimpleURLLoaderWrapper::GetURLLoaderFactoryForURL(const GURL& url) {
}
// static
gin::Handle<SimpleURLLoaderWrapper> SimpleURLLoaderWrapper::Create(
gin_helper::Handle<SimpleURLLoaderWrapper> SimpleURLLoaderWrapper::Create(
gin::Arguments* args) {
gin_helper::Dictionary opts;
if (!args->GetNext(&opts)) {
@ -697,7 +698,7 @@ gin::Handle<SimpleURLLoaderWrapper> SimpleURLLoaderWrapper::Create(
ElectronBrowserContext* browser_context = nullptr;
if (electron::IsBrowserProcess()) {
std::string partition;
gin::Handle<Session> session;
gin_helper::Handle<Session> session;
if (!opts.Get("session", &session)) {
if (opts.Get("partition", &partition))
session = Session::FromPartition(args->isolate(), partition);
@ -707,7 +708,7 @@ gin::Handle<SimpleURLLoaderWrapper> SimpleURLLoaderWrapper::Create(
browser_context = session->browser_context();
}
auto ret = gin::CreateHandle(
auto ret = gin_helper::CreateHandle(
args->isolate(),
new SimpleURLLoaderWrapper(browser_context, std::move(request), options));
ret->Pin();

View file

@ -27,9 +27,12 @@
namespace gin {
class Arguments;
} // namespace gin
namespace gin_helper {
template <typename T>
class Handle;
} // namespace gin
} // namespace gin_helper
namespace net {
class AuthChallengeInfo;
@ -56,7 +59,8 @@ class SimpleURLLoaderWrapper final
private network::mojom::URLLoaderNetworkServiceObserver {
public:
~SimpleURLLoaderWrapper() override;
static gin::Handle<SimpleURLLoaderWrapper> Create(gin::Arguments* args);
static gin_helper::Handle<SimpleURLLoaderWrapper> Create(
gin::Arguments* args);
void Cancel();