chore: remove native_mate (Part 3) (#20131)

* use gin converter in atom_api_menu

* please only put necessary includes in header

Having include in header means they have dependency relationship,
putting arbitrary includes really really really really really makes
refacoring much harder.

* remove some simple uses of callback_converter_deprecated.h

* use gin callback converter in file_dialog code

* use gin in ErrorThrower

* use gin in atom_bundle_mover

* fix mistake in node stream

* deprecate native_mate version of event_emitter_caller

* use gin in node_bindings

* remove usages of native_mate event_emitter_caller.h except for EventEmitter

* fix compilation on Windows

* gin::Arguments behaves differently on GetNext

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

View file

@ -26,6 +26,7 @@
#include "content/public/browser/gpu_data_manager.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/common/content_switches.h"
#include "gin/arguments.h"
#include "media/audio/audio_manager.h"
#include "native_mate/object_template_builder.h"
#include "net/ssl/client_cert_identity.h"
@ -846,7 +847,7 @@ void App::SetAppPath(const base::FilePath& app_path) {
}
#if !defined(OS_MACOSX)
void App::SetAppLogsPath(util::ErrorThrower thrower,
void App::SetAppLogsPath(gin_helper::ErrorThrower thrower,
base::Optional<base::FilePath> custom_path) {
if (custom_path.has_value()) {
if (!custom_path->IsAbsolute()) {
@ -865,7 +866,7 @@ void App::SetAppLogsPath(util::ErrorThrower thrower,
}
#endif
base::FilePath App::GetPath(util::ErrorThrower thrower,
base::FilePath App::GetPath(gin_helper::ErrorThrower thrower,
const std::string& name) {
bool succeed = false;
base::FilePath path;
@ -888,7 +889,7 @@ base::FilePath App::GetPath(util::ErrorThrower thrower,
return path;
}
void App::SetPath(util::ErrorThrower thrower,
void App::SetPath(gin_helper::ErrorThrower thrower,
const std::string& name,
const base::FilePath& path) {
if (!path.IsAbsolute()) {
@ -1031,7 +1032,7 @@ bool App::Relaunch(mate::Arguments* js_args) {
return relauncher::RelaunchApp(argv);
}
void App::DisableHardwareAcceleration(util::ErrorThrower thrower) {
void App::DisableHardwareAcceleration(gin_helper::ErrorThrower thrower) {
if (Browser::Get()->is_ready()) {
thrower.ThrowError(
"app.disableHardwareAcceleration() can only be called "
@ -1041,7 +1042,7 @@ void App::DisableHardwareAcceleration(util::ErrorThrower thrower) {
content::GpuDataManager::GetInstance()->DisableHardwareAcceleration();
}
void App::DisableDomainBlockingFor3DAPIs(util::ErrorThrower thrower) {
void App::DisableDomainBlockingFor3DAPIs(gin_helper::ErrorThrower thrower) {
if (Browser::Get()->is_ready()) {
thrower.ThrowError(
"app.disableDomainBlockingFor3DAPIs() can only be called "
@ -1057,7 +1058,7 @@ bool App::IsAccessibilitySupportEnabled() {
return ax_state->IsAccessibleBrowser();
}
void App::SetAccessibilitySupportEnabled(util::ErrorThrower thrower,
void App::SetAccessibilitySupportEnabled(gin_helper::ErrorThrower thrower,
bool enabled) {
if (!Browser::Get()->is_ready()) {
thrower.ThrowError(
@ -1314,7 +1315,7 @@ static void RemoveNoSandboxSwitch(base::CommandLine* command_line) {
}
}
void App::EnableSandbox(util::ErrorThrower thrower) {
void App::EnableSandbox(gin_helper::ErrorThrower thrower) {
if (Browser::Get()->is_ready()) {
thrower.ThrowError(
"app.enableSandbox() can only be called "
@ -1343,12 +1344,14 @@ bool App::CanBrowserClientUseCustomSiteInstance() {
}
#if defined(OS_MACOSX)
bool App::MoveToApplicationsFolder(mate::Arguments* args) {
return ui::cocoa::AtomBundleMover::Move(args);
bool App::MoveToApplicationsFolder(gin_helper::ErrorThrower thrower,
mate::Arguments* args) {
gin::Arguments gin_args(args->info());
return AtomBundleMover::Move(thrower, &gin_args);
}
bool App::IsInApplicationsFolder() {
return ui::cocoa::AtomBundleMover::IsCurrentAppInApplicationsFolder();
return AtomBundleMover::IsCurrentAppInApplicationsFolder();
}
int DockBounce(mate::Arguments* args) {

View file

@ -27,8 +27,7 @@
#include "shell/browser/atom_browser_client.h"
#include "shell/browser/browser.h"
#include "shell/browser/browser_observer.h"
#include "shell/common/error_util.h"
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
#include "shell/common/gin_helper/error_thrower.h"
#include "shell/common/promise_util.h"
#if defined(USE_NSS_CERTS)
@ -165,12 +164,13 @@ class App : public AtomBrowserClient::Delegate,
void ChildProcessLaunched(int process_type, base::ProcessHandle handle);
void ChildProcessDisconnected(base::ProcessId pid);
void SetAppLogsPath(util::ErrorThrower thrower,
void SetAppLogsPath(gin_helper::ErrorThrower thrower,
base::Optional<base::FilePath> custom_path);
// Get/Set the pre-defined path in PathService.
base::FilePath GetPath(util::ErrorThrower thrower, const std::string& name);
void SetPath(util::ErrorThrower thrower,
base::FilePath GetPath(gin_helper::ErrorThrower thrower,
const std::string& name);
void SetPath(gin_helper::ErrorThrower thrower,
const std::string& name,
const base::FilePath& path);
@ -183,10 +183,11 @@ class App : public AtomBrowserClient::Delegate,
bool RequestSingleInstanceLock();
void ReleaseSingleInstanceLock();
bool Relaunch(mate::Arguments* args);
void DisableHardwareAcceleration(util::ErrorThrower thrower);
void DisableDomainBlockingFor3DAPIs(util::ErrorThrower thrower);
void DisableHardwareAcceleration(gin_helper::ErrorThrower thrower);
void DisableDomainBlockingFor3DAPIs(gin_helper::ErrorThrower thrower);
bool IsAccessibilitySupportEnabled();
void SetAccessibilitySupportEnabled(util::ErrorThrower thrower, bool enabled);
void SetAccessibilitySupportEnabled(gin_helper::ErrorThrower thrower,
bool enabled);
Browser::LoginItemSettings GetLoginItemSettings(mate::Arguments* args);
#if defined(USE_NSS_CERTS)
void ImportCertificate(const base::DictionaryValue& options,
@ -199,14 +200,15 @@ class App : public AtomBrowserClient::Delegate,
v8::Local<v8::Value> GetGPUFeatureStatus(v8::Isolate* isolate);
v8::Local<v8::Promise> GetGPUInfo(v8::Isolate* isolate,
const std::string& info_type);
void EnableSandbox(util::ErrorThrower thrower);
void EnableSandbox(gin_helper::ErrorThrower thrower);
void SetUserAgentFallback(const std::string& user_agent);
std::string GetUserAgentFallback();
void SetBrowserClientCanUseCustomSiteInstance(bool should_disable);
bool CanBrowserClientUseCustomSiteInstance();
#if defined(OS_MACOSX)
bool MoveToApplicationsFolder(mate::Arguments* args);
bool MoveToApplicationsFolder(gin_helper::ErrorThrower,
mate::Arguments* args);
bool IsInApplicationsFolder();
v8::Local<v8::Value> GetDockAPI(v8::Isolate* isolate);
v8::Global<v8::Value> dock_;

View file

@ -13,7 +13,7 @@ namespace electron {
namespace api {
void App::SetAppLogsPath(util::ErrorThrower thrower,
void App::SetAppLogsPath(gin_helper::ErrorThrower thrower,
base::Optional<base::FilePath> custom_path) {
if (custom_path.has_value()) {
if (!custom_path->IsAbsolute()) {

View file

@ -10,10 +10,12 @@
#include "shell/browser/browser.h"
#include "shell/browser/native_window.h"
#include "shell/browser/window_list.h"
#include "shell/common/api/event_emitter_caller.h"
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
#include "shell/common/gin_helper/event_emitter_caller.h"
#include "shell/common/node_includes.h"
// TODO(zcbenz): Remove this after removing mate::ObjectTemplateBuilder.
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
namespace mate {
template <>
@ -48,7 +50,7 @@ void AutoUpdater::OnError(const std::string& message) {
v8::Locker locker(isolate());
v8::HandleScope handle_scope(isolate());
auto error = v8::Exception::Error(mate::StringToV8(isolate(), message));
mate::EmitEvent(
gin_helper::EmitEvent(
isolate(), GetWrapper(), "error",
error->ToObject(isolate()->GetCurrentContext()).ToLocalChecked(),
// Message is also emitted to keep compatibility with old code.
@ -76,7 +78,7 @@ void AutoUpdater::OnError(const std::string& message,
mate::StringToV8(isolate(), domain))
.Check();
mate::EmitEvent(isolate(), GetWrapper(), "error", errorObject, message);
gin_helper::EmitEvent(isolate(), GetWrapper(), "error", errorObject, message);
}
void AutoUpdater::OnCheckingForUpdate() {

View file

@ -20,7 +20,6 @@
#include "shell/browser/window_list.h"
#include "shell/common/api/constructor.h"
#include "shell/common/color_util.h"
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
#include "shell/common/native_mate_converters/value_converter.h"
#include "shell/common/node_includes.h"
#include "shell/common/options_switches.h"

View file

@ -20,7 +20,6 @@
#include "net/cookies/cookie_util.h"
#include "shell/browser/atom_browser_context.h"
#include "shell/browser/cookie_change_notifier.h"
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
#include "shell/common/native_mate_converters/gurl_converter.h"
#include "shell/common/native_mate_converters/value_converter.h"

View file

@ -13,7 +13,6 @@
#include "content/public/browser/devtools_agent_host.h"
#include "content/public/browser/web_contents.h"
#include "native_mate/dictionary.h"
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
#include "shell/common/native_mate_converters/value_converter.h"
#include "shell/common/node_includes.h"

View file

@ -11,6 +11,7 @@
#include "shell/browser/ui/message_box.h"
#include "shell/common/gin_converters/callback_converter.h"
#include "shell/common/gin_converters/file_dialog_converter.h"
#include "shell/common/gin_converters/file_path_converter.h"
#include "shell/common/gin_converters/message_box_converter.h"
#include "shell/common/gin_converters/native_window_converter.h"
#include "shell/common/gin_converters/net_converter.h"
@ -59,7 +60,7 @@ void ShowOpenDialogSync(const file_dialog::DialogSettings& settings,
v8::Local<v8::Promise> ShowOpenDialog(
const file_dialog::DialogSettings& settings,
gin::Arguments* args) {
electron::util::Promise<mate::Dictionary> promise(args->isolate());
electron::util::Promise<gin::Dictionary> promise(args->isolate());
v8::Local<v8::Promise> handle = promise.GetHandle();
file_dialog::ShowOpenDialog(settings, std::move(promise));
return handle;
@ -75,7 +76,7 @@ void ShowSaveDialogSync(const file_dialog::DialogSettings& settings,
v8::Local<v8::Promise> ShowSaveDialog(
const file_dialog::DialogSettings& settings,
gin::Arguments* args) {
electron::util::Promise<mate::Dictionary> promise(args->isolate());
electron::util::Promise<gin::Dictionary> promise(args->isolate());
v8::Local<v8::Promise> handle = promise.GetHandle();
file_dialog::ShowSaveDialog(settings, std::move(promise));

View file

@ -11,7 +11,6 @@
#include "native_mate/dictionary.h"
#include "net/base/filename_util.h"
#include "shell/browser/atom_browser_main_parts.h"
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
#include "shell/common/native_mate_converters/file_dialog_converter.h"
#include "shell/common/native_mate_converters/file_path_converter.h"
#include "shell/common/native_mate_converters/gurl_converter.h"

View file

@ -9,7 +9,6 @@
#include <vector>
#include "native_mate/dictionary.h"
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
#include "shell/common/node_includes.h"
namespace mate {

View file

@ -6,16 +6,19 @@
#include <map>
#include "gin/dictionary.h"
#include "native_mate/constructor.h"
#include "native_mate/dictionary.h"
#include "native_mate/object_template_builder.h"
#include "shell/browser/native_window.h"
#include "shell/common/gin_converters/callback_converter.h"
#include "shell/common/native_mate_converters/accelerator_converter.h"
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
#include "shell/common/native_mate_converters/image_converter.h"
#include "shell/common/native_mate_converters/string16_converter.h"
#include "shell/common/node_includes.h"
// TODO(zcbenz): Remove this after removing mate::ObjectTemplateBuilder.
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
namespace {
// We need this map to keep references to currently opened menus.
// Without this menus would be destroyed by js garbage collector
@ -40,8 +43,8 @@ Menu::~Menu() {
}
void Menu::AfterInit(v8::Isolate* isolate) {
mate::Dictionary wrappable(isolate, GetWrapper());
mate::Dictionary delegate;
gin::Dictionary wrappable(isolate, GetWrapper());
gin::Dictionary delegate(nullptr);
if (!wrappable.Get("delegate", &delegate))
return;

View file

@ -144,4 +144,17 @@ struct Converter<electron::AtomMenuModel*> {
} // namespace mate
namespace gin {
template <>
struct Converter<electron::AtomMenuModel*> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
electron::AtomMenuModel** out) {
return mate::ConvertFromV8(isolate, val, out);
}
};
} // namespace gin
#endif // SHELL_BROWSER_API_ATOM_API_MENU_H_

View file

@ -16,7 +16,6 @@
#include "native_mate/handle.h"
#include "shell/browser/atom_browser_context.h"
#include "shell/browser/net/system_network_context_manager.h"
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
#include "shell/common/native_mate_converters/file_path_converter.h"
#include "shell/common/node_includes.h"

View file

@ -6,9 +6,9 @@
#include "base/power_monitor/power_monitor.h"
#include "base/power_monitor/power_monitor_device_source.h"
#include "native_mate/dictionary.h"
#include "gin/dictionary.h"
#include "shell/browser/browser.h"
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
#include "shell/common/gin_converters/callback_converter.h"
#include "shell/common/node_includes.h"
namespace mate {
@ -138,9 +138,8 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Context> context,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
mate::Dictionary dict(isolate, exports);
dict.Set("createPowerMonitor",
base::BindRepeating(&PowerMonitor::Create, isolate));
gin::Dictionary dict(isolate, exports);
dict.Set("createPowerMonitor", base::BindRepeating(&PowerMonitor::Create));
dict.Set("PowerMonitor", PowerMonitor::GetConstructor(isolate)
->GetFunction(context)
.ToLocalChecked());

View file

@ -8,9 +8,10 @@
#include <string>
#include "base/bind.h"
#include "native_mate/dictionary.h"
#include "gin/dictionary.h"
#include "native_mate/object_template_builder.h"
#include "shell/browser/browser.h"
#include "shell/common/gin_converters/callback_converter.h"
#include "shell/common/native_mate_converters/gfx_converter.h"
#include "shell/common/native_mate_converters/native_window_converter.h"
#include "shell/common/node_includes.h"
@ -182,8 +183,8 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Context> context,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
mate::Dictionary dict(isolate, exports);
dict.Set("createScreen", base::BindRepeating(&Screen::Create, isolate));
gin::Dictionary dict(isolate, exports);
dict.Set("createScreen", base::BindRepeating(&Screen::Create));
dict.Set(
"Screen",
Screen::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());

View file

@ -58,6 +58,7 @@
#include "shell/common/native_mate_converters/file_path_converter.h"
#include "shell/common/native_mate_converters/gurl_converter.h"
#include "shell/common/native_mate_converters/net_converter.h"
#include "shell/common/native_mate_converters/once_callback.h"
#include "shell/common/native_mate_converters/value_converter.h"
#include "shell/common/node_includes.h"
#include "shell/common/options_switches.h"

View file

@ -12,7 +12,7 @@
#include "base/values.h"
#include "native_mate/handle.h"
#include "shell/browser/api/event_emitter.h"
#include "shell/common/error_util.h"
#include "shell/common/gin_helper/error_thrower.h"
#include "shell/common/promise_util.h"
#if defined(OS_WIN)
@ -96,7 +96,7 @@ class SystemPreferences : public mate::EventEmitter<SystemPreferences>
void RemoveUserDefault(const std::string& name);
bool IsSwipeTrackingFromScrollEventsEnabled();
std::string GetSystemColor(util::ErrorThrower thrower,
std::string GetSystemColor(gin_helper::ErrorThrower thrower,
const std::string& color);
bool CanPromptTouchID();

View file

@ -405,7 +405,7 @@ std::string SystemPreferences::GetAccentColor() {
return base::SysNSStringToUTF8([sysColor RGBAValue]);
}
std::string SystemPreferences::GetSystemColor(util::ErrorThrower thrower,
std::string SystemPreferences::GetSystemColor(gin_helper::ErrorThrower thrower,
const std::string& color) {
NSColor* sysColor = nil;
if (color == "blue") {

View file

@ -8,7 +8,7 @@
#include <vector>
#include "electron/buildflags/buildflags.h"
#include "gin/converter.h"
#include "gin/dictionary.h"
#include "native_mate/handle.h"
#include "native_mate/persistent_dictionary.h"
#include "shell/browser/api/atom_api_browser_view.h"
@ -16,7 +16,8 @@
#include "shell/browser/api/atom_api_view.h"
#include "shell/browser/api/atom_api_web_contents.h"
#include "shell/common/color_util.h"
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
#include "shell/common/gin_converters/callback_converter.h"
#include "shell/common/gin_converters/image_converter.h"
#include "shell/common/native_mate_converters/file_path_converter.h"
#include "shell/common/native_mate_converters/gfx_converter.h"
#include "shell/common/native_mate_converters/image_converter.h"
@ -35,6 +36,9 @@
#include "ui/base/win/shell.h"
#endif
// TODO(zcbenz): Remove this after removing mate::ObjectTemplateBuilder.
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
#if defined(OS_WIN)
namespace mate {
@ -43,8 +47,8 @@ struct Converter<electron::TaskbarHost::ThumbarButton> {
static bool FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val,
electron::TaskbarHost::ThumbarButton* out) {
mate::Dictionary dict;
if (!ConvertFromV8(isolate, val, &dict))
gin::Dictionary dict;
if (!gin::ConvertFromV8(isolate, val, &dict))
return false;
dict.Get("click", &(out->clicked_callback));
dict.Get("tooltip", &(out->tooltip));

View file

@ -69,7 +69,6 @@
#include "shell/browser/web_contents_zoom_controller.h"
#include "shell/browser/web_view_guest_delegate.h"
#include "shell/common/api/atom_api_native_image.h"
#include "shell/common/api/event_emitter_caller.h"
#include "shell/common/color_util.h"
#include "shell/common/mouse_util.h"
#include "shell/common/native_mate_converters/blink_converter.h"

View file

@ -566,4 +566,22 @@ class WebContents : public mate::TrackableObject<WebContents>,
} // namespace electron
namespace gin {
// TODO(zcbenz): Remove this after converting WebContents to gin::Wrapper.
template <>
struct Converter<electron::api::WebContents*> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
electron::api::WebContents** out) {
return mate::ConvertFromV8(isolate, val, out);
}
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
electron::api::WebContents* in) {
return mate::ConvertToV8(isolate, in);
}
};
} // namespace gin
#endif // SHELL_BROWSER_API_ATOM_API_WEB_CONTENTS_H_

View file

@ -12,7 +12,7 @@
#include "content/public/browser/browser_thread.h"
#include "electron/shell/common/api/api.mojom.h"
#include "native_mate/wrappable.h"
#include "shell/common/api/event_emitter_caller.h"
#include "shell/common/api/event_emitter_caller_deprecated.h"
namespace content {
class RenderFrameHost;

View file

@ -17,13 +17,15 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/download_item_utils.h"
#include "content/public/browser/download_manager.h"
#include "gin/dictionary.h"
#include "net/base/filename_util.h"
#include "shell/browser/api/atom_api_download_item.h"
#include "shell/browser/atom_browser_context.h"
#include "shell/browser/native_window.h"
#include "shell/browser/ui/file_dialog.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"
namespace electron {
@ -122,7 +124,7 @@ void AtomDownloadManagerDelegate::OnDownloadPathGenerated(
settings.force_detached = offscreen;
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 =
base::BindOnce(&AtomDownloadManagerDelegate::OnDownloadSaveDialogDone,
base::Unretained(this), download_id, callback);
@ -139,7 +141,7 @@ void AtomDownloadManagerDelegate::OnDownloadPathGenerated(
void AtomDownloadManagerDelegate::OnDownloadSaveDialogDone(
uint32_t download_id,
const content::DownloadTargetCallback& download_callback,
mate::Dictionary result) {
gin::Dictionary result) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
auto* item = download_manager_->GetDownload(download_id);

View file

@ -48,7 +48,7 @@ class AtomDownloadManagerDelegate : public content::DownloadManagerDelegate {
void OnDownloadSaveDialogDone(
uint32_t download_id,
const content::DownloadTargetCallback& download_callback,
mate::Dictionary result);
gin::Dictionary result);
content::DownloadManager* download_manager_;
base::WeakPtrFactory<AtomDownloadManagerDelegate> weak_ptr_factory_;

View file

@ -7,9 +7,7 @@
#include <utility>
#include "mojo/public/cpp/system/string_data_source.h"
#include "shell/common/api/event_emitter_caller.h"
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
#include "shell/common/gin_converters/callback_converter.h"
#include "shell/common/node_includes.h"
namespace electron {
@ -41,7 +39,7 @@ NodeStreamLoader::~NodeStreamLoader() {
// Unsubscribe all 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_)};
node::MakeCallback(isolate_, emitter_.Get(isolate_), "removeListener",
node::arraysize(args), args, {0, 0});
@ -142,8 +140,8 @@ void NodeStreamLoader::On(const char* event, EventCallback callback) {
// emitter.on(event, callback)
v8::Local<v8::Value> args[] = {
mate::StringToV8(isolate_, event),
mate::CallbackToV8(isolate_, std::move(callback)),
gin::StringToV8(isolate_, event),
gin_helper::CallbackToV8Leaked(isolate_, std::move(callback)),
};
handlers_[event].Reset(isolate_, args[1]);
node::MakeCallback(isolate_, emitter_.Get(isolate_), "on",

View file

@ -23,6 +23,8 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "shell/common/api/locker.h"
#include "shell/common/node_includes.h"
using content::BrowserThread;

View file

@ -5,27 +5,27 @@
#ifndef 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 {
// Possible bundle movement conflicts
enum class BundlerMoverConflictType { EXISTS, EXISTS_AND_RUNNING };
namespace ui {
namespace cocoa {
class AtomBundleMover {
public:
static bool Move(mate::Arguments* args);
static bool Move(gin_helper::ErrorThrower thrower, gin::Arguments* args);
static bool IsCurrentAppInApplicationsFolder();
private:
static bool ShouldContinueMove(BundlerMoverConflictType type,
mate::Arguments* args);
static bool ShouldContinueMove(gin_helper::ErrorThrower thrower,
BundlerMoverConflictType type,
gin::Arguments* args);
static bool IsInApplicationsFolder(NSString* bundlePath);
static NSString* ContainingDiskImageDevice(NSString* bundlePath);
static void Relaunch(NSString* destinationPath);
@ -39,10 +39,6 @@ class AtomBundleMover {
static bool Trash(NSString* path);
};
} // namespace cocoa
} // namespace ui
} // namespace electron
#endif // SHELL_BROWSER_UI_COCOA_ATOM_BUNDLE_MOVER_H_

View file

@ -4,19 +4,17 @@
#import "shell/browser/ui/cocoa/atom_bundle_mover.h"
#include <string>
#import <AppKit/AppKit.h>
#import <Foundation/Foundation.h>
#import <Security/Security.h>
#import <dlfcn.h>
#import <sys/mount.h>
#import <sys/param.h>
#import "shell/browser/browser.h"
#include "shell/common/native_mate_converters/once_callback.h"
#include "gin/dictionary.h"
#include "shell/browser/browser.h"
#include "shell/common/gin_converters/callback_converter.h"
namespace mate {
namespace gin {
template <>
struct Converter<electron::BundlerMoverConflictType> {
@ -24,26 +22,23 @@ struct Converter<electron::BundlerMoverConflictType> {
electron::BundlerMoverConflictType value) {
switch (value) {
case electron::BundlerMoverConflictType::EXISTS:
return mate::StringToV8(isolate, "exists");
return gin::StringToV8(isolate, "exists");
case electron::BundlerMoverConflictType::EXISTS_AND_RUNNING:
return mate::StringToV8(isolate, "existsAndRunning");
return gin::StringToV8(isolate, "existsAndRunning");
default:
return mate::StringToV8(isolate, "");
return gin::StringToV8(isolate, "");
}
}
};
} // namespace mate
} // namespace gin
namespace electron {
namespace ui {
namespace cocoa {
bool AtomBundleMover::ShouldContinueMove(BundlerMoverConflictType type,
mate::Arguments* args) {
mate::Dictionary options;
bool AtomBundleMover::ShouldContinueMove(gin_helper::ErrorThrower thrower,
BundlerMoverConflictType type,
gin::Arguments* args) {
gin::Dictionary options;
bool hasOptions = args->GetNext(&options);
base::OnceCallback<v8::Local<v8::Value>(BundlerMoverConflictType)>
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
// value; this allows for client-side error handling should something in
// the handler throw
args->ThrowError("Invalid conflict handler return type.");
thrower.ThrowError("Invalid conflict handler return type.");
}
}
return true;
}
bool AtomBundleMover::Move(mate::Arguments* args) {
bool AtomBundleMover::Move(gin_helper::ErrorThrower thrower,
gin::Arguments* args) {
// Path of the current bundle
NSString* bundlePath = [[NSBundle mainBundle] bundlePath];
@ -103,10 +99,10 @@ bool AtomBundleMover::Move(mate::Arguments* args) {
&authorizationCanceled)) {
if (authorizationCanceled) {
// User rejected the authorization request
args->ThrowError("User rejected the authorization request");
thrower.ThrowError("User rejected the authorization request");
return false;
} else {
args->ThrowError(
thrower.ThrowError(
"Failed to copy to applications directory even with authorization");
return false;
}
@ -117,8 +113,8 @@ bool AtomBundleMover::Move(mate::Arguments* args) {
// But first, make sure that it's not running
if (IsApplicationAtPathRunning(destinationPath)) {
// Check for callback handler and get user choice for open/quit
if (!ShouldContinueMove(BundlerMoverConflictType::EXISTS_AND_RUNNING,
args))
if (!ShouldContinueMove(
thrower, BundlerMoverConflictType::EXISTS_AND_RUNNING, args))
return false;
// Unless explicitly denied, give running app focus and terminate self
@ -131,20 +127,21 @@ bool AtomBundleMover::Move(mate::Arguments* args) {
return true;
} else {
// Check callback handler and get user choice for app trashing
if (!ShouldContinueMove(BundlerMoverConflictType::EXISTS, args))
if (!ShouldContinueMove(thrower, BundlerMoverConflictType::EXISTS,
args))
return false;
// Unless explicitly denied, attempt to trash old app
if (!Trash([applicationsDirectory
stringByAppendingPathComponent:bundleName])) {
args->ThrowError("Failed to delete existing application");
thrower.ThrowError("Failed to delete existing application");
return false;
}
}
}
if (!CopyBundle(bundlePath, destinationPath)) {
args->ThrowError(
thrower.ThrowError(
"Failed to copy current bundle to the applications folder");
return false;
}
@ -466,8 +463,4 @@ bool AtomBundleMover::DeleteOrTrash(NSString* path) {
}
}
} // namespace cocoa
} // namespace ui
} // namespace electron

View file

@ -10,8 +10,7 @@
#include <vector>
#include "base/files/file_path.h"
#include "native_mate/dictionary.h"
#include "shell/common/native_mate_converters/file_path_converter.h"
#include "gin/dictionary.h"
#include "shell/common/promise_util.h"
namespace electron {
@ -66,12 +65,12 @@ bool ShowOpenDialogSync(const DialogSettings& settings,
std::vector<base::FilePath>* paths);
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);
void ShowSaveDialog(const DialogSettings& settings,
electron::util::Promise<mate::Dictionary> promise);
electron::util::Promise<gin::Dictionary> promise);
} // namespace file_dialog

View file

@ -11,6 +11,7 @@
#include "chrome/browser/ui/libgtkui/gtk_util.h"
#include "shell/browser/native_window_views.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/views/widget/desktop_aura/x11_desktop_handler.h"
@ -137,15 +138,15 @@ class FileChooserDialog {
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(
new electron::util::Promise<mate::Dictionary>(std::move(promise)));
new electron::util::Promise<gin::Dictionary>(std::move(promise)));
RunAsynchronous();
}
void RunOpenAsynchronous(electron::util::Promise<mate::Dictionary> promise) {
void RunOpenAsynchronous(electron::util::Promise<gin::Dictionary> promise) {
open_promise_.reset(
new electron::util::Promise<mate::Dictionary>(std::move(promise)));
new electron::util::Promise<gin::Dictionary>(std::move(promise)));
RunAsynchronous();
}
@ -186,8 +187,8 @@ class FileChooserDialog {
GtkWidget* preview_;
Filters filters_;
std::unique_ptr<electron::util::Promise<mate::Dictionary>> save_promise_;
std::unique_ptr<electron::util::Promise<mate::Dictionary>> open_promise_;
std::unique_ptr<electron::util::Promise<gin::Dictionary>> save_promise_;
std::unique_ptr<electron::util::Promise<gin::Dictionary>> open_promise_;
// Callback for when we update the preview for the selection.
CHROMEG_CALLBACK_0(FileChooserDialog, void, OnUpdatePreview, GtkWidget*);
@ -198,8 +199,8 @@ class FileChooserDialog {
void FileChooserDialog::OnFileDialogResponse(GtkWidget* widget, int response) {
gtk_widget_hide(dialog_);
if (save_promise_) {
mate::Dictionary dict =
mate::Dictionary::CreateEmpty(save_promise_->isolate());
gin::Dictionary dict =
gin::Dictionary::CreateEmpty(save_promise_->isolate());
if (response == GTK_RESPONSE_ACCEPT) {
dict.Set("canceled", false);
dict.Set("filePath", GetFileName());
@ -207,10 +208,10 @@ void FileChooserDialog::OnFileDialogResponse(GtkWidget* widget, int response) {
dict.Set("canceled", true);
dict.Set("filePath", base::FilePath());
}
save_promise_->Resolve(dict);
save_promise_->ResolveWithGin(dict);
} else if (open_promise_) {
mate::Dictionary dict =
mate::Dictionary::CreateEmpty(open_promise_->isolate());
gin::Dictionary dict =
gin::Dictionary::CreateEmpty(open_promise_->isolate());
if (response == GTK_RESPONSE_ACCEPT) {
dict.Set("canceled", false);
dict.Set("filePaths", GetFileNames());
@ -218,7 +219,7 @@ void FileChooserDialog::OnFileDialogResponse(GtkWidget* widget, int response) {
dict.Set("canceled", true);
dict.Set("filePaths", std::vector<base::FilePath>());
}
open_promise_->Resolve(dict);
open_promise_->ResolveWithGin(dict);
}
delete this;
}
@ -294,7 +295,7 @@ bool ShowOpenDialogSync(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;
if (settings.properties & OPEN_DIALOG_OPEN_DIRECTORY)
action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
@ -317,7 +318,7 @@ bool ShowSaveDialogSync(const DialogSettings& settings, base::FilePath* path) {
}
void ShowSaveDialog(const DialogSettings& settings,
electron::util::Promise<mate::Dictionary> promise) {
electron::util::Promise<gin::Dictionary> promise) {
FileChooserDialog* save_dialog =
new FileChooserDialog(GTK_FILE_CHOOSER_ACTION_SAVE, settings);
save_dialog->RunSaveAsynchronous(std::move(promise));

View file

@ -17,6 +17,7 @@
#include "base/mac/scoped_cftyperef.h"
#include "base/strings/sys_string_conversions.h"
#include "shell/browser/native_window.h"
#include "shell/common/gin_converters/file_path_converter.h"
@interface PopUpButtonHandler : NSObject
@ -300,15 +301,15 @@ bool ShowOpenDialogSync(const DialogSettings& settings,
void OpenDialogCompletion(int chosen,
NSOpenPanel* dialog,
bool security_scoped_bookmarks,
electron::util::Promise<mate::Dictionary> promise) {
mate::Dictionary dict = mate::Dictionary::CreateEmpty(promise.isolate());
electron::util::Promise<gin::Dictionary> promise) {
gin::Dictionary dict = gin::Dictionary::CreateEmpty(promise.isolate());
if (chosen == NSFileHandlingPanelCancelButton) {
dict.Set("canceled", true);
dict.Set("filePaths", std::vector<base::FilePath>());
#if defined(MAS_BUILD)
dict.Set("bookmarks", std::vector<std::string>());
#endif
promise.Resolve(dict);
promise.ResolveWithGin(dict);
} else {
std::vector<base::FilePath> paths;
dict.Set("canceled", false);
@ -324,12 +325,12 @@ void OpenDialogCompletion(int chosen,
ReadDialogPaths(dialog, &paths);
dict.Set("filePaths", paths);
#endif
promise.Resolve(dict);
promise.ResolveWithGin(dict);
}
}
void ShowOpenDialog(const DialogSettings& settings,
electron::util::Promise<mate::Dictionary> promise) {
electron::util::Promise<gin::Dictionary> promise) {
NSOpenPanel* dialog = [NSOpenPanel openPanel];
SetupDialog(dialog, settings);
@ -339,7 +340,7 @@ void ShowOpenDialog(const DialogSettings& settings,
// and pass it to the completion handler.
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() ||
settings.force_detached) {
@ -377,13 +378,13 @@ bool ShowSaveDialogSync(const DialogSettings& settings, base::FilePath* path) {
void SaveDialogCompletion(int chosen,
NSSavePanel* dialog,
bool security_scoped_bookmarks,
electron::util::Promise<mate::Dictionary> promise) {
mate::Dictionary dict = mate::Dictionary::CreateEmpty(promise.isolate());
electron::util::Promise<gin::Dictionary> promise) {
gin::Dictionary dict = gin::Dictionary::CreateEmpty(promise.isolate());
if (chosen == NSFileHandlingPanelCancelButton) {
dict.Set("canceled", true);
dict.Set("filePath", base::FilePath());
#if defined(MAS_BUILD)
dict.Set("bookmark", "");
dict.Set("bookmark", base::StringPiece());
#endif
} else {
std::string path = base::SysNSStringToUTF8([[dialog URL] path]);
@ -397,11 +398,11 @@ void SaveDialogCompletion(int chosen,
}
#endif
}
promise.Resolve(dict);
promise.ResolveWithGin(dict);
}
void ShowSaveDialog(const DialogSettings& settings,
electron::util::Promise<mate::Dictionary> promise) {
electron::util::Promise<gin::Dictionary> promise) {
NSSavePanel* dialog = [NSSavePanel savePanel];
SetupDialog(dialog, settings);
@ -412,7 +413,7 @@ void ShowSaveDialog(const DialogSettings& settings,
// and pass it to the completion handler.
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() ||
settings.force_detached) {

View file

@ -21,6 +21,7 @@
#include "base/win/registry.h"
#include "shell/browser/native_window_views.h"
#include "shell/browser/unresponsive_suppressor.h"
#include "shell/common/gin_converters/file_path_converter.h"
namespace file_dialog {
@ -81,19 +82,19 @@ bool CreateDialogThread(RunState* run_state) {
return true;
}
void OnDialogOpened(electron::util::Promise<mate::Dictionary> promise,
void OnDialogOpened(electron::util::Promise<gin::Dictionary> promise,
bool canceled,
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("filePaths", paths);
promise.Resolve(dict);
promise.ResolveWithGin(dict);
}
void RunOpenDialogInNewThread(
const RunState& run_state,
const DialogSettings& settings,
electron::util::Promise<mate::Dictionary> promise) {
electron::util::Promise<gin::Dictionary> promise) {
std::vector<base::FilePath> paths;
bool result = ShowOpenDialogSync(settings, &paths);
run_state.ui_task_runner->PostTask(
@ -102,19 +103,19 @@ void RunOpenDialogInNewThread(
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,
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("filePath", path);
promise.Resolve(dict);
promise.ResolveWithGin(dict);
}
void RunSaveDialogInNewThread(
const RunState& run_state,
const DialogSettings& settings,
electron::util::Promise<mate::Dictionary> promise) {
electron::util::Promise<gin::Dictionary> promise) {
base::FilePath path;
bool result = ShowSaveDialogSync(settings, &path);
run_state.ui_task_runner->PostTask(
@ -276,13 +277,13 @@ bool ShowOpenDialogSync(const DialogSettings& settings,
}
void ShowOpenDialog(const DialogSettings& settings,
electron::util::Promise<mate::Dictionary> promise) {
mate::Dictionary dict = mate::Dictionary::CreateEmpty(promise.isolate());
electron::util::Promise<gin::Dictionary> promise) {
gin::Dictionary dict = gin::Dictionary::CreateEmpty(promise.isolate());
RunState run_state;
if (!CreateDialogThread(&run_state)) {
dict.Set("canceled", true);
dict.Set("filePaths", std::vector<base::FilePath>());
promise.Resolve(dict);
promise.ResolveWithGin(dict);
} else {
run_state.dialog_thread->task_runner()->PostTask(
FROM_HERE, base::BindOnce(&RunOpenDialogInNewThread, run_state,
@ -326,13 +327,13 @@ bool ShowSaveDialogSync(const DialogSettings& settings, base::FilePath* path) {
}
void ShowSaveDialog(const DialogSettings& settings,
electron::util::Promise<mate::Dictionary> promise) {
electron::util::Promise<gin::Dictionary> promise) {
RunState 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("filePath", base::FilePath());
promise.Resolve(dict);
promise.ResolveWithGin(dict);
} else {
run_state.dialog_thread->task_runner()->PostTask(
FROM_HERE, base::BindOnce(&RunSaveDialogInNewThread, run_state,

View file

@ -20,13 +20,14 @@
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.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/mime_util.h"
#include "shell/browser/atom_browser_context.h"
#include "shell/browser/native_window.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"
using blink::mojom::FileChooserFileInfo;
@ -54,7 +55,7 @@ class FileSelectHelper : public base::RefCounted<FileSelectHelper>,
void ShowOpenDialog(const file_dialog::DialogSettings& settings) {
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);
ignore_result(promise.Then(std::move(callback)));
@ -64,7 +65,7 @@ class FileSelectHelper : public base::RefCounted<FileSelectHelper>,
void ShowSaveDialog(const file_dialog::DialogSettings& settings) {
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);
ignore_result(promise.Then(std::move(callback)));
@ -115,7 +116,7 @@ class FileSelectHelper : public base::RefCounted<FileSelectHelper>,
AddRef();
}
void OnOpenDialogDone(mate::Dictionary result) {
void OnOpenDialogDone(gin::Dictionary result) {
std::vector<FileChooserFileInfoPtr> file_info;
bool canceled = true;
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;
bool canceled = true;
result.Get("canceled", &canceled);