Browse Source

chore: remove native_mate (Part 3) (#20131)

* use gin converter in atom_api_menu

* please only put necessary includes in header

Having include in header means they have dependency relationship,
putting arbitrary includes really really really really really makes
refacoring much harder.

* remove some simple uses of callback_converter_deprecated.h

* use gin callback converter in file_dialog code

* use gin in ErrorThrower

* use gin in atom_bundle_mover

* fix mistake in node stream

* deprecate native_mate version of event_emitter_caller

* use gin in node_bindings

* remove usages of native_mate event_emitter_caller.h except for EventEmitter

* fix compilation on Windows

* gin::Arguments behaves differently on GetNext

* just use StringToV8
Cheng Zhao 5 years ago
parent
commit
2c23e44ed9
61 changed files with 515 additions and 323 deletions
  1. 6 4
      filenames.gni
  2. 1 0
      native_mate/native_mate/arguments.h
  3. 3 5
      native_mate/native_mate/function_template.h
  4. 1 0
      patches/chromium/.patches
  5. 37 0
      patches/chromium/gin_dictionary_default_constructor.patch
  6. 1 0
      script/lint.js
  7. 13 10
      shell/browser/api/atom_api_app.cc
  8. 12 10
      shell/browser/api/atom_api_app.h
  9. 1 1
      shell/browser/api/atom_api_app_mac.mm
  10. 6 4
      shell/browser/api/atom_api_auto_updater.cc
  11. 0 1
      shell/browser/api/atom_api_browser_window.cc
  12. 0 1
      shell/browser/api/atom_api_cookies.cc
  13. 0 1
      shell/browser/api/atom_api_debugger.cc
  14. 3 2
      shell/browser/api/atom_api_dialog.cc
  15. 0 1
      shell/browser/api/atom_api_download_item.cc
  16. 0 1
      shell/browser/api/atom_api_in_app_purchase.cc
  17. 7 4
      shell/browser/api/atom_api_menu.cc
  18. 13 0
      shell/browser/api/atom_api_menu.h
  19. 0 1
      shell/browser/api/atom_api_net_log.cc
  20. 4 5
      shell/browser/api/atom_api_power_monitor.cc
  21. 4 3
      shell/browser/api/atom_api_screen.cc
  22. 1 0
      shell/browser/api/atom_api_session.cc
  23. 2 2
      shell/browser/api/atom_api_system_preferences.h
  24. 1 1
      shell/browser/api/atom_api_system_preferences_mac.mm
  25. 8 4
      shell/browser/api/atom_api_top_level_window.cc
  26. 0 1
      shell/browser/api/atom_api_web_contents.cc
  27. 18 0
      shell/browser/api/atom_api_web_contents.h
  28. 1 1
      shell/browser/api/event_emitter.h
  29. 5 3
      shell/browser/atom_download_manager_delegate.cc
  30. 1 1
      shell/browser/atom_download_manager_delegate.h
  31. 4 6
      shell/browser/net/node_stream_loader.cc
  32. 2 0
      shell/browser/printing/print_preview_message_handler.cc
  33. 9 13
      shell/browser/ui/cocoa/atom_bundle_mover.h
  34. 23 30
      shell/browser/ui/cocoa/atom_bundle_mover.mm
  35. 3 4
      shell/browser/ui/file_dialog.h
  36. 15 14
      shell/browser/ui/file_dialog_gtk.cc
  37. 13 12
      shell/browser/ui/file_dialog_mac.mm
  38. 15 14
      shell/browser/ui/file_dialog_win.cc
  39. 7 6
      shell/browser/web_dialog_helper.cc
  40. 5 5
      shell/common/api/atom_api_asar.cc
  41. 19 17
      shell/common/api/atom_api_shell.cc
  42. 38 0
      shell/common/api/event_emitter_caller_deprecated.cc
  43. 73 0
      shell/common/api/event_emitter_caller_deprecated.h
  44. 3 5
      shell/common/deprecate_util.cc
  45. 0 47
      shell/common/error_util.h
  46. 19 0
      shell/common/gin_converters/std_converter.h
  47. 3 3
      shell/common/gin_helper/callback.cc
  48. 1 11
      shell/common/gin_helper/callback.h
  49. 17 0
      shell/common/gin_helper/dictionary.h
  50. 14 13
      shell/common/gin_helper/error_thrower.cc
  51. 38 0
      shell/common/gin_helper/error_thrower.h
  52. 4 4
      shell/common/gin_helper/event_emitter_caller.cc
  53. 11 12
      shell/common/gin_helper/event_emitter_caller.h
  54. 3 3
      shell/common/gin_helper/function_template.h
  55. 6 6
      shell/common/node_bindings.cc
  56. 2 4
      shell/common/promise_util.h
  57. 0 3
      shell/renderer/api/atom_api_web_frame.cc
  58. 0 4
      shell/renderer/atom_render_frame_observer.cc
  59. 8 6
      shell/renderer/atom_renderer_client.cc
  60. 9 12
      shell/renderer/electron_api_service_impl.cc
  61. 2 2
      shell/renderer/web_worker_observer.cc

+ 6 - 4
filenames.gni

@@ -435,8 +435,8 @@ filenames = {
     "shell/common/api/electron_bindings.cc",
     "shell/common/api/electron_bindings.h",
     "shell/common/api/constructor.h",
-    "shell/common/api/event_emitter_caller.cc",
-    "shell/common/api/event_emitter_caller.h",
+    "shell/common/api/event_emitter_caller_deprecated.cc",
+    "shell/common/api/event_emitter_caller_deprecated.h",
     "shell/common/api/features.cc",
     "shell/common/api/locker.cc",
     "shell/common/api/locker.h",
@@ -494,6 +494,10 @@ filenames = {
     "shell/common/gin_helper/destroyable.cc",
     "shell/common/gin_helper/destroyable.h",
     "shell/common/gin_helper/dictionary.h",
+    "shell/common/gin_helper/error_thrower.cc",
+    "shell/common/gin_helper/error_thrower.h",
+    "shell/common/gin_helper/event_emitter_caller.cc",
+    "shell/common/gin_helper/event_emitter_caller.h",
     "shell/common/gin_helper/function_template.cc",
     "shell/common/gin_helper/function_template.h",
     "shell/common/heap_snapshot.cc",
@@ -503,8 +507,6 @@ filenames = {
     "shell/common/keyboard_util.h",
     "shell/common/deprecate_util.cc",
     "shell/common/deprecate_util.h",
-    "shell/common/error_util.cc",
-    "shell/common/error_util.h",
     "shell/common/mouse_util.cc",
     "shell/common/mouse_util.h",
     "shell/common/mac/main_application_bundle.h",

+ 1 - 0
native_mate/native_mate/arguments.h

@@ -97,6 +97,7 @@ class Arguments {
   v8::Local<v8::Value> ThrowTypeError(const std::string& message) const;
 
   v8::Isolate* isolate() const { return isolate_; }
+  const v8::FunctionCallbackInfo<v8::Value>& info() const { return *info_; }
 
  private:
   v8::Isolate* isolate_ = nullptr;

+ 3 - 5
native_mate/native_mate/function_template.h

@@ -5,13 +5,11 @@
 #ifndef NATIVE_MATE_NATIVE_MATE_FUNCTION_TEMPLATE_H_
 #define NATIVE_MATE_NATIVE_MATE_FUNCTION_TEMPLATE_H_
 
-#include "../shell/common/error_util.h"
 #include "../shell/common/gin_helper/destroyable.h"
+#include "../shell/common/gin_helper/error_thrower.h"
 #include "base/callback.h"
-#include "base/logging.h"
 #include "native_mate/arguments.h"
 #include "native_mate/wrappable_base.h"
-#include "v8/include/v8.h"
 
 // =============================== NOTICE ===============================
 // Do not add code here, native_mate is being removed. Any new code
@@ -122,8 +120,8 @@ inline bool GetNextArgument(Arguments* args,
 inline bool GetNextArgument(Arguments* args,
                             int create_flags,
                             bool is_first,
-                            electron::util::ErrorThrower* result) {
-  *result = electron::util::ErrorThrower(args->isolate());
+                            gin_helper::ErrorThrower* result) {
+  *result = gin_helper::ErrorThrower(args->isolate());
   return true;
 }
 

+ 1 - 0
patches/chromium/.patches

@@ -17,6 +17,7 @@ web_contents.patch
 webview_cross_drag.patch
 disable_user_gesture_requirement_for_beforeunload_dialogs.patch
 gin_enable_disable_v8_platform.patch
+gin_dictionary_default_constructor.patch
 blink-worker-enable-csp-in-file-scheme.patch
 disable-redraw-lock.patch
 v8_context_snapshot_generator.patch

+ 37 - 0
patches/chromium/gin_dictionary_default_constructor.patch

@@ -0,0 +1,37 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Cheng Zhao <[email protected]>
+Date: Thu, 4 Oct 2018 14:57:02 -0700
+Subject: gin_dictionary_default_constructor.patch
+
+Add default constructor for gin::Dictionary.
+
+This is required for automatically converting arguments for functions that
+take gin::Dictionary as parameter.
+
+diff --git a/gin/dictionary.cc b/gin/dictionary.cc
+index 95e00072700c..7643347890a5 100644
+--- a/gin/dictionary.cc
++++ b/gin/dictionary.cc
+@@ -6,6 +6,10 @@
+ 
+ namespace gin {
+ 
++Dictionary::Dictionary()
++    : isolate_(nullptr) {
++}
++
+ Dictionary::Dictionary(v8::Isolate* isolate)
+     : isolate_(isolate) {
+ }
+diff --git a/gin/dictionary.h b/gin/dictionary.h
+index 2645d328b4c1..43b227dd7e48 100644
+--- a/gin/dictionary.h
++++ b/gin/dictionary.h
+@@ -24,6 +24,7 @@ namespace gin {
+ //
+ class GIN_EXPORT Dictionary {
+  public:
++  Dictionary();
+   explicit Dictionary(v8::Isolate* isolate);
+   Dictionary(v8::Isolate* isolate, v8::Local<v8::Object> object);
+   Dictionary(const Dictionary& other);

+ 1 - 0
script/lint.js

@@ -15,6 +15,7 @@ const BLACKLIST = new Set([
   ['shell', 'browser', 'mac', 'atom_application_delegate.h'],
   ['shell', 'browser', 'resources', 'win', 'resource.h'],
   ['shell', 'browser', 'notifications', 'mac', 'notification_center_delegate.h'],
+  ['shell', 'browser', 'ui', 'cocoa', 'atom_bundle_mover.h'],
   ['shell', 'browser', 'ui', 'cocoa', 'atom_menu_controller.h'],
   ['shell', 'browser', 'ui', 'cocoa', 'atom_ns_window.h'],
   ['shell', 'browser', 'ui', 'cocoa', 'atom_ns_window_delegate.h'],

+ 13 - 10
shell/browser/api/atom_api_app.cc

@@ -26,6 +26,7 @@
 #include "content/public/browser/gpu_data_manager.h"
 #include "content/public/browser/render_frame_host.h"
 #include "content/public/common/content_switches.h"
+#include "gin/arguments.h"
 #include "media/audio/audio_manager.h"
 #include "native_mate/object_template_builder.h"
 #include "net/ssl/client_cert_identity.h"
@@ -846,7 +847,7 @@ void App::SetAppPath(const base::FilePath& app_path) {
 }
 
 #if !defined(OS_MACOSX)
-void App::SetAppLogsPath(util::ErrorThrower thrower,
+void App::SetAppLogsPath(gin_helper::ErrorThrower thrower,
                          base::Optional<base::FilePath> custom_path) {
   if (custom_path.has_value()) {
     if (!custom_path->IsAbsolute()) {
@@ -865,7 +866,7 @@ void App::SetAppLogsPath(util::ErrorThrower thrower,
 }
 #endif
 
-base::FilePath App::GetPath(util::ErrorThrower thrower,
+base::FilePath App::GetPath(gin_helper::ErrorThrower thrower,
                             const std::string& name) {
   bool succeed = false;
   base::FilePath path;
@@ -888,7 +889,7 @@ base::FilePath App::GetPath(util::ErrorThrower thrower,
   return path;
 }
 
-void App::SetPath(util::ErrorThrower thrower,
+void App::SetPath(gin_helper::ErrorThrower thrower,
                   const std::string& name,
                   const base::FilePath& path) {
   if (!path.IsAbsolute()) {
@@ -1031,7 +1032,7 @@ bool App::Relaunch(mate::Arguments* js_args) {
   return relauncher::RelaunchApp(argv);
 }
 
-void App::DisableHardwareAcceleration(util::ErrorThrower thrower) {
+void App::DisableHardwareAcceleration(gin_helper::ErrorThrower thrower) {
   if (Browser::Get()->is_ready()) {
     thrower.ThrowError(
         "app.disableHardwareAcceleration() can only be called "
@@ -1041,7 +1042,7 @@ void App::DisableHardwareAcceleration(util::ErrorThrower thrower) {
   content::GpuDataManager::GetInstance()->DisableHardwareAcceleration();
 }
 
-void App::DisableDomainBlockingFor3DAPIs(util::ErrorThrower thrower) {
+void App::DisableDomainBlockingFor3DAPIs(gin_helper::ErrorThrower thrower) {
   if (Browser::Get()->is_ready()) {
     thrower.ThrowError(
         "app.disableDomainBlockingFor3DAPIs() can only be called "
@@ -1057,7 +1058,7 @@ bool App::IsAccessibilitySupportEnabled() {
   return ax_state->IsAccessibleBrowser();
 }
 
-void App::SetAccessibilitySupportEnabled(util::ErrorThrower thrower,
+void App::SetAccessibilitySupportEnabled(gin_helper::ErrorThrower thrower,
                                          bool enabled) {
   if (!Browser::Get()->is_ready()) {
     thrower.ThrowError(
@@ -1314,7 +1315,7 @@ static void RemoveNoSandboxSwitch(base::CommandLine* command_line) {
   }
 }
 
-void App::EnableSandbox(util::ErrorThrower thrower) {
+void App::EnableSandbox(gin_helper::ErrorThrower thrower) {
   if (Browser::Get()->is_ready()) {
     thrower.ThrowError(
         "app.enableSandbox() can only be called "
@@ -1343,12 +1344,14 @@ bool App::CanBrowserClientUseCustomSiteInstance() {
 }
 
 #if defined(OS_MACOSX)
-bool App::MoveToApplicationsFolder(mate::Arguments* args) {
-  return ui::cocoa::AtomBundleMover::Move(args);
+bool App::MoveToApplicationsFolder(gin_helper::ErrorThrower thrower,
+                                   mate::Arguments* args) {
+  gin::Arguments gin_args(args->info());
+  return AtomBundleMover::Move(thrower, &gin_args);
 }
 
 bool App::IsInApplicationsFolder() {
-  return ui::cocoa::AtomBundleMover::IsCurrentAppInApplicationsFolder();
+  return AtomBundleMover::IsCurrentAppInApplicationsFolder();
 }
 
 int DockBounce(mate::Arguments* args) {

+ 12 - 10
shell/browser/api/atom_api_app.h

@@ -27,8 +27,7 @@
 #include "shell/browser/atom_browser_client.h"
 #include "shell/browser/browser.h"
 #include "shell/browser/browser_observer.h"
-#include "shell/common/error_util.h"
-#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
+#include "shell/common/gin_helper/error_thrower.h"
 #include "shell/common/promise_util.h"
 
 #if defined(USE_NSS_CERTS)
@@ -165,12 +164,13 @@ class App : public AtomBrowserClient::Delegate,
   void ChildProcessLaunched(int process_type, base::ProcessHandle handle);
   void ChildProcessDisconnected(base::ProcessId pid);
 
-  void SetAppLogsPath(util::ErrorThrower thrower,
+  void SetAppLogsPath(gin_helper::ErrorThrower thrower,
                       base::Optional<base::FilePath> custom_path);
 
   // Get/Set the pre-defined path in PathService.
-  base::FilePath GetPath(util::ErrorThrower thrower, const std::string& name);
-  void SetPath(util::ErrorThrower thrower,
+  base::FilePath GetPath(gin_helper::ErrorThrower thrower,
+                         const std::string& name);
+  void SetPath(gin_helper::ErrorThrower thrower,
                const std::string& name,
                const base::FilePath& path);
 
@@ -183,10 +183,11 @@ class App : public AtomBrowserClient::Delegate,
   bool RequestSingleInstanceLock();
   void ReleaseSingleInstanceLock();
   bool Relaunch(mate::Arguments* args);
-  void DisableHardwareAcceleration(util::ErrorThrower thrower);
-  void DisableDomainBlockingFor3DAPIs(util::ErrorThrower thrower);
+  void DisableHardwareAcceleration(gin_helper::ErrorThrower thrower);
+  void DisableDomainBlockingFor3DAPIs(gin_helper::ErrorThrower thrower);
   bool IsAccessibilitySupportEnabled();
-  void SetAccessibilitySupportEnabled(util::ErrorThrower thrower, bool enabled);
+  void SetAccessibilitySupportEnabled(gin_helper::ErrorThrower thrower,
+                                      bool enabled);
   Browser::LoginItemSettings GetLoginItemSettings(mate::Arguments* args);
 #if defined(USE_NSS_CERTS)
   void ImportCertificate(const base::DictionaryValue& options,
@@ -199,14 +200,15 @@ class App : public AtomBrowserClient::Delegate,
   v8::Local<v8::Value> GetGPUFeatureStatus(v8::Isolate* isolate);
   v8::Local<v8::Promise> GetGPUInfo(v8::Isolate* isolate,
                                     const std::string& info_type);
-  void EnableSandbox(util::ErrorThrower thrower);
+  void EnableSandbox(gin_helper::ErrorThrower thrower);
   void SetUserAgentFallback(const std::string& user_agent);
   std::string GetUserAgentFallback();
   void SetBrowserClientCanUseCustomSiteInstance(bool should_disable);
   bool CanBrowserClientUseCustomSiteInstance();
 
 #if defined(OS_MACOSX)
-  bool MoveToApplicationsFolder(mate::Arguments* args);
+  bool MoveToApplicationsFolder(gin_helper::ErrorThrower,
+                                mate::Arguments* args);
   bool IsInApplicationsFolder();
   v8::Local<v8::Value> GetDockAPI(v8::Isolate* isolate);
   v8::Global<v8::Value> dock_;

+ 1 - 1
shell/browser/api/atom_api_app_mac.mm

@@ -13,7 +13,7 @@ namespace electron {
 
 namespace api {
 
-void App::SetAppLogsPath(util::ErrorThrower thrower,
+void App::SetAppLogsPath(gin_helper::ErrorThrower thrower,
                          base::Optional<base::FilePath> custom_path) {
   if (custom_path.has_value()) {
     if (!custom_path->IsAbsolute()) {

+ 6 - 4
shell/browser/api/atom_api_auto_updater.cc

@@ -10,10 +10,12 @@
 #include "shell/browser/browser.h"
 #include "shell/browser/native_window.h"
 #include "shell/browser/window_list.h"
-#include "shell/common/api/event_emitter_caller.h"
-#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
+#include "shell/common/gin_helper/event_emitter_caller.h"
 #include "shell/common/node_includes.h"
 
+// TODO(zcbenz): Remove this after removing mate::ObjectTemplateBuilder.
+#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
+
 namespace mate {
 
 template <>
@@ -48,7 +50,7 @@ void AutoUpdater::OnError(const std::string& message) {
   v8::Locker locker(isolate());
   v8::HandleScope handle_scope(isolate());
   auto error = v8::Exception::Error(mate::StringToV8(isolate(), message));
-  mate::EmitEvent(
+  gin_helper::EmitEvent(
       isolate(), GetWrapper(), "error",
       error->ToObject(isolate()->GetCurrentContext()).ToLocalChecked(),
       // Message is also emitted to keep compatibility with old code.
@@ -76,7 +78,7 @@ void AutoUpdater::OnError(const std::string& message,
             mate::StringToV8(isolate(), domain))
       .Check();
 
-  mate::EmitEvent(isolate(), GetWrapper(), "error", errorObject, message);
+  gin_helper::EmitEvent(isolate(), GetWrapper(), "error", errorObject, message);
 }
 
 void AutoUpdater::OnCheckingForUpdate() {

+ 0 - 1
shell/browser/api/atom_api_browser_window.cc

@@ -20,7 +20,6 @@
 #include "shell/browser/window_list.h"
 #include "shell/common/api/constructor.h"
 #include "shell/common/color_util.h"
-#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
 #include "shell/common/native_mate_converters/value_converter.h"
 #include "shell/common/node_includes.h"
 #include "shell/common/options_switches.h"

+ 0 - 1
shell/browser/api/atom_api_cookies.cc

@@ -20,7 +20,6 @@
 #include "net/cookies/cookie_util.h"
 #include "shell/browser/atom_browser_context.h"
 #include "shell/browser/cookie_change_notifier.h"
-#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
 #include "shell/common/native_mate_converters/gurl_converter.h"
 #include "shell/common/native_mate_converters/value_converter.h"
 

+ 0 - 1
shell/browser/api/atom_api_debugger.cc

@@ -13,7 +13,6 @@
 #include "content/public/browser/devtools_agent_host.h"
 #include "content/public/browser/web_contents.h"
 #include "native_mate/dictionary.h"
-#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
 #include "shell/common/native_mate_converters/value_converter.h"
 #include "shell/common/node_includes.h"
 

+ 3 - 2
shell/browser/api/atom_api_dialog.cc

@@ -11,6 +11,7 @@
 #include "shell/browser/ui/message_box.h"
 #include "shell/common/gin_converters/callback_converter.h"
 #include "shell/common/gin_converters/file_dialog_converter.h"
+#include "shell/common/gin_converters/file_path_converter.h"
 #include "shell/common/gin_converters/message_box_converter.h"
 #include "shell/common/gin_converters/native_window_converter.h"
 #include "shell/common/gin_converters/net_converter.h"
@@ -59,7 +60,7 @@ void ShowOpenDialogSync(const file_dialog::DialogSettings& settings,
 v8::Local<v8::Promise> ShowOpenDialog(
     const file_dialog::DialogSettings& settings,
     gin::Arguments* args) {
-  electron::util::Promise<mate::Dictionary> promise(args->isolate());
+  electron::util::Promise<gin::Dictionary> promise(args->isolate());
   v8::Local<v8::Promise> handle = promise.GetHandle();
   file_dialog::ShowOpenDialog(settings, std::move(promise));
   return handle;
@@ -75,7 +76,7 @@ void ShowSaveDialogSync(const file_dialog::DialogSettings& settings,
 v8::Local<v8::Promise> ShowSaveDialog(
     const file_dialog::DialogSettings& settings,
     gin::Arguments* args) {
-  electron::util::Promise<mate::Dictionary> promise(args->isolate());
+  electron::util::Promise<gin::Dictionary> promise(args->isolate());
   v8::Local<v8::Promise> handle = promise.GetHandle();
 
   file_dialog::ShowSaveDialog(settings, std::move(promise));

+ 0 - 1
shell/browser/api/atom_api_download_item.cc

@@ -11,7 +11,6 @@
 #include "native_mate/dictionary.h"
 #include "net/base/filename_util.h"
 #include "shell/browser/atom_browser_main_parts.h"
-#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
 #include "shell/common/native_mate_converters/file_dialog_converter.h"
 #include "shell/common/native_mate_converters/file_path_converter.h"
 #include "shell/common/native_mate_converters/gurl_converter.h"

+ 0 - 1
shell/browser/api/atom_api_in_app_purchase.cc

@@ -9,7 +9,6 @@
 #include <vector>
 
 #include "native_mate/dictionary.h"
-#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
 #include "shell/common/node_includes.h"
 
 namespace mate {

+ 7 - 4
shell/browser/api/atom_api_menu.cc

@@ -6,16 +6,19 @@
 
 #include <map>
 
+#include "gin/dictionary.h"
 #include "native_mate/constructor.h"
-#include "native_mate/dictionary.h"
 #include "native_mate/object_template_builder.h"
 #include "shell/browser/native_window.h"
+#include "shell/common/gin_converters/callback_converter.h"
 #include "shell/common/native_mate_converters/accelerator_converter.h"
-#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
 #include "shell/common/native_mate_converters/image_converter.h"
 #include "shell/common/native_mate_converters/string16_converter.h"
 #include "shell/common/node_includes.h"
 
+// TODO(zcbenz): Remove this after removing mate::ObjectTemplateBuilder.
+#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
+
 namespace {
 // We need this map to keep references to currently opened menus.
 // Without this menus would be destroyed by js garbage collector
@@ -40,8 +43,8 @@ Menu::~Menu() {
 }
 
 void Menu::AfterInit(v8::Isolate* isolate) {
-  mate::Dictionary wrappable(isolate, GetWrapper());
-  mate::Dictionary delegate;
+  gin::Dictionary wrappable(isolate, GetWrapper());
+  gin::Dictionary delegate(nullptr);
   if (!wrappable.Get("delegate", &delegate))
     return;
 

+ 13 - 0
shell/browser/api/atom_api_menu.h

@@ -144,4 +144,17 @@ struct Converter<electron::AtomMenuModel*> {
 
 }  // namespace mate
 
+namespace gin {
+
+template <>
+struct Converter<electron::AtomMenuModel*> {
+  static bool FromV8(v8::Isolate* isolate,
+                     v8::Local<v8::Value> val,
+                     electron::AtomMenuModel** out) {
+    return mate::ConvertFromV8(isolate, val, out);
+  }
+};
+
+}  // namespace gin
+
 #endif  // SHELL_BROWSER_API_ATOM_API_MENU_H_

+ 0 - 1
shell/browser/api/atom_api_net_log.cc

@@ -16,7 +16,6 @@
 #include "native_mate/handle.h"
 #include "shell/browser/atom_browser_context.h"
 #include "shell/browser/net/system_network_context_manager.h"
-#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
 #include "shell/common/native_mate_converters/file_path_converter.h"
 #include "shell/common/node_includes.h"
 

+ 4 - 5
shell/browser/api/atom_api_power_monitor.cc

@@ -6,9 +6,9 @@
 
 #include "base/power_monitor/power_monitor.h"
 #include "base/power_monitor/power_monitor_device_source.h"
-#include "native_mate/dictionary.h"
+#include "gin/dictionary.h"
 #include "shell/browser/browser.h"
-#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
+#include "shell/common/gin_converters/callback_converter.h"
 #include "shell/common/node_includes.h"
 
 namespace mate {
@@ -138,9 +138,8 @@ void Initialize(v8::Local<v8::Object> exports,
                 v8::Local<v8::Context> context,
                 void* priv) {
   v8::Isolate* isolate = context->GetIsolate();
-  mate::Dictionary dict(isolate, exports);
-  dict.Set("createPowerMonitor",
-           base::BindRepeating(&PowerMonitor::Create, isolate));
+  gin::Dictionary dict(isolate, exports);
+  dict.Set("createPowerMonitor", base::BindRepeating(&PowerMonitor::Create));
   dict.Set("PowerMonitor", PowerMonitor::GetConstructor(isolate)
                                ->GetFunction(context)
                                .ToLocalChecked());

+ 4 - 3
shell/browser/api/atom_api_screen.cc

@@ -8,9 +8,10 @@
 #include <string>
 
 #include "base/bind.h"
-#include "native_mate/dictionary.h"
+#include "gin/dictionary.h"
 #include "native_mate/object_template_builder.h"
 #include "shell/browser/browser.h"
+#include "shell/common/gin_converters/callback_converter.h"
 #include "shell/common/native_mate_converters/gfx_converter.h"
 #include "shell/common/native_mate_converters/native_window_converter.h"
 #include "shell/common/node_includes.h"
@@ -182,8 +183,8 @@ void Initialize(v8::Local<v8::Object> exports,
                 v8::Local<v8::Context> context,
                 void* priv) {
   v8::Isolate* isolate = context->GetIsolate();
-  mate::Dictionary dict(isolate, exports);
-  dict.Set("createScreen", base::BindRepeating(&Screen::Create, isolate));
+  gin::Dictionary dict(isolate, exports);
+  dict.Set("createScreen", base::BindRepeating(&Screen::Create));
   dict.Set(
       "Screen",
       Screen::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());

+ 1 - 0
shell/browser/api/atom_api_session.cc

@@ -58,6 +58,7 @@
 #include "shell/common/native_mate_converters/file_path_converter.h"
 #include "shell/common/native_mate_converters/gurl_converter.h"
 #include "shell/common/native_mate_converters/net_converter.h"
+#include "shell/common/native_mate_converters/once_callback.h"
 #include "shell/common/native_mate_converters/value_converter.h"
 #include "shell/common/node_includes.h"
 #include "shell/common/options_switches.h"

+ 2 - 2
shell/browser/api/atom_api_system_preferences.h

@@ -12,7 +12,7 @@
 #include "base/values.h"
 #include "native_mate/handle.h"
 #include "shell/browser/api/event_emitter.h"
-#include "shell/common/error_util.h"
+#include "shell/common/gin_helper/error_thrower.h"
 #include "shell/common/promise_util.h"
 
 #if defined(OS_WIN)
@@ -96,7 +96,7 @@ class SystemPreferences : public mate::EventEmitter<SystemPreferences>
   void RemoveUserDefault(const std::string& name);
   bool IsSwipeTrackingFromScrollEventsEnabled();
 
-  std::string GetSystemColor(util::ErrorThrower thrower,
+  std::string GetSystemColor(gin_helper::ErrorThrower thrower,
                              const std::string& color);
 
   bool CanPromptTouchID();

+ 1 - 1
shell/browser/api/atom_api_system_preferences_mac.mm

@@ -405,7 +405,7 @@ std::string SystemPreferences::GetAccentColor() {
   return base::SysNSStringToUTF8([sysColor RGBAValue]);
 }
 
-std::string SystemPreferences::GetSystemColor(util::ErrorThrower thrower,
+std::string SystemPreferences::GetSystemColor(gin_helper::ErrorThrower thrower,
                                               const std::string& color) {
   NSColor* sysColor = nil;
   if (color == "blue") {

+ 8 - 4
shell/browser/api/atom_api_top_level_window.cc

@@ -8,7 +8,7 @@
 #include <vector>
 
 #include "electron/buildflags/buildflags.h"
-#include "gin/converter.h"
+#include "gin/dictionary.h"
 #include "native_mate/handle.h"
 #include "native_mate/persistent_dictionary.h"
 #include "shell/browser/api/atom_api_browser_view.h"
@@ -16,7 +16,8 @@
 #include "shell/browser/api/atom_api_view.h"
 #include "shell/browser/api/atom_api_web_contents.h"
 #include "shell/common/color_util.h"
-#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
+#include "shell/common/gin_converters/callback_converter.h"
+#include "shell/common/gin_converters/image_converter.h"
 #include "shell/common/native_mate_converters/file_path_converter.h"
 #include "shell/common/native_mate_converters/gfx_converter.h"
 #include "shell/common/native_mate_converters/image_converter.h"
@@ -35,6 +36,9 @@
 #include "ui/base/win/shell.h"
 #endif
 
+// TODO(zcbenz): Remove this after removing mate::ObjectTemplateBuilder.
+#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
+
 #if defined(OS_WIN)
 namespace mate {
 
@@ -43,8 +47,8 @@ struct Converter<electron::TaskbarHost::ThumbarButton> {
   static bool FromV8(v8::Isolate* isolate,
                      v8::Handle<v8::Value> val,
                      electron::TaskbarHost::ThumbarButton* out) {
-    mate::Dictionary dict;
-    if (!ConvertFromV8(isolate, val, &dict))
+    gin::Dictionary dict;
+    if (!gin::ConvertFromV8(isolate, val, &dict))
       return false;
     dict.Get("click", &(out->clicked_callback));
     dict.Get("tooltip", &(out->tooltip));

+ 0 - 1
shell/browser/api/atom_api_web_contents.cc

@@ -69,7 +69,6 @@
 #include "shell/browser/web_contents_zoom_controller.h"
 #include "shell/browser/web_view_guest_delegate.h"
 #include "shell/common/api/atom_api_native_image.h"
-#include "shell/common/api/event_emitter_caller.h"
 #include "shell/common/color_util.h"
 #include "shell/common/mouse_util.h"
 #include "shell/common/native_mate_converters/blink_converter.h"

+ 18 - 0
shell/browser/api/atom_api_web_contents.h

@@ -566,4 +566,22 @@ class WebContents : public mate::TrackableObject<WebContents>,
 
 }  // namespace electron
 
+namespace gin {
+
+// TODO(zcbenz): Remove this after converting WebContents to gin::Wrapper.
+template <>
+struct Converter<electron::api::WebContents*> {
+  static bool FromV8(v8::Isolate* isolate,
+                     v8::Local<v8::Value> val,
+                     electron::api::WebContents** out) {
+    return mate::ConvertFromV8(isolate, val, out);
+  }
+  static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
+                                   electron::api::WebContents* in) {
+    return mate::ConvertToV8(isolate, in);
+  }
+};
+
+}  // namespace gin
+
 #endif  // SHELL_BROWSER_API_ATOM_API_WEB_CONTENTS_H_

+ 1 - 1
shell/browser/api/event_emitter.h

@@ -12,7 +12,7 @@
 #include "content/public/browser/browser_thread.h"
 #include "electron/shell/common/api/api.mojom.h"
 #include "native_mate/wrappable.h"
-#include "shell/common/api/event_emitter_caller.h"
+#include "shell/common/api/event_emitter_caller_deprecated.h"
 
 namespace content {
 class RenderFrameHost;

+ 5 - 3
shell/browser/atom_download_manager_delegate.cc

@@ -17,13 +17,15 @@
 #include "content/public/browser/browser_thread.h"
 #include "content/public/browser/download_item_utils.h"
 #include "content/public/browser/download_manager.h"
+#include "gin/dictionary.h"
 #include "net/base/filename_util.h"
 #include "shell/browser/api/atom_api_download_item.h"
 #include "shell/browser/atom_browser_context.h"
 #include "shell/browser/native_window.h"
 #include "shell/browser/ui/file_dialog.h"
 #include "shell/browser/web_contents_preferences.h"
-#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
+#include "shell/common/gin_converters/callback_converter.h"
+#include "shell/common/gin_converters/file_path_converter.h"
 #include "shell/common/options_switches.h"
 
 namespace electron {
@@ -122,7 +124,7 @@ void AtomDownloadManagerDelegate::OnDownloadPathGenerated(
     settings.force_detached = offscreen;
 
     v8::Isolate* isolate = v8::Isolate::GetCurrent();
-    electron::util::Promise<mate::Dictionary> dialog_promise(isolate);
+    electron::util::Promise<gin::Dictionary> dialog_promise(isolate);
     auto dialog_callback =
         base::BindOnce(&AtomDownloadManagerDelegate::OnDownloadSaveDialogDone,
                        base::Unretained(this), download_id, callback);
@@ -139,7 +141,7 @@ void AtomDownloadManagerDelegate::OnDownloadPathGenerated(
 void AtomDownloadManagerDelegate::OnDownloadSaveDialogDone(
     uint32_t download_id,
     const content::DownloadTargetCallback& download_callback,
-    mate::Dictionary result) {
+    gin::Dictionary result) {
   DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
 
   auto* item = download_manager_->GetDownload(download_id);

+ 1 - 1
shell/browser/atom_download_manager_delegate.h

@@ -48,7 +48,7 @@ class AtomDownloadManagerDelegate : public content::DownloadManagerDelegate {
   void OnDownloadSaveDialogDone(
       uint32_t download_id,
       const content::DownloadTargetCallback& download_callback,
-      mate::Dictionary result);
+      gin::Dictionary result);
 
   content::DownloadManager* download_manager_;
   base::WeakPtrFactory<AtomDownloadManagerDelegate> weak_ptr_factory_;

+ 4 - 6
shell/browser/net/node_stream_loader.cc

@@ -7,9 +7,7 @@
 #include <utility>
 
 #include "mojo/public/cpp/system/string_data_source.h"
-#include "shell/common/api/event_emitter_caller.h"
-#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
-
+#include "shell/common/gin_converters/callback_converter.h"
 #include "shell/common/node_includes.h"
 
 namespace electron {
@@ -41,7 +39,7 @@ NodeStreamLoader::~NodeStreamLoader() {
 
   // Unsubscribe all handlers.
   for (const auto& it : handlers_) {
-    v8::Local<v8::Value> args[] = {mate::StringToV8(isolate_, it.first),
+    v8::Local<v8::Value> args[] = {gin::StringToV8(isolate_, it.first),
                                    it.second.Get(isolate_)};
     node::MakeCallback(isolate_, emitter_.Get(isolate_), "removeListener",
                        node::arraysize(args), args, {0, 0});
@@ -142,8 +140,8 @@ void NodeStreamLoader::On(const char* event, EventCallback callback) {
 
   // emitter.on(event, callback)
   v8::Local<v8::Value> args[] = {
-      mate::StringToV8(isolate_, event),
-      mate::CallbackToV8(isolate_, std::move(callback)),
+      gin::StringToV8(isolate_, event),
+      gin_helper::CallbackToV8Leaked(isolate_, std::move(callback)),
   };
   handlers_[event].Reset(isolate_, args[1]);
   node::MakeCallback(isolate_, emitter_.Get(isolate_), "on",

+ 2 - 0
shell/browser/printing/print_preview_message_handler.cc

@@ -23,6 +23,8 @@
 #include "content/public/browser/browser_thread.h"
 #include "content/public/browser/render_frame_host.h"
 #include "content/public/browser/web_contents.h"
+#include "shell/common/api/locker.h"
+
 #include "shell/common/node_includes.h"
 
 using content::BrowserThread;

+ 9 - 13
shell/browser/ui/cocoa/atom_bundle_mover.h

@@ -5,27 +5,27 @@
 #ifndef SHELL_BROWSER_UI_COCOA_ATOM_BUNDLE_MOVER_H_
 #define SHELL_BROWSER_UI_COCOA_ATOM_BUNDLE_MOVER_H_
 
-#include <string>
+#include "base/mac/foundation_util.h"
+#include "shell/common/gin_helper/error_thrower.h"
 
-#include "native_mate/persistent_dictionary.h"
+namespace gin {
+class Arguments;
+}
 
 namespace electron {
 
 // Possible bundle movement conflicts
 enum class BundlerMoverConflictType { EXISTS, EXISTS_AND_RUNNING };
 
-namespace ui {
-
-namespace cocoa {
-
 class AtomBundleMover {
  public:
-  static bool Move(mate::Arguments* args);
+  static bool Move(gin_helper::ErrorThrower thrower, gin::Arguments* args);
   static bool IsCurrentAppInApplicationsFolder();
 
  private:
-  static bool ShouldContinueMove(BundlerMoverConflictType type,
-                                 mate::Arguments* args);
+  static bool ShouldContinueMove(gin_helper::ErrorThrower thrower,
+                                 BundlerMoverConflictType type,
+                                 gin::Arguments* args);
   static bool IsInApplicationsFolder(NSString* bundlePath);
   static NSString* ContainingDiskImageDevice(NSString* bundlePath);
   static void Relaunch(NSString* destinationPath);
@@ -39,10 +39,6 @@ class AtomBundleMover {
   static bool Trash(NSString* path);
 };
 
-}  // namespace cocoa
-
-}  // namespace ui
-
 }  // namespace electron
 
 #endif  // SHELL_BROWSER_UI_COCOA_ATOM_BUNDLE_MOVER_H_

+ 23 - 30
shell/browser/ui/cocoa/atom_bundle_mover.mm

@@ -4,19 +4,17 @@
 
 #import "shell/browser/ui/cocoa/atom_bundle_mover.h"
 
-#include <string>
-
 #import <AppKit/AppKit.h>
-#import <Foundation/Foundation.h>
 #import <Security/Security.h>
 #import <dlfcn.h>
 #import <sys/mount.h>
 #import <sys/param.h>
 
-#import "shell/browser/browser.h"
-#include "shell/common/native_mate_converters/once_callback.h"
+#include "gin/dictionary.h"
+#include "shell/browser/browser.h"
+#include "shell/common/gin_converters/callback_converter.h"
 
-namespace mate {
+namespace gin {
 
 template <>
 struct Converter<electron::BundlerMoverConflictType> {
@@ -24,26 +22,23 @@ struct Converter<electron::BundlerMoverConflictType> {
                                    electron::BundlerMoverConflictType value) {
     switch (value) {
       case electron::BundlerMoverConflictType::EXISTS:
-        return mate::StringToV8(isolate, "exists");
+        return gin::StringToV8(isolate, "exists");
       case electron::BundlerMoverConflictType::EXISTS_AND_RUNNING:
-        return mate::StringToV8(isolate, "existsAndRunning");
+        return gin::StringToV8(isolate, "existsAndRunning");
       default:
-        return mate::StringToV8(isolate, "");
+        return gin::StringToV8(isolate, "");
     }
   }
 };
 
-}  // namespace mate
+}  // namespace gin
 
 namespace electron {
 
-namespace ui {
-
-namespace cocoa {
-
-bool AtomBundleMover::ShouldContinueMove(BundlerMoverConflictType type,
-                                         mate::Arguments* args) {
-  mate::Dictionary options;
+bool AtomBundleMover::ShouldContinueMove(gin_helper::ErrorThrower thrower,
+                                         BundlerMoverConflictType type,
+                                         gin::Arguments* args) {
+  gin::Dictionary options;
   bool hasOptions = args->GetNext(&options);
   base::OnceCallback<v8::Local<v8::Value>(BundlerMoverConflictType)>
       conflict_cb;
@@ -57,13 +52,14 @@ bool AtomBundleMover::ShouldContinueMove(BundlerMoverConflictType type,
       // we only want to throw an error if a user has returned a non-boolean
       // value; this allows for client-side error handling should something in
       // the handler throw
-      args->ThrowError("Invalid conflict handler return type.");
+      thrower.ThrowError("Invalid conflict handler return type.");
     }
   }
   return true;
 }
 
-bool AtomBundleMover::Move(mate::Arguments* args) {
+bool AtomBundleMover::Move(gin_helper::ErrorThrower thrower,
+                           gin::Arguments* args) {
   // Path of the current bundle
   NSString* bundlePath = [[NSBundle mainBundle] bundlePath];
 
@@ -103,10 +99,10 @@ bool AtomBundleMover::Move(mate::Arguments* args) {
                            &authorizationCanceled)) {
       if (authorizationCanceled) {
         // User rejected the authorization request
-        args->ThrowError("User rejected the authorization request");
+        thrower.ThrowError("User rejected the authorization request");
         return false;
       } else {
-        args->ThrowError(
+        thrower.ThrowError(
             "Failed to copy to applications directory even with authorization");
         return false;
       }
@@ -117,8 +113,8 @@ bool AtomBundleMover::Move(mate::Arguments* args) {
       // But first, make sure that it's not running
       if (IsApplicationAtPathRunning(destinationPath)) {
         // Check for callback handler and get user choice for open/quit
-        if (!ShouldContinueMove(BundlerMoverConflictType::EXISTS_AND_RUNNING,
-                                args))
+        if (!ShouldContinueMove(
+                thrower, BundlerMoverConflictType::EXISTS_AND_RUNNING, args))
           return false;
 
         // Unless explicitly denied, give running app focus and terminate self
@@ -131,20 +127,21 @@ bool AtomBundleMover::Move(mate::Arguments* args) {
         return true;
       } else {
         // Check callback handler and get user choice for app trashing
-        if (!ShouldContinueMove(BundlerMoverConflictType::EXISTS, args))
+        if (!ShouldContinueMove(thrower, BundlerMoverConflictType::EXISTS,
+                                args))
           return false;
 
         // Unless explicitly denied, attempt to trash old app
         if (!Trash([applicationsDirectory
                 stringByAppendingPathComponent:bundleName])) {
-          args->ThrowError("Failed to delete existing application");
+          thrower.ThrowError("Failed to delete existing application");
           return false;
         }
       }
     }
 
     if (!CopyBundle(bundlePath, destinationPath)) {
-      args->ThrowError(
+      thrower.ThrowError(
           "Failed to copy current bundle to the applications folder");
       return false;
     }
@@ -466,8 +463,4 @@ bool AtomBundleMover::DeleteOrTrash(NSString* path) {
   }
 }
 
-}  // namespace cocoa
-
-}  // namespace ui
-
 }  // namespace electron

+ 3 - 4
shell/browser/ui/file_dialog.h

@@ -10,8 +10,7 @@
 #include <vector>
 
 #include "base/files/file_path.h"
-#include "native_mate/dictionary.h"
-#include "shell/common/native_mate_converters/file_path_converter.h"
+#include "gin/dictionary.h"
 #include "shell/common/promise_util.h"
 
 namespace electron {
@@ -66,12 +65,12 @@ bool ShowOpenDialogSync(const DialogSettings& settings,
                         std::vector<base::FilePath>* paths);
 
 void ShowOpenDialog(const DialogSettings& settings,
-                    electron::util::Promise<mate::Dictionary> promise);
+                    electron::util::Promise<gin::Dictionary> promise);
 
 bool ShowSaveDialogSync(const DialogSettings& settings, base::FilePath* path);
 
 void ShowSaveDialog(const DialogSettings& settings,
-                    electron::util::Promise<mate::Dictionary> promise);
+                    electron::util::Promise<gin::Dictionary> promise);
 
 }  // namespace file_dialog
 

+ 15 - 14
shell/browser/ui/file_dialog_gtk.cc

@@ -11,6 +11,7 @@
 #include "chrome/browser/ui/libgtkui/gtk_util.h"
 #include "shell/browser/native_window_views.h"
 #include "shell/browser/unresponsive_suppressor.h"
+#include "shell/common/gin_converters/file_path_converter.h"
 #include "ui/base/glib/glib_signal.h"
 #include "ui/views/widget/desktop_aura/x11_desktop_handler.h"
 
@@ -137,15 +138,15 @@ class FileChooserDialog {
     gtk_window_present_with_time(GTK_WINDOW(dialog_), time);
   }
 
-  void RunSaveAsynchronous(electron::util::Promise<mate::Dictionary> promise) {
+  void RunSaveAsynchronous(electron::util::Promise<gin::Dictionary> promise) {
     save_promise_.reset(
-        new electron::util::Promise<mate::Dictionary>(std::move(promise)));
+        new electron::util::Promise<gin::Dictionary>(std::move(promise)));
     RunAsynchronous();
   }
 
-  void RunOpenAsynchronous(electron::util::Promise<mate::Dictionary> promise) {
+  void RunOpenAsynchronous(electron::util::Promise<gin::Dictionary> promise) {
     open_promise_.reset(
-        new electron::util::Promise<mate::Dictionary>(std::move(promise)));
+        new electron::util::Promise<gin::Dictionary>(std::move(promise)));
     RunAsynchronous();
   }
 
@@ -186,8 +187,8 @@ class FileChooserDialog {
   GtkWidget* preview_;
 
   Filters filters_;
-  std::unique_ptr<electron::util::Promise<mate::Dictionary>> save_promise_;
-  std::unique_ptr<electron::util::Promise<mate::Dictionary>> open_promise_;
+  std::unique_ptr<electron::util::Promise<gin::Dictionary>> save_promise_;
+  std::unique_ptr<electron::util::Promise<gin::Dictionary>> open_promise_;
 
   // Callback for when we update the preview for the selection.
   CHROMEG_CALLBACK_0(FileChooserDialog, void, OnUpdatePreview, GtkWidget*);
@@ -198,8 +199,8 @@ class FileChooserDialog {
 void FileChooserDialog::OnFileDialogResponse(GtkWidget* widget, int response) {
   gtk_widget_hide(dialog_);
   if (save_promise_) {
-    mate::Dictionary dict =
-        mate::Dictionary::CreateEmpty(save_promise_->isolate());
+    gin::Dictionary dict =
+        gin::Dictionary::CreateEmpty(save_promise_->isolate());
     if (response == GTK_RESPONSE_ACCEPT) {
       dict.Set("canceled", false);
       dict.Set("filePath", GetFileName());
@@ -207,10 +208,10 @@ void FileChooserDialog::OnFileDialogResponse(GtkWidget* widget, int response) {
       dict.Set("canceled", true);
       dict.Set("filePath", base::FilePath());
     }
-    save_promise_->Resolve(dict);
+    save_promise_->ResolveWithGin(dict);
   } else if (open_promise_) {
-    mate::Dictionary dict =
-        mate::Dictionary::CreateEmpty(open_promise_->isolate());
+    gin::Dictionary dict =
+        gin::Dictionary::CreateEmpty(open_promise_->isolate());
     if (response == GTK_RESPONSE_ACCEPT) {
       dict.Set("canceled", false);
       dict.Set("filePaths", GetFileNames());
@@ -218,7 +219,7 @@ void FileChooserDialog::OnFileDialogResponse(GtkWidget* widget, int response) {
       dict.Set("canceled", true);
       dict.Set("filePaths", std::vector<base::FilePath>());
     }
-    open_promise_->Resolve(dict);
+    open_promise_->ResolveWithGin(dict);
   }
   delete this;
 }
@@ -294,7 +295,7 @@ bool ShowOpenDialogSync(const DialogSettings& settings,
 }
 
 void ShowOpenDialog(const DialogSettings& settings,
-                    electron::util::Promise<mate::Dictionary> promise) {
+                    electron::util::Promise<gin::Dictionary> promise) {
   GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
   if (settings.properties & OPEN_DIALOG_OPEN_DIRECTORY)
     action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
@@ -317,7 +318,7 @@ bool ShowSaveDialogSync(const DialogSettings& settings, base::FilePath* path) {
 }
 
 void ShowSaveDialog(const DialogSettings& settings,
-                    electron::util::Promise<mate::Dictionary> promise) {
+                    electron::util::Promise<gin::Dictionary> promise) {
   FileChooserDialog* save_dialog =
       new FileChooserDialog(GTK_FILE_CHOOSER_ACTION_SAVE, settings);
   save_dialog->RunSaveAsynchronous(std::move(promise));

+ 13 - 12
shell/browser/ui/file_dialog_mac.mm

@@ -17,6 +17,7 @@
 #include "base/mac/scoped_cftyperef.h"
 #include "base/strings/sys_string_conversions.h"
 #include "shell/browser/native_window.h"
+#include "shell/common/gin_converters/file_path_converter.h"
 
 @interface PopUpButtonHandler : NSObject
 
@@ -300,15 +301,15 @@ bool ShowOpenDialogSync(const DialogSettings& settings,
 void OpenDialogCompletion(int chosen,
                           NSOpenPanel* dialog,
                           bool security_scoped_bookmarks,
-                          electron::util::Promise<mate::Dictionary> promise) {
-  mate::Dictionary dict = mate::Dictionary::CreateEmpty(promise.isolate());
+                          electron::util::Promise<gin::Dictionary> promise) {
+  gin::Dictionary dict = gin::Dictionary::CreateEmpty(promise.isolate());
   if (chosen == NSFileHandlingPanelCancelButton) {
     dict.Set("canceled", true);
     dict.Set("filePaths", std::vector<base::FilePath>());
 #if defined(MAS_BUILD)
     dict.Set("bookmarks", std::vector<std::string>());
 #endif
-    promise.Resolve(dict);
+    promise.ResolveWithGin(dict);
   } else {
     std::vector<base::FilePath> paths;
     dict.Set("canceled", false);
@@ -324,12 +325,12 @@ void OpenDialogCompletion(int chosen,
     ReadDialogPaths(dialog, &paths);
     dict.Set("filePaths", paths);
 #endif
-    promise.Resolve(dict);
+    promise.ResolveWithGin(dict);
   }
 }
 
 void ShowOpenDialog(const DialogSettings& settings,
-                    electron::util::Promise<mate::Dictionary> promise) {
+                    electron::util::Promise<gin::Dictionary> promise) {
   NSOpenPanel* dialog = [NSOpenPanel openPanel];
 
   SetupDialog(dialog, settings);
@@ -339,7 +340,7 @@ void ShowOpenDialog(const DialogSettings& settings,
   // and pass it to the completion handler.
   bool security_scoped_bookmarks = settings.security_scoped_bookmarks;
 
-  __block electron::util::Promise<mate::Dictionary> p = std::move(promise);
+  __block electron::util::Promise<gin::Dictionary> p = std::move(promise);
 
   if (!settings.parent_window || !settings.parent_window->GetNativeWindow() ||
       settings.force_detached) {
@@ -377,13 +378,13 @@ bool ShowSaveDialogSync(const DialogSettings& settings, base::FilePath* path) {
 void SaveDialogCompletion(int chosen,
                           NSSavePanel* dialog,
                           bool security_scoped_bookmarks,
-                          electron::util::Promise<mate::Dictionary> promise) {
-  mate::Dictionary dict = mate::Dictionary::CreateEmpty(promise.isolate());
+                          electron::util::Promise<gin::Dictionary> promise) {
+  gin::Dictionary dict = gin::Dictionary::CreateEmpty(promise.isolate());
   if (chosen == NSFileHandlingPanelCancelButton) {
     dict.Set("canceled", true);
     dict.Set("filePath", base::FilePath());
 #if defined(MAS_BUILD)
-    dict.Set("bookmark", "");
+    dict.Set("bookmark", base::StringPiece());
 #endif
   } else {
     std::string path = base::SysNSStringToUTF8([[dialog URL] path]);
@@ -397,11 +398,11 @@ void SaveDialogCompletion(int chosen,
     }
 #endif
   }
-  promise.Resolve(dict);
+  promise.ResolveWithGin(dict);
 }
 
 void ShowSaveDialog(const DialogSettings& settings,
-                    electron::util::Promise<mate::Dictionary> promise) {
+                    electron::util::Promise<gin::Dictionary> promise) {
   NSSavePanel* dialog = [NSSavePanel savePanel];
 
   SetupDialog(dialog, settings);
@@ -412,7 +413,7 @@ void ShowSaveDialog(const DialogSettings& settings,
   // and pass it to the completion handler.
   bool security_scoped_bookmarks = settings.security_scoped_bookmarks;
 
-  __block electron::util::Promise<mate::Dictionary> p = std::move(promise);
+  __block electron::util::Promise<gin::Dictionary> p = std::move(promise);
 
   if (!settings.parent_window || !settings.parent_window->GetNativeWindow() ||
       settings.force_detached) {

+ 15 - 14
shell/browser/ui/file_dialog_win.cc

@@ -21,6 +21,7 @@
 #include "base/win/registry.h"
 #include "shell/browser/native_window_views.h"
 #include "shell/browser/unresponsive_suppressor.h"
+#include "shell/common/gin_converters/file_path_converter.h"
 
 namespace file_dialog {
 
@@ -81,19 +82,19 @@ bool CreateDialogThread(RunState* run_state) {
   return true;
 }
 
-void OnDialogOpened(electron::util::Promise<mate::Dictionary> promise,
+void OnDialogOpened(electron::util::Promise<gin::Dictionary> promise,
                     bool canceled,
                     std::vector<base::FilePath> paths) {
-  mate::Dictionary dict = mate::Dictionary::CreateEmpty(promise.isolate());
+  gin::Dictionary dict = gin::Dictionary::CreateEmpty(promise.isolate());
   dict.Set("canceled", canceled);
   dict.Set("filePaths", paths);
-  promise.Resolve(dict);
+  promise.ResolveWithGin(dict);
 }
 
 void RunOpenDialogInNewThread(
     const RunState& run_state,
     const DialogSettings& settings,
-    electron::util::Promise<mate::Dictionary> promise) {
+    electron::util::Promise<gin::Dictionary> promise) {
   std::vector<base::FilePath> paths;
   bool result = ShowOpenDialogSync(settings, &paths);
   run_state.ui_task_runner->PostTask(
@@ -102,19 +103,19 @@ void RunOpenDialogInNewThread(
   run_state.ui_task_runner->DeleteSoon(FROM_HERE, run_state.dialog_thread);
 }
 
-void OnSaveDialogDone(electron::util::Promise<mate::Dictionary> promise,
+void OnSaveDialogDone(electron::util::Promise<gin::Dictionary> promise,
                       bool canceled,
                       const base::FilePath path) {
-  mate::Dictionary dict = mate::Dictionary::CreateEmpty(promise.isolate());
+  gin::Dictionary dict = gin::Dictionary::CreateEmpty(promise.isolate());
   dict.Set("canceled", canceled);
   dict.Set("filePath", path);
-  promise.Resolve(dict);
+  promise.ResolveWithGin(dict);
 }
 
 void RunSaveDialogInNewThread(
     const RunState& run_state,
     const DialogSettings& settings,
-    electron::util::Promise<mate::Dictionary> promise) {
+    electron::util::Promise<gin::Dictionary> promise) {
   base::FilePath path;
   bool result = ShowSaveDialogSync(settings, &path);
   run_state.ui_task_runner->PostTask(
@@ -276,13 +277,13 @@ bool ShowOpenDialogSync(const DialogSettings& settings,
 }
 
 void ShowOpenDialog(const DialogSettings& settings,
-                    electron::util::Promise<mate::Dictionary> promise) {
-  mate::Dictionary dict = mate::Dictionary::CreateEmpty(promise.isolate());
+                    electron::util::Promise<gin::Dictionary> promise) {
+  gin::Dictionary dict = gin::Dictionary::CreateEmpty(promise.isolate());
   RunState run_state;
   if (!CreateDialogThread(&run_state)) {
     dict.Set("canceled", true);
     dict.Set("filePaths", std::vector<base::FilePath>());
-    promise.Resolve(dict);
+    promise.ResolveWithGin(dict);
   } else {
     run_state.dialog_thread->task_runner()->PostTask(
         FROM_HERE, base::BindOnce(&RunOpenDialogInNewThread, run_state,
@@ -326,13 +327,13 @@ bool ShowSaveDialogSync(const DialogSettings& settings, base::FilePath* path) {
 }
 
 void ShowSaveDialog(const DialogSettings& settings,
-                    electron::util::Promise<mate::Dictionary> promise) {
+                    electron::util::Promise<gin::Dictionary> promise) {
   RunState run_state;
   if (!CreateDialogThread(&run_state)) {
-    mate::Dictionary dict = mate::Dictionary::CreateEmpty(promise.isolate());
+    gin::Dictionary dict = gin::Dictionary::CreateEmpty(promise.isolate());
     dict.Set("canceled", true);
     dict.Set("filePath", base::FilePath());
-    promise.Resolve(dict);
+    promise.ResolveWithGin(dict);
   } else {
     run_state.dialog_thread->task_runner()->PostTask(
         FROM_HERE, base::BindOnce(&RunSaveDialogInNewThread, run_state,

+ 7 - 6
shell/browser/web_dialog_helper.cc

@@ -20,13 +20,14 @@
 #include "content/public/browser/render_view_host.h"
 #include "content/public/browser/web_contents.h"
 #include "content/public/browser/web_contents_observer.h"
-#include "native_mate/dictionary.h"
+#include "gin/dictionary.h"
 #include "net/base/directory_lister.h"
 #include "net/base/mime_util.h"
 #include "shell/browser/atom_browser_context.h"
 #include "shell/browser/native_window.h"
 #include "shell/browser/ui/file_dialog.h"
-#include "shell/common/native_mate_converters/once_callback.h"
+#include "shell/common/gin_converters/callback_converter.h"
+#include "shell/common/gin_converters/file_path_converter.h"
 #include "ui/shell_dialogs/selected_file_info.h"
 
 using blink::mojom::FileChooserFileInfo;
@@ -54,7 +55,7 @@ class FileSelectHelper : public base::RefCounted<FileSelectHelper>,
 
   void ShowOpenDialog(const file_dialog::DialogSettings& settings) {
     v8::Isolate* isolate = v8::Isolate::GetCurrent();
-    electron::util::Promise<mate::Dictionary> promise(isolate);
+    electron::util::Promise<gin::Dictionary> promise(isolate);
 
     auto callback = base::BindOnce(&FileSelectHelper::OnOpenDialogDone, this);
     ignore_result(promise.Then(std::move(callback)));
@@ -64,7 +65,7 @@ class FileSelectHelper : public base::RefCounted<FileSelectHelper>,
 
   void ShowSaveDialog(const file_dialog::DialogSettings& settings) {
     v8::Isolate* isolate = v8::Isolate::GetCurrent();
-    electron::util::Promise<mate::Dictionary> promise(isolate);
+    electron::util::Promise<gin::Dictionary> promise(isolate);
 
     auto callback = base::BindOnce(&FileSelectHelper::OnSaveDialogDone, this);
     ignore_result(promise.Then(std::move(callback)));
@@ -115,7 +116,7 @@ class FileSelectHelper : public base::RefCounted<FileSelectHelper>,
     AddRef();
   }
 
-  void OnOpenDialogDone(mate::Dictionary result) {
+  void OnOpenDialogDone(gin::Dictionary result) {
     std::vector<FileChooserFileInfoPtr> file_info;
     bool canceled = true;
     result.Get("canceled", &canceled);
@@ -157,7 +158,7 @@ class FileSelectHelper : public base::RefCounted<FileSelectHelper>,
     }
   }
 
-  void OnSaveDialogDone(mate::Dictionary result) {
+  void OnSaveDialogDone(gin::Dictionary result) {
     std::vector<FileChooserFileInfoPtr> file_info;
     bool canceled = true;
     result.Get("canceled", &canceled);

+ 5 - 5
shell/common/api/atom_api_asar.cc

@@ -7,11 +7,11 @@
 #include <vector>
 
 #include "native_mate/arguments.h"
-#include "native_mate/dictionary.h"
 #include "native_mate/object_template_builder.h"
 #include "native_mate/wrappable.h"
 #include "shell/common/asar/archive.h"
-#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
+#include "shell/common/gin_converters/callback_converter.h"
+#include "shell/common/gin_helper/dictionary.h"
 #include "shell/common/native_mate_converters/file_path_converter.h"
 #include "shell/common/node_includes.h"
 #include "third_party/electron_node/src/node_native_module_env.h"
@@ -56,7 +56,7 @@ class Archive : public mate::Wrappable<Archive> {
     asar::Archive::FileInfo info;
     if (!archive_ || !archive_->GetFileInfo(path, &info))
       return v8::False(isolate);
-    mate::Dictionary dict(isolate, v8::Object::New(isolate));
+    gin_helper::Dictionary dict(isolate, v8::Object::New(isolate));
     dict.Set("size", info.size);
     dict.Set("unpacked", info.unpacked);
     dict.Set("offset", info.offset);
@@ -68,7 +68,7 @@ class Archive : public mate::Wrappable<Archive> {
     asar::Archive::Stats stats;
     if (!archive_ || !archive_->Stat(path, &stats))
       return v8::False(isolate);
-    mate::Dictionary dict(isolate, v8::Object::New(isolate));
+    gin_helper::Dictionary dict(isolate, v8::Object::New(isolate));
     dict.Set("size", stats.size);
     dict.Set("offset", stats.offset);
     dict.Set("isFile", stats.is_file);
@@ -131,7 +131,7 @@ void Initialize(v8::Local<v8::Object> exports,
                 v8::Local<v8::Value> unused,
                 v8::Local<v8::Context> context,
                 void* priv) {
-  mate::Dictionary dict(context->GetIsolate(), exports);
+  gin_helper::Dictionary dict(context->GetIsolate(), exports);
   dict.SetMethod("createArchive", &Archive::Create);
   dict.SetMethod("initAsarSupport", &InitAsarSupport);
 }

+ 19 - 17
shell/common/api/atom_api_shell.cc

@@ -4,9 +4,10 @@
 
 #include <string>
 
-#include "native_mate/dictionary.h"
-#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
-#include "shell/common/native_mate_converters/file_path_converter.h"
+#include "shell/common/gin_converters/callback_converter.h"
+#include "shell/common/gin_converters/file_path_converter.h"
+#include "shell/common/gin_helper/dictionary.h"
+#include "shell/common/gin_helper/error_thrower.h"
 #include "shell/common/native_mate_converters/gurl_converter.h"
 #include "shell/common/native_mate_converters/string16_converter.h"
 #include "shell/common/node_includes.h"
@@ -17,7 +18,7 @@
 #include "base/win/scoped_com_initializer.h"
 #include "base/win/shortcut.h"
 
-namespace mate {
+namespace gin {
 
 template <>
 struct Converter<base::win::ShortcutOperation> {
@@ -39,7 +40,7 @@ struct Converter<base::win::ShortcutOperation> {
   }
 };
 
-}  // namespace mate
+}  // namespace gin
 #endif
 
 namespace {
@@ -52,13 +53,13 @@ void OnOpenExternalFinished(electron::util::Promise<void*> promise,
     promise.RejectWithErrorMessage(error.c_str());
 }
 
-v8::Local<v8::Promise> OpenExternal(const GURL& url, mate::Arguments* args) {
+v8::Local<v8::Promise> OpenExternal(const GURL& url, gin::Arguments* args) {
   electron::util::Promise<void*> promise(args->isolate());
   v8::Local<v8::Promise> handle = promise.GetHandle();
 
   platform_util::OpenExternalOptions options;
   if (args->Length() >= 2) {
-    mate::Dictionary obj;
+    gin::Dictionary obj(nullptr);
     if (args->GetNext(&obj)) {
       obj.Get("activate", &options.activate);
       obj.Get("workingDirectory", &options.working_dir);
@@ -71,7 +72,7 @@ v8::Local<v8::Promise> OpenExternal(const GURL& url, mate::Arguments* args) {
   return handle;
 }
 
-bool MoveItemToTrash(mate::Arguments* args) {
+bool MoveItemToTrash(gin::Arguments* args) {
   base::FilePath full_path;
   args->GetNext(&full_path);
 
@@ -83,10 +84,11 @@ bool MoveItemToTrash(mate::Arguments* args) {
 
 #if defined(OS_WIN)
 bool WriteShortcutLink(const base::FilePath& shortcut_path,
-                       mate::Arguments* args) {
+                       gin::Arguments* args) {
   base::win::ShortcutOperation operation = base::win::SHORTCUT_CREATE_ALWAYS;
-  args->GetNext(&operation);
-  mate::Dictionary options = mate::Dictionary::CreateEmpty(args->isolate());
+  if (gin::ConvertFromV8(args->isolate(), args->PeekNext(), &operation))
+    args->Skip();
+  gin::Dictionary options = gin::Dictionary::CreateEmpty(args->isolate());
   if (!args->GetNext(&options)) {
     args->ThrowError();
     return false;
@@ -114,16 +116,16 @@ bool WriteShortcutLink(const base::FilePath& shortcut_path,
                                                operation);
 }
 
-v8::Local<v8::Value> ReadShortcutLink(mate::Arguments* args,
+v8::Local<v8::Value> ReadShortcutLink(gin_helper::ErrorThrower thrower,
                                       const base::FilePath& path) {
   using base::win::ShortcutProperties;
-  mate::Dictionary options = mate::Dictionary::CreateEmpty(args->isolate());
+  gin::Dictionary options = gin::Dictionary::CreateEmpty(thrower.isolate());
   base::win::ScopedCOMInitializer com_initializer;
   base::win::ShortcutProperties properties;
   if (!base::win::ResolveShortcutProperties(
           path, ShortcutProperties::PROPERTIES_ALL, &properties)) {
-    args->ThrowError("Failed to read shortcut link");
-    return v8::Null(args->isolate());
+    thrower.ThrowError("Failed to read shortcut link");
+    return v8::Null(thrower.isolate());
   }
   options.Set("target", properties.target);
   options.Set("cwd", properties.working_dir);
@@ -132,7 +134,7 @@ v8::Local<v8::Value> ReadShortcutLink(mate::Arguments* args,
   options.Set("icon", properties.icon);
   options.Set("iconIndex", properties.icon_index);
   options.Set("appUserModelId", properties.app_id);
-  return options.GetHandle();
+  return gin::ConvertToV8(thrower.isolate(), options);
 }
 #endif
 
@@ -140,7 +142,7 @@ void Initialize(v8::Local<v8::Object> exports,
                 v8::Local<v8::Value> unused,
                 v8::Local<v8::Context> context,
                 void* priv) {
-  mate::Dictionary dict(context->GetIsolate(), exports);
+  gin_helper::Dictionary dict(context->GetIsolate(), exports);
   dict.SetMethod("showItemInFolder", &platform_util::ShowItemInFolder);
   dict.SetMethod("openItem", &platform_util::OpenItem);
   dict.SetMethod("openExternal", &OpenExternal);

+ 38 - 0
shell/common/api/event_emitter_caller_deprecated.cc

@@ -0,0 +1,38 @@
+// Copyright (c) 2015 GitHub, Inc.
+// Use of this source code is governed by the MIT license that can be
+// found in the LICENSE file.
+
+#include "shell/common/api/event_emitter_caller_deprecated.h"
+
+#include "shell/common/api/locker.h"
+#include "shell/common/node_includes.h"
+
+namespace mate {
+
+namespace internal {
+
+v8::Local<v8::Value> CallMethodWithArgs(v8::Isolate* isolate,
+                                        v8::Local<v8::Object> obj,
+                                        const char* method,
+                                        ValueVector* args) {
+  // Perform microtask checkpoint after running JavaScript.
+  v8::MicrotasksScope script_scope(isolate,
+                                   v8::MicrotasksScope::kRunMicrotasks);
+  // Use node::MakeCallback to call the callback, and it will also run pending
+  // tasks in Node.js.
+  v8::MaybeLocal<v8::Value> ret = node::MakeCallback(
+      isolate, obj, method, args->size(), &args->front(), {0, 0});
+  // If the JS function throws an exception (doesn't return a value) the result
+  // of MakeCallback will be empty and therefore ToLocal will be false, in this
+  // case we need to return "false" as that indicates that the event emitter did
+  // not handle the event
+  v8::Local<v8::Value> localRet;
+  if (ret.ToLocal(&localRet)) {
+    return localRet;
+  }
+  return v8::Boolean::New(isolate, false);
+}
+
+}  // namespace internal
+
+}  // namespace mate

+ 73 - 0
shell/common/api/event_emitter_caller_deprecated.h

@@ -0,0 +1,73 @@
+// Copyright (c) 2015 GitHub, Inc.
+// Use of this source code is governed by the MIT license that can be
+// found in the LICENSE file.
+
+#ifndef SHELL_COMMON_API_EVENT_EMITTER_CALLER_DEPRECATED_H_
+#define SHELL_COMMON_API_EVENT_EMITTER_CALLER_DEPRECATED_H_
+
+// =============================== NOTICE ===============================
+// Do not add code here, native_mate is being removed. Any new code
+// should use gin_helper version instead.
+
+#include <utility>
+#include <vector>
+
+#include "native_mate/converter.h"
+#include "shell/common/native_mate_converters/string16_converter.h"
+
+namespace mate {
+
+namespace internal {
+
+using ValueVector = std::vector<v8::Local<v8::Value>>;
+
+v8::Local<v8::Value> CallMethodWithArgs(v8::Isolate* isolate,
+                                        v8::Local<v8::Object> obj,
+                                        const char* method,
+                                        ValueVector* args);
+
+}  // namespace internal
+
+// obj.emit.apply(obj, name, args...);
+// The caller is responsible of allocating a HandleScope.
+template <typename StringType>
+v8::Local<v8::Value> EmitEvent(v8::Isolate* isolate,
+                               v8::Local<v8::Object> obj,
+                               const StringType& name,
+                               const internal::ValueVector& args) {
+  internal::ValueVector concatenated_args = {StringToV8(isolate, name)};
+  concatenated_args.reserve(1 + args.size());
+  concatenated_args.insert(concatenated_args.end(), args.begin(), args.end());
+  return internal::CallMethodWithArgs(isolate, obj, "emit", &concatenated_args);
+}
+
+// obj.emit(name, args...);
+// The caller is responsible of allocating a HandleScope.
+template <typename StringType, typename... Args>
+v8::Local<v8::Value> EmitEvent(v8::Isolate* isolate,
+                               v8::Local<v8::Object> obj,
+                               const StringType& name,
+                               Args&&... args) {
+  internal::ValueVector converted_args = {
+      StringToV8(isolate, name),
+      ConvertToV8(isolate, std::forward<Args>(args))...,
+  };
+  return internal::CallMethodWithArgs(isolate, obj, "emit", &converted_args);
+}
+
+// obj.custom_emit(args...)
+template <typename... Args>
+v8::Local<v8::Value> CustomEmit(v8::Isolate* isolate,
+                                v8::Local<v8::Object> object,
+                                const char* custom_emit,
+                                Args&&... args) {
+  internal::ValueVector converted_args = {
+      ConvertToV8(isolate, std::forward<Args>(args))...,
+  };
+  return internal::CallMethodWithArgs(isolate, object, custom_emit,
+                                      &converted_args);
+}
+
+}  // namespace mate
+
+#endif  // SHELL_COMMON_API_EVENT_EMITTER_CALLER_DEPRECATED_H_

+ 3 - 5
shell/common/deprecate_util.cc

@@ -4,17 +4,15 @@
 
 #include "shell/common/deprecate_util.h"
 
-#include "base/callback.h"
-#include "native_mate/converter.h"
-#include "native_mate/dictionary.h"
-#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
+#include "gin/dictionary.h"
+#include "shell/common/gin_converters/callback_converter.h"
 
 namespace electron {
 
 void EmitDeprecationWarning(node::Environment* env,
                             const std::string& warning_msg,
                             const std::string& warning_type) {
-  mate::Dictionary process(env->isolate(), env->process_object());
+  gin::Dictionary process(env->isolate(), env->process_object());
 
   base::RepeatingCallback<void(base::StringPiece, base::StringPiece,
                                base::StringPiece)>

+ 0 - 47
shell/common/error_util.h

@@ -1,47 +0,0 @@
-// Copyright (c) 2019 GitHub, Inc.
-// Use of this source code is governed by the MIT license that can be
-// found in the LICENSE file.
-
-#ifndef SHELL_COMMON_ERROR_UTIL_H_
-#define SHELL_COMMON_ERROR_UTIL_H_
-
-#include <string>
-
-#include "native_mate/converter.h"
-
-namespace electron {
-
-namespace util {
-
-class ErrorThrower {
- public:
-  explicit ErrorThrower(v8::Isolate* isolate);
-  ErrorThrower();
-
-  ~ErrorThrower();
-
-  void ThrowError(const std::string& err_msg);
-  void ThrowTypeError(const std::string& err_msg);
-  void ThrowRangeError(const std::string& err_msg);
-  void ThrowReferenceError(const std::string& err_msg);
-  void ThrowSyntaxError(const std::string& err_msg);
-
- private:
-  v8::Isolate* isolate() const { return isolate_; }
-
-  using ErrorGenerator =
-      v8::Local<v8::Value> (*)(v8::Local<v8::String> err_msg);
-  void Throw(ErrorGenerator gen, const std::string& err_msg) {
-    v8::Local<v8::Value> exception = gen(mate::StringToV8(isolate_, err_msg));
-    if (!isolate_->IsExecutionTerminating())
-      isolate_->ThrowException(exception);
-  }
-
-  v8::Isolate* isolate_;
-};
-
-}  // namespace util
-
-}  // namespace electron
-
-#endif  // SHELL_COMMON_ERROR_UTIL_H_

+ 19 - 0
shell/common/gin_converters/std_converter.h

@@ -6,11 +6,30 @@
 #define SHELL_COMMON_GIN_CONVERTERS_STD_CONVERTER_H_
 
 #include <set>
+#include <utility>
 
 #include "gin/converter.h"
 
 namespace gin {
 
+// Make it possible to convert move-only types.
+template <typename T>
+v8::Local<v8::Value> ConvertToV8(v8::Isolate* isolate, T&& input) {
+  return Converter<typename std::remove_reference<T>::type>::ToV8(
+      isolate, std::move(input));
+}
+
+#if !defined(OS_LINUX) && !defined(OS_FREEBSD)
+template <>
+struct Converter<unsigned long> {  // NOLINT(runtime/int)
+  static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
+                                   unsigned long val);  // NOLINT(runtime/int)
+  static bool FromV8(v8::Isolate* isolate,
+                     v8::Local<v8::Value> val,
+                     unsigned long* out);  // NOLINT(runtime/int)
+};
+#endif
+
 template <>
 struct Converter<v8::Local<v8::Array>> {
   static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,

+ 3 - 3
shell/common/gin_helper/callback.cc

@@ -41,11 +41,11 @@ void CallTranslater(v8::Local<v8::External> external,
   v8::Isolate* isolate = args->isolate();
   auto context = isolate->GetCurrentContext();
   bool one_time =
-      state->Has(context, mate::StringToSymbol(isolate, "oneTime")).ToChecked();
+      state->Has(context, gin::StringToSymbol(isolate, "oneTime")).ToChecked();
 
   // Check if the callback has already been called.
   if (one_time) {
-    auto called_symbol = mate::StringToSymbol(isolate, "called");
+    auto called_symbol = gin::StringToSymbol(isolate, "called");
     if (state->Has(context, called_symbol).ToChecked()) {
       args->ThrowTypeError("callback can only be called for once");
       return;
@@ -145,7 +145,7 @@ v8::Local<v8::Value> BindFunctionWith(v8::Isolate* isolate,
                                       v8::Local<v8::Value> arg1,
                                       v8::Local<v8::Value> arg2) {
   v8::MaybeLocal<v8::Value> bind =
-      func->Get(context, mate::StringToV8(isolate, "bind"));
+      func->Get(context, gin::StringToV8(isolate, "bind"));
   CHECK(!bind.IsEmpty());
   v8::Local<v8::Function> bind_func =
       v8::Local<v8::Function>::Cast(bind.ToLocalChecked());

+ 1 - 11
shell/common/gin_helper/callback.h

@@ -10,21 +10,11 @@
 
 #include "base/bind.h"
 #include "shell/common/api/locker.h"
+#include "shell/common/gin_converters/std_converter.h"
 #include "shell/common/gin_helper/function_template.h"
 
 // Implements safe convertions between JS functions and base::Callback.
 
-namespace gin {
-
-// Make it possible to convert move-only types.
-template <typename T>
-v8::Local<v8::Value> ConvertToV8(v8::Isolate* isolate, T&& input) {
-  return Converter<typename std::remove_reference<T>::type>::ToV8(
-      isolate, std::move(input));
-}
-
-}  // namespace gin
-
 namespace gin_helper {
 
 template <typename T>

+ 17 - 0
shell/common/gin_helper/dictionary.h

@@ -69,6 +69,23 @@ class Dictionary : public gin::Dictionary {
         .ToChecked();
   }
 
+  template <typename T>
+  bool SetReadOnly(base::StringPiece key, const T& val) {
+    v8::Local<v8::Value> v8_value;
+    if (!gin::TryConvertToV8(isolate(), val, &v8_value))
+      return false;
+    v8::Maybe<bool> result = GetHandle()->DefineOwnProperty(
+        isolate()->GetCurrentContext(), gin::StringToV8(isolate(), key),
+        v8_value, v8::ReadOnly);
+    return !result.IsNothing() && result.FromJust();
+  }
+
+  bool Delete(base::StringPiece key) {
+    v8::Maybe<bool> result = GetHandle()->Delete(
+        isolate()->GetCurrentContext(), gin::StringToV8(isolate(), key));
+    return !result.IsNothing() && result.FromJust();
+  }
+
   v8::Local<v8::Object> GetHandle() const {
     return gin::ConvertToV8(isolate(),
                             *static_cast<const gin::Dictionary*>(this))

+ 14 - 13
shell/common/error_util.cc → shell/common/gin_helper/error_thrower.cc

@@ -2,14 +2,11 @@
 // Use of this source code is governed by the MIT license that can be
 // found in the LICENSE file.
 
-#include <string>
+#include "shell/common/gin_helper/error_thrower.h"
 
-#include "native_mate/converter.h"
-#include "shell/common/error_util.h"
+#include "gin/converter.h"
 
-namespace electron {
-
-namespace util {
+namespace gin_helper {
 
 ErrorThrower::ErrorThrower(v8::Isolate* isolate) : isolate_(isolate) {}
 
@@ -20,26 +17,30 @@ ErrorThrower::ErrorThrower() : isolate_(v8::Isolate::GetCurrent()) {}
 
 ErrorThrower::~ErrorThrower() = default;
 
-void ErrorThrower::ThrowError(const std::string& err_msg) {
+void ErrorThrower::ThrowError(base::StringPiece err_msg) {
   Throw(v8::Exception::Error, err_msg);
 }
 
-void ErrorThrower::ThrowTypeError(const std::string& err_msg) {
+void ErrorThrower::ThrowTypeError(base::StringPiece err_msg) {
   Throw(v8::Exception::TypeError, err_msg);
 }
 
-void ErrorThrower::ThrowRangeError(const std::string& err_msg) {
+void ErrorThrower::ThrowRangeError(base::StringPiece err_msg) {
   Throw(v8::Exception::RangeError, err_msg);
 }
 
-void ErrorThrower::ThrowReferenceError(const std::string& err_msg) {
+void ErrorThrower::ThrowReferenceError(base::StringPiece err_msg) {
   Throw(v8::Exception::ReferenceError, err_msg);
 }
 
-void ErrorThrower::ThrowSyntaxError(const std::string& err_msg) {
+void ErrorThrower::ThrowSyntaxError(base::StringPiece err_msg) {
   Throw(v8::Exception::SyntaxError, err_msg);
 }
 
-}  // namespace util
+void ErrorThrower::Throw(ErrorGenerator gen, base::StringPiece err_msg) {
+  v8::Local<v8::Value> exception = gen(gin::StringToV8(isolate_, err_msg));
+  if (!isolate_->IsExecutionTerminating())
+    isolate_->ThrowException(exception);
+}
 
-}  // namespace electron
+}  // namespace gin_helper

+ 38 - 0
shell/common/gin_helper/error_thrower.h

@@ -0,0 +1,38 @@
+// Copyright (c) 2019 GitHub, Inc.
+// Use of this source code is governed by the MIT license that can be
+// found in the LICENSE file.
+
+#ifndef SHELL_COMMON_GIN_HELPER_ERROR_THROWER_H_
+#define SHELL_COMMON_GIN_HELPER_ERROR_THROWER_H_
+
+#include "base/strings/string_piece.h"
+#include "v8/include/v8.h"
+
+namespace gin_helper {
+
+class ErrorThrower {
+ public:
+  explicit ErrorThrower(v8::Isolate* isolate);
+  ErrorThrower();
+
+  ~ErrorThrower();
+
+  void ThrowError(base::StringPiece err_msg);
+  void ThrowTypeError(base::StringPiece err_msg);
+  void ThrowRangeError(base::StringPiece err_msg);
+  void ThrowReferenceError(base::StringPiece err_msg);
+  void ThrowSyntaxError(base::StringPiece err_msg);
+
+  v8::Isolate* isolate() const { return isolate_; }
+
+ private:
+  using ErrorGenerator =
+      v8::Local<v8::Value> (*)(v8::Local<v8::String> err_msg);
+  void Throw(ErrorGenerator gen, base::StringPiece err_msg);
+
+  v8::Isolate* isolate_;
+};
+
+}  // namespace gin_helper
+
+#endif  // SHELL_COMMON_GIN_HELPER_ERROR_THROWER_H_

+ 4 - 4
shell/common/api/event_emitter_caller.cc → shell/common/gin_helper/event_emitter_caller.cc

@@ -1,13 +1,13 @@
-// Copyright (c) 2015 GitHub, Inc.
+// Copyright (c) 2019 GitHub, Inc.
 // Use of this source code is governed by the MIT license that can be
 // found in the LICENSE file.
 
-#include "shell/common/api/event_emitter_caller.h"
+#include "shell/common/gin_helper/event_emitter_caller.h"
 
 #include "shell/common/api/locker.h"
 #include "shell/common/node_includes.h"
 
-namespace mate {
+namespace gin_helper {
 
 namespace internal {
 
@@ -35,4 +35,4 @@ v8::Local<v8::Value> CallMethodWithArgs(v8::Isolate* isolate,
 
 }  // namespace internal
 
-}  // namespace mate
+}  // namespace gin_helper

+ 11 - 12
shell/common/api/event_emitter_caller.h → shell/common/gin_helper/event_emitter_caller.h

@@ -1,17 +1,16 @@
-// Copyright (c) 2015 GitHub, Inc.
+// Copyright (c) 2019 GitHub, Inc.
 // Use of this source code is governed by the MIT license that can be
 // found in the LICENSE file.
 
-#ifndef SHELL_COMMON_API_EVENT_EMITTER_CALLER_H_
-#define SHELL_COMMON_API_EVENT_EMITTER_CALLER_H_
+#ifndef SHELL_COMMON_GIN_HELPER_EVENT_EMITTER_CALLER_H_
+#define SHELL_COMMON_GIN_HELPER_EVENT_EMITTER_CALLER_H_
 
 #include <utility>
 #include <vector>
 
-#include "native_mate/converter.h"
-#include "shell/common/native_mate_converters/string16_converter.h"
+#include "gin/converter.h"
 
-namespace mate {
+namespace gin_helper {
 
 namespace internal {
 
@@ -31,7 +30,7 @@ v8::Local<v8::Value> EmitEvent(v8::Isolate* isolate,
                                v8::Local<v8::Object> obj,
                                const StringType& name,
                                const internal::ValueVector& args) {
-  internal::ValueVector concatenated_args = {StringToV8(isolate, name)};
+  internal::ValueVector concatenated_args = {gin::StringToV8(isolate, name)};
   concatenated_args.reserve(1 + args.size());
   concatenated_args.insert(concatenated_args.end(), args.begin(), args.end());
   return internal::CallMethodWithArgs(isolate, obj, "emit", &concatenated_args);
@@ -45,8 +44,8 @@ v8::Local<v8::Value> EmitEvent(v8::Isolate* isolate,
                                const StringType& name,
                                Args&&... args) {
   internal::ValueVector converted_args = {
-      StringToV8(isolate, name),
-      ConvertToV8(isolate, std::forward<Args>(args))...,
+      gin::StringToV8(isolate, name),
+      gin::ConvertToV8(isolate, std::forward<Args>(args))...,
   };
   return internal::CallMethodWithArgs(isolate, obj, "emit", &converted_args);
 }
@@ -58,12 +57,12 @@ v8::Local<v8::Value> CustomEmit(v8::Isolate* isolate,
                                 const char* custom_emit,
                                 Args&&... args) {
   internal::ValueVector converted_args = {
-      ConvertToV8(isolate, std::forward<Args>(args))...,
+      gin::ConvertToV8(isolate, std::forward<Args>(args))...,
   };
   return internal::CallMethodWithArgs(isolate, object, custom_emit,
                                       &converted_args);
 }
 
-}  // namespace mate
+}  // namespace gin_helper
 
-#endif  // SHELL_COMMON_API_EVENT_EMITTER_CALLER_H_
+#endif  // SHELL_COMMON_GIN_HELPER_EVENT_EMITTER_CALLER_H_

+ 3 - 3
shell/common/gin_helper/function_template.h

@@ -7,8 +7,8 @@
 
 #include "base/callback.h"
 #include "gin/arguments.h"
-#include "shell/common/error_util.h"
 #include "shell/common/gin_helper/destroyable.h"
+#include "shell/common/gin_helper/error_thrower.h"
 
 // This file is forked from gin/function_template.h with 2 differences:
 // 1. Support for additional types of arguments.
@@ -112,8 +112,8 @@ inline bool GetNextArgument(gin::Arguments* args,
 inline bool GetNextArgument(gin::Arguments* args,
                             int create_flags,
                             bool is_first,
-                            electron::util::ErrorThrower* result) {
-  *result = electron::util::ErrorThrower(args->isolate());
+                            ErrorThrower* result) {
+  *result = ErrorThrower(args->isolate());
   return true;
 }
 

+ 6 - 6
shell/common/node_bindings.cc

@@ -22,12 +22,12 @@
 #include "content/public/browser/browser_thread.h"
 #include "content/public/common/content_paths.h"
 #include "electron/buildflags/buildflags.h"
-#include "native_mate/dictionary.h"
-#include "shell/common/api/event_emitter_caller.h"
 #include "shell/common/api/locker.h"
 #include "shell/common/atom_command_line.h"
+#include "shell/common/gin_converters/file_path_converter.h"
+#include "shell/common/gin_helper/dictionary.h"
+#include "shell/common/gin_helper/event_emitter_caller.h"
 #include "shell/common/mac/main_application_bundle.h"
-#include "shell/common/native_mate_converters/file_path_converter.h"
 #include "shell/common/node_includes.h"
 
 #define ELECTRON_BUILTIN_MODULES(V)  \
@@ -314,7 +314,7 @@ node::Environment* NodeBindings::CreateEnvironment(
       break;
   }
 
-  mate::Dictionary global(context->GetIsolate(), context->Global());
+  gin_helper::Dictionary global(context->GetIsolate(), context->Global());
   // Do not set DOM globals for renderer process.
   // We must set this before the node bootstrapper which is run inside
   // CreateEnvironment
@@ -351,7 +351,7 @@ node::Environment* NodeBindings::CreateEnvironment(
     context->GetIsolate()->SetMicrotasksPolicy(v8::MicrotasksPolicy::kScoped);
   }
 
-  mate::Dictionary process(context->GetIsolate(), env->process_object());
+  gin_helper::Dictionary process(context->GetIsolate(), env->process_object());
   process.SetReadOnly("type", process_type);
   process.Set("resourcesPath", resources_path);
   // The path to helper app.
@@ -364,7 +364,7 @@ node::Environment* NodeBindings::CreateEnvironment(
 
 void NodeBindings::LoadEnvironment(node::Environment* env) {
   node::LoadEnvironment(env);
-  mate::EmitEvent(env->isolate(), env->process_object(), "loaded");
+  gin_helper::EmitEvent(env->isolate(), env->process_object(), "loaded");
 }
 
 void NodeBindings::PrepareMessageLoop() {

+ 2 - 4
shell/common/promise_util.h

@@ -14,9 +14,7 @@
 #include "content/public/browser/browser_task_traits.h"
 #include "content/public/browser/browser_thread.h"
 #include "native_mate/converter.h"
-#include "shell/common/api/locker.h"
-#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
-#include "shell/common/native_mate_converters/once_callback.h"
+#include "shell/common/gin_converters/std_converter.h"
 
 namespace electron {
 
@@ -142,7 +140,7 @@ class Promise {
     v8::Context::Scope context_scope(
         v8::Local<v8::Context>::New(isolate(), GetContext()));
 
-    v8::Local<v8::Value> value = mate::ConvertToV8(isolate(), cb);
+    v8::Local<v8::Value> value = gin::ConvertToV8(isolate(), std::move(cb));
     v8::Local<v8::Function> handler = v8::Local<v8::Function>::Cast(value);
 
     return GetHandle()->Then(GetContext(), handler);

+ 0 - 3
shell/renderer/api/atom_api_web_frame.cc

@@ -13,12 +13,9 @@
 #include "content/public/renderer/render_frame_visitor.h"
 #include "content/public/renderer/render_view.h"
 #include "native_mate/dictionary.h"
-#include "native_mate/object_template_builder.h"
 #include "services/service_manager/public/cpp/interface_provider.h"
 #include "shell/common/api/api.mojom.h"
-#include "shell/common/api/event_emitter_caller.h"
 #include "shell/common/native_mate_converters/blink_converter.h"
-#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
 #include "shell/common/native_mate_converters/gfx_converter.h"
 #include "shell/common/native_mate_converters/string16_converter.h"
 #include "shell/common/node_includes.h"

+ 0 - 4
shell/renderer/atom_render_frame_observer.cc

@@ -16,13 +16,9 @@
 #include "electron/buildflags/buildflags.h"
 #include "electron/shell/common/api/api.mojom.h"
 #include "ipc/ipc_message_macros.h"
-#include "native_mate/dictionary.h"
 #include "net/base/net_module.h"
 #include "net/grit/net_resources.h"
 #include "services/service_manager/public/cpp/interface_provider.h"
-#include "shell/common/api/event_emitter_caller.h"
-#include "shell/common/native_mate_converters/value_converter.h"
-#include "shell/common/node_includes.h"
 #include "shell/common/options_switches.h"
 #include "third_party/blink/public/platform/web_isolated_world_info.h"
 #include "third_party/blink/public/web/blink.h"

+ 8 - 6
shell/renderer/atom_renderer_client.cc

@@ -10,10 +10,10 @@
 #include "base/command_line.h"
 #include "content/public/renderer/render_frame.h"
 #include "electron/buildflags/buildflags.h"
-#include "native_mate/dictionary.h"
 #include "shell/common/api/electron_bindings.h"
-#include "shell/common/api/event_emitter_caller.h"
 #include "shell/common/asar/asar_util.h"
+#include "shell/common/gin_helper/dictionary.h"
+#include "shell/common/gin_helper/event_emitter_caller.h"
 #include "shell/common/node_bindings.h"
 #include "shell/common/node_includes.h"
 #include "shell/common/options_switches.h"
@@ -56,7 +56,8 @@ void AtomRendererClient::RunScriptsAtDocumentStart(
   v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
   node::Environment* env = GetEnvironment(render_frame);
   if (env)
-    mate::EmitEvent(env->isolate(), env->process_object(), "document-start");
+    gin_helper::EmitEvent(env->isolate(), env->process_object(),
+                          "document-start");
 }
 
 void AtomRendererClient::RunScriptsAtDocumentEnd(
@@ -66,7 +67,8 @@ void AtomRendererClient::RunScriptsAtDocumentEnd(
   v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
   node::Environment* env = GetEnvironment(render_frame);
   if (env)
-    mate::EmitEvent(env->isolate(), env->process_object(), "document-end");
+    gin_helper::EmitEvent(env->isolate(), env->process_object(),
+                          "document-end");
 }
 
 void AtomRendererClient::DidCreateScriptContext(
@@ -135,7 +137,7 @@ void AtomRendererClient::DidCreateScriptContext(
   // Add Electron extended APIs.
   electron_bindings_->BindTo(env->isolate(), env->process_object());
   AddRenderBindings(env->isolate(), env->process_object());
-  mate::Dictionary process_dict(env->isolate(), env->process_object());
+  gin_helper::Dictionary process_dict(env->isolate(), env->process_object());
   process_dict.SetReadOnly("isMainFrame", render_frame->IsMainFrame());
 
   // Load everything.
@@ -160,7 +162,7 @@ void AtomRendererClient::WillReleaseScriptContext(
   if (environments_.erase(env) == 0)
     return;
 
-  mate::EmitEvent(env->isolate(), env->process_object(), "exit");
+  gin_helper::EmitEvent(env->isolate(), env->process_object(), "exit");
 
   // The main frame may be replaced.
   if (env == node_bindings_->uv_env())

+ 9 - 12
shell/renderer/electron_api_service_impl.cc

@@ -11,16 +11,14 @@
 #include "base/environment.h"
 #include "base/macros.h"
 #include "base/threading/thread_restrictions.h"
-#include "electron/shell/common/api/event_emitter_caller.h"
-#include "electron/shell/common/node_includes.h"
-#include "electron/shell/common/options_switches.h"
-#include "electron/shell/renderer/atom_render_frame_observer.h"
-#include "electron/shell/renderer/renderer_client_base.h"
 #include "mojo/public/cpp/system/platform_handle.h"
-#include "native_mate/dictionary.h"
 #include "shell/common/atom_constants.h"
+#include "shell/common/gin_converters/value_converter_gin_adapter.h"
 #include "shell/common/heap_snapshot.h"
-#include "shell/common/native_mate_converters/value_converter.h"
+#include "shell/common/node_includes.h"
+#include "shell/common/options_switches.h"
+#include "shell/renderer/atom_render_frame_observer.h"
+#include "shell/renderer/renderer_client_base.h"
 #include "third_party/blink/public/web/blink.h"
 #include "third_party/blink/public/web/web_local_frame.h"
 
@@ -33,8 +31,7 @@ const char kIpcKey[] = "ipcNative";
 // Gets the private object under kIpcKey
 v8::Local<v8::Object> GetIpcObject(v8::Local<v8::Context> context) {
   auto* isolate = context->GetIsolate();
-  auto binding_key =
-      mate::ConvertToV8(isolate, kIpcKey)->ToString(context).ToLocalChecked();
+  auto binding_key = gin::StringToV8(isolate, kIpcKey);
   auto private_binding_key = v8::Private::ForApi(isolate, binding_key);
   auto global_object = context->Global();
   auto value =
@@ -64,7 +61,7 @@ void InvokeIpcCallback(v8::Local<v8::Context> context,
     callback_scope.reset(new node::CallbackScope(isolate, ipcNative, {0, 0}));
   }
 
-  auto callback_key = mate::ConvertToV8(isolate, callback_name)
+  auto callback_key = gin::ConvertToV8(isolate, callback_name)
                           ->ToString(context)
                           .ToLocalChecked();
   auto callback_value = ipcNative->Get(context, callback_key).ToLocalChecked();
@@ -86,8 +83,8 @@ void EmitIPCEvent(v8::Local<v8::Context> context,
                                    v8::MicrotasksScope::kRunMicrotasks);
 
   std::vector<v8::Local<v8::Value>> argv = {
-      mate::ConvertToV8(isolate, internal), mate::ConvertToV8(isolate, channel),
-      mate::ConvertToV8(isolate, args), mate::ConvertToV8(isolate, sender_id)};
+      gin::ConvertToV8(isolate, internal), gin::ConvertToV8(isolate, channel),
+      gin::ConvertToV8(isolate, args), gin::ConvertToV8(isolate, sender_id)};
 
   InvokeIpcCallback(context, "onMessage", argv);
 }

+ 2 - 2
shell/renderer/web_worker_observer.cc

@@ -7,8 +7,8 @@
 #include "base/lazy_instance.h"
 #include "base/threading/thread_local.h"
 #include "shell/common/api/electron_bindings.h"
-#include "shell/common/api/event_emitter_caller.h"
 #include "shell/common/asar/asar_util.h"
+#include "shell/common/gin_helper/event_emitter_caller.h"
 #include "shell/common/node_bindings.h"
 #include "shell/common/node_includes.h"
 
@@ -69,7 +69,7 @@ void WebWorkerObserver::ContextCreated(v8::Local<v8::Context> worker_context) {
 void WebWorkerObserver::ContextWillDestroy(v8::Local<v8::Context> context) {
   node::Environment* env = node::Environment::GetCurrent(context);
   if (env)
-    mate::EmitEvent(env->isolate(), env->process_object(), "exit");
+    gin_helper::EmitEvent(env->isolate(), env->process_object(), "exit");
 
   delete this;
 }