diff --git a/src/lib/app/mainapplication.cpp b/src/lib/app/mainapplication.cpp index 5f726b8f2..87a3136fd 100644 --- a/src/lib/app/mainapplication.cpp +++ b/src/lib/app/mainapplication.cpp @@ -269,22 +269,7 @@ MainApplication::MainApplication(int &argc, char** argv) m_networkManager = new NetworkManager(this); - // Setup QWebChannel userscript - QWebEngineScript script; - script.setName(QSL("_falkon_webchannel")); - script.setInjectionPoint(QWebEngineScript::DocumentCreation); - script.setWorldId(WebPage::SafeJsWorld); - script.setRunsOnSubFrames(true); - script.setSourceCode(Scripts::setupWebChannel(script.worldId())); - m_webProfile->scripts()->insert(script); - - QWebEngineScript script2; - script2.setName(QSL("_qupzilla_webchannel2")); - script2.setInjectionPoint(QWebEngineScript::DocumentCreation); - script2.setWorldId(WebPage::UnsafeJsWorld); - script2.setRunsOnSubFrames(true); - script2.setSourceCode(Scripts::setupWebChannel(script2.worldId())); - m_webProfile->scripts()->insert(script2); + setupUserScripts(); if (!isPrivate()) { m_sessionManager = new SessionManager(this); @@ -1131,6 +1116,36 @@ void MainApplication::checkOptimizeDatabase() settings.endGroup(); } +void MainApplication::setupUserScripts() +{ + // WebChannel for SafeJsWorld + QWebEngineScript script; + script.setName(QSL("_falkon_webchannel")); + script.setInjectionPoint(QWebEngineScript::DocumentCreation); + script.setWorldId(WebPage::SafeJsWorld); + script.setRunsOnSubFrames(true); + script.setSourceCode(Scripts::setupWebChannel(script.worldId())); + m_webProfile->scripts()->insert(script); + + // WebChannel for UnsafeJsWorld + QWebEngineScript script2; + script2.setName(QSL("_falkon_webchannel2")); + script2.setInjectionPoint(QWebEngineScript::DocumentCreation); + script2.setWorldId(WebPage::UnsafeJsWorld); + script2.setRunsOnSubFrames(true); + script2.setSourceCode(Scripts::setupWebChannel(script2.worldId())); + m_webProfile->scripts()->insert(script2); + + // window.external support + QWebEngineScript script3; + script3.setName(QSL("_falkon_window_external")); + script3.setInjectionPoint(QWebEngineScript::DocumentCreation); + script3.setWorldId(WebPage::UnsafeJsWorld); + script3.setRunsOnSubFrames(true); + script3.setSourceCode(Scripts::setupWindowExternal()); + m_webProfile->scripts()->insert(script3); +} + void MainApplication::setUserStyleSheet(const QString &filePath) { QString userCss; diff --git a/src/lib/app/mainapplication.h b/src/lib/app/mainapplication.h index 714afe991..188f40557 100644 --- a/src/lib/app/mainapplication.h +++ b/src/lib/app/mainapplication.h @@ -156,6 +156,7 @@ private: void translateApp(); + void setupUserScripts(); void setUserStyleSheet(const QString &filePath); void checkDefaultWebBrowser(); diff --git a/src/lib/tools/scripts.cpp b/src/lib/tools/scripts.cpp index fab318e38..640f72305 100644 --- a/src/lib/tools/scripts.cpp +++ b/src/lib/tools/scripts.cpp @@ -143,6 +143,23 @@ QString Scripts::setupFormObserver() return source; } +QString Scripts::setupWindowExternal() +{ + QString source = QL1S("(function() {" + "var external = {};" + "external.AddSearchProvider = function(url) {" + " window.location = 'qupzilla:AddSearchProvider?url=' + url;" + "};" + "external.IsSearchProviderInstalled = function(url) {" + " console.warn('NOT IMPLEMENTED: IsSearchProviderInstalled()');" + " return false;" + "};" + "window.external = external;" + "})()"); + + return source; +} + QString Scripts::setCss(const QString &css) { QString source = QL1S("(function() {" diff --git a/src/lib/tools/scripts.h b/src/lib/tools/scripts.h index 4cf799c30..4965bc725 100644 --- a/src/lib/tools/scripts.h +++ b/src/lib/tools/scripts.h @@ -30,6 +30,7 @@ class FALKON_EXPORT Scripts public: static QString setupWebChannel(quint32 worldId); static QString setupFormObserver(); + static QString setupWindowExternal(); static QString setCss(const QString &css); static QString sendPostData(const QUrl &url, const QByteArray &data); diff --git a/src/lib/webengine/webpage.cpp b/src/lib/webengine/webpage.cpp index d6abf0eca..214403524 100644 --- a/src/lib/webengine/webpage.cpp +++ b/src/lib/webengine/webpage.cpp @@ -55,6 +55,7 @@ #include #include #include +#include QString WebPage::s_lastUploadLocation = QDir::homePath(); QUrl WebPage::s_lastUnsupportedUrl; @@ -379,6 +380,12 @@ bool WebPage::acceptNavigationRequest(const QUrl &url, QWebEnginePage::Navigatio if (!mApp->plugins()->acceptNavigationRequest(this, url, type, isMainFrame)) return false; + if (url.scheme() == QL1S("qupzilla") && url.path() == QL1S("AddSearchProvider")) { + QUrlQuery query(url); + mApp->searchEnginesManager()->addEngine(QUrl(query.queryItemValue(QSL("url")))); + return false; + } + const bool result = QWebEnginePage::acceptNavigationRequest(url, type, isMainFrame); if (result && isMainFrame) {