From 04416ff40cd8ae334a4acac9a869a5e9849c71c9 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 22 Oct 2014 17:27:42 -0700 Subject: [PATCH] fix for DataWebPage hifi link handling --- interface/src/ui/DataWebPage.cpp | 18 +++++++++++++++--- interface/src/ui/DataWebPage.h | 1 + 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/interface/src/ui/DataWebPage.cpp b/interface/src/ui/DataWebPage.cpp index 812489a34d..b8b6649276 100644 --- a/interface/src/ui/DataWebPage.cpp +++ b/interface/src/ui/DataWebPage.cpp @@ -9,6 +9,9 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include + +#include #include #include "DataWebPage.h" @@ -19,13 +22,22 @@ DataWebPage::DataWebPage(QObject* parent) : // use an OAuthNetworkAccessManager instead of regular QNetworkAccessManager so our requests are authed setNetworkAccessManager(OAuthNetworkAccessManager::getInstance()); - // have the page delegate external links so they can be captured by the Application in case they are a hifi link - setLinkDelegationPolicy(QWebPage::DelegateExternalLinks); - // give the page an empty stylesheet settings()->setUserStyleSheetUrl(QUrl()); } void DataWebPage::javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID) { qDebug() << "JS console message at line" << lineNumber << "from" << sourceID << "-" << message; +} + +bool DataWebPage::acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest& request, QWebPage::NavigationType type) { + + if (!request.url().toString().startsWith(HIFI_URL_SCHEME)) { + return true; + } else { + // this is a hifi URL - have the AddressManager handle it + QMetaObject::invokeMethod(&AddressManager::getInstance(), "handleLookupString", + Qt::AutoConnection, Q_ARG(const QString&, request.url().toString())); + return false; + } } \ No newline at end of file diff --git a/interface/src/ui/DataWebPage.h b/interface/src/ui/DataWebPage.h index 72fcbb5992..6d89077a33 100644 --- a/interface/src/ui/DataWebPage.h +++ b/interface/src/ui/DataWebPage.h @@ -19,6 +19,7 @@ public: DataWebPage(QObject* parent = 0); protected: void javaScriptConsoleMessage(const QString & message, int lineNumber, const QString & sourceID); + bool acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest& request, QWebPage::NavigationType type); }; #endif // hifi_DataWebPage_h \ No newline at end of file