mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 10:46:35 +01:00
SearchEngines: Add back support for window.external.AddSearchProvider
This commit is contained in:
parent
6ecc9f616f
commit
e0e62c6e81
@ -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;
|
||||
|
@ -156,6 +156,7 @@ private:
|
||||
|
||||
void translateApp();
|
||||
|
||||
void setupUserScripts();
|
||||
void setUserStyleSheet(const QString &filePath);
|
||||
|
||||
void checkDefaultWebBrowser();
|
||||
|
@ -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() {"
|
||||
|
@ -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);
|
||||
|
@ -55,6 +55,7 @@
|
||||
#include <QFileDialog>
|
||||
#include <QAuthenticator>
|
||||
#include <QPushButton>
|
||||
#include <QUrlQuery>
|
||||
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user