From d0c7a91a50fefc8a50cd452b89a2359765609536 Mon Sep 17 00:00:00 2001 From: Micha Hanselmann Date: Wed, 14 Aug 2019 19:18:34 -0700 Subject: [PATCH] move image converter to gin (#19655) --- filenames.gni | 4 +-- .../image_converter.cc | 15 ++++---- shell/common/gin_converters/image_converter.h | 34 +++++++++++++++++++ .../image_converter_gin_adapter.h | 29 ---------------- .../gin_converters/message_box_converter.cc | 2 +- .../native_mate_converters/image_converter.h | 19 ++++++----- 6 files changed, 56 insertions(+), 47 deletions(-) rename shell/common/{native_mate_converters => gin_converters}/image_converter.cc (73%) create mode 100644 shell/common/gin_converters/image_converter.h delete mode 100644 shell/common/gin_converters/image_converter_gin_adapter.h diff --git a/filenames.gni b/filenames.gni index 231ce1db2633..1a3578d851ad 100644 --- a/filenames.gni +++ b/filenames.gni @@ -472,7 +472,8 @@ filenames = { "shell/common/gin_converters/file_dialog_converter.h", "shell/common/gin_converters/file_path_converter.h", "shell/common/gin_converters/gurl_converter.h", - "shell/common/gin_converters/image_converter_gin_adapter.h", + "shell/common/gin_converters/image_converter.cc", + "shell/common/gin_converters/image_converter.h", "shell/common/gin_converters/message_box_converter.cc", "shell/common/gin_converters/message_box_converter.h", "shell/common/gin_converters/native_window_converter.h", @@ -506,7 +507,6 @@ filenames = { "shell/common/native_mate_converters/gfx_converter.cc", "shell/common/native_mate_converters/gfx_converter.h", "shell/common/native_mate_converters/gurl_converter.h", - "shell/common/native_mate_converters/image_converter.cc", "shell/common/native_mate_converters/image_converter.h", "shell/common/native_mate_converters/map_converter.h", "shell/common/native_mate_converters/native_window_converter.h", diff --git a/shell/common/native_mate_converters/image_converter.cc b/shell/common/gin_converters/image_converter.cc similarity index 73% rename from shell/common/native_mate_converters/image_converter.cc rename to shell/common/gin_converters/image_converter.cc index 68443ad8cab6..78bcfa96bc30 100644 --- a/shell/common/native_mate_converters/image_converter.cc +++ b/shell/common/gin_converters/image_converter.cc @@ -1,14 +1,14 @@ -// Copyright (c) 2014 GitHub, Inc. +// Copyright (c) 2019 GitHub, Inc. // Use of this source code is governed by the MIT license that can be // found in the LICENSE file. -#include "shell/common/native_mate_converters/image_converter.h" +#include "shell/common/gin_converters/image_converter.h" #include "shell/common/api/atom_api_native_image.h" -#include "shell/common/native_mate_converters/file_path_converter.h" +#include "shell/common/gin_converters/file_path_converter.h" #include "ui/gfx/image/image_skia.h" -namespace mate { +namespace gin { bool Converter::FromV8(v8::Isolate* isolate, v8::Local val, @@ -27,8 +27,9 @@ bool Converter::FromV8(v8::Isolate* isolate, if (val->IsNull()) return true; - Handle native_image; - if (!ConvertFromV8(isolate, val, &native_image)) + // TODO(deermichel): remove mate:: after dropping mate + mate::Handle native_image; + if (!mate::ConvertFromV8(isolate, val, &native_image)) return false; *out = native_image->image(); @@ -40,4 +41,4 @@ v8::Local Converter::ToV8(v8::Isolate* isolate, return ConvertToV8(isolate, electron::api::NativeImage::Create(isolate, val)); } -} // namespace mate +} // namespace gin diff --git a/shell/common/gin_converters/image_converter.h b/shell/common/gin_converters/image_converter.h new file mode 100644 index 000000000000..f4de04fb465f --- /dev/null +++ b/shell/common/gin_converters/image_converter.h @@ -0,0 +1,34 @@ +// Copyright (c) 2019 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#ifndef SHELL_COMMON_GIN_CONVERTERS_IMAGE_CONVERTER_H_ +#define SHELL_COMMON_GIN_CONVERTERS_IMAGE_CONVERTER_H_ + +#include "gin/converter.h" + +namespace gfx { +class Image; +class ImageSkia; +} // namespace gfx + +namespace gin { + +template <> +struct Converter { + static bool FromV8(v8::Isolate* isolate, + v8::Local val, + gfx::ImageSkia* out); +}; + +template <> +struct Converter { + static bool FromV8(v8::Isolate* isolate, + v8::Local val, + gfx::Image* out); + static v8::Local ToV8(v8::Isolate* isolate, const gfx::Image& val); +}; + +} // namespace gin + +#endif // SHELL_COMMON_GIN_CONVERTERS_IMAGE_CONVERTER_H_ diff --git a/shell/common/gin_converters/image_converter_gin_adapter.h b/shell/common/gin_converters/image_converter_gin_adapter.h deleted file mode 100644 index 2ff62b21415e..000000000000 --- a/shell/common/gin_converters/image_converter_gin_adapter.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2019 GitHub, Inc. -// Use of this source code is governed by the MIT license that can be -// found in the LICENSE file. - -#ifndef SHELL_COMMON_GIN_CONVERTERS_IMAGE_CONVERTER_GIN_ADAPTER_H_ -#define SHELL_COMMON_GIN_CONVERTERS_IMAGE_CONVERTER_GIN_ADAPTER_H_ - -#include "gin/converter.h" -#include "shell/common/native_mate_converters/image_converter.h" - -// TODO(deermichel): replace adapter with real implementation after removing -// mate -// -- this adapter forwards all conversions to the existing mate converter -- -// (other direction might be preferred, but this is safer for now :D) - -namespace gin { - -template <> -struct Converter { - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - gfx::ImageSkia* out) { - return mate::ConvertFromV8(isolate, val, out); - } -}; - -} // namespace gin - -#endif // SHELL_COMMON_GIN_CONVERTERS_IMAGE_CONVERTER_GIN_ADAPTER_H_ diff --git a/shell/common/gin_converters/message_box_converter.cc b/shell/common/gin_converters/message_box_converter.cc index ac357634c252..92ec509764e3 100644 --- a/shell/common/gin_converters/message_box_converter.cc +++ b/shell/common/gin_converters/message_box_converter.cc @@ -5,7 +5,7 @@ #include "shell/common/gin_converters/message_box_converter.h" #include "gin/dictionary.h" -#include "shell/common/gin_converters/image_converter_gin_adapter.h" +#include "shell/common/gin_converters/image_converter.h" #include "shell/common/gin_converters/native_window_converter.h" namespace gin { diff --git a/shell/common/native_mate_converters/image_converter.h b/shell/common/native_mate_converters/image_converter.h index 93c2d2ca53fb..befa1c50ec3f 100644 --- a/shell/common/native_mate_converters/image_converter.h +++ b/shell/common/native_mate_converters/image_converter.h @@ -6,11 +6,7 @@ #define SHELL_COMMON_NATIVE_MATE_CONVERTERS_IMAGE_CONVERTER_H_ #include "native_mate/converter.h" - -namespace gfx { -class Image; -class ImageSkia; -} // namespace gfx +#include "shell/common/gin_converters/image_converter.h" namespace mate { @@ -18,15 +14,22 @@ template <> struct Converter { static bool FromV8(v8::Isolate* isolate, v8::Local val, - gfx::ImageSkia* out); + gfx::ImageSkia* out) { + return gin::ConvertFromV8(isolate, val, out); + } }; template <> struct Converter { static bool FromV8(v8::Isolate* isolate, v8::Local val, - gfx::Image* out); - static v8::Local ToV8(v8::Isolate* isolate, const gfx::Image& val); + gfx::Image* out) { + return gin::ConvertFromV8(isolate, val, out); + } + static v8::Local ToV8(v8::Isolate* isolate, + const gfx::Image& val) { + return gin::ConvertToV8(isolate, val); + } }; } // namespace mate