macOS: Add support for custom uri scheme handling

With this support applications can claim to be handler for
specific custom scheme URLs such as "com.my.app"

This requires that the scheme is listed in the plist file
(CFBundleURLTypes and CFBundleURLSchemes).

One notable usage example is the use of OAuth redirect_uris.

[ChangeLog][macOS] Added support for custom uri scheme handling

Task-number: QTBUG-124340
Change-Id: Ia04e9b89b53ee6f24129f9dd5ee8fbc5c0f0516c
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
bb10
Juha Vuolle 2024-04-30 11:19:23 +03:00 committed by Tor Arne Vestbø
parent e8e881ba35
commit 664c7ffb21
1 changed files with 13 additions and 1 deletions

View File

@ -359,13 +359,25 @@ QT_USE_NAMESPACE
- (void)getUrl:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
{
Q_UNUSED(replyEvent);
NSString *urlString = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
const QString qurlString = QString::fromNSString(urlString);
if (event.eventClass == kInternetEventClass && event.eventID == kAEGetURL) {
// 'GURL' (Get URL) event this application should handle
if (!QGuiApplication::instance())
return;
QCocoaIntegration *cocoaIntegration = QCocoaIntegration::instance();
Q_ASSERT(cocoaIntegration);
cocoaIntegration->services()->handleUrl(QUrl(qurlString));
return;
}
// The string we get from the requesting application might not necessarily meet
// QUrl's requirement for a IDN-compliant host. So if we can't parse into a QUrl,
// then we pass the string on to the application as the name of a file (and
// QFileOpenEvent::file is not guaranteed to be the path to a local, open'able
// file anyway).
const QString qurlString = QString::fromNSString(urlString);
if (const QUrl url(qurlString); url.isValid())
QWindowSystemInterface::handleFileOpenEvent(url);
else