summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuha Vuolle <juha.vuolle@qt.io>2024-04-30 11:19:23 +0300
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2024-05-03 08:17:17 +0000
commit664c7ffb212eb898ed03f7b19c883400fa027b6b (patch)
tree21fda27c16bb11b8a0b917e9dbb5822716011bb3
parente8e881ba35fe7009961cbeb4b89efedc5371d5b5 (diff)
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>
-rw-r--r--src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm
index 10be0fe658..d642115926 100644
--- a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm
+++ b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm
@@ -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