macOS: Add support for universal links / https uri scheme handling

With this support applications can claim to be handler for
specific https URLs. This requires that an appropriate AASA
(apple-app-site-association) JSON file is hosted and accessible.

One notable usage example is the use of OAuth redirect_uris,
which are often required to use "https" URI scheme.

[ChangeLog][macOS] Added support for https/universal links handling

Task-number: QTBUG-124340
Change-Id: I91c725fcf209b295dc1b2687a52cd0a547aff1c8
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
bb10
Juha Vuolle 2024-04-30 09:41:56 +03:00 committed by Tor Arne Vestbø
parent cbba65f9ce
commit e8e881ba35
3 changed files with 45 additions and 0 deletions

View File

@ -334,6 +334,28 @@ QT_USE_NAMESPACE
[self doesNotRecognizeSelector:invocationSelector];
}
- (BOOL)application:(NSApplication *)application continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void(^)(NSArray<id<NSUserActivityRestoring>> *restorableObjects))restorationHandler
{
// Check if eg. user has installed an app delegate capable of handling this
if ([reflectionDelegate respondsToSelector:_cmd]
&& [reflectionDelegate application:application continueUserActivity:userActivity
restorationHandler:restorationHandler] == YES) {
return YES;
}
if (!QGuiApplication::instance())
return NO;
if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
QCocoaIntegration *cocoaIntegration = QCocoaIntegration::instance();
Q_ASSERT(cocoaIntegration);
return cocoaIntegration->services()->handleUrl(QUrl::fromNSURL(userActivity.webpageURL));
}
return NO;
}
- (void)getUrl:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
{
Q_UNUSED(replyEvent);

View File

@ -4,6 +4,8 @@
#ifndef QCOCOADESKTOPSERVICES_H
#define QCOCOADESKTOPSERVICES_H
#include <QtCore/qurl.h>
#include <qpa/qplatformservices.h>
QT_BEGIN_NAMESPACE
@ -15,8 +17,12 @@ public:
bool openUrl(const QUrl &url) override;
bool openDocument(const QUrl &url) override;
bool handleUrl(const QUrl &url);
QPlatformServiceColorPicker *colorPicker(QWindow *parent) override;
private:
QUrl m_handlingUrl;
};
QT_END_NAMESPACE

View File

@ -8,12 +8,19 @@
#include <Foundation/NSURL.h>
#include <QtCore/QUrl>
#include <QtCore/qscopedvaluerollback.h>
#include <QtGui/qdesktopservices.h>
#include <QtGui/private/qcoregraphics_p.h>
QT_BEGIN_NAMESPACE
bool QCocoaServices::openUrl(const QUrl &url)
{
// avoid recursing back into self
if (url == m_handlingUrl)
return false;
return [[NSWorkspace sharedWorkspace] openURL:url.toNSURL()];
}
@ -22,6 +29,16 @@ bool QCocoaServices::openDocument(const QUrl &url)
return openUrl(url);
}
/* Callback from macOS that the application should handle a URL */
bool QCocoaServices::handleUrl(const QUrl &url)
{
QScopedValueRollback<QUrl> rollback(m_handlingUrl, url);
// FIXME: Add platform services callback from QDesktopServices::setUrlHandler
// so that we can warn the user if calling setUrlHandler without also setting
// up the matching keys in the Info.plist file (CFBundleURLTypes and friends).
return QDesktopServices::openUrl(url);
}
class QCocoaColorPicker : public QPlatformServiceColorPicker
{
public: