Skip to content

Commit 624ba4f

Browse files
zcbenzcodebytere
authored andcommitted
chore: remove native_mate (Part 5) (electron#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
1 parent 63f08fc commit 624ba4f

39 files changed

+474
-121
lines changed

Diff for: filenames.gni

+3
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ filenames = {
476476
"shell/common/gin_converters/gurl_converter.h",
477477
"shell/common/gin_converters/image_converter.cc",
478478
"shell/common/gin_converters/image_converter.h",
479+
"shell/common/gin_converters/native_mate_handle_converter.h",
479480
"shell/common/gin_converters/message_box_converter.cc",
480481
"shell/common/gin_converters/message_box_converter.h",
481482
"shell/common/gin_converters/native_window_converter.h",
@@ -494,6 +495,8 @@ filenames = {
494495
"shell/common/gin_helper/event_emitter_caller.h",
495496
"shell/common/gin_helper/function_template.cc",
496497
"shell/common/gin_helper/function_template.h",
498+
"shell/common/gin_helper/object_template_builder.cc",
499+
"shell/common/gin_helper/object_template_builder.h",
497500
"shell/common/heap_snapshot.cc",
498501
"shell/common/heap_snapshot.h",
499502
"shell/common/key_weak_map.h",

Diff for: native_mate/BUILD.gn

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ source_set("native_mate") {
2323
"native_mate/function_template.h",
2424
"native_mate/handle.h",
2525
"native_mate/object_template_builder.cc",
26-
"native_mate/object_template_builder.h",
26+
"native_mate/object_template_builder_deprecated.h",
2727
"native_mate/persistent_dictionary.cc",
2828
"native_mate/persistent_dictionary.h",
2929
"native_mate/scoped_persistent.h",

Diff for: native_mate/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void Initialize(v8::Handle<v8::Object> exports) {
4545
types. You can define your own by specializing `Converter`.
4646
* `function_template.h` - Create JavaScript functions that dispatch to any C++
4747
function, member function pointer, or `base::Callback`.
48-
* `object_template_builder.h` - A handy utility for creation of `v8::ObjectTemplate`.
48+
* `object_template_builder_deprecated.h` - A handy utility for creation of `v8::ObjectTemplate`.
4949
* `wrappable.h` - Base class for C++ classes that want to be owned by the V8 GC.
5050
Wrappable objects are automatically deleted when GC discovers that nothing in
5151
the V8 heap refers to them. This is also an easy way to expose C++ objects to

Diff for: native_mate/native_mate/dictionary.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#define NATIVE_MATE_NATIVE_MATE_DICTIONARY_H_
77

88
#include "native_mate/converter.h"
9-
#include "native_mate/object_template_builder.h"
9+
#include "native_mate/object_template_builder_deprecated.h"
1010

1111
namespace mate {
1212

Diff for: native_mate/native_mate/object_template_builder.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE.chromium file.
44

5-
#include "native_mate/object_template_builder.h"
5+
#include "native_mate/object_template_builder_deprecated.h"
66

77
namespace mate {
88

Diff for: native_mate/native_mate/object_template_builder.h renamed to native_mate/native_mate/object_template_builder_deprecated.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE.chromium file.
44

5-
#ifndef NATIVE_MATE_NATIVE_MATE_OBJECT_TEMPLATE_BUILDER_H_
6-
#define NATIVE_MATE_NATIVE_MATE_OBJECT_TEMPLATE_BUILDER_H_
5+
#ifndef NATIVE_MATE_NATIVE_MATE_OBJECT_TEMPLATE_BUILDER_DEPRECATED_H_
6+
#define NATIVE_MATE_NATIVE_MATE_OBJECT_TEMPLATE_BUILDER_DEPRECATED_H_
77

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

118118
} // namespace mate
119119

120-
#endif // NATIVE_MATE_NATIVE_MATE_OBJECT_TEMPLATE_BUILDER_H_
120+
#endif // NATIVE_MATE_NATIVE_MATE_OBJECT_TEMPLATE_BUILDER_DEPRECATED_H_

Diff for: native_mate/native_mate/wrappable.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include "base/logging.h"
88
#include "native_mate/dictionary.h"
9-
#include "native_mate/object_template_builder.h"
9+
#include "native_mate/object_template_builder_deprecated.h"
1010

1111
namespace mate {
1212

Diff for: patches/chromium/.patches

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ web_contents.patch
1717
webview_cross_drag.patch
1818
disable_user_gesture_requirement_for_beforeunload_dialogs.patch
1919
gin_enable_disable_v8_platform.patch
20+
gin_with_namespace.patch
2021
blink-worker-enable-csp-in-file-scheme.patch
2122
disable-redraw-lock.patch
2223
v8_context_snapshot_generator.patch

Diff for: patches/chromium/gin_with_namespace.patch

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Cheng Zhao <[email protected]>
3+
Date: Thu, 20 Sep 2018 17:47:44 -0700
4+
Subject: gin_with_namespace.patch
5+
6+
When using gin with native_mate together we may have C++ confused with
7+
finding the correct ConvertFromV8. We add gin:: namespace explicitly in
8+
those calls to work around the ambiguous compilation error.
9+
10+
Note that this is only a work around to make it easier to remove
11+
native_mate, and we should remove this patch once native_mate is erased
12+
from Electron.
13+
14+
diff --git a/gin/arguments.h b/gin/arguments.h
15+
index eaded13e2991..03e1495566d1 100644
16+
--- a/gin/arguments.h
17+
+++ b/gin/arguments.h
18+
@@ -28,14 +28,14 @@ class GIN_EXPORT Arguments {
19+
v8::Local<v8::Object> holder = is_for_property_
20+
? info_for_property_->Holder()
21+
: info_for_function_->Holder();
22+
- return ConvertFromV8(isolate_, holder, out);
23+
+ return gin::ConvertFromV8(isolate_, holder, out);
24+
}
25+
26+
template<typename T>
27+
bool GetData(T* out) {
28+
v8::Local<v8::Value> data = is_for_property_ ? info_for_property_->Data()
29+
: info_for_function_->Data();
30+
- return ConvertFromV8(isolate_, data, out);
31+
+ return gin::ConvertFromV8(isolate_, data, out);
32+
}
33+
34+
template<typename T>
35+
@@ -45,7 +45,7 @@ class GIN_EXPORT Arguments {
36+
return false;
37+
}
38+
v8::Local<v8::Value> val = (*info_for_function_)[next_++];
39+
- return ConvertFromV8(isolate_, val, out);
40+
+ return gin::ConvertFromV8(isolate_, val, out);
41+
}
42+
43+
template<typename T>
44+
@@ -58,7 +58,7 @@ class GIN_EXPORT Arguments {
45+
out->resize(remaining);
46+
for (int i = 0; i < remaining; ++i) {
47+
v8::Local<v8::Value> val = (*info_for_function_)[next_++];
48+
- if (!ConvertFromV8(isolate_, val, &out->at(i)))
49+
+ if (!gin::ConvertFromV8(isolate_, val, &out->at(i)))
50+
return false;
51+
}
52+
return true;
53+
@@ -80,7 +80,7 @@ class GIN_EXPORT Arguments {
54+
template<typename T>
55+
void Return(T val) {
56+
v8::Local<v8::Value> v8_value;
57+
- if (!TryConvertToV8(isolate_, val, &v8_value))
58+
+ if (!gin::TryConvertToV8(isolate_, val, &v8_value))
59+
return;
60+
(is_for_property_ ? info_for_property_->GetReturnValue()
61+
: info_for_function_->GetReturnValue())
62+
diff --git a/gin/converter.h b/gin/converter.h
63+
index 27b4d0acd016..b19209a8534a 100644
64+
--- a/gin/converter.h
65+
+++ b/gin/converter.h
66+
@@ -250,7 +250,7 @@ std::enable_if_t<ToV8ReturnsMaybe<T>::value, bool> TryConvertToV8(
67+
v8::Isolate* isolate,
68+
const T& input,
69+
v8::Local<v8::Value>* output) {
70+
- return ConvertToV8(isolate, input).ToLocal(output);
71+
+ return gin::ConvertToV8(isolate, input).ToLocal(output);
72+
}
73+
74+
template <typename T>
75+
@@ -258,7 +258,7 @@ std::enable_if_t<!ToV8ReturnsMaybe<T>::value, bool> TryConvertToV8(
76+
v8::Isolate* isolate,
77+
const T& input,
78+
v8::Local<v8::Value>* output) {
79+
- *output = ConvertToV8(isolate, input);
80+
+ *output = gin::ConvertToV8(isolate, input);
81+
return true;
82+
}
83+

Diff for: shell/browser/api/atom_api_app.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include "content/public/common/content_switches.h"
3131
#include "gin/arguments.h"
3232
#include "media/audio/audio_manager.h"
33-
#include "native_mate/object_template_builder.h"
33+
#include "native_mate/object_template_builder_deprecated.h"
3434
#include "net/ssl/client_cert_identity.h"
3535
#include "net/ssl/ssl_cert_request_info.h"
3636
#include "services/service_manager/sandbox/switches.h"

Diff for: shell/browser/api/atom_api_auto_updater.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include "base/time/time.h"
88
#include "native_mate/dictionary.h"
9-
#include "native_mate/object_template_builder.h"
9+
#include "native_mate/object_template_builder_deprecated.h"
1010
#include "shell/browser/browser.h"
1111
#include "shell/browser/native_window.h"
1212
#include "shell/browser/window_list.h"

Diff for: shell/browser/api/atom_api_menu.cc

+8-10
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,22 @@
66

77
#include <map>
88

9-
#include "gin/dictionary.h"
109
#include "native_mate/constructor.h"
11-
#include "native_mate/object_template_builder.h"
1210
#include "shell/browser/native_window.h"
1311
#include "shell/common/gin_converters/callback_converter.h"
12+
#include "shell/common/gin_converters/image_converter.h"
13+
#include "shell/common/gin_helper/dictionary.h"
14+
#include "shell/common/gin_helper/object_template_builder.h"
1415
#include "shell/common/native_mate_converters/accelerator_converter.h"
15-
#include "shell/common/native_mate_converters/image_converter.h"
16-
#include "shell/common/native_mate_converters/string16_converter.h"
1716
#include "shell/common/node_includes.h"
1817

19-
// TODO(zcbenz): Remove this after removing mate::ObjectTemplateBuilder.
20-
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
21-
2218
namespace {
19+
2320
// We need this map to keep references to currently opened menus.
2421
// Without this menus would be destroyed by js garbage collector
2522
// even when they are still displayed.
2623
std::map<uint32_t, v8::Global<v8::Object>> g_menus;
24+
2725
} // unnamed namespace
2826

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

270-
mate::Dictionary dict(isolate, exports);
268+
gin_helper::Dictionary dict(isolate, exports);
271269
dict.Set(
272270
"Menu",
273271
Menu::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());

Diff for: shell/browser/api/atom_api_menu.h

+14
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,20 @@ struct Converter<electron::AtomMenuModel*> {
155155
}
156156
};
157157

158+
// TODO(zcbenz): Remove this after converting Menu to gin::Wrapper.
159+
template <>
160+
struct Converter<electron::api::Menu*> {
161+
static bool FromV8(v8::Isolate* isolate,
162+
v8::Local<v8::Value> val,
163+
electron::api::Menu** out) {
164+
return mate::ConvertFromV8(isolate, val, out);
165+
}
166+
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
167+
electron::api::Menu* in) {
168+
return mate::ConvertToV8(isolate, in);
169+
}
170+
};
171+
158172
} // namespace gin
159173

160174
#endif // SHELL_BROWSER_API_ATOM_API_MENU_H_

Diff for: shell/browser/api/atom_api_native_theme.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "content/public/browser/browser_task_traits.h"
1111
#include "content/public/browser/browser_thread.h"
1212
#include "native_mate/dictionary.h"
13-
#include "native_mate/object_template_builder.h"
13+
#include "native_mate/object_template_builder_deprecated.h"
1414
#include "shell/common/node_includes.h"
1515
#include "ui/gfx/color_utils.h"
1616
#include "ui/native_theme/native_theme.h"

Diff for: shell/browser/api/atom_api_notification.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "base/strings/utf_string_conversions.h"
99
#include "native_mate/constructor.h"
1010
#include "native_mate/dictionary.h"
11-
#include "native_mate/object_template_builder.h"
11+
#include "native_mate/object_template_builder_deprecated.h"
1212
#include "shell/browser/api/atom_api_menu.h"
1313
#include "shell/browser/atom_browser_client.h"
1414
#include "shell/browser/browser.h"

Diff for: shell/browser/api/atom_api_screen.cc

+10-10
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
#include "base/bind.h"
1111
#include "gin/dictionary.h"
12-
#include "native_mate/object_template_builder.h"
1312
#include "shell/browser/browser.h"
1413
#include "shell/common/gin_converters/callback_converter.h"
14+
#include "shell/common/gin_helper/object_template_builder.h"
1515
#include "shell/common/native_mate_converters/gfx_converter.h"
1616
#include "shell/common/native_mate_converters/native_window_converter.h"
1717
#include "shell/common/node_includes.h"
@@ -134,22 +134,22 @@ void Screen::OnDisplayMetricsChanged(const display::Display& display,
134134
}
135135

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

145144
display::Screen* screen = display::Screen::GetScreen();
146145
if (!screen) {
147-
isolate->ThrowException(v8::Exception::Error(
148-
mate::StringToV8(isolate, "Failed to get screen information")));
149-
return v8::Null(isolate);
146+
error_thrower.ThrowError("Failed to get screen information");
147+
return v8::Null(error_thrower.isolate());
150148
}
151149

152-
return mate::CreateHandle(isolate, new Screen(isolate, screen)).ToV8();
150+
return mate::CreateHandle(error_thrower.isolate(),
151+
new Screen(error_thrower.isolate(), screen))
152+
.ToV8();
153153
}
154154

155155
// static

Diff for: shell/browser/api/atom_api_screen.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
#include <vector>
99

10-
#include "native_mate/handle.h"
1110
#include "shell/browser/api/event_emitter.h"
11+
#include "shell/common/gin_helper/error_thrower.h"
1212
#include "ui/display/display_observer.h"
1313
#include "ui/display/screen.h"
1414

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

3030
static void BuildPrototype(v8::Isolate* isolate,
3131
v8::Local<v8::FunctionTemplate> prototype);

Diff for: shell/browser/api/atom_api_session.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include "mojo/public/cpp/bindings/pending_remote.h"
3434
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
3535
#include "native_mate/dictionary.h"
36-
#include "native_mate/object_template_builder.h"
36+
#include "native_mate/object_template_builder_deprecated.h"
3737
#include "net/base/completion_repeating_callback.h"
3838
#include "net/base/load_flags.h"
3939
#include "net/http/http_auth_handler_factory.h"

Diff for: shell/browser/api/atom_api_session.h

+18
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,22 @@ class Session : public mate::TrackableObject<Session>,
121121

122122
} // namespace electron
123123

124+
namespace gin {
125+
126+
// TODO(zcbenz): Remove this after converting Session to gin::Wrapper.
127+
template <>
128+
struct Converter<electron::api::Session*> {
129+
static bool FromV8(v8::Isolate* isolate,
130+
v8::Local<v8::Value> val,
131+
electron::api::Session** out) {
132+
return mate::ConvertFromV8(isolate, val, out);
133+
}
134+
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
135+
electron::api::Session* in) {
136+
return mate::ConvertToV8(isolate, in);
137+
}
138+
};
139+
140+
} // namespace gin
141+
124142
#endif // SHELL_BROWSER_API_ATOM_API_SESSION_H_

Diff for: shell/browser/api/atom_api_system_preferences_mac.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "base/strings/sys_string_conversions.h"
2222
#include "base/threading/sequenced_task_runner_handle.h"
2323
#include "base/values.h"
24-
#include "native_mate/object_template_builder.h"
24+
#include "native_mate/object_template_builder_deprecated.h"
2525
#include "net/base/mac/url_conversions.h"
2626
#include "shell/browser/mac/atom_application.h"
2727
#include "shell/browser/mac/dict_util.h"

0 commit comments

Comments
 (0)