chore: remove native_mate (Part 11) (#20719)

* refactor: convert Menu and globalShortcut to gin

* refactor: convert api::Cookies to gin

* refactor: convert View and WebContentsView to gin

* refactor: convert WebContents related classes to gin

* refactor: convert powerMonitor to gin

* refactor: prepare for header change

* refactor: remove last uses of mate::EventEmitter

* refactor: remove mate::EventEmitter

* refactor: move trackable_object to gin_helper

* fix: custom converter should not use Handle

* fix: no more need to check if icon is empty

It was a bug that the Handle<NativeImage> can be non-empty when the
image file does not exist. The bug was caused by the converter code
writing out the image even when the convertion fails.

The bug was work-arounded by adding an additional check, but since the
original bug had been fixed, the additional check is no longer needed.

* fix: should always set frameId even when callback is null

* fix: do not mix gin/mate handles for NativeImage
This commit is contained in:
Cheng Zhao 2019-10-25 22:03:28 +09:00 committed by GitHub
parent 0e0d4fe990
commit 0fe6767d6b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
80 changed files with 823 additions and 1087 deletions

View file

@ -9,7 +9,7 @@
#include <string>
#include "base/values.h"
#include "native_mate/handle.h"
#include "gin/handle.h"
#include "native_mate/wrappable.h"
#include "shell/common/gin_helper/error_thrower.h"
#include "ui/gfx/image/image.h"
@ -40,30 +40,29 @@ namespace api {
class NativeImage : public mate::Wrappable<NativeImage> {
public:
static mate::Handle<NativeImage> CreateEmpty(v8::Isolate* isolate);
static mate::Handle<NativeImage> Create(v8::Isolate* isolate,
const gfx::Image& image);
static mate::Handle<NativeImage> CreateFromPNG(v8::Isolate* isolate,
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,
const char* buffer,
size_t length);
static gin::Handle<NativeImage> CreateFromJPEG(v8::Isolate* isolate,
const char* buffer,
size_t length);
static mate::Handle<NativeImage> CreateFromJPEG(v8::Isolate* isolate,
const char* buffer,
size_t length);
static mate::Handle<NativeImage> CreateFromPath(v8::Isolate* isolate,
const base::FilePath& path);
static mate::Handle<NativeImage> CreateFromBitmap(
static gin::Handle<NativeImage> CreateFromPath(v8::Isolate* isolate,
const base::FilePath& path);
static gin::Handle<NativeImage> CreateFromBitmap(
gin_helper::ErrorThrower thrower,
v8::Local<v8::Value> buffer,
const gin_helper::Dictionary& options);
static mate::Handle<NativeImage> CreateFromBuffer(
static gin::Handle<NativeImage> CreateFromBuffer(
gin_helper::ErrorThrower thrower,
v8::Local<v8::Value> buffer,
gin::Arguments* args);
static mate::Handle<NativeImage> CreateFromDataURL(v8::Isolate* isolate,
const GURL& url);
static mate::Handle<NativeImage> CreateFromNamedImage(
gin::Arguments* args,
const std::string& name);
static gin::Handle<NativeImage> CreateFromDataURL(v8::Isolate* isolate,
const GURL& url);
static gin::Handle<NativeImage> CreateFromNamedImage(gin::Arguments* args,
const std::string& name);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);
@ -87,9 +86,9 @@ class NativeImage : public mate::Wrappable<NativeImage> {
v8::Local<v8::Value> ToBitmap(gin::Arguments* args);
v8::Local<v8::Value> GetBitmap(gin::Arguments* args);
v8::Local<v8::Value> GetNativeHandle(gin_helper::ErrorThrower thrower);
mate::Handle<NativeImage> Resize(v8::Isolate* isolate,
const base::DictionaryValue& options);
mate::Handle<NativeImage> Crop(v8::Isolate* isolate, const gfx::Rect& rect);
gin::Handle<NativeImage> Resize(v8::Isolate* isolate,
const base::DictionaryValue& options);
gin::Handle<NativeImage> Crop(v8::Isolate* isolate, const gfx::Rect& rect);
std::string ToDataURL(gin::Arguments* args);
bool IsEmpty();
gfx::Size GetSize();
@ -119,36 +118,14 @@ namespace gin {
// A custom converter that allows converting path to NativeImage.
template <>
struct Converter<mate::Handle<electron::api::NativeImage>> {
static v8::Local<v8::Value> ToV8(
v8::Isolate* isolate,
const mate::Handle<electron::api::NativeImage>& val);
struct Converter<electron::api::NativeImage*> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
electron::api::NativeImage* val);
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
mate::Handle<electron::api::NativeImage>* out);
electron::api::NativeImage** out);
};
} // namespace gin
namespace mate {
// Keep compatibility with native_mate code.
//
// TODO(zcbenz): Remove this after removing native_mate.
template <>
struct Converter<mate::Handle<electron::api::NativeImage>> {
static v8::Local<v8::Value> ToV8(
v8::Isolate* isolate,
const mate::Handle<electron::api::NativeImage>& val) {
return gin::ConvertToV8(isolate, val);
}
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
mate::Handle<electron::api::NativeImage>* out) {
return gin::ConvertFromV8(isolate, val, out);
}
};
} // namespace mate
#endif // SHELL_COMMON_API_ATOM_API_NATIVE_IMAGE_H_