chore: remove native_mate (Part 6) (#20391)

This commit is contained in:
Cheng Zhao 2019-10-02 09:30:55 +09:00 коммит произвёл GitHub
Родитель 01ed55ff02
Коммит 4ac4b34ae9
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 74 добавлений и 40 удалений

Просмотреть файл

@ -9,8 +9,10 @@
#include "base/task/post_task.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "native_mate/dictionary.h"
#include "native_mate/object_template_builder_deprecated.h"
#include "gin/handle.h"
#include "shell/common/gin_converters/std_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 "ui/gfx/color_utils.h"
#include "ui/native_theme/native_theme.h"
@ -84,14 +86,14 @@ bool NativeTheme::ShouldUseInvertedColorScheme() {
// static
v8::Local<v8::Value> NativeTheme::Create(v8::Isolate* isolate) {
ui::NativeTheme* theme = ui::NativeTheme::GetInstanceForNativeUi();
return mate::CreateHandle(isolate, new NativeTheme(isolate, theme)).ToV8();
return gin::CreateHandle(isolate, new NativeTheme(isolate, theme)).ToV8();
}
// static
void NativeTheme::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "NativeTheme"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
prototype->SetClassName(gin::StringToV8(isolate, "NativeTheme"));
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetProperty("shouldUseDarkColors", &NativeTheme::ShouldUseDarkColors)
.SetProperty("themeSource", &NativeTheme::GetThemeSource,
&NativeTheme::SetThemeSource)
@ -112,7 +114,7 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Context> context,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
mate::Dictionary dict(isolate, exports);
gin::Dictionary dict(isolate, exports);
dict.Set("nativeTheme", electron::api::NativeTheme::Create(isolate));
dict.Set("NativeTheme", electron::api::NativeTheme::GetConstructor(isolate)
->GetFunction(context)
@ -121,19 +123,19 @@ void Initialize(v8::Local<v8::Object> exports,
} // namespace
namespace mate {
namespace gin {
v8::Local<v8::Value> Converter<ui::NativeTheme::ThemeSource>::ToV8(
v8::Isolate* isolate,
const ui::NativeTheme::ThemeSource& val) {
switch (val) {
case ui::NativeTheme::ThemeSource::kForcedDark:
return mate::ConvertToV8(isolate, "dark");
return ConvertToV8(isolate, "dark");
case ui::NativeTheme::ThemeSource::kForcedLight:
return mate::ConvertToV8(isolate, "light");
return ConvertToV8(isolate, "light");
case ui::NativeTheme::ThemeSource::kSystem:
default:
return mate::ConvertToV8(isolate, "system");
return ConvertToV8(isolate, "system");
}
}
@ -142,7 +144,7 @@ bool Converter<ui::NativeTheme::ThemeSource>::FromV8(
v8::Local<v8::Value> val,
ui::NativeTheme::ThemeSource* out) {
std::string theme_source;
if (mate::ConvertFromV8(isolate, val, &theme_source)) {
if (ConvertFromV8(isolate, val, &theme_source)) {
if (theme_source == "dark") {
*out = ui::NativeTheme::ThemeSource::kForcedDark;
} else if (theme_source == "light") {
@ -157,6 +159,6 @@ bool Converter<ui::NativeTheme::ThemeSource>::FromV8(
return false;
}
} // namespace mate
} // namespace gin
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_common_native_theme, Initialize)

Просмотреть файл

@ -5,7 +5,6 @@
#ifndef SHELL_BROWSER_API_ATOM_API_NATIVE_THEME_H_
#define SHELL_BROWSER_API_ATOM_API_NATIVE_THEME_H_
#include "native_mate/handle.h"
#include "shell/browser/api/event_emitter.h"
#include "ui/native_theme/native_theme.h"
#include "ui/native_theme/native_theme_observer.h"
@ -50,7 +49,7 @@ class NativeTheme : public mate::EventEmitter<NativeTheme>,
} // namespace electron
namespace mate {
namespace gin {
template <>
struct Converter<ui::NativeTheme::ThemeSource> {
@ -61,6 +60,20 @@ struct Converter<ui::NativeTheme::ThemeSource> {
ui::NativeTheme::ThemeSource* out);
};
} // namespace mate
// TODO(zcbenz): Remove this after converting NativeTheme to gin::Wrapper.
template <>
struct Converter<electron::api::NativeTheme*> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
electron::api::NativeTheme** out) {
return mate::ConvertFromV8(isolate, val, out);
}
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
electron::api::NativeTheme* in) {
return mate::ConvertToV8(isolate, in);
}
};
} // namespace gin
#endif // SHELL_BROWSER_API_ATOM_API_NATIVE_THEME_H_

Просмотреть файл

@ -7,24 +7,23 @@
#include "base/guid.h"
#include "base/strings/utf_string_conversions.h"
#include "native_mate/constructor.h"
#include "native_mate/dictionary.h"
#include "native_mate/object_template_builder_deprecated.h"
#include "shell/browser/api/atom_api_menu.h"
#include "shell/browser/atom_browser_client.h"
#include "shell/browser/browser.h"
#include "shell/common/native_mate_converters/gfx_converter.h"
#include "shell/common/native_mate_converters/image_converter.h"
#include "shell/common/native_mate_converters/string16_converter.h"
#include "shell/common/gin_converters/image_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 "url/gurl.h"
namespace mate {
namespace gin {
template <>
struct Converter<electron::NotificationAction> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
electron::NotificationAction* out) {
mate::Dictionary dict;
gin::Dictionary dict(isolate);
if (!ConvertFromV8(isolate, val, &dict))
return false;
@ -37,27 +36,27 @@ struct Converter<electron::NotificationAction> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
electron::NotificationAction val) {
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
gin::Dictionary dict = gin::Dictionary::CreateEmpty(isolate);
dict.Set("text", val.text);
dict.Set("type", val.type);
return dict.GetHandle();
return ConvertToV8(isolate, dict);
}
};
} // namespace mate
} // namespace gin
namespace electron {
namespace api {
Notification::Notification(v8::Isolate* isolate,
v8::Local<v8::Object> wrapper,
mate::Arguments* args) {
InitWith(isolate, wrapper);
Notification::Notification(v8::Local<v8::Object> wrapper,
gin::Arguments* args) {
InitWith(args->isolate(), wrapper);
presenter_ = static_cast<AtomBrowserClient*>(AtomBrowserClient::Get())
->GetNotificationPresenter();
mate::Dictionary opts;
gin::Dictionary opts(nullptr);
if (args->GetNext(&opts)) {
opts.Get("title", &title_);
opts.Get("subtitle", &subtitle_);
@ -87,7 +86,8 @@ mate::WrappableBase* Notification::New(mate::Arguments* args) {
args->ThrowError("Cannot create Notification before app is ready");
return nullptr;
}
return new Notification(args->isolate(), args->GetThis(), args);
gin::Arguments gin_args(args->info());
return new Notification(args->GetThis(), &gin_args);
}
// Getters
@ -234,9 +234,9 @@ bool Notification::IsSupported() {
// static
void Notification::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "Notification"));
prototype->SetClassName(gin::StringToV8(isolate, "Notification"));
gin_helper::Destroyable::MakeDestroyable(isolate, prototype);
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("show", &Notification::Show)
.SetMethod("close", &Notification::Close)
.SetProperty("title", &Notification::GetTitle, &Notification::SetTitle)
@ -273,7 +273,7 @@ void Initialize(v8::Local<v8::Object> exports,
Notification::SetConstructor(isolate,
base::BindRepeating(&Notification::New));
mate::Dictionary dict(isolate, exports);
gin_helper::Dictionary dict(isolate, exports);
dict.Set("Notification", Notification::GetConstructor(isolate)
->GetFunction(context)
.ToLocalChecked());

Просмотреть файл

@ -10,13 +10,16 @@
#include <vector>
#include "base/strings/utf_string_conversions.h"
#include "native_mate/handle.h"
#include "shell/browser/api/trackable_object.h"
#include "shell/browser/notifications/notification.h"
#include "shell/browser/notifications/notification_delegate.h"
#include "shell/browser/notifications/notification_presenter.h"
#include "ui/gfx/image/image.h"
namespace gin {
class Arguments;
}
namespace electron {
namespace api {
@ -39,9 +42,7 @@ class Notification : public mate::TrackableObject<Notification>,
void NotificationClosed() override;
protected:
Notification(v8::Isolate* isolate,
v8::Local<v8::Object> wrapper,
mate::Arguments* args);
Notification(v8::Local<v8::Object> wrapper, gin::Arguments* args);
~Notification() override;
void Show();
@ -97,4 +98,22 @@ class Notification : public mate::TrackableObject<Notification>,
} // namespace electron
namespace gin {
// TODO(zcbenz): Remove this after converting Notification to gin::Wrapper.
template <>
struct Converter<electron::api::Notification*> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
electron::api::Notification** out) {
return mate::ConvertFromV8(isolate, val, out);
}
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
electron::api::Notification* in) {
return mate::ConvertToV8(isolate, in);
}
};
} // namespace gin
#endif // SHELL_BROWSER_API_ATOM_API_NOTIFICATION_H_

Просмотреть файл

@ -39,7 +39,7 @@ struct Converter<const char*> {
};
template <size_t n>
struct Converter<const char[n]> {
struct Converter<char[n]> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, const char* val) {
return v8::String::NewFromUtf8(isolate, val, v8::NewStringType::kNormal,
n - 1)

Просмотреть файл

@ -53,7 +53,7 @@ class ObjectTemplateBuilder {
const U& setter) {
return SetPropertyImpl(name,
CallbackTraits<T>::CreateTemplate(isolate_, getter),
CallbackTraits<T>::CreateTemplate(isolate_, setter));
CallbackTraits<U>::CreateTemplate(isolate_, setter));
}
private: