From f1a0d5e811b0d9a2f119bb6665acd7f9a144c52b Mon Sep 17 00:00:00 2001 From: Jeremy Apthorp Date: Thu, 19 Mar 2020 14:33:45 -0700 Subject: [PATCH] refactor: ginify globalShortcut (#22755) --- .../api/electron_api_global_shortcut.cc | 23 +++++++++++-------- .../api/electron_api_global_shortcut.h | 11 +++++---- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/shell/browser/api/electron_api_global_shortcut.cc b/shell/browser/api/electron_api_global_shortcut.cc index 954066991eb2..f0f6622e6e2f 100644 --- a/shell/browser/api/electron_api_global_shortcut.cc +++ b/shell/browser/api/electron_api_global_shortcut.cc @@ -9,11 +9,11 @@ #include "base/stl_util.h" #include "base/strings/utf_string_conversions.h" +#include "gin/dictionary.h" +#include "gin/object_template_builder.h" #include "shell/browser/api/electron_api_system_preferences.h" #include "shell/common/gin_converters/accelerator_converter.h" #include "shell/common/gin_converters/callback_converter.h" -#include "shell/common/gin_helper/dictionary.h" -#include "shell/common/gin_helper/object_template_builder.h" #include "shell/common/node_includes.h" #if defined(OS_MACOSX) @@ -49,9 +49,9 @@ namespace electron { namespace api { -GlobalShortcut::GlobalShortcut(v8::Isolate* isolate) { - Init(isolate); -} +gin::WrapperInfo GlobalShortcut::kWrapperInfo = {gin::kEmbedderNativeGin}; + +GlobalShortcut::GlobalShortcut(v8::Isolate* isolate) {} GlobalShortcut::~GlobalShortcut() { UnregisterAll(); @@ -131,10 +131,9 @@ gin::Handle GlobalShortcut::Create(v8::Isolate* isolate) { } // static -void GlobalShortcut::BuildPrototype(v8::Isolate* isolate, - v8::Local prototype) { - prototype->SetClassName(gin::StringToV8(isolate, "GlobalShortcut")); - gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) +gin::ObjectTemplateBuilder GlobalShortcut::GetObjectTemplateBuilder( + v8::Isolate* isolate) { + return gin::Wrappable::GetObjectTemplateBuilder(isolate) .SetMethod("registerAll", &GlobalShortcut::RegisterAll) .SetMethod("register", &GlobalShortcut::Register) .SetMethod("isRegistered", &GlobalShortcut::IsRegistered) @@ -142,6 +141,10 @@ void GlobalShortcut::BuildPrototype(v8::Isolate* isolate, .SetMethod("unregisterAll", &GlobalShortcut::UnregisterAll); } +const char* GlobalShortcut::GetTypeName() { + return "GlobalShortcut"; +} + } // namespace api } // namespace electron @@ -153,7 +156,7 @@ void Initialize(v8::Local exports, v8::Local context, void* priv) { v8::Isolate* isolate = context->GetIsolate(); - gin_helper::Dictionary dict(isolate, exports); + gin::Dictionary dict(isolate, exports); dict.Set("globalShortcut", electron::api::GlobalShortcut::Create(isolate)); } diff --git a/shell/browser/api/electron_api_global_shortcut.h b/shell/browser/api/electron_api_global_shortcut.h index c1f9051b76e4..fea58d668ec1 100644 --- a/shell/browser/api/electron_api_global_shortcut.h +++ b/shell/browser/api/electron_api_global_shortcut.h @@ -12,7 +12,7 @@ #include "base/callback.h" #include "chrome/browser/extensions/global_shortcut_listener.h" #include "gin/handle.h" -#include "shell/common/gin_helper/trackable_object.h" +#include "gin/wrappable.h" #include "ui/base/accelerators/accelerator.h" namespace electron { @@ -20,12 +20,15 @@ namespace electron { namespace api { class GlobalShortcut : public extensions::GlobalShortcutListener::Observer, - public gin_helper::TrackableObject { + public gin::Wrappable { public: static gin::Handle Create(v8::Isolate* isolate); - static void BuildPrototype(v8::Isolate* isolate, - v8::Local prototype); + // gin::Wrappable + static gin::WrapperInfo kWrapperInfo; + gin::ObjectTemplateBuilder GetObjectTemplateBuilder( + v8::Isolate* isolate) override; + const char* GetTypeName() override; protected: explicit GlobalShortcut(v8::Isolate* isolate);