chore: remove native_mate (Part 12) (#20869)

* refactor: move mate::Event to gin

* refactor: move mate::Locker to gin

* refactor: convert contextBridge to gin

* refactor: convert contentTracing to gin

* refactor: remove callback converter of native_mate

* refactor: remove file_dialog_converter and native_window_converter from native_mate

* refactor: convert webFrame to gin

* refactor: move blink_converter to gin

* refactor: remove net_converter from native_mate

* refactor: remove event_emitter_caller_deprecated

* refactor: remove gurl_converter from native_mate

* refactor: remove file_path and string16_converter from native_mate

* refactor: remove image_converter from native_mate

* refactor: move value_converter to gin
This commit is contained in:
Cheng Zhao 2019-10-31 16:56:00 +09:00 committed by GitHub
parent 6781d5e3c8
commit 3ae3233e65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
96 changed files with 622 additions and 1711 deletions

View file

@ -6,15 +6,13 @@
#include <vector>
#include "native_mate/arguments.h"
#include "native_mate/dictionary.h"
#include "native_mate/object_template_builder_deprecated.h"
#include "native_mate/wrappable.h"
#include "shell/common/asar/archive.h"
#include "shell/common/asar/asar_util.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/native_mate_converters/file_path_converter.h"
#include "shell/common/gin_helper/object_template_builder.h"
#include "shell/common/node_includes.h"
#include "shell/common/node_util.h"
namespace {
@ -31,8 +29,8 @@ class Archive : public mate::Wrappable<Archive> {
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "Archive"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
prototype->SetClassName(gin::StringToV8(isolate, "Archive"));
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetProperty("path", &Archive::GetPath)
.SetMethod("getFileInfo", &Archive::GetFileInfo)
.SetMethod("stat", &Archive::Stat)
@ -84,7 +82,7 @@ class Archive : public mate::Wrappable<Archive> {
std::vector<base::FilePath> files;
if (!archive_ || !archive_->Readdir(path, &files))
return v8::False(isolate);
return mate::ConvertToV8(isolate, files);
return gin::ConvertToV8(isolate, files);
}
// Returns the path of file with symbol link resolved.
@ -93,7 +91,7 @@ class Archive : public mate::Wrappable<Archive> {
base::FilePath realpath;
if (!archive_ || !archive_->Realpath(path, &realpath))
return v8::False(isolate);
return mate::ConvertToV8(isolate, realpath);
return gin::ConvertToV8(isolate, realpath);
}
// Copy the file out into a temporary file and returns the new path.
@ -102,7 +100,7 @@ class Archive : public mate::Wrappable<Archive> {
base::FilePath new_path;
if (!archive_ || !archive_->CopyFileOut(path, &new_path))
return v8::False(isolate);
return mate::ConvertToV8(isolate, new_path);
return gin::ConvertToV8(isolate, new_path);
}
// Return the file descriptor.
@ -130,7 +128,7 @@ void InitAsarSupport(v8::Isolate* isolate, v8::Local<v8::Value> require) {
v8::Local<v8::Value> SplitPath(v8::Isolate* isolate,
const base::FilePath& path) {
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate);
base::FilePath asar_path, file_path;
if (asar::GetAsarArchivePath(path, &asar_path, &file_path, true)) {
dict.Set("isAsar", true);

View file

@ -5,8 +5,8 @@
#include "shell/common/api/atom_api_clipboard.h"
#include "base/strings/utf_string_conversions.h"
#include "shell/common/native_mate_converters/image_converter.h"
#include "shell/common/native_mate_converters/string16_converter.h"
#include "shell/common/gin_converters/image_converter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/node_includes.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkImageInfo.h"
@ -18,7 +18,7 @@ namespace electron {
namespace api {
ui::ClipboardBuffer Clipboard::GetClipboardBuffer(mate::Arguments* args) {
ui::ClipboardBuffer Clipboard::GetClipboardBuffer(gin_helper::Arguments* args) {
std::string type;
if (args->GetNext(&type) && type == "selection")
return ui::ClipboardBuffer::kSelection;
@ -26,7 +26,8 @@ ui::ClipboardBuffer Clipboard::GetClipboardBuffer(mate::Arguments* args) {
return ui::ClipboardBuffer::kCopyPaste;
}
std::vector<base::string16> Clipboard::AvailableFormats(mate::Arguments* args) {
std::vector<base::string16> Clipboard::AvailableFormats(
gin_helper::Arguments* args) {
std::vector<base::string16> format_types;
bool ignore;
ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
@ -35,7 +36,8 @@ std::vector<base::string16> Clipboard::AvailableFormats(mate::Arguments* args) {
return format_types;
}
bool Clipboard::Has(const std::string& format_string, mate::Arguments* args) {
bool Clipboard::Has(const std::string& format_string,
gin_helper::Arguments* args) {
ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
ui::ClipboardFormatType format(
ui::ClipboardFormatType::GetType(format_string));
@ -53,7 +55,7 @@ std::string Clipboard::Read(const std::string& format_string) {
}
v8::Local<v8::Value> Clipboard::ReadBuffer(const std::string& format_string,
mate::Arguments* args) {
gin_helper::Arguments* args) {
std::string data = Read(format_string);
return node::Buffer::Copy(args->isolate(), data.data(), data.length())
.ToLocalChecked();
@ -61,7 +63,7 @@ v8::Local<v8::Value> Clipboard::ReadBuffer(const std::string& format_string,
void Clipboard::WriteBuffer(const std::string& format,
const v8::Local<v8::Value> buffer,
mate::Arguments* args) {
gin_helper::Arguments* args) {
if (!node::Buffer::HasInstance(buffer)) {
args->ThrowError("buffer must be a node Buffer");
return;
@ -76,7 +78,8 @@ void Clipboard::WriteBuffer(const std::string& format,
mojo_base::BigBuffer(payload_span));
}
void Clipboard::Write(const mate::Dictionary& data, mate::Arguments* args) {
void Clipboard::Write(const gin_helper::Dictionary& data,
gin_helper::Arguments* args) {
ui::ScopedClipboardWriter writer(GetClipboardBuffer(args));
base::string16 text, html, bookmark;
gfx::Image image;
@ -100,7 +103,7 @@ void Clipboard::Write(const mate::Dictionary& data, mate::Arguments* args) {
writer.WriteImage(image.AsBitmap());
}
base::string16 Clipboard::ReadText(mate::Arguments* args) {
base::string16 Clipboard::ReadText(gin_helper::Arguments* args) {
base::string16 data;
ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
auto type = GetClipboardBuffer(args);
@ -116,24 +119,25 @@ base::string16 Clipboard::ReadText(mate::Arguments* args) {
return data;
}
void Clipboard::WriteText(const base::string16& text, mate::Arguments* args) {
void Clipboard::WriteText(const base::string16& text,
gin_helper::Arguments* args) {
ui::ScopedClipboardWriter writer(GetClipboardBuffer(args));
writer.WriteText(text);
}
base::string16 Clipboard::ReadRTF(mate::Arguments* args) {
base::string16 Clipboard::ReadRTF(gin_helper::Arguments* args) {
std::string data;
ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
clipboard->ReadRTF(GetClipboardBuffer(args), &data);
return base::UTF8ToUTF16(data);
}
void Clipboard::WriteRTF(const std::string& text, mate::Arguments* args) {
void Clipboard::WriteRTF(const std::string& text, gin_helper::Arguments* args) {
ui::ScopedClipboardWriter writer(GetClipboardBuffer(args));
writer.WriteRTF(text);
}
base::string16 Clipboard::ReadHTML(mate::Arguments* args) {
base::string16 Clipboard::ReadHTML(gin_helper::Arguments* args) {
base::string16 data;
base::string16 html;
std::string url;
@ -145,15 +149,17 @@ base::string16 Clipboard::ReadHTML(mate::Arguments* args) {
return data;
}
void Clipboard::WriteHTML(const base::string16& html, mate::Arguments* args) {
void Clipboard::WriteHTML(const base::string16& html,
gin_helper::Arguments* args) {
ui::ScopedClipboardWriter writer(GetClipboardBuffer(args));
writer.WriteHTML(html, std::string());
}
v8::Local<v8::Value> Clipboard::ReadBookmark(mate::Arguments* args) {
v8::Local<v8::Value> Clipboard::ReadBookmark(gin_helper::Arguments* args) {
base::string16 title;
std::string url;
mate::Dictionary dict = mate::Dictionary::CreateEmpty(args->isolate());
gin_helper::Dictionary dict =
gin_helper::Dictionary::CreateEmpty(args->isolate());
ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
clipboard->ReadBookmark(&title, &url);
dict.Set("title", title);
@ -163,18 +169,19 @@ v8::Local<v8::Value> Clipboard::ReadBookmark(mate::Arguments* args) {
void Clipboard::WriteBookmark(const base::string16& title,
const std::string& url,
mate::Arguments* args) {
gin_helper::Arguments* args) {
ui::ScopedClipboardWriter writer(GetClipboardBuffer(args));
writer.WriteBookmark(title, url);
}
gfx::Image Clipboard::ReadImage(mate::Arguments* args) {
gfx::Image Clipboard::ReadImage(gin_helper::Arguments* args) {
ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
SkBitmap bitmap = clipboard->ReadImage(GetClipboardBuffer(args));
return gfx::Image::CreateFrom1xBitmap(bitmap);
}
void Clipboard::WriteImage(const gfx::Image& image, mate::Arguments* args) {
void Clipboard::WriteImage(const gfx::Image& image,
gin_helper::Arguments* args) {
ui::ScopedClipboardWriter writer(GetClipboardBuffer(args));
SkBitmap orig = image.AsBitmap();
SkBitmap bmp;
@ -192,7 +199,7 @@ base::string16 Clipboard::ReadFindText() {
}
#endif
void Clipboard::Clear(mate::Arguments* args) {
void Clipboard::Clear(gin_helper::Arguments* args) {
ui::Clipboard::GetForCurrentThread()->Clear(GetClipboardBuffer(args));
}
@ -206,7 +213,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("availableFormats",
&electron::api::Clipboard::AvailableFormats);
dict.SetMethod("has", &electron::api::Clipboard::Has);

View file

@ -8,10 +8,14 @@
#include <string>
#include <vector>
#include "native_mate/arguments.h"
#include "native_mate/dictionary.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/gfx/image/image.h"
#include "v8/include/v8.h"
namespace gin_helper {
class Arguments;
class Dictionary;
} // namespace gin_helper
namespace electron {
@ -19,39 +23,44 @@ namespace api {
class Clipboard {
public:
static ui::ClipboardBuffer GetClipboardBuffer(mate::Arguments* args);
static std::vector<base::string16> AvailableFormats(mate::Arguments* args);
static bool Has(const std::string& format_string, mate::Arguments* args);
static void Clear(mate::Arguments* args);
static ui::ClipboardBuffer GetClipboardBuffer(gin_helper::Arguments* args);
static std::vector<base::string16> AvailableFormats(
gin_helper::Arguments* args);
static bool Has(const std::string& format_string,
gin_helper::Arguments* args);
static void Clear(gin_helper::Arguments* args);
static std::string Read(const std::string& format_string);
static void Write(const mate::Dictionary& data, mate::Arguments* args);
static void Write(const gin_helper::Dictionary& data,
gin_helper::Arguments* args);
static base::string16 ReadText(mate::Arguments* args);
static void WriteText(const base::string16& text, mate::Arguments* args);
static base::string16 ReadText(gin_helper::Arguments* args);
static void WriteText(const base::string16& text,
gin_helper::Arguments* args);
static base::string16 ReadRTF(mate::Arguments* args);
static void WriteRTF(const std::string& text, mate::Arguments* args);
static base::string16 ReadRTF(gin_helper::Arguments* args);
static void WriteRTF(const std::string& text, gin_helper::Arguments* args);
static base::string16 ReadHTML(mate::Arguments* args);
static void WriteHTML(const base::string16& html, mate::Arguments* args);
static base::string16 ReadHTML(gin_helper::Arguments* args);
static void WriteHTML(const base::string16& html,
gin_helper::Arguments* args);
static v8::Local<v8::Value> ReadBookmark(mate::Arguments* args);
static v8::Local<v8::Value> ReadBookmark(gin_helper::Arguments* args);
static void WriteBookmark(const base::string16& title,
const std::string& url,
mate::Arguments* args);
gin_helper::Arguments* args);
static gfx::Image ReadImage(mate::Arguments* args);
static void WriteImage(const gfx::Image& image, mate::Arguments* args);
static gfx::Image ReadImage(gin_helper::Arguments* args);
static void WriteImage(const gfx::Image& image, gin_helper::Arguments* args);
static base::string16 ReadFindText();
static void WriteFindText(const base::string16& text);
static v8::Local<v8::Value> ReadBuffer(const std::string& format_string,
mate::Arguments* args);
gin_helper::Arguments* args);
static void WriteBuffer(const std::string& format_string,
const v8::Local<v8::Value> buffer,
mate::Arguments* args);
gin_helper::Arguments* args);
private:
DISALLOW_COPY_AND_ASSIGN(Clipboard);

View file

@ -5,11 +5,9 @@
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/strings/string_util.h"
#include "native_mate/converter.h"
#include "native_mate/dictionary.h"
#include "services/network/public/cpp/network_switches.h"
#include "shell/common/native_mate_converters/file_path_converter.h"
#include "shell/common/native_mate_converters/string16_converter.h"
#include "shell/common/gin_converters/file_path_converter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/node_includes.h"
namespace {
@ -23,7 +21,8 @@ base::CommandLine::StringType GetSwitchValue(const std::string& name) {
name.c_str());
}
void AppendSwitch(const std::string& switch_string, mate::Arguments* args) {
void AppendSwitch(const std::string& switch_string,
gin_helper::Arguments* args) {
auto* command_line = base::CommandLine::ForCurrentProcess();
if (base::EndsWith(switch_string, "-path",
@ -47,7 +46,7 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Context> context,
void* priv) {
auto* command_line = base::CommandLine::ForCurrentProcess();
mate::Dictionary dict(context->GetIsolate(), exports);
gin_helper::Dictionary dict(context->GetIsolate(), exports);
dict.SetMethod("hasSwitch", &HasSwitch);
dict.SetMethod("getSwitchValue", &GetSwitchValue);
dict.SetMethod("appendSwitch", &AppendSwitch);

View file

@ -18,7 +18,7 @@
#include "shell/common/gin_converters/file_path_converter.h"
#include "shell/common/gin_converters/gfx_converter.h"
#include "shell/common/gin_converters/gurl_converter.h"
#include "shell/common/gin_converters/value_converter_gin_adapter.h"
#include "shell/common/gin_converters/value_converter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/gin_helper/object_template_builder.h"
#include "shell/common/node_includes.h"

View file

@ -6,10 +6,9 @@
#include "shell/common/gin_converters/callback_converter.h"
#include "shell/common/gin_converters/file_path_converter.h"
#include "shell/common/gin_converters/gurl_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"
#include "shell/common/platform_util.h"
#include "shell/common/promise_util.h"

View file

@ -18,16 +18,14 @@
#include "base/threading/thread_restrictions.h"
#include "chrome/common/chrome_version.h"
#include "electron/electron_version.h"
#include "native_mate/dictionary.h"
#include "services/resource_coordinator/public/cpp/memory_instrumentation/global_memory_dump.h"
#include "services/resource_coordinator/public/cpp/memory_instrumentation/memory_instrumentation.h"
#include "shell/browser/browser.h"
#include "shell/common/api/locker.h"
#include "shell/common/application_info.h"
#include "shell/common/gin_converters/file_path_converter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/gin_helper/locker.h"
#include "shell/common/heap_snapshot.h"
#include "shell/common/native_mate_converters/file_path_converter.h"
#include "shell/common/native_mate_converters/string16_converter.h"
#include "shell/common/node_includes.h"
#include "shell/common/promise_util.h"
#include "third_party/blink/renderer/platform/heap/process_heap.h" // nogncheck
@ -57,7 +55,7 @@ ElectronBindings::~ElectronBindings() {
// static
void ElectronBindings::BindProcess(v8::Isolate* isolate,
mate::Dictionary* process,
gin_helper::Dictionary* process,
base::ProcessMetrics* metrics) {
// These bindings are shared between sandboxed & unsandboxed renderers
process->SetMethod("crash", &Crash);
@ -89,7 +87,7 @@ void ElectronBindings::BindTo(v8::Isolate* isolate,
v8::Local<v8::Object> process) {
isolate->SetFatalErrorHandler(FatalErrorCallback);
mate::Dictionary dict(isolate, process);
gin_helper::Dictionary dict(isolate, process);
BindProcess(isolate, &dict, metrics_.get());
dict.SetMethod("takeHeapSnapshot", &TakeHeapSnapshot);
@ -100,7 +98,7 @@ void ElectronBindings::BindTo(v8::Isolate* isolate,
base::BindRepeating(&ElectronBindings::ActivateUVLoop,
base::Unretained(this)));
mate::Dictionary versions;
gin_helper::Dictionary versions;
if (dict.Get("versions", &versions)) {
versions.SetReadOnly(ELECTRON_PROJECT_NAME, ELECTRON_VERSION_STRING);
versions.SetReadOnly("chrome", CHROME_VERSION_STRING);
@ -131,7 +129,7 @@ void ElectronBindings::OnCallNextTick(uv_async_t* handle) {
self->pending_next_ticks_.begin();
it != self->pending_next_ticks_.end(); ++it) {
node::Environment* env = *it;
mate::Locker locker(env->isolate());
gin_helper::Locker locker(env->isolate());
v8::Context::Scope context_scope(env->context());
node::InternalCallbackScope scope(
env, v8::Local<v8::Object>(), {0, 0},
@ -201,7 +199,7 @@ v8::Local<v8::Value> ElectronBindings::GetCreationTime(v8::Isolate* isolate) {
// static
v8::Local<v8::Value> ElectronBindings::GetSystemMemoryInfo(
v8::Isolate* isolate,
mate::Arguments* args) {
gin_helper::Arguments* args) {
base::SystemMemoryInfoKB mem_info;
if (!base::GetSystemMemoryInfo(&mem_info)) {
args->ThrowError("Unable to retrieve system memory information");
@ -233,10 +231,10 @@ v8::Local<v8::Value> ElectronBindings::GetSystemMemoryInfo(
// static
v8::Local<v8::Promise> ElectronBindings::GetProcessMemoryInfo(
v8::Isolate* isolate) {
util::Promise<mate::Dictionary> promise(isolate);
util::Promise<gin_helper::Dictionary> promise(isolate);
v8::Local<v8::Promise> handle = promise.GetHandle();
if (mate::Locker::IsBrowserProcess() && !Browser::Get()->is_ready()) {
if (gin_helper::Locker::IsBrowserProcess() && !Browser::Get()->is_ready()) {
promise.RejectWithErrorMessage(
"Memory Info is available only after app ready");
return handle;
@ -267,11 +265,11 @@ v8::Local<v8::Value> ElectronBindings::GetBlinkMemoryInfo(
// static
void ElectronBindings::DidReceiveMemoryDump(
v8::Global<v8::Context> context,
util::Promise<mate::Dictionary> promise,
util::Promise<gin_helper::Dictionary> promise,
bool success,
std::unique_ptr<memory_instrumentation::GlobalMemoryDump> global_dump) {
v8::Isolate* isolate = promise.isolate();
mate::Locker locker(isolate);
gin_helper::Locker locker(isolate);
v8::HandleScope handle_scope(isolate);
v8::MicrotasksScope script_scope(isolate,
v8::MicrotasksScope::kRunMicrotasks);
@ -287,14 +285,14 @@ void ElectronBindings::DidReceiveMemoryDump(
for (const memory_instrumentation::GlobalMemoryDump::ProcessDump& dump :
global_dump->process_dumps()) {
if (base::GetCurrentProcId() == dump.pid()) {
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate);
const auto& osdump = dump.os_dump();
#if defined(OS_LINUX) || defined(OS_WIN)
dict.Set("residentSet", osdump.resident_set_kb);
#endif
dict.Set("private", osdump.private_footprint_kb);
dict.Set("shared", osdump.shared_footprint_kb);
promise.Resolve(dict);
promise.ResolveWithGin(dict);
resolved = true;
break;
}

View file

@ -13,14 +13,13 @@
#include "base/memory/scoped_refptr.h"
#include "base/process/process_metrics.h"
#include "base/strings/string16.h"
#include "native_mate/arguments.h"
#include "shell/common/promise_util.h"
#include "uv.h" // NOLINT(build/include)
#include "v8/include/v8.h"
namespace mate {
namespace gin_helper {
class Arguments;
class Dictionary;
}
} // namespace gin_helper
namespace memory_instrumentation {
class GlobalMemoryDump;
@ -45,7 +44,7 @@ class ElectronBindings {
void EnvironmentDestroyed(node::Environment* env);
static void BindProcess(v8::Isolate* isolate,
mate::Dictionary* process,
gin_helper::Dictionary* process,
base::ProcessMetrics* metrics);
static void Log(const base::string16& message);
@ -56,7 +55,7 @@ class ElectronBindings {
static v8::Local<v8::Value> GetHeapStatistics(v8::Isolate* isolate);
static v8::Local<v8::Value> GetCreationTime(v8::Isolate* isolate);
static v8::Local<v8::Value> GetSystemMemoryInfo(v8::Isolate* isolate,
mate::Arguments* args);
gin_helper::Arguments* args);
static v8::Local<v8::Promise> GetProcessMemoryInfo(v8::Isolate* isolate);
static v8::Local<v8::Value> GetBlinkMemoryInfo(v8::Isolate* isolate);
static v8::Local<v8::Value> GetCPUUsage(base::ProcessMetrics* metrics,
@ -71,7 +70,7 @@ class ElectronBindings {
static void DidReceiveMemoryDump(
v8::Global<v8::Context> context,
util::Promise<mate::Dictionary> promise,
util::Promise<gin_helper::Dictionary> promise,
bool success,
std::unique_ptr<memory_instrumentation::GlobalMemoryDump> dump);

View file

@ -1,38 +0,0 @@
// 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

View file

@ -1,73 +0,0 @@
// 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_

View file

@ -7,10 +7,8 @@
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "content/public/renderer/render_frame.h"
#include "electron/shell/common/api/api.mojom.h"
#include "electron/shell/common/native_mate_converters/blink_converter.h"
#include "electron/shell/common/native_mate_converters/value_converter.h"
#include "services/service_manager/public/cpp/interface_provider.h"
#include "shell/common/api/api.mojom.h"
#include "third_party/blink/public/web/web_local_frame.h"
using blink::WebLocalFrame;

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/native_mate_converters/blink_converter.h"
#include "shell/common/gin_converters/blink_converter.h"
#include <algorithm>
#include <string>
@ -14,10 +14,10 @@
#include "gin/converter.h"
#include "mojo/public/cpp/base/values_mojom_traits.h"
#include "mojo/public/mojom/base/values.mojom.h"
#include "native_mate/dictionary.h"
#include "shell/common/deprecate_util.h"
#include "shell/common/gin_converters/value_converter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/keyboard_util.h"
#include "shell/common/native_mate_converters/value_converter.h"
#include "third_party/blink/public/platform/web_input_event.h"
#include "third_party/blink/public/platform/web_keyboard_event.h"
#include "third_party/blink/public/platform/web_mouse_event.h"
@ -39,7 +39,7 @@ int VectorToBitArray(const std::vector<T>& vec) {
} // namespace
namespace mate {
namespace gin {
template <>
struct Converter<base::char16> {
@ -149,7 +149,7 @@ struct Converter<blink::WebInputEvent::Modifiers> {
blink::WebInputEvent::Type GetWebInputEventType(v8::Isolate* isolate,
v8::Local<v8::Value> val) {
blink::WebInputEvent::Type type = blink::WebInputEvent::kUndefined;
mate::Dictionary dict;
gin_helper::Dictionary dict;
ConvertFromV8(isolate, val, &dict) && dict.Get("type", &type);
return type;
}
@ -157,7 +157,7 @@ blink::WebInputEvent::Type GetWebInputEventType(v8::Isolate* isolate,
bool Converter<blink::WebInputEvent>::FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
blink::WebInputEvent* out) {
mate::Dictionary dict;
gin_helper::Dictionary dict;
if (!ConvertFromV8(isolate, val, &dict))
return false;
blink::WebInputEvent::Type type;
@ -174,7 +174,7 @@ bool Converter<blink::WebInputEvent>::FromV8(v8::Isolate* isolate,
bool Converter<blink::WebKeyboardEvent>::FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
blink::WebKeyboardEvent* out) {
mate::Dictionary dict;
gin_helper::Dictionary dict;
if (!ConvertFromV8(isolate, val, &dict))
return false;
if (!ConvertFromV8(isolate, val, static_cast<blink::WebInputEvent*>(out)))
@ -219,7 +219,7 @@ bool Converter<blink::WebKeyboardEvent>::FromV8(v8::Isolate* isolate,
bool Converter<blink::WebMouseEvent>::FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
blink::WebMouseEvent* out) {
mate::Dictionary dict;
gin_helper::Dictionary dict;
if (!ConvertFromV8(isolate, val, &dict))
return false;
if (!ConvertFromV8(isolate, val, static_cast<blink::WebInputEvent*>(out)))
@ -250,7 +250,7 @@ bool Converter<blink::WebMouseWheelEvent>::FromV8(
v8::Isolate* isolate,
v8::Local<v8::Value> val,
blink::WebMouseWheelEvent* out) {
mate::Dictionary dict;
gin_helper::Dictionary dict;
if (!ConvertFromV8(isolate, val, &dict))
return false;
if (!ConvertFromV8(isolate, val, static_cast<blink::WebMouseEvent*>(out)))
@ -285,7 +285,7 @@ bool Converter<blink::WebMouseWheelEvent>::FromV8(
bool Converter<blink::WebFloatPoint>::FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
blink::WebFloatPoint* out) {
mate::Dictionary dict;
gin_helper::Dictionary dict;
if (!ConvertFromV8(isolate, val, &dict))
return false;
return dict.Get("x", &out->x) && dict.Get("y", &out->y);
@ -296,7 +296,7 @@ struct Converter<base::Optional<blink::WebPoint>> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
base::Optional<blink::WebPoint>* out) {
mate::Dictionary dict;
gin_helper::Dictionary dict;
if (!ConvertFromV8(isolate, val, &dict))
return false;
blink::WebPoint point;
@ -311,7 +311,7 @@ struct Converter<base::Optional<blink::WebPoint>> {
bool Converter<blink::WebSize>::FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
blink::WebSize* out) {
mate::Dictionary dict;
gin_helper::Dictionary dict;
if (!ConvertFromV8(isolate, val, &dict))
return false;
return dict.Get("width", &out->width) && dict.Get("height", &out->height);
@ -321,7 +321,7 @@ bool Converter<blink::WebDeviceEmulationParams>::FromV8(
v8::Isolate* isolate,
v8::Local<v8::Value> val,
blink::WebDeviceEmulationParams* out) {
mate::Dictionary dict;
gin_helper::Dictionary dict;
if (!ConvertFromV8(isolate, val, &dict))
return false;
@ -350,19 +350,19 @@ v8::Local<v8::Value> Converter<blink::WebContextMenuData::MediaType>::ToV8(
const blink::WebContextMenuData::MediaType& in) {
switch (in) {
case blink::WebContextMenuData::kMediaTypeImage:
return mate::StringToV8(isolate, "image");
return StringToV8(isolate, "image");
case blink::WebContextMenuData::kMediaTypeVideo:
return mate::StringToV8(isolate, "video");
return StringToV8(isolate, "video");
case blink::WebContextMenuData::kMediaTypeAudio:
return mate::StringToV8(isolate, "audio");
return StringToV8(isolate, "audio");
case blink::WebContextMenuData::kMediaTypeCanvas:
return mate::StringToV8(isolate, "canvas");
return StringToV8(isolate, "canvas");
case blink::WebContextMenuData::kMediaTypeFile:
return mate::StringToV8(isolate, "file");
return StringToV8(isolate, "file");
case blink::WebContextMenuData::kMediaTypePlugin:
return mate::StringToV8(isolate, "plugin");
return StringToV8(isolate, "plugin");
default:
return mate::StringToV8(isolate, "none");
return StringToV8(isolate, "none");
}
}
@ -372,18 +372,18 @@ v8::Local<v8::Value> Converter<blink::WebContextMenuData::InputFieldType>::ToV8(
const blink::WebContextMenuData::InputFieldType& in) {
switch (in) {
case blink::WebContextMenuData::kInputFieldTypePlainText:
return mate::StringToV8(isolate, "plainText");
return StringToV8(isolate, "plainText");
case blink::WebContextMenuData::kInputFieldTypePassword:
return mate::StringToV8(isolate, "password");
return StringToV8(isolate, "password");
case blink::WebContextMenuData::kInputFieldTypeOther:
return mate::StringToV8(isolate, "other");
return StringToV8(isolate, "other");
default:
return mate::StringToV8(isolate, "none");
return StringToV8(isolate, "none");
}
}
v8::Local<v8::Value> EditFlagsToV8(v8::Isolate* isolate, int editFlags) {
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate);
dict.Set("canUndo", !!(editFlags & blink::WebContextMenuData::kCanUndo));
dict.Set("canRedo", !!(editFlags & blink::WebContextMenuData::kCanRedo));
dict.Set("canCut", !!(editFlags & blink::WebContextMenuData::kCanCut));
@ -403,11 +403,11 @@ v8::Local<v8::Value> EditFlagsToV8(v8::Isolate* isolate, int editFlags) {
dict.Set("canSelectAll",
!!(editFlags & blink::WebContextMenuData::kCanSelectAll));
return mate::ConvertToV8(isolate, dict);
return ConvertToV8(isolate, dict);
}
v8::Local<v8::Value> MediaFlagsToV8(v8::Isolate* isolate, int mediaFlags) {
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate);
dict.Set("inError",
!!(mediaFlags & blink::WebContextMenuData::kMediaInError));
dict.Set("isPaused",
@ -423,13 +423,13 @@ v8::Local<v8::Value> MediaFlagsToV8(v8::Isolate* isolate, int mediaFlags) {
!!(mediaFlags & blink::WebContextMenuData::kMediaCanToggleControls));
dict.Set("canRotate",
!!(mediaFlags & blink::WebContextMenuData::kMediaCanRotate));
return mate::ConvertToV8(isolate, dict);
return ConvertToV8(isolate, dict);
}
v8::Local<v8::Value> Converter<blink::WebCacheResourceTypeStat>::ToV8(
v8::Isolate* isolate,
const blink::WebCacheResourceTypeStat& stat) {
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate);
dict.Set("count", static_cast<uint32_t>(stat.count));
dict.Set("size", static_cast<double>(stat.size));
dict.Set("liveSize", static_cast<double>(stat.decoded_size));
@ -439,7 +439,7 @@ v8::Local<v8::Value> Converter<blink::WebCacheResourceTypeStat>::ToV8(
v8::Local<v8::Value> Converter<blink::WebCacheResourceTypeStats>::ToV8(
v8::Isolate* isolate,
const blink::WebCacheResourceTypeStats& stats) {
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate);
dict.Set("images", stats.images);
dict.Set("scripts", stats.scripts);
dict.Set("cssStyleSheets", stats.css_style_sheets);
@ -455,24 +455,24 @@ v8::Local<v8::Value> Converter<network::mojom::ReferrerPolicy>::ToV8(
const network::mojom::ReferrerPolicy& in) {
switch (in) {
case network::mojom::ReferrerPolicy::kDefault:
return mate::StringToV8(isolate, "default");
return StringToV8(isolate, "default");
case network::mojom::ReferrerPolicy::kAlways:
return mate::StringToV8(isolate, "unsafe-url");
return StringToV8(isolate, "unsafe-url");
case network::mojom::ReferrerPolicy::kNoReferrerWhenDowngrade:
return mate::StringToV8(isolate, "no-referrer-when-downgrade");
return StringToV8(isolate, "no-referrer-when-downgrade");
case network::mojom::ReferrerPolicy::kNever:
return mate::StringToV8(isolate, "no-referrer");
return StringToV8(isolate, "no-referrer");
case network::mojom::ReferrerPolicy::kOrigin:
return mate::StringToV8(isolate, "origin");
return StringToV8(isolate, "origin");
case network::mojom::ReferrerPolicy::
kNoReferrerWhenDowngradeOriginWhenCrossOrigin:
return mate::StringToV8(isolate, "strict-origin-when-cross-origin");
return StringToV8(isolate, "strict-origin-when-cross-origin");
case network::mojom::ReferrerPolicy::kSameOrigin:
return mate::StringToV8(isolate, "same-origin");
return StringToV8(isolate, "same-origin");
case network::mojom::ReferrerPolicy::kStrictOrigin:
return mate::StringToV8(isolate, "strict-origin");
return StringToV8(isolate, "strict-origin");
default:
return mate::StringToV8(isolate, "no-referrer");
return StringToV8(isolate, "no-referrer");
}
}
@ -523,7 +523,7 @@ class V8Serializer : public v8::ValueSerializer::Delegate {
WriteTag(kOldSerializationTag);
if (!WriteBaseValue(value)) {
isolate_->ThrowException(
mate::StringToV8(isolate_, "An object could not be cloned."));
StringToV8(isolate_, "An object could not be cloned."));
return false;
}
} else {
@ -684,4 +684,4 @@ bool Converter<blink::CloneableMessage>::FromV8(v8::Isolate* isolate,
return V8Serializer(isolate).Serialize(val, out);
}
} // namespace mate
} // namespace gin

View file

@ -2,10 +2,10 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_COMMON_NATIVE_MATE_CONVERTERS_BLINK_CONVERTER_H_
#define SHELL_COMMON_NATIVE_MATE_CONVERTERS_BLINK_CONVERTER_H_
#ifndef SHELL_COMMON_GIN_CONVERTERS_BLINK_CONVERTER_H_
#define SHELL_COMMON_GIN_CONVERTERS_BLINK_CONVERTER_H_
#include "native_mate/converter.h"
#include "gin/converter.h"
#include "third_party/blink/public/common/messaging/cloneable_message.h"
#include "third_party/blink/public/common/web_cache/web_cache_resource_type_stats.h"
#include "third_party/blink/public/platform/web_input_event.h"
@ -21,7 +21,7 @@ struct WebPoint;
struct WebSize;
} // namespace blink
namespace mate {
namespace gin {
blink::WebInputEvent::Type GetWebInputEventType(v8::Isolate* isolate,
v8::Local<v8::Value> val);
@ -130,6 +130,6 @@ struct Converter<blink::CloneableMessage> {
v8::Local<v8::Value> EditFlagsToV8(v8::Isolate* isolate, int editFlags);
v8::Local<v8::Value> MediaFlagsToV8(v8::Isolate* isolate, int mediaFlags);
} // namespace mate
} // namespace gin
#endif // SHELL_COMMON_NATIVE_MATE_CONVERTERS_BLINK_CONVERTER_H_
#endif // SHELL_COMMON_GIN_CONVERTERS_BLINK_CONVERTER_H_

View file

@ -1,79 +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_GIN_CONVERTERS_BLINK_CONVERTER_GIN_ADAPTER_H_
#define SHELL_COMMON_GIN_CONVERTERS_BLINK_CONVERTER_GIN_ADAPTER_H_
#include "gin/converter.h"
#include "shell/common/native_mate_converters/blink_converter.h"
// TODO(zcbenz): Move the implementations from native_mate_converters to here.
namespace gin {
template <>
struct Converter<blink::WebKeyboardEvent> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
blink::WebKeyboardEvent* out) {
return mate::ConvertFromV8(isolate, val, out);
}
};
template <>
struct Converter<blink::CloneableMessage> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
blink::CloneableMessage* out) {
return mate::ConvertFromV8(isolate, val, out);
}
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const blink::CloneableMessage& val) {
return mate::ConvertToV8(isolate, val);
}
};
template <>
struct Converter<blink::WebDeviceEmulationParams> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
blink::WebDeviceEmulationParams* out) {
return mate::ConvertFromV8(isolate, val, out);
}
};
template <>
struct Converter<blink::WebContextMenuData::MediaType> {
static v8::Local<v8::Value> ToV8(
v8::Isolate* isolate,
const blink::WebContextMenuData::MediaType& in) {
return mate::ConvertToV8(isolate, in);
}
};
template <>
struct Converter<blink::WebContextMenuData::InputFieldType> {
static v8::Local<v8::Value> ToV8(
v8::Isolate* isolate,
const blink::WebContextMenuData::InputFieldType& in) {
return mate::ConvertToV8(isolate, in);
}
};
template <>
struct Converter<network::mojom::ReferrerPolicy> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const network::mojom::ReferrerPolicy& in) {
return mate::ConvertToV8(isolate, in);
}
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
network::mojom::ReferrerPolicy* out) {
return mate::ConvertFromV8(isolate, val, out);
}
};
} // namespace gin
#endif // SHELL_COMMON_GIN_CONVERTERS_BLINK_CONVERTER_GIN_ADAPTER_H_

View file

@ -12,7 +12,7 @@
#include "content/public/common/context_menu_params.h"
#include "shell/browser/api/atom_api_web_contents.h"
#include "shell/browser/web_contents_permission_helper.h"
#include "shell/common/gin_converters/blink_converter_gin_adapter.h"
#include "shell/common/gin_converters/blink_converter.h"
#include "shell/common/gin_converters/callback_converter.h"
#include "shell/common/gin_converters/gurl_converter.h"
#include "shell/common/gin_helper/dictionary.h"
@ -128,13 +128,13 @@ v8::Local<v8::Value> Converter<ContextMenuParamsWithWebContents>::ToV8(
dict.Set("frameURL", params.frame_url);
dict.Set("srcURL", params.src_url);
dict.Set("mediaType", params.media_type);
dict.Set("mediaFlags", mate::MediaFlagsToV8(isolate, params.media_flags));
dict.Set("mediaFlags", MediaFlagsToV8(isolate, params.media_flags));
bool has_image_contents =
(params.media_type == blink::WebContextMenuData::kMediaTypeImage) &&
params.has_image_contents;
dict.Set("hasImageContents", has_image_contents);
dict.Set("isEditable", params.is_editable);
dict.Set("editFlags", mate::EditFlagsToV8(isolate, params.edit_flags));
dict.Set("editFlags", EditFlagsToV8(isolate, params.edit_flags));
dict.Set("selectionText", params.selection_text);
dict.Set("titleText", params.title_text);
dict.Set("misspelledWord", params.misspelled_word);

View file

@ -9,6 +9,7 @@
#include "gin/converter.h"
namespace gin {
template <>
struct Converter<base::FilePath> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,

View file

@ -14,10 +14,6 @@
#include "base/values.h"
#include "gin/converter.h"
#include "gin/dictionary.h"
#include "net/base/upload_bytes_element_reader.h"
#include "net/base/upload_data_stream.h"
#include "net/base/upload_element_reader.h"
#include "net/base/upload_file_element_reader.h"
#include "net/cert/x509_certificate.h"
#include "net/cert/x509_util.h"
#include "net/http/http_response_headers.h"
@ -25,7 +21,7 @@
#include "shell/browser/api/atom_api_data_pipe_holder.h"
#include "shell/common/gin_converters/gurl_converter.h"
#include "shell/common/gin_converters/std_converter.h"
#include "shell/common/gin_converters/value_converter_gin_adapter.h"
#include "shell/common/gin_converters/value_converter.h"
#include "shell/common/node_includes.h"
namespace gin {
@ -364,57 +360,3 @@ v8::Local<v8::Value> Converter<electron::VerifyRequestParams>::ToV8(
}
} // namespace gin
namespace electron {
void FillRequestDetails(base::DictionaryValue* details,
const net::URLRequest* request) {
details->SetString("method", request->method());
std::string url;
if (!request->url_chain().empty())
url = request->url().spec();
details->SetKey("url", base::Value(url));
details->SetString("referrer", request->referrer());
auto list = std::make_unique<base::ListValue>();
GetUploadData(list.get(), request);
if (!list->empty())
details->Set("uploadData", std::move(list));
auto headers_value = std::make_unique<base::DictionaryValue>();
for (net::HttpRequestHeaders::Iterator it(request->extra_request_headers());
it.GetNext();) {
headers_value->SetString(it.name(), it.value());
}
details->Set("headers", std::move(headers_value));
}
void GetUploadData(base::ListValue* upload_data_list,
const net::URLRequest* request) {
const net::UploadDataStream* upload_data = request->get_upload_for_testing();
if (!upload_data)
return;
const std::vector<std::unique_ptr<net::UploadElementReader>>* readers =
upload_data->GetElementReaders();
for (const auto& reader : *readers) {
auto upload_data_dict = std::make_unique<base::DictionaryValue>();
if (reader->AsBytesReader()) {
const net::UploadBytesElementReader* bytes_reader =
reader->AsBytesReader();
auto bytes = std::make_unique<base::Value>(
std::vector<char>(bytes_reader->bytes(),
bytes_reader->bytes() + bytes_reader->length()));
upload_data_dict->Set("bytes", std::move(bytes));
} else if (reader->AsFileReader()) {
const net::UploadFileElementReader* file_reader = reader->AsFileReader();
auto file_path = file_reader->path().AsUTF8Unsafe();
upload_data_dict->SetKey("file", base::Value(file_path));
}
// else {
// const storage::UploadBlobElementReader* blob_reader =
// static_cast<storage::UploadBlobElementReader*>(reader.get());
// upload_data_dict->SetString("blobUUID", blob_reader->uuid());
// }
upload_data_list->Append(std::move(upload_data_dict));
}
}
} // namespace electron

View file

@ -5,7 +5,6 @@
#ifndef SHELL_COMMON_GIN_CONVERTERS_NET_CONVERTER_H_
#define SHELL_COMMON_GIN_CONVERTERS_NET_CONVERTER_H_
#include "base/memory/ref_counted.h"
#include "gin/converter.h"
#include "shell/browser/net/cert_verifier_client.h"
@ -99,14 +98,4 @@ struct Converter<electron::VerifyRequestParams> {
} // namespace gin
namespace electron {
void FillRequestDetails(base::DictionaryValue* details,
const net::URLRequest* request);
void GetUploadData(base::ListValue* upload_data_list,
const net::URLRequest* request);
} // namespace electron
#endif // SHELL_COMMON_GIN_CONVERTERS_NET_CONVERTER_H_

View file

@ -2,15 +2,15 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/common/native_mate_converters/value_converter.h"
#include "shell/common/gin_converters/value_converter.h"
#include <memory>
#include <utility>
#include "base/values.h"
#include "shell/common/native_mate_converters/v8_value_converter.h"
#include "shell/common/v8_value_converter.h"
namespace mate {
namespace gin {
bool Converter<base::DictionaryValue>::FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
@ -74,4 +74,4 @@ v8::Local<v8::Value> Converter<base::ListValue>::ToV8(
return converter.ToV8Value(&val, isolate->GetCurrentContext());
}
} // namespace mate
} // namespace gin

View file

@ -2,12 +2,10 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_COMMON_NATIVE_MATE_CONVERTERS_VALUE_CONVERTER_H_
#define SHELL_COMMON_NATIVE_MATE_CONVERTERS_VALUE_CONVERTER_H_
#ifndef SHELL_COMMON_GIN_CONVERTERS_VALUE_CONVERTER_H_
#define SHELL_COMMON_GIN_CONVERTERS_VALUE_CONVERTER_H_
#include "native_mate/converter.h"
#include "base/optional.h"
#include "gin/converter.h"
namespace base {
class DictionaryValue;
@ -15,7 +13,7 @@ class ListValue;
class Value;
} // namespace base
namespace mate {
namespace gin {
template <>
struct Converter<base::DictionaryValue> {
@ -35,29 +33,6 @@ struct Converter<base::Value> {
const base::Value& val);
};
template <typename T>
struct Converter<base::Optional<T>> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
base::Optional<T>* out) {
if (val->IsNull() || val->IsUndefined()) {
return true;
}
T converted;
if (Converter<T>::FromV8(isolate, val, &converted)) {
return true;
}
out->emplace(converted);
return true;
}
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const base::Optional<T>& val) {
if (val.has_value())
return Converter<T>::ToV8(val.value());
return v8::Undefined(isolate);
}
};
template <>
struct Converter<base::ListValue> {
static bool FromV8(v8::Isolate* isolate,
@ -67,6 +42,6 @@ struct Converter<base::ListValue> {
const base::ListValue& val);
};
} // namespace mate
} // namespace gin
#endif // SHELL_COMMON_NATIVE_MATE_CONVERTERS_VALUE_CONVERTER_H_
#endif // SHELL_COMMON_GIN_CONVERTERS_VALUE_CONVERTER_H_

View file

@ -1,56 +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_GIN_CONVERTERS_VALUE_CONVERTER_GIN_ADAPTER_H_
#define SHELL_COMMON_GIN_CONVERTERS_VALUE_CONVERTER_GIN_ADAPTER_H_
#include "gin/converter.h"
#include "shell/common/native_mate_converters/value_converter.h"
// TODO(zcbenz): Move the implementations from native_mate_converters to here.
namespace gin {
template <>
struct Converter<base::DictionaryValue> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
base::DictionaryValue* out) {
return mate::ConvertFromV8(isolate, val, out);
}
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const base::DictionaryValue& val) {
return mate::ConvertToV8(isolate, val);
}
};
template <>
struct Converter<base::ListValue> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
base::ListValue* out) {
return mate::ConvertFromV8(isolate, val, out);
}
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const base::ListValue& val) {
return mate::ConvertToV8(isolate, val);
}
};
template <>
struct Converter<base::Value> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
base::Value* out) {
return mate::ConvertFromV8(isolate, val, out);
}
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const base::Value& in) {
return mate::ConvertToV8(isolate, in);
}
};
} // namespace gin
#endif // SHELL_COMMON_GIN_CONVERTERS_VALUE_CONVERTER_GIN_ADAPTER_H_

View file

@ -69,7 +69,7 @@ void CallTranslater(v8::Local<v8::External> external,
struct DeleteOnUIThread {
template <typename T>
static void Destruct(const T* x) {
if (mate::Locker::IsBrowserProcess() &&
if (gin_helper::Locker::IsBrowserProcess() &&
!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
content::BrowserThread::DeleteSoon(content::BrowserThread::UI, FROM_HERE,
x);

View file

@ -9,9 +9,9 @@
#include <vector>
#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"
#include "shell/common/gin_helper/locker.h"
// Implements safe convertions between JS functions and base::Callback.
@ -43,7 +43,7 @@ struct V8FunctionInvoker<v8::Local<v8::Value>(ArgTypes...)> {
static v8::Local<v8::Value> Go(v8::Isolate* isolate,
const SafeV8Function& function,
ArgTypes... raw) {
mate::Locker locker(isolate);
gin_helper::Locker locker(isolate);
v8::EscapableHandleScope handle_scope(isolate);
if (!function.IsAlive())
return v8::Null(isolate);
@ -68,7 +68,7 @@ struct V8FunctionInvoker<void(ArgTypes...)> {
static void Go(v8::Isolate* isolate,
const SafeV8Function& function,
ArgTypes... raw) {
mate::Locker locker(isolate);
gin_helper::Locker locker(isolate);
v8::HandleScope handle_scope(isolate);
if (!function.IsAlive())
return;
@ -91,7 +91,7 @@ struct V8FunctionInvoker<ReturnType(ArgTypes...)> {
static ReturnType Go(v8::Isolate* isolate,
const SafeV8Function& function,
ArgTypes... raw) {
mate::Locker locker(isolate);
gin_helper::Locker locker(isolate);
v8::HandleScope handle_scope(isolate);
ReturnType ret = ReturnType();
if (!function.IsAlive())

View file

@ -108,6 +108,26 @@ class Dictionary : public gin::Dictionary {
return !result.IsNothing() && result.FromJust();
}
// Note: If we plan to add more Set methods, consider adding an option instead
// of copying code.
template <typename T>
bool SetReadOnlyNonConfigurable(base::StringPiece key, 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,
static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete));
return !result.IsNothing() && result.FromJust();
}
bool Has(base::StringPiece key) const {
v8::Maybe<bool> result = GetHandle()->Has(isolate()->GetCurrentContext(),
gin::StringToV8(isolate(), key));
return !result.IsNothing() && result.FromJust();
}
bool Delete(base::StringPiece key) {
v8::Maybe<bool> result = GetHandle()->Delete(
isolate()->GetCurrentContext(), gin::StringToV8(isolate(), key));

View file

@ -68,11 +68,10 @@ v8::Local<v8::Object> CreateNativeEvent(
v8::Isolate* isolate,
v8::Local<v8::Object> sender,
content::RenderFrameHost* frame,
base::Optional<electron::mojom::ElectronBrowser::MessageSyncCallback>
callback) {
electron::mojom::ElectronBrowser::MessageSyncCallback callback) {
v8::Local<v8::Object> event;
if (frame && callback) {
mate::Handle<mate::Event> native_event = mate::Event::Create(isolate);
gin::Handle<Event> native_event = Event::Create(isolate);
native_event->SetCallback(std::move(callback));
event = v8::Local<v8::Object>::Cast(native_event.ToV8());
} else {

View file

@ -8,7 +8,6 @@
#include <utility>
#include <vector>
#include "base/optional.h"
#include "content/public/browser/browser_thread.h"
#include "electron/shell/common/api/api.mojom.h"
#include "native_mate/wrappable.h"
@ -31,8 +30,7 @@ v8::Local<v8::Object> CreateNativeEvent(
v8::Isolate* isolate,
v8::Local<v8::Object> sender,
content::RenderFrameHost* frame,
base::Optional<electron::mojom::ElectronBrowser::MessageSyncCallback>
callback);
electron::mojom::ElectronBrowser::MessageSyncCallback callback);
} // namespace internal
@ -83,11 +81,10 @@ class EventEmitter : public mate::Wrappable<T> {
// this.emit(name, new Event(sender, message), args...);
template <typename... Args>
bool EmitWithSender(
base::StringPiece name,
content::RenderFrameHost* sender,
base::Optional<electron::mojom::ElectronBrowser::InvokeCallback> callback,
Args&&... args) {
bool EmitWithSender(base::StringPiece name,
content::RenderFrameHost* sender,
electron::mojom::ElectronBrowser::InvokeCallback callback,
Args&&... args) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
v8::Locker locker(isolate());
v8::HandleScope handle_scope(isolate());

View file

@ -4,7 +4,7 @@
#include "shell/common/gin_helper/event_emitter_caller.h"
#include "shell/common/api/locker.h"
#include "shell/common/gin_helper/locker.h"
#include "shell/common/node_includes.h"
namespace gin_helper {

View file

@ -2,11 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE.chromium file.
#include "shell/common/api/locker.h"
#include "shell/common/gin_helper/locker.h"
#include <memory>
namespace mate {
namespace gin_helper {
Locker::Locker(v8::Isolate* isolate) {
if (IsBrowserProcess())
@ -15,4 +13,4 @@ Locker::Locker(v8::Isolate* isolate) {
Locker::~Locker() = default;
} // namespace mate
} // namespace gin_helper

View file

@ -2,15 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE.chromium file.
#ifndef SHELL_COMMON_API_LOCKER_H_
#define SHELL_COMMON_API_LOCKER_H_
#ifndef SHELL_COMMON_GIN_HELPER_LOCKER_H_
#define SHELL_COMMON_GIN_HELPER_LOCKER_H_
#include <memory>
#include "base/macros.h"
#include "v8/include/v8.h"
namespace mate {
namespace gin_helper {
// Only lock when lockers are used in current thread.
class Locker {
@ -31,6 +31,6 @@ class Locker {
DISALLOW_COPY_AND_ASSIGN(Locker);
};
} // namespace mate
} // namespace gin_helper
#endif // SHELL_COMMON_API_LOCKER_H_
#endif // SHELL_COMMON_GIN_HELPER_LOCKER_H_

View file

@ -0,0 +1,32 @@
// Copyright 2014 Cheng Zhao. All rights reserved.
// Use of this source code is governed by MIT license that can be found in the
// LICENSE file.
#include "shell/common/gin_helper/persistent_dictionary.h"
namespace gin_helper {
PersistentDictionary::PersistentDictionary() = default;
PersistentDictionary::PersistentDictionary(v8::Isolate* isolate,
v8::Local<v8::Object> object)
: isolate_(isolate), handle_(isolate, object) {}
PersistentDictionary::PersistentDictionary(const PersistentDictionary& other)
: isolate_(other.isolate_),
handle_(isolate_, v8::Local<v8::Object>::New(isolate_, other.handle_)) {}
PersistentDictionary::~PersistentDictionary() = default;
PersistentDictionary& PersistentDictionary::operator=(
const PersistentDictionary& other) {
isolate_ = other.isolate_;
handle_.Reset(isolate_, v8::Local<v8::Object>::New(isolate_, other.handle_));
return *this;
}
v8::Local<v8::Object> PersistentDictionary::GetHandle() const {
return v8::Local<v8::Object>::New(isolate_, handle_);
}
} // namespace gin_helper

View file

@ -0,0 +1,64 @@
// Copyright 2014 Cheng Zhao. All rights reserved.
// Use of this source code is governed by MIT license that can be found in the
// LICENSE file.
#ifndef SHELL_COMMON_GIN_HELPER_PERSISTENT_DICTIONARY_H_
#define SHELL_COMMON_GIN_HELPER_PERSISTENT_DICTIONARY_H_
#include "shell/common/gin_helper/dictionary.h"
namespace gin_helper {
// Like Dictionary, but stores object in persistent handle so you can keep it
// safely on heap.
//
// TODO(zcbenz): The only user of this class is AtomTouchBar, we should migrate
// away from this class.
class PersistentDictionary {
public:
PersistentDictionary();
PersistentDictionary(v8::Isolate* isolate, v8::Local<v8::Object> object);
PersistentDictionary(const PersistentDictionary& other);
~PersistentDictionary();
PersistentDictionary& operator=(const PersistentDictionary& other);
v8::Local<v8::Object> GetHandle() const;
template <typename K, typename V>
bool Get(const K& key, V* out) const {
v8::Local<v8::Context> context = isolate_->GetCurrentContext();
v8::Local<v8::Value> v8_key = gin::ConvertToV8(isolate_, key);
v8::Local<v8::Value> value;
v8::Maybe<bool> result = GetHandle()->Has(context, v8_key);
if (result.IsJust() && result.FromJust() &&
GetHandle()->Get(context, v8_key).ToLocal(&value))
return gin::ConvertFromV8(isolate_, value, out);
return false;
}
private:
v8::Isolate* isolate_ = nullptr;
v8::Global<v8::Object> handle_;
};
} // namespace gin_helper
namespace gin {
template <>
struct Converter<gin_helper::PersistentDictionary> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
gin_helper::PersistentDictionary* out) {
if (!val->IsObject())
return false;
*out = gin_helper::PersistentDictionary(isolate,
v8::Local<v8::Object>::Cast(val));
return true;
}
};
} // namespace gin
#endif // SHELL_COMMON_GIN_HELPER_PERSISTENT_DICTIONARY_H_

View file

@ -9,7 +9,7 @@
#include "base/bind.h"
#include "base/supports_user_data.h"
#include "shell/browser/atom_browser_main_parts.h"
#include "shell/common/api/locker.h"
#include "shell/common/gin_helper/locker.h"
namespace gin_helper {
@ -33,7 +33,7 @@ class IDUserData : public base::SupportsUserData::Data {
TrackableObjectBase::TrackableObjectBase() : weak_factory_(this) {
// TODO(zcbenz): Make TrackedObject work in renderer process.
DCHECK(mate::Locker::IsBrowserProcess())
DCHECK(gin_helper::Locker::IsBrowserProcess())
<< "This class only works for browser process";
electron::AtomBrowserMainParts::Get()->RegisterDestructionCallback(

View file

@ -1,162 +0,0 @@
// Copyright (c) 2015 GitHub, Inc. All rights reserved.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
#include "base/stl_util.h"
#include "content/public/browser/browser_thread.h"
#include "native_mate/dictionary.h"
using content::BrowserThread;
namespace mate {
namespace internal {
namespace {
struct TranslaterHolder {
explicit TranslaterHolder(v8::Isolate* isolate)
: handle(isolate, v8::External::New(isolate, this)) {
handle.SetWeak(this, &GC, v8::WeakCallbackType::kFinalizer);
}
~TranslaterHolder() {
if (!handle.IsEmpty()) {
handle.ClearWeak();
handle.Reset();
}
}
static void GC(const v8::WeakCallbackInfo<TranslaterHolder>& data) {
delete data.GetParameter();
}
v8::Global<v8::External> handle;
Translater translater;
};
// Cached JavaScript version of |CallTranslater|.
v8::Persistent<v8::FunctionTemplate> g_call_translater;
void CallTranslater(v8::Local<v8::External> external,
v8::Local<v8::Object> state,
mate::Arguments* args) {
// Whether the callback should only be called for once.
v8::Isolate* isolate = args->isolate();
auto context = isolate->GetCurrentContext();
bool one_time =
state->Has(context, mate::StringToSymbol(isolate, "oneTime")).ToChecked();
// Check if the callback has already been called.
if (one_time) {
auto called_symbol = mate::StringToSymbol(isolate, "called");
if (state->Has(context, called_symbol).ToChecked()) {
args->ThrowError("callback can only be called for once");
return;
} else {
state->Set(context, called_symbol, v8::Boolean::New(isolate, true))
.ToChecked();
}
}
TranslaterHolder* holder = static_cast<TranslaterHolder*>(external->Value());
holder->translater.Run(args);
// Free immediately for one-time callback.
if (one_time)
delete holder;
}
} // namespace
// Destroy the class on UI thread when possible.
struct DeleteOnUIThread {
template <typename T>
static void Destruct(const T* x) {
if (Locker::IsBrowserProcess() &&
!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, x);
} else {
delete x;
}
}
};
// Like v8::Global, but ref-counted.
template <typename T>
class RefCountedGlobal
: public base::RefCountedThreadSafe<RefCountedGlobal<T>, DeleteOnUIThread> {
public:
RefCountedGlobal(v8::Isolate* isolate, v8::Local<v8::Value> value)
: handle_(isolate, v8::Local<T>::Cast(value)) {}
bool IsAlive() const { return !handle_.IsEmpty(); }
v8::Local<T> NewHandle(v8::Isolate* isolate) const {
return v8::Local<T>::New(isolate, handle_);
}
private:
v8::Global<T> handle_;
DISALLOW_COPY_AND_ASSIGN(RefCountedGlobal);
};
SafeV8Function::SafeV8Function(v8::Isolate* isolate, v8::Local<v8::Value> value)
: v8_function_(new RefCountedGlobal<v8::Function>(isolate, value)) {}
SafeV8Function::SafeV8Function(const SafeV8Function& other) = default;
SafeV8Function::~SafeV8Function() = default;
bool SafeV8Function::IsAlive() const {
return v8_function_.get() && v8_function_->IsAlive();
}
v8::Local<v8::Function> SafeV8Function::NewHandle(v8::Isolate* isolate) const {
return v8_function_->NewHandle(isolate);
}
v8::Local<v8::Value> CreateFunctionFromTranslater(v8::Isolate* isolate,
const Translater& translater,
bool one_time) {
// The FunctionTemplate is cached.
if (g_call_translater.IsEmpty())
g_call_translater.Reset(isolate,
mate::CreateFunctionTemplate(
isolate, base::BindRepeating(&CallTranslater)));
v8::Local<v8::FunctionTemplate> call_translater =
v8::Local<v8::FunctionTemplate>::New(isolate, g_call_translater);
auto* holder = new TranslaterHolder(isolate);
holder->translater = translater;
Dictionary state = mate::Dictionary::CreateEmpty(isolate);
if (one_time)
state.Set("oneTime", true);
auto context = isolate->GetCurrentContext();
return BindFunctionWith(
isolate, context, call_translater->GetFunction(context).ToLocalChecked(),
holder->handle.Get(isolate), state.GetHandle());
}
// func.bind(func, arg1).
// NB(zcbenz): Using C++11 version crashes VS.
v8::Local<v8::Value> BindFunctionWith(v8::Isolate* isolate,
v8::Local<v8::Context> context,
v8::Local<v8::Function> func,
v8::Local<v8::Value> arg1,
v8::Local<v8::Value> arg2) {
v8::MaybeLocal<v8::Value> bind =
func->Get(context, mate::StringToV8(isolate, "bind"));
CHECK(!bind.IsEmpty());
v8::Local<v8::Function> bind_func =
v8::Local<v8::Function>::Cast(bind.ToLocalChecked());
v8::Local<v8::Value> converted[] = {func, arg1, arg2};
return bind_func->Call(context, func, base::size(converted), converted)
.ToLocalChecked();
}
} // namespace internal
} // namespace mate

View file

@ -1,185 +0,0 @@
// Copyright (c) 2015 GitHub, Inc. All rights reserved.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_COMMON_NATIVE_MATE_CONVERTERS_CALLBACK_CONVERTER_DEPRECATED_H_
#define SHELL_COMMON_NATIVE_MATE_CONVERTERS_CALLBACK_CONVERTER_DEPRECATED_H_
#include <utility>
#include <vector>
#include "base/bind.h"
#include "base/callback.h"
#include "base/memory/weak_ptr.h"
#include "base/message_loop/message_loop.h"
#include "native_mate/function_template.h"
#include "native_mate/scoped_persistent.h"
#include "shell/common/api/locker.h"
// =============================== NOTICE ===============================
// Do not add code here, native_mate is being removed. Any new code
// should use gin instead.
namespace mate {
namespace internal {
template <typename T>
class RefCountedGlobal;
// Manages the V8 function with RAII.
class SafeV8Function {
public:
SafeV8Function(v8::Isolate* isolate, v8::Local<v8::Value> value);
SafeV8Function(const SafeV8Function& other);
~SafeV8Function();
bool IsAlive() const;
v8::Local<v8::Function> NewHandle(v8::Isolate* isolate) const;
private:
scoped_refptr<RefCountedGlobal<v8::Function>> v8_function_;
};
// Helper to invoke a V8 function with C++ parameters.
template <typename Sig>
struct V8FunctionInvoker {};
template <typename... ArgTypes>
struct V8FunctionInvoker<v8::Local<v8::Value>(ArgTypes...)> {
static v8::Local<v8::Value> Go(v8::Isolate* isolate,
const SafeV8Function& function,
ArgTypes... raw) {
Locker locker(isolate);
v8::EscapableHandleScope handle_scope(isolate);
if (!function.IsAlive())
return v8::Null(isolate);
v8::MicrotasksScope script_scope(isolate,
v8::MicrotasksScope::kRunMicrotasks);
v8::Local<v8::Function> holder = function.NewHandle(isolate);
v8::Local<v8::Context> context = holder->CreationContext();
v8::Context::Scope context_scope(context);
std::vector<v8::Local<v8::Value>> args{
ConvertToV8(isolate, std::forward<ArgTypes>(raw))...};
v8::MaybeLocal<v8::Value> ret = holder->Call(
context, holder, args.size(), args.empty() ? nullptr : &args.front());
if (ret.IsEmpty())
return v8::Undefined(isolate);
else
return handle_scope.Escape(ret.ToLocalChecked());
}
};
template <typename... ArgTypes>
struct V8FunctionInvoker<void(ArgTypes...)> {
static void Go(v8::Isolate* isolate,
const SafeV8Function& function,
ArgTypes... raw) {
Locker locker(isolate);
v8::HandleScope handle_scope(isolate);
if (!function.IsAlive())
return;
v8::MicrotasksScope script_scope(isolate,
v8::MicrotasksScope::kRunMicrotasks);
v8::Local<v8::Function> holder = function.NewHandle(isolate);
v8::Local<v8::Context> context = holder->CreationContext();
v8::Context::Scope context_scope(context);
std::vector<v8::Local<v8::Value>> args{
ConvertToV8(isolate, std::forward<ArgTypes>(raw))...};
holder
->Call(context, holder, args.size(),
args.empty() ? nullptr : &args.front())
.IsEmpty();
}
};
template <typename ReturnType, typename... ArgTypes>
struct V8FunctionInvoker<ReturnType(ArgTypes...)> {
static ReturnType Go(v8::Isolate* isolate,
const SafeV8Function& function,
ArgTypes... raw) {
Locker locker(isolate);
v8::HandleScope handle_scope(isolate);
ReturnType ret = ReturnType();
if (!function.IsAlive())
return ret;
v8::MicrotasksScope script_scope(isolate,
v8::MicrotasksScope::kRunMicrotasks);
v8::Local<v8::Function> holder = function.NewHandle(isolate);
v8::Local<v8::Context> context = holder->CreationContext();
v8::Context::Scope context_scope(context);
std::vector<v8::Local<v8::Value>> args{
ConvertToV8(isolate, std::forward<ArgTypes>(raw))...};
v8::Local<v8::Value> result;
auto maybe_result = holder->Call(context, holder, args.size(),
args.empty() ? nullptr : &args.front());
if (maybe_result.ToLocal(&result))
Converter<ReturnType>::FromV8(isolate, result, &ret);
return ret;
}
};
// Helper to pass a C++ funtion to JavaScript.
using Translater = base::Callback<void(Arguments* args)>;
v8::Local<v8::Value> CreateFunctionFromTranslater(v8::Isolate* isolate,
const Translater& translater,
bool one_time);
v8::Local<v8::Value> BindFunctionWith(v8::Isolate* isolate,
v8::Local<v8::Context> context,
v8::Local<v8::Function> func,
v8::Local<v8::Value> arg1,
v8::Local<v8::Value> arg2);
// Calls callback with Arguments.
template <typename Sig>
struct NativeFunctionInvoker {};
template <typename ReturnType, typename... ArgTypes>
struct NativeFunctionInvoker<ReturnType(ArgTypes...)> {
static void Go(base::Callback<ReturnType(ArgTypes...)> val, Arguments* args) {
using Indices = typename IndicesGenerator<sizeof...(ArgTypes)>::type;
Invoker<Indices, ArgTypes...> invoker(args, 0);
if (invoker.IsOK())
invoker.DispatchToCallback(val);
}
};
} // namespace internal
template <typename Sig>
struct Converter<base::RepeatingCallback<Sig>> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const base::RepeatingCallback<Sig>& val) {
// We don't use CreateFunctionTemplate here because it creates a new
// FunctionTemplate everytime, which is cached by V8 and causes leaks.
internal::Translater translater =
base::Bind(&internal::NativeFunctionInvoker<Sig>::Go, val);
// To avoid memory leak, we ensure that the callback can only be called
// for once.
return internal::CreateFunctionFromTranslater(isolate, translater, true);
}
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
base::RepeatingCallback<Sig>* out) {
if (!val->IsFunction())
return false;
*out = base::BindRepeating(&internal::V8FunctionInvoker<Sig>::Go, isolate,
internal::SafeV8Function(isolate, val));
return true;
}
};
// Convert a callback to V8 without the call number limitation, this can easily
// cause memory leaks so use it with caution.
template <typename Sig>
v8::Local<v8::Value> CallbackToV8(v8::Isolate* isolate,
const base::Callback<Sig>& val) {
internal::Translater translater =
base::Bind(&internal::NativeFunctionInvoker<Sig>::Go, val);
return internal::CreateFunctionFromTranslater(isolate, translater, false);
}
} // namespace mate
#endif // SHELL_COMMON_NATIVE_MATE_CONVERTERS_CALLBACK_CONVERTER_DEPRECATED_H_

View file

@ -1,41 +0,0 @@
// Copyright (c) 2014 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_COMMON_NATIVE_MATE_CONVERTERS_FILE_DIALOG_CONVERTER_H_
#define SHELL_COMMON_NATIVE_MATE_CONVERTERS_FILE_DIALOG_CONVERTER_H_
#include "native_mate/converter.h"
#include "shell/common/gin_converters/file_dialog_converter.h"
namespace mate {
template <>
struct Converter<file_dialog::Filter> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const file_dialog::Filter& in) {
return gin::ConvertToV8(isolate, in);
}
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
file_dialog::Filter* out) {
return gin::ConvertFromV8(isolate, val, out);
}
};
template <>
struct Converter<file_dialog::DialogSettings> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const file_dialog::DialogSettings& in) {
return gin::ConvertToV8(isolate, in);
}
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
file_dialog::DialogSettings* out) {
return gin::ConvertFromV8(isolate, val, out);
}
};
} // namespace mate
#endif // SHELL_COMMON_NATIVE_MATE_CONVERTERS_FILE_DIALOG_CONVERTER_H_

View file

@ -1,28 +0,0 @@
// Copyright (c) 2014 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_COMMON_NATIVE_MATE_CONVERTERS_FILE_PATH_CONVERTER_H_
#define SHELL_COMMON_NATIVE_MATE_CONVERTERS_FILE_PATH_CONVERTER_H_
#include "shell/common/gin_converters/file_path_converter.h"
namespace mate {
template <>
struct Converter<base::FilePath> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const base::FilePath& val) {
return gin::Converter<base::FilePath::StringType>::ToV8(isolate,
val.value());
}
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
base::FilePath* out) {
return gin::Converter<base::FilePath>::FromV8(isolate, val, out);
}
};
} // namespace mate
#endif // SHELL_COMMON_NATIVE_MATE_CONVERTERS_FILE_PATH_CONVERTER_H_

View file

@ -1,27 +0,0 @@
// Copyright (c) 2014 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_COMMON_NATIVE_MATE_CONVERTERS_GURL_CONVERTER_H_
#define SHELL_COMMON_NATIVE_MATE_CONVERTERS_GURL_CONVERTER_H_
#include "native_mate/converter.h"
#include "shell/common/gin_converters/gurl_converter.h"
namespace mate {
template <>
struct Converter<GURL> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, const GURL& val) {
return gin::ConvertToV8(isolate, val);
}
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
GURL* out) {
return gin::ConvertFromV8(isolate, val, out);
}
};
} // namespace mate
#endif // SHELL_COMMON_NATIVE_MATE_CONVERTERS_GURL_CONVERTER_H_

View file

@ -1,37 +0,0 @@
// Copyright (c) 2014 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_COMMON_NATIVE_MATE_CONVERTERS_IMAGE_CONVERTER_H_
#define SHELL_COMMON_NATIVE_MATE_CONVERTERS_IMAGE_CONVERTER_H_
#include "native_mate/converter.h"
#include "shell/common/gin_converters/image_converter.h"
namespace mate {
template <>
struct Converter<gfx::ImageSkia> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
gfx::ImageSkia* out) {
return gin::ConvertFromV8(isolate, val, out);
}
};
template <>
struct Converter<gfx::Image> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
gfx::Image* out) {
return gin::ConvertFromV8(isolate, val, out);
}
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const gfx::Image& val) {
return gin::ConvertToV8(isolate, val);
}
};
} // namespace mate
#endif // SHELL_COMMON_NATIVE_MATE_CONVERTERS_IMAGE_CONVERTER_H_

View file

@ -1,24 +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_NATIVE_MATE_CONVERTERS_NATIVE_WINDOW_CONVERTER_H_
#define SHELL_COMMON_NATIVE_MATE_CONVERTERS_NATIVE_WINDOW_CONVERTER_H_
#include "native_mate/converter.h"
#include "shell/common/gin_converters/native_window_converter.h"
namespace mate {
template <>
struct Converter<electron::NativeWindow*> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
electron::NativeWindow** out) {
return gin::ConvertFromV8(isolate, val, out);
}
};
} // namespace mate
#endif // SHELL_COMMON_NATIVE_MATE_CONVERTERS_NATIVE_WINDOW_CONVERTER_H_

View file

@ -1,75 +0,0 @@
// 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_NATIVE_MATE_CONVERTERS_NET_CONVERTER_H_
#define SHELL_COMMON_NATIVE_MATE_CONVERTERS_NET_CONVERTER_H_
#include "native_mate/converter.h"
#include "shell/common/gin_converters/net_converter.h"
namespace mate {
template <>
struct Converter<net::AuthChallengeInfo> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const net::AuthChallengeInfo& val) {
return gin::ConvertToV8(isolate, val);
}
};
template <>
struct Converter<scoped_refptr<net::X509Certificate>> {
static v8::Local<v8::Value> ToV8(
v8::Isolate* isolate,
const scoped_refptr<net::X509Certificate>& val) {
return gin::ConvertToV8(isolate, val);
}
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
scoped_refptr<net::X509Certificate>* out) {
return gin::ConvertFromV8(isolate, val, out);
}
};
template <>
struct Converter<net::CertPrincipal> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const net::CertPrincipal& val) {
return gin::ConvertToV8(isolate, val);
}
};
template <>
struct Converter<net::HttpResponseHeaders*> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
net::HttpResponseHeaders* headers) {
return gin::ConvertToV8(isolate, headers);
}
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
net::HttpResponseHeaders* out) {
return gin::Converter<net::HttpResponseHeaders*>::FromV8(isolate, val, out);
}
};
template <>
struct Converter<network::ResourceRequest> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const network::ResourceRequest& val) {
return gin::ConvertToV8(isolate, val);
}
};
template <>
struct Converter<electron::VerifyRequestParams> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
electron::VerifyRequestParams val) {
return gin::ConvertToV8(isolate, val);
}
};
} // namespace mate
#endif // SHELL_COMMON_NATIVE_MATE_CONVERTERS_NET_CONVERTER_H_

View file

@ -1,87 +0,0 @@
// Copyright (c) 2019 GitHub, Inc. All rights reserved.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_COMMON_NATIVE_MATE_CONVERTERS_ONCE_CALLBACK_H_
#define SHELL_COMMON_NATIVE_MATE_CONVERTERS_ONCE_CALLBACK_H_
#include <utility>
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
namespace mate {
namespace internal {
// Manages the OnceCallback with ref-couting.
template <typename Sig>
class RefCountedOnceCallback
: public base::RefCounted<RefCountedOnceCallback<Sig>> {
public:
explicit RefCountedOnceCallback(base::OnceCallback<Sig> callback)
: callback_(std::move(callback)) {}
base::OnceCallback<Sig> GetCallback() { return std::move(callback_); }
private:
friend class base::RefCounted<RefCountedOnceCallback<Sig>>;
~RefCountedOnceCallback() = default;
base::OnceCallback<Sig> callback_;
};
// Invokes the OnceCallback.
template <typename Sig>
struct InvokeOnceCallback {};
template <typename... ArgTypes>
struct InvokeOnceCallback<void(ArgTypes...)> {
static void Go(
scoped_refptr<RefCountedOnceCallback<void(ArgTypes...)>> holder,
ArgTypes... args) {
base::OnceCallback<void(ArgTypes...)> callback = holder->GetCallback();
DCHECK(!callback.is_null());
std::move(callback).Run(std::move(args)...);
}
};
template <typename ReturnType, typename... ArgTypes>
struct InvokeOnceCallback<ReturnType(ArgTypes...)> {
static ReturnType Go(
scoped_refptr<RefCountedOnceCallback<ReturnType(ArgTypes...)>> holder,
ArgTypes... args) {
base::OnceCallback<void(ArgTypes...)> callback = holder->GetCallback();
DCHECK(!callback.is_null());
return std::move(callback).Run(std::move(args)...);
}
};
} // namespace internal
template <typename Sig>
struct Converter<base::OnceCallback<Sig>> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
base::OnceCallback<Sig> val) {
// Reuse the converter of base::RepeatingCallback by storing the callback
// with a RefCounted.
auto holder = base::MakeRefCounted<internal::RefCountedOnceCallback<Sig>>(
std::move(val));
return Converter<base::RepeatingCallback<Sig>>::ToV8(
isolate,
base::BindRepeating(&internal::InvokeOnceCallback<Sig>::Go, holder));
}
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
base::OnceCallback<Sig>* out) {
if (!val->IsFunction())
return false;
*out = base::BindOnce(&internal::V8FunctionInvoker<Sig>::Go, isolate,
internal::SafeV8Function(isolate, val));
return true;
}
};
} // namespace mate
#endif // SHELL_COMMON_NATIVE_MATE_CONVERTERS_ONCE_CALLBACK_H_

View file

@ -1,33 +0,0 @@
// Copyright (c) 2014 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_COMMON_NATIVE_MATE_CONVERTERS_STRING16_CONVERTER_H_
#define SHELL_COMMON_NATIVE_MATE_CONVERTERS_STRING16_CONVERTER_H_
#include "gin/converter.h"
#include "native_mate/converter.h"
namespace mate {
template <>
struct Converter<base::string16> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const base::string16& val) {
return gin::Converter<base::string16>::ToV8(isolate, val);
}
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
base::string16* out) {
return gin::Converter<base::string16>::FromV8(isolate, val, out);
}
};
inline v8::Local<v8::String> StringToV8(v8::Isolate* isolate,
const base::string16& input) {
return ConvertToV8(isolate, input).As<v8::String>();
}
} // namespace mate
#endif // SHELL_COMMON_NATIVE_MATE_CONVERTERS_STRING16_CONVERTER_H_

View file

@ -22,11 +22,11 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/common/content_paths.h"
#include "electron/buildflags/buildflags.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/gin_helper/locker.h"
#include "shell/common/mac/main_application_bundle.h"
#include "shell/common/node_includes.h"
@ -396,7 +396,7 @@ void NodeBindings::UvRunOnce() {
return;
// Use Locker in browser process.
mate::Locker locker(env->isolate());
gin_helper::Locker locker(env->isolate());
v8::HandleScope handle_scope(env->isolate());
// Enter node context while dealing with uv events.

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/native_mate_converters/v8_value_converter.h"
#include "shell/common/v8_value_converter.h"
#include <map>
#include <memory>

View file

@ -2,8 +2,8 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_COMMON_NATIVE_MATE_CONVERTERS_V8_VALUE_CONVERTER_H_
#define SHELL_COMMON_NATIVE_MATE_CONVERTERS_V8_VALUE_CONVERTER_H_
#ifndef SHELL_COMMON_V8_VALUE_CONVERTER_H_
#define SHELL_COMMON_V8_VALUE_CONVERTER_H_
#include <memory>
@ -74,4 +74,4 @@ class V8ValueConverter {
} // namespace electron
#endif // SHELL_COMMON_NATIVE_MATE_CONVERTERS_V8_VALUE_CONVERTER_H_
#endif // SHELL_COMMON_V8_VALUE_CONVERTER_H_