Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement RemoveAsDefaultProtocolClient on OS X #5440

Merged
merged 2 commits into from
May 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion atom/browser/browser_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,31 @@
}

bool Browser::RemoveAsDefaultProtocolClient(const std::string& protocol) {
return false;
NSString* identifier = [base::mac::MainBundle() bundleIdentifier];
if (!identifier)
return false;

if (!Browser::IsDefaultProtocolClient(protocol))
return false;

NSString* protocol_ns = [NSString stringWithUTF8String:protocol.c_str()];
CFStringRef protocol_cf = base::mac::NSToCFCast(protocol_ns);
CFArrayRef bundleList = LSCopyAllHandlersForURLScheme(protocol_cf);
if (!bundleList) {
return false;
}
// On Mac OS X, we can't query the default, but the handlers list seems to put
// Apple's defaults first, so we'll use the first option that isn't our bundle
CFStringRef other = nil;
for (CFIndex i = 0; i < CFArrayGetCount(bundleList); i++) {
other = (CFStringRef)CFArrayGetValueAtIndex(bundleList, i);
if (![identifier isEqualToString: (__bridge NSString *)other]) {
break;
}
}

OSStatus return_code = LSSetDefaultHandlerForURLScheme(protocol_cf, other);
return return_code == noErr;
}

bool Browser::SetAsDefaultProtocolClient(const std::string& protocol) {
Expand Down
5 changes: 1 addition & 4 deletions docs/api/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,16 +393,13 @@ Please refer to [Apple's documentation][CFBundleURLTypes] for details.

The API uses the Windows Registry and LSSetDefaultHandlerForURLScheme internally.

### `app.removeAsDefaultProtocolClient(protocol)` _Windows_
### `app.removeAsDefaultProtocolClient(protocol)` _OS X_ _Windows_

* `protocol` String - The name of your protocol, without `://`.

This method checks if the current executable as the default handler for a protocol
(aka URI scheme). If so, it will remove the app as the default handler.

**Note:** On OS X, removing the app will automatically remove the app as the
default protocol handler.

### `app.isDefaultProtocolClient(protocol)` _OS X_ _Windows_

* `protocol` String - The name of your protocol, without `://`.
Expand Down