chore: remove native_mate (Part 8) (#20598)
* refactor: convert methods of AutoUpdater to gin * refactor: converter in map_converter.h is no more needed * refactor: use gin in crash_reporter * refactor: remove native_mate_converters/map_converter.h * refactor: implement gfx_converter with gin * refactor: convert methods of NativeImage to gin * refactor: add gin_helper::Arguments * fix: use gin_helper::Arguments to parse multi-type parameters
This commit is contained in:
parent
58115c1cae
commit
19223952a8
23 changed files with 361 additions and 212 deletions
|
@ -473,6 +473,8 @@ filenames = {
|
||||||
"shell/common/gin_converters/file_dialog_converter.cc",
|
"shell/common/gin_converters/file_dialog_converter.cc",
|
||||||
"shell/common/gin_converters/file_dialog_converter.h",
|
"shell/common/gin_converters/file_dialog_converter.h",
|
||||||
"shell/common/gin_converters/file_path_converter.h",
|
"shell/common/gin_converters/file_path_converter.h",
|
||||||
|
"shell/common/gin_converters/gfx_converter.cc",
|
||||||
|
"shell/common/gin_converters/gfx_converter.h",
|
||||||
"shell/common/gin_converters/gurl_converter.h",
|
"shell/common/gin_converters/gurl_converter.h",
|
||||||
"shell/common/gin_converters/image_converter.cc",
|
"shell/common/gin_converters/image_converter.cc",
|
||||||
"shell/common/gin_converters/image_converter.h",
|
"shell/common/gin_converters/image_converter.h",
|
||||||
|
@ -484,6 +486,7 @@ filenames = {
|
||||||
"shell/common/gin_converters/std_converter.h",
|
"shell/common/gin_converters/std_converter.h",
|
||||||
"shell/common/gin_converters/blink_converter_gin_adapter.h",
|
"shell/common/gin_converters/blink_converter_gin_adapter.h",
|
||||||
"shell/common/gin_converters/value_converter_gin_adapter.h",
|
"shell/common/gin_converters/value_converter_gin_adapter.h",
|
||||||
|
"shell/common/gin_helper/arguments.h",
|
||||||
"shell/common/gin_helper/callback.cc",
|
"shell/common/gin_helper/callback.cc",
|
||||||
"shell/common/gin_helper/callback.h",
|
"shell/common/gin_helper/callback.h",
|
||||||
"shell/common/gin_helper/destroyable.cc",
|
"shell/common/gin_helper/destroyable.cc",
|
||||||
|
@ -518,11 +521,9 @@ filenames = {
|
||||||
"shell/common/native_mate_converters/content_converter.h",
|
"shell/common/native_mate_converters/content_converter.h",
|
||||||
"shell/common/native_mate_converters/file_dialog_converter.h",
|
"shell/common/native_mate_converters/file_dialog_converter.h",
|
||||||
"shell/common/native_mate_converters/file_path_converter.h",
|
"shell/common/native_mate_converters/file_path_converter.h",
|
||||||
"shell/common/native_mate_converters/gfx_converter.cc",
|
|
||||||
"shell/common/native_mate_converters/gfx_converter.h",
|
"shell/common/native_mate_converters/gfx_converter.h",
|
||||||
"shell/common/native_mate_converters/gurl_converter.h",
|
"shell/common/native_mate_converters/gurl_converter.h",
|
||||||
"shell/common/native_mate_converters/image_converter.h",
|
"shell/common/native_mate_converters/image_converter.h",
|
||||||
"shell/common/native_mate_converters/map_converter.h",
|
|
||||||
"shell/common/native_mate_converters/native_window_converter.h",
|
"shell/common/native_mate_converters/native_window_converter.h",
|
||||||
"shell/common/native_mate_converters/net_converter.h",
|
"shell/common/native_mate_converters/net_converter.h",
|
||||||
"shell/common/native_mate_converters/network_converter.cc",
|
"shell/common/native_mate_converters/network_converter.cc",
|
||||||
|
|
|
@ -16,13 +16,12 @@
|
||||||
#include "gin/array_buffer.h"
|
#include "gin/array_buffer.h"
|
||||||
#include "gin/public/isolate_holder.h"
|
#include "gin/public/isolate_holder.h"
|
||||||
#include "gin/v8_initializer.h"
|
#include "gin/v8_initializer.h"
|
||||||
#include "native_mate/dictionary.h"
|
|
||||||
#include "shell/app/uv_task_runner.h"
|
#include "shell/app/uv_task_runner.h"
|
||||||
#include "shell/browser/javascript_environment.h"
|
#include "shell/browser/javascript_environment.h"
|
||||||
#include "shell/browser/node_debugger.h"
|
#include "shell/browser/node_debugger.h"
|
||||||
#include "shell/common/api/electron_bindings.h"
|
#include "shell/common/api/electron_bindings.h"
|
||||||
#include "shell/common/crash_reporter/crash_reporter.h"
|
#include "shell/common/crash_reporter/crash_reporter.h"
|
||||||
#include "shell/common/native_mate_converters/string16_converter.h"
|
#include "shell/common/gin_helper/dictionary.h"
|
||||||
#include "shell/common/node_bindings.h"
|
#include "shell/common/node_bindings.h"
|
||||||
#include "shell/common/node_includes.h"
|
#include "shell/common/node_includes.h"
|
||||||
|
|
||||||
|
@ -94,14 +93,15 @@ int NodeMain(int argc, char* argv[]) {
|
||||||
|
|
||||||
node::BootstrapEnvironment(env);
|
node::BootstrapEnvironment(env);
|
||||||
|
|
||||||
mate::Dictionary process(gin_env.isolate(), env->process_object());
|
gin_helper::Dictionary process(gin_env.isolate(), env->process_object());
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
process.SetMethod("log", &ElectronBindings::Log);
|
process.SetMethod("log", &ElectronBindings::Log);
|
||||||
#endif
|
#endif
|
||||||
process.SetMethod("crash", &ElectronBindings::Crash);
|
process.SetMethod("crash", &ElectronBindings::Crash);
|
||||||
|
|
||||||
// Setup process.crashReporter.start in child node processes
|
// Setup process.crashReporter.start in child node processes
|
||||||
auto reporter = mate::Dictionary::CreateEmpty(gin_env.isolate());
|
gin_helper::Dictionary reporter =
|
||||||
|
gin::Dictionary::CreateEmpty(gin_env.isolate());
|
||||||
reporter.SetMethod("start", &crash_reporter::CrashReporter::StartInstance);
|
reporter.SetMethod("start", &crash_reporter::CrashReporter::StartInstance);
|
||||||
|
|
||||||
#if !defined(OS_LINUX)
|
#if !defined(OS_LINUX)
|
||||||
|
@ -111,7 +111,7 @@ int NodeMain(int argc, char* argv[]) {
|
||||||
|
|
||||||
process.Set("crashReporter", reporter);
|
process.Set("crashReporter", reporter);
|
||||||
|
|
||||||
mate::Dictionary versions;
|
gin_helper::Dictionary versions;
|
||||||
if (process.Get("versions", &versions)) {
|
if (process.Get("versions", &versions)) {
|
||||||
versions.SetReadOnly(ELECTRON_PROJECT_NAME, ELECTRON_VERSION_STRING);
|
versions.SetReadOnly(ELECTRON_PROJECT_NAME, ELECTRON_VERSION_STRING);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,15 +5,16 @@
|
||||||
#include "shell/browser/api/atom_api_auto_updater.h"
|
#include "shell/browser/api/atom_api_auto_updater.h"
|
||||||
|
|
||||||
#include "base/time/time.h"
|
#include "base/time/time.h"
|
||||||
#include "native_mate/dictionary.h"
|
|
||||||
#include "native_mate/object_template_builder_deprecated.h"
|
|
||||||
#include "shell/browser/browser.h"
|
#include "shell/browser/browser.h"
|
||||||
#include "shell/browser/native_window.h"
|
#include "shell/browser/native_window.h"
|
||||||
#include "shell/browser/window_list.h"
|
#include "shell/browser/window_list.h"
|
||||||
|
#include "shell/common/gin_converters/callback_converter.h"
|
||||||
|
#include "shell/common/gin_helper/dictionary.h"
|
||||||
#include "shell/common/gin_helper/event_emitter_caller.h"
|
#include "shell/common/gin_helper/event_emitter_caller.h"
|
||||||
|
#include "shell/common/gin_helper/object_template_builder.h"
|
||||||
#include "shell/common/node_includes.h"
|
#include "shell/common/node_includes.h"
|
||||||
|
|
||||||
// TODO(zcbenz): Remove this after removing mate::ObjectTemplateBuilder.
|
// TODO(zcbenz): Remove this after removing mate::EventEmitter.
|
||||||
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
|
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
|
||||||
|
|
||||||
namespace mate {
|
namespace mate {
|
||||||
|
@ -49,7 +50,7 @@ AutoUpdater::~AutoUpdater() {
|
||||||
void AutoUpdater::OnError(const std::string& message) {
|
void AutoUpdater::OnError(const std::string& message) {
|
||||||
v8::Locker locker(isolate());
|
v8::Locker locker(isolate());
|
||||||
v8::HandleScope handle_scope(isolate());
|
v8::HandleScope handle_scope(isolate());
|
||||||
auto error = v8::Exception::Error(mate::StringToV8(isolate(), message));
|
auto error = v8::Exception::Error(gin::StringToV8(isolate(), message));
|
||||||
gin_helper::EmitEvent(
|
gin_helper::EmitEvent(
|
||||||
isolate(), GetWrapper(), "error",
|
isolate(), GetWrapper(), "error",
|
||||||
error->ToObject(isolate()->GetCurrentContext()).ToLocalChecked(),
|
error->ToObject(isolate()->GetCurrentContext()).ToLocalChecked(),
|
||||||
|
@ -62,7 +63,7 @@ void AutoUpdater::OnError(const std::string& message,
|
||||||
const std::string& domain) {
|
const std::string& domain) {
|
||||||
v8::Locker locker(isolate());
|
v8::Locker locker(isolate());
|
||||||
v8::HandleScope handle_scope(isolate());
|
v8::HandleScope handle_scope(isolate());
|
||||||
auto error = v8::Exception::Error(mate::StringToV8(isolate(), message));
|
auto error = v8::Exception::Error(gin::StringToV8(isolate(), message));
|
||||||
auto errorObject =
|
auto errorObject =
|
||||||
error->ToObject(isolate()->GetCurrentContext()).ToLocalChecked();
|
error->ToObject(isolate()->GetCurrentContext()).ToLocalChecked();
|
||||||
|
|
||||||
|
@ -70,12 +71,12 @@ void AutoUpdater::OnError(const std::string& message,
|
||||||
|
|
||||||
// add two new params for better error handling
|
// add two new params for better error handling
|
||||||
errorObject
|
errorObject
|
||||||
->Set(context, mate::StringToV8(isolate(), "code"),
|
->Set(context, gin::StringToV8(isolate(), "code"),
|
||||||
v8::Integer::New(isolate(), code))
|
v8::Integer::New(isolate(), code))
|
||||||
.Check();
|
.Check();
|
||||||
errorObject
|
errorObject
|
||||||
->Set(context, mate::StringToV8(isolate(), "domain"),
|
->Set(context, gin::StringToV8(isolate(), "domain"),
|
||||||
mate::StringToV8(isolate(), domain))
|
gin::StringToV8(isolate(), domain))
|
||||||
.Check();
|
.Check();
|
||||||
|
|
||||||
gin_helper::EmitEvent(isolate(), GetWrapper(), "error", errorObject, message);
|
gin_helper::EmitEvent(isolate(), GetWrapper(), "error", errorObject, message);
|
||||||
|
@ -107,7 +108,7 @@ void AutoUpdater::OnWindowAllClosed() {
|
||||||
QuitAndInstall();
|
QuitAndInstall();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutoUpdater::SetFeedURL(mate::Arguments* args) {
|
void AutoUpdater::SetFeedURL(gin_helper::Arguments* args) {
|
||||||
auto_updater::AutoUpdater::SetFeedURL(args);
|
auto_updater::AutoUpdater::SetFeedURL(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,15 +127,15 @@ void AutoUpdater::QuitAndInstall() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
mate::Handle<AutoUpdater> AutoUpdater::Create(v8::Isolate* isolate) {
|
gin::Handle<AutoUpdater> AutoUpdater::Create(v8::Isolate* isolate) {
|
||||||
return mate::CreateHandle(isolate, new AutoUpdater(isolate));
|
return gin::CreateHandle(isolate, new AutoUpdater(isolate));
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void AutoUpdater::BuildPrototype(v8::Isolate* isolate,
|
void AutoUpdater::BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::FunctionTemplate> prototype) {
|
v8::Local<v8::FunctionTemplate> prototype) {
|
||||||
prototype->SetClassName(mate::StringToV8(isolate, "AutoUpdater"));
|
prototype->SetClassName(gin::StringToV8(isolate, "AutoUpdater"));
|
||||||
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||||
.SetMethod("checkForUpdates", &auto_updater::AutoUpdater::CheckForUpdates)
|
.SetMethod("checkForUpdates", &auto_updater::AutoUpdater::CheckForUpdates)
|
||||||
.SetMethod("getFeedURL", &auto_updater::AutoUpdater::GetFeedURL)
|
.SetMethod("getFeedURL", &auto_updater::AutoUpdater::GetFeedURL)
|
||||||
.SetMethod("setFeedURL", &AutoUpdater::SetFeedURL)
|
.SetMethod("setFeedURL", &AutoUpdater::SetFeedURL)
|
||||||
|
@ -154,7 +155,7 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||||
v8::Local<v8::Context> context,
|
v8::Local<v8::Context> context,
|
||||||
void* priv) {
|
void* priv) {
|
||||||
v8::Isolate* isolate = context->GetIsolate();
|
v8::Isolate* isolate = context->GetIsolate();
|
||||||
mate::Dictionary dict(isolate, exports);
|
gin_helper::Dictionary dict(isolate, exports);
|
||||||
dict.Set("autoUpdater", AutoUpdater::Create(isolate));
|
dict.Set("autoUpdater", AutoUpdater::Create(isolate));
|
||||||
dict.Set("AutoUpdater", AutoUpdater::GetConstructor(isolate)
|
dict.Set("AutoUpdater", AutoUpdater::GetConstructor(isolate)
|
||||||
->GetFunction(context)
|
->GetFunction(context)
|
||||||
|
|
|
@ -7,8 +7,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "native_mate/arguments.h"
|
#include "gin/handle.h"
|
||||||
#include "native_mate/handle.h"
|
|
||||||
#include "shell/browser/api/event_emitter.h"
|
#include "shell/browser/api/event_emitter.h"
|
||||||
#include "shell/browser/auto_updater.h"
|
#include "shell/browser/auto_updater.h"
|
||||||
#include "shell/browser/window_list_observer.h"
|
#include "shell/browser/window_list_observer.h"
|
||||||
|
@ -21,7 +20,7 @@ class AutoUpdater : public mate::EventEmitter<AutoUpdater>,
|
||||||
public auto_updater::Delegate,
|
public auto_updater::Delegate,
|
||||||
public WindowListObserver {
|
public WindowListObserver {
|
||||||
public:
|
public:
|
||||||
static mate::Handle<AutoUpdater> Create(v8::Isolate* isolate);
|
static gin::Handle<AutoUpdater> Create(v8::Isolate* isolate);
|
||||||
|
|
||||||
static void BuildPrototype(v8::Isolate* isolate,
|
static void BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::FunctionTemplate> prototype);
|
v8::Local<v8::FunctionTemplate> prototype);
|
||||||
|
@ -48,7 +47,7 @@ class AutoUpdater : public mate::EventEmitter<AutoUpdater>,
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string GetFeedURL();
|
std::string GetFeedURL();
|
||||||
void SetFeedURL(mate::Arguments* args);
|
void SetFeedURL(gin_helper::Arguments* args);
|
||||||
void QuitAndInstall();
|
void QuitAndInstall();
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(AutoUpdater);
|
DISALLOW_COPY_AND_ASSIGN(AutoUpdater);
|
||||||
|
|
|
@ -72,6 +72,7 @@
|
||||||
#include "shell/browser/web_view_guest_delegate.h"
|
#include "shell/browser/web_view_guest_delegate.h"
|
||||||
#include "shell/common/api/atom_api_native_image.h"
|
#include "shell/common/api/atom_api_native_image.h"
|
||||||
#include "shell/common/color_util.h"
|
#include "shell/common/color_util.h"
|
||||||
|
#include "shell/common/gin_helper/dictionary.h"
|
||||||
#include "shell/common/mouse_util.h"
|
#include "shell/common/mouse_util.h"
|
||||||
#include "shell/common/native_mate_converters/blink_converter.h"
|
#include "shell/common/native_mate_converters/blink_converter.h"
|
||||||
#include "shell/common/native_mate_converters/content_converter.h"
|
#include "shell/common/native_mate_converters/content_converter.h"
|
||||||
|
@ -79,7 +80,6 @@
|
||||||
#include "shell/common/native_mate_converters/gfx_converter.h"
|
#include "shell/common/native_mate_converters/gfx_converter.h"
|
||||||
#include "shell/common/native_mate_converters/gurl_converter.h"
|
#include "shell/common/native_mate_converters/gurl_converter.h"
|
||||||
#include "shell/common/native_mate_converters/image_converter.h"
|
#include "shell/common/native_mate_converters/image_converter.h"
|
||||||
#include "shell/common/native_mate_converters/map_converter.h"
|
|
||||||
#include "shell/common/native_mate_converters/net_converter.h"
|
#include "shell/common/native_mate_converters/net_converter.h"
|
||||||
#include "shell/common/native_mate_converters/network_converter.h"
|
#include "shell/common/native_mate_converters/network_converter.h"
|
||||||
#include "shell/common/native_mate_converters/once_callback.h"
|
#include "shell/common/native_mate_converters/once_callback.h"
|
||||||
|
@ -130,7 +130,7 @@ template <>
|
||||||
struct Converter<printing::PrinterBasicInfo> {
|
struct Converter<printing::PrinterBasicInfo> {
|
||||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||||
const printing::PrinterBasicInfo& val) {
|
const printing::PrinterBasicInfo& val) {
|
||||||
mate::Dictionary dict(isolate, v8::Object::New(isolate));
|
gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate);
|
||||||
dict.Set("name", val.printer_name);
|
dict.Set("name", val.printer_name);
|
||||||
dict.Set("description", val.printer_description);
|
dict.Set("description", val.printer_description);
|
||||||
dict.Set("status", val.printer_status);
|
dict.Set("status", val.printer_status);
|
||||||
|
|
|
@ -21,7 +21,7 @@ std::string AutoUpdater::GetFeedURL() {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutoUpdater::SetFeedURL(mate::Arguments* args) {}
|
void AutoUpdater::SetFeedURL(gin_helper::Arguments* args) {}
|
||||||
|
|
||||||
void AutoUpdater::CheckForUpdates() {}
|
void AutoUpdater::CheckForUpdates() {}
|
||||||
|
|
||||||
|
|
|
@ -10,12 +10,15 @@
|
||||||
|
|
||||||
#include "base/macros.h"
|
#include "base/macros.h"
|
||||||
#include "build/build_config.h"
|
#include "build/build_config.h"
|
||||||
#include "native_mate/arguments.h"
|
|
||||||
|
|
||||||
namespace base {
|
namespace base {
|
||||||
class Time;
|
class Time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace gin_helper {
|
||||||
|
class Arguments;
|
||||||
|
}
|
||||||
|
|
||||||
namespace auto_updater {
|
namespace auto_updater {
|
||||||
|
|
||||||
class Delegate {
|
class Delegate {
|
||||||
|
@ -55,7 +58,10 @@ class AutoUpdater {
|
||||||
static void SetDelegate(Delegate* delegate);
|
static void SetDelegate(Delegate* delegate);
|
||||||
|
|
||||||
static std::string GetFeedURL();
|
static std::string GetFeedURL();
|
||||||
static void SetFeedURL(mate::Arguments* args);
|
// FIXME(zcbenz): We should not do V8 in this file, this method should only
|
||||||
|
// accept C++ struct as parameter, and atom_api_auto_updater.cc is responsible
|
||||||
|
// for parsing the parameter from JavaScript.
|
||||||
|
static void SetFeedURL(gin_helper::Arguments* args);
|
||||||
static void CheckForUpdates();
|
static void CheckForUpdates();
|
||||||
static void QuitAndInstall();
|
static void QuitAndInstall();
|
||||||
|
|
||||||
|
|
|
@ -14,10 +14,11 @@
|
||||||
#include "base/bind.h"
|
#include "base/bind.h"
|
||||||
#include "base/strings/sys_string_conversions.h"
|
#include "base/strings/sys_string_conversions.h"
|
||||||
#include "base/time/time.h"
|
#include "base/time/time.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "gin/arguments.h"
|
||||||
#include "shell/browser/browser.h"
|
#include "shell/browser/browser.h"
|
||||||
#include "shell/common/native_mate_converters/map_converter.h"
|
#include "shell/common/gin_converters/value_converter_gin_adapter.h"
|
||||||
#include "shell/common/native_mate_converters/value_converter.h"
|
#include "shell/common/gin_helper/dictionary.h"
|
||||||
|
#include "shell/common/gin_helper/error_thrower.h"
|
||||||
|
|
||||||
namespace auto_updater {
|
namespace auto_updater {
|
||||||
|
|
||||||
|
@ -40,14 +41,16 @@ std::string AutoUpdater::GetFeedURL() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void AutoUpdater::SetFeedURL(mate::Arguments* args) {
|
void AutoUpdater::SetFeedURL(gin_helper::Arguments* args) {
|
||||||
mate::Dictionary opts;
|
gin_helper::ErrorThrower thrower(args->isolate());
|
||||||
|
gin_helper::Dictionary opts;
|
||||||
|
|
||||||
std::string feed;
|
std::string feed;
|
||||||
HeaderMap requestHeaders;
|
HeaderMap requestHeaders;
|
||||||
std::string serverType = "default";
|
std::string serverType = "default";
|
||||||
if (args->GetNext(&opts)) {
|
if (args->GetNext(&opts)) {
|
||||||
if (!opts.Get("url", &feed)) {
|
if (!opts.Get("url", &feed)) {
|
||||||
args->ThrowError(
|
thrower.ThrowError(
|
||||||
"Expected options object to contain a 'url' string property in "
|
"Expected options object to contain a 'url' string property in "
|
||||||
"setFeedUrl call");
|
"setFeedUrl call");
|
||||||
return;
|
return;
|
||||||
|
@ -55,13 +58,13 @@ void AutoUpdater::SetFeedURL(mate::Arguments* args) {
|
||||||
opts.Get("headers", &requestHeaders);
|
opts.Get("headers", &requestHeaders);
|
||||||
opts.Get("serverType", &serverType);
|
opts.Get("serverType", &serverType);
|
||||||
if (serverType != "default" && serverType != "json") {
|
if (serverType != "default" && serverType != "json") {
|
||||||
args->ThrowError("Expected serverType to be 'default' or 'json'");
|
thrower.ThrowError("Expected serverType to be 'default' or 'json'");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (args->GetNext(&feed)) {
|
} else if (args->GetNext(&feed)) {
|
||||||
args->GetNext(&requestHeaders);
|
args->GetNext(&requestHeaders);
|
||||||
} else {
|
} else {
|
||||||
args->ThrowError(
|
thrower.ThrowError(
|
||||||
"Expected an options object with a 'url' property to be provided");
|
"Expected an options object with a 'url' property to be provided");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,9 +9,8 @@
|
||||||
#include "gin/data_object_builder.h"
|
#include "gin/data_object_builder.h"
|
||||||
#include "shell/common/crash_reporter/crash_reporter.h"
|
#include "shell/common/crash_reporter/crash_reporter.h"
|
||||||
#include "shell/common/gin_converters/callback_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/dictionary.h"
|
||||||
#include "shell/common/native_mate_converters/file_path_converter.h"
|
|
||||||
#include "shell/common/native_mate_converters/map_converter.h"
|
|
||||||
|
|
||||||
#include "shell/common/node_includes.h"
|
#include "shell/common/node_includes.h"
|
||||||
|
|
||||||
|
|
|
@ -13,13 +13,14 @@
|
||||||
#include "base/strings/pattern.h"
|
#include "base/strings/pattern.h"
|
||||||
#include "base/strings/string_util.h"
|
#include "base/strings/string_util.h"
|
||||||
#include "base/threading/thread_restrictions.h"
|
#include "base/threading/thread_restrictions.h"
|
||||||
#include "native_mate/object_template_builder_deprecated.h"
|
|
||||||
#include "net/base/data_url.h"
|
#include "net/base/data_url.h"
|
||||||
#include "shell/common/asar/asar_util.h"
|
#include "shell/common/asar/asar_util.h"
|
||||||
#include "shell/common/native_mate_converters/file_path_converter.h"
|
#include "shell/common/gin_converters/file_path_converter.h"
|
||||||
#include "shell/common/native_mate_converters/gfx_converter.h"
|
#include "shell/common/gin_converters/gfx_converter.h"
|
||||||
#include "shell/common/native_mate_converters/gurl_converter.h"
|
#include "shell/common/gin_converters/gurl_converter.h"
|
||||||
#include "shell/common/native_mate_converters/value_converter.h"
|
#include "shell/common/gin_converters/value_converter_gin_adapter.h"
|
||||||
|
#include "shell/common/gin_helper/dictionary.h"
|
||||||
|
#include "shell/common/gin_helper/object_template_builder.h"
|
||||||
#include "shell/common/node_includes.h"
|
#include "shell/common/node_includes.h"
|
||||||
#include "shell/common/skia_util.h"
|
#include "shell/common/skia_util.h"
|
||||||
#include "third_party/skia/include/core/SkBitmap.h"
|
#include "third_party/skia/include/core/SkBitmap.h"
|
||||||
|
@ -47,9 +48,9 @@ namespace api {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// Get the scale factor from options object at the first argument
|
// Get the scale factor from options object at the first argument
|
||||||
float GetScaleFactorFromOptions(mate::Arguments* args) {
|
float GetScaleFactorFromOptions(gin::Arguments* args) {
|
||||||
float scale_factor = 1.0f;
|
float scale_factor = 1.0f;
|
||||||
mate::Dictionary options;
|
gin_helper::Dictionary options;
|
||||||
if (args->GetNext(&options))
|
if (args->GetNext(&options))
|
||||||
options.Get("scaleFactor", &scale_factor);
|
options.Get("scaleFactor", &scale_factor);
|
||||||
return scale_factor;
|
return scale_factor;
|
||||||
|
@ -151,7 +152,7 @@ HICON NativeImage::GetHICON(int size) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
v8::Local<v8::Value> NativeImage::ToPNG(mate::Arguments* args) {
|
v8::Local<v8::Value> NativeImage::ToPNG(gin::Arguments* args) {
|
||||||
float scale_factor = GetScaleFactorFromOptions(args);
|
float scale_factor = GetScaleFactorFromOptions(args);
|
||||||
|
|
||||||
if (scale_factor == 1.0f) {
|
if (scale_factor == 1.0f) {
|
||||||
|
@ -173,7 +174,7 @@ v8::Local<v8::Value> NativeImage::ToPNG(mate::Arguments* args) {
|
||||||
return node::Buffer::Copy(args->isolate(), data, size).ToLocalChecked();
|
return node::Buffer::Copy(args->isolate(), data, size).ToLocalChecked();
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Local<v8::Value> NativeImage::ToBitmap(mate::Arguments* args) {
|
v8::Local<v8::Value> NativeImage::ToBitmap(gin::Arguments* args) {
|
||||||
float scale_factor = GetScaleFactorFromOptions(args);
|
float scale_factor = GetScaleFactorFromOptions(args);
|
||||||
|
|
||||||
const SkBitmap bitmap =
|
const SkBitmap bitmap =
|
||||||
|
@ -198,7 +199,7 @@ v8::Local<v8::Value> NativeImage::ToJPEG(v8::Isolate* isolate, int quality) {
|
||||||
.ToLocalChecked();
|
.ToLocalChecked();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string NativeImage::ToDataURL(mate::Arguments* args) {
|
std::string NativeImage::ToDataURL(gin::Arguments* args) {
|
||||||
float scale_factor = GetScaleFactorFromOptions(args);
|
float scale_factor = GetScaleFactorFromOptions(args);
|
||||||
|
|
||||||
if (scale_factor == 1.0f) {
|
if (scale_factor == 1.0f) {
|
||||||
|
@ -212,7 +213,7 @@ std::string NativeImage::ToDataURL(mate::Arguments* args) {
|
||||||
image_.AsImageSkia().GetRepresentation(scale_factor).GetBitmap());
|
image_.AsImageSkia().GetRepresentation(scale_factor).GetBitmap());
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Local<v8::Value> NativeImage::GetBitmap(mate::Arguments* args) {
|
v8::Local<v8::Value> NativeImage::GetBitmap(gin::Arguments* args) {
|
||||||
float scale_factor = GetScaleFactorFromOptions(args);
|
float scale_factor = GetScaleFactorFromOptions(args);
|
||||||
|
|
||||||
const SkBitmap bitmap =
|
const SkBitmap bitmap =
|
||||||
|
@ -226,19 +227,19 @@ v8::Local<v8::Value> NativeImage::GetBitmap(mate::Arguments* args) {
|
||||||
.ToLocalChecked();
|
.ToLocalChecked();
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Local<v8::Value> NativeImage::GetNativeHandle(v8::Isolate* isolate,
|
v8::Local<v8::Value> NativeImage::GetNativeHandle(
|
||||||
mate::Arguments* args) {
|
gin_helper::ErrorThrower thrower) {
|
||||||
#if defined(OS_MACOSX)
|
#if defined(OS_MACOSX)
|
||||||
if (IsEmpty())
|
if (IsEmpty())
|
||||||
return node::Buffer::New(isolate, 0).ToLocalChecked();
|
return node::Buffer::New(thrower.isolate(), 0).ToLocalChecked();
|
||||||
|
|
||||||
NSImage* ptr = image_.AsNSImage();
|
NSImage* ptr = image_.AsNSImage();
|
||||||
return node::Buffer::Copy(isolate, reinterpret_cast<char*>(ptr),
|
return node::Buffer::Copy(thrower.isolate(), reinterpret_cast<char*>(ptr),
|
||||||
sizeof(void*))
|
sizeof(void*))
|
||||||
.ToLocalChecked();
|
.ToLocalChecked();
|
||||||
#else
|
#else
|
||||||
args->ThrowError("Not implemented");
|
thrower.ThrowError("Not implemented");
|
||||||
return v8::Undefined(isolate);
|
return v8::Undefined(thrower.isolate());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,7 +302,7 @@ mate::Handle<NativeImage> NativeImage::Crop(v8::Isolate* isolate,
|
||||||
new NativeImage(isolate, gfx::Image(cropped)));
|
new NativeImage(isolate, gfx::Image(cropped)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeImage::AddRepresentation(const mate::Dictionary& options) {
|
void NativeImage::AddRepresentation(const gin_helper::Dictionary& options) {
|
||||||
int width = 0;
|
int width = 0;
|
||||||
int height = 0;
|
int height = 0;
|
||||||
float scale_factor = 1.0f;
|
float scale_factor = 1.0f;
|
||||||
|
@ -400,11 +401,11 @@ mate::Handle<NativeImage> NativeImage::CreateFromPath(
|
||||||
|
|
||||||
// static
|
// static
|
||||||
mate::Handle<NativeImage> NativeImage::CreateFromBitmap(
|
mate::Handle<NativeImage> NativeImage::CreateFromBitmap(
|
||||||
mate::Arguments* args,
|
gin_helper::ErrorThrower thrower,
|
||||||
v8::Local<v8::Value> buffer,
|
v8::Local<v8::Value> buffer,
|
||||||
const mate::Dictionary& options) {
|
const gin_helper::Dictionary& options) {
|
||||||
if (!node::Buffer::HasInstance(buffer)) {
|
if (!node::Buffer::HasInstance(buffer)) {
|
||||||
args->ThrowError("buffer must be a node Buffer");
|
thrower.ThrowError("buffer must be a node Buffer");
|
||||||
return mate::Handle<NativeImage>();
|
return mate::Handle<NativeImage>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -413,12 +414,12 @@ mate::Handle<NativeImage> NativeImage::CreateFromBitmap(
|
||||||
double scale_factor = 1.;
|
double scale_factor = 1.;
|
||||||
|
|
||||||
if (!options.Get("width", &width)) {
|
if (!options.Get("width", &width)) {
|
||||||
args->ThrowError("width is required");
|
thrower.ThrowError("width is required");
|
||||||
return mate::Handle<NativeImage>();
|
return mate::Handle<NativeImage>();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!options.Get("height", &height)) {
|
if (!options.Get("height", &height)) {
|
||||||
args->ThrowError("height is required");
|
thrower.ThrowError("height is required");
|
||||||
return mate::Handle<NativeImage>();
|
return mate::Handle<NativeImage>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -426,14 +427,14 @@ mate::Handle<NativeImage> NativeImage::CreateFromBitmap(
|
||||||
auto size_bytes = info.computeMinByteSize();
|
auto size_bytes = info.computeMinByteSize();
|
||||||
|
|
||||||
if (size_bytes != node::Buffer::Length(buffer)) {
|
if (size_bytes != node::Buffer::Length(buffer)) {
|
||||||
args->ThrowError("invalid buffer size");
|
thrower.ThrowError("invalid buffer size");
|
||||||
return mate::Handle<NativeImage>();
|
return mate::Handle<NativeImage>();
|
||||||
}
|
}
|
||||||
|
|
||||||
options.Get("scaleFactor", &scale_factor);
|
options.Get("scaleFactor", &scale_factor);
|
||||||
|
|
||||||
if (width == 0 || height == 0) {
|
if (width == 0 || height == 0) {
|
||||||
return CreateEmpty(args->isolate());
|
return CreateEmpty(thrower.isolate());
|
||||||
}
|
}
|
||||||
|
|
||||||
SkBitmap bitmap;
|
SkBitmap bitmap;
|
||||||
|
@ -443,15 +444,16 @@ mate::Handle<NativeImage> NativeImage::CreateFromBitmap(
|
||||||
gfx::ImageSkia image_skia;
|
gfx::ImageSkia image_skia;
|
||||||
image_skia.AddRepresentation(gfx::ImageSkiaRep(bitmap, scale_factor));
|
image_skia.AddRepresentation(gfx::ImageSkiaRep(bitmap, scale_factor));
|
||||||
|
|
||||||
return Create(args->isolate(), gfx::Image(image_skia));
|
return Create(thrower.isolate(), gfx::Image(image_skia));
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
mate::Handle<NativeImage> NativeImage::CreateFromBuffer(
|
mate::Handle<NativeImage> NativeImage::CreateFromBuffer(
|
||||||
mate::Arguments* args,
|
gin_helper::ErrorThrower thrower,
|
||||||
v8::Local<v8::Value> buffer) {
|
v8::Local<v8::Value> buffer,
|
||||||
|
gin::Arguments* args) {
|
||||||
if (!node::Buffer::HasInstance(buffer)) {
|
if (!node::Buffer::HasInstance(buffer)) {
|
||||||
args->ThrowError("buffer must be a node Buffer");
|
thrower.ThrowError("buffer must be a node Buffer");
|
||||||
return mate::Handle<NativeImage>();
|
return mate::Handle<NativeImage>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -459,7 +461,7 @@ mate::Handle<NativeImage> NativeImage::CreateFromBuffer(
|
||||||
int height = 0;
|
int height = 0;
|
||||||
double scale_factor = 1.;
|
double scale_factor = 1.;
|
||||||
|
|
||||||
mate::Dictionary options;
|
gin_helper::Dictionary options;
|
||||||
if (args->GetNext(&options)) {
|
if (args->GetNext(&options)) {
|
||||||
options.Get("width", &width);
|
options.Get("width", &width);
|
||||||
options.Get("height", &height);
|
options.Get("height", &height);
|
||||||
|
@ -489,7 +491,7 @@ mate::Handle<NativeImage> NativeImage::CreateFromDataURL(v8::Isolate* isolate,
|
||||||
|
|
||||||
#if !defined(OS_MACOSX)
|
#if !defined(OS_MACOSX)
|
||||||
mate::Handle<NativeImage> NativeImage::CreateFromNamedImage(
|
mate::Handle<NativeImage> NativeImage::CreateFromNamedImage(
|
||||||
mate::Arguments* args,
|
gin::Arguments* args,
|
||||||
const std::string& name) {
|
const std::string& name) {
|
||||||
return CreateEmpty(args->isolate());
|
return CreateEmpty(args->isolate());
|
||||||
}
|
}
|
||||||
|
@ -498,8 +500,8 @@ mate::Handle<NativeImage> NativeImage::CreateFromNamedImage(
|
||||||
// static
|
// static
|
||||||
void NativeImage::BuildPrototype(v8::Isolate* isolate,
|
void NativeImage::BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::FunctionTemplate> prototype) {
|
v8::Local<v8::FunctionTemplate> prototype) {
|
||||||
prototype->SetClassName(mate::StringToV8(isolate, "NativeImage"));
|
prototype->SetClassName(gin::StringToV8(isolate, "NativeImage"));
|
||||||
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||||
.SetMethod("toPNG", &NativeImage::ToPNG)
|
.SetMethod("toPNG", &NativeImage::ToPNG)
|
||||||
.SetMethod("toJPEG", &NativeImage::ToJPEG)
|
.SetMethod("toJPEG", &NativeImage::ToJPEG)
|
||||||
.SetMethod("toBitmap", &NativeImage::ToBitmap)
|
.SetMethod("toBitmap", &NativeImage::ToBitmap)
|
||||||
|
@ -522,7 +524,7 @@ void NativeImage::BuildPrototype(v8::Isolate* isolate,
|
||||||
|
|
||||||
} // namespace electron
|
} // namespace electron
|
||||||
|
|
||||||
namespace mate {
|
namespace gin {
|
||||||
|
|
||||||
v8::Local<v8::Value> Converter<mate::Handle<electron::api::NativeImage>>::ToV8(
|
v8::Local<v8::Value> Converter<mate::Handle<electron::api::NativeImage>>::ToV8(
|
||||||
v8::Isolate* isolate,
|
v8::Isolate* isolate,
|
||||||
|
@ -542,17 +544,17 @@ bool Converter<mate::Handle<electron::api::NativeImage>>::FromV8(
|
||||||
return !(*out)->image().IsEmpty();
|
return !(*out)->image().IsEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
WrappableBase* wrapper =
|
auto* wrapper = static_cast<mate::WrappableBase*>(
|
||||||
static_cast<WrappableBase*>(internal::FromV8Impl(isolate, val));
|
mate::internal::FromV8Impl(isolate, val));
|
||||||
if (!wrapper)
|
if (!wrapper)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
*out =
|
*out = mate::CreateHandle(isolate,
|
||||||
CreateHandle(isolate, static_cast<electron::api::NativeImage*>(wrapper));
|
static_cast<electron::api::NativeImage*>(wrapper));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace mate
|
} // namespace gin
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
@ -563,11 +565,11 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||||
v8::Local<v8::Context> context,
|
v8::Local<v8::Context> context,
|
||||||
void* priv) {
|
void* priv) {
|
||||||
v8::Isolate* isolate = context->GetIsolate();
|
v8::Isolate* isolate = context->GetIsolate();
|
||||||
mate::Dictionary dict(isolate, exports);
|
gin_helper::Dictionary dict(isolate, exports);
|
||||||
dict.Set("NativeImage", NativeImage::GetConstructor(isolate)
|
dict.Set("NativeImage", NativeImage::GetConstructor(isolate)
|
||||||
->GetFunction(context)
|
->GetFunction(context)
|
||||||
.ToLocalChecked());
|
.ToLocalChecked());
|
||||||
mate::Dictionary native_image = mate::Dictionary::CreateEmpty(isolate);
|
gin_helper::Dictionary native_image = gin::Dictionary::CreateEmpty(isolate);
|
||||||
dict.Set("nativeImage", native_image);
|
dict.Set("nativeImage", native_image);
|
||||||
|
|
||||||
native_image.SetMethod("createEmpty", &NativeImage::CreateEmpty);
|
native_image.SetMethod("createEmpty", &NativeImage::CreateEmpty);
|
||||||
|
|
|
@ -9,10 +9,9 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "base/values.h"
|
#include "base/values.h"
|
||||||
#include "native_mate/dictionary.h"
|
|
||||||
#include "native_mate/handle.h"
|
#include "native_mate/handle.h"
|
||||||
#include "native_mate/wrappable.h"
|
#include "native_mate/wrappable.h"
|
||||||
#include "ui/gfx/geometry/rect.h"
|
#include "shell/common/gin_helper/error_thrower.h"
|
||||||
#include "ui/gfx/image/image.h"
|
#include "ui/gfx/image/image.h"
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
|
@ -27,11 +26,12 @@ class FilePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace gfx {
|
namespace gfx {
|
||||||
|
class Rect;
|
||||||
class Size;
|
class Size;
|
||||||
}
|
} // namespace gfx
|
||||||
|
|
||||||
namespace mate {
|
namespace gin_helper {
|
||||||
class Arguments;
|
class Dictionary;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace electron {
|
namespace electron {
|
||||||
|
@ -52,16 +52,17 @@ class NativeImage : public mate::Wrappable<NativeImage> {
|
||||||
static mate::Handle<NativeImage> CreateFromPath(v8::Isolate* isolate,
|
static mate::Handle<NativeImage> CreateFromPath(v8::Isolate* isolate,
|
||||||
const base::FilePath& path);
|
const base::FilePath& path);
|
||||||
static mate::Handle<NativeImage> CreateFromBitmap(
|
static mate::Handle<NativeImage> CreateFromBitmap(
|
||||||
mate::Arguments* args,
|
gin_helper::ErrorThrower thrower,
|
||||||
v8::Local<v8::Value> buffer,
|
v8::Local<v8::Value> buffer,
|
||||||
const mate::Dictionary& options);
|
const gin_helper::Dictionary& options);
|
||||||
static mate::Handle<NativeImage> CreateFromBuffer(
|
static mate::Handle<NativeImage> CreateFromBuffer(
|
||||||
mate::Arguments* args,
|
gin_helper::ErrorThrower thrower,
|
||||||
v8::Local<v8::Value> buffer);
|
v8::Local<v8::Value> buffer,
|
||||||
|
gin::Arguments* args);
|
||||||
static mate::Handle<NativeImage> CreateFromDataURL(v8::Isolate* isolate,
|
static mate::Handle<NativeImage> CreateFromDataURL(v8::Isolate* isolate,
|
||||||
const GURL& url);
|
const GURL& url);
|
||||||
static mate::Handle<NativeImage> CreateFromNamedImage(
|
static mate::Handle<NativeImage> CreateFromNamedImage(
|
||||||
mate::Arguments* args,
|
gin::Arguments* args,
|
||||||
const std::string& name);
|
const std::string& name);
|
||||||
|
|
||||||
static void BuildPrototype(v8::Isolate* isolate,
|
static void BuildPrototype(v8::Isolate* isolate,
|
||||||
|
@ -81,20 +82,19 @@ class NativeImage : public mate::Wrappable<NativeImage> {
|
||||||
~NativeImage() override;
|
~NativeImage() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
v8::Local<v8::Value> ToPNG(mate::Arguments* args);
|
v8::Local<v8::Value> ToPNG(gin::Arguments* args);
|
||||||
v8::Local<v8::Value> ToJPEG(v8::Isolate* isolate, int quality);
|
v8::Local<v8::Value> ToJPEG(v8::Isolate* isolate, int quality);
|
||||||
v8::Local<v8::Value> ToBitmap(mate::Arguments* args);
|
v8::Local<v8::Value> ToBitmap(gin::Arguments* args);
|
||||||
v8::Local<v8::Value> GetBitmap(mate::Arguments* args);
|
v8::Local<v8::Value> GetBitmap(gin::Arguments* args);
|
||||||
v8::Local<v8::Value> GetNativeHandle(v8::Isolate* isolate,
|
v8::Local<v8::Value> GetNativeHandle(gin_helper::ErrorThrower thrower);
|
||||||
mate::Arguments* args);
|
|
||||||
mate::Handle<NativeImage> Resize(v8::Isolate* isolate,
|
mate::Handle<NativeImage> Resize(v8::Isolate* isolate,
|
||||||
const base::DictionaryValue& options);
|
const base::DictionaryValue& options);
|
||||||
mate::Handle<NativeImage> Crop(v8::Isolate* isolate, const gfx::Rect& rect);
|
mate::Handle<NativeImage> Crop(v8::Isolate* isolate, const gfx::Rect& rect);
|
||||||
std::string ToDataURL(mate::Arguments* args);
|
std::string ToDataURL(gin::Arguments* args);
|
||||||
bool IsEmpty();
|
bool IsEmpty();
|
||||||
gfx::Size GetSize();
|
gfx::Size GetSize();
|
||||||
float GetAspectRatio();
|
float GetAspectRatio();
|
||||||
void AddRepresentation(const mate::Dictionary& options);
|
void AddRepresentation(const gin_helper::Dictionary& options);
|
||||||
|
|
||||||
// Mark the image as template image.
|
// Mark the image as template image.
|
||||||
void SetTemplateImage(bool setAsTemplate);
|
void SetTemplateImage(bool setAsTemplate);
|
||||||
|
@ -115,7 +115,7 @@ class NativeImage : public mate::Wrappable<NativeImage> {
|
||||||
|
|
||||||
} // namespace electron
|
} // namespace electron
|
||||||
|
|
||||||
namespace mate {
|
namespace gin {
|
||||||
|
|
||||||
// A custom converter that allows converting path to NativeImage.
|
// A custom converter that allows converting path to NativeImage.
|
||||||
template <>
|
template <>
|
||||||
|
@ -128,6 +128,27 @@ struct Converter<mate::Handle<electron::api::NativeImage>> {
|
||||||
mate::Handle<electron::api::NativeImage>* out);
|
mate::Handle<electron::api::NativeImage>* out);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace gin
|
||||||
|
|
||||||
|
namespace mate {
|
||||||
|
|
||||||
|
// Keep compatibility with native_mate code.
|
||||||
|
//
|
||||||
|
// TODO(zcbenz): Remove this after removing native_mate.
|
||||||
|
template <>
|
||||||
|
struct Converter<mate::Handle<electron::api::NativeImage>> {
|
||||||
|
static v8::Local<v8::Value> ToV8(
|
||||||
|
v8::Isolate* isolate,
|
||||||
|
const mate::Handle<electron::api::NativeImage>& val) {
|
||||||
|
return gin::ConvertToV8(isolate, val);
|
||||||
|
}
|
||||||
|
static bool FromV8(v8::Isolate* isolate,
|
||||||
|
v8::Local<v8::Value> val,
|
||||||
|
mate::Handle<electron::api::NativeImage>* out) {
|
||||||
|
return gin::ConvertFromV8(isolate, val, out);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace mate
|
} // namespace mate
|
||||||
|
|
||||||
#endif // SHELL_COMMON_API_ATOM_API_NATIVE_IMAGE_H_
|
#endif // SHELL_COMMON_API_ATOM_API_NATIVE_IMAGE_H_
|
||||||
|
|
|
@ -34,7 +34,7 @@ double safeShift(double in, double def) {
|
||||||
}
|
}
|
||||||
|
|
||||||
mate::Handle<NativeImage> NativeImage::CreateFromNamedImage(
|
mate::Handle<NativeImage> NativeImage::CreateFromNamedImage(
|
||||||
mate::Arguments* args,
|
gin::Arguments* args,
|
||||||
const std::string& name) {
|
const std::string& name) {
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
std::vector<double> hsl_shift;
|
std::vector<double> hsl_shift;
|
||||||
|
|
|
@ -84,10 +84,9 @@ bool MoveItemToTrash(gin::Arguments* args) {
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
bool WriteShortcutLink(const base::FilePath& shortcut_path,
|
bool WriteShortcutLink(const base::FilePath& shortcut_path,
|
||||||
gin::Arguments* args) {
|
gin_helper::Arguments* args) {
|
||||||
base::win::ShortcutOperation operation = base::win::SHORTCUT_CREATE_ALWAYS;
|
base::win::ShortcutOperation operation = base::win::SHORTCUT_CREATE_ALWAYS;
|
||||||
if (gin::ConvertFromV8(args->isolate(), args->PeekNext(), &operation))
|
args->GetNext(&operation);
|
||||||
args->Skip();
|
|
||||||
gin::Dictionary options = gin::Dictionary::CreateEmpty(args->isolate());
|
gin::Dictionary options = gin::Dictionary::CreateEmpty(args->isolate());
|
||||||
if (!args->GetNext(&options)) {
|
if (!args->GetNext(&options)) {
|
||||||
args->ThrowError();
|
args->ThrowError();
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
#include "electron/electron_version.h"
|
#include "electron/electron_version.h"
|
||||||
#include "shell/browser/browser.h"
|
#include "shell/browser/browser.h"
|
||||||
#include "shell/common/atom_constants.h"
|
#include "shell/common/atom_constants.h"
|
||||||
#include "shell/common/native_mate_converters/file_path_converter.h"
|
#include "shell/common/gin_converters/file_path_converter.h"
|
||||||
#include "shell/common/native_mate_converters/map_converter.h"
|
#include "shell/common/gin_helper/dictionary.h"
|
||||||
|
|
||||||
namespace crash_reporter {
|
namespace crash_reporter {
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ CrashReporter* CrashReporter::GetInstance() {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void CrashReporter::StartInstance(const mate::Dictionary& options) {
|
void CrashReporter::StartInstance(const gin_helper::Dictionary& options) {
|
||||||
auto* reporter = GetInstance();
|
auto* reporter = GetInstance();
|
||||||
if (!reporter)
|
if (!reporter)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -12,7 +12,10 @@
|
||||||
|
|
||||||
#include "base/files/file_path.h"
|
#include "base/files/file_path.h"
|
||||||
#include "base/macros.h"
|
#include "base/macros.h"
|
||||||
#include "native_mate/dictionary.h"
|
|
||||||
|
namespace gin_helper {
|
||||||
|
class Dictionary;
|
||||||
|
}
|
||||||
|
|
||||||
namespace crash_reporter {
|
namespace crash_reporter {
|
||||||
|
|
||||||
|
@ -25,7 +28,10 @@ class CrashReporter {
|
||||||
typedef std::pair<int, std::string> UploadReportResult; // upload-date, id
|
typedef std::pair<int, std::string> UploadReportResult; // upload-date, id
|
||||||
|
|
||||||
static CrashReporter* GetInstance();
|
static CrashReporter* GetInstance();
|
||||||
static void StartInstance(const mate::Dictionary& options);
|
// FIXME(zcbenz): We should not do V8 in this file, this method should only
|
||||||
|
// accept C++ struct as parameter, and atom_api_crash_reporter.cc is
|
||||||
|
// responsible for parsing the parameter from JavaScript.
|
||||||
|
static void StartInstance(const gin_helper::Dictionary& options);
|
||||||
|
|
||||||
bool IsInitialized();
|
bool IsInitialized();
|
||||||
void Start(const std::string& product_name,
|
void Start(const std::string& product_name,
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright (c) 2015 GitHub, Inc.
|
// Copyright (c) 2019 GitHub, Inc.
|
||||||
// Use of this source code is governed by the MIT license that can be
|
// Use of this source code is governed by the MIT license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
#include "shell/common/native_mate_converters/gfx_converter.h"
|
#include "shell/common/gin_converters/gfx_converter.h"
|
||||||
|
|
||||||
#include "native_mate/dictionary.h"
|
|
||||||
#include "shell/common/gin_helper/dictionary.h"
|
#include "shell/common/gin_helper/dictionary.h"
|
||||||
#include "ui/display/display.h"
|
#include "ui/display/display.h"
|
||||||
#include "ui/display/screen.h"
|
#include "ui/display/screen.h"
|
||||||
#include "ui/gfx/geometry/point.h"
|
#include "ui/gfx/geometry/point.h"
|
||||||
|
#include "ui/gfx/geometry/point_f.h"
|
||||||
#include "ui/gfx/geometry/rect.h"
|
#include "ui/gfx/geometry/rect.h"
|
||||||
#include "ui/gfx/geometry/size.h"
|
#include "ui/gfx/geometry/size.h"
|
||||||
|
|
||||||
namespace mate {
|
namespace gin {
|
||||||
|
|
||||||
v8::Local<v8::Value> Converter<gfx::Point>::ToV8(v8::Isolate* isolate,
|
v8::Local<v8::Value> Converter<gfx::Point>::ToV8(v8::Isolate* isolate,
|
||||||
const gfx::Point& val) {
|
const gfx::Point& val) {
|
||||||
|
@ -140,9 +140,8 @@ struct Converter<display::Display::TouchSupport> {
|
||||||
v8::Local<v8::Value> Converter<display::Display>::ToV8(
|
v8::Local<v8::Value> Converter<display::Display>::ToV8(
|
||||||
v8::Isolate* isolate,
|
v8::Isolate* isolate,
|
||||||
const display::Display& val) {
|
const display::Display& val) {
|
||||||
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate);
|
||||||
// TODO(zcbenz): Just call SetHidden when this file is converted to gin.
|
dict.SetHidden("simple", true);
|
||||||
gin_helper::Dictionary(isolate, dict.GetHandle()).SetHidden("simple", true);
|
|
||||||
dict.Set("id", val.id());
|
dict.Set("id", val.id());
|
||||||
dict.Set("bounds", val.bounds());
|
dict.Set("bounds", val.bounds());
|
||||||
dict.Set("workArea", val.work_area());
|
dict.Set("workArea", val.work_area());
|
||||||
|
@ -160,4 +159,4 @@ v8::Local<v8::Value> Converter<display::Display>::ToV8(
|
||||||
return dict.GetHandle();
|
return dict.GetHandle();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace mate
|
} // namespace gin
|
67
shell/common/gin_converters/gfx_converter.h
Normal file
67
shell/common/gin_converters/gfx_converter.h
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
// 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_GFX_CONVERTER_H_
|
||||||
|
#define SHELL_COMMON_GIN_CONVERTERS_GFX_CONVERTER_H_
|
||||||
|
|
||||||
|
#include "gin/converter.h"
|
||||||
|
|
||||||
|
namespace display {
|
||||||
|
class Display;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace gfx {
|
||||||
|
class Point;
|
||||||
|
class PointF;
|
||||||
|
class Size;
|
||||||
|
class Rect;
|
||||||
|
} // namespace gfx
|
||||||
|
|
||||||
|
namespace gin {
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct Converter<gfx::Point> {
|
||||||
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, const gfx::Point& val);
|
||||||
|
static bool FromV8(v8::Isolate* isolate,
|
||||||
|
v8::Local<v8::Value> val,
|
||||||
|
gfx::Point* out);
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct Converter<gfx::PointF> {
|
||||||
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||||
|
const gfx::PointF& val);
|
||||||
|
static bool FromV8(v8::Isolate* isolate,
|
||||||
|
v8::Local<v8::Value> val,
|
||||||
|
gfx::PointF* out);
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct Converter<gfx::Size> {
|
||||||
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, const gfx::Size& val);
|
||||||
|
static bool FromV8(v8::Isolate* isolate,
|
||||||
|
v8::Local<v8::Value> val,
|
||||||
|
gfx::Size* out);
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct Converter<gfx::Rect> {
|
||||||
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, const gfx::Rect& val);
|
||||||
|
static bool FromV8(v8::Isolate* isolate,
|
||||||
|
v8::Local<v8::Value> val,
|
||||||
|
gfx::Rect* out);
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct Converter<display::Display> {
|
||||||
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||||
|
const display::Display& val);
|
||||||
|
static bool FromV8(v8::Isolate* isolate,
|
||||||
|
v8::Local<v8::Value> val,
|
||||||
|
display::Display* out);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace gin
|
||||||
|
|
||||||
|
#endif // SHELL_COMMON_GIN_CONVERTERS_GFX_CONVERTER_H_
|
|
@ -5,6 +5,7 @@
|
||||||
#ifndef SHELL_COMMON_GIN_CONVERTERS_STD_CONVERTER_H_
|
#ifndef SHELL_COMMON_GIN_CONVERTERS_STD_CONVERTER_H_
|
||||||
#define SHELL_COMMON_GIN_CONVERTERS_STD_CONVERTER_H_
|
#define SHELL_COMMON_GIN_CONVERTERS_STD_CONVERTER_H_
|
||||||
|
|
||||||
|
#include <map>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
@ -115,6 +116,49 @@ struct Converter<std::set<T>> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename K, typename V>
|
||||||
|
struct Converter<std::map<K, V>> {
|
||||||
|
static bool FromV8(v8::Isolate* isolate,
|
||||||
|
v8::Local<v8::Value> value,
|
||||||
|
std::map<K, V>* out) {
|
||||||
|
if (!value->IsObject())
|
||||||
|
return false;
|
||||||
|
out->clear();
|
||||||
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
||||||
|
v8::Local<v8::Object> obj = value.As<v8::Object>();
|
||||||
|
v8::Local<v8::Array> keys = obj->GetPropertyNames(context).ToLocalChecked();
|
||||||
|
for (uint32_t i = 0; i < keys->Length(); ++i) {
|
||||||
|
v8::MaybeLocal<v8::Value> maybe_v8key = keys->Get(context, i);
|
||||||
|
if (maybe_v8key.IsEmpty())
|
||||||
|
return false;
|
||||||
|
v8::Local<v8::Value> v8key = maybe_v8key.ToLocalChecked();
|
||||||
|
v8::MaybeLocal<v8::Value> maybe_v8value = obj->Get(context, v8key);
|
||||||
|
if (maybe_v8value.IsEmpty())
|
||||||
|
return false;
|
||||||
|
K key;
|
||||||
|
V value;
|
||||||
|
if (!ConvertFromV8(isolate, v8key, &key) ||
|
||||||
|
!ConvertFromV8(isolate, maybe_v8value.ToLocalChecked(), &value))
|
||||||
|
return false;
|
||||||
|
(*out)[key] = std::move(value);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||||
|
const std::map<K, V>& dict) {
|
||||||
|
v8::Local<v8::Object> obj = v8::Object::New(isolate);
|
||||||
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
||||||
|
for (const auto& it : dict) {
|
||||||
|
if (obj->Set(context, ConvertToV8(isolate, it.first),
|
||||||
|
ConvertToV8(isolate, it.second))
|
||||||
|
.IsNothing())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace gin
|
} // namespace gin
|
||||||
|
|
||||||
#endif // SHELL_COMMON_GIN_CONVERTERS_STD_CONVERTER_H_
|
#endif // SHELL_COMMON_GIN_CONVERTERS_STD_CONVERTER_H_
|
||||||
|
|
34
shell/common/gin_helper/arguments.h
Normal file
34
shell/common/gin_helper/arguments.h
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
// Copyright 2019 The Chromium Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
|
// found in the LICENSE.chromium file.
|
||||||
|
|
||||||
|
#ifndef SHELL_COMMON_GIN_HELPER_ARGUMENTS_H_
|
||||||
|
#define SHELL_COMMON_GIN_HELPER_ARGUMENTS_H_
|
||||||
|
|
||||||
|
namespace gin_helper {
|
||||||
|
|
||||||
|
// Provides additional APIs to the gin::Arguments class.
|
||||||
|
class Arguments : public gin::Arguments {
|
||||||
|
public:
|
||||||
|
// Get the next argument, if conversion to T fails then state is unchanged.
|
||||||
|
//
|
||||||
|
// This is difference from gin::Arguments::GetNext which always advances the
|
||||||
|
// |next_| counter no matter whether the conversion succeeds.
|
||||||
|
template <typename T>
|
||||||
|
bool GetNext(T* out) {
|
||||||
|
v8::Local<v8::Value> val = PeekNext();
|
||||||
|
if (val.IsEmpty())
|
||||||
|
return false;
|
||||||
|
if (!gin::ConvertFromV8(isolate(), val, out))
|
||||||
|
return false;
|
||||||
|
Skip();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
// MUST NOT ADD ANY DATA MEMBER.
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace gin_helper
|
||||||
|
|
||||||
|
#endif // SHELL_COMMON_GIN_HELPER_ARGUMENTS_H_
|
|
@ -8,6 +8,7 @@
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
#include "gin/dictionary.h"
|
#include "gin/dictionary.h"
|
||||||
|
#include "shell/common/gin_converters/std_converter.h"
|
||||||
#include "shell/common/gin_helper/function_template.h"
|
#include "shell/common/gin_helper/function_template.h"
|
||||||
|
|
||||||
namespace gin_helper {
|
namespace gin_helper {
|
||||||
|
@ -27,15 +28,16 @@ class Dictionary : public gin::Dictionary {
|
||||||
Dictionary(const gin::Dictionary& dict) // NOLINT(runtime/explicit)
|
Dictionary(const gin::Dictionary& dict) // NOLINT(runtime/explicit)
|
||||||
: gin::Dictionary(dict) {}
|
: gin::Dictionary(dict) {}
|
||||||
|
|
||||||
// Difference from the Get method in gin::Dictionary:
|
// Differences from the Get method in gin::Dictionary:
|
||||||
// 1. This is a const method;
|
// 1. This is a const method;
|
||||||
// 2. It checks whether the key exists before reading.
|
// 2. It checks whether the key exists before reading;
|
||||||
template <typename T>
|
// 3. It accepts arbitrary type of key.
|
||||||
bool Get(base::StringPiece key, T* out) const {
|
template <typename K, typename V>
|
||||||
|
bool Get(const K& key, V* out) const {
|
||||||
// Check for existence before getting, otherwise this method will always
|
// Check for existence before getting, otherwise this method will always
|
||||||
// returns true when T == v8::Local<v8::Value>.
|
// returns true when T == v8::Local<v8::Value>.
|
||||||
v8::Local<v8::Context> context = isolate()->GetCurrentContext();
|
v8::Local<v8::Context> context = isolate()->GetCurrentContext();
|
||||||
v8::Local<v8::String> v8_key = gin::StringToV8(isolate(), key);
|
v8::Local<v8::Value> v8_key = gin::ConvertToV8(isolate(), key);
|
||||||
v8::Local<v8::Value> value;
|
v8::Local<v8::Value> value;
|
||||||
v8::Maybe<bool> result = GetHandle()->Has(context, v8_key);
|
v8::Maybe<bool> result = GetHandle()->Has(context, v8_key);
|
||||||
if (result.IsJust() && result.FromJust() &&
|
if (result.IsJust() && result.FromJust() &&
|
||||||
|
@ -44,6 +46,21 @@ class Dictionary : public gin::Dictionary {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Differences from the Set method in gin::Dictionary:
|
||||||
|
// 1. It accepts arbitrary type of key.
|
||||||
|
// 2. It forces using gin::ConvertFromV8 (would no longer be needed after
|
||||||
|
// removing native_mate).
|
||||||
|
template <typename K, typename V>
|
||||||
|
bool Set(const K& key, const V& val) {
|
||||||
|
v8::Local<v8::Value> v8_value;
|
||||||
|
if (!gin::TryConvertToV8(isolate(), val, &v8_value))
|
||||||
|
return false;
|
||||||
|
v8::Maybe<bool> result =
|
||||||
|
GetHandle()->Set(isolate()->GetCurrentContext(),
|
||||||
|
gin::ConvertToV8(isolate(), key), v8_value);
|
||||||
|
return !result.IsNothing() && result.FromJust();
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool GetHidden(base::StringPiece key, T* out) const {
|
bool GetHidden(base::StringPiece key, T* out) const {
|
||||||
v8::Local<v8::Context> context = isolate()->GetCurrentContext();
|
v8::Local<v8::Context> context = isolate()->GetCurrentContext();
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "base/bind.h"
|
#include "base/bind.h"
|
||||||
#include "base/callback.h"
|
#include "base/callback.h"
|
||||||
#include "gin/arguments.h"
|
#include "gin/arguments.h"
|
||||||
|
#include "shell/common/gin_helper/arguments.h"
|
||||||
#include "shell/common/gin_helper/destroyable.h"
|
#include "shell/common/gin_helper/destroyable.h"
|
||||||
#include "shell/common/gin_helper/error_thrower.h"
|
#include "shell/common/gin_helper/error_thrower.h"
|
||||||
|
|
||||||
|
@ -118,6 +119,15 @@ inline bool GetNextArgument(gin::Arguments* args,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Supports the gin_helper::Arguments.
|
||||||
|
inline bool GetNextArgument(gin::Arguments* args,
|
||||||
|
int create_flags,
|
||||||
|
bool is_first,
|
||||||
|
gin_helper::Arguments** result) {
|
||||||
|
*result = static_cast<gin_helper::Arguments*>(args);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Classes for generating and storing an argument pack of integer indices
|
// Classes for generating and storing an argument pack of integer indices
|
||||||
// (based on well-known "indices trick", see: http://goo.gl/bKKojn):
|
// (based on well-known "indices trick", see: http://goo.gl/bKKojn):
|
||||||
template <size_t... indices>
|
template <size_t... indices>
|
||||||
|
|
|
@ -6,60 +6,71 @@
|
||||||
#define SHELL_COMMON_NATIVE_MATE_CONVERTERS_GFX_CONVERTER_H_
|
#define SHELL_COMMON_NATIVE_MATE_CONVERTERS_GFX_CONVERTER_H_
|
||||||
|
|
||||||
#include "native_mate/converter.h"
|
#include "native_mate/converter.h"
|
||||||
#include "ui/gfx/geometry/point_f.h"
|
#include "shell/common/gin_converters/gfx_converter.h"
|
||||||
|
|
||||||
namespace display {
|
|
||||||
class Display;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace gfx {
|
|
||||||
class Point;
|
|
||||||
class Size;
|
|
||||||
class Rect;
|
|
||||||
} // namespace gfx
|
|
||||||
|
|
||||||
namespace mate {
|
namespace mate {
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct Converter<gfx::Point> {
|
struct Converter<gfx::Point> {
|
||||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, const gfx::Point& val);
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||||
|
const gfx::Point& val) {
|
||||||
|
return gin::ConvertToV8(isolate, val);
|
||||||
|
}
|
||||||
static bool FromV8(v8::Isolate* isolate,
|
static bool FromV8(v8::Isolate* isolate,
|
||||||
v8::Local<v8::Value> val,
|
v8::Local<v8::Value> val,
|
||||||
gfx::Point* out);
|
gfx::Point* out) {
|
||||||
|
return gin::ConvertFromV8(isolate, val, out);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct Converter<gfx::PointF> {
|
struct Converter<gfx::PointF> {
|
||||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||||
const gfx::PointF& val);
|
const gfx::PointF& val) {
|
||||||
|
return gin::ConvertToV8(isolate, val);
|
||||||
|
}
|
||||||
static bool FromV8(v8::Isolate* isolate,
|
static bool FromV8(v8::Isolate* isolate,
|
||||||
v8::Local<v8::Value> val,
|
v8::Local<v8::Value> val,
|
||||||
gfx::PointF* out);
|
gfx::PointF* out) {
|
||||||
|
return gin::ConvertFromV8(isolate, val, out);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct Converter<gfx::Size> {
|
struct Converter<gfx::Size> {
|
||||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, const gfx::Size& val);
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, const gfx::Size& val) {
|
||||||
|
return gin::ConvertToV8(isolate, val);
|
||||||
|
}
|
||||||
static bool FromV8(v8::Isolate* isolate,
|
static bool FromV8(v8::Isolate* isolate,
|
||||||
v8::Local<v8::Value> val,
|
v8::Local<v8::Value> val,
|
||||||
gfx::Size* out);
|
gfx::Size* out) {
|
||||||
|
return gin::ConvertFromV8(isolate, val, out);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct Converter<gfx::Rect> {
|
struct Converter<gfx::Rect> {
|
||||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, const gfx::Rect& val);
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, const gfx::Rect& val) {
|
||||||
|
return gin::ConvertToV8(isolate, val);
|
||||||
|
}
|
||||||
static bool FromV8(v8::Isolate* isolate,
|
static bool FromV8(v8::Isolate* isolate,
|
||||||
v8::Local<v8::Value> val,
|
v8::Local<v8::Value> val,
|
||||||
gfx::Rect* out);
|
gfx::Rect* out) {
|
||||||
|
return gin::ConvertFromV8(isolate, val, out);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct Converter<display::Display> {
|
struct Converter<display::Display> {
|
||||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||||
const display::Display& val);
|
const display::Display& val) {
|
||||||
|
return gin::ConvertToV8(isolate, val);
|
||||||
|
}
|
||||||
static bool FromV8(v8::Isolate* isolate,
|
static bool FromV8(v8::Isolate* isolate,
|
||||||
v8::Local<v8::Value> val,
|
v8::Local<v8::Value> val,
|
||||||
display::Display* out);
|
display::Display* out) {
|
||||||
|
return gin::ConvertFromV8(isolate, val, out);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace mate
|
} // namespace mate
|
||||||
|
|
|
@ -1,70 +0,0 @@
|
||||||
// Copyright (c) 2019 Slack Technologies, 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_MAP_CONVERTER_H_
|
|
||||||
#define SHELL_COMMON_NATIVE_MATE_CONVERTERS_MAP_CONVERTER_H_
|
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
#include "gin/converter.h"
|
|
||||||
|
|
||||||
namespace gin {
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
struct Converter<std::map<std::string, T>> {
|
|
||||||
static bool FromV8(v8::Isolate* isolate,
|
|
||||||
v8::Local<v8::Value> val,
|
|
||||||
std::map<std::string, T>* out) {
|
|
||||||
if (!val->IsObject())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
|
||||||
v8::Local<v8::Object> dict = val->ToObject(context).ToLocalChecked();
|
|
||||||
v8::Local<v8::Array> keys =
|
|
||||||
dict->GetOwnPropertyNames(context).ToLocalChecked();
|
|
||||||
for (uint32_t i = 0; i < keys->Length(); ++i) {
|
|
||||||
v8::Local<v8::Value> key = keys->Get(context, i).ToLocalChecked();
|
|
||||||
T value;
|
|
||||||
if (Converter<T>::FromV8(
|
|
||||||
isolate, dict->Get(context, key).ToLocalChecked(), &value))
|
|
||||||
(*out)[gin::V8ToString(isolate, key)] = std::move(value);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
|
||||||
const std::map<std::string, T>& val) {
|
|
||||||
v8::Local<v8::Object> result = v8::Object::New(isolate);
|
|
||||||
auto context = isolate->GetCurrentContext();
|
|
||||||
for (auto i = val.begin(); i != val.end(); i++) {
|
|
||||||
result
|
|
||||||
->Set(context, Converter<T>::ToV8(isolate, i->first),
|
|
||||||
Converter<T>::ToV8(isolate, i->second))
|
|
||||||
.Check();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace gin
|
|
||||||
|
|
||||||
namespace mate {
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
struct Converter<std::map<std::string, T>> {
|
|
||||||
static bool FromV8(v8::Isolate* isolate,
|
|
||||||
v8::Local<v8::Value> val,
|
|
||||||
std::map<std::string, T>* out) {
|
|
||||||
return gin::Converter<std::map<std::string, T>>::FromV8(isolate, val, out);
|
|
||||||
}
|
|
||||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
|
||||||
const std::map<std::string, T>& val) {
|
|
||||||
return gin::Converter<std::map<std::string, T>>::ToV8(isolate, val);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace mate
|
|
||||||
|
|
||||||
#endif // SHELL_COMMON_NATIVE_MATE_CONVERTERS_MAP_CONVERTER_H_
|
|
Loading…
Reference in a new issue