Add API: SetASDefaultProtocolHandler

This PR adds an API enabling Electron to set itself as the default
protocol handler for a custom porotocl on both oS X and Windows.

For details, please see `docs/app.md`.

Closes #4857
This commit is contained in:
Felix Rieseberg 2016-03-21 11:24:25 -07:00
parent 4abed1f83f
commit d2567b0381
6 changed files with 99 additions and 0 deletions

View file

@ -8,6 +8,7 @@
#include "atom/browser/mac/atom_application_delegate.h"
#include "atom/browser/native_window.h"
#include "atom/browser/window_list.h"
#include "base/mac/bundle_locations.h"
#include "base/mac/foundation_util.h"
#include "base/strings/sys_string_conversions.h"
#include "brightray/common/application_info.h"
@ -45,6 +46,21 @@ void Browser::ClearRecentDocuments() {
[[NSDocumentController sharedDocumentController] clearRecentDocuments:nil];
}
bool Browser::SetAsDefaultProtocolClient(const std::string& protocol) {
if (protocol.empty())
return false;
NSString* identifier = [base::mac::MainBundle() bundleIdentifier];
if (!identifier)
return false;
NSString* protocol_ns = [NSString stringWithUTF8String:protocol.c_str()];
OSStatus return_code =
LSSetDefaultHandlerForURLScheme(base::mac::NSToCFCast(protocol_ns),
base::mac::NSToCFCast(identifier));
return return_code == noErr;
}
void Browser::SetAppUserModelID(const base::string16& name) {
}