diff --git a/src/lib/opensearch/searchenginesmanager.cpp b/src/lib/opensearch/searchenginesmanager.cpp index 42e84436e..2a0a49593 100644 --- a/src/lib/opensearch/searchenginesmanager.cpp +++ b/src/lib/opensearch/searchenginesmanager.cpp @@ -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); } diff --git a/src/lib/tools/scripts.cpp b/src/lib/tools/scripts.cpp index 29b3fa9ab..5b3d4e410 100644 --- a/src/lib/tools/scripts.cpp +++ b/src/lib/tools/scripts.cpp @@ -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 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 &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); +} diff --git a/src/lib/tools/scripts.h b/src/lib/tools/scripts.h index 76bd34808..c83c41f33 100644 --- a/src/lib/tools/scripts.h +++ b/src/lib/tools/scripts.h @@ -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 diff --git a/src/lib/webengine/webview.cpp b/src/lib/webengine/webview.cpp index 86822646c..928110d22 100644 --- a/src/lib/webengine/webview.cpp +++ b/src/lib/webengine/webview.cpp @@ -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)