From bb3924ef6da895e7e0a53078d35bb0c0335ae83d Mon Sep 17 00:00:00 2001 From: Xiao YiFang Date: Tue, 17 May 2022 20:44:48 +0800 Subject: [PATCH] fix: iframe new experimental feature enabled only when user append ## to the website dictionary url --- utils.hh | 5 ++--- website.cc | 28 +++++++++++++++++++++++----- weburlrequestinterceptor.cpp | 10 +++++++--- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/utils.hh b/utils.hh index 9c7699e1a..0a1450527 100644 --- a/utils.hh +++ b/utils.hh @@ -50,9 +50,8 @@ inline QString unescapeHtml(const QString &str) { inline bool isExternalLink(QUrl const &url) { - return url.scheme() == "http" || url.scheme() == "https" || - url.scheme() == "ftp" || url.scheme() == "mailto" || - url.scheme() == "file"; + return url.scheme() == "http" || url.scheme() == "https" || url.scheme() == "ftp" || url.scheme() == "mailto" || + url.scheme() == "file" || url.toString().startsWith( "//" ); } inline bool isCssFontImage(QUrl const &url) { diff --git a/website.cc b/website.cc index 6534626e3..6c62e19a1 100644 --- a/website.cc +++ b/website.cc @@ -23,6 +23,7 @@ class WebSiteDictionary: public Dictionary::Class { string name; QByteArray urlTemplate; + bool experimentalIframe; QString iconFilename; bool inside_iframe; QNetworkAccessManager & netMgr; @@ -36,12 +37,20 @@ class WebSiteDictionary: public Dictionary::Class QNetworkAccessManager & netMgr_ ): Dictionary::Class( id, vector< string >() ), name( name_ ), - urlTemplate( QUrl( urlTemplate_ ).toEncoded() ), iconFilename( iconFilename_ ), inside_iframe( inside_iframe_ ), - netMgr( netMgr_ ) + netMgr( netMgr_ ), + experimentalIframe(false) { - dictionaryDescription = urlTemplate_; + QString temp=urlTemplate_; + if(temp.endsWith("##")){ + experimentalIframe=true; + temp.chop(2); + } + + urlTemplate = QUrl( temp ).toEncoded() ; + + dictionaryDescription = temp; } virtual string getName() throw() @@ -372,12 +381,21 @@ sptr< DataRequest > WebSiteDictionary::getArticle( wstring const & str, string result = "
"; - //permissive add url to global whitelist. + //heuristic add url to global whitelist. QUrl url(urlString); GlobalBroadcaster::instance()->addWhitelist(url.host()); + QString encodeUrl; + if(experimentalIframe){ + encodeUrl="ifr://localhost?url="+QUrl::toPercentEncoding( urlString); + } + else{ + encodeUrl = urlString; + } + + result += string( "