Skip to content
Permalink
Browse files

chore: remove native_mate (Part 5) (#20264)

* deprecate native_mate/native_mate/object_template_builder.h

* add gin_helper/object_template_builder.h

* add patch to avoid ambiguous error

* remove usage of object_template_builder_deprecated.h in a few files

* add note we should remove gin_helper/object_template_builder.h in future
  • Loading branch information...
zcbenz authored and codebytere committed Sep 19, 2019
1 parent 63f08fc commit 624ba4f642d3ef33bde23ff311f1e5ef03a69a28
Showing with 474 additions and 121 deletions.
  1. +3 −0 filenames.gni
  2. +1 −1 native_mate/BUILD.gn
  3. +1 −1 native_mate/README.md
  4. +1 −1 native_mate/native_mate/dictionary.h
  5. +1 −1 native_mate/native_mate/object_template_builder.cc
  6. +3 −3 native_mate/native_mate/{object_template_builder.h → object_template_builder_deprecated.h}
  7. +1 −1 native_mate/native_mate/wrappable.cc
  8. +1 −0 patches/chromium/.patches
  9. +83 −0 patches/chromium/gin_with_namespace.patch
  10. +1 −1 shell/browser/api/atom_api_app.cc
  11. +1 −1 shell/browser/api/atom_api_auto_updater.cc
  12. +8 −10 shell/browser/api/atom_api_menu.cc
  13. +14 −0 shell/browser/api/atom_api_menu.h
  14. +1 −1 shell/browser/api/atom_api_native_theme.cc
  15. +1 −1 shell/browser/api/atom_api_notification.cc
  16. +10 −10 shell/browser/api/atom_api_screen.cc
  17. +2 −2 shell/browser/api/atom_api_screen.h
  18. +1 −1 shell/browser/api/atom_api_session.cc
  19. +18 −0 shell/browser/api/atom_api_session.h
  20. +1 −1 shell/browser/api/atom_api_system_preferences_mac.mm
  21. +18 −0 shell/browser/api/atom_api_top_level_window.h
  22. +8 −7 shell/browser/api/atom_api_url_request_ns.cc
  23. +21 −2 shell/browser/api/atom_api_url_request_ns.h
  24. +1 −1 shell/browser/api/atom_api_web_contents.cc
  25. +1 −1 shell/browser/api/event.cc
  26. +1 −1 shell/browser/api/event_emitter.cc
  27. +1 −1 shell/browser/api/trackable_object.h
  28. +1 −1 shell/common/api/atom_api_asar.cc
  29. +22 −3 shell/common/api/atom_api_key_weak_map.h
  30. +1 −1 shell/common/api/atom_api_native_image.cc
  31. +15 −8 shell/common/api/atom_api_v8_util.cc
  32. +30 −0 shell/common/gin_converters/native_mate_handle_converter.h
  33. +16 −0 shell/common/gin_converters/std_converter.h
  34. +13 −0 shell/common/gin_converters/value_converter_gin_adapter.h
  35. +0 −38 shell/common/gin_helper/dictionary.h
  36. +39 −0 shell/common/gin_helper/function_template.h
  37. +32 −0 shell/common/gin_helper/object_template_builder.cc
  38. +75 −0 shell/common/gin_helper/object_template_builder.h
  39. +26 −21 shell/renderer/api/atom_api_renderer_ipc.cc
@@ -476,6 +476,7 @@ filenames = {
"shell/common/gin_converters/gurl_converter.h",
"shell/common/gin_converters/image_converter.cc",
"shell/common/gin_converters/image_converter.h",
"shell/common/gin_converters/native_mate_handle_converter.h",
"shell/common/gin_converters/message_box_converter.cc",
"shell/common/gin_converters/message_box_converter.h",
"shell/common/gin_converters/native_window_converter.h",
@@ -494,6 +495,8 @@ filenames = {
"shell/common/gin_helper/event_emitter_caller.h",
"shell/common/gin_helper/function_template.cc",
"shell/common/gin_helper/function_template.h",
"shell/common/gin_helper/object_template_builder.cc",
"shell/common/gin_helper/object_template_builder.h",
"shell/common/heap_snapshot.cc",
"shell/common/heap_snapshot.h",
"shell/common/key_weak_map.h",
@@ -23,7 +23,7 @@ source_set("native_mate") {
"native_mate/function_template.h",
"native_mate/handle.h",
"native_mate/object_template_builder.cc",
"native_mate/object_template_builder.h",
"native_mate/object_template_builder_deprecated.h",
"native_mate/persistent_dictionary.cc",
"native_mate/persistent_dictionary.h",
"native_mate/scoped_persistent.h",
@@ -45,7 +45,7 @@ void Initialize(v8::Handle<v8::Object> exports) {
types. You can define your own by specializing `Converter`.
* `function_template.h` - Create JavaScript functions that dispatch to any C++
function, member function pointer, or `base::Callback`.
* `object_template_builder.h` - A handy utility for creation of `v8::ObjectTemplate`.
* `object_template_builder_deprecated.h` - A handy utility for creation of `v8::ObjectTemplate`.
* `wrappable.h` - Base class for C++ classes that want to be owned by the V8 GC.
Wrappable objects are automatically deleted when GC discovers that nothing in
the V8 heap refers to them. This is also an easy way to expose C++ objects to
@@ -6,7 +6,7 @@
#define NATIVE_MATE_NATIVE_MATE_DICTIONARY_H_

#include "native_mate/converter.h"
#include "native_mate/object_template_builder.h"
#include "native_mate/object_template_builder_deprecated.h"

namespace mate {

@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE.chromium file.

#include "native_mate/object_template_builder.h"
#include "native_mate/object_template_builder_deprecated.h"

namespace mate {

@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE.chromium file.

#ifndef NATIVE_MATE_NATIVE_MATE_OBJECT_TEMPLATE_BUILDER_H_
#define NATIVE_MATE_NATIVE_MATE_OBJECT_TEMPLATE_BUILDER_H_
#ifndef NATIVE_MATE_NATIVE_MATE_OBJECT_TEMPLATE_BUILDER_DEPRECATED_H_
#define NATIVE_MATE_NATIVE_MATE_OBJECT_TEMPLATE_BUILDER_DEPRECATED_H_

#include "base/bind.h"
#include "base/callback.h"
@@ -117,4 +117,4 @@ class ObjectTemplateBuilder {

} // namespace mate

#endif // NATIVE_MATE_NATIVE_MATE_OBJECT_TEMPLATE_BUILDER_H_
#endif // NATIVE_MATE_NATIVE_MATE_OBJECT_TEMPLATE_BUILDER_DEPRECATED_H_
@@ -6,7 +6,7 @@

#include "base/logging.h"
#include "native_mate/dictionary.h"
#include "native_mate/object_template_builder.h"
#include "native_mate/object_template_builder_deprecated.h"

namespace mate {

@@ -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_with_namespace.patch
blink-worker-enable-csp-in-file-scheme.patch
disable-redraw-lock.patch
v8_context_snapshot_generator.patch
@@ -0,0 +1,83 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Cheng Zhao <zcbenz@gmail.com>
Date: Thu, 20 Sep 2018 17:47:44 -0700
Subject: gin_with_namespace.patch

When using gin with native_mate together we may have C++ confused with
finding the correct ConvertFromV8. We add gin:: namespace explicitly in
those calls to work around the ambiguous compilation error.

Note that this is only a work around to make it easier to remove
native_mate, and we should remove this patch once native_mate is erased
from Electron.

diff --git a/gin/arguments.h b/gin/arguments.h
index eaded13e2991..03e1495566d1 100644
--- a/gin/arguments.h
+++ b/gin/arguments.h
@@ -28,14 +28,14 @@ class GIN_EXPORT Arguments {
v8::Local<v8::Object> holder = is_for_property_
? info_for_property_->Holder()
: info_for_function_->Holder();
- return ConvertFromV8(isolate_, holder, out);
+ return gin::ConvertFromV8(isolate_, holder, out);
}

template<typename T>
bool GetData(T* out) {
v8::Local<v8::Value> data = is_for_property_ ? info_for_property_->Data()
: info_for_function_->Data();
- return ConvertFromV8(isolate_, data, out);
+ return gin::ConvertFromV8(isolate_, data, out);
}

template<typename T>
@@ -45,7 +45,7 @@ class GIN_EXPORT Arguments {
return false;
}
v8::Local<v8::Value> val = (*info_for_function_)[next_++];
- return ConvertFromV8(isolate_, val, out);
+ return gin::ConvertFromV8(isolate_, val, out);
}

template<typename T>
@@ -58,7 +58,7 @@ class GIN_EXPORT Arguments {
out->resize(remaining);
for (int i = 0; i < remaining; ++i) {
v8::Local<v8::Value> val = (*info_for_function_)[next_++];
- if (!ConvertFromV8(isolate_, val, &out->at(i)))
+ if (!gin::ConvertFromV8(isolate_, val, &out->at(i)))
return false;
}
return true;
@@ -80,7 +80,7 @@ class GIN_EXPORT Arguments {
template<typename T>
void Return(T val) {
v8::Local<v8::Value> v8_value;
- if (!TryConvertToV8(isolate_, val, &v8_value))
+ if (!gin::TryConvertToV8(isolate_, val, &v8_value))
return;
(is_for_property_ ? info_for_property_->GetReturnValue()
: info_for_function_->GetReturnValue())
diff --git a/gin/converter.h b/gin/converter.h
index 27b4d0acd016..b19209a8534a 100644
--- a/gin/converter.h
+++ b/gin/converter.h
@@ -250,7 +250,7 @@ std::enable_if_t<ToV8ReturnsMaybe<T>::value, bool> TryConvertToV8(
v8::Isolate* isolate,
const T& input,
v8::Local<v8::Value>* output) {
- return ConvertToV8(isolate, input).ToLocal(output);
+ return gin::ConvertToV8(isolate, input).ToLocal(output);
}

template <typename T>
@@ -258,7 +258,7 @@ std::enable_if_t<!ToV8ReturnsMaybe<T>::value, bool> TryConvertToV8(
v8::Isolate* isolate,
const T& input,
v8::Local<v8::Value>* output) {
- *output = ConvertToV8(isolate, input);
+ *output = gin::ConvertToV8(isolate, input);
return true;
}

@@ -30,7 +30,7 @@
#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 "native_mate/object_template_builder_deprecated.h"
#include "net/ssl/client_cert_identity.h"
#include "net/ssl/ssl_cert_request_info.h"
#include "services/service_manager/sandbox/switches.h"
@@ -6,7 +6,7 @@

#include "base/time/time.h"
#include "native_mate/dictionary.h"
#include "native_mate/object_template_builder.h"
#include "native_mate/object_template_builder_deprecated.h"
#include "shell/browser/browser.h"
#include "shell/browser/native_window.h"
#include "shell/browser/window_list.h"
@@ -6,24 +6,22 @@

#include <map>

#include "gin/dictionary.h"
#include "native_mate/constructor.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/gin_converters/image_converter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/gin_helper/object_template_builder.h"
#include "shell/common/native_mate_converters/accelerator_converter.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
// even when they are still displayed.
std::map<uint32_t, v8::Global<v8::Object>> g_menus;

} // unnamed namespace

namespace electron {
@@ -224,9 +222,9 @@ void Menu::OnMenuWillShow() {
// static
void Menu::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "Menu"));
prototype->SetClassName(gin::StringToV8(isolate, "Menu"));
gin_helper::Destroyable::MakeDestroyable(isolate, prototype);
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("insertItem", &Menu::InsertItemAt)
.SetMethod("insertCheckItem", &Menu::InsertCheckItemAt)
.SetMethod("insertRadioItem", &Menu::InsertRadioItemAt)
@@ -267,7 +265,7 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Isolate* isolate = context->GetIsolate();
Menu::SetConstructor(isolate, base::BindRepeating(&Menu::New));

mate::Dictionary dict(isolate, exports);
gin_helper::Dictionary dict(isolate, exports);
dict.Set(
"Menu",
Menu::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());
@@ -155,6 +155,20 @@ struct Converter<electron::AtomMenuModel*> {
}
};

// TODO(zcbenz): Remove this after converting Menu to gin::Wrapper.
template <>
struct Converter<electron::api::Menu*> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
electron::api::Menu** out) {
return mate::ConvertFromV8(isolate, val, out);
}
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
electron::api::Menu* in) {
return mate::ConvertToV8(isolate, in);
}
};

} // namespace gin

#endif // SHELL_BROWSER_API_ATOM_API_MENU_H_
@@ -10,7 +10,7 @@
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "native_mate/dictionary.h"
#include "native_mate/object_template_builder.h"
#include "native_mate/object_template_builder_deprecated.h"
#include "shell/common/node_includes.h"
#include "ui/gfx/color_utils.h"
#include "ui/native_theme/native_theme.h"
@@ -8,7 +8,7 @@
#include "base/strings/utf_string_conversions.h"
#include "native_mate/constructor.h"
#include "native_mate/dictionary.h"
#include "native_mate/object_template_builder.h"
#include "native_mate/object_template_builder_deprecated.h"
#include "shell/browser/api/atom_api_menu.h"
#include "shell/browser/atom_browser_client.h"
#include "shell/browser/browser.h"
@@ -9,9 +9,9 @@

#include "base/bind.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/gin_helper/object_template_builder.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"
@@ -134,22 +134,22 @@ void Screen::OnDisplayMetricsChanged(const display::Display& display,
}

// static
v8::Local<v8::Value> Screen::Create(v8::Isolate* isolate) {
v8::Local<v8::Value> Screen::Create(gin_helper::ErrorThrower error_thrower) {
if (!Browser::Get()->is_ready()) {
isolate->ThrowException(v8::Exception::Error(mate::StringToV8(
isolate,
"The 'screen' module can't be used before the app 'ready' event")));
return v8::Null(isolate);
error_thrower.ThrowError(
"The 'screen' module can't be used before the app 'ready' event");
return v8::Null(error_thrower.isolate());
}

display::Screen* screen = display::Screen::GetScreen();
if (!screen) {
isolate->ThrowException(v8::Exception::Error(
mate::StringToV8(isolate, "Failed to get screen information")));
return v8::Null(isolate);
error_thrower.ThrowError("Failed to get screen information");
return v8::Null(error_thrower.isolate());
}

return mate::CreateHandle(isolate, new Screen(isolate, screen)).ToV8();
return mate::CreateHandle(error_thrower.isolate(),
new Screen(error_thrower.isolate(), screen))
.ToV8();
}

// static
@@ -7,8 +7,8 @@

#include <vector>

#include "native_mate/handle.h"
#include "shell/browser/api/event_emitter.h"
#include "shell/common/gin_helper/error_thrower.h"
#include "ui/display/display_observer.h"
#include "ui/display/screen.h"

@@ -25,7 +25,7 @@ namespace api {
class Screen : public mate::EventEmitter<Screen>,
public display::DisplayObserver {
public:
static v8::Local<v8::Value> Create(v8::Isolate* isolate);
static v8::Local<v8::Value> Create(gin_helper::ErrorThrower error_thrower);

static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);
@@ -33,7 +33,7 @@
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "native_mate/dictionary.h"
#include "native_mate/object_template_builder.h"
#include "native_mate/object_template_builder_deprecated.h"
#include "net/base/completion_repeating_callback.h"
#include "net/base/load_flags.h"
#include "net/http/http_auth_handler_factory.h"
@@ -121,4 +121,22 @@ class Session : public mate::TrackableObject<Session>,

} // namespace electron

namespace gin {

// TODO(zcbenz): Remove this after converting Session to gin::Wrapper.
template <>
struct Converter<electron::api::Session*> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
electron::api::Session** out) {
return mate::ConvertFromV8(isolate, val, out);
}
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
electron::api::Session* in) {
return mate::ConvertToV8(isolate, in);
}
};

} // namespace gin

#endif // SHELL_BROWSER_API_ATOM_API_SESSION_H_
@@ -21,7 +21,7 @@
#include "base/strings/sys_string_conversions.h"
#include "base/threading/sequenced_task_runner_handle.h"
#include "base/values.h"
#include "native_mate/object_template_builder.h"
#include "native_mate/object_template_builder_deprecated.h"
#include "net/base/mac/url_conversions.h"
#include "shell/browser/mac/atom_application.h"
#include "shell/browser/mac/dict_util.h"

0 comments on commit 624ba4f

Please sign in to comment.
You can’t perform that action at this time.