chore: remove native_mate (Part 9) (#20645)

* refactor: remove a few uses of native_mate/gfx_converter.h

* refactor: deprecate mate::EventEmitter

* refactor: add gin_helper::EventEmitter

* refactor: convert a few classes to use gin_helper::EventEmitter

* refactor: get rid of native_mate_converters/gfx_converter.h

* fix: follow native_mate on reporting errors

* fix: gin is weak at guessing parameter types

* fix: incorrect full class name

* fix: gin::Handle does not accept null
This commit is contained in:
Cheng Zhao 2019-10-21 16:05:40 +09:00 committed by GitHub
parent b155ebeeb3
commit eb0e55c514
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
38 changed files with 532 additions and 326 deletions

View file

@ -4,26 +4,26 @@
#include "shell/browser/api/atom_api_browser_view.h"
#include "native_mate/constructor.h"
#include "native_mate/dictionary.h"
#include "shell/browser/api/atom_api_web_contents.h"
#include "shell/browser/browser.h"
#include "shell/browser/native_browser_view.h"
#include "shell/common/color_util.h"
#include "shell/common/native_mate_converters/gfx_converter.h"
#include "shell/common/native_mate_converters/value_converter.h"
#include "shell/common/gin_converters/gfx_converter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/gin_helper/object_template_builder.h"
#include "shell/common/node_includes.h"
#include "shell/common/options_switches.h"
#include "ui/gfx/geometry/rect.h"
namespace mate {
namespace gin {
template <>
struct Converter<electron::AutoResizeFlags> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
electron::AutoResizeFlags* auto_resize_flags) {
mate::Dictionary params;
gin_helper::Dictionary params;
if (!ConvertFromV8(isolate, val, &params)) {
return false;
}
@ -51,20 +51,24 @@ struct Converter<electron::AutoResizeFlags> {
}
};
} // namespace mate
} // namespace gin
namespace electron {
namespace api {
BrowserView::BrowserView(gin::Arguments* args,
const mate::Dictionary& options) {
const gin_helper::Dictionary& options) {
v8::Isolate* isolate = args->isolate();
mate::Dictionary web_preferences = mate::Dictionary::CreateEmpty(isolate);
gin_helper::Dictionary web_preferences =
gin::Dictionary::CreateEmpty(isolate);
options.Get(options::kWebPreferences, &web_preferences);
web_preferences.Set("type", "browserView");
mate::Handle<class WebContents> web_contents =
WebContents::Create(isolate, web_preferences);
mate::Handle<class WebContents> web_contents = WebContents::Create(
isolate,
// TODO(zcbenz): No need to do convertion after converting constructor
// of WebContents to gin.
mate::Dictionary(isolate, web_preferences.GetHandle()));
web_contents_.Reset(isolate, web_contents.ToV8());
api_web_contents_ = web_contents.get();
@ -97,7 +101,7 @@ mate::WrappableBase* BrowserView::New(gin_helper::ErrorThrower thrower,
return nullptr;
}
mate::Dictionary options = mate::Dictionary::CreateEmpty(args->isolate());
gin::Dictionary options = gin::Dictionary::CreateEmpty(args->isolate());
args->GetNext(&options);
return new BrowserView(args, options);
@ -134,9 +138,9 @@ v8::Local<v8::Value> BrowserView::GetWebContents() {
// static
void BrowserView::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "BrowserView"));
prototype->SetClassName(gin::StringToV8(isolate, "BrowserView"));
gin_helper::Destroyable::MakeDestroyable(isolate, prototype);
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("setAutoResize", &BrowserView::SetAutoResize)
.SetMethod("setBounds", &BrowserView::SetBounds)
.SetMethod("getBounds", &BrowserView::GetBounds)
@ -160,14 +164,13 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Isolate* isolate = context->GetIsolate();
BrowserView::SetConstructor(isolate, base::BindRepeating(&BrowserView::New));
mate::Dictionary browser_view(isolate, BrowserView::GetConstructor(isolate)
->GetFunction(context)
.ToLocalChecked());
browser_view.SetMethod("fromId",
&mate::TrackableObject<BrowserView>::FromWeakMapID);
browser_view.SetMethod("getAllViews",
&mate::TrackableObject<BrowserView>::GetAll);
mate::Dictionary dict(isolate, exports);
gin_helper::Dictionary browser_view(isolate,
BrowserView::GetConstructor(isolate)
->GetFunction(context)
.ToLocalChecked());
browser_view.SetMethod("fromId", &BrowserView::FromWeakMapID);
browser_view.SetMethod("getAllViews", &BrowserView::GetAll);
gin_helper::Dictionary dict(isolate, exports);
dict.Set("BrowserView", browser_view);
}