Merge pull request #4508 from atom/open-external-without-activation
Allow shell.openExternal to open URLs in the background
This commit is contained in:
commit
0446f07884
7 changed files with 33 additions and 9 deletions
|
@ -26,7 +26,8 @@ bool AtomResourceDispatcherHostDelegate::HandleExternalProtocol(
|
||||||
bool has_user_gesture) {
|
bool has_user_gesture) {
|
||||||
GURL escaped_url(net::EscapeExternalHandlerValue(url.spec()));
|
GURL escaped_url(net::EscapeExternalHandlerValue(url.spec()));
|
||||||
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
||||||
base::Bind(base::IgnoreResult(platform_util::OpenExternal), escaped_url));
|
base::Bind(
|
||||||
|
base::IgnoreResult(platform_util::OpenExternal), escaped_url, true));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,12 +12,23 @@
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
bool OpenExternal(const GURL& url, mate::Arguments* args) {
|
||||||
|
bool activate = true;
|
||||||
|
if (args->Length() == 2) {
|
||||||
|
mate::Dictionary options;
|
||||||
|
if (args->GetNext(&options)) {
|
||||||
|
options.Get("activate", &activate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return platform_util::OpenExternal(url, activate);
|
||||||
|
}
|
||||||
|
|
||||||
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
||||||
v8::Local<v8::Context> context, void* priv) {
|
v8::Local<v8::Context> context, void* priv) {
|
||||||
mate::Dictionary dict(context->GetIsolate(), exports);
|
mate::Dictionary dict(context->GetIsolate(), exports);
|
||||||
dict.SetMethod("showItemInFolder", &platform_util::ShowItemInFolder);
|
dict.SetMethod("showItemInFolder", &platform_util::ShowItemInFolder);
|
||||||
dict.SetMethod("openItem", &platform_util::OpenItem);
|
dict.SetMethod("openItem", &platform_util::OpenItem);
|
||||||
dict.SetMethod("openExternal", &platform_util::OpenExternal);
|
dict.SetMethod("openExternal", &OpenExternal);
|
||||||
dict.SetMethod("moveItemToTrash", &platform_util::MoveItemToTrash);
|
dict.SetMethod("moveItemToTrash", &platform_util::MoveItemToTrash);
|
||||||
dict.SetMethod("beep", &platform_util::Beep);
|
dict.SetMethod("beep", &platform_util::Beep);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.)
|
||||||
bool OpenExternal(const GURL& url);
|
bool OpenExternal(const GURL& url, bool activate);
|
||||||
|
|
||||||
// Move a file to trash.
|
// Move a file to trash.
|
||||||
bool MoveItemToTrash(const base::FilePath& full_path);
|
bool MoveItemToTrash(const base::FilePath& full_path);
|
||||||
|
|
|
@ -64,7 +64,7 @@ void OpenItem(const base::FilePath& full_path) {
|
||||||
XDGOpen(full_path.value());
|
XDGOpen(full_path.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OpenExternal(const GURL& url) {
|
bool OpenExternal(const GURL& url, bool activate) {
|
||||||
if (url.SchemeIs("mailto"))
|
if (url.SchemeIs("mailto"))
|
||||||
return XDGEmail(url.spec());
|
return XDGEmail(url.spec());
|
||||||
else
|
else
|
||||||
|
|
|
@ -119,7 +119,7 @@ void OpenItem(const base::FilePath& full_path) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OpenExternal(const GURL& url) {
|
bool OpenExternal(const GURL& url, bool activate) {
|
||||||
DCHECK([NSThread isMainThread]);
|
DCHECK([NSThread isMainThread]);
|
||||||
NSURL* ns_url = net::NSURLWithGURL(url);
|
NSURL* ns_url = net::NSURLWithGURL(url);
|
||||||
if (!ns_url) {
|
if (!ns_url) {
|
||||||
|
@ -136,7 +136,15 @@ bool OpenExternal(const GURL& url) {
|
||||||
}
|
}
|
||||||
CFRelease(openingApp); // NOT A BUG; LSGetApplicationForURL retains for us
|
CFRelease(openingApp); // NOT A BUG; LSGetApplicationForURL retains for us
|
||||||
|
|
||||||
return [[NSWorkspace sharedWorkspace] openURL:ns_url];
|
NSUInteger launchOptions = NSWorkspaceLaunchDefault;
|
||||||
|
if (!activate)
|
||||||
|
launchOptions |= NSWorkspaceLaunchWithoutActivation;
|
||||||
|
|
||||||
|
return [[NSWorkspace sharedWorkspace] openURLs: @[ns_url]
|
||||||
|
withAppBundleIdentifier: nil
|
||||||
|
options: launchOptions
|
||||||
|
additionalEventParamDescriptor: NULL
|
||||||
|
launchIdentifiers: NULL];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MoveItemToTrash(const base::FilePath& full_path) {
|
bool MoveItemToTrash(const base::FilePath& full_path) {
|
||||||
|
|
|
@ -301,7 +301,7 @@ void OpenItem(const base::FilePath& full_path) {
|
||||||
ui::win::OpenFileViaShell(full_path);
|
ui::win::OpenFileViaShell(full_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OpenExternal(const GURL& url) {
|
bool OpenExternal(const GURL& url, bool activate) {
|
||||||
// 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.
|
||||||
|
|
|
@ -26,12 +26,16 @@ Show the given file in a file manager. If possible, select the file.
|
||||||
|
|
||||||
Open the given file in the desktop's default manner.
|
Open the given file in the desktop's default manner.
|
||||||
|
|
||||||
### `shell.openExternal(url)`
|
### `shell.openExternal(url[, options])`
|
||||||
|
|
||||||
* `url` String
|
* `url` String
|
||||||
|
* `options` Object (optional) _OS X_
|
||||||
|
* `activate` Boolean - `true` to bring the opened application to the
|
||||||
|
foreground. The default is `true`.
|
||||||
|
|
||||||
Open the given external protocol URL in the desktop's default manner. (For
|
Open the given external protocol URL in the desktop's default manner. (For
|
||||||
example, mailto: URLs in the user's default mail agent.)
|
example, mailto: URLs in the user's default mail agent.) Returns true if an
|
||||||
|
application was available to open the URL, false otherwise.
|
||||||
|
|
||||||
### `shell.moveItemToTrash(fullPath)`
|
### `shell.moveItemToTrash(fullPath)`
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue