mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-23 13:35:58 +03:00
Merge pull request #541 from nextcloud/bugfix/noid/wizard-external-links
Make links open in an external browser
This commit is contained in:
commit
92aaa09643
2 changed files with 41 additions and 3 deletions
|
@ -6,6 +6,7 @@
|
|||
#include <QWebEngineUrlRequestJob>
|
||||
#include <QWebEngineUrlSchemeHandler>
|
||||
#include <QWebEngineView>
|
||||
#include <QDesktopServices>
|
||||
#include <QProgressBar>
|
||||
#include <QLoggingCategory>
|
||||
#include <QLocale>
|
||||
|
@ -36,6 +37,19 @@ Q_SIGNALS:
|
|||
void urlCatched(QString user, QString pass, QString host);
|
||||
};
|
||||
|
||||
class WebEnginePage : public QWebEnginePage {
|
||||
public:
|
||||
WebEnginePage(QWebEngineProfile *profile, QObject* parent = nullptr);
|
||||
QWebEnginePage * createWindow(QWebEnginePage::WebWindowType type) override;
|
||||
};
|
||||
|
||||
// We need a separate class here, since we cannot simply return the same WebEnginePage object
|
||||
// this leads to a strage segfault somewhere deep inside of the QWebEngine code
|
||||
class ExternalWebEnginePage : public QWebEnginePage {
|
||||
public:
|
||||
ExternalWebEnginePage(QWebEngineProfile *profile, QObject* parent = nullptr);
|
||||
bool acceptNavigationRequest(const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame) override;
|
||||
};
|
||||
|
||||
WebView::WebView(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
|
@ -45,11 +59,13 @@ WebView::WebView(QWidget *parent)
|
|||
|
||||
_webview = new QWebEngineView(this);
|
||||
_profile = new QWebEngineProfile(this);
|
||||
_page = new QWebEnginePage(_profile);
|
||||
_page = new WebEnginePage(_profile);
|
||||
_interceptor = new WebViewPageUrlRequestInterceptor(this);
|
||||
_schemeHandler = new WebViewPageUrlSchemeHandler(this);
|
||||
|
||||
_profile->setHttpUserAgent(Utility::userAgentString());
|
||||
const QString userAgent(Utility::userAgentString());
|
||||
_profile->setHttpUserAgent(userAgent);
|
||||
QWebEngineProfile::defaultProfile()->setHttpUserAgent(userAgent);
|
||||
_profile->setRequestInterceptor(_interceptor);
|
||||
_profile->installUrlSchemeHandler("nc", _schemeHandler);
|
||||
|
||||
|
@ -120,6 +136,27 @@ void WebViewPageUrlSchemeHandler::requestStarted(QWebEngineUrlRequestJob *reques
|
|||
emit urlCatched(user, password, server);
|
||||
}
|
||||
|
||||
|
||||
WebEnginePage::WebEnginePage(QWebEngineProfile *profile, QObject* parent) : QWebEnginePage(profile, parent) {
|
||||
|
||||
}
|
||||
|
||||
QWebEnginePage * WebEnginePage::createWindow(QWebEnginePage::WebWindowType type) {
|
||||
ExternalWebEnginePage *view = new ExternalWebEnginePage(this->profile());
|
||||
return view;
|
||||
}
|
||||
|
||||
ExternalWebEnginePage::ExternalWebEnginePage(QWebEngineProfile *profile, QObject* parent) : QWebEnginePage(profile, parent) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool ExternalWebEnginePage::acceptNavigationRequest(const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame)
|
||||
{
|
||||
QDesktopServices::openUrl(url);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#include "webview.moc"
|
||||
|
|
|
@ -14,6 +14,7 @@ namespace OCC {
|
|||
|
||||
class WebViewPageUrlRequestInterceptor;
|
||||
class WebViewPageUrlSchemeHandler;
|
||||
class WebEnginePage;
|
||||
|
||||
class WebView : public QWidget
|
||||
{
|
||||
|
@ -30,7 +31,7 @@ private:
|
|||
|
||||
QWebEngineView *_webview;
|
||||
QWebEngineProfile *_profile;
|
||||
QWebEnginePage *_page;
|
||||
WebEnginePage *_page;
|
||||
|
||||
WebViewPageUrlRequestInterceptor *_interceptor;
|
||||
WebViewPageUrlSchemeHandler *_schemeHandler;
|
||||
|
|
Loading…
Reference in a new issue