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
This commit is contained in:
Cheng Zhao 2019-09-06 14:52:54 +09:00 committed by GitHub
parent 7be1905023
commit 2c23e44ed9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
61 changed files with 515 additions and 323 deletions

View file

@ -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) {

View file

@ -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_;

View file

@ -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()) {

View file

@ -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() {

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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));

View file

@ -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"

View file

@ -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 {

View file

@ -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;

View file

@ -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_

View file

@ -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"

View file

@ -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());

View file

@ -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());

View file

@ -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"

View file

@ -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();

View file

@ -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") {

View file

@ -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));

View file

@ -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"

View file

@ -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_

View file

@ -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;