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

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

View file

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

View file

@ -2,7 +2,7 @@
// 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/api/event_emitter_caller_deprecated.h"
#include "shell/common/api/locker.h"
#include "shell/common/node_includes.h"

View file

@ -2,8 +2,12 @@
// 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_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>
@ -66,4 +70,4 @@ v8::Local<v8::Value> CustomEmit(v8::Isolate* isolate,
} // namespace mate
#endif // SHELL_COMMON_API_EVENT_EMITTER_CALLER_H_
#endif // SHELL_COMMON_API_EVENT_EMITTER_CALLER_DEPRECATED_H_