chore: remove native_mate (Part 3) (#20131)
* use gin converter in atom_api_menu * please only put necessary includes in header Having include in header means they have dependency relationship, putting arbitrary includes really really really really really makes refacoring much harder. * remove some simple uses of callback_converter_deprecated.h * use gin callback converter in file_dialog code * use gin in ErrorThrower * use gin in atom_bundle_mover * fix mistake in node stream * deprecate native_mate version of event_emitter_caller * use gin in node_bindings * remove usages of native_mate event_emitter_caller.h except for EventEmitter * fix compilation on Windows * gin::Arguments behaves differently on GetNext * just use StringToV8
This commit is contained in:
Родитель
7be1905023
Коммит
2c23e44ed9
|
@ -435,8 +435,8 @@ filenames = {
|
||||||
"shell/common/api/electron_bindings.cc",
|
"shell/common/api/electron_bindings.cc",
|
||||||
"shell/common/api/electron_bindings.h",
|
"shell/common/api/electron_bindings.h",
|
||||||
"shell/common/api/constructor.h",
|
"shell/common/api/constructor.h",
|
||||||
"shell/common/api/event_emitter_caller.cc",
|
"shell/common/api/event_emitter_caller_deprecated.cc",
|
||||||
"shell/common/api/event_emitter_caller.h",
|
"shell/common/api/event_emitter_caller_deprecated.h",
|
||||||
"shell/common/api/features.cc",
|
"shell/common/api/features.cc",
|
||||||
"shell/common/api/locker.cc",
|
"shell/common/api/locker.cc",
|
||||||
"shell/common/api/locker.h",
|
"shell/common/api/locker.h",
|
||||||
|
@ -494,6 +494,10 @@ filenames = {
|
||||||
"shell/common/gin_helper/destroyable.cc",
|
"shell/common/gin_helper/destroyable.cc",
|
||||||
"shell/common/gin_helper/destroyable.h",
|
"shell/common/gin_helper/destroyable.h",
|
||||||
"shell/common/gin_helper/dictionary.h",
|
"shell/common/gin_helper/dictionary.h",
|
||||||
|
"shell/common/gin_helper/error_thrower.cc",
|
||||||
|
"shell/common/gin_helper/error_thrower.h",
|
||||||
|
"shell/common/gin_helper/event_emitter_caller.cc",
|
||||||
|
"shell/common/gin_helper/event_emitter_caller.h",
|
||||||
"shell/common/gin_helper/function_template.cc",
|
"shell/common/gin_helper/function_template.cc",
|
||||||
"shell/common/gin_helper/function_template.h",
|
"shell/common/gin_helper/function_template.h",
|
||||||
"shell/common/heap_snapshot.cc",
|
"shell/common/heap_snapshot.cc",
|
||||||
|
@ -503,8 +507,6 @@ filenames = {
|
||||||
"shell/common/keyboard_util.h",
|
"shell/common/keyboard_util.h",
|
||||||
"shell/common/deprecate_util.cc",
|
"shell/common/deprecate_util.cc",
|
||||||
"shell/common/deprecate_util.h",
|
"shell/common/deprecate_util.h",
|
||||||
"shell/common/error_util.cc",
|
|
||||||
"shell/common/error_util.h",
|
|
||||||
"shell/common/mouse_util.cc",
|
"shell/common/mouse_util.cc",
|
||||||
"shell/common/mouse_util.h",
|
"shell/common/mouse_util.h",
|
||||||
"shell/common/mac/main_application_bundle.h",
|
"shell/common/mac/main_application_bundle.h",
|
||||||
|
|
|
@ -97,6 +97,7 @@ class Arguments {
|
||||||
v8::Local<v8::Value> ThrowTypeError(const std::string& message) const;
|
v8::Local<v8::Value> ThrowTypeError(const std::string& message) const;
|
||||||
|
|
||||||
v8::Isolate* isolate() const { return isolate_; }
|
v8::Isolate* isolate() const { return isolate_; }
|
||||||
|
const v8::FunctionCallbackInfo<v8::Value>& info() const { return *info_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
v8::Isolate* isolate_ = nullptr;
|
v8::Isolate* isolate_ = nullptr;
|
||||||
|
|
|
@ -5,13 +5,11 @@
|
||||||
#ifndef NATIVE_MATE_NATIVE_MATE_FUNCTION_TEMPLATE_H_
|
#ifndef NATIVE_MATE_NATIVE_MATE_FUNCTION_TEMPLATE_H_
|
||||||
#define NATIVE_MATE_NATIVE_MATE_FUNCTION_TEMPLATE_H_
|
#define NATIVE_MATE_NATIVE_MATE_FUNCTION_TEMPLATE_H_
|
||||||
|
|
||||||
#include "../shell/common/error_util.h"
|
|
||||||
#include "../shell/common/gin_helper/destroyable.h"
|
#include "../shell/common/gin_helper/destroyable.h"
|
||||||
|
#include "../shell/common/gin_helper/error_thrower.h"
|
||||||
#include "base/callback.h"
|
#include "base/callback.h"
|
||||||
#include "base/logging.h"
|
|
||||||
#include "native_mate/arguments.h"
|
#include "native_mate/arguments.h"
|
||||||
#include "native_mate/wrappable_base.h"
|
#include "native_mate/wrappable_base.h"
|
||||||
#include "v8/include/v8.h"
|
|
||||||
|
|
||||||
// =============================== NOTICE ===============================
|
// =============================== NOTICE ===============================
|
||||||
// Do not add code here, native_mate is being removed. Any new code
|
// Do not add code here, native_mate is being removed. Any new code
|
||||||
|
@ -122,8 +120,8 @@ inline bool GetNextArgument(Arguments* args,
|
||||||
inline bool GetNextArgument(Arguments* args,
|
inline bool GetNextArgument(Arguments* args,
|
||||||
int create_flags,
|
int create_flags,
|
||||||
bool is_first,
|
bool is_first,
|
||||||
electron::util::ErrorThrower* result) {
|
gin_helper::ErrorThrower* result) {
|
||||||
*result = electron::util::ErrorThrower(args->isolate());
|
*result = gin_helper::ErrorThrower(args->isolate());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ web_contents.patch
|
||||||
webview_cross_drag.patch
|
webview_cross_drag.patch
|
||||||
disable_user_gesture_requirement_for_beforeunload_dialogs.patch
|
disable_user_gesture_requirement_for_beforeunload_dialogs.patch
|
||||||
gin_enable_disable_v8_platform.patch
|
gin_enable_disable_v8_platform.patch
|
||||||
|
gin_dictionary_default_constructor.patch
|
||||||
blink-worker-enable-csp-in-file-scheme.patch
|
blink-worker-enable-csp-in-file-scheme.patch
|
||||||
disable-redraw-lock.patch
|
disable-redraw-lock.patch
|
||||||
v8_context_snapshot_generator.patch
|
v8_context_snapshot_generator.patch
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Cheng Zhao <zcbenz@gmail.com>
|
||||||
|
Date: Thu, 4 Oct 2018 14:57:02 -0700
|
||||||
|
Subject: gin_dictionary_default_constructor.patch
|
||||||
|
|
||||||
|
Add default constructor for gin::Dictionary.
|
||||||
|
|
||||||
|
This is required for automatically converting arguments for functions that
|
||||||
|
take gin::Dictionary as parameter.
|
||||||
|
|
||||||
|
diff --git a/gin/dictionary.cc b/gin/dictionary.cc
|
||||||
|
index 95e00072700c..7643347890a5 100644
|
||||||
|
--- a/gin/dictionary.cc
|
||||||
|
+++ b/gin/dictionary.cc
|
||||||
|
@@ -6,6 +6,10 @@
|
||||||
|
|
||||||
|
namespace gin {
|
||||||
|
|
||||||
|
+Dictionary::Dictionary()
|
||||||
|
+ : isolate_(nullptr) {
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
Dictionary::Dictionary(v8::Isolate* isolate)
|
||||||
|
: isolate_(isolate) {
|
||||||
|
}
|
||||||
|
diff --git a/gin/dictionary.h b/gin/dictionary.h
|
||||||
|
index 2645d328b4c1..43b227dd7e48 100644
|
||||||
|
--- a/gin/dictionary.h
|
||||||
|
+++ b/gin/dictionary.h
|
||||||
|
@@ -24,6 +24,7 @@ namespace gin {
|
||||||
|
//
|
||||||
|
class GIN_EXPORT Dictionary {
|
||||||
|
public:
|
||||||
|
+ Dictionary();
|
||||||
|
explicit Dictionary(v8::Isolate* isolate);
|
||||||
|
Dictionary(v8::Isolate* isolate, v8::Local<v8::Object> object);
|
||||||
|
Dictionary(const Dictionary& other);
|
|
@ -15,6 +15,7 @@ const BLACKLIST = new Set([
|
||||||
['shell', 'browser', 'mac', 'atom_application_delegate.h'],
|
['shell', 'browser', 'mac', 'atom_application_delegate.h'],
|
||||||
['shell', 'browser', 'resources', 'win', 'resource.h'],
|
['shell', 'browser', 'resources', 'win', 'resource.h'],
|
||||||
['shell', 'browser', 'notifications', 'mac', 'notification_center_delegate.h'],
|
['shell', 'browser', 'notifications', 'mac', 'notification_center_delegate.h'],
|
||||||
|
['shell', 'browser', 'ui', 'cocoa', 'atom_bundle_mover.h'],
|
||||||
['shell', 'browser', 'ui', 'cocoa', 'atom_menu_controller.h'],
|
['shell', 'browser', 'ui', 'cocoa', 'atom_menu_controller.h'],
|
||||||
['shell', 'browser', 'ui', 'cocoa', 'atom_ns_window.h'],
|
['shell', 'browser', 'ui', 'cocoa', 'atom_ns_window.h'],
|
||||||
['shell', 'browser', 'ui', 'cocoa', 'atom_ns_window_delegate.h'],
|
['shell', 'browser', 'ui', 'cocoa', 'atom_ns_window_delegate.h'],
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "content/public/browser/gpu_data_manager.h"
|
#include "content/public/browser/gpu_data_manager.h"
|
||||||
#include "content/public/browser/render_frame_host.h"
|
#include "content/public/browser/render_frame_host.h"
|
||||||
#include "content/public/common/content_switches.h"
|
#include "content/public/common/content_switches.h"
|
||||||
|
#include "gin/arguments.h"
|
||||||
#include "media/audio/audio_manager.h"
|
#include "media/audio/audio_manager.h"
|
||||||
#include "native_mate/object_template_builder.h"
|
#include "native_mate/object_template_builder.h"
|
||||||
#include "net/ssl/client_cert_identity.h"
|
#include "net/ssl/client_cert_identity.h"
|
||||||
|
@ -846,7 +847,7 @@ void App::SetAppPath(const base::FilePath& app_path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(OS_MACOSX)
|
#if !defined(OS_MACOSX)
|
||||||
void App::SetAppLogsPath(util::ErrorThrower thrower,
|
void App::SetAppLogsPath(gin_helper::ErrorThrower thrower,
|
||||||
base::Optional<base::FilePath> custom_path) {
|
base::Optional<base::FilePath> custom_path) {
|
||||||
if (custom_path.has_value()) {
|
if (custom_path.has_value()) {
|
||||||
if (!custom_path->IsAbsolute()) {
|
if (!custom_path->IsAbsolute()) {
|
||||||
|
@ -865,7 +866,7 @@ void App::SetAppLogsPath(util::ErrorThrower thrower,
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
base::FilePath App::GetPath(util::ErrorThrower thrower,
|
base::FilePath App::GetPath(gin_helper::ErrorThrower thrower,
|
||||||
const std::string& name) {
|
const std::string& name) {
|
||||||
bool succeed = false;
|
bool succeed = false;
|
||||||
base::FilePath path;
|
base::FilePath path;
|
||||||
|
@ -888,7 +889,7 @@ base::FilePath App::GetPath(util::ErrorThrower thrower,
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::SetPath(util::ErrorThrower thrower,
|
void App::SetPath(gin_helper::ErrorThrower thrower,
|
||||||
const std::string& name,
|
const std::string& name,
|
||||||
const base::FilePath& path) {
|
const base::FilePath& path) {
|
||||||
if (!path.IsAbsolute()) {
|
if (!path.IsAbsolute()) {
|
||||||
|
@ -1031,7 +1032,7 @@ bool App::Relaunch(mate::Arguments* js_args) {
|
||||||
return relauncher::RelaunchApp(argv);
|
return relauncher::RelaunchApp(argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::DisableHardwareAcceleration(util::ErrorThrower thrower) {
|
void App::DisableHardwareAcceleration(gin_helper::ErrorThrower thrower) {
|
||||||
if (Browser::Get()->is_ready()) {
|
if (Browser::Get()->is_ready()) {
|
||||||
thrower.ThrowError(
|
thrower.ThrowError(
|
||||||
"app.disableHardwareAcceleration() can only be called "
|
"app.disableHardwareAcceleration() can only be called "
|
||||||
|
@ -1041,7 +1042,7 @@ void App::DisableHardwareAcceleration(util::ErrorThrower thrower) {
|
||||||
content::GpuDataManager::GetInstance()->DisableHardwareAcceleration();
|
content::GpuDataManager::GetInstance()->DisableHardwareAcceleration();
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::DisableDomainBlockingFor3DAPIs(util::ErrorThrower thrower) {
|
void App::DisableDomainBlockingFor3DAPIs(gin_helper::ErrorThrower thrower) {
|
||||||
if (Browser::Get()->is_ready()) {
|
if (Browser::Get()->is_ready()) {
|
||||||
thrower.ThrowError(
|
thrower.ThrowError(
|
||||||
"app.disableDomainBlockingFor3DAPIs() can only be called "
|
"app.disableDomainBlockingFor3DAPIs() can only be called "
|
||||||
|
@ -1057,7 +1058,7 @@ bool App::IsAccessibilitySupportEnabled() {
|
||||||
return ax_state->IsAccessibleBrowser();
|
return ax_state->IsAccessibleBrowser();
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::SetAccessibilitySupportEnabled(util::ErrorThrower thrower,
|
void App::SetAccessibilitySupportEnabled(gin_helper::ErrorThrower thrower,
|
||||||
bool enabled) {
|
bool enabled) {
|
||||||
if (!Browser::Get()->is_ready()) {
|
if (!Browser::Get()->is_ready()) {
|
||||||
thrower.ThrowError(
|
thrower.ThrowError(
|
||||||
|
@ -1314,7 +1315,7 @@ static void RemoveNoSandboxSwitch(base::CommandLine* command_line) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::EnableSandbox(util::ErrorThrower thrower) {
|
void App::EnableSandbox(gin_helper::ErrorThrower thrower) {
|
||||||
if (Browser::Get()->is_ready()) {
|
if (Browser::Get()->is_ready()) {
|
||||||
thrower.ThrowError(
|
thrower.ThrowError(
|
||||||
"app.enableSandbox() can only be called "
|
"app.enableSandbox() can only be called "
|
||||||
|
@ -1343,12 +1344,14 @@ bool App::CanBrowserClientUseCustomSiteInstance() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(OS_MACOSX)
|
#if defined(OS_MACOSX)
|
||||||
bool App::MoveToApplicationsFolder(mate::Arguments* args) {
|
bool App::MoveToApplicationsFolder(gin_helper::ErrorThrower thrower,
|
||||||
return ui::cocoa::AtomBundleMover::Move(args);
|
mate::Arguments* args) {
|
||||||
|
gin::Arguments gin_args(args->info());
|
||||||
|
return AtomBundleMover::Move(thrower, &gin_args);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool App::IsInApplicationsFolder() {
|
bool App::IsInApplicationsFolder() {
|
||||||
return ui::cocoa::AtomBundleMover::IsCurrentAppInApplicationsFolder();
|
return AtomBundleMover::IsCurrentAppInApplicationsFolder();
|
||||||
}
|
}
|
||||||
|
|
||||||
int DockBounce(mate::Arguments* args) {
|
int DockBounce(mate::Arguments* args) {
|
||||||
|
|
|
@ -27,8 +27,7 @@
|
||||||
#include "shell/browser/atom_browser_client.h"
|
#include "shell/browser/atom_browser_client.h"
|
||||||
#include "shell/browser/browser.h"
|
#include "shell/browser/browser.h"
|
||||||
#include "shell/browser/browser_observer.h"
|
#include "shell/browser/browser_observer.h"
|
||||||
#include "shell/common/error_util.h"
|
#include "shell/common/gin_helper/error_thrower.h"
|
||||||
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
|
|
||||||
#include "shell/common/promise_util.h"
|
#include "shell/common/promise_util.h"
|
||||||
|
|
||||||
#if defined(USE_NSS_CERTS)
|
#if defined(USE_NSS_CERTS)
|
||||||
|
@ -165,12 +164,13 @@ class App : public AtomBrowserClient::Delegate,
|
||||||
void ChildProcessLaunched(int process_type, base::ProcessHandle handle);
|
void ChildProcessLaunched(int process_type, base::ProcessHandle handle);
|
||||||
void ChildProcessDisconnected(base::ProcessId pid);
|
void ChildProcessDisconnected(base::ProcessId pid);
|
||||||
|
|
||||||
void SetAppLogsPath(util::ErrorThrower thrower,
|
void SetAppLogsPath(gin_helper::ErrorThrower thrower,
|
||||||
base::Optional<base::FilePath> custom_path);
|
base::Optional<base::FilePath> custom_path);
|
||||||
|
|
||||||
// Get/Set the pre-defined path in PathService.
|
// Get/Set the pre-defined path in PathService.
|
||||||
base::FilePath GetPath(util::ErrorThrower thrower, const std::string& name);
|
base::FilePath GetPath(gin_helper::ErrorThrower thrower,
|
||||||
void SetPath(util::ErrorThrower thrower,
|
const std::string& name);
|
||||||
|
void SetPath(gin_helper::ErrorThrower thrower,
|
||||||
const std::string& name,
|
const std::string& name,
|
||||||
const base::FilePath& path);
|
const base::FilePath& path);
|
||||||
|
|
||||||
|
@ -183,10 +183,11 @@ class App : public AtomBrowserClient::Delegate,
|
||||||
bool RequestSingleInstanceLock();
|
bool RequestSingleInstanceLock();
|
||||||
void ReleaseSingleInstanceLock();
|
void ReleaseSingleInstanceLock();
|
||||||
bool Relaunch(mate::Arguments* args);
|
bool Relaunch(mate::Arguments* args);
|
||||||
void DisableHardwareAcceleration(util::ErrorThrower thrower);
|
void DisableHardwareAcceleration(gin_helper::ErrorThrower thrower);
|
||||||
void DisableDomainBlockingFor3DAPIs(util::ErrorThrower thrower);
|
void DisableDomainBlockingFor3DAPIs(gin_helper::ErrorThrower thrower);
|
||||||
bool IsAccessibilitySupportEnabled();
|
bool IsAccessibilitySupportEnabled();
|
||||||
void SetAccessibilitySupportEnabled(util::ErrorThrower thrower, bool enabled);
|
void SetAccessibilitySupportEnabled(gin_helper::ErrorThrower thrower,
|
||||||
|
bool enabled);
|
||||||
Browser::LoginItemSettings GetLoginItemSettings(mate::Arguments* args);
|
Browser::LoginItemSettings GetLoginItemSettings(mate::Arguments* args);
|
||||||
#if defined(USE_NSS_CERTS)
|
#if defined(USE_NSS_CERTS)
|
||||||
void ImportCertificate(const base::DictionaryValue& options,
|
void ImportCertificate(const base::DictionaryValue& options,
|
||||||
|
@ -199,14 +200,15 @@ class App : public AtomBrowserClient::Delegate,
|
||||||
v8::Local<v8::Value> GetGPUFeatureStatus(v8::Isolate* isolate);
|
v8::Local<v8::Value> GetGPUFeatureStatus(v8::Isolate* isolate);
|
||||||
v8::Local<v8::Promise> GetGPUInfo(v8::Isolate* isolate,
|
v8::Local<v8::Promise> GetGPUInfo(v8::Isolate* isolate,
|
||||||
const std::string& info_type);
|
const std::string& info_type);
|
||||||
void EnableSandbox(util::ErrorThrower thrower);
|
void EnableSandbox(gin_helper::ErrorThrower thrower);
|
||||||
void SetUserAgentFallback(const std::string& user_agent);
|
void SetUserAgentFallback(const std::string& user_agent);
|
||||||
std::string GetUserAgentFallback();
|
std::string GetUserAgentFallback();
|
||||||
void SetBrowserClientCanUseCustomSiteInstance(bool should_disable);
|
void SetBrowserClientCanUseCustomSiteInstance(bool should_disable);
|
||||||
bool CanBrowserClientUseCustomSiteInstance();
|
bool CanBrowserClientUseCustomSiteInstance();
|
||||||
|
|
||||||
#if defined(OS_MACOSX)
|
#if defined(OS_MACOSX)
|
||||||
bool MoveToApplicationsFolder(mate::Arguments* args);
|
bool MoveToApplicationsFolder(gin_helper::ErrorThrower,
|
||||||
|
mate::Arguments* args);
|
||||||
bool IsInApplicationsFolder();
|
bool IsInApplicationsFolder();
|
||||||
v8::Local<v8::Value> GetDockAPI(v8::Isolate* isolate);
|
v8::Local<v8::Value> GetDockAPI(v8::Isolate* isolate);
|
||||||
v8::Global<v8::Value> dock_;
|
v8::Global<v8::Value> dock_;
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace electron {
|
||||||
|
|
||||||
namespace api {
|
namespace api {
|
||||||
|
|
||||||
void App::SetAppLogsPath(util::ErrorThrower thrower,
|
void App::SetAppLogsPath(gin_helper::ErrorThrower thrower,
|
||||||
base::Optional<base::FilePath> custom_path) {
|
base::Optional<base::FilePath> custom_path) {
|
||||||
if (custom_path.has_value()) {
|
if (custom_path.has_value()) {
|
||||||
if (!custom_path->IsAbsolute()) {
|
if (!custom_path->IsAbsolute()) {
|
||||||
|
|
|
@ -10,10 +10,12 @@
|
||||||
#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/api/event_emitter_caller.h"
|
#include "shell/common/gin_helper/event_emitter_caller.h"
|
||||||
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
|
|
||||||
#include "shell/common/node_includes.h"
|
#include "shell/common/node_includes.h"
|
||||||
|
|
||||||
|
// TODO(zcbenz): Remove this after removing mate::ObjectTemplateBuilder.
|
||||||
|
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
|
||||||
|
|
||||||
namespace mate {
|
namespace mate {
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
|
@ -48,7 +50,7 @@ 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(mate::StringToV8(isolate(), message));
|
||||||
mate::EmitEvent(
|
gin_helper::EmitEvent(
|
||||||
isolate(), GetWrapper(), "error",
|
isolate(), GetWrapper(), "error",
|
||||||
error->ToObject(isolate()->GetCurrentContext()).ToLocalChecked(),
|
error->ToObject(isolate()->GetCurrentContext()).ToLocalChecked(),
|
||||||
// Message is also emitted to keep compatibility with old code.
|
// Message is also emitted to keep compatibility with old code.
|
||||||
|
@ -76,7 +78,7 @@ void AutoUpdater::OnError(const std::string& message,
|
||||||
mate::StringToV8(isolate(), domain))
|
mate::StringToV8(isolate(), domain))
|
||||||
.Check();
|
.Check();
|
||||||
|
|
||||||
mate::EmitEvent(isolate(), GetWrapper(), "error", errorObject, message);
|
gin_helper::EmitEvent(isolate(), GetWrapper(), "error", errorObject, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutoUpdater::OnCheckingForUpdate() {
|
void AutoUpdater::OnCheckingForUpdate() {
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
#include "shell/browser/window_list.h"
|
#include "shell/browser/window_list.h"
|
||||||
#include "shell/common/api/constructor.h"
|
#include "shell/common/api/constructor.h"
|
||||||
#include "shell/common/color_util.h"
|
#include "shell/common/color_util.h"
|
||||||
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
|
|
||||||
#include "shell/common/native_mate_converters/value_converter.h"
|
#include "shell/common/native_mate_converters/value_converter.h"
|
||||||
#include "shell/common/node_includes.h"
|
#include "shell/common/node_includes.h"
|
||||||
#include "shell/common/options_switches.h"
|
#include "shell/common/options_switches.h"
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
#include "net/cookies/cookie_util.h"
|
#include "net/cookies/cookie_util.h"
|
||||||
#include "shell/browser/atom_browser_context.h"
|
#include "shell/browser/atom_browser_context.h"
|
||||||
#include "shell/browser/cookie_change_notifier.h"
|
#include "shell/browser/cookie_change_notifier.h"
|
||||||
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
|
|
||||||
#include "shell/common/native_mate_converters/gurl_converter.h"
|
#include "shell/common/native_mate_converters/gurl_converter.h"
|
||||||
#include "shell/common/native_mate_converters/value_converter.h"
|
#include "shell/common/native_mate_converters/value_converter.h"
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
#include "content/public/browser/devtools_agent_host.h"
|
#include "content/public/browser/devtools_agent_host.h"
|
||||||
#include "content/public/browser/web_contents.h"
|
#include "content/public/browser/web_contents.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "native_mate/dictionary.h"
|
||||||
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
|
|
||||||
#include "shell/common/native_mate_converters/value_converter.h"
|
#include "shell/common/native_mate_converters/value_converter.h"
|
||||||
#include "shell/common/node_includes.h"
|
#include "shell/common/node_includes.h"
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "shell/browser/ui/message_box.h"
|
#include "shell/browser/ui/message_box.h"
|
||||||
#include "shell/common/gin_converters/callback_converter.h"
|
#include "shell/common/gin_converters/callback_converter.h"
|
||||||
#include "shell/common/gin_converters/file_dialog_converter.h"
|
#include "shell/common/gin_converters/file_dialog_converter.h"
|
||||||
|
#include "shell/common/gin_converters/file_path_converter.h"
|
||||||
#include "shell/common/gin_converters/message_box_converter.h"
|
#include "shell/common/gin_converters/message_box_converter.h"
|
||||||
#include "shell/common/gin_converters/native_window_converter.h"
|
#include "shell/common/gin_converters/native_window_converter.h"
|
||||||
#include "shell/common/gin_converters/net_converter.h"
|
#include "shell/common/gin_converters/net_converter.h"
|
||||||
|
@ -59,7 +60,7 @@ void ShowOpenDialogSync(const file_dialog::DialogSettings& settings,
|
||||||
v8::Local<v8::Promise> ShowOpenDialog(
|
v8::Local<v8::Promise> ShowOpenDialog(
|
||||||
const file_dialog::DialogSettings& settings,
|
const file_dialog::DialogSettings& settings,
|
||||||
gin::Arguments* args) {
|
gin::Arguments* args) {
|
||||||
electron::util::Promise<mate::Dictionary> promise(args->isolate());
|
electron::util::Promise<gin::Dictionary> promise(args->isolate());
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
file_dialog::ShowOpenDialog(settings, std::move(promise));
|
file_dialog::ShowOpenDialog(settings, std::move(promise));
|
||||||
return handle;
|
return handle;
|
||||||
|
@ -75,7 +76,7 @@ void ShowSaveDialogSync(const file_dialog::DialogSettings& settings,
|
||||||
v8::Local<v8::Promise> ShowSaveDialog(
|
v8::Local<v8::Promise> ShowSaveDialog(
|
||||||
const file_dialog::DialogSettings& settings,
|
const file_dialog::DialogSettings& settings,
|
||||||
gin::Arguments* args) {
|
gin::Arguments* args) {
|
||||||
electron::util::Promise<mate::Dictionary> promise(args->isolate());
|
electron::util::Promise<gin::Dictionary> promise(args->isolate());
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
file_dialog::ShowSaveDialog(settings, std::move(promise));
|
file_dialog::ShowSaveDialog(settings, std::move(promise));
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
#include "native_mate/dictionary.h"
|
#include "native_mate/dictionary.h"
|
||||||
#include "net/base/filename_util.h"
|
#include "net/base/filename_util.h"
|
||||||
#include "shell/browser/atom_browser_main_parts.h"
|
#include "shell/browser/atom_browser_main_parts.h"
|
||||||
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
|
|
||||||
#include "shell/common/native_mate_converters/file_dialog_converter.h"
|
#include "shell/common/native_mate_converters/file_dialog_converter.h"
|
||||||
#include "shell/common/native_mate_converters/file_path_converter.h"
|
#include "shell/common/native_mate_converters/file_path_converter.h"
|
||||||
#include "shell/common/native_mate_converters/gurl_converter.h"
|
#include "shell/common/native_mate_converters/gurl_converter.h"
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "native_mate/dictionary.h"
|
#include "native_mate/dictionary.h"
|
||||||
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
|
|
||||||
#include "shell/common/node_includes.h"
|
#include "shell/common/node_includes.h"
|
||||||
|
|
||||||
namespace mate {
|
namespace mate {
|
||||||
|
|
|
@ -6,16 +6,19 @@
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
#include "gin/dictionary.h"
|
||||||
#include "native_mate/constructor.h"
|
#include "native_mate/constructor.h"
|
||||||
#include "native_mate/dictionary.h"
|
|
||||||
#include "native_mate/object_template_builder.h"
|
#include "native_mate/object_template_builder.h"
|
||||||
#include "shell/browser/native_window.h"
|
#include "shell/browser/native_window.h"
|
||||||
|
#include "shell/common/gin_converters/callback_converter.h"
|
||||||
#include "shell/common/native_mate_converters/accelerator_converter.h"
|
#include "shell/common/native_mate_converters/accelerator_converter.h"
|
||||||
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
|
|
||||||
#include "shell/common/native_mate_converters/image_converter.h"
|
#include "shell/common/native_mate_converters/image_converter.h"
|
||||||
#include "shell/common/native_mate_converters/string16_converter.h"
|
#include "shell/common/native_mate_converters/string16_converter.h"
|
||||||
#include "shell/common/node_includes.h"
|
#include "shell/common/node_includes.h"
|
||||||
|
|
||||||
|
// TODO(zcbenz): Remove this after removing mate::ObjectTemplateBuilder.
|
||||||
|
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
// We need this map to keep references to currently opened menus.
|
// We need this map to keep references to currently opened menus.
|
||||||
// Without this menus would be destroyed by js garbage collector
|
// Without this menus would be destroyed by js garbage collector
|
||||||
|
@ -40,8 +43,8 @@ Menu::~Menu() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::AfterInit(v8::Isolate* isolate) {
|
void Menu::AfterInit(v8::Isolate* isolate) {
|
||||||
mate::Dictionary wrappable(isolate, GetWrapper());
|
gin::Dictionary wrappable(isolate, GetWrapper());
|
||||||
mate::Dictionary delegate;
|
gin::Dictionary delegate(nullptr);
|
||||||
if (!wrappable.Get("delegate", &delegate))
|
if (!wrappable.Get("delegate", &delegate))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -144,4 +144,17 @@ struct Converter<electron::AtomMenuModel*> {
|
||||||
|
|
||||||
} // namespace mate
|
} // namespace mate
|
||||||
|
|
||||||
|
namespace gin {
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct Converter<electron::AtomMenuModel*> {
|
||||||
|
static bool FromV8(v8::Isolate* isolate,
|
||||||
|
v8::Local<v8::Value> val,
|
||||||
|
electron::AtomMenuModel** out) {
|
||||||
|
return mate::ConvertFromV8(isolate, val, out);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace gin
|
||||||
|
|
||||||
#endif // SHELL_BROWSER_API_ATOM_API_MENU_H_
|
#endif // SHELL_BROWSER_API_ATOM_API_MENU_H_
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
#include "native_mate/handle.h"
|
#include "native_mate/handle.h"
|
||||||
#include "shell/browser/atom_browser_context.h"
|
#include "shell/browser/atom_browser_context.h"
|
||||||
#include "shell/browser/net/system_network_context_manager.h"
|
#include "shell/browser/net/system_network_context_manager.h"
|
||||||
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
|
|
||||||
#include "shell/common/native_mate_converters/file_path_converter.h"
|
#include "shell/common/native_mate_converters/file_path_converter.h"
|
||||||
#include "shell/common/node_includes.h"
|
#include "shell/common/node_includes.h"
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
|
|
||||||
#include "base/power_monitor/power_monitor.h"
|
#include "base/power_monitor/power_monitor.h"
|
||||||
#include "base/power_monitor/power_monitor_device_source.h"
|
#include "base/power_monitor/power_monitor_device_source.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "gin/dictionary.h"
|
||||||
#include "shell/browser/browser.h"
|
#include "shell/browser/browser.h"
|
||||||
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
|
#include "shell/common/gin_converters/callback_converter.h"
|
||||||
#include "shell/common/node_includes.h"
|
#include "shell/common/node_includes.h"
|
||||||
|
|
||||||
namespace mate {
|
namespace mate {
|
||||||
|
@ -138,9 +138,8 @@ 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::Dictionary dict(isolate, exports);
|
||||||
dict.Set("createPowerMonitor",
|
dict.Set("createPowerMonitor", base::BindRepeating(&PowerMonitor::Create));
|
||||||
base::BindRepeating(&PowerMonitor::Create, isolate));
|
|
||||||
dict.Set("PowerMonitor", PowerMonitor::GetConstructor(isolate)
|
dict.Set("PowerMonitor", PowerMonitor::GetConstructor(isolate)
|
||||||
->GetFunction(context)
|
->GetFunction(context)
|
||||||
.ToLocalChecked());
|
.ToLocalChecked());
|
||||||
|
|
|
@ -8,9 +8,10 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "base/bind.h"
|
#include "base/bind.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "gin/dictionary.h"
|
||||||
#include "native_mate/object_template_builder.h"
|
#include "native_mate/object_template_builder.h"
|
||||||
#include "shell/browser/browser.h"
|
#include "shell/browser/browser.h"
|
||||||
|
#include "shell/common/gin_converters/callback_converter.h"
|
||||||
#include "shell/common/native_mate_converters/gfx_converter.h"
|
#include "shell/common/native_mate_converters/gfx_converter.h"
|
||||||
#include "shell/common/native_mate_converters/native_window_converter.h"
|
#include "shell/common/native_mate_converters/native_window_converter.h"
|
||||||
#include "shell/common/node_includes.h"
|
#include "shell/common/node_includes.h"
|
||||||
|
@ -182,8 +183,8 @@ 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::Dictionary dict(isolate, exports);
|
||||||
dict.Set("createScreen", base::BindRepeating(&Screen::Create, isolate));
|
dict.Set("createScreen", base::BindRepeating(&Screen::Create));
|
||||||
dict.Set(
|
dict.Set(
|
||||||
"Screen",
|
"Screen",
|
||||||
Screen::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());
|
Screen::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());
|
||||||
|
|
|
@ -58,6 +58,7 @@
|
||||||
#include "shell/common/native_mate_converters/file_path_converter.h"
|
#include "shell/common/native_mate_converters/file_path_converter.h"
|
||||||
#include "shell/common/native_mate_converters/gurl_converter.h"
|
#include "shell/common/native_mate_converters/gurl_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/once_callback.h"
|
||||||
#include "shell/common/native_mate_converters/value_converter.h"
|
#include "shell/common/native_mate_converters/value_converter.h"
|
||||||
#include "shell/common/node_includes.h"
|
#include "shell/common/node_includes.h"
|
||||||
#include "shell/common/options_switches.h"
|
#include "shell/common/options_switches.h"
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
#include "base/values.h"
|
#include "base/values.h"
|
||||||
#include "native_mate/handle.h"
|
#include "native_mate/handle.h"
|
||||||
#include "shell/browser/api/event_emitter.h"
|
#include "shell/browser/api/event_emitter.h"
|
||||||
#include "shell/common/error_util.h"
|
#include "shell/common/gin_helper/error_thrower.h"
|
||||||
#include "shell/common/promise_util.h"
|
#include "shell/common/promise_util.h"
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
|
@ -96,7 +96,7 @@ class SystemPreferences : public mate::EventEmitter<SystemPreferences>
|
||||||
void RemoveUserDefault(const std::string& name);
|
void RemoveUserDefault(const std::string& name);
|
||||||
bool IsSwipeTrackingFromScrollEventsEnabled();
|
bool IsSwipeTrackingFromScrollEventsEnabled();
|
||||||
|
|
||||||
std::string GetSystemColor(util::ErrorThrower thrower,
|
std::string GetSystemColor(gin_helper::ErrorThrower thrower,
|
||||||
const std::string& color);
|
const std::string& color);
|
||||||
|
|
||||||
bool CanPromptTouchID();
|
bool CanPromptTouchID();
|
||||||
|
|
|
@ -405,7 +405,7 @@ std::string SystemPreferences::GetAccentColor() {
|
||||||
return base::SysNSStringToUTF8([sysColor RGBAValue]);
|
return base::SysNSStringToUTF8([sysColor RGBAValue]);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string SystemPreferences::GetSystemColor(util::ErrorThrower thrower,
|
std::string SystemPreferences::GetSystemColor(gin_helper::ErrorThrower thrower,
|
||||||
const std::string& color) {
|
const std::string& color) {
|
||||||
NSColor* sysColor = nil;
|
NSColor* sysColor = nil;
|
||||||
if (color == "blue") {
|
if (color == "blue") {
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "electron/buildflags/buildflags.h"
|
#include "electron/buildflags/buildflags.h"
|
||||||
#include "gin/converter.h"
|
#include "gin/dictionary.h"
|
||||||
#include "native_mate/handle.h"
|
#include "native_mate/handle.h"
|
||||||
#include "native_mate/persistent_dictionary.h"
|
#include "native_mate/persistent_dictionary.h"
|
||||||
#include "shell/browser/api/atom_api_browser_view.h"
|
#include "shell/browser/api/atom_api_browser_view.h"
|
||||||
|
@ -16,7 +16,8 @@
|
||||||
#include "shell/browser/api/atom_api_view.h"
|
#include "shell/browser/api/atom_api_view.h"
|
||||||
#include "shell/browser/api/atom_api_web_contents.h"
|
#include "shell/browser/api/atom_api_web_contents.h"
|
||||||
#include "shell/common/color_util.h"
|
#include "shell/common/color_util.h"
|
||||||
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
|
#include "shell/common/gin_converters/callback_converter.h"
|
||||||
|
#include "shell/common/gin_converters/image_converter.h"
|
||||||
#include "shell/common/native_mate_converters/file_path_converter.h"
|
#include "shell/common/native_mate_converters/file_path_converter.h"
|
||||||
#include "shell/common/native_mate_converters/gfx_converter.h"
|
#include "shell/common/native_mate_converters/gfx_converter.h"
|
||||||
#include "shell/common/native_mate_converters/image_converter.h"
|
#include "shell/common/native_mate_converters/image_converter.h"
|
||||||
|
@ -35,6 +36,9 @@
|
||||||
#include "ui/base/win/shell.h"
|
#include "ui/base/win/shell.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// TODO(zcbenz): Remove this after removing mate::ObjectTemplateBuilder.
|
||||||
|
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
namespace mate {
|
namespace mate {
|
||||||
|
|
||||||
|
@ -43,8 +47,8 @@ struct Converter<electron::TaskbarHost::ThumbarButton> {
|
||||||
static bool FromV8(v8::Isolate* isolate,
|
static bool FromV8(v8::Isolate* isolate,
|
||||||
v8::Handle<v8::Value> val,
|
v8::Handle<v8::Value> val,
|
||||||
electron::TaskbarHost::ThumbarButton* out) {
|
electron::TaskbarHost::ThumbarButton* out) {
|
||||||
mate::Dictionary dict;
|
gin::Dictionary dict;
|
||||||
if (!ConvertFromV8(isolate, val, &dict))
|
if (!gin::ConvertFromV8(isolate, val, &dict))
|
||||||
return false;
|
return false;
|
||||||
dict.Get("click", &(out->clicked_callback));
|
dict.Get("click", &(out->clicked_callback));
|
||||||
dict.Get("tooltip", &(out->tooltip));
|
dict.Get("tooltip", &(out->tooltip));
|
||||||
|
|
|
@ -69,7 +69,6 @@
|
||||||
#include "shell/browser/web_contents_zoom_controller.h"
|
#include "shell/browser/web_contents_zoom_controller.h"
|
||||||
#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/api/event_emitter_caller.h"
|
|
||||||
#include "shell/common/color_util.h"
|
#include "shell/common/color_util.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"
|
||||||
|
|
|
@ -566,4 +566,22 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||||
|
|
||||||
} // namespace electron
|
} // namespace electron
|
||||||
|
|
||||||
|
namespace gin {
|
||||||
|
|
||||||
|
// TODO(zcbenz): Remove this after converting WebContents to gin::Wrapper.
|
||||||
|
template <>
|
||||||
|
struct Converter<electron::api::WebContents*> {
|
||||||
|
static bool FromV8(v8::Isolate* isolate,
|
||||||
|
v8::Local<v8::Value> val,
|
||||||
|
electron::api::WebContents** out) {
|
||||||
|
return mate::ConvertFromV8(isolate, val, out);
|
||||||
|
}
|
||||||
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||||
|
electron::api::WebContents* in) {
|
||||||
|
return mate::ConvertToV8(isolate, in);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace gin
|
||||||
|
|
||||||
#endif // SHELL_BROWSER_API_ATOM_API_WEB_CONTENTS_H_
|
#endif // SHELL_BROWSER_API_ATOM_API_WEB_CONTENTS_H_
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
#include "content/public/browser/browser_thread.h"
|
#include "content/public/browser/browser_thread.h"
|
||||||
#include "electron/shell/common/api/api.mojom.h"
|
#include "electron/shell/common/api/api.mojom.h"
|
||||||
#include "native_mate/wrappable.h"
|
#include "native_mate/wrappable.h"
|
||||||
#include "shell/common/api/event_emitter_caller.h"
|
#include "shell/common/api/event_emitter_caller_deprecated.h"
|
||||||
|
|
||||||
namespace content {
|
namespace content {
|
||||||
class RenderFrameHost;
|
class RenderFrameHost;
|
||||||
|
|
|
@ -17,13 +17,15 @@
|
||||||
#include "content/public/browser/browser_thread.h"
|
#include "content/public/browser/browser_thread.h"
|
||||||
#include "content/public/browser/download_item_utils.h"
|
#include "content/public/browser/download_item_utils.h"
|
||||||
#include "content/public/browser/download_manager.h"
|
#include "content/public/browser/download_manager.h"
|
||||||
|
#include "gin/dictionary.h"
|
||||||
#include "net/base/filename_util.h"
|
#include "net/base/filename_util.h"
|
||||||
#include "shell/browser/api/atom_api_download_item.h"
|
#include "shell/browser/api/atom_api_download_item.h"
|
||||||
#include "shell/browser/atom_browser_context.h"
|
#include "shell/browser/atom_browser_context.h"
|
||||||
#include "shell/browser/native_window.h"
|
#include "shell/browser/native_window.h"
|
||||||
#include "shell/browser/ui/file_dialog.h"
|
#include "shell/browser/ui/file_dialog.h"
|
||||||
#include "shell/browser/web_contents_preferences.h"
|
#include "shell/browser/web_contents_preferences.h"
|
||||||
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
|
#include "shell/common/gin_converters/callback_converter.h"
|
||||||
|
#include "shell/common/gin_converters/file_path_converter.h"
|
||||||
#include "shell/common/options_switches.h"
|
#include "shell/common/options_switches.h"
|
||||||
|
|
||||||
namespace electron {
|
namespace electron {
|
||||||
|
@ -122,7 +124,7 @@ void AtomDownloadManagerDelegate::OnDownloadPathGenerated(
|
||||||
settings.force_detached = offscreen;
|
settings.force_detached = offscreen;
|
||||||
|
|
||||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||||
electron::util::Promise<mate::Dictionary> dialog_promise(isolate);
|
electron::util::Promise<gin::Dictionary> dialog_promise(isolate);
|
||||||
auto dialog_callback =
|
auto dialog_callback =
|
||||||
base::BindOnce(&AtomDownloadManagerDelegate::OnDownloadSaveDialogDone,
|
base::BindOnce(&AtomDownloadManagerDelegate::OnDownloadSaveDialogDone,
|
||||||
base::Unretained(this), download_id, callback);
|
base::Unretained(this), download_id, callback);
|
||||||
|
@ -139,7 +141,7 @@ void AtomDownloadManagerDelegate::OnDownloadPathGenerated(
|
||||||
void AtomDownloadManagerDelegate::OnDownloadSaveDialogDone(
|
void AtomDownloadManagerDelegate::OnDownloadSaveDialogDone(
|
||||||
uint32_t download_id,
|
uint32_t download_id,
|
||||||
const content::DownloadTargetCallback& download_callback,
|
const content::DownloadTargetCallback& download_callback,
|
||||||
mate::Dictionary result) {
|
gin::Dictionary result) {
|
||||||
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
||||||
|
|
||||||
auto* item = download_manager_->GetDownload(download_id);
|
auto* item = download_manager_->GetDownload(download_id);
|
||||||
|
|
|
@ -48,7 +48,7 @@ class AtomDownloadManagerDelegate : public content::DownloadManagerDelegate {
|
||||||
void OnDownloadSaveDialogDone(
|
void OnDownloadSaveDialogDone(
|
||||||
uint32_t download_id,
|
uint32_t download_id,
|
||||||
const content::DownloadTargetCallback& download_callback,
|
const content::DownloadTargetCallback& download_callback,
|
||||||
mate::Dictionary result);
|
gin::Dictionary result);
|
||||||
|
|
||||||
content::DownloadManager* download_manager_;
|
content::DownloadManager* download_manager_;
|
||||||
base::WeakPtrFactory<AtomDownloadManagerDelegate> weak_ptr_factory_;
|
base::WeakPtrFactory<AtomDownloadManagerDelegate> weak_ptr_factory_;
|
||||||
|
|
|
@ -7,9 +7,7 @@
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "mojo/public/cpp/system/string_data_source.h"
|
#include "mojo/public/cpp/system/string_data_source.h"
|
||||||
#include "shell/common/api/event_emitter_caller.h"
|
#include "shell/common/gin_converters/callback_converter.h"
|
||||||
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
|
|
||||||
|
|
||||||
#include "shell/common/node_includes.h"
|
#include "shell/common/node_includes.h"
|
||||||
|
|
||||||
namespace electron {
|
namespace electron {
|
||||||
|
@ -41,7 +39,7 @@ NodeStreamLoader::~NodeStreamLoader() {
|
||||||
|
|
||||||
// Unsubscribe all handlers.
|
// Unsubscribe all handlers.
|
||||||
for (const auto& it : handlers_) {
|
for (const auto& it : handlers_) {
|
||||||
v8::Local<v8::Value> args[] = {mate::StringToV8(isolate_, it.first),
|
v8::Local<v8::Value> args[] = {gin::StringToV8(isolate_, it.first),
|
||||||
it.second.Get(isolate_)};
|
it.second.Get(isolate_)};
|
||||||
node::MakeCallback(isolate_, emitter_.Get(isolate_), "removeListener",
|
node::MakeCallback(isolate_, emitter_.Get(isolate_), "removeListener",
|
||||||
node::arraysize(args), args, {0, 0});
|
node::arraysize(args), args, {0, 0});
|
||||||
|
@ -142,8 +140,8 @@ void NodeStreamLoader::On(const char* event, EventCallback callback) {
|
||||||
|
|
||||||
// emitter.on(event, callback)
|
// emitter.on(event, callback)
|
||||||
v8::Local<v8::Value> args[] = {
|
v8::Local<v8::Value> args[] = {
|
||||||
mate::StringToV8(isolate_, event),
|
gin::StringToV8(isolate_, event),
|
||||||
mate::CallbackToV8(isolate_, std::move(callback)),
|
gin_helper::CallbackToV8Leaked(isolate_, std::move(callback)),
|
||||||
};
|
};
|
||||||
handlers_[event].Reset(isolate_, args[1]);
|
handlers_[event].Reset(isolate_, args[1]);
|
||||||
node::MakeCallback(isolate_, emitter_.Get(isolate_), "on",
|
node::MakeCallback(isolate_, emitter_.Get(isolate_), "on",
|
||||||
|
|
|
@ -23,6 +23,8 @@
|
||||||
#include "content/public/browser/browser_thread.h"
|
#include "content/public/browser/browser_thread.h"
|
||||||
#include "content/public/browser/render_frame_host.h"
|
#include "content/public/browser/render_frame_host.h"
|
||||||
#include "content/public/browser/web_contents.h"
|
#include "content/public/browser/web_contents.h"
|
||||||
|
#include "shell/common/api/locker.h"
|
||||||
|
|
||||||
#include "shell/common/node_includes.h"
|
#include "shell/common/node_includes.h"
|
||||||
|
|
||||||
using content::BrowserThread;
|
using content::BrowserThread;
|
||||||
|
|
|
@ -5,27 +5,27 @@
|
||||||
#ifndef SHELL_BROWSER_UI_COCOA_ATOM_BUNDLE_MOVER_H_
|
#ifndef SHELL_BROWSER_UI_COCOA_ATOM_BUNDLE_MOVER_H_
|
||||||
#define SHELL_BROWSER_UI_COCOA_ATOM_BUNDLE_MOVER_H_
|
#define SHELL_BROWSER_UI_COCOA_ATOM_BUNDLE_MOVER_H_
|
||||||
|
|
||||||
#include <string>
|
#include "base/mac/foundation_util.h"
|
||||||
|
#include "shell/common/gin_helper/error_thrower.h"
|
||||||
|
|
||||||
#include "native_mate/persistent_dictionary.h"
|
namespace gin {
|
||||||
|
class Arguments;
|
||||||
|
}
|
||||||
|
|
||||||
namespace electron {
|
namespace electron {
|
||||||
|
|
||||||
// Possible bundle movement conflicts
|
// Possible bundle movement conflicts
|
||||||
enum class BundlerMoverConflictType { EXISTS, EXISTS_AND_RUNNING };
|
enum class BundlerMoverConflictType { EXISTS, EXISTS_AND_RUNNING };
|
||||||
|
|
||||||
namespace ui {
|
|
||||||
|
|
||||||
namespace cocoa {
|
|
||||||
|
|
||||||
class AtomBundleMover {
|
class AtomBundleMover {
|
||||||
public:
|
public:
|
||||||
static bool Move(mate::Arguments* args);
|
static bool Move(gin_helper::ErrorThrower thrower, gin::Arguments* args);
|
||||||
static bool IsCurrentAppInApplicationsFolder();
|
static bool IsCurrentAppInApplicationsFolder();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool ShouldContinueMove(BundlerMoverConflictType type,
|
static bool ShouldContinueMove(gin_helper::ErrorThrower thrower,
|
||||||
mate::Arguments* args);
|
BundlerMoverConflictType type,
|
||||||
|
gin::Arguments* args);
|
||||||
static bool IsInApplicationsFolder(NSString* bundlePath);
|
static bool IsInApplicationsFolder(NSString* bundlePath);
|
||||||
static NSString* ContainingDiskImageDevice(NSString* bundlePath);
|
static NSString* ContainingDiskImageDevice(NSString* bundlePath);
|
||||||
static void Relaunch(NSString* destinationPath);
|
static void Relaunch(NSString* destinationPath);
|
||||||
|
@ -39,10 +39,6 @@ class AtomBundleMover {
|
||||||
static bool Trash(NSString* path);
|
static bool Trash(NSString* path);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace cocoa
|
|
||||||
|
|
||||||
} // namespace ui
|
|
||||||
|
|
||||||
} // namespace electron
|
} // namespace electron
|
||||||
|
|
||||||
#endif // SHELL_BROWSER_UI_COCOA_ATOM_BUNDLE_MOVER_H_
|
#endif // SHELL_BROWSER_UI_COCOA_ATOM_BUNDLE_MOVER_H_
|
||||||
|
|
|
@ -4,19 +4,17 @@
|
||||||
|
|
||||||
#import "shell/browser/ui/cocoa/atom_bundle_mover.h"
|
#import "shell/browser/ui/cocoa/atom_bundle_mover.h"
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#import <AppKit/AppKit.h>
|
#import <AppKit/AppKit.h>
|
||||||
#import <Foundation/Foundation.h>
|
|
||||||
#import <Security/Security.h>
|
#import <Security/Security.h>
|
||||||
#import <dlfcn.h>
|
#import <dlfcn.h>
|
||||||
#import <sys/mount.h>
|
#import <sys/mount.h>
|
||||||
#import <sys/param.h>
|
#import <sys/param.h>
|
||||||
|
|
||||||
#import "shell/browser/browser.h"
|
#include "gin/dictionary.h"
|
||||||
#include "shell/common/native_mate_converters/once_callback.h"
|
#include "shell/browser/browser.h"
|
||||||
|
#include "shell/common/gin_converters/callback_converter.h"
|
||||||
|
|
||||||
namespace mate {
|
namespace gin {
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct Converter<electron::BundlerMoverConflictType> {
|
struct Converter<electron::BundlerMoverConflictType> {
|
||||||
|
@ -24,26 +22,23 @@ struct Converter<electron::BundlerMoverConflictType> {
|
||||||
electron::BundlerMoverConflictType value) {
|
electron::BundlerMoverConflictType value) {
|
||||||
switch (value) {
|
switch (value) {
|
||||||
case electron::BundlerMoverConflictType::EXISTS:
|
case electron::BundlerMoverConflictType::EXISTS:
|
||||||
return mate::StringToV8(isolate, "exists");
|
return gin::StringToV8(isolate, "exists");
|
||||||
case electron::BundlerMoverConflictType::EXISTS_AND_RUNNING:
|
case electron::BundlerMoverConflictType::EXISTS_AND_RUNNING:
|
||||||
return mate::StringToV8(isolate, "existsAndRunning");
|
return gin::StringToV8(isolate, "existsAndRunning");
|
||||||
default:
|
default:
|
||||||
return mate::StringToV8(isolate, "");
|
return gin::StringToV8(isolate, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace mate
|
} // namespace gin
|
||||||
|
|
||||||
namespace electron {
|
namespace electron {
|
||||||
|
|
||||||
namespace ui {
|
bool AtomBundleMover::ShouldContinueMove(gin_helper::ErrorThrower thrower,
|
||||||
|
BundlerMoverConflictType type,
|
||||||
namespace cocoa {
|
gin::Arguments* args) {
|
||||||
|
gin::Dictionary options;
|
||||||
bool AtomBundleMover::ShouldContinueMove(BundlerMoverConflictType type,
|
|
||||||
mate::Arguments* args) {
|
|
||||||
mate::Dictionary options;
|
|
||||||
bool hasOptions = args->GetNext(&options);
|
bool hasOptions = args->GetNext(&options);
|
||||||
base::OnceCallback<v8::Local<v8::Value>(BundlerMoverConflictType)>
|
base::OnceCallback<v8::Local<v8::Value>(BundlerMoverConflictType)>
|
||||||
conflict_cb;
|
conflict_cb;
|
||||||
|
@ -57,13 +52,14 @@ bool AtomBundleMover::ShouldContinueMove(BundlerMoverConflictType type,
|
||||||
// we only want to throw an error if a user has returned a non-boolean
|
// we only want to throw an error if a user has returned a non-boolean
|
||||||
// value; this allows for client-side error handling should something in
|
// value; this allows for client-side error handling should something in
|
||||||
// the handler throw
|
// the handler throw
|
||||||
args->ThrowError("Invalid conflict handler return type.");
|
thrower.ThrowError("Invalid conflict handler return type.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AtomBundleMover::Move(mate::Arguments* args) {
|
bool AtomBundleMover::Move(gin_helper::ErrorThrower thrower,
|
||||||
|
gin::Arguments* args) {
|
||||||
// Path of the current bundle
|
// Path of the current bundle
|
||||||
NSString* bundlePath = [[NSBundle mainBundle] bundlePath];
|
NSString* bundlePath = [[NSBundle mainBundle] bundlePath];
|
||||||
|
|
||||||
|
@ -103,10 +99,10 @@ bool AtomBundleMover::Move(mate::Arguments* args) {
|
||||||
&authorizationCanceled)) {
|
&authorizationCanceled)) {
|
||||||
if (authorizationCanceled) {
|
if (authorizationCanceled) {
|
||||||
// User rejected the authorization request
|
// User rejected the authorization request
|
||||||
args->ThrowError("User rejected the authorization request");
|
thrower.ThrowError("User rejected the authorization request");
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
args->ThrowError(
|
thrower.ThrowError(
|
||||||
"Failed to copy to applications directory even with authorization");
|
"Failed to copy to applications directory even with authorization");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -117,8 +113,8 @@ bool AtomBundleMover::Move(mate::Arguments* args) {
|
||||||
// But first, make sure that it's not running
|
// But first, make sure that it's not running
|
||||||
if (IsApplicationAtPathRunning(destinationPath)) {
|
if (IsApplicationAtPathRunning(destinationPath)) {
|
||||||
// Check for callback handler and get user choice for open/quit
|
// Check for callback handler and get user choice for open/quit
|
||||||
if (!ShouldContinueMove(BundlerMoverConflictType::EXISTS_AND_RUNNING,
|
if (!ShouldContinueMove(
|
||||||
args))
|
thrower, BundlerMoverConflictType::EXISTS_AND_RUNNING, args))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Unless explicitly denied, give running app focus and terminate self
|
// Unless explicitly denied, give running app focus and terminate self
|
||||||
|
@ -131,20 +127,21 @@ bool AtomBundleMover::Move(mate::Arguments* args) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// Check callback handler and get user choice for app trashing
|
// Check callback handler and get user choice for app trashing
|
||||||
if (!ShouldContinueMove(BundlerMoverConflictType::EXISTS, args))
|
if (!ShouldContinueMove(thrower, BundlerMoverConflictType::EXISTS,
|
||||||
|
args))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Unless explicitly denied, attempt to trash old app
|
// Unless explicitly denied, attempt to trash old app
|
||||||
if (!Trash([applicationsDirectory
|
if (!Trash([applicationsDirectory
|
||||||
stringByAppendingPathComponent:bundleName])) {
|
stringByAppendingPathComponent:bundleName])) {
|
||||||
args->ThrowError("Failed to delete existing application");
|
thrower.ThrowError("Failed to delete existing application");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!CopyBundle(bundlePath, destinationPath)) {
|
if (!CopyBundle(bundlePath, destinationPath)) {
|
||||||
args->ThrowError(
|
thrower.ThrowError(
|
||||||
"Failed to copy current bundle to the applications folder");
|
"Failed to copy current bundle to the applications folder");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -466,8 +463,4 @@ bool AtomBundleMover::DeleteOrTrash(NSString* path) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace cocoa
|
|
||||||
|
|
||||||
} // namespace ui
|
|
||||||
|
|
||||||
} // namespace electron
|
} // namespace electron
|
||||||
|
|
|
@ -10,8 +10,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "base/files/file_path.h"
|
#include "base/files/file_path.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "gin/dictionary.h"
|
||||||
#include "shell/common/native_mate_converters/file_path_converter.h"
|
|
||||||
#include "shell/common/promise_util.h"
|
#include "shell/common/promise_util.h"
|
||||||
|
|
||||||
namespace electron {
|
namespace electron {
|
||||||
|
@ -66,12 +65,12 @@ bool ShowOpenDialogSync(const DialogSettings& settings,
|
||||||
std::vector<base::FilePath>* paths);
|
std::vector<base::FilePath>* paths);
|
||||||
|
|
||||||
void ShowOpenDialog(const DialogSettings& settings,
|
void ShowOpenDialog(const DialogSettings& settings,
|
||||||
electron::util::Promise<mate::Dictionary> promise);
|
electron::util::Promise<gin::Dictionary> promise);
|
||||||
|
|
||||||
bool ShowSaveDialogSync(const DialogSettings& settings, base::FilePath* path);
|
bool ShowSaveDialogSync(const DialogSettings& settings, base::FilePath* path);
|
||||||
|
|
||||||
void ShowSaveDialog(const DialogSettings& settings,
|
void ShowSaveDialog(const DialogSettings& settings,
|
||||||
electron::util::Promise<mate::Dictionary> promise);
|
electron::util::Promise<gin::Dictionary> promise);
|
||||||
|
|
||||||
} // namespace file_dialog
|
} // namespace file_dialog
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "chrome/browser/ui/libgtkui/gtk_util.h"
|
#include "chrome/browser/ui/libgtkui/gtk_util.h"
|
||||||
#include "shell/browser/native_window_views.h"
|
#include "shell/browser/native_window_views.h"
|
||||||
#include "shell/browser/unresponsive_suppressor.h"
|
#include "shell/browser/unresponsive_suppressor.h"
|
||||||
|
#include "shell/common/gin_converters/file_path_converter.h"
|
||||||
#include "ui/base/glib/glib_signal.h"
|
#include "ui/base/glib/glib_signal.h"
|
||||||
#include "ui/views/widget/desktop_aura/x11_desktop_handler.h"
|
#include "ui/views/widget/desktop_aura/x11_desktop_handler.h"
|
||||||
|
|
||||||
|
@ -137,15 +138,15 @@ class FileChooserDialog {
|
||||||
gtk_window_present_with_time(GTK_WINDOW(dialog_), time);
|
gtk_window_present_with_time(GTK_WINDOW(dialog_), time);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RunSaveAsynchronous(electron::util::Promise<mate::Dictionary> promise) {
|
void RunSaveAsynchronous(electron::util::Promise<gin::Dictionary> promise) {
|
||||||
save_promise_.reset(
|
save_promise_.reset(
|
||||||
new electron::util::Promise<mate::Dictionary>(std::move(promise)));
|
new electron::util::Promise<gin::Dictionary>(std::move(promise)));
|
||||||
RunAsynchronous();
|
RunAsynchronous();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RunOpenAsynchronous(electron::util::Promise<mate::Dictionary> promise) {
|
void RunOpenAsynchronous(electron::util::Promise<gin::Dictionary> promise) {
|
||||||
open_promise_.reset(
|
open_promise_.reset(
|
||||||
new electron::util::Promise<mate::Dictionary>(std::move(promise)));
|
new electron::util::Promise<gin::Dictionary>(std::move(promise)));
|
||||||
RunAsynchronous();
|
RunAsynchronous();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,8 +187,8 @@ class FileChooserDialog {
|
||||||
GtkWidget* preview_;
|
GtkWidget* preview_;
|
||||||
|
|
||||||
Filters filters_;
|
Filters filters_;
|
||||||
std::unique_ptr<electron::util::Promise<mate::Dictionary>> save_promise_;
|
std::unique_ptr<electron::util::Promise<gin::Dictionary>> save_promise_;
|
||||||
std::unique_ptr<electron::util::Promise<mate::Dictionary>> open_promise_;
|
std::unique_ptr<electron::util::Promise<gin::Dictionary>> open_promise_;
|
||||||
|
|
||||||
// Callback for when we update the preview for the selection.
|
// Callback for when we update the preview for the selection.
|
||||||
CHROMEG_CALLBACK_0(FileChooserDialog, void, OnUpdatePreview, GtkWidget*);
|
CHROMEG_CALLBACK_0(FileChooserDialog, void, OnUpdatePreview, GtkWidget*);
|
||||||
|
@ -198,8 +199,8 @@ class FileChooserDialog {
|
||||||
void FileChooserDialog::OnFileDialogResponse(GtkWidget* widget, int response) {
|
void FileChooserDialog::OnFileDialogResponse(GtkWidget* widget, int response) {
|
||||||
gtk_widget_hide(dialog_);
|
gtk_widget_hide(dialog_);
|
||||||
if (save_promise_) {
|
if (save_promise_) {
|
||||||
mate::Dictionary dict =
|
gin::Dictionary dict =
|
||||||
mate::Dictionary::CreateEmpty(save_promise_->isolate());
|
gin::Dictionary::CreateEmpty(save_promise_->isolate());
|
||||||
if (response == GTK_RESPONSE_ACCEPT) {
|
if (response == GTK_RESPONSE_ACCEPT) {
|
||||||
dict.Set("canceled", false);
|
dict.Set("canceled", false);
|
||||||
dict.Set("filePath", GetFileName());
|
dict.Set("filePath", GetFileName());
|
||||||
|
@ -207,10 +208,10 @@ void FileChooserDialog::OnFileDialogResponse(GtkWidget* widget, int response) {
|
||||||
dict.Set("canceled", true);
|
dict.Set("canceled", true);
|
||||||
dict.Set("filePath", base::FilePath());
|
dict.Set("filePath", base::FilePath());
|
||||||
}
|
}
|
||||||
save_promise_->Resolve(dict);
|
save_promise_->ResolveWithGin(dict);
|
||||||
} else if (open_promise_) {
|
} else if (open_promise_) {
|
||||||
mate::Dictionary dict =
|
gin::Dictionary dict =
|
||||||
mate::Dictionary::CreateEmpty(open_promise_->isolate());
|
gin::Dictionary::CreateEmpty(open_promise_->isolate());
|
||||||
if (response == GTK_RESPONSE_ACCEPT) {
|
if (response == GTK_RESPONSE_ACCEPT) {
|
||||||
dict.Set("canceled", false);
|
dict.Set("canceled", false);
|
||||||
dict.Set("filePaths", GetFileNames());
|
dict.Set("filePaths", GetFileNames());
|
||||||
|
@ -218,7 +219,7 @@ void FileChooserDialog::OnFileDialogResponse(GtkWidget* widget, int response) {
|
||||||
dict.Set("canceled", true);
|
dict.Set("canceled", true);
|
||||||
dict.Set("filePaths", std::vector<base::FilePath>());
|
dict.Set("filePaths", std::vector<base::FilePath>());
|
||||||
}
|
}
|
||||||
open_promise_->Resolve(dict);
|
open_promise_->ResolveWithGin(dict);
|
||||||
}
|
}
|
||||||
delete this;
|
delete this;
|
||||||
}
|
}
|
||||||
|
@ -294,7 +295,7 @@ bool ShowOpenDialogSync(const DialogSettings& settings,
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShowOpenDialog(const DialogSettings& settings,
|
void ShowOpenDialog(const DialogSettings& settings,
|
||||||
electron::util::Promise<mate::Dictionary> promise) {
|
electron::util::Promise<gin::Dictionary> promise) {
|
||||||
GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
|
GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
|
||||||
if (settings.properties & OPEN_DIALOG_OPEN_DIRECTORY)
|
if (settings.properties & OPEN_DIALOG_OPEN_DIRECTORY)
|
||||||
action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
|
action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
|
||||||
|
@ -317,7 +318,7 @@ bool ShowSaveDialogSync(const DialogSettings& settings, base::FilePath* path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShowSaveDialog(const DialogSettings& settings,
|
void ShowSaveDialog(const DialogSettings& settings,
|
||||||
electron::util::Promise<mate::Dictionary> promise) {
|
electron::util::Promise<gin::Dictionary> promise) {
|
||||||
FileChooserDialog* save_dialog =
|
FileChooserDialog* save_dialog =
|
||||||
new FileChooserDialog(GTK_FILE_CHOOSER_ACTION_SAVE, settings);
|
new FileChooserDialog(GTK_FILE_CHOOSER_ACTION_SAVE, settings);
|
||||||
save_dialog->RunSaveAsynchronous(std::move(promise));
|
save_dialog->RunSaveAsynchronous(std::move(promise));
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include "base/mac/scoped_cftyperef.h"
|
#include "base/mac/scoped_cftyperef.h"
|
||||||
#include "base/strings/sys_string_conversions.h"
|
#include "base/strings/sys_string_conversions.h"
|
||||||
#include "shell/browser/native_window.h"
|
#include "shell/browser/native_window.h"
|
||||||
|
#include "shell/common/gin_converters/file_path_converter.h"
|
||||||
|
|
||||||
@interface PopUpButtonHandler : NSObject
|
@interface PopUpButtonHandler : NSObject
|
||||||
|
|
||||||
|
@ -300,15 +301,15 @@ bool ShowOpenDialogSync(const DialogSettings& settings,
|
||||||
void OpenDialogCompletion(int chosen,
|
void OpenDialogCompletion(int chosen,
|
||||||
NSOpenPanel* dialog,
|
NSOpenPanel* dialog,
|
||||||
bool security_scoped_bookmarks,
|
bool security_scoped_bookmarks,
|
||||||
electron::util::Promise<mate::Dictionary> promise) {
|
electron::util::Promise<gin::Dictionary> promise) {
|
||||||
mate::Dictionary dict = mate::Dictionary::CreateEmpty(promise.isolate());
|
gin::Dictionary dict = gin::Dictionary::CreateEmpty(promise.isolate());
|
||||||
if (chosen == NSFileHandlingPanelCancelButton) {
|
if (chosen == NSFileHandlingPanelCancelButton) {
|
||||||
dict.Set("canceled", true);
|
dict.Set("canceled", true);
|
||||||
dict.Set("filePaths", std::vector<base::FilePath>());
|
dict.Set("filePaths", std::vector<base::FilePath>());
|
||||||
#if defined(MAS_BUILD)
|
#if defined(MAS_BUILD)
|
||||||
dict.Set("bookmarks", std::vector<std::string>());
|
dict.Set("bookmarks", std::vector<std::string>());
|
||||||
#endif
|
#endif
|
||||||
promise.Resolve(dict);
|
promise.ResolveWithGin(dict);
|
||||||
} else {
|
} else {
|
||||||
std::vector<base::FilePath> paths;
|
std::vector<base::FilePath> paths;
|
||||||
dict.Set("canceled", false);
|
dict.Set("canceled", false);
|
||||||
|
@ -324,12 +325,12 @@ void OpenDialogCompletion(int chosen,
|
||||||
ReadDialogPaths(dialog, &paths);
|
ReadDialogPaths(dialog, &paths);
|
||||||
dict.Set("filePaths", paths);
|
dict.Set("filePaths", paths);
|
||||||
#endif
|
#endif
|
||||||
promise.Resolve(dict);
|
promise.ResolveWithGin(dict);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShowOpenDialog(const DialogSettings& settings,
|
void ShowOpenDialog(const DialogSettings& settings,
|
||||||
electron::util::Promise<mate::Dictionary> promise) {
|
electron::util::Promise<gin::Dictionary> promise) {
|
||||||
NSOpenPanel* dialog = [NSOpenPanel openPanel];
|
NSOpenPanel* dialog = [NSOpenPanel openPanel];
|
||||||
|
|
||||||
SetupDialog(dialog, settings);
|
SetupDialog(dialog, settings);
|
||||||
|
@ -339,7 +340,7 @@ void ShowOpenDialog(const DialogSettings& settings,
|
||||||
// and pass it to the completion handler.
|
// and pass it to the completion handler.
|
||||||
bool security_scoped_bookmarks = settings.security_scoped_bookmarks;
|
bool security_scoped_bookmarks = settings.security_scoped_bookmarks;
|
||||||
|
|
||||||
__block electron::util::Promise<mate::Dictionary> p = std::move(promise);
|
__block electron::util::Promise<gin::Dictionary> p = std::move(promise);
|
||||||
|
|
||||||
if (!settings.parent_window || !settings.parent_window->GetNativeWindow() ||
|
if (!settings.parent_window || !settings.parent_window->GetNativeWindow() ||
|
||||||
settings.force_detached) {
|
settings.force_detached) {
|
||||||
|
@ -377,13 +378,13 @@ bool ShowSaveDialogSync(const DialogSettings& settings, base::FilePath* path) {
|
||||||
void SaveDialogCompletion(int chosen,
|
void SaveDialogCompletion(int chosen,
|
||||||
NSSavePanel* dialog,
|
NSSavePanel* dialog,
|
||||||
bool security_scoped_bookmarks,
|
bool security_scoped_bookmarks,
|
||||||
electron::util::Promise<mate::Dictionary> promise) {
|
electron::util::Promise<gin::Dictionary> promise) {
|
||||||
mate::Dictionary dict = mate::Dictionary::CreateEmpty(promise.isolate());
|
gin::Dictionary dict = gin::Dictionary::CreateEmpty(promise.isolate());
|
||||||
if (chosen == NSFileHandlingPanelCancelButton) {
|
if (chosen == NSFileHandlingPanelCancelButton) {
|
||||||
dict.Set("canceled", true);
|
dict.Set("canceled", true);
|
||||||
dict.Set("filePath", base::FilePath());
|
dict.Set("filePath", base::FilePath());
|
||||||
#if defined(MAS_BUILD)
|
#if defined(MAS_BUILD)
|
||||||
dict.Set("bookmark", "");
|
dict.Set("bookmark", base::StringPiece());
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
std::string path = base::SysNSStringToUTF8([[dialog URL] path]);
|
std::string path = base::SysNSStringToUTF8([[dialog URL] path]);
|
||||||
|
@ -397,11 +398,11 @@ void SaveDialogCompletion(int chosen,
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
promise.Resolve(dict);
|
promise.ResolveWithGin(dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShowSaveDialog(const DialogSettings& settings,
|
void ShowSaveDialog(const DialogSettings& settings,
|
||||||
electron::util::Promise<mate::Dictionary> promise) {
|
electron::util::Promise<gin::Dictionary> promise) {
|
||||||
NSSavePanel* dialog = [NSSavePanel savePanel];
|
NSSavePanel* dialog = [NSSavePanel savePanel];
|
||||||
|
|
||||||
SetupDialog(dialog, settings);
|
SetupDialog(dialog, settings);
|
||||||
|
@ -412,7 +413,7 @@ void ShowSaveDialog(const DialogSettings& settings,
|
||||||
// and pass it to the completion handler.
|
// and pass it to the completion handler.
|
||||||
bool security_scoped_bookmarks = settings.security_scoped_bookmarks;
|
bool security_scoped_bookmarks = settings.security_scoped_bookmarks;
|
||||||
|
|
||||||
__block electron::util::Promise<mate::Dictionary> p = std::move(promise);
|
__block electron::util::Promise<gin::Dictionary> p = std::move(promise);
|
||||||
|
|
||||||
if (!settings.parent_window || !settings.parent_window->GetNativeWindow() ||
|
if (!settings.parent_window || !settings.parent_window->GetNativeWindow() ||
|
||||||
settings.force_detached) {
|
settings.force_detached) {
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "base/win/registry.h"
|
#include "base/win/registry.h"
|
||||||
#include "shell/browser/native_window_views.h"
|
#include "shell/browser/native_window_views.h"
|
||||||
#include "shell/browser/unresponsive_suppressor.h"
|
#include "shell/browser/unresponsive_suppressor.h"
|
||||||
|
#include "shell/common/gin_converters/file_path_converter.h"
|
||||||
|
|
||||||
namespace file_dialog {
|
namespace file_dialog {
|
||||||
|
|
||||||
|
@ -81,19 +82,19 @@ bool CreateDialogThread(RunState* run_state) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnDialogOpened(electron::util::Promise<mate::Dictionary> promise,
|
void OnDialogOpened(electron::util::Promise<gin::Dictionary> promise,
|
||||||
bool canceled,
|
bool canceled,
|
||||||
std::vector<base::FilePath> paths) {
|
std::vector<base::FilePath> paths) {
|
||||||
mate::Dictionary dict = mate::Dictionary::CreateEmpty(promise.isolate());
|
gin::Dictionary dict = gin::Dictionary::CreateEmpty(promise.isolate());
|
||||||
dict.Set("canceled", canceled);
|
dict.Set("canceled", canceled);
|
||||||
dict.Set("filePaths", paths);
|
dict.Set("filePaths", paths);
|
||||||
promise.Resolve(dict);
|
promise.ResolveWithGin(dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RunOpenDialogInNewThread(
|
void RunOpenDialogInNewThread(
|
||||||
const RunState& run_state,
|
const RunState& run_state,
|
||||||
const DialogSettings& settings,
|
const DialogSettings& settings,
|
||||||
electron::util::Promise<mate::Dictionary> promise) {
|
electron::util::Promise<gin::Dictionary> promise) {
|
||||||
std::vector<base::FilePath> paths;
|
std::vector<base::FilePath> paths;
|
||||||
bool result = ShowOpenDialogSync(settings, &paths);
|
bool result = ShowOpenDialogSync(settings, &paths);
|
||||||
run_state.ui_task_runner->PostTask(
|
run_state.ui_task_runner->PostTask(
|
||||||
|
@ -102,19 +103,19 @@ void RunOpenDialogInNewThread(
|
||||||
run_state.ui_task_runner->DeleteSoon(FROM_HERE, run_state.dialog_thread);
|
run_state.ui_task_runner->DeleteSoon(FROM_HERE, run_state.dialog_thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnSaveDialogDone(electron::util::Promise<mate::Dictionary> promise,
|
void OnSaveDialogDone(electron::util::Promise<gin::Dictionary> promise,
|
||||||
bool canceled,
|
bool canceled,
|
||||||
const base::FilePath path) {
|
const base::FilePath path) {
|
||||||
mate::Dictionary dict = mate::Dictionary::CreateEmpty(promise.isolate());
|
gin::Dictionary dict = gin::Dictionary::CreateEmpty(promise.isolate());
|
||||||
dict.Set("canceled", canceled);
|
dict.Set("canceled", canceled);
|
||||||
dict.Set("filePath", path);
|
dict.Set("filePath", path);
|
||||||
promise.Resolve(dict);
|
promise.ResolveWithGin(dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RunSaveDialogInNewThread(
|
void RunSaveDialogInNewThread(
|
||||||
const RunState& run_state,
|
const RunState& run_state,
|
||||||
const DialogSettings& settings,
|
const DialogSettings& settings,
|
||||||
electron::util::Promise<mate::Dictionary> promise) {
|
electron::util::Promise<gin::Dictionary> promise) {
|
||||||
base::FilePath path;
|
base::FilePath path;
|
||||||
bool result = ShowSaveDialogSync(settings, &path);
|
bool result = ShowSaveDialogSync(settings, &path);
|
||||||
run_state.ui_task_runner->PostTask(
|
run_state.ui_task_runner->PostTask(
|
||||||
|
@ -276,13 +277,13 @@ bool ShowOpenDialogSync(const DialogSettings& settings,
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShowOpenDialog(const DialogSettings& settings,
|
void ShowOpenDialog(const DialogSettings& settings,
|
||||||
electron::util::Promise<mate::Dictionary> promise) {
|
electron::util::Promise<gin::Dictionary> promise) {
|
||||||
mate::Dictionary dict = mate::Dictionary::CreateEmpty(promise.isolate());
|
gin::Dictionary dict = gin::Dictionary::CreateEmpty(promise.isolate());
|
||||||
RunState run_state;
|
RunState run_state;
|
||||||
if (!CreateDialogThread(&run_state)) {
|
if (!CreateDialogThread(&run_state)) {
|
||||||
dict.Set("canceled", true);
|
dict.Set("canceled", true);
|
||||||
dict.Set("filePaths", std::vector<base::FilePath>());
|
dict.Set("filePaths", std::vector<base::FilePath>());
|
||||||
promise.Resolve(dict);
|
promise.ResolveWithGin(dict);
|
||||||
} else {
|
} else {
|
||||||
run_state.dialog_thread->task_runner()->PostTask(
|
run_state.dialog_thread->task_runner()->PostTask(
|
||||||
FROM_HERE, base::BindOnce(&RunOpenDialogInNewThread, run_state,
|
FROM_HERE, base::BindOnce(&RunOpenDialogInNewThread, run_state,
|
||||||
|
@ -326,13 +327,13 @@ bool ShowSaveDialogSync(const DialogSettings& settings, base::FilePath* path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShowSaveDialog(const DialogSettings& settings,
|
void ShowSaveDialog(const DialogSettings& settings,
|
||||||
electron::util::Promise<mate::Dictionary> promise) {
|
electron::util::Promise<gin::Dictionary> promise) {
|
||||||
RunState run_state;
|
RunState run_state;
|
||||||
if (!CreateDialogThread(&run_state)) {
|
if (!CreateDialogThread(&run_state)) {
|
||||||
mate::Dictionary dict = mate::Dictionary::CreateEmpty(promise.isolate());
|
gin::Dictionary dict = gin::Dictionary::CreateEmpty(promise.isolate());
|
||||||
dict.Set("canceled", true);
|
dict.Set("canceled", true);
|
||||||
dict.Set("filePath", base::FilePath());
|
dict.Set("filePath", base::FilePath());
|
||||||
promise.Resolve(dict);
|
promise.ResolveWithGin(dict);
|
||||||
} else {
|
} else {
|
||||||
run_state.dialog_thread->task_runner()->PostTask(
|
run_state.dialog_thread->task_runner()->PostTask(
|
||||||
FROM_HERE, base::BindOnce(&RunSaveDialogInNewThread, run_state,
|
FROM_HERE, base::BindOnce(&RunSaveDialogInNewThread, run_state,
|
||||||
|
|
|
@ -20,13 +20,14 @@
|
||||||
#include "content/public/browser/render_view_host.h"
|
#include "content/public/browser/render_view_host.h"
|
||||||
#include "content/public/browser/web_contents.h"
|
#include "content/public/browser/web_contents.h"
|
||||||
#include "content/public/browser/web_contents_observer.h"
|
#include "content/public/browser/web_contents_observer.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "gin/dictionary.h"
|
||||||
#include "net/base/directory_lister.h"
|
#include "net/base/directory_lister.h"
|
||||||
#include "net/base/mime_util.h"
|
#include "net/base/mime_util.h"
|
||||||
#include "shell/browser/atom_browser_context.h"
|
#include "shell/browser/atom_browser_context.h"
|
||||||
#include "shell/browser/native_window.h"
|
#include "shell/browser/native_window.h"
|
||||||
#include "shell/browser/ui/file_dialog.h"
|
#include "shell/browser/ui/file_dialog.h"
|
||||||
#include "shell/common/native_mate_converters/once_callback.h"
|
#include "shell/common/gin_converters/callback_converter.h"
|
||||||
|
#include "shell/common/gin_converters/file_path_converter.h"
|
||||||
#include "ui/shell_dialogs/selected_file_info.h"
|
#include "ui/shell_dialogs/selected_file_info.h"
|
||||||
|
|
||||||
using blink::mojom::FileChooserFileInfo;
|
using blink::mojom::FileChooserFileInfo;
|
||||||
|
@ -54,7 +55,7 @@ class FileSelectHelper : public base::RefCounted<FileSelectHelper>,
|
||||||
|
|
||||||
void ShowOpenDialog(const file_dialog::DialogSettings& settings) {
|
void ShowOpenDialog(const file_dialog::DialogSettings& settings) {
|
||||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||||
electron::util::Promise<mate::Dictionary> promise(isolate);
|
electron::util::Promise<gin::Dictionary> promise(isolate);
|
||||||
|
|
||||||
auto callback = base::BindOnce(&FileSelectHelper::OnOpenDialogDone, this);
|
auto callback = base::BindOnce(&FileSelectHelper::OnOpenDialogDone, this);
|
||||||
ignore_result(promise.Then(std::move(callback)));
|
ignore_result(promise.Then(std::move(callback)));
|
||||||
|
@ -64,7 +65,7 @@ class FileSelectHelper : public base::RefCounted<FileSelectHelper>,
|
||||||
|
|
||||||
void ShowSaveDialog(const file_dialog::DialogSettings& settings) {
|
void ShowSaveDialog(const file_dialog::DialogSettings& settings) {
|
||||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||||
electron::util::Promise<mate::Dictionary> promise(isolate);
|
electron::util::Promise<gin::Dictionary> promise(isolate);
|
||||||
|
|
||||||
auto callback = base::BindOnce(&FileSelectHelper::OnSaveDialogDone, this);
|
auto callback = base::BindOnce(&FileSelectHelper::OnSaveDialogDone, this);
|
||||||
ignore_result(promise.Then(std::move(callback)));
|
ignore_result(promise.Then(std::move(callback)));
|
||||||
|
@ -115,7 +116,7 @@ class FileSelectHelper : public base::RefCounted<FileSelectHelper>,
|
||||||
AddRef();
|
AddRef();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnOpenDialogDone(mate::Dictionary result) {
|
void OnOpenDialogDone(gin::Dictionary result) {
|
||||||
std::vector<FileChooserFileInfoPtr> file_info;
|
std::vector<FileChooserFileInfoPtr> file_info;
|
||||||
bool canceled = true;
|
bool canceled = true;
|
||||||
result.Get("canceled", &canceled);
|
result.Get("canceled", &canceled);
|
||||||
|
@ -157,7 +158,7 @@ class FileSelectHelper : public base::RefCounted<FileSelectHelper>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnSaveDialogDone(mate::Dictionary result) {
|
void OnSaveDialogDone(gin::Dictionary result) {
|
||||||
std::vector<FileChooserFileInfoPtr> file_info;
|
std::vector<FileChooserFileInfoPtr> file_info;
|
||||||
bool canceled = true;
|
bool canceled = true;
|
||||||
result.Get("canceled", &canceled);
|
result.Get("canceled", &canceled);
|
||||||
|
|
|
@ -7,11 +7,11 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "native_mate/arguments.h"
|
#include "native_mate/arguments.h"
|
||||||
#include "native_mate/dictionary.h"
|
|
||||||
#include "native_mate/object_template_builder.h"
|
#include "native_mate/object_template_builder.h"
|
||||||
#include "native_mate/wrappable.h"
|
#include "native_mate/wrappable.h"
|
||||||
#include "shell/common/asar/archive.h"
|
#include "shell/common/asar/archive.h"
|
||||||
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
|
#include "shell/common/gin_converters/callback_converter.h"
|
||||||
|
#include "shell/common/gin_helper/dictionary.h"
|
||||||
#include "shell/common/native_mate_converters/file_path_converter.h"
|
#include "shell/common/native_mate_converters/file_path_converter.h"
|
||||||
#include "shell/common/node_includes.h"
|
#include "shell/common/node_includes.h"
|
||||||
#include "third_party/electron_node/src/node_native_module_env.h"
|
#include "third_party/electron_node/src/node_native_module_env.h"
|
||||||
|
@ -56,7 +56,7 @@ class Archive : public mate::Wrappable<Archive> {
|
||||||
asar::Archive::FileInfo info;
|
asar::Archive::FileInfo info;
|
||||||
if (!archive_ || !archive_->GetFileInfo(path, &info))
|
if (!archive_ || !archive_->GetFileInfo(path, &info))
|
||||||
return v8::False(isolate);
|
return v8::False(isolate);
|
||||||
mate::Dictionary dict(isolate, v8::Object::New(isolate));
|
gin_helper::Dictionary dict(isolate, v8::Object::New(isolate));
|
||||||
dict.Set("size", info.size);
|
dict.Set("size", info.size);
|
||||||
dict.Set("unpacked", info.unpacked);
|
dict.Set("unpacked", info.unpacked);
|
||||||
dict.Set("offset", info.offset);
|
dict.Set("offset", info.offset);
|
||||||
|
@ -68,7 +68,7 @@ class Archive : public mate::Wrappable<Archive> {
|
||||||
asar::Archive::Stats stats;
|
asar::Archive::Stats stats;
|
||||||
if (!archive_ || !archive_->Stat(path, &stats))
|
if (!archive_ || !archive_->Stat(path, &stats))
|
||||||
return v8::False(isolate);
|
return v8::False(isolate);
|
||||||
mate::Dictionary dict(isolate, v8::Object::New(isolate));
|
gin_helper::Dictionary dict(isolate, v8::Object::New(isolate));
|
||||||
dict.Set("size", stats.size);
|
dict.Set("size", stats.size);
|
||||||
dict.Set("offset", stats.offset);
|
dict.Set("offset", stats.offset);
|
||||||
dict.Set("isFile", stats.is_file);
|
dict.Set("isFile", stats.is_file);
|
||||||
|
@ -131,7 +131,7 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||||
v8::Local<v8::Value> unused,
|
v8::Local<v8::Value> unused,
|
||||||
v8::Local<v8::Context> context,
|
v8::Local<v8::Context> context,
|
||||||
void* priv) {
|
void* priv) {
|
||||||
mate::Dictionary dict(context->GetIsolate(), exports);
|
gin_helper::Dictionary dict(context->GetIsolate(), exports);
|
||||||
dict.SetMethod("createArchive", &Archive::Create);
|
dict.SetMethod("createArchive", &Archive::Create);
|
||||||
dict.SetMethod("initAsarSupport", &InitAsarSupport);
|
dict.SetMethod("initAsarSupport", &InitAsarSupport);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,10 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "native_mate/dictionary.h"
|
#include "shell/common/gin_converters/callback_converter.h"
|
||||||
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
|
#include "shell/common/gin_converters/file_path_converter.h"
|
||||||
#include "shell/common/native_mate_converters/file_path_converter.h"
|
#include "shell/common/gin_helper/dictionary.h"
|
||||||
|
#include "shell/common/gin_helper/error_thrower.h"
|
||||||
#include "shell/common/native_mate_converters/gurl_converter.h"
|
#include "shell/common/native_mate_converters/gurl_converter.h"
|
||||||
#include "shell/common/native_mate_converters/string16_converter.h"
|
#include "shell/common/native_mate_converters/string16_converter.h"
|
||||||
#include "shell/common/node_includes.h"
|
#include "shell/common/node_includes.h"
|
||||||
|
@ -17,7 +18,7 @@
|
||||||
#include "base/win/scoped_com_initializer.h"
|
#include "base/win/scoped_com_initializer.h"
|
||||||
#include "base/win/shortcut.h"
|
#include "base/win/shortcut.h"
|
||||||
|
|
||||||
namespace mate {
|
namespace gin {
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct Converter<base::win::ShortcutOperation> {
|
struct Converter<base::win::ShortcutOperation> {
|
||||||
|
@ -39,7 +40,7 @@ struct Converter<base::win::ShortcutOperation> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace mate
|
} // namespace gin
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -52,13 +53,13 @@ void OnOpenExternalFinished(electron::util::Promise<void*> promise,
|
||||||
promise.RejectWithErrorMessage(error.c_str());
|
promise.RejectWithErrorMessage(error.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Local<v8::Promise> OpenExternal(const GURL& url, mate::Arguments* args) {
|
v8::Local<v8::Promise> OpenExternal(const GURL& url, gin::Arguments* args) {
|
||||||
electron::util::Promise<void*> promise(args->isolate());
|
electron::util::Promise<void*> promise(args->isolate());
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
platform_util::OpenExternalOptions options;
|
platform_util::OpenExternalOptions options;
|
||||||
if (args->Length() >= 2) {
|
if (args->Length() >= 2) {
|
||||||
mate::Dictionary obj;
|
gin::Dictionary obj(nullptr);
|
||||||
if (args->GetNext(&obj)) {
|
if (args->GetNext(&obj)) {
|
||||||
obj.Get("activate", &options.activate);
|
obj.Get("activate", &options.activate);
|
||||||
obj.Get("workingDirectory", &options.working_dir);
|
obj.Get("workingDirectory", &options.working_dir);
|
||||||
|
@ -71,7 +72,7 @@ v8::Local<v8::Promise> OpenExternal(const GURL& url, mate::Arguments* args) {
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MoveItemToTrash(mate::Arguments* args) {
|
bool MoveItemToTrash(gin::Arguments* args) {
|
||||||
base::FilePath full_path;
|
base::FilePath full_path;
|
||||||
args->GetNext(&full_path);
|
args->GetNext(&full_path);
|
||||||
|
|
||||||
|
@ -83,10 +84,11 @@ bool MoveItemToTrash(mate::Arguments* args) {
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
bool WriteShortcutLink(const base::FilePath& shortcut_path,
|
bool WriteShortcutLink(const base::FilePath& shortcut_path,
|
||||||
mate::Arguments* args) {
|
gin::Arguments* args) {
|
||||||
base::win::ShortcutOperation operation = base::win::SHORTCUT_CREATE_ALWAYS;
|
base::win::ShortcutOperation operation = base::win::SHORTCUT_CREATE_ALWAYS;
|
||||||
args->GetNext(&operation);
|
if (gin::ConvertFromV8(args->isolate(), args->PeekNext(), &operation))
|
||||||
mate::Dictionary options = mate::Dictionary::CreateEmpty(args->isolate());
|
args->Skip();
|
||||||
|
gin::Dictionary options = gin::Dictionary::CreateEmpty(args->isolate());
|
||||||
if (!args->GetNext(&options)) {
|
if (!args->GetNext(&options)) {
|
||||||
args->ThrowError();
|
args->ThrowError();
|
||||||
return false;
|
return false;
|
||||||
|
@ -114,16 +116,16 @@ bool WriteShortcutLink(const base::FilePath& shortcut_path,
|
||||||
operation);
|
operation);
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Local<v8::Value> ReadShortcutLink(mate::Arguments* args,
|
v8::Local<v8::Value> ReadShortcutLink(gin_helper::ErrorThrower thrower,
|
||||||
const base::FilePath& path) {
|
const base::FilePath& path) {
|
||||||
using base::win::ShortcutProperties;
|
using base::win::ShortcutProperties;
|
||||||
mate::Dictionary options = mate::Dictionary::CreateEmpty(args->isolate());
|
gin::Dictionary options = gin::Dictionary::CreateEmpty(thrower.isolate());
|
||||||
base::win::ScopedCOMInitializer com_initializer;
|
base::win::ScopedCOMInitializer com_initializer;
|
||||||
base::win::ShortcutProperties properties;
|
base::win::ShortcutProperties properties;
|
||||||
if (!base::win::ResolveShortcutProperties(
|
if (!base::win::ResolveShortcutProperties(
|
||||||
path, ShortcutProperties::PROPERTIES_ALL, &properties)) {
|
path, ShortcutProperties::PROPERTIES_ALL, &properties)) {
|
||||||
args->ThrowError("Failed to read shortcut link");
|
thrower.ThrowError("Failed to read shortcut link");
|
||||||
return v8::Null(args->isolate());
|
return v8::Null(thrower.isolate());
|
||||||
}
|
}
|
||||||
options.Set("target", properties.target);
|
options.Set("target", properties.target);
|
||||||
options.Set("cwd", properties.working_dir);
|
options.Set("cwd", properties.working_dir);
|
||||||
|
@ -132,7 +134,7 @@ v8::Local<v8::Value> ReadShortcutLink(mate::Arguments* args,
|
||||||
options.Set("icon", properties.icon);
|
options.Set("icon", properties.icon);
|
||||||
options.Set("iconIndex", properties.icon_index);
|
options.Set("iconIndex", properties.icon_index);
|
||||||
options.Set("appUserModelId", properties.app_id);
|
options.Set("appUserModelId", properties.app_id);
|
||||||
return options.GetHandle();
|
return gin::ConvertToV8(thrower.isolate(), options);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -140,7 +142,7 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||||
v8::Local<v8::Value> unused,
|
v8::Local<v8::Value> unused,
|
||||||
v8::Local<v8::Context> context,
|
v8::Local<v8::Context> context,
|
||||||
void* priv) {
|
void* priv) {
|
||||||
mate::Dictionary dict(context->GetIsolate(), exports);
|
gin_helper::Dictionary dict(context->GetIsolate(), exports);
|
||||||
dict.SetMethod("showItemInFolder", &platform_util::ShowItemInFolder);
|
dict.SetMethod("showItemInFolder", &platform_util::ShowItemInFolder);
|
||||||
dict.SetMethod("openItem", &platform_util::OpenItem);
|
dict.SetMethod("openItem", &platform_util::OpenItem);
|
||||||
dict.SetMethod("openExternal", &OpenExternal);
|
dict.SetMethod("openExternal", &OpenExternal);
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
// 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
|
|
@ -0,0 +1,73 @@
|
||||||
|
// 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_
|
|
@ -4,17 +4,15 @@
|
||||||
|
|
||||||
#include "shell/common/deprecate_util.h"
|
#include "shell/common/deprecate_util.h"
|
||||||
|
|
||||||
#include "base/callback.h"
|
#include "gin/dictionary.h"
|
||||||
#include "native_mate/converter.h"
|
#include "shell/common/gin_converters/callback_converter.h"
|
||||||
#include "native_mate/dictionary.h"
|
|
||||||
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
|
|
||||||
|
|
||||||
namespace electron {
|
namespace electron {
|
||||||
|
|
||||||
void EmitDeprecationWarning(node::Environment* env,
|
void EmitDeprecationWarning(node::Environment* env,
|
||||||
const std::string& warning_msg,
|
const std::string& warning_msg,
|
||||||
const std::string& warning_type) {
|
const std::string& warning_type) {
|
||||||
mate::Dictionary process(env->isolate(), env->process_object());
|
gin::Dictionary process(env->isolate(), env->process_object());
|
||||||
|
|
||||||
base::RepeatingCallback<void(base::StringPiece, base::StringPiece,
|
base::RepeatingCallback<void(base::StringPiece, base::StringPiece,
|
||||||
base::StringPiece)>
|
base::StringPiece)>
|
||||||
|
|
|
@ -1,47 +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_ERROR_UTIL_H_
|
|
||||||
#define SHELL_COMMON_ERROR_UTIL_H_
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "native_mate/converter.h"
|
|
||||||
|
|
||||||
namespace electron {
|
|
||||||
|
|
||||||
namespace util {
|
|
||||||
|
|
||||||
class ErrorThrower {
|
|
||||||
public:
|
|
||||||
explicit ErrorThrower(v8::Isolate* isolate);
|
|
||||||
ErrorThrower();
|
|
||||||
|
|
||||||
~ErrorThrower();
|
|
||||||
|
|
||||||
void ThrowError(const std::string& err_msg);
|
|
||||||
void ThrowTypeError(const std::string& err_msg);
|
|
||||||
void ThrowRangeError(const std::string& err_msg);
|
|
||||||
void ThrowReferenceError(const std::string& err_msg);
|
|
||||||
void ThrowSyntaxError(const std::string& err_msg);
|
|
||||||
|
|
||||||
private:
|
|
||||||
v8::Isolate* isolate() const { return isolate_; }
|
|
||||||
|
|
||||||
using ErrorGenerator =
|
|
||||||
v8::Local<v8::Value> (*)(v8::Local<v8::String> err_msg);
|
|
||||||
void Throw(ErrorGenerator gen, const std::string& err_msg) {
|
|
||||||
v8::Local<v8::Value> exception = gen(mate::StringToV8(isolate_, err_msg));
|
|
||||||
if (!isolate_->IsExecutionTerminating())
|
|
||||||
isolate_->ThrowException(exception);
|
|
||||||
}
|
|
||||||
|
|
||||||
v8::Isolate* isolate_;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace util
|
|
||||||
|
|
||||||
} // namespace electron
|
|
||||||
|
|
||||||
#endif // SHELL_COMMON_ERROR_UTIL_H_
|
|
|
@ -6,11 +6,30 @@
|
||||||
#define SHELL_COMMON_GIN_CONVERTERS_STD_CONVERTER_H_
|
#define SHELL_COMMON_GIN_CONVERTERS_STD_CONVERTER_H_
|
||||||
|
|
||||||
#include <set>
|
#include <set>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#include "gin/converter.h"
|
#include "gin/converter.h"
|
||||||
|
|
||||||
namespace gin {
|
namespace gin {
|
||||||
|
|
||||||
|
// Make it possible to convert move-only types.
|
||||||
|
template <typename T>
|
||||||
|
v8::Local<v8::Value> ConvertToV8(v8::Isolate* isolate, T&& input) {
|
||||||
|
return Converter<typename std::remove_reference<T>::type>::ToV8(
|
||||||
|
isolate, std::move(input));
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !defined(OS_LINUX) && !defined(OS_FREEBSD)
|
||||||
|
template <>
|
||||||
|
struct Converter<unsigned long> { // NOLINT(runtime/int)
|
||||||
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||||
|
unsigned long val); // NOLINT(runtime/int)
|
||||||
|
static bool FromV8(v8::Isolate* isolate,
|
||||||
|
v8::Local<v8::Value> val,
|
||||||
|
unsigned long* out); // NOLINT(runtime/int)
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct Converter<v8::Local<v8::Array>> {
|
struct Converter<v8::Local<v8::Array>> {
|
||||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||||
|
|
|
@ -41,11 +41,11 @@ void CallTranslater(v8::Local<v8::External> external,
|
||||||
v8::Isolate* isolate = args->isolate();
|
v8::Isolate* isolate = args->isolate();
|
||||||
auto context = isolate->GetCurrentContext();
|
auto context = isolate->GetCurrentContext();
|
||||||
bool one_time =
|
bool one_time =
|
||||||
state->Has(context, mate::StringToSymbol(isolate, "oneTime")).ToChecked();
|
state->Has(context, gin::StringToSymbol(isolate, "oneTime")).ToChecked();
|
||||||
|
|
||||||
// Check if the callback has already been called.
|
// Check if the callback has already been called.
|
||||||
if (one_time) {
|
if (one_time) {
|
||||||
auto called_symbol = mate::StringToSymbol(isolate, "called");
|
auto called_symbol = gin::StringToSymbol(isolate, "called");
|
||||||
if (state->Has(context, called_symbol).ToChecked()) {
|
if (state->Has(context, called_symbol).ToChecked()) {
|
||||||
args->ThrowTypeError("callback can only be called for once");
|
args->ThrowTypeError("callback can only be called for once");
|
||||||
return;
|
return;
|
||||||
|
@ -145,7 +145,7 @@ v8::Local<v8::Value> BindFunctionWith(v8::Isolate* isolate,
|
||||||
v8::Local<v8::Value> arg1,
|
v8::Local<v8::Value> arg1,
|
||||||
v8::Local<v8::Value> arg2) {
|
v8::Local<v8::Value> arg2) {
|
||||||
v8::MaybeLocal<v8::Value> bind =
|
v8::MaybeLocal<v8::Value> bind =
|
||||||
func->Get(context, mate::StringToV8(isolate, "bind"));
|
func->Get(context, gin::StringToV8(isolate, "bind"));
|
||||||
CHECK(!bind.IsEmpty());
|
CHECK(!bind.IsEmpty());
|
||||||
v8::Local<v8::Function> bind_func =
|
v8::Local<v8::Function> bind_func =
|
||||||
v8::Local<v8::Function>::Cast(bind.ToLocalChecked());
|
v8::Local<v8::Function>::Cast(bind.ToLocalChecked());
|
||||||
|
|
|
@ -10,21 +10,11 @@
|
||||||
|
|
||||||
#include "base/bind.h"
|
#include "base/bind.h"
|
||||||
#include "shell/common/api/locker.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/function_template.h"
|
||||||
|
|
||||||
// Implements safe convertions between JS functions and base::Callback.
|
// Implements safe convertions between JS functions and base::Callback.
|
||||||
|
|
||||||
namespace gin {
|
|
||||||
|
|
||||||
// Make it possible to convert move-only types.
|
|
||||||
template <typename T>
|
|
||||||
v8::Local<v8::Value> ConvertToV8(v8::Isolate* isolate, T&& input) {
|
|
||||||
return Converter<typename std::remove_reference<T>::type>::ToV8(
|
|
||||||
isolate, std::move(input));
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace gin
|
|
||||||
|
|
||||||
namespace gin_helper {
|
namespace gin_helper {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|
|
@ -69,6 +69,23 @@ class Dictionary : public gin::Dictionary {
|
||||||
.ToChecked();
|
.ToChecked();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
bool SetReadOnly(base::StringPiece key, const 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, v8::ReadOnly);
|
||||||
|
return !result.IsNothing() && result.FromJust();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Delete(base::StringPiece key) {
|
||||||
|
v8::Maybe<bool> result = GetHandle()->Delete(
|
||||||
|
isolate()->GetCurrentContext(), gin::StringToV8(isolate(), key));
|
||||||
|
return !result.IsNothing() && result.FromJust();
|
||||||
|
}
|
||||||
|
|
||||||
v8::Local<v8::Object> GetHandle() const {
|
v8::Local<v8::Object> GetHandle() const {
|
||||||
return gin::ConvertToV8(isolate(),
|
return gin::ConvertToV8(isolate(),
|
||||||
*static_cast<const gin::Dictionary*>(this))
|
*static_cast<const gin::Dictionary*>(this))
|
||||||
|
|
|
@ -2,14 +2,11 @@
|
||||||
// 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 <string>
|
#include "shell/common/gin_helper/error_thrower.h"
|
||||||
|
|
||||||
#include "native_mate/converter.h"
|
#include "gin/converter.h"
|
||||||
#include "shell/common/error_util.h"
|
|
||||||
|
|
||||||
namespace electron {
|
namespace gin_helper {
|
||||||
|
|
||||||
namespace util {
|
|
||||||
|
|
||||||
ErrorThrower::ErrorThrower(v8::Isolate* isolate) : isolate_(isolate) {}
|
ErrorThrower::ErrorThrower(v8::Isolate* isolate) : isolate_(isolate) {}
|
||||||
|
|
||||||
|
@ -20,26 +17,30 @@ ErrorThrower::ErrorThrower() : isolate_(v8::Isolate::GetCurrent()) {}
|
||||||
|
|
||||||
ErrorThrower::~ErrorThrower() = default;
|
ErrorThrower::~ErrorThrower() = default;
|
||||||
|
|
||||||
void ErrorThrower::ThrowError(const std::string& err_msg) {
|
void ErrorThrower::ThrowError(base::StringPiece err_msg) {
|
||||||
Throw(v8::Exception::Error, err_msg);
|
Throw(v8::Exception::Error, err_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ErrorThrower::ThrowTypeError(const std::string& err_msg) {
|
void ErrorThrower::ThrowTypeError(base::StringPiece err_msg) {
|
||||||
Throw(v8::Exception::TypeError, err_msg);
|
Throw(v8::Exception::TypeError, err_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ErrorThrower::ThrowRangeError(const std::string& err_msg) {
|
void ErrorThrower::ThrowRangeError(base::StringPiece err_msg) {
|
||||||
Throw(v8::Exception::RangeError, err_msg);
|
Throw(v8::Exception::RangeError, err_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ErrorThrower::ThrowReferenceError(const std::string& err_msg) {
|
void ErrorThrower::ThrowReferenceError(base::StringPiece err_msg) {
|
||||||
Throw(v8::Exception::ReferenceError, err_msg);
|
Throw(v8::Exception::ReferenceError, err_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ErrorThrower::ThrowSyntaxError(const std::string& err_msg) {
|
void ErrorThrower::ThrowSyntaxError(base::StringPiece err_msg) {
|
||||||
Throw(v8::Exception::SyntaxError, err_msg);
|
Throw(v8::Exception::SyntaxError, err_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace util
|
void ErrorThrower::Throw(ErrorGenerator gen, base::StringPiece err_msg) {
|
||||||
|
v8::Local<v8::Value> exception = gen(gin::StringToV8(isolate_, err_msg));
|
||||||
|
if (!isolate_->IsExecutionTerminating())
|
||||||
|
isolate_->ThrowException(exception);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace electron
|
} // namespace gin_helper
|
|
@ -0,0 +1,38 @@
|
||||||
|
// 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_HELPER_ERROR_THROWER_H_
|
||||||
|
#define SHELL_COMMON_GIN_HELPER_ERROR_THROWER_H_
|
||||||
|
|
||||||
|
#include "base/strings/string_piece.h"
|
||||||
|
#include "v8/include/v8.h"
|
||||||
|
|
||||||
|
namespace gin_helper {
|
||||||
|
|
||||||
|
class ErrorThrower {
|
||||||
|
public:
|
||||||
|
explicit ErrorThrower(v8::Isolate* isolate);
|
||||||
|
ErrorThrower();
|
||||||
|
|
||||||
|
~ErrorThrower();
|
||||||
|
|
||||||
|
void ThrowError(base::StringPiece err_msg);
|
||||||
|
void ThrowTypeError(base::StringPiece err_msg);
|
||||||
|
void ThrowRangeError(base::StringPiece err_msg);
|
||||||
|
void ThrowReferenceError(base::StringPiece err_msg);
|
||||||
|
void ThrowSyntaxError(base::StringPiece err_msg);
|
||||||
|
|
||||||
|
v8::Isolate* isolate() const { return isolate_; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
using ErrorGenerator =
|
||||||
|
v8::Local<v8::Value> (*)(v8::Local<v8::String> err_msg);
|
||||||
|
void Throw(ErrorGenerator gen, base::StringPiece err_msg);
|
||||||
|
|
||||||
|
v8::Isolate* isolate_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace gin_helper
|
||||||
|
|
||||||
|
#endif // SHELL_COMMON_GIN_HELPER_ERROR_THROWER_H_
|
|
@ -1,13 +1,13 @@
|
||||||
// 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/api/event_emitter_caller.h"
|
#include "shell/common/gin_helper/event_emitter_caller.h"
|
||||||
|
|
||||||
#include "shell/common/api/locker.h"
|
#include "shell/common/api/locker.h"
|
||||||
#include "shell/common/node_includes.h"
|
#include "shell/common/node_includes.h"
|
||||||
|
|
||||||
namespace mate {
|
namespace gin_helper {
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
|
@ -35,4 +35,4 @@ v8::Local<v8::Value> CallMethodWithArgs(v8::Isolate* isolate,
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
|
||||||
} // namespace mate
|
} // namespace gin_helper
|
|
@ -1,17 +1,16 @@
|
||||||
// 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.
|
||||||
|
|
||||||
#ifndef SHELL_COMMON_API_EVENT_EMITTER_CALLER_H_
|
#ifndef SHELL_COMMON_GIN_HELPER_EVENT_EMITTER_CALLER_H_
|
||||||
#define SHELL_COMMON_API_EVENT_EMITTER_CALLER_H_
|
#define SHELL_COMMON_GIN_HELPER_EVENT_EMITTER_CALLER_H_
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "native_mate/converter.h"
|
#include "gin/converter.h"
|
||||||
#include "shell/common/native_mate_converters/string16_converter.h"
|
|
||||||
|
|
||||||
namespace mate {
|
namespace gin_helper {
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
|
@ -31,7 +30,7 @@ v8::Local<v8::Value> EmitEvent(v8::Isolate* isolate,
|
||||||
v8::Local<v8::Object> obj,
|
v8::Local<v8::Object> obj,
|
||||||
const StringType& name,
|
const StringType& name,
|
||||||
const internal::ValueVector& args) {
|
const internal::ValueVector& args) {
|
||||||
internal::ValueVector concatenated_args = {StringToV8(isolate, name)};
|
internal::ValueVector concatenated_args = {gin::StringToV8(isolate, name)};
|
||||||
concatenated_args.reserve(1 + args.size());
|
concatenated_args.reserve(1 + args.size());
|
||||||
concatenated_args.insert(concatenated_args.end(), args.begin(), args.end());
|
concatenated_args.insert(concatenated_args.end(), args.begin(), args.end());
|
||||||
return internal::CallMethodWithArgs(isolate, obj, "emit", &concatenated_args);
|
return internal::CallMethodWithArgs(isolate, obj, "emit", &concatenated_args);
|
||||||
|
@ -45,8 +44,8 @@ v8::Local<v8::Value> EmitEvent(v8::Isolate* isolate,
|
||||||
const StringType& name,
|
const StringType& name,
|
||||||
Args&&... args) {
|
Args&&... args) {
|
||||||
internal::ValueVector converted_args = {
|
internal::ValueVector converted_args = {
|
||||||
StringToV8(isolate, name),
|
gin::StringToV8(isolate, name),
|
||||||
ConvertToV8(isolate, std::forward<Args>(args))...,
|
gin::ConvertToV8(isolate, std::forward<Args>(args))...,
|
||||||
};
|
};
|
||||||
return internal::CallMethodWithArgs(isolate, obj, "emit", &converted_args);
|
return internal::CallMethodWithArgs(isolate, obj, "emit", &converted_args);
|
||||||
}
|
}
|
||||||
|
@ -58,12 +57,12 @@ v8::Local<v8::Value> CustomEmit(v8::Isolate* isolate,
|
||||||
const char* custom_emit,
|
const char* custom_emit,
|
||||||
Args&&... args) {
|
Args&&... args) {
|
||||||
internal::ValueVector converted_args = {
|
internal::ValueVector converted_args = {
|
||||||
ConvertToV8(isolate, std::forward<Args>(args))...,
|
gin::ConvertToV8(isolate, std::forward<Args>(args))...,
|
||||||
};
|
};
|
||||||
return internal::CallMethodWithArgs(isolate, object, custom_emit,
|
return internal::CallMethodWithArgs(isolate, object, custom_emit,
|
||||||
&converted_args);
|
&converted_args);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace mate
|
} // namespace gin_helper
|
||||||
|
|
||||||
#endif // SHELL_COMMON_API_EVENT_EMITTER_CALLER_H_
|
#endif // SHELL_COMMON_GIN_HELPER_EVENT_EMITTER_CALLER_H_
|
|
@ -7,8 +7,8 @@
|
||||||
|
|
||||||
#include "base/callback.h"
|
#include "base/callback.h"
|
||||||
#include "gin/arguments.h"
|
#include "gin/arguments.h"
|
||||||
#include "shell/common/error_util.h"
|
|
||||||
#include "shell/common/gin_helper/destroyable.h"
|
#include "shell/common/gin_helper/destroyable.h"
|
||||||
|
#include "shell/common/gin_helper/error_thrower.h"
|
||||||
|
|
||||||
// This file is forked from gin/function_template.h with 2 differences:
|
// This file is forked from gin/function_template.h with 2 differences:
|
||||||
// 1. Support for additional types of arguments.
|
// 1. Support for additional types of arguments.
|
||||||
|
@ -112,8 +112,8 @@ inline bool GetNextArgument(gin::Arguments* args,
|
||||||
inline bool GetNextArgument(gin::Arguments* args,
|
inline bool GetNextArgument(gin::Arguments* args,
|
||||||
int create_flags,
|
int create_flags,
|
||||||
bool is_first,
|
bool is_first,
|
||||||
electron::util::ErrorThrower* result) {
|
ErrorThrower* result) {
|
||||||
*result = electron::util::ErrorThrower(args->isolate());
|
*result = ErrorThrower(args->isolate());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,12 +22,12 @@
|
||||||
#include "content/public/browser/browser_thread.h"
|
#include "content/public/browser/browser_thread.h"
|
||||||
#include "content/public/common/content_paths.h"
|
#include "content/public/common/content_paths.h"
|
||||||
#include "electron/buildflags/buildflags.h"
|
#include "electron/buildflags/buildflags.h"
|
||||||
#include "native_mate/dictionary.h"
|
|
||||||
#include "shell/common/api/event_emitter_caller.h"
|
|
||||||
#include "shell/common/api/locker.h"
|
#include "shell/common/api/locker.h"
|
||||||
#include "shell/common/atom_command_line.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/mac/main_application_bundle.h"
|
#include "shell/common/mac/main_application_bundle.h"
|
||||||
#include "shell/common/native_mate_converters/file_path_converter.h"
|
|
||||||
#include "shell/common/node_includes.h"
|
#include "shell/common/node_includes.h"
|
||||||
|
|
||||||
#define ELECTRON_BUILTIN_MODULES(V) \
|
#define ELECTRON_BUILTIN_MODULES(V) \
|
||||||
|
@ -314,7 +314,7 @@ node::Environment* NodeBindings::CreateEnvironment(
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
mate::Dictionary global(context->GetIsolate(), context->Global());
|
gin_helper::Dictionary global(context->GetIsolate(), context->Global());
|
||||||
// Do not set DOM globals for renderer process.
|
// Do not set DOM globals for renderer process.
|
||||||
// We must set this before the node bootstrapper which is run inside
|
// We must set this before the node bootstrapper which is run inside
|
||||||
// CreateEnvironment
|
// CreateEnvironment
|
||||||
|
@ -351,7 +351,7 @@ node::Environment* NodeBindings::CreateEnvironment(
|
||||||
context->GetIsolate()->SetMicrotasksPolicy(v8::MicrotasksPolicy::kScoped);
|
context->GetIsolate()->SetMicrotasksPolicy(v8::MicrotasksPolicy::kScoped);
|
||||||
}
|
}
|
||||||
|
|
||||||
mate::Dictionary process(context->GetIsolate(), env->process_object());
|
gin_helper::Dictionary process(context->GetIsolate(), env->process_object());
|
||||||
process.SetReadOnly("type", process_type);
|
process.SetReadOnly("type", process_type);
|
||||||
process.Set("resourcesPath", resources_path);
|
process.Set("resourcesPath", resources_path);
|
||||||
// The path to helper app.
|
// The path to helper app.
|
||||||
|
@ -364,7 +364,7 @@ node::Environment* NodeBindings::CreateEnvironment(
|
||||||
|
|
||||||
void NodeBindings::LoadEnvironment(node::Environment* env) {
|
void NodeBindings::LoadEnvironment(node::Environment* env) {
|
||||||
node::LoadEnvironment(env);
|
node::LoadEnvironment(env);
|
||||||
mate::EmitEvent(env->isolate(), env->process_object(), "loaded");
|
gin_helper::EmitEvent(env->isolate(), env->process_object(), "loaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeBindings::PrepareMessageLoop() {
|
void NodeBindings::PrepareMessageLoop() {
|
||||||
|
|
|
@ -14,9 +14,7 @@
|
||||||
#include "content/public/browser/browser_task_traits.h"
|
#include "content/public/browser/browser_task_traits.h"
|
||||||
#include "content/public/browser/browser_thread.h"
|
#include "content/public/browser/browser_thread.h"
|
||||||
#include "native_mate/converter.h"
|
#include "native_mate/converter.h"
|
||||||
#include "shell/common/api/locker.h"
|
#include "shell/common/gin_converters/std_converter.h"
|
||||||
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
|
|
||||||
#include "shell/common/native_mate_converters/once_callback.h"
|
|
||||||
|
|
||||||
namespace electron {
|
namespace electron {
|
||||||
|
|
||||||
|
@ -142,7 +140,7 @@ class Promise {
|
||||||
v8::Context::Scope context_scope(
|
v8::Context::Scope context_scope(
|
||||||
v8::Local<v8::Context>::New(isolate(), GetContext()));
|
v8::Local<v8::Context>::New(isolate(), GetContext()));
|
||||||
|
|
||||||
v8::Local<v8::Value> value = mate::ConvertToV8(isolate(), cb);
|
v8::Local<v8::Value> value = gin::ConvertToV8(isolate(), std::move(cb));
|
||||||
v8::Local<v8::Function> handler = v8::Local<v8::Function>::Cast(value);
|
v8::Local<v8::Function> handler = v8::Local<v8::Function>::Cast(value);
|
||||||
|
|
||||||
return GetHandle()->Then(GetContext(), handler);
|
return GetHandle()->Then(GetContext(), handler);
|
||||||
|
|
|
@ -13,12 +13,9 @@
|
||||||
#include "content/public/renderer/render_frame_visitor.h"
|
#include "content/public/renderer/render_frame_visitor.h"
|
||||||
#include "content/public/renderer/render_view.h"
|
#include "content/public/renderer/render_view.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "native_mate/dictionary.h"
|
||||||
#include "native_mate/object_template_builder.h"
|
|
||||||
#include "services/service_manager/public/cpp/interface_provider.h"
|
#include "services/service_manager/public/cpp/interface_provider.h"
|
||||||
#include "shell/common/api/api.mojom.h"
|
#include "shell/common/api/api.mojom.h"
|
||||||
#include "shell/common/api/event_emitter_caller.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/callback_converter_deprecated.h"
|
|
||||||
#include "shell/common/native_mate_converters/gfx_converter.h"
|
#include "shell/common/native_mate_converters/gfx_converter.h"
|
||||||
#include "shell/common/native_mate_converters/string16_converter.h"
|
#include "shell/common/native_mate_converters/string16_converter.h"
|
||||||
#include "shell/common/node_includes.h"
|
#include "shell/common/node_includes.h"
|
||||||
|
|
|
@ -16,13 +16,9 @@
|
||||||
#include "electron/buildflags/buildflags.h"
|
#include "electron/buildflags/buildflags.h"
|
||||||
#include "electron/shell/common/api/api.mojom.h"
|
#include "electron/shell/common/api/api.mojom.h"
|
||||||
#include "ipc/ipc_message_macros.h"
|
#include "ipc/ipc_message_macros.h"
|
||||||
#include "native_mate/dictionary.h"
|
|
||||||
#include "net/base/net_module.h"
|
#include "net/base/net_module.h"
|
||||||
#include "net/grit/net_resources.h"
|
#include "net/grit/net_resources.h"
|
||||||
#include "services/service_manager/public/cpp/interface_provider.h"
|
#include "services/service_manager/public/cpp/interface_provider.h"
|
||||||
#include "shell/common/api/event_emitter_caller.h"
|
|
||||||
#include "shell/common/native_mate_converters/value_converter.h"
|
|
||||||
#include "shell/common/node_includes.h"
|
|
||||||
#include "shell/common/options_switches.h"
|
#include "shell/common/options_switches.h"
|
||||||
#include "third_party/blink/public/platform/web_isolated_world_info.h"
|
#include "third_party/blink/public/platform/web_isolated_world_info.h"
|
||||||
#include "third_party/blink/public/web/blink.h"
|
#include "third_party/blink/public/web/blink.h"
|
||||||
|
|
|
@ -10,10 +10,10 @@
|
||||||
#include "base/command_line.h"
|
#include "base/command_line.h"
|
||||||
#include "content/public/renderer/render_frame.h"
|
#include "content/public/renderer/render_frame.h"
|
||||||
#include "electron/buildflags/buildflags.h"
|
#include "electron/buildflags/buildflags.h"
|
||||||
#include "native_mate/dictionary.h"
|
|
||||||
#include "shell/common/api/electron_bindings.h"
|
#include "shell/common/api/electron_bindings.h"
|
||||||
#include "shell/common/api/event_emitter_caller.h"
|
|
||||||
#include "shell/common/asar/asar_util.h"
|
#include "shell/common/asar/asar_util.h"
|
||||||
|
#include "shell/common/gin_helper/dictionary.h"
|
||||||
|
#include "shell/common/gin_helper/event_emitter_caller.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"
|
||||||
#include "shell/common/options_switches.h"
|
#include "shell/common/options_switches.h"
|
||||||
|
@ -56,7 +56,8 @@ void AtomRendererClient::RunScriptsAtDocumentStart(
|
||||||
v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
|
v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
|
||||||
node::Environment* env = GetEnvironment(render_frame);
|
node::Environment* env = GetEnvironment(render_frame);
|
||||||
if (env)
|
if (env)
|
||||||
mate::EmitEvent(env->isolate(), env->process_object(), "document-start");
|
gin_helper::EmitEvent(env->isolate(), env->process_object(),
|
||||||
|
"document-start");
|
||||||
}
|
}
|
||||||
|
|
||||||
void AtomRendererClient::RunScriptsAtDocumentEnd(
|
void AtomRendererClient::RunScriptsAtDocumentEnd(
|
||||||
|
@ -66,7 +67,8 @@ void AtomRendererClient::RunScriptsAtDocumentEnd(
|
||||||
v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
|
v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
|
||||||
node::Environment* env = GetEnvironment(render_frame);
|
node::Environment* env = GetEnvironment(render_frame);
|
||||||
if (env)
|
if (env)
|
||||||
mate::EmitEvent(env->isolate(), env->process_object(), "document-end");
|
gin_helper::EmitEvent(env->isolate(), env->process_object(),
|
||||||
|
"document-end");
|
||||||
}
|
}
|
||||||
|
|
||||||
void AtomRendererClient::DidCreateScriptContext(
|
void AtomRendererClient::DidCreateScriptContext(
|
||||||
|
@ -135,7 +137,7 @@ void AtomRendererClient::DidCreateScriptContext(
|
||||||
// Add Electron extended APIs.
|
// Add Electron extended APIs.
|
||||||
electron_bindings_->BindTo(env->isolate(), env->process_object());
|
electron_bindings_->BindTo(env->isolate(), env->process_object());
|
||||||
AddRenderBindings(env->isolate(), env->process_object());
|
AddRenderBindings(env->isolate(), env->process_object());
|
||||||
mate::Dictionary process_dict(env->isolate(), env->process_object());
|
gin_helper::Dictionary process_dict(env->isolate(), env->process_object());
|
||||||
process_dict.SetReadOnly("isMainFrame", render_frame->IsMainFrame());
|
process_dict.SetReadOnly("isMainFrame", render_frame->IsMainFrame());
|
||||||
|
|
||||||
// Load everything.
|
// Load everything.
|
||||||
|
@ -160,7 +162,7 @@ void AtomRendererClient::WillReleaseScriptContext(
|
||||||
if (environments_.erase(env) == 0)
|
if (environments_.erase(env) == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mate::EmitEvent(env->isolate(), env->process_object(), "exit");
|
gin_helper::EmitEvent(env->isolate(), env->process_object(), "exit");
|
||||||
|
|
||||||
// The main frame may be replaced.
|
// The main frame may be replaced.
|
||||||
if (env == node_bindings_->uv_env())
|
if (env == node_bindings_->uv_env())
|
||||||
|
|
|
@ -11,16 +11,14 @@
|
||||||
#include "base/environment.h"
|
#include "base/environment.h"
|
||||||
#include "base/macros.h"
|
#include "base/macros.h"
|
||||||
#include "base/threading/thread_restrictions.h"
|
#include "base/threading/thread_restrictions.h"
|
||||||
#include "electron/shell/common/api/event_emitter_caller.h"
|
|
||||||
#include "electron/shell/common/node_includes.h"
|
|
||||||
#include "electron/shell/common/options_switches.h"
|
|
||||||
#include "electron/shell/renderer/atom_render_frame_observer.h"
|
|
||||||
#include "electron/shell/renderer/renderer_client_base.h"
|
|
||||||
#include "mojo/public/cpp/system/platform_handle.h"
|
#include "mojo/public/cpp/system/platform_handle.h"
|
||||||
#include "native_mate/dictionary.h"
|
|
||||||
#include "shell/common/atom_constants.h"
|
#include "shell/common/atom_constants.h"
|
||||||
|
#include "shell/common/gin_converters/value_converter_gin_adapter.h"
|
||||||
#include "shell/common/heap_snapshot.h"
|
#include "shell/common/heap_snapshot.h"
|
||||||
#include "shell/common/native_mate_converters/value_converter.h"
|
#include "shell/common/node_includes.h"
|
||||||
|
#include "shell/common/options_switches.h"
|
||||||
|
#include "shell/renderer/atom_render_frame_observer.h"
|
||||||
|
#include "shell/renderer/renderer_client_base.h"
|
||||||
#include "third_party/blink/public/web/blink.h"
|
#include "third_party/blink/public/web/blink.h"
|
||||||
#include "third_party/blink/public/web/web_local_frame.h"
|
#include "third_party/blink/public/web/web_local_frame.h"
|
||||||
|
|
||||||
|
@ -33,8 +31,7 @@ const char kIpcKey[] = "ipcNative";
|
||||||
// Gets the private object under kIpcKey
|
// Gets the private object under kIpcKey
|
||||||
v8::Local<v8::Object> GetIpcObject(v8::Local<v8::Context> context) {
|
v8::Local<v8::Object> GetIpcObject(v8::Local<v8::Context> context) {
|
||||||
auto* isolate = context->GetIsolate();
|
auto* isolate = context->GetIsolate();
|
||||||
auto binding_key =
|
auto binding_key = gin::StringToV8(isolate, kIpcKey);
|
||||||
mate::ConvertToV8(isolate, kIpcKey)->ToString(context).ToLocalChecked();
|
|
||||||
auto private_binding_key = v8::Private::ForApi(isolate, binding_key);
|
auto private_binding_key = v8::Private::ForApi(isolate, binding_key);
|
||||||
auto global_object = context->Global();
|
auto global_object = context->Global();
|
||||||
auto value =
|
auto value =
|
||||||
|
@ -64,7 +61,7 @@ void InvokeIpcCallback(v8::Local<v8::Context> context,
|
||||||
callback_scope.reset(new node::CallbackScope(isolate, ipcNative, {0, 0}));
|
callback_scope.reset(new node::CallbackScope(isolate, ipcNative, {0, 0}));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto callback_key = mate::ConvertToV8(isolate, callback_name)
|
auto callback_key = gin::ConvertToV8(isolate, callback_name)
|
||||||
->ToString(context)
|
->ToString(context)
|
||||||
.ToLocalChecked();
|
.ToLocalChecked();
|
||||||
auto callback_value = ipcNative->Get(context, callback_key).ToLocalChecked();
|
auto callback_value = ipcNative->Get(context, callback_key).ToLocalChecked();
|
||||||
|
@ -86,8 +83,8 @@ void EmitIPCEvent(v8::Local<v8::Context> context,
|
||||||
v8::MicrotasksScope::kRunMicrotasks);
|
v8::MicrotasksScope::kRunMicrotasks);
|
||||||
|
|
||||||
std::vector<v8::Local<v8::Value>> argv = {
|
std::vector<v8::Local<v8::Value>> argv = {
|
||||||
mate::ConvertToV8(isolate, internal), mate::ConvertToV8(isolate, channel),
|
gin::ConvertToV8(isolate, internal), gin::ConvertToV8(isolate, channel),
|
||||||
mate::ConvertToV8(isolate, args), mate::ConvertToV8(isolate, sender_id)};
|
gin::ConvertToV8(isolate, args), gin::ConvertToV8(isolate, sender_id)};
|
||||||
|
|
||||||
InvokeIpcCallback(context, "onMessage", argv);
|
InvokeIpcCallback(context, "onMessage", argv);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,8 @@
|
||||||
#include "base/lazy_instance.h"
|
#include "base/lazy_instance.h"
|
||||||
#include "base/threading/thread_local.h"
|
#include "base/threading/thread_local.h"
|
||||||
#include "shell/common/api/electron_bindings.h"
|
#include "shell/common/api/electron_bindings.h"
|
||||||
#include "shell/common/api/event_emitter_caller.h"
|
|
||||||
#include "shell/common/asar/asar_util.h"
|
#include "shell/common/asar/asar_util.h"
|
||||||
|
#include "shell/common/gin_helper/event_emitter_caller.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"
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ void WebWorkerObserver::ContextCreated(v8::Local<v8::Context> worker_context) {
|
||||||
void WebWorkerObserver::ContextWillDestroy(v8::Local<v8::Context> context) {
|
void WebWorkerObserver::ContextWillDestroy(v8::Local<v8::Context> context) {
|
||||||
node::Environment* env = node::Environment::GetCurrent(context);
|
node::Environment* env = node::Environment::GetCurrent(context);
|
||||||
if (env)
|
if (env)
|
||||||
mate::EmitEvent(env->isolate(), env->process_object(), "exit");
|
gin_helper::EmitEvent(env->isolate(), env->process_object(), "exit");
|
||||||
|
|
||||||
delete this;
|
delete this;
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче