From 69172601c91c7d3e6b13406ea726fc217953031e Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Fri, 9 Aug 2019 18:55:51 -0700 Subject: [PATCH] platform_util shouldn't know about mate::Arguments --- shell/common/api/atom_api_shell.cc | 9 ++++++++- shell/common/platform_util.h | 2 +- shell/common/platform_util_linux.cc | 2 +- shell/common/platform_util_mac.mm | 7 +++---- shell/common/platform_util_win.cc | 2 +- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/shell/common/api/atom_api_shell.cc b/shell/common/api/atom_api_shell.cc index 6a226a888d5ca..93f673f0e329e 100644 --- a/shell/common/api/atom_api_shell.cc +++ b/shell/common/api/atom_api_shell.cc @@ -71,6 +71,13 @@ v8::Local OpenExternal(const GURL& url, mate::Arguments* args) { return handle; } +bool MoveItemToTrash(const base::FilePath& full_path, mate::Arguments* args) { + bool delete_on_fail = false; + args->GetNext(&delete_on_fail); + + return platform_util::MoveItemToTrash(full_path, delete_on_fail); +} + #if defined(OS_WIN) bool WriteShortcutLink(const base::FilePath& shortcut_path, mate::Arguments* args) { @@ -134,7 +141,7 @@ void Initialize(v8::Local exports, dict.SetMethod("showItemInFolder", &platform_util::ShowItemInFolder); dict.SetMethod("openItem", &platform_util::OpenItem); dict.SetMethod("openExternal", &OpenExternal); - dict.SetMethod("moveItemToTrash", &platform_util::MoveItemToTrash); + dict.SetMethod("moveItemToTrash", &MoveItemToTrash); dict.SetMethod("beep", &platform_util::Beep); #if defined(OS_WIN) dict.SetMethod("writeShortcutLink", &WriteShortcutLink); diff --git a/shell/common/platform_util.h b/shell/common/platform_util.h index 9e62a39f3b250..6972051e1e73e 100644 --- a/shell/common/platform_util.h +++ b/shell/common/platform_util.h @@ -42,7 +42,7 @@ void OpenExternal(const GURL& url, OpenExternalCallback callback); // Move a file to trash. -bool MoveItemToTrash(const base::FilePath& full_path, mate::Arguments* args); +bool MoveItemToTrash(const base::FilePath& full_path, bool delete_on_fail); void Beep(); diff --git a/shell/common/platform_util_linux.cc b/shell/common/platform_util_linux.cc index 87adc9f95a7e3..900f90cae1a57 100644 --- a/shell/common/platform_util_linux.cc +++ b/shell/common/platform_util_linux.cc @@ -82,7 +82,7 @@ void OpenExternal(const GURL& url, std::move(callback).Run(XDGOpen(url.spec(), false) ? "" : "Failed to open"); } -bool MoveItemToTrash(const base::FilePath& full_path, mate::Arguments* args) { +bool MoveItemToTrash(const base::FilePath& full_path, bool delete_on_fail) { std::unique_ptr env(base::Environment::Create()); // find the trash method diff --git a/shell/common/platform_util_mac.mm b/shell/common/platform_util_mac.mm index 079c79905e603..f141c4063178c 100644 --- a/shell/common/platform_util_mac.mm +++ b/shell/common/platform_util_mac.mm @@ -115,10 +115,10 @@ void OpenExternal(const GURL& url, }); } -bool MoveItemToTrash(const base::FilePath& full_path, mate::Arguments* args) { +bool MoveItemToTrash(const base::FilePath& full_path, bool delete_on_fail) { NSString* path_string = base::SysUTF8ToNSString(full_path.value()); if (!path_string) { - args->ThrowError("moveItemToTrash(): Invalid path."); + LOG(WARNING) << "Invalid file path " << full_path.value(); return false; } @@ -128,8 +128,7 @@ bool MoveItemToTrash(const base::FilePath& full_path, mate::Arguments* args) { resultingItemURL:nil error:&err]; - bool delete_on_fail = false; - if (args->GetNext(&delete_on_fail) && delete_on_fail) { + if (delete_on_fail) { // Some volumes may not support a Trash folder or it may be disabled // so these methods will report failure by returning NO or nil and // an NSError with NSFeatureUnsupportedError. diff --git a/shell/common/platform_util_win.cc b/shell/common/platform_util_win.cc index fc66398b2a9d7..87e389ddd54ac 100644 --- a/shell/common/platform_util_win.cc +++ b/shell/common/platform_util_win.cc @@ -335,7 +335,7 @@ void OpenExternal(const GURL& url, std::move(callback)); } -bool MoveItemToTrash(const base::FilePath& path, mate::Arguments* args) { +bool MoveItemToTrash(const base::FilePath& path, bool delete_on_fail) { base::win::ScopedCOMInitializer com_initializer; if (!com_initializer.Succeeded()) return false;