chore: remove native_mate (Part 6) (#20391)
This commit is contained in:
parent
01ed55ff02
commit
4ac4b34ae9
6 changed files with 74 additions and 40 deletions
|
@ -9,8 +9,10 @@
|
||||||
#include "base/task/post_task.h"
|
#include "base/task/post_task.h"
|
||||||
#include "content/public/browser/browser_task_traits.h"
|
#include "content/public/browser/browser_task_traits.h"
|
||||||
#include "content/public/browser/browser_thread.h"
|
#include "content/public/browser/browser_thread.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "gin/handle.h"
|
||||||
#include "native_mate/object_template_builder_deprecated.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 "shell/common/node_includes.h"
|
||||||
#include "ui/gfx/color_utils.h"
|
#include "ui/gfx/color_utils.h"
|
||||||
#include "ui/native_theme/native_theme.h"
|
#include "ui/native_theme/native_theme.h"
|
||||||
|
@ -84,14 +86,14 @@ bool NativeTheme::ShouldUseInvertedColorScheme() {
|
||||||
// static
|
// static
|
||||||
v8::Local<v8::Value> NativeTheme::Create(v8::Isolate* isolate) {
|
v8::Local<v8::Value> NativeTheme::Create(v8::Isolate* isolate) {
|
||||||
ui::NativeTheme* theme = ui::NativeTheme::GetInstanceForNativeUi();
|
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
|
// static
|
||||||
void NativeTheme::BuildPrototype(v8::Isolate* isolate,
|
void NativeTheme::BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::FunctionTemplate> prototype) {
|
v8::Local<v8::FunctionTemplate> prototype) {
|
||||||
prototype->SetClassName(mate::StringToV8(isolate, "NativeTheme"));
|
prototype->SetClassName(gin::StringToV8(isolate, "NativeTheme"));
|
||||||
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||||
.SetProperty("shouldUseDarkColors", &NativeTheme::ShouldUseDarkColors)
|
.SetProperty("shouldUseDarkColors", &NativeTheme::ShouldUseDarkColors)
|
||||||
.SetProperty("themeSource", &NativeTheme::GetThemeSource,
|
.SetProperty("themeSource", &NativeTheme::GetThemeSource,
|
||||||
&NativeTheme::SetThemeSource)
|
&NativeTheme::SetThemeSource)
|
||||||
|
@ -112,7 +114,7 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||||
v8::Local<v8::Context> context,
|
v8::Local<v8::Context> context,
|
||||||
void* priv) {
|
void* priv) {
|
||||||
v8::Isolate* isolate = context->GetIsolate();
|
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::Create(isolate));
|
||||||
dict.Set("NativeTheme", electron::api::NativeTheme::GetConstructor(isolate)
|
dict.Set("NativeTheme", electron::api::NativeTheme::GetConstructor(isolate)
|
||||||
->GetFunction(context)
|
->GetFunction(context)
|
||||||
|
@ -121,19 +123,19 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace mate {
|
namespace gin {
|
||||||
|
|
||||||
v8::Local<v8::Value> Converter<ui::NativeTheme::ThemeSource>::ToV8(
|
v8::Local<v8::Value> Converter<ui::NativeTheme::ThemeSource>::ToV8(
|
||||||
v8::Isolate* isolate,
|
v8::Isolate* isolate,
|
||||||
const ui::NativeTheme::ThemeSource& val) {
|
const ui::NativeTheme::ThemeSource& val) {
|
||||||
switch (val) {
|
switch (val) {
|
||||||
case ui::NativeTheme::ThemeSource::kForcedDark:
|
case ui::NativeTheme::ThemeSource::kForcedDark:
|
||||||
return mate::ConvertToV8(isolate, "dark");
|
return ConvertToV8(isolate, "dark");
|
||||||
case ui::NativeTheme::ThemeSource::kForcedLight:
|
case ui::NativeTheme::ThemeSource::kForcedLight:
|
||||||
return mate::ConvertToV8(isolate, "light");
|
return ConvertToV8(isolate, "light");
|
||||||
case ui::NativeTheme::ThemeSource::kSystem:
|
case ui::NativeTheme::ThemeSource::kSystem:
|
||||||
default:
|
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,
|
v8::Local<v8::Value> val,
|
||||||
ui::NativeTheme::ThemeSource* out) {
|
ui::NativeTheme::ThemeSource* out) {
|
||||||
std::string theme_source;
|
std::string theme_source;
|
||||||
if (mate::ConvertFromV8(isolate, val, &theme_source)) {
|
if (ConvertFromV8(isolate, val, &theme_source)) {
|
||||||
if (theme_source == "dark") {
|
if (theme_source == "dark") {
|
||||||
*out = ui::NativeTheme::ThemeSource::kForcedDark;
|
*out = ui::NativeTheme::ThemeSource::kForcedDark;
|
||||||
} else if (theme_source == "light") {
|
} else if (theme_source == "light") {
|
||||||
|
@ -157,6 +159,6 @@ bool Converter<ui::NativeTheme::ThemeSource>::FromV8(
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace mate
|
} // namespace gin
|
||||||
|
|
||||||
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_common_native_theme, Initialize)
|
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_common_native_theme, Initialize)
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
#ifndef SHELL_BROWSER_API_ATOM_API_NATIVE_THEME_H_
|
#ifndef SHELL_BROWSER_API_ATOM_API_NATIVE_THEME_H_
|
||||||
#define 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 "shell/browser/api/event_emitter.h"
|
||||||
#include "ui/native_theme/native_theme.h"
|
#include "ui/native_theme/native_theme.h"
|
||||||
#include "ui/native_theme/native_theme_observer.h"
|
#include "ui/native_theme/native_theme_observer.h"
|
||||||
|
@ -50,7 +49,7 @@ class NativeTheme : public mate::EventEmitter<NativeTheme>,
|
||||||
|
|
||||||
} // namespace electron
|
} // namespace electron
|
||||||
|
|
||||||
namespace mate {
|
namespace gin {
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct Converter<ui::NativeTheme::ThemeSource> {
|
struct Converter<ui::NativeTheme::ThemeSource> {
|
||||||
|
@ -61,6 +60,20 @@ struct Converter<ui::NativeTheme::ThemeSource> {
|
||||||
ui::NativeTheme::ThemeSource* out);
|
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_
|
#endif // SHELL_BROWSER_API_ATOM_API_NATIVE_THEME_H_
|
||||||
|
|
|
@ -7,24 +7,23 @@
|
||||||
#include "base/guid.h"
|
#include "base/guid.h"
|
||||||
#include "base/strings/utf_string_conversions.h"
|
#include "base/strings/utf_string_conversions.h"
|
||||||
#include "native_mate/constructor.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/api/atom_api_menu.h"
|
||||||
#include "shell/browser/atom_browser_client.h"
|
#include "shell/browser/atom_browser_client.h"
|
||||||
#include "shell/browser/browser.h"
|
#include "shell/browser/browser.h"
|
||||||
#include "shell/common/native_mate_converters/gfx_converter.h"
|
#include "shell/common/gin_converters/image_converter.h"
|
||||||
#include "shell/common/native_mate_converters/image_converter.h"
|
#include "shell/common/gin_helper/dictionary.h"
|
||||||
#include "shell/common/native_mate_converters/string16_converter.h"
|
#include "shell/common/gin_helper/object_template_builder.h"
|
||||||
#include "shell/common/node_includes.h"
|
#include "shell/common/node_includes.h"
|
||||||
#include "url/gurl.h"
|
#include "url/gurl.h"
|
||||||
|
|
||||||
namespace mate {
|
namespace gin {
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct Converter<electron::NotificationAction> {
|
struct Converter<electron::NotificationAction> {
|
||||||
static bool FromV8(v8::Isolate* isolate,
|
static bool FromV8(v8::Isolate* isolate,
|
||||||
v8::Local<v8::Value> val,
|
v8::Local<v8::Value> val,
|
||||||
electron::NotificationAction* out) {
|
electron::NotificationAction* out) {
|
||||||
mate::Dictionary dict;
|
gin::Dictionary dict(isolate);
|
||||||
if (!ConvertFromV8(isolate, val, &dict))
|
if (!ConvertFromV8(isolate, val, &dict))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -37,27 +36,27 @@ struct Converter<electron::NotificationAction> {
|
||||||
|
|
||||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||||
electron::NotificationAction val) {
|
electron::NotificationAction val) {
|
||||||
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
gin::Dictionary dict = gin::Dictionary::CreateEmpty(isolate);
|
||||||
dict.Set("text", val.text);
|
dict.Set("text", val.text);
|
||||||
dict.Set("type", val.type);
|
dict.Set("type", val.type);
|
||||||
return dict.GetHandle();
|
return ConvertToV8(isolate, dict);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace mate
|
|
||||||
|
} // namespace gin
|
||||||
|
|
||||||
namespace electron {
|
namespace electron {
|
||||||
|
|
||||||
namespace api {
|
namespace api {
|
||||||
|
|
||||||
Notification::Notification(v8::Isolate* isolate,
|
Notification::Notification(v8::Local<v8::Object> wrapper,
|
||||||
v8::Local<v8::Object> wrapper,
|
gin::Arguments* args) {
|
||||||
mate::Arguments* args) {
|
InitWith(args->isolate(), wrapper);
|
||||||
InitWith(isolate, wrapper);
|
|
||||||
|
|
||||||
presenter_ = static_cast<AtomBrowserClient*>(AtomBrowserClient::Get())
|
presenter_ = static_cast<AtomBrowserClient*>(AtomBrowserClient::Get())
|
||||||
->GetNotificationPresenter();
|
->GetNotificationPresenter();
|
||||||
|
|
||||||
mate::Dictionary opts;
|
gin::Dictionary opts(nullptr);
|
||||||
if (args->GetNext(&opts)) {
|
if (args->GetNext(&opts)) {
|
||||||
opts.Get("title", &title_);
|
opts.Get("title", &title_);
|
||||||
opts.Get("subtitle", &subtitle_);
|
opts.Get("subtitle", &subtitle_);
|
||||||
|
@ -87,7 +86,8 @@ mate::WrappableBase* Notification::New(mate::Arguments* args) {
|
||||||
args->ThrowError("Cannot create Notification before app is ready");
|
args->ThrowError("Cannot create Notification before app is ready");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return new Notification(args->isolate(), args->GetThis(), args);
|
gin::Arguments gin_args(args->info());
|
||||||
|
return new Notification(args->GetThis(), &gin_args);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
|
@ -234,9 +234,9 @@ bool Notification::IsSupported() {
|
||||||
// static
|
// static
|
||||||
void Notification::BuildPrototype(v8::Isolate* isolate,
|
void Notification::BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::FunctionTemplate> prototype) {
|
v8::Local<v8::FunctionTemplate> prototype) {
|
||||||
prototype->SetClassName(mate::StringToV8(isolate, "Notification"));
|
prototype->SetClassName(gin::StringToV8(isolate, "Notification"));
|
||||||
gin_helper::Destroyable::MakeDestroyable(isolate, prototype);
|
gin_helper::Destroyable::MakeDestroyable(isolate, prototype);
|
||||||
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||||
.SetMethod("show", &Notification::Show)
|
.SetMethod("show", &Notification::Show)
|
||||||
.SetMethod("close", &Notification::Close)
|
.SetMethod("close", &Notification::Close)
|
||||||
.SetProperty("title", &Notification::GetTitle, &Notification::SetTitle)
|
.SetProperty("title", &Notification::GetTitle, &Notification::SetTitle)
|
||||||
|
@ -273,7 +273,7 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||||
Notification::SetConstructor(isolate,
|
Notification::SetConstructor(isolate,
|
||||||
base::BindRepeating(&Notification::New));
|
base::BindRepeating(&Notification::New));
|
||||||
|
|
||||||
mate::Dictionary dict(isolate, exports);
|
gin_helper::Dictionary dict(isolate, exports);
|
||||||
dict.Set("Notification", Notification::GetConstructor(isolate)
|
dict.Set("Notification", Notification::GetConstructor(isolate)
|
||||||
->GetFunction(context)
|
->GetFunction(context)
|
||||||
.ToLocalChecked());
|
.ToLocalChecked());
|
||||||
|
|
|
@ -10,13 +10,16 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "base/strings/utf_string_conversions.h"
|
#include "base/strings/utf_string_conversions.h"
|
||||||
#include "native_mate/handle.h"
|
|
||||||
#include "shell/browser/api/trackable_object.h"
|
#include "shell/browser/api/trackable_object.h"
|
||||||
#include "shell/browser/notifications/notification.h"
|
#include "shell/browser/notifications/notification.h"
|
||||||
#include "shell/browser/notifications/notification_delegate.h"
|
#include "shell/browser/notifications/notification_delegate.h"
|
||||||
#include "shell/browser/notifications/notification_presenter.h"
|
#include "shell/browser/notifications/notification_presenter.h"
|
||||||
#include "ui/gfx/image/image.h"
|
#include "ui/gfx/image/image.h"
|
||||||
|
|
||||||
|
namespace gin {
|
||||||
|
class Arguments;
|
||||||
|
}
|
||||||
|
|
||||||
namespace electron {
|
namespace electron {
|
||||||
|
|
||||||
namespace api {
|
namespace api {
|
||||||
|
@ -39,9 +42,7 @@ class Notification : public mate::TrackableObject<Notification>,
|
||||||
void NotificationClosed() override;
|
void NotificationClosed() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Notification(v8::Isolate* isolate,
|
Notification(v8::Local<v8::Object> wrapper, gin::Arguments* args);
|
||||||
v8::Local<v8::Object> wrapper,
|
|
||||||
mate::Arguments* args);
|
|
||||||
~Notification() override;
|
~Notification() override;
|
||||||
|
|
||||||
void Show();
|
void Show();
|
||||||
|
@ -97,4 +98,22 @@ class Notification : public mate::TrackableObject<Notification>,
|
||||||
|
|
||||||
} // namespace electron
|
} // 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_
|
#endif // SHELL_BROWSER_API_ATOM_API_NOTIFICATION_H_
|
||||||
|
|
|
@ -39,7 +39,7 @@ struct Converter<const char*> {
|
||||||
};
|
};
|
||||||
|
|
||||||
template <size_t n>
|
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) {
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, const char* val) {
|
||||||
return v8::String::NewFromUtf8(isolate, val, v8::NewStringType::kNormal,
|
return v8::String::NewFromUtf8(isolate, val, v8::NewStringType::kNormal,
|
||||||
n - 1)
|
n - 1)
|
||||||
|
|
|
@ -53,7 +53,7 @@ class ObjectTemplateBuilder {
|
||||||
const U& setter) {
|
const U& setter) {
|
||||||
return SetPropertyImpl(name,
|
return SetPropertyImpl(name,
|
||||||
CallbackTraits<T>::CreateTemplate(isolate_, getter),
|
CallbackTraits<T>::CreateTemplate(isolate_, getter),
|
||||||
CallbackTraits<T>::CreateTemplate(isolate_, setter));
|
CallbackTraits<U>::CreateTemplate(isolate_, setter));
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in a new issue