return bool on shell.openExternal

This commit is contained in:
msullivan 2015-06-10 11:06:22 -04:00
parent 8aa815e6d1
commit b4674923c9
4 changed files with 23 additions and 15 deletions

View file

@ -23,7 +23,7 @@ void OpenItem(const base::FilePath& full_path);
// Open the given external protocol URL in the desktop's default manner. // Open the given external protocol URL in the desktop's default manner.
// (For example, mailto: URLs in the default mail user agent.) // (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. // Move a file to trash.
bool MoveItemToTrash(const base::FilePath& full_path); bool MoveItemToTrash(const base::FilePath& full_path);

View file

@ -37,12 +37,12 @@ bool XDGUtil(const std::string& util, const std::string& arg) {
return (exit_code == 0); return (exit_code == 0);
} }
void XDGOpen(const std::string& path) { bool XDGOpen(const std::string& path) {
XDGUtil("xdg-open", path); return XDGUtil("xdg-open", path);
} }
void XDGEmail(const std::string& email) { bool XDGEmail(const std::string& email) {
XDGUtil("xdg-email", email); return XDGUtil("xdg-email", email);
} }
} // namespace } // namespace
@ -64,11 +64,11 @@ void OpenItem(const base::FilePath& full_path) {
XDGOpen(full_path.value()); XDGOpen(full_path.value());
} }
void OpenExternal(const GURL& url) { bool OpenExternal(const GURL& url) {
if (url.SchemeIs("mailto")) if (url.SchemeIs("mailto"))
XDGEmail(url.spec()); return XDGEmail(url.spec());
else else
XDGOpen(url.spec()); return XDGOpen(url.spec());
} }
bool MoveItemToTrash(const base::FilePath& full_path) { bool MoveItemToTrash(const base::FilePath& full_path) {

View 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]); DCHECK([NSThread isMainThread]);
NSString* url_string = base::SysUTF8ToNSString(url.spec()); NSString* url_string = base::SysUTF8ToNSString(url.spec());
NSURL* ns_url = [NSURL URLWithString:url_string]; NSURL* ns_url = [NSURL URLWithString:url_string];
if (!ns_url || ![[NSWorkspace sharedWorkspace] openURL:ns_url]) if (!ns_url){
LOG(WARNING) << "NSWorkspace failed to open URL " << 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) { bool MoveItemToTrash(const base::FilePath& full_path) {

View file

@ -135,7 +135,7 @@ void OpenItem(const base::FilePath& full_path) {
ui::win::OpenFileViaShell(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 // Quote the input scheme to be sure that the command does not have
// parameters unexpected by the external program. This url should already // parameters unexpected by the external program. This url should already
// have been escaped. // have been escaped.
@ -150,12 +150,12 @@ void OpenExternal(const GURL& url) {
const size_t kMaxUrlLength = 2048; const size_t kMaxUrlLength = 2048;
if (escaped_url.length() > kMaxUrlLength) { if (escaped_url.length() > kMaxUrlLength) {
NOTREACHED(); NOTREACHED();
return; return false;
} }
if (base::win::GetVersion() < base::win::VERSION_WIN7) { if (base::win::GetVersion() < base::win::VERSION_WIN7) {
if (!ValidateShellCommandForScheme(url.scheme())) if (!ValidateShellCommandForScheme(url.scheme()))
return; return false;
} }
if (reinterpret_cast<ULONG_PTR>(ShellExecuteA(NULL, "open", 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. // 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 // TODO(nsylvain): we should also add a dialog to warn on errors. See
// bug 1136923. // bug 1136923.
return; return false;
} }
return true;
} }
bool MoveItemToTrash(const base::FilePath& path) { bool MoveItemToTrash(const base::FilePath& path) {