Return boolean from shell.openItem

This commit is contained in:
Kevin Sawicki 2016-09-12 14:29:06 -07:00
parent 72558654ef
commit 55eab8e385
5 changed files with 18 additions and 16 deletions

View file

@ -25,7 +25,7 @@ bool ShowItemInFolder(const base::FilePath& full_path);
// Open the given file in the desktop's default manner. // Open the given file in the desktop's default manner.
// Must be called from the UI thread. // Must be called from the UI thread.
void OpenItem(const base::FilePath& full_path); bool 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.)

View file

@ -67,8 +67,8 @@ bool ShowItemInFolder(const base::FilePath& full_path) {
return XDGOpen(dir.value(), true); return XDGOpen(dir.value(), true);
} }
void OpenItem(const base::FilePath& full_path) { bool OpenItem(const base::FilePath& full_path) {
XDGOpen(full_path.value(), true); return XDGOpen(full_path.value(), true);
} }
bool OpenExternal(const GURL& url, bool activate) { bool OpenExternal(const GURL& url, bool activate) {

View file

@ -40,11 +40,11 @@ bool ShowItemInFolder(const base::FilePath& path) {
// 2. Silent no-op for unassociated file types: http://crbug.com/50263 // 2. Silent no-op for unassociated file types: http://crbug.com/50263
// Instead, an AppleEvent is constructed to tell the Finder to open the // Instead, an AppleEvent is constructed to tell the Finder to open the
// document. // document.
void OpenItem(const base::FilePath& full_path) { bool OpenItem(const base::FilePath& full_path) {
DCHECK([NSThread isMainThread]); DCHECK([NSThread isMainThread]);
NSString* path_string = base::SysUTF8ToNSString(full_path.value()); NSString* path_string = base::SysUTF8ToNSString(full_path.value());
if (!path_string) if (!path_string)
return; return false;
// Create the target of this AppleEvent, the Finder. // Create the target of this AppleEvent, the Finder.
base::mac::ScopedAEDesc<AEAddressDesc> address; base::mac::ScopedAEDesc<AEAddressDesc> address;
@ -55,7 +55,7 @@ void OpenItem(const base::FilePath& full_path) {
address.OutPointer()); // result address.OutPointer()); // result
if (status != noErr) { if (status != noErr) {
OSSTATUS_LOG(WARNING, status) << "Could not create OpenItem() AE target"; OSSTATUS_LOG(WARNING, status) << "Could not create OpenItem() AE target";
return; return false;
} }
// Build the AppleEvent data structure that instructs Finder to open files. // Build the AppleEvent data structure that instructs Finder to open files.
@ -68,7 +68,7 @@ void OpenItem(const base::FilePath& full_path) {
theEvent.OutPointer()); // result theEvent.OutPointer()); // result
if (status != noErr) { if (status != noErr) {
OSSTATUS_LOG(WARNING, status) << "Could not create OpenItem() AE event"; OSSTATUS_LOG(WARNING, status) << "Could not create OpenItem() AE event";
return; return false;
} }
// Create the list of files (only ever one) to open. // Create the list of files (only ever one) to open.
@ -79,7 +79,7 @@ void OpenItem(const base::FilePath& full_path) {
fileList.OutPointer()); // resultList fileList.OutPointer()); // resultList
if (status != noErr) { if (status != noErr) {
OSSTATUS_LOG(WARNING, status) << "Could not create OpenItem() AE file list"; OSSTATUS_LOG(WARNING, status) << "Could not create OpenItem() AE file list";
return; return false;
} }
// Add the single path to the file list. C-style cast to avoid both a // Add the single path to the file list. C-style cast to avoid both a
@ -95,11 +95,11 @@ void OpenItem(const base::FilePath& full_path) {
if (status != noErr) { if (status != noErr) {
OSSTATUS_LOG(WARNING, status) OSSTATUS_LOG(WARNING, status)
<< "Could not add file path to AE list in OpenItem()"; << "Could not add file path to AE list in OpenItem()";
return; return false;
} }
} else { } else {
LOG(WARNING) << "Could not get FSRef for path URL in OpenItem()"; LOG(WARNING) << "Could not get FSRef for path URL in OpenItem()";
return; return false;
} }
// Attach the file list to the AppleEvent. // Attach the file list to the AppleEvent.
@ -109,7 +109,7 @@ void OpenItem(const base::FilePath& full_path) {
if (status != noErr) { if (status != noErr) {
OSSTATUS_LOG(WARNING, status) OSSTATUS_LOG(WARNING, status)
<< "Could not put the AE file list the path in OpenItem()"; << "Could not put the AE file list the path in OpenItem()";
return; return false;
} }
// Send the actual event. Do not care about the reply. // Send the actual event. Do not care about the reply.
@ -125,6 +125,7 @@ void OpenItem(const base::FilePath& full_path) {
OSSTATUS_LOG(WARNING, status) OSSTATUS_LOG(WARNING, status)
<< "Could not send AE to Finder in OpenItem()"; << "Could not send AE to Finder in OpenItem()";
} }
return status == noErr;
} }
bool OpenExternal(const GURL& url, bool activate) { bool OpenExternal(const GURL& url, bool activate) {

View file

@ -292,11 +292,11 @@ bool ShowItemInFolder(const base::FilePath& full_path) {
} }
} }
void OpenItem(const base::FilePath& full_path) { bool OpenItem(const base::FilePath& full_path) {
if (base::DirectoryExists(full_path)) if (base::DirectoryExists(full_path))
ui::win::OpenFolderViaShell(full_path); return ui::win::OpenFolderViaShell(full_path);
else else
ui::win::OpenFileViaShell(full_path); return ui::win::OpenFileViaShell(full_path);
} }
bool OpenExternal(const base::string16& url, bool activate) { bool OpenExternal(const base::string16& url, bool activate) {

View file

@ -21,13 +21,14 @@ The `shell` module has the following methods:
* `fullPath` String * `fullPath` String
Show the given file in a file manager. If possible, select the file. Returns Show the given file in a file manager. If possible, select the file. Returns
true if the item was successfully shown, false otherwse. true if the item was successfully shown, false otherwise.
### `shell.openItem(fullPath)` ### `shell.openItem(fullPath)`
* `fullPath` String * `fullPath` String
Open the given file in the desktop's default manner. Open the given file in the desktop's default manner. Returns true if the item
was successfully opened, false otherwise.
### `shell.openExternal(url[, options])` ### `shell.openExternal(url[, options])`