Skip to content

Commit

Permalink
fix: iframe new experimental feature
Browse files Browse the repository at this point in the history
enabled only when user append ## to the website dictionary url
  • Loading branch information
xiaoyifang committed May 17, 2022
1 parent e8c550e commit bb3924e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
5 changes: 2 additions & 3 deletions utils.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
28 changes: 23 additions & 5 deletions website.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class WebSiteDictionary: public Dictionary::Class
{
string name;
QByteArray urlTemplate;
bool experimentalIframe;
QString iconFilename;
bool inside_iframe;
QNetworkAccessManager & netMgr;
Expand All @@ -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()
Expand Down Expand Up @@ -372,12 +381,21 @@ sptr< DataRequest > WebSiteDictionary::getArticle( wstring const & str,

string result = "<div class=\"website_padding\"></div>";

//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( "<iframe id=\"gdexpandframe-" ) + getId() +
"\" src=\"ifr://localhost?url=" +QUrl::toPercentEncoding( urlString).data() +
"\" src=\""+encodeUrl.toStdString() +
"\" onmouseover=\"processIframeMouseOver('gdexpandframe-" + getId() + "');\" "
"onmouseout=\"processIframeMouseOut();\" "
"scrolling=\"no\" marginwidth=\"0\" marginheight=\"0\" "
Expand Down
10 changes: 7 additions & 3 deletions weburlrequestinterceptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ WebUrlRequestInterceptor::WebUrlRequestInterceptor(QObject *p)

}
void WebUrlRequestInterceptor::interceptRequest( QWebEngineUrlRequestInfo &info) {
if( Utils::isExternalLink( info.requestUrl() ) )
if( GlobalBroadcaster::instance()->getPreference()->disallowContentFromOtherSites && Utils::isExternalLink( info.requestUrl() ) )
{
//file:// link ,pass
if(info.requestUrl().scheme()=="file"){
return;
}
auto hostBase = getHostBase( info.requestUrl().host() );
if( GlobalBroadcaster::instance()->existedInWhitelist( hostBase ) )
{
Expand All @@ -22,10 +26,10 @@ void WebUrlRequestInterceptor::interceptRequest( QWebEngineUrlRequestInfo &info)
return;
}

// configure should the gd block external links
// if( GlobalBroadcaster::instance()->getPreference()->disallowContentFromOtherSites )
// block external links
{
info.block( true );
return;
}
}

Expand Down

0 comments on commit bb3924e

Please sign in to comment.