]> khamidou — GitHub mirrors - electron.git/commitdiff
return bool on shell.openExternal
authormsullivan <msullivan@logmein.com>
Wed, 10 Jun 2015 15:06:22 +0000 (11:06 -0400)
committermsullivan <msullivan@logmein.com>
Wed, 10 Jun 2015 15:06:22 +0000 (11:06 -0400)
atom/common/platform_util.h
atom/common/platform_util_linux.cc
atom/common/platform_util_mac.mm
atom/common/platform_util_win.cc

index 7ac150b792112b8facb317e160403ed0d8587951..312942c4f5dca781326b6decb559be83d9858732 100644 (file)
@@ -23,7 +23,7 @@ void OpenItem(const base::FilePath& full_path);
 
 // Open the given external protocol URL in the desktop's default manner.
 // (For example, mailto: URLs in the default mail user agent.)
-void OpenExternal(const GURL& url);
+bool OpenExternal(const GURL& url);
 
 // Move a file to trash.
 bool MoveItemToTrash(const base::FilePath& full_path);
index f70d16a559a7a387fb63e79bd95d0e00280ca6e4..aa7439968daa802e02e95ffced726a9d1c4243dd 100644 (file)
@@ -37,12 +37,12 @@ bool XDGUtil(const std::string& util, const std::string& arg) {
   return (exit_code == 0);
 }
 
-void XDGOpen(const std::string& path) {
-  XDGUtil("xdg-open", path);
+bool XDGOpen(const std::string& path) {
+  return XDGUtil("xdg-open", path);
 }
 
-void XDGEmail(const std::string& email) {
-  XDGUtil("xdg-email", email);
+bool XDGEmail(const std::string& email) {
+  return XDGUtil("xdg-email", email);
 }
 
 }  // namespace
@@ -64,11 +64,11 @@ void OpenItem(const base::FilePath& full_path) {
   XDGOpen(full_path.value());
 }
 
-void OpenExternal(const GURL& url) {
+bool OpenExternal(const GURL& url) {
   if (url.SchemeIs("mailto"))
-    XDGEmail(url.spec());
+    return XDGEmail(url.spec());
   else
-    XDGOpen(url.spec());
+    return XDGOpen(url.spec());
 }
 
 bool MoveItemToTrash(const base::FilePath& full_path) {
index 41f3c59916aa1f2500d373ede69aeaf0af3191a5..4637bc330e315002837a8c145260bd881ee52983 100644 (file)
@@ -118,12 +118,19 @@ void OpenItem(const base::FilePath& full_path) {
   }
 }
 
-void OpenExternal(const GURL& url) {
+bool OpenExternal(const GURL& url) {
   DCHECK([NSThread isMainThread]);
   NSString* url_string = base::SysUTF8ToNSString(url.spec());
   NSURL* ns_url = [NSURL URLWithString:url_string];
-  if (!ns_url || ![[NSWorkspace sharedWorkspace] openURL:ns_url])
-    LOG(WARNING) << "NSWorkspace failed to open URL " << url;
+  if (!ns_url){
+    return false;
+  }
+  NSArray *appUrls = (NSArray*)LSCopyApplicationURLsForURL((CFURLRef)ns_url, kLSRolesAll);
+  if([appUrls count] > 0){
+    if([[NSWorkspace sharedWorkspace] openURL:ns_url])
+      return true;
+  }
+  return false;
 }
 
 bool MoveItemToTrash(const base::FilePath& full_path) {
index 1998b887318941e9fddaaa617608da271599fcc7..09ac5aca48f2027350cbebf374ac87717a9c0b2c 100644 (file)
@@ -135,7 +135,7 @@ void OpenItem(const base::FilePath& full_path) {
     ui::win::OpenFileViaShell(full_path);
 }
 
-void OpenExternal(const GURL& url) {
+bool OpenExternal(const GURL& url) {
   // Quote the input scheme to be sure that the command does not have
   // parameters unexpected by the external program. This url should already
   // have been escaped.
@@ -150,12 +150,12 @@ void OpenExternal(const GURL& url) {
   const size_t kMaxUrlLength = 2048;
   if (escaped_url.length() > kMaxUrlLength) {
     NOTREACHED();
-    return;
+    return false;
   }
 
   if (base::win::GetVersion() < base::win::VERSION_WIN7) {
     if (!ValidateShellCommandForScheme(url.scheme()))
-      return;
+      return false;
   }
 
   if (reinterpret_cast<ULONG_PTR>(ShellExecuteA(NULL, "open",
@@ -164,8 +164,9 @@ void OpenExternal(const GURL& url) {
     // We fail to execute the call. We could display a message to the user.
     // TODO(nsylvain): we should also add a dialog to warn on errors. See
     // bug 1136923.
-    return;
+    return false;
   }
+  return true;
 }
 
 bool MoveItemToTrash(const base::FilePath& path) {