From 4ac4b34ae9f4399995f9ff351007393221807183 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 2 Oct 2019 09:30:55 +0900 Subject: [PATCH] chore: remove native_mate (Part 6) (#20391) --- shell/browser/api/atom_api_native_theme.cc | 26 +++++++------ shell/browser/api/atom_api_native_theme.h | 19 ++++++++-- shell/browser/api/atom_api_notification.cc | 38 +++++++++---------- shell/browser/api/atom_api_notification.h | 27 +++++++++++-- shell/common/gin_converters/std_converter.h | 2 +- .../gin_helper/object_template_builder.h | 2 +- 6 files changed, 74 insertions(+), 40 deletions(-) diff --git a/shell/browser/api/atom_api_native_theme.cc b/shell/browser/api/atom_api_native_theme.cc index bef3094860..114edcf25b 100644 --- a/shell/browser/api/atom_api_native_theme.cc +++ b/shell/browser/api/atom_api_native_theme.cc @@ -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 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 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 exports, v8::Local 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 exports, } // namespace -namespace mate { +namespace gin { v8::Local Converter::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::FromV8( v8::Local 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::FromV8( return false; } -} // namespace mate +} // namespace gin NODE_LINKED_MODULE_CONTEXT_AWARE(atom_common_native_theme, Initialize) diff --git a/shell/browser/api/atom_api_native_theme.h b/shell/browser/api/atom_api_native_theme.h index 3742e41b53..b5b41eb66d 100644 --- a/shell/browser/api/atom_api_native_theme.h +++ b/shell/browser/api/atom_api_native_theme.h @@ -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, } // namespace electron -namespace mate { +namespace gin { template <> struct Converter { @@ -61,6 +60,20 @@ struct Converter { ui::NativeTheme::ThemeSource* out); }; -} // namespace mate +// TODO(zcbenz): Remove this after converting NativeTheme to gin::Wrapper. +template <> +struct Converter { + static bool FromV8(v8::Isolate* isolate, + v8::Local val, + electron::api::NativeTheme** out) { + return mate::ConvertFromV8(isolate, val, out); + } + static v8::Local ToV8(v8::Isolate* isolate, + electron::api::NativeTheme* in) { + return mate::ConvertToV8(isolate, in); + } +}; + +} // namespace gin #endif // SHELL_BROWSER_API_ATOM_API_NATIVE_THEME_H_ diff --git a/shell/browser/api/atom_api_notification.cc b/shell/browser/api/atom_api_notification.cc index bc104d7112..f36f6640ef 100644 --- a/shell/browser/api/atom_api_notification.cc +++ b/shell/browser/api/atom_api_notification.cc @@ -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 { static bool FromV8(v8::Isolate* isolate, v8::Local val, electron::NotificationAction* out) { - mate::Dictionary dict; + gin::Dictionary dict(isolate); if (!ConvertFromV8(isolate, val, &dict)) return false; @@ -37,27 +36,27 @@ struct Converter { static v8::Local 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 wrapper, - mate::Arguments* args) { - InitWith(isolate, wrapper); +Notification::Notification(v8::Local wrapper, + gin::Arguments* args) { + InitWith(args->isolate(), wrapper); presenter_ = static_cast(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 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 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()); diff --git a/shell/browser/api/atom_api_notification.h b/shell/browser/api/atom_api_notification.h index ec43fb4326..8e77fc893b 100644 --- a/shell/browser/api/atom_api_notification.h +++ b/shell/browser/api/atom_api_notification.h @@ -10,13 +10,16 @@ #include #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, void NotificationClosed() override; protected: - Notification(v8::Isolate* isolate, - v8::Local wrapper, - mate::Arguments* args); + Notification(v8::Local wrapper, gin::Arguments* args); ~Notification() override; void Show(); @@ -97,4 +98,22 @@ class Notification : public mate::TrackableObject, } // namespace electron +namespace gin { + +// TODO(zcbenz): Remove this after converting Notification to gin::Wrapper. +template <> +struct Converter { + static bool FromV8(v8::Isolate* isolate, + v8::Local val, + electron::api::Notification** out) { + return mate::ConvertFromV8(isolate, val, out); + } + static v8::Local ToV8(v8::Isolate* isolate, + electron::api::Notification* in) { + return mate::ConvertToV8(isolate, in); + } +}; + +} // namespace gin + #endif // SHELL_BROWSER_API_ATOM_API_NOTIFICATION_H_ diff --git a/shell/common/gin_converters/std_converter.h b/shell/common/gin_converters/std_converter.h index 8c1efd273e..3e4ff39cf3 100644 --- a/shell/common/gin_converters/std_converter.h +++ b/shell/common/gin_converters/std_converter.h @@ -39,7 +39,7 @@ struct Converter { }; template -struct Converter { +struct Converter { static v8::Local ToV8(v8::Isolate* isolate, const char* val) { return v8::String::NewFromUtf8(isolate, val, v8::NewStringType::kNormal, n - 1) diff --git a/shell/common/gin_helper/object_template_builder.h b/shell/common/gin_helper/object_template_builder.h index 5b683464d4..4c782d3c3a 100644 --- a/shell/common/gin_helper/object_template_builder.h +++ b/shell/common/gin_helper/object_template_builder.h @@ -53,7 +53,7 @@ class ObjectTemplateBuilder { const U& setter) { return SetPropertyImpl(name, CallbackTraits::CreateTemplate(isolate_, getter), - CallbackTraits::CreateTemplate(isolate_, setter)); + CallbackTraits::CreateTemplate(isolate_, setter)); } private: