mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 09:32:12 +01:00
Bring back support for sending POST data
This fixes searching with engines that use POST method
This commit is contained in:
parent
44de2b48a0
commit
e83734069b
|
@ -146,8 +146,6 @@ LoadRequest SearchEnginesManager::searchResult(const Engine &engine, const QStri
|
|||
data.replace("%s", QUrl::toPercentEncoding(string));
|
||||
|
||||
QNetworkRequest req(QUrl::fromEncoded(engine.url.toUtf8()));
|
||||
req.setHeader(QNetworkRequest::ContentTypeHeader, QByteArray("application/x-www-form-urlencoded"));
|
||||
|
||||
return LoadRequest(req, LoadRequest::PostOperation, data);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,20 +19,7 @@
|
|||
#include "scripts.h"
|
||||
#include "qztools.h"
|
||||
|
||||
QString Scripts::setCss(const QString &css)
|
||||
{
|
||||
static QString source = QL1S("(function() {"
|
||||
"var css = document.createElement('style');"
|
||||
"css.setAttribute('type', 'text/css');"
|
||||
"css.appendChild(document.createTextNode('%1'));"
|
||||
"document.getElementsByTagName('head')[0].appendChild(css);"
|
||||
"})()");
|
||||
|
||||
QString style = css;
|
||||
style.replace(QL1S("'"), QL1S("\\'"));
|
||||
style.replace(QL1S("\n"), QL1S("\\n"));
|
||||
return source.arg(style);
|
||||
}
|
||||
#include <QUrlQuery>
|
||||
|
||||
QString Scripts::setupWebChannel()
|
||||
{
|
||||
|
@ -49,3 +36,49 @@ QString Scripts::setupWebChannel()
|
|||
|
||||
return source.arg(QzTools::readAllFileContents(QSL(":/html/qwebchannel.js")));
|
||||
}
|
||||
|
||||
QString Scripts::setCss(const QString &css)
|
||||
{
|
||||
QString source = QL1S("(function() {"
|
||||
"var css = document.createElement('style');"
|
||||
"css.setAttribute('type', 'text/css');"
|
||||
"css.appendChild(document.createTextNode('%1'));"
|
||||
"document.getElementsByTagName('head')[0].appendChild(css);"
|
||||
"})()");
|
||||
|
||||
QString style = css;
|
||||
style.replace(QL1S("'"), QL1S("\\'"));
|
||||
style.replace(QL1S("\n"), QL1S("\\n"));
|
||||
return source.arg(style);
|
||||
}
|
||||
|
||||
QString Scripts::sendPostData(const QUrl &url, const QByteArray &data)
|
||||
{
|
||||
QString source = QL1S("(function() {"
|
||||
"var form = document.createElement('form');"
|
||||
"form.setAttribute('method', 'POST');"
|
||||
"form.setAttribute('action', '%1');"
|
||||
"var val;"
|
||||
"%2"
|
||||
"form.submit();"
|
||||
"})()");
|
||||
|
||||
QString valueSource = QL1S("val = document.createElement('input');"
|
||||
"val.setAttribute('type', 'hidden');"
|
||||
"val.setAttribute('name', '%1');"
|
||||
"val.setAttribute('value', '%2');"
|
||||
"form.appendChild(val);");
|
||||
|
||||
QString values;
|
||||
QUrlQuery query(data);
|
||||
|
||||
for (const QPair<QString, QString> &pair : query.queryItems(QUrl::FullyDecoded)) {
|
||||
QString value = pair.first;
|
||||
QString key = pair.second;
|
||||
value.replace(QL1S("'"), QL1S("\\'"));
|
||||
key.replace(QL1S("'"), QL1S("\\'"));
|
||||
values.append(valueSource.arg(value, key));
|
||||
}
|
||||
|
||||
return source.arg(url.toString(), values);
|
||||
}
|
||||
|
|
|
@ -28,8 +28,9 @@ class QWebEngineView;
|
|||
class QUPZILLA_EXPORT Scripts
|
||||
{
|
||||
public:
|
||||
static QString setCss(const QString &css);
|
||||
static QString setupWebChannel();
|
||||
static QString setCss(const QString &css);
|
||||
static QString sendPostData(const QUrl &url, const QByteArray &data);
|
||||
};
|
||||
|
||||
#endif // SCRIPTS_H
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include "enhancedmenu.h"
|
||||
#include "locationbar.h"
|
||||
#include "webinspector.h"
|
||||
#include "scripts.h"
|
||||
|
||||
#ifdef USE_HUNSPELL
|
||||
#include "qtwebkit/spellcheck/speller.h"
|
||||
|
@ -1602,14 +1603,10 @@ void WebView::loadRequest(const LoadRequest &req)
|
|||
{
|
||||
m_aboutToLoadUrl = req.url();
|
||||
|
||||
#if QTWEBENGINE_DISABLED
|
||||
if (req.operation() == LoadRequest::GetOperation)
|
||||
QWebEngineView::load(req.networkRequest());
|
||||
load(req.url());
|
||||
else
|
||||
QWebEngineView::load(req.networkRequest(), QNetworkAccessManager::PostOperation, req.data());
|
||||
#else
|
||||
load(req.url());
|
||||
#endif
|
||||
m_page->runJavaScript(Scripts::sendPostData(req.url(), req.data()));
|
||||
}
|
||||
|
||||
bool WebView::eventFilter(QObject* obj, QEvent* event)
|
||||
|
|
Loading…
Reference in New Issue
Block a user